84 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 23:00:31 +03:00
#include "interface/mutex.h"
2014-09-17 02:18:03 +03:00
#include "test1/include/api.h"
#include "network/include/api.h"
#include "core/log.h"
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 23:00:31 +03:00
interface::Mutex m_interface_mutex;
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;
Module(interface::Server *server):
2014-09-17 23:00:31 +03:00
interface::Module("test1"),
2014-09-17 02:18:03 +03:00
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
{
log_v(MODULE, "test1 construct");
2014-09-16 23:14:04 +03:00
}
2014-09-16 22:42:47 +03:00
~Module()
{
log_v(MODULE, "test1 destruct");
}
2014-09-17 14:53:06 +03:00
void init()
{
2014-09-17 23:00:31 +03:00
interface::MutexScope ms(m_interface_mutex);
log_v(MODULE, "test1 init");
2014-09-17 23:00:31 +03:00
m_server->sub_event(this, Event::t("core:start"));
2014-09-17 14:53:06 +03:00
m_server->sub_event(this, m_EventType_test1_thing);
m_server->sub_event(this, Event::t("network:new_client"));
2014-09-18 01:35:53 +03:00
m_server->sub_event(this, Event::t("network:packet_received"));
2014-09-17 14:53:06 +03:00
}
2014-09-17 18:52:59 +03:00
void event(const Event::Type &type, const Event::Private *p)
{
2014-09-17 23:00:31 +03:00
interface::MutexScope ms(m_interface_mutex);
EVENT_VOIDN("core:start", on_start)
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-18 01:35:53 +03:00
EVENT_TYPEN("network:packet_received", on_packet_received, network::Packet)
}
2014-09-17 23:00:31 +03:00
void on_start()
{
}
2014-09-17 16:43:05 +03:00
void on_thing(const Thing &thing)
2014-09-17 01:04:51 +03:00
{
log_i(MODULE, "test1.thing: some_data=%s", cs(thing.some_data));
2014-09-17 01:04:51 +03:00
}
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");
}
2014-09-18 01:35:53 +03:00
void on_packet_received(const network::Packet &packet)
{
log_i(MODULE, "test1::on_packet_received: type=%zu, size=%zu",
packet.type, packet.data.size());
}
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
}