enable unloading of module for cleaner shutdown

sayer/1.4-spce2.6
Stefan Sayer 15 years ago
parent 23694e99b4
commit 7fd59bf2f3

@ -81,6 +81,12 @@ class AmPluginFactory
* @return 1 on error.
*/
virtual int onLoad()=0;
/**
* Enables the plug-in to deinitialize once the server is stopped.
*/
virtual void onUnload() { };
};
/**

@ -115,6 +115,9 @@ static void delete_plugin_factory(std::pair<string, AmPluginFactory*> pf)
{
if ((deleted_factories.find(pf.second) == deleted_factories.end()) &&
(deleted_factories_names.find(pf.first) == deleted_factories_names.end())) {
DBG("onUnload of plugin '%s'\n", pf.first.c_str());
pf.second->onUnload();
DBG("deleting plug-in factory: %s\n", pf.first.c_str());
deleted_factories.insert(pf.second);
deleted_factories_names.insert(pf.first);

@ -25,6 +25,15 @@ public:
#endif
return 0;
}
#ifdef SESSION_TIMER_THREAD
void onUnload() {
DBG("stopping userTimer thread\n");
UserTimer::instance()->_running = false;
usleep(10 * SESSION_TIMER_GRANULARITY * 1000);
UserTimer::instance()->stop();
}
#endif
};
@ -56,7 +65,8 @@ UserTimer* UserTimer::instance()
#ifdef SESSION_TIMER_THREAD
void UserTimer::run() {
while(1){
_running = true;
while(_running){
usleep(SESSION_TIMER_GRANULARITY * 1000);
checkTimers();
}
@ -216,6 +226,9 @@ void UserTimer::invoke(const string& method, const AmArg& args, AmArg& ret)
else if(method == "removeUserTimers"){
removeUserTimers(args.get(0).asCStr());
}
else if(method == "stop"){
_running = false;
}
else
throw AmDynInvoke::NotImplemented(method);
}

@ -74,12 +74,15 @@ class UserTimer: public AmDynInvoke
unsigned int hash(const string& s1);
void unsafe_removeTimer(int id, const string& session_id, unsigned int bucket);
public:
UserTimer();
~UserTimer();
static UserTimer* instance();
bool _running;
/** set timer with ID id, fire after s seconds event in
session session_id */
void setTimer(int id, int seconds, const string& session_id);

Loading…
Cancel
Save