Module: sems
Branch: master
Commit: 873a37d34955559ece48cac5d2213605e489f329
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=873a37d34955559ece48cac5d2213605e489f329

Author: Stefan Sayer <[email protected]>
Committer: Stefan Sayer <[email protected]>
Date:   Wed Oct 12 22:36:21 2011 +0200

enable unloading of module for cleaner shutdown

---

 core/AmApi.h                             |    6 ++++++
 core/AmPlugIn.cpp                        |    3 +++
 core/plug-in/session_timer/UserTimer.cpp |   15 ++++++++++++++-
 core/plug-in/session_timer/UserTimer.h   |    3 +++
 4 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/core/AmApi.h b/core/AmApi.h
index 1223392..a8faa73 100644
--- a/core/AmApi.h
+++ b/core/AmApi.h
@@ -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() { };
 };
 
 /**
diff --git a/core/AmPlugIn.cpp b/core/AmPlugIn.cpp
index 8db47ff..a447cd9 100644
--- a/core/AmPlugIn.cpp
+++ b/core/AmPlugIn.cpp
@@ -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);
diff --git a/core/plug-in/session_timer/UserTimer.cpp 
b/core/plug-in/session_timer/UserTimer.cpp
index 57ff863..8f28f33 100644
--- a/core/plug-in/session_timer/UserTimer.cpp
+++ b/core/plug-in/session_timer/UserTimer.cpp
@@ -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);
 }
diff --git a/core/plug-in/session_timer/UserTimer.h 
b/core/plug-in/session_timer/UserTimer.h
index 64c20f0..984b319 100644
--- a/core/plug-in/session_timer/UserTimer.h
+++ b/core/plug-in/session_timer/UserTimer.h
@@ -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);

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to