#include "interface/module.h" #include "interface/server.h" #include "interface/event.h" #include "interface/mutex.h" #include "test1/include/api.h" #include "network/include/api.h" #include "core/log.h" using interface::Event; namespace test1 { struct Module: public interface::Module { interface::Mutex m_interface_mutex; interface::Server *m_server; Event::Type m_EventType_test1_thing; Module(interface::Server *server): interface::Module("test1"), m_server(server), m_EventType_test1_thing(Event::t("test1:thing")) { log_v(MODULE, "test1 construct"); } void init() { interface::MutexScope ms(m_interface_mutex); log_v(MODULE, "test1 init"); m_server->sub_event(this, Event::t("core:start")); m_server->sub_event(this, m_EventType_test1_thing); m_server->sub_event(this, Event::t("network:new_client")); } ~Module() { log_v(MODULE, "test1 destruct"); } void event(const Event::Type &type, const Event::Private *p) { interface::MutexScope ms(m_interface_mutex); EVENT_VOIDN("core:start", on_start) EVENT_TYPE(m_EventType_test1_thing, on_thing, Thing) EVENT_TYPEN("network:new_client", on_new_client, network::NewClient) } void on_start() { } void on_thing(const Thing &thing) { log_i(MODULE, "test1.thing: some_data=%s", cs(thing.some_data)); } void on_new_client(const network::NewClient &new_client) { log_i(MODULE, "test1::on_new_client: id=%zu", new_client.info.id); network::Interface *inetwork = network::get_interface(m_server); inetwork->send(new_client.info.id, "test1:dummy", "dummy data"); } }; extern "C" { EXPORT void* createModule_test1(interface::Server *server){ return (void*)(new Module(server)); } } }