[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "smart-proxy" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Fri Dec 3 09:00:54 CST 2010
branch "smart-proxy" has been updated
via 6c28b354ea95d1722f3643320a3d4054913844fb (commit)
via cf5c0c056f8b62c126dea4087f4c3003e77d08e7 (commit)
via 3f5e6b9888e8a75d3846f191c7cc0cc03a1c59b3 (commit)
via c64f60676cb2cab9f7c94e159a4a3af577e24d1e (commit)
via 016cc138f828cff40f81a2f45247a3de9351886e (commit)
via 9719909659c73691c43007c173a12d193b5927f9 (commit)
via f2da511f5e9c516626fb788254ee3c83d4df1a58 (commit)
from f5e31dfba81ff92cec22ba81e36ff333afd38fa4 (commit)
Summary of changes:
SmartProxy/src/SmartProxy.h | 69 +++++++++++++++++++++++++++++++++---------
1 files changed, 54 insertions(+), 15 deletions(-)
- Log -----------------------------------------------------------------
commit 6c28b354ea95d1722f3643320a3d4054913844fb
Author: David M. Lee <dlee at digium.com>
Date: Thu Dec 2 16:26:28 2010 -0600
Making SmartProxy thread safe.
See CR-ASTSCF-1.
diff --git a/SmartProxy/src/SmartProxy.h b/SmartProxy/src/SmartProxy.h
index 6af5aba..e0443c9 100644
--- a/SmartProxy/src/SmartProxy.h
+++ b/SmartProxy/src/SmartProxy.h
@@ -18,6 +18,7 @@
#include <iostream>
#include <Ice/Ice.h>
+#include <IceUtil/Mutex.h>
#include "Core/Discovery/ServiceLocatorIf.h"
#include "logger.h"
@@ -68,6 +69,7 @@ public:
P& operator->()
{
+ // everything this calls is thread safe. no need to lock.
assert(mServiceLocator && mLocatorParams);
if (!initializeOnce())
@@ -80,6 +82,8 @@ public:
SmartProxy &operator=(const SmartProxy &rhs)
{
+ // copy is thread safe. no need to lock.
+
// Boo to self-assignment
if (this == &rhs)
{
@@ -91,11 +95,13 @@ public:
operator void*() const
{
+ // mProxy itself is thread safe. no need to lock
return mProxy ? (void *)1 : 0;
}
bool isInitialized() const
{
+ // mProxy itself is thread safe. no need to lock
return mProxy != 0;
}
@@ -106,6 +112,9 @@ private:
*/
void initialize()
{
+ // thread safe
+ IceUtil::Mutex::Lock myLock(mMutex);
+
using namespace AsteriskSCF::System::Logging;
if (!mServiceLocator)
{
@@ -156,6 +165,7 @@ private:
*/
bool initializeOnce()
{
+ // isInitialized() and initialize() are thread safe. no need to lock
if (isInitialized())
{
return true;
@@ -168,12 +178,18 @@ private:
void copy(const SmartProxy &rhs)
{
+ // thread safe
+ IceUtil::Mutex::Lock myLock(mMutex);
+ IceUtil::Mutex::Lock rhsLock(rhs.mMutex);
+
mProxy = rhs.mProxy;
mServiceLocator = rhs.mServiceLocator;
mLocatorParams = rhs.mLocatorParams;
mLogger = rhs.mLogger;
}
+ // we want to lock even const instances, so mMutex must be mutable
+ mutable IceUtil::Mutex mMutex;
P mProxy;
AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr mLocatorParams;
commit cf5c0c056f8b62c126dea4087f4c3003e77d08e7
Author: David M. Lee <dlee at digium.com>
Date: Thu Dec 2 16:20:47 2010 -0600
A little const correctness.
diff --git a/SmartProxy/src/SmartProxy.h b/SmartProxy/src/SmartProxy.h
index e295bbb..6af5aba 100644
--- a/SmartProxy/src/SmartProxy.h
+++ b/SmartProxy/src/SmartProxy.h
@@ -94,7 +94,7 @@ public:
return mProxy ? (void *)1 : 0;
}
- bool isInitialized()
+ bool isInitialized() const
{
return mProxy != 0;
}
commit 3f5e6b9888e8a75d3846f191c7cc0cc03a1c59b3
Author: David M. Lee <dlee at digium.com>
Date: Thu Dec 2 15:28:33 2010 -0600
Added some additional null checks.
See CR-ASTSCF-1.
diff --git a/SmartProxy/src/SmartProxy.h b/SmartProxy/src/SmartProxy.h
index 36597f7..e295bbb 100644
--- a/SmartProxy/src/SmartProxy.h
+++ b/SmartProxy/src/SmartProxy.h
@@ -57,6 +57,12 @@ public:
AsteriskSCF::System::Logging::Logger const &lg)
: mServiceLocator(locator), mLocatorParams(params), mLogger(&lg)
{
+ using namespace AsteriskSCF::System::Logging;
+ if (!mLocatorParams)
+ {
+ lg(Error) << "Cannot find service with null parameters";
+ throw AsteriskSCF::Core::Discovery::V1::ServiceNotFound();
+ }
initialize();
}
@@ -108,6 +114,16 @@ private:
return;
}
+ // all paths to set mServiceLocator also set mLogger.
+ // but just in case things change in the future...
+ assert(mLogger);
+
+ if (!mLocatorParams)
+ {
+ (*mLogger)(Error) << "Cannot find service with null parameters";
+ return;
+ }
+
try
{
// Use the locator to find the Proxy
commit c64f60676cb2cab9f7c94e159a4a3af577e24d1e
Author: David M. Lee <dlee at digium.com>
Date: Thu Dec 2 15:27:32 2010 -0600
Removed exception specification. Old Java habits die hard.
See CR-ASTSCF-1.
diff --git a/SmartProxy/src/SmartProxy.h b/SmartProxy/src/SmartProxy.h
index 550425b..36597f7 100644
--- a/SmartProxy/src/SmartProxy.h
+++ b/SmartProxy/src/SmartProxy.h
@@ -60,7 +60,7 @@ public:
initialize();
}
- P& operator->() throw (AsteriskSCF::Core::Discovery::V1::ServiceNotFound)
+ P& operator->()
{
assert(mServiceLocator && mLocatorParams);
commit 016cc138f828cff40f81a2f45247a3de9351886e
Author: David M. Lee <dlee at digium.com>
Date: Thu Dec 2 14:50:34 2010 -0600
Pass Ptr by reference instead of by value.
diff --git a/SmartProxy/src/SmartProxy.h b/SmartProxy/src/SmartProxy.h
index 71c5856..550425b 100644
--- a/SmartProxy/src/SmartProxy.h
+++ b/SmartProxy/src/SmartProxy.h
@@ -53,7 +53,7 @@ public:
SmartProxy(
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& locator,
- AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr params,
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr& params,
AsteriskSCF::System::Logging::Logger const &lg)
: mServiceLocator(locator), mLocatorParams(params), mLogger(&lg)
{
commit 9719909659c73691c43007c173a12d193b5927f9
Author: David M. Lee <dlee at digium.com>
Date: Thu Dec 2 12:53:34 2010 -0600
mLg -> mLogger
The mLg name was carried over from the use of lg as the Logger name when
it's a file scoped variable. But given the scope of this member
variable, mLogger is more appropriate.
See CR-ASTSCF-1.
diff --git a/SmartProxy/src/SmartProxy.h b/SmartProxy/src/SmartProxy.h
index d141d95..71c5856 100644
--- a/SmartProxy/src/SmartProxy.h
+++ b/SmartProxy/src/SmartProxy.h
@@ -44,17 +44,18 @@ template <class P>
class SmartProxy
{
public:
- SmartProxy() : mServiceLocator(0), mLocatorParams(0), mLg(0) {}
+ SmartProxy() : mServiceLocator(0), mLocatorParams(0), mLogger(0) {}
SmartProxy(const SmartProxy &rhs)
{
copy(rhs);
}
- SmartProxy(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& locator,
+ SmartProxy(
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& locator,
AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr params,
AsteriskSCF::System::Logging::Logger const &lg)
- : mServiceLocator(locator), mLocatorParams(params), mLg(&lg)
+ : mServiceLocator(locator), mLocatorParams(params), mLogger(&lg)
{
initialize();
}
@@ -94,7 +95,8 @@ public:
private:
/**
- * Initialization. Primarily involves acquring access to specific IceStorm topic.
+ * Initialization. Primarily involves acquring access to specific IceStorm
+ * topic.
*/
void initialize()
{
@@ -113,18 +115,20 @@ private:
mProxy = P::checkedCast(obj);
if (obj && !mProxy)
{
- (*mLg)(Error) << "Object (" << obj->ice_toString() << ") isn't of expected type";
+ (*mLogger)(Error) << "Object (" << obj->ice_toString()
+ << ") isn't of expected type";
}
}
catch (const Ice::Exception &e)
{
- (*mLg)(Error) << "Exception locating " << mLocatorParams->category << ": " << e.what();
+ (*mLogger)(Error) << "Exception locating "
+ << mLocatorParams->category << ": " << e.what();
return;
}
if (mProxy == 0)
{
- (*mLg)(Error) << "Unable to locate " << mLocatorParams->category;
+ (*mLogger)(Error) << "Unable to locate " << mLocatorParams->category;
}
}
@@ -151,13 +155,13 @@ private:
mProxy = rhs.mProxy;
mServiceLocator = rhs.mServiceLocator;
mLocatorParams = rhs.mLocatorParams;
- mLg = rhs.mLg;
+ mLogger = rhs.mLogger;
}
P mProxy;
AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr mLocatorParams;
- AsteriskSCF::System::Logging::Logger const *mLg;
+ AsteriskSCF::System::Logging::Logger const *mLogger;
};
}; // end SmartProxy
commit f2da511f5e9c516626fb788254ee3c83d4df1a58
Author: David M. Lee <dlee at digium.com>
Date: Thu Dec 2 12:48:39 2010 -0600
verifyInitialize -> initializeOnce
Since the function does more than just verify, it needs a more accurate
name.
diff --git a/SmartProxy/src/SmartProxy.h b/SmartProxy/src/SmartProxy.h
index dd0d8bb..d141d95 100644
--- a/SmartProxy/src/SmartProxy.h
+++ b/SmartProxy/src/SmartProxy.h
@@ -63,7 +63,7 @@ public:
{
assert(mServiceLocator && mLocatorParams);
- if (!verifyInitialized())
+ if (!initializeOnce())
{
throw AsteriskSCF::Core::Discovery::V1::ServiceNotFound();
}
@@ -129,9 +129,12 @@ private:
}
/**
- * Utiltity to check for initialization state.
+ * Initializes this SmartProxy, but only if it hasn't already been
+ * initialized.
+ *
+ * @return True if initialization successful; false if unsuccessful.
*/
- bool verifyInitialized()
+ bool initializeOnce()
{
if (isInitialized())
{
-----------------------------------------------------------------------
--
asterisk-scf/integration/ice-util-cpp.git
More information about the asterisk-scf-commits
mailing list