[asterisk-scf-commits] asterisk-scf/release/media_rtp_pjmedia.git branch "master" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Fri Sep 30 13:26:57 CDT 2011
branch "master" has been updated
via a6641628f49f2554a7663c7d807dc4680f79519d (commit)
from 9cbd638d2c5620be9c1822374024b07705d4b268 (commit)
Summary of changes:
src/CMakeLists.txt | 2 +-
src/Component.cpp | 164 ++++++++++++++++------------------------------------
2 files changed, 51 insertions(+), 115 deletions(-)
- Log -----------------------------------------------------------------
commit a6641628f49f2554a7663c7d807dc4680f79519d
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Fri Sep 30 13:26:09 2011 -0500
Use AsteriskSCF::PJLib::ThreadHook for tracking threads created by the
Ice runtime.
Review: https://code.asterisk.org/code/cru/CR-ASTSCF-168
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d130546..10fee6a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -49,7 +49,7 @@ astscf_component_add_slices(media_rtp_pjmedia PROJECT AsteriskSCF/Configuration/
astscf_component_add_boost_libraries(media_rtp_pjmedia core thread)
astscf_component_add_slice_collection_libraries(media_rtp_pjmedia ASTSCF)
astscf_component_build_icebox(media_rtp_pjmedia)
-target_link_libraries(media_rtp_pjmedia logging-client astscf-ice-util-cpp)
+target_link_libraries(media_rtp_pjmedia logging-client astscf-ice-util-cpp astscf-ice-util-cpp-pjlib)
pjproject_link(media_rtp_pjmedia pjlib)
pjproject_link(media_rtp_pjmedia pjlib-util)
diff --git a/src/Component.cpp b/src/Component.cpp
index 2b4b3a2..abfea53 100644
--- a/src/Component.cpp
+++ b/src/Component.cpp
@@ -31,6 +31,7 @@
#include <AsteriskSCF/logger.h>
#include <AsteriskSCF/Discovery/SmartProxy.h>
#include <AsteriskSCF/Component/Component.h>
+#include <AsteriskSCF/PJLib/ThreadHook.h>
#include "RtpReplicationContext.h"
#include "RTPSession.h"
@@ -67,7 +68,7 @@ static const string MediaComparatorServiceId("RTPMediaServiceComparator");
class RTPMediaServiceImpl : public RTPMediaService
{
public:
- RTPMediaServiceImpl(const Ice::ObjectAdapterPtr&,
+ RTPMediaServiceImpl(const Ice::ObjectAdapterPtr&,
const RtpReplicationContextPtr& replicationContext,
const ConfigurationServiceImplPtr&);
@@ -138,7 +139,7 @@ public:
{
return false;
}
-
+
RTPOverICEServiceLocatorParamsPtr iceParams = RTPOverICEServiceLocatorParamsPtr::dynamicCast(locatorParams);
if (iceParams)
{
@@ -176,13 +177,13 @@ private:
};
/**
- * Implementation of the Component class.
+ * Implementation of the Component class.
*/
class Component : public AsteriskSCF::Component::Component
{
public:
- Component() :
- AsteriskSCF::Component::Component(lg, AsteriskSCF::Media::RTP::V1::ComponentServiceDiscoveryCategory),
+ Component() :
+ AsteriskSCF::Component::Component(lg, AsteriskSCF::Media::RTP::V1::ComponentServiceDiscoveryCategory),
mListeningToReplicator(false), mGeneralState(new RtpGeneralStateItem()) { mGeneralState->key = IceUtil::generateUUID(); };
private:
@@ -199,7 +200,7 @@ private:
virtual void onSuspend();
virtual void onResume();
virtual void onPreInitialize();
- virtual void onStop();
+ virtual void onStop();
virtual void onStart();
// Other base Component overrides
@@ -223,93 +224,35 @@ private:
LocatorRegistrationWrapperPtr mRtpMediaServiceRegistration;
// Media comparator service
- ServiceLocatorParamsComparePtr mRtpMediaComparatorService;
+ ServiceLocatorParamsComparePtr mRtpMediaComparatorService;
ServiceLocatorParamsComparePrx mRtpMediaComparatorServicePrx;
RTPOverICEServiceLocatorParamsPtr mRtpOverIceLocatorParams;
- // Configuration state
+ // Configuration state
ConfigurationServiceImplPtr mConfigurationService;
ConfigurationServicePrx mConfigurationServicePrx;
LocatorRegistrationWrapperPtr mConfigurationRegistration;
};
-void Component::onSuspend()
+void Component::onSuspend()
{
mGeneralState->serviceManagement->suspend();
}
-void Component::onResume()
+void Component::onResume()
{
mGeneralState->serviceManagement->unsuspend();
}
/**
- * 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(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.
- */
- map<pj_thread_t*, ThreadDescWrapperPtr> pjThreads;
-
- /**
- * Mutex to protect the map
- */
- boost::mutex mLock;
-};
-
-/**
* Constructor for the RTPMediaServiceImpl class.
*/
RTPMediaServiceImpl::RTPMediaServiceImpl(const Ice::ObjectAdapterPtr& adapter,
const RtpReplicationContextPtr& replicationContext,
const ConfigurationServiceImplPtr& configurationService) :
- mAdapter(adapter),
+ mAdapter(adapter),
mEnvironment(PJMediaEnvironment::create(adapter->getCommunicator()->getProperties(), configurationService)),
- mReplicationContext(replicationContext),
+ mReplicationContext(replicationContext),
mConfigurationService(configurationService)
{
}
@@ -334,35 +277,28 @@ RTPSessionPrx RTPMediaServiceImpl::allocate(
outputs);
}
-void Component::onPreInitialize()
+void Component::onPreInitialize()
{
- /* Initialize pjlib as pjmedia will be using it */
- pj_status_t status = pj_init();
- if (status != PJ_SUCCESS)
+ try
{
- lg(Error) << "PJ library initialization failed.";
- return;
- }
+ lg(Info) << "Initializing pjmedia rtp component" << endl;
+
+ Ice::InitializationData id;
+ id.threadHook = new AsteriskSCF::PJLib::ThreadHook("Ice");
+ id.properties = getCommunicator()->getProperties();
- if ((status = pjlib_util_init()) != PJ_SUCCESS)
+ // To use our thread-hook, we need to set an alternate
+ // communicator in our Component base.
+ setCommunicator(Ice::initialize(id));
+ }
+ catch(const std::exception& e)
{
- lg(Error) << "PJ Utility library initialization failed.";
- return;
+ lg(Critical) << "Major problems in " << getName() << " initialization: " << e.what();
}
-
- lg(Info) << "Initializing pjmedia rtp component" << endl;
-
- Ice::InitializationData id;
- id.threadHook = new pjlibHook();
- id.properties = getCommunicator()->getProperties();
-
- // To use our thread-hook, we need to set an alternate
- // communicator in our Component base.
- setCommunicator(Ice::initialize(id));
}
/**
- * 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)
{
@@ -371,14 +307,14 @@ ReplicationContextPtr Component::createReplicationContext(ReplicationStateType s
}
/**
- * 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
{
- RtpReplicationContextPtr rtpReplicationContext =
+ RtpReplicationContextPtr rtpReplicationContext =
boost::static_pointer_cast<RtpReplicationContext>(getReplicationContext());
mConfigurationService = ConfigurationServiceImpl::create();
@@ -391,7 +327,7 @@ void Component::createPrimaryServices()
mRtpMediaComparatorService = new RTPMediaServiceCompareServiceImpl(mConfigurationService);
mRtpMediaComparatorServicePrx = ServiceLocatorParamsComparePrx::uncheckedCast(
- getServiceAdapter()->add(mRtpMediaComparatorService,
+ getServiceAdapter()->add(mRtpMediaComparatorService,
getCommunicator()->stringToIdentity(MediaComparatorServiceId)));
@@ -423,7 +359,7 @@ void Component::createPrimaryServices()
mGeneralState->comparatorId = IceUtil::generateUUID();
getServiceLocatorManagement()->addCompare(mGeneralState->comparatorId, mRtpMediaComparatorServicePrx);
}
-
+
}
catch(const Ice::Exception& e)
{
@@ -437,13 +373,13 @@ void Component::createPrimaryServices()
*/
void Component::prepareBackplaneServicesForDiscovery()
{
- // Insure the default Component services are prepped.
+ // Insure the default Component services are prepped.
AsteriskSCF::Component::Component::prepareBackplaneServicesForDiscovery();
try
{
// Register our configuration interface with the Service Locator.
- mConfigurationRegistration = wrapServiceForRegistration(mConfigurationServicePrx,
+ mConfigurationRegistration = wrapServiceForRegistration(mConfigurationServicePrx,
ConfigurationDiscoveryCategory);
manageBackplaneService(mConfigurationRegistration);
}
@@ -453,7 +389,7 @@ void Component::prepareBackplaneServicesForDiscovery()
}
}
-void Component::findRemoteServices()
+void Component::findRemoteServices()
{
if (getReplicationContext()->getState() == ACTIVE_STANDALONE)
{
@@ -468,14 +404,14 @@ void Component::findRemoteServices()
try
{
- RtpReplicationContextPtr rtpReplicationContext =
+ RtpReplicationContextPtr rtpReplicationContext =
boost::static_pointer_cast<RtpReplicationContext>(getReplicationContext());
AsteriskSCF::Discovery::SmartProxy<RtpStateReplicatorPrx> pw(getServiceLocator(), replicatorParams, lg);
rtpReplicationContext->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(
rtpReplicationContext->getReplicator().initialize(), ReplicatorFacet);
configurationReplicator->registerConfigurationService(mConfigurationServicePrx);
@@ -491,7 +427,7 @@ void Component::createReplicationStateListeners()
{
try
{
- RtpReplicationContextPtr rtpReplicationContext =
+ RtpReplicationContextPtr rtpReplicationContext =
boost::static_pointer_cast<RtpReplicationContext>(getReplicationContext());
// Create and publish our state replicator listener interface.
@@ -500,7 +436,7 @@ void Component::createReplicationStateListeners()
RtpStateReplicatorListenerPrx replicatorListener = RtpStateReplicatorListenerPrx::uncheckedCast(
getBackplaneAdapter()->addWithUUID(mReplicatorListener));
mReplicatorListenerProxy = RtpStateReplicatorListenerPrx::uncheckedCast(replicatorListener->ice_oneway());
-
+
lg(Debug) << "Got proxy to RTP state replicator";
}
catch(const Ice::Exception &e)
@@ -512,7 +448,7 @@ void Component::createReplicationStateListeners()
void Component::listenToStateReplicators()
{
- RtpReplicationContextPtr rtpReplicationContext =
+ RtpReplicationContextPtr rtpReplicationContext =
boost::static_pointer_cast<RtpReplicationContext>(getReplicationContext());
if (mListeningToReplicator == true)
@@ -542,14 +478,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()
{
- RtpReplicationContextPtr rtpReplicationContext =
+ RtpReplicationContextPtr rtpReplicationContext =
boost::static_pointer_cast<RtpReplicationContext>(getReplicationContext());
if ((!rtpReplicationContext->getReplicator().isInitialized()) || (mListeningToReplicator == false))
@@ -579,11 +515,11 @@ void Component::preparePrimaryServicesForDiscovery()
{
mRtpMediaServiceRegistration = wrapServiceForRegistration(mRtpMediaServicePrx,
"rtp");
- managePrimaryService(mRtpMediaServiceRegistration);
+ managePrimaryService(mRtpMediaServiceRegistration);
}
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
}
@@ -600,15 +536,15 @@ void Component::onRegisterPrimaryServices()
mGeneralState->serviceManagement->addLocatorParams(mRtpOverIceLocatorParams, mGeneralState->comparatorId);
}
-void Component::onStart()
+void Component::onStart()
{
- // Note: I don't think this is necessary. If we make the
+ // Note: I don't think this is necessary. If we make the
// comparator computed from a "service" identifier (which could default
// to "default"), there's nothing replicated here that the standby component
- // couldn't already determine itself.
+ // couldn't already determine itself.
if (getReplicationContext()->isReplicating() == true)
{
- RtpReplicationContextPtr rtpReplicationContext =
+ RtpReplicationContextPtr rtpReplicationContext =
boost::static_pointer_cast<RtpReplicationContext>(getReplicationContext());
RtpStateItemSeq items;
@@ -618,7 +554,7 @@ void Component::onStart()
}
}
-void Component::onStop()
+void Component::onStop()
{
if (getReplicationContext()->isActive() == true)
{
-----------------------------------------------------------------------
--
asterisk-scf/release/media_rtp_pjmedia.git
More information about the asterisk-scf-commits
mailing list