Supporting things for builtin/network,builtin/client_file reload restore

This commit is contained in:
Perttu Ahola 2014-09-19 17:00:15 +03:00
parent 66ab5c1985
commit 028e4b9975
5 changed files with 51 additions and 0 deletions

View File

@ -48,6 +48,8 @@ struct Module: public interface::Module, public client_file::Interface
{
log_v(MODULE, "client_file init");
m_server->sub_event(this, Event::t("core:start"));
m_server->sub_event(this, Event::t("core:unload"));
m_server->sub_event(this, Event::t("core:continue"));
m_server->sub_event(this, Event::t("network:new_client"));
m_server->sub_event(this,
Event::t("network:packet_received/core:request_file"));
@ -62,6 +64,8 @@ struct Module: public interface::Module, public client_file::Interface
void event(const Event::Type &type, const Event::Private *p)
{
EVENT_VOIDN("core:start", on_start)
EVENT_VOIDN("core:unload", on_unload)
EVENT_VOIDN("core:continue", on_continue)
EVENT_TYPEN("network:new_client", on_new_client, network::NewClient)
EVENT_TYPEN("network:packet_received/core:request_file", on_request_file,
network::Packet)
@ -75,6 +79,16 @@ struct Module: public interface::Module, public client_file::Interface
{
}
void on_unload()
{
log_v(MODULE, "on_unload");
}
void on_continue()
{
log_v(MODULE, "on_continue");
}
void on_new_client(const network::NewClient &new_client)
{
log_i(MODULE, "client_file::on_new_client: id=%zu", new_client.info.id);

View File

@ -61,6 +61,8 @@ struct Module: public interface::Module, public network::Interface
{
log_v(MODULE, "network init");
m_server->sub_event(this, Event::t("core:start"));
m_server->sub_event(this, Event::t("core:unload"));
m_server->sub_event(this, Event::t("core:continue"));
m_server->sub_event(this, Event::t("network:listen_event"));
m_server->sub_event(this, Event::t("network:incoming_data"));
}
@ -68,6 +70,8 @@ struct Module: public interface::Module, public network::Interface
void event(const Event::Type &type, const Event::Private *p)
{
EVENT_VOIDN("core:start", on_start)
EVENT_VOIDN("core:unload", on_unload)
EVENT_VOIDN("core:continue", on_continue)
EVENT_TYPEN("network:listen_event", on_listen_event, interface::SocketEvent)
EVENT_TYPEN("network:incoming_data", on_incoming_data, interface::SocketEvent)
}
@ -90,6 +94,16 @@ struct Module: public interface::Module, public network::Interface
Event::t("network:listen_event"));
}
void on_unload()
{
log_v(MODULE, "on_unload");
}
void on_continue()
{
log_v(MODULE, "on_continue");
}
void on_listen_event(const interface::SocketEvent &event)
{
log_i(MODULE, "network: on_listen_event(): fd=%i", event.fd);

View File

@ -54,6 +54,7 @@ Startup sequence and what the module should do:
- constructor : Don't access other modules. Throw on fatal errors.
- init() : Subscribe to events; access other external things.
- "core:start" : Start doing whatever the module wants to actively do.
- "core:unload" : Module will be unloaded immediately after event handler.
- "core:continue" : Continue doing stuff after a reload.
Dependencies: deps.txt

View File

@ -58,5 +58,8 @@ namespace interface
virtual void add_socket_event(int fd, const Event::Type &event_type) = 0;
virtual void remove_socket_event(int fd) = 0;
virtual void tmp_store_data(const ss_ &name, const ss_ &data) = 0;
virtual ss_ tmp_restore_data(const ss_ &name) = 0;
};
}

View File

@ -50,6 +50,9 @@ struct CState: public State, public interface::Server
sm_<int, SocketState> m_sockets;
interface::Mutex m_sockets_mutex;
sm_<ss_, ss_> m_tmp_data;
interface::Mutex m_tmp_data_mutex;
CState():
m_compiler(rccpp::createCompiler())
{
@ -188,6 +191,8 @@ struct CState: public State, public interface::Server
}
ModuleContainer *mc = &it->second;
interface::MutexScope mc_ms(mc->mutex);
// Send core::unload directly to module
mc->module->event(Event::t("core:unload"), nullptr);
// Clear unload request
m_unloads_requested.erase(module_name);
// Delete subscriptions
@ -439,6 +444,20 @@ struct CState: public State, public interface::Server
return;
} while(0);
}
void tmp_store_data(const ss_ &name, const ss_ &data)
{
interface::MutexScope ms(m_tmp_data_mutex);
m_tmp_data[name] = data;
}
ss_ tmp_restore_data(const ss_ &name)
{
interface::MutexScope ms(m_tmp_data_mutex);
ss_ data = m_tmp_data[name];
m_tmp_data.erase(name);
return data;
}
};
State* createState()