[asterisk-scf-commits] asterisk-scf/release/sip.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Sep 30 13:25:58 CDT 2011


branch "master" has been updated
       via  4558877dfa0be63ee1a06dad330c6a6dda84d147 (commit)
      from  1d5c2ca973d7e766cb128c1aa301757dbfc5c196 (commit)

Summary of changes:
 src/CMakeLists.txt           |    2 +-
 src/Component.cpp            |   93 +++++++++++++++++++++---------------------
 src/PJSipManager.h           |   64 +----------------------------
 src/PJSipRegistrarModule.cpp |   10 +++--
 src/PJSipSessionModule.cpp   |    2 +-
 src/PJSipSessionModule.h     |    7 +--
 6 files changed, 60 insertions(+), 118 deletions(-)


- Log -----------------------------------------------------------------
commit 4558877dfa0be63ee1a06dad330c6a6dda84d147
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Fri Sep 30 13:25:06 2011 -0500

    Use AsteriskSCF::PJLib::ThreadHook for tracking threads created by the Ice
    runtime and by thread pools.
    
    Review: https://code.asterisk.org/code/cru/CR-ASTSCF-168

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 58861aa..5bef902 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -81,7 +81,7 @@ astscf_component_add_ice_libraries(SipSessionManager IceStorm)
 astscf_component_add_boost_libraries(SipSessionManager core)
 astscf_component_add_slice_collection_libraries(SipSessionManager ASTSCF)
 astscf_component_build_icebox(SipSessionManager)
-target_link_libraries(SipSessionManager logging-client astscf-ice-util-cpp ${OPENSSL_LIBRARIES})
+target_link_libraries(SipSessionManager logging-client astscf-ice-util-cpp astscf-ice-util-cpp-pjlib ${OPENSSL_LIBRARIES})
 
 pjproject_link(SipSessionManager pjsip)
 pjproject_link(SipSessionManager pjmedia)
diff --git a/src/Component.cpp b/src/Component.cpp
index 77b835b..1d63c04 100644
--- a/src/Component.cpp
+++ b/src/Component.cpp
@@ -32,6 +32,7 @@
 #include <AsteriskSCF/Logger/IceLogger.h>
 #include <AsteriskSCF/logger.h>
 #include <AsteriskSCF/Component/Component.h>
+#include <AsteriskSCF/PJLib/ThreadHook.h>
 #include <AsteriskSCF/Replication/ReplicationContext.h>
 
 #include "SipSessionManagerEventPublisher.h"
@@ -78,7 +79,7 @@ public:
         : mPJSipManager(manager)
     {
     }
-    
+
     void addAuthHook(
             const AuthHookPrx &hook,
             int priority,
@@ -87,12 +88,12 @@ public:
     {
         mPJSipManager->addAuthHook(hook, priority, requestTypes);
     }
-    
+
     void removeAuthHook(const AuthHookPrx &hook, const Ice::Current&)
     {
         mPJSipManager->removeAuthHook(hook);
     }
-    
+
     void clearAuthHooks(const Ice::Current&)
     {
         mPJSipManager->clearAuthHooks();
@@ -110,7 +111,7 @@ typedef IceUtil::Handle<SipAuthExtensionPoint> SipAuthExtensionPointPtr;
 class Component : public AsteriskSCF::Component::Component
 {
 public:
-    Component() 
+    Component()
         :  AsteriskSCF::Component::Component(lg, ComponentServiceDiscoveryCategory),
            mListeningToReplicator(false)
     {
@@ -138,10 +139,10 @@ private:
     virtual void createBackplaneServices();
     virtual void prepareBackplaneServicesForDiscovery();
     virtual ReplicationContextPtr createReplicationContext(ReplicationStateType state);
-    virtual void unregisterFromRemoteServices();    
+    virtual void unregisterFromRemoteServices();
     virtual void registerWithRemoteServices();
 
-    // Our own implementation operations. 
+    // Our own implementation operations.
     void registerWithRoutingService();
     void unregisterFromRoutingService();
 
@@ -155,11 +156,11 @@ private:
 
     bool mListeningToReplicator;
 
-    // Unique Id for this component's EndpointLocator. 
-    // Used when registering with routing service. 
+    // Unique Id for this component's EndpointLocator.
+    // Used when registering with routing service.
     std::string mRoutingId;
 
-    // Configuration 
+    // Configuration
     LocatorRegistrationWrapperPtr mConfigurationRegistration;
     ConfigurationServicePtr mConfigurationService;
     ConfigurationServicePrx mConfigurationServiceProxy;
@@ -193,7 +194,7 @@ static const string AuthServiceId("SipAuthExtensionPoint");
 static const string RegistrarListenerId("SipRegistrarListener");
 
 /**
- * Override of factory method to create our custom replication context. 
+ * Override of factory method to create our custom replication context.
  */
 ReplicationContextPtr Component::createReplicationContext(ReplicationStateType state)
 {
@@ -210,13 +211,13 @@ void Component::preparePrimaryServicesForDiscovery()
     try
     {
         // Wrap our authentication extensions point for the Service Locator.
-        mAuthExtensionRegistration = wrapServiceForRegistration(mAuthExtensionPrx, 
+        mAuthExtensionRegistration = wrapServiceForRegistration(mAuthExtensionPrx,
                                                                  AsteriskSCF::SIP::V1::AuthExtensionPointCategory);
         managePrimaryService(mAuthExtensionRegistration);
     }
     catch(const std::exception& e)
     {
-        lg(Error) << "Unable to publish component interfaces in " << getName() << BOOST_CURRENT_FUNCTION << 
+        lg(Error) << "Unable to publish component interfaces in " << getName() << BOOST_CURRENT_FUNCTION <<
             ". Exception: " << e.what();
         throw; // rethrow
     }
@@ -227,13 +228,13 @@ void Component::preparePrimaryServicesForDiscovery()
  */
 void Component::prepareBackplaneServicesForDiscovery()
 {
-    // Insure the default Component services are prepped. 
+    // Insure the default Component services are prepped.
     AsteriskSCF::Component::Component::prepareBackplaneServicesForDiscovery();
 
     try
     {
         // Wrap our configuration interface for the Service Locator.
-        mConfigurationRegistration = wrapServiceForRegistration(mConfigurationServiceProxy, 
+        mConfigurationRegistration = wrapServiceForRegistration(mConfigurationServiceProxy,
                                                                 ConfigurationDiscoveryCategory);
         manageBackplaneService(mConfigurationRegistration);
     }
@@ -276,13 +277,13 @@ void Component::locateStateReplicator()
     try
     {
         AsteriskSCF::Discovery::SmartProxy<SipStateReplicatorPrx> pw(getServiceLocator(), replicatorParams, lg);
-        SipReplicationContextPtr sipReplicationContext = 
+        SipReplicationContextPtr sipReplicationContext =
             boost::static_pointer_cast<SipReplicationContext>(getReplicationContext());
 
         sipReplicationContext->setReplicator(pw);
 
         // Since we're not in standalone mode, we'll get our configuration updates routed via the
-        // replicator service. 
+        // replicator service.
 	    ConfigurationReplicatorPrx configurationReplicator = ConfigurationReplicatorPrx::checkedCast(
             sipReplicationContext->getReplicator().initialize(), ReplicatorFacet);
 	    configurationReplicator->registerConfigurationService(mConfigurationServiceProxy);
@@ -295,7 +296,7 @@ void Component::locateStateReplicator()
 
 void Component::listenToStateReplicators()
 {
-    SipReplicationContextPtr sipReplicationContext = 
+    SipReplicationContextPtr sipReplicationContext =
         boost::static_pointer_cast<SipReplicationContext>(getReplicationContext());
 
     if (mListeningToReplicator == true)
@@ -325,14 +326,14 @@ void Component::listenToStateReplicators()
     }
 }
 
-/** 
- * Unregister as a listener to our state replicator. 
+/**
+ * Unregister as a listener to our state replicator.
  * A component in active mode doesn't neeed to listen to
- * state replication data. 
+ * state replication data.
  */
 void Component::stopListeningToStateReplicators()
 {
-    SipReplicationContextPtr sipReplicationContext = 
+    SipReplicationContextPtr sipReplicationContext =
         boost::static_pointer_cast<SipReplicationContext>(getReplicationContext());
 
     if ((!sipReplicationContext->getReplicator().isInitialized()) || (mListeningToReplicator == false))
@@ -368,7 +369,7 @@ void Component::locateSessionRouter()
 
 void Component::registerPJSipModules()
 {
-    SipReplicationContextPtr sipReplicationContext = 
+    SipReplicationContextPtr sipReplicationContext =
         boost::static_pointer_cast<SipReplicationContext>(getReplicationContext());
 
     Ice::PropertiesPtr props = getCommunicator()->getProperties();
@@ -384,10 +385,10 @@ void Component::registerPJSipModules()
         if ((*i) == "Session")
         {
             mPJSipManager->registerSessionModule(mEndpointFactory,
-                mSessionRouter, 
-                getServiceLocator(), 
-                sipReplicationContext, 
-                getServiceAdapter(), 
+                mSessionRouter,
+                getServiceLocator(),
+                sipReplicationContext,
+                getServiceAdapter(),
                 getServiceLocatorManagement());
         }
         else if ((*i) == "Logging" || (*i) == "Logger")
@@ -396,8 +397,8 @@ void Component::registerPJSipModules()
         }
         else if (*i == "Registrar")
         {
-            mPJSipManager->registerRegistrarModule(mDefaultRegistrarListenerPrx, 
-                                                   sipReplicationContext, 
+            mPJSipManager->registerRegistrarModule(mDefaultRegistrarListenerPrx,
+                                                   sipReplicationContext,
                                                    getServiceAdapter());
         }
     }
@@ -407,14 +408,14 @@ void Component::registerPJSipModules()
 /**
  * Pre-init notification from the base component. Allows us
  * to initialize things before the base component does anything
- * else. 
+ * else.
  */
 void Component::onPreInitialize()
 {
     try
     {
         // Initialize PJSIP
-        // NOTE: Should use PJSipManager::create now. 
+        // NOTE: Should use PJSipManager::create now.
         mPJSipManager = PJSipManager::create(getName(), getCommunicator()->getProperties());
         lg(Debug) << "Created PJSIP manager";
 
@@ -422,7 +423,7 @@ void Component::onPreInitialize()
         //we're going to create our own so that we can provide it with a threadhook.
         //Yes, this could be done via a plugin, but this is easier. Go away.
         Ice::InitializationData id;
-        id.threadHook = new pjlibHook();
+        id.threadHook = new AsteriskSCF::PJLib::ThreadHook("Ice");
         id.properties = getCommunicator()->getProperties();
 
         setCommunicator(Ice::initialize(id));
@@ -474,9 +475,9 @@ void Component::unregisterFromRoutingService()
 /**
  * This operation is called by the base Component class
  * at times such as activation, or resumed, to allow us to
- * add our own proxies with remote services. 
+ * add our own proxies with remote services.
  */
-void Component::registerWithRemoteServices() 
+void Component::registerWithRemoteServices()
 {
     // Register our Endpoint Locator so that we can provide endpoints to the
     // Routing Service for the endpoints we manage.
@@ -486,9 +487,9 @@ void Component::registerWithRemoteServices()
 /**
  * This operation is called by the base Component class
  * at times such as standy, or paused, to allow us to
- * remove our own proxies from remote services. 
+ * remove our own proxies from remote services.
  */
-void Component::unregisterFromRemoteServices() 
+void Component::unregisterFromRemoteServices()
 {
     unregisterFromRoutingService();
 }
@@ -496,7 +497,7 @@ void Component::unregisterFromRemoteServices()
 /**
  * Post-init notification from the base component. Allows us
  * to initialize things after the base component does common
- * initialization. 
+ * initialization.
  */
 void Component::onPostInitialize()
 {
@@ -511,26 +512,26 @@ void Component::onPostInitialize()
 }
 
 /**
- * Create the objects that implement the main services this component provides 
+ * Create the objects that implement the main services this component provides
  * the system.
  */
 void Component::createPrimaryServices()
 {
     try
     {
-        SipReplicationContextPtr sipReplicationContext = 
+        SipReplicationContextPtr sipReplicationContext =
             boost::static_pointer_cast<SipReplicationContext>(getReplicationContext());
 
         mEventPublisher.reset(new SipSessionManagerEventPublisher(getServiceAdapter()));
         lg(Debug) << "Created SIP Session Manager event publisher";
 
-        mEndpointFactory.reset(new SipEndpointFactory(getServiceAdapter(), 
+        mEndpointFactory.reset(new SipEndpointFactory(getServiceAdapter(),
                mPJSipManager, getServiceLocator(), sipReplicationContext));
         lg(Debug) << "Created SIP endpoint factory";
 
 	    // Locate the Routing Service so that we can do routing. This is done here so it can be
-        // passed to the configuration service. 
-        // (NOTE: I suspect that since we're using a smart pointer, 
+        // passed to the configuration service.
+        // (NOTE: I suspect that since we're using a smart pointer,
         // this could be deferred to findRemoteServices)
 	    locateRoutingService();
 
@@ -545,7 +546,7 @@ void Component::createPrimaryServices()
             getServiceAdapter()->add(mDefaultRegistrarListener, getCommunicator()->stringToIdentity(RegistrarListenerId)));
         lg(Debug) << "Added default registrar listener to object adapter";
 
-        // Create our SipAuthExtensionPoint servant. 
+        // Create our SipAuthExtensionPoint servant.
         mAuthExtension = new SipAuthExtensionPoint(mPJSipManager);
         mAuthExtensionPrx = AuthExtensionPointPrx::uncheckedCast(
              getServiceAdapter()->add(mAuthExtension, getCommunicator()->stringToIdentity(AuthServiceId)));
@@ -560,7 +561,7 @@ void Component::createPrimaryServices()
 
 void Component::createBackplaneServices()
 {
-    // Include the base Component services. 
+    // Include the base Component services.
     AsteriskSCF::Component::Component::createBackplaneServices();
 
     try
@@ -591,7 +592,7 @@ void Component::createReplicationStateListeners()
         SipStateReplicatorListenerPrx replicatorListener = SipStateReplicatorListenerPrx::uncheckedCast(
              getBackplaneAdapter()->addWithUUID(mReplicatorListener));
         mReplicatorListenerProxy = SipStateReplicatorListenerPrx::uncheckedCast(replicatorListener->ice_oneway());
-            
+
         lg(Debug) << "Got proxy to SIP state replicator";
     }
     catch(const Ice::Exception &e)
@@ -601,7 +602,7 @@ void Component::createReplicationStateListeners()
     }
 }
 
-void Component::findRemoteServices() 
+void Component::findRemoteServices()
 {
     // Locate the Session Router so we can REALLY do routing.
     locateSessionRouter();
@@ -611,7 +612,7 @@ void Component::findRemoteServices()
 }
 
 /**
- * Notification from the component that we're stopping. 
+ * Notification from the component that we're stopping.
  */
 void Component::onStop()
 {
diff --git a/src/PJSipManager.h b/src/PJSipManager.h
index 9f70907..c7f0477 100644
--- a/src/PJSipManager.h
+++ b/src/PJSipManager.h
@@ -75,7 +75,7 @@ public:
     PJSipLoggingModulePtr getLoggingModule();
 
     pj_caching_pool* getCachingPool();
-    
+
     pj_pool_t* getMemoryPool();
 
     /**
@@ -120,7 +120,7 @@ public:
     // PJSipManager does not need it.
     //
     /**
-     * Add a transport the module. 
+     * Add a transport the module.
      **/
     void addTransport(const std::string& id, const TransportPtr& transport);
     TransportPtr getTransport(const std::string& id);
@@ -146,66 +146,6 @@ private:
     PJSipManager();
 };
 
-/**
- * Wrapper class around pj_thread_desc.
- */
-class ThreadDescWrapper
-{
-public:
-    /**
-     * pjthread thread description information, must persist for the life of the thread
-     */
-    pj_thread_desc mDesc;
-};
-
-/**
- * Type definition used to create a smart pointer for the above.
- */
-typedef boost::shared_ptr<ThreadDescWrapper> ThreadDescWrapperPtr;
-
-/**
- * Implementation of the Ice::ThreadNotification class.
- */
-class pjlibHook : public Ice::ThreadNotification
-{
-public:
-    /**
-     * Implementation of the start function which is called when a thread starts.
-     */
-    void start()
-    {
-        ThreadDescWrapperPtr wrapper = ThreadDescWrapperPtr(new ThreadDescWrapper());
-        pj_thread_t *thread;
-        pj_thread_register("ICE Thread", wrapper->mDesc, &thread);
-        {
-            boost::lock_guard<boost::mutex> lock(mLock);
-            pjThreads.insert(std::make_pair(thread, wrapper));
-        }
-    }
-
-    /**
-     * Implementation of the stop function which is called when a thread stops.
-     */
-    void stop()
-    {
-        if (pj_thread_is_registered())
-        {
-            boost::lock_guard<boost::mutex> lock(mLock);
-            pjThreads.erase(pj_thread_this());
-        }
-    }
-
-private:
-    /**
-     * A map containing thread lifetime persistent data.
-     */
-    std::map<pj_thread_t*, ThreadDescWrapperPtr> pjThreads;
-    /**
-     * Mutex to protect the map
-     */
-    boost::mutex mLock;
-};
-
 }; //End namespace SipSessionManager
 
 }; //End namespace AsteriskSCF
diff --git a/src/PJSipRegistrarModule.cpp b/src/PJSipRegistrarModule.cpp
index 837c03b..d3eae84 100644
--- a/src/PJSipRegistrarModule.cpp
+++ b/src/PJSipRegistrarModule.cpp
@@ -19,6 +19,7 @@
 #include <AsteriskSCF/System/WorkQueue/WorkQueueIf.h>
 #include <AsteriskSCF/WorkQueue/WorkQueue.h>
 #include <AsteriskSCF/WorkQueue/DefaultQueueListener.h>
+#include <AsteriskSCF/PJLib/ThreadHook.h>
 
 #include "PJSipRegistrarModule.h"
 #include "PJSipManager.h"
@@ -144,7 +145,8 @@ RegistrarI::RegistrarI(const RegistrarListenerPrx& defaultListener)
 {
     lg(Debug) << "In RegistrarI constructor, should be adding a listener...";
     mQueue = new AsteriskSCF::WorkQueue::WorkQueue();
-    AsteriskSCF::WorkQueue::DefaultQueueListenerPtr listener(new AsteriskSCF::WorkQueue::DefaultQueueListener(mQueue, new pjlibHook()));
+    AsteriskSCF::WorkQueue::DefaultQueueListenerPtr listener(new AsteriskSCF::WorkQueue::DefaultQueueListener(mQueue,
+	    new AsteriskSCF::PJLib::ThreadHook("SIP Registrar Module Pool")));
     mQueue->setListener(listener);
     mListeners.push_back(defaultListener);
 }
@@ -168,7 +170,7 @@ public:
             const RegistrarListenerPrx& listener,
             const RegistrarIPtr& registrar)
         : mCB(cb), mListener(listener), mRegistrar(registrar) { }
-    
+
     void execute()
     {
         std::vector<AsteriskSCF::SIP::Registration::V1::RegistrarListenerPrx>& listeners(mRegistrar->getListeners());
@@ -410,7 +412,7 @@ public:
                 items.push_back(newItem);
                 mReplicationContext->getReplicator().tryOneWay()->setState(items);
             }
-            
+
             if (!mExistingBindings.empty())
             {
                 BindingDict existingDict = mRegistrar->createBindingDict(mAOR, mExistingBindings);
@@ -458,7 +460,7 @@ void PJSipRegistrarModule::replicateState(
 }
 
 //XXX This and the method that queues this work should
-//have different names. It's easy to get confused with 
+//have different names. It's easy to get confused with
 //UpdateBinding, and this could stand to be more descriptive
 class AddAndRemoveBindings : public Work
 {
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 500acbe..4a08875 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -1651,7 +1651,7 @@ void PJSipSessionModule::enqueueSessionWork(const SuspendableWorkPtr& work, pjsi
 }
 
 PJSipSessionModuleThreadPoolListener::PJSipSessionModuleThreadPoolListener()
-    : mActiveThreads(0), mPjLibHook(new pjlibHook()) { }
+    : mActiveThreads(0), mPjLibHook(new AsteriskSCF::PJLib::ThreadHook("SIP Session Module Pool")) { }
 
 void PJSipSessionModuleThreadPoolListener::stateChanged(const PoolPtr& pool, Ice::Long active, Ice::Long idle, Ice::Long)
 {
diff --git a/src/PJSipSessionModule.h b/src/PJSipSessionModule.h
index e641f28..9305f0f 100644
--- a/src/PJSipSessionModule.h
+++ b/src/PJSipSessionModule.h
@@ -26,6 +26,7 @@
 #include <AsteriskSCF/Discovery/SmartProxy.h>
 #include <AsteriskSCF/System/ThreadPool/ThreadPoolIf.h>
 #include <AsteriskSCF/System/WorkQueue/WorkQueueIf.h>
+#include <AsteriskSCF/PJLib/ThreadHook.h>
 
 #include "SipEndpointFactory.h"
 #include "SipReplicationContext.h"
@@ -58,8 +59,6 @@ private:
     SessionWorkPtr mSessionWork;
 };
 
-class pjlibHook;
-
 /**
  * Listens to the PJSipSessionModule's thread pool.
  *
@@ -77,7 +76,7 @@ public:
     void threadStop();
 private:
     Ice::Long mActiveThreads;
-    pjlibHook *mPjLibHook;
+    AsteriskSCF::PJLib::ThreadHook *mPjLibHook;
 };
 
 typedef IceUtil::Handle<PJSipSessionModuleThreadPoolListener> PJSipSessionModuleThreadPoolListenerPtr;
@@ -136,7 +135,7 @@ public:
             pjsip_inv_session *);
 
     AsteriskSCF::System::WorkQueue::V1::QueuePtr getThreadPoolQueue();
-    
+
     AsteriskSCF::SessionCommunications::ExtensionPoints::V1::SessionCreationHookSeq getSessionCreationHooks();
 
 private:

-----------------------------------------------------------------------


-- 
asterisk-scf/release/sip.git



More information about the asterisk-scf-commits mailing list