diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2012-03-23 16:39:43 +0000 |
---|---|---|
committer | Matúš Kukan <matus.kukan@gmail.com> | 2012-07-17 16:39:56 +0200 |
commit | 0dae49a03c9b4816d8cdde69e30bcd2db2e30724 (patch) | |
tree | e27f8759d133152608a45017f2591730a9c5bab5 /tubes | |
parent | c72addf2d5445a86be5307c306002565b43f4dcb (diff) |
tubes: add a shared TeleManager singleton
Yes, this is in addition to the existing TeleManagerImpl singleton. This
class needs to be properly split in half: one Manager part from which
the UI can request new sessions and which signals the appearance of new
incoming sessions, and another Session part representing the shared
editing session (which in turn owns one or more Conferences, which owns
exactly one tube, as now). The Manager will dispatch incoming files to
the appropriate Conference by UUID or similar.
But for now, Michael is opening a new window with the received file,
so we want incoming and outgoing events to go to both windows so that it
works well enough for a demo.
Diffstat (limited to 'tubes')
-rw-r--r-- | tubes/inc/tubes/manager.hxx | 11 | ||||
-rw-r--r-- | tubes/source/manager.cxx | 36 |
2 files changed, 46 insertions, 1 deletions
diff --git a/tubes/inc/tubes/manager.hxx b/tubes/inc/tubes/manager.hxx index f7edbfa2ff84..6d26b0225222 100644 --- a/tubes/inc/tubes/manager.hxx +++ b/tubes/inc/tubes/manager.hxx @@ -80,6 +80,9 @@ public: TeleManager( bool bCreateOwnGMainLoop = false ); ~TeleManager(); + static TeleManager *get(); + void unref(); + /** Prepare the Telepathy Account Manager. Requires connect() to have succeeded. Invokes an async call that is not ready until meAccountManagerStatus is @@ -227,13 +230,19 @@ private: static sal_uInt32 nRefCount; static rtl::OString aNameSuffix; + /* FIXME: double-singletonning is bad. These two are used by ::get and + * ::unref, and are a quick hack so that we can have a demo working. + */ + static TeleManager* pSingleton; + static sal_uInt32 nAnotherRefCount; + TUBES_DLLPRIVATE static ::osl::Mutex& GetAnotherMutex(); + FileReceivedCallback mpFileReceivedCallback; void *mpFileReceivedCallbackData; friend class TeleManagerImpl; // access to mutex TUBES_DLLPRIVATE static ::osl::Mutex& GetMutex(); - }; diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx index 088080d7f1bd..e0e242574bda 100644 --- a/tubes/source/manager.cxx +++ b/tubes/source/manager.cxx @@ -70,6 +70,9 @@ TeleManagerImpl* TeleManager::pImpl = NULL; sal_uInt32 TeleManager::nRefCount = 0; rtl::OString TeleManager::aNameSuffix; +sal_uInt32 TeleManager::nAnotherRefCount = 0; +TeleManager* TeleManager::pSingleton = NULL; + /** Refcounted singleton implementation class. */ class TeleManagerImpl @@ -386,6 +389,27 @@ TeleManager::~TeleManager() } } +TeleManager * +TeleManager::get() +{ + MutexGuard aGuard( GetAnotherMutex()); + if (!pSingleton) + pSingleton = new TeleManager(); + + nAnotherRefCount++; + return pSingleton; +} + +void +TeleManager::unref() +{ + MutexGuard aGuard( GetAnotherMutex()); + if (--nAnotherRefCount == 0) { + delete pSingleton; + pSingleton = NULL; + } +} + bool TeleManager::connect() { @@ -931,6 +955,18 @@ Mutex& TeleManager::GetMutex() return *pMutex; } +Mutex& TeleManager::GetAnotherMutex() +{ + static Mutex* pMutex = NULL; + if (!pMutex) + { + MutexGuard aGuard( Mutex::getGlobalMutex()); + if (!pMutex) + pMutex = new Mutex; + } + return *pMutex; +} + // static void TeleManager::addSuffixToNames( const char* pName ) |