78 lines
2.0 KiB
C++
Raw Normal View History

2014-09-16 22:42:47 +03:00
#include "interface/module.h"
2014-09-16 23:14:04 +03:00
#include "interface/server.h"
2014-09-17 01:04:51 +03:00
#include "interface/event.h"
2014-09-17 02:18:03 +03:00
#include "test1/include/api.h"
#include "network/include/api.h"
2014-09-16 23:57:31 +03:00
#include <iostream>
2014-09-16 22:42:47 +03:00
2014-09-17 01:04:51 +03:00
using interface::Event;
2014-09-17 02:18:03 +03:00
namespace test1 {
2014-09-16 23:14:04 +03:00
struct Module: public interface::Module
2014-09-16 22:42:47 +03:00
{
2014-09-17 02:18:03 +03:00
interface::Server *m_server;
2014-09-17 02:18:03 +03:00
Event::Type m_EventType_test1_thing;
network::Packet::Type m_NetworkPacketType_dummy_packet = 0;
2014-09-17 02:18:03 +03:00
Module(interface::Server *server):
m_server(server),
2014-09-17 16:43:05 +03:00
m_EventType_test1_thing(Event::t("test1:thing"))
2014-09-16 23:14:04 +03:00
{
2014-09-16 23:57:31 +03:00
std::cout<<"test1 construct"<<std::endl;
2014-09-16 23:14:04 +03:00
}
2014-09-16 22:42:47 +03:00
2014-09-17 14:53:06 +03:00
void init()
{
std::cout<<"test1 init"<<std::endl;
m_server->sub_event(this, m_EventType_test1_thing);
m_server->sub_event(this, Event::t("network:new_client"));
m_server->sub_event(this, Event::t("network:get_packet_type_resp"));
m_server->emit_event("network:get_packet_type",
2014-09-17 20:58:23 +03:00
new network::Req_get_packet_type("test1:dummy_packet"));
2014-09-17 14:53:06 +03:00
}
2014-09-16 23:14:04 +03:00
~Module()
{
2014-09-16 23:57:31 +03:00
std::cout<<"test1 destruct"<<std::endl;
2014-09-16 23:14:04 +03:00
}
2014-09-16 22:42:47 +03:00
2014-09-17 18:52:59 +03:00
void event(const Event::Type &type, const Event::Private *p)
{
2014-09-17 20:15:46 +03:00
EVENT_TYPE(m_EventType_test1_thing, on_thing, Thing)
EVENT_TYPEN("network:new_client", on_new_client, network::NewClient)
2014-09-17 20:58:23 +03:00
EVENT_TYPEN("network:get_packet_type_resp", on_get_packet_type_resp,
network::Resp_get_packet_type)
}
2014-09-17 16:43:05 +03:00
void on_thing(const Thing &thing)
2014-09-17 01:04:51 +03:00
{
2014-09-17 16:43:05 +03:00
std::cout<<"test1.thing: some_data="<<thing.some_data<<std::endl;
2014-09-17 01:04:51 +03:00
}
void on_new_client(const network::NewClient &new_client)
{
std::cout<<"test1::on_new_client: id="<<new_client.info.id<<std::endl;
m_server->emit_event("network:send",
2014-09-17 20:58:23 +03:00
new network::Packet(new_client.info.id,
m_NetworkPacketType_dummy_packet, "dummy data"));
}
void on_get_packet_type_resp(const network::Resp_get_packet_type &event)
{
std::cout<<"test1: Got packet type: "<<event.type<<std::endl;
m_NetworkPacketType_dummy_packet = event.type;
}
2014-09-16 23:14:04 +03:00
};
extern "C" {
2014-09-17 02:18:03 +03:00
EXPORT void* createModule_test1(interface::Server *server){
return (void*)(new Module(server));
}
2014-09-16 23:14:04 +03:00
}
2014-09-16 22:42:47 +03:00
}