summaryrefslogtreecommitdiff
path: root/tubes
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@gmail.com>2012-08-15 14:10:22 +0200
committerMatúš Kukan <matus.kukan@gmail.com>2012-08-16 11:41:51 +0200
commit766a0247fc3ac49b25aab69948e4d0a5df334ff9 (patch)
treed94ac9ded910f4437201a6fb9b9cffb09f6a20ab /tubes
parentbd465b57caf1bf5eba04c37a2095e902c8b4e4f9 (diff)
tubes: also prepare the Account Manager when creating; and simplify
Change-Id: I7705d627d17f20c3c81de7aa4debbefc127354b0
Diffstat (limited to 'tubes')
-rw-r--r--tubes/inc/tubes/manager.hxx27
-rw-r--r--tubes/qa/test_manager.cxx11
-rw-r--r--tubes/source/contact-list.cxx23
-rw-r--r--tubes/source/manager.cxx99
4 files changed, 44 insertions, 116 deletions
diff --git a/tubes/inc/tubes/manager.hxx b/tubes/inc/tubes/manager.hxx
index 38e5d8cdca14..06f682d0e51b 100644
--- a/tubes/inc/tubes/manager.hxx
+++ b/tubes/inc/tubes/manager.hxx
@@ -57,16 +57,8 @@ class TeleManager
{
TeleManager();
~TeleManager();
-public:
-
- enum AccountManagerStatus
- {
- AMS_UNINITIALIZED = 0,
- AMS_INPREPARATION,
- AMS_UNPREPARABLE,
- AMS_PREPARED
- };
+public:
/** Prepare tube manager with account and service to be offered/listened
to.
*/
@@ -80,23 +72,12 @@ public:
/** Get a conference with current UUID to set a session. */
TUBES_DLLPUBLIC static TeleConference* getConference();
- /** Connect to DBus and create AccountManager. */
+ /** Connect to DBus, create and prepare the Telepathy Account Manager. */
static bool createAccountManager();
/** Setup client handlers. */
static bool registerClients();
- /** Prepare the Telepathy Account Manager.
- Requires createAccountManager() to have succeeded.
-
- Invokes an async call that is not ready until meAccountManagerStatus is
- set! Until that is AMS_PREPARED nothing else will work.
-
- TODO: this needs some signalling mechanism
- */
- static void prepareAccountManager();
- static AccountManagerStatus getAccountManagerStatus();
-
/** Fetches the contact list. Returns 0 before connect() is called successfully.
Is non-functional until prepareAccountManager().
*/
@@ -151,12 +132,10 @@ public:
static void addConference( TeleConference* pConference );
static void setChannelReadyHandlerInvoked( bool b );
static bool isChannelReadyHandlerInvoked();
+ static void setAccountManagerReady( bool bPrepared);
static void setAccountManagerReadyHandlerInvoked( bool b );
static bool isAccountManagerReadyHandlerInvoked();
- /** Only the callback of prepareAccountManager() is to set this. */
- static void setAccountManagerReady( bool bPrepared);
-
/// "LibreOfficeWhatEver"
static rtl::OString getFullClientName();
diff --git a/tubes/qa/test_manager.cxx b/tubes/qa/test_manager.cxx
index 00ce9e5c8488..76f093c748b7 100644
--- a/tubes/qa/test_manager.cxx
+++ b/tubes/qa/test_manager.cxx
@@ -55,7 +55,6 @@ public:
void testCreateAccountManager();
void testRegisterClients();
void testContactList();
- void testPrepareAccountManager();
void testStartBuddySession();
void testSendPacket();
void testReceivePacket();
@@ -70,7 +69,6 @@ public:
CPPUNIT_TEST( testInitialize );
CPPUNIT_TEST( testCreateAccountManager );
CPPUNIT_TEST( testRegisterClients );
- CPPUNIT_TEST( testPrepareAccountManager );
CPPUNIT_TEST( testContactList );
CPPUNIT_TEST( testStartBuddySession );
CPPUNIT_TEST( testSendPacket );
@@ -129,8 +127,6 @@ void TestTeleTubes::testInitialize()
void TestTeleTubes::testContactList()
{
- CPPUNIT_ASSERT( TeleManager::getAccountManagerStatus() == TeleManager::AMS_PREPARED);
-
ContactList *cl = TeleManager::getContactList();
AccountContactPairV pairs;
@@ -172,13 +168,6 @@ void TestTeleTubes::testContactList()
mpAccepterContact);
}
-void TestTeleTubes::testPrepareAccountManager()
-{
- TeleManager::prepareAccountManager();
- TeleManager::AccountManagerStatus eStatus = TeleManager::getAccountManagerStatus();
- CPPUNIT_ASSERT( eStatus == TeleManager::AMS_PREPARED);
-}
-
void TestTeleTubes::testStartBuddySession()
{
TpAccount *pAcc1 = TeleManager::getAccount(maOffererIdentifier);
diff --git a/tubes/source/contact-list.cxx b/tubes/source/contact-list.cxx
index 03fc3b1f6956..e240ece872ad 100644
--- a/tubes/source/contact-list.cxx
+++ b/tubes/source/contact-list.cxx
@@ -40,29 +40,6 @@ ContactList::ContactList(TpAccountManager *pAccountManager)
SAL_WARN_IF( !mpAccountManager, "tubes",
"ContactList::ContactList: passed a null account manager");
g_object_ref( mpAccountManager);
-
- /* Tell the client factory (which creates and prepares proxy objects) to
- * get the features we need ready before giving us any objects.
- */
- TpSimpleClientFactory *factory = tp_proxy_get_factory (mpAccountManager);
- /* We need every online account's connection object to be available... */
- tp_simple_client_factory_add_account_features_varargs (factory,
- TP_ACCOUNT_FEATURE_CONNECTION,
- 0);
- /* ...and we want those connection objects to have the contact list
- * available... */
- tp_simple_client_factory_add_connection_features_varargs (factory,
- TP_CONNECTION_FEATURE_CONTACT_LIST,
- 0);
- /* ...and those contacts should have their alias and their capabilities
- * available.
- */
- tp_simple_client_factory_add_contact_features_varargs (factory,
- TP_CONTACT_FEATURE_ALIAS,
- TP_CONTACT_FEATURE_AVATAR_DATA,
- TP_CONTACT_FEATURE_CAPABILITIES,
- TP_CONTACT_FEATURE_PRESENCE,
- TP_CONTACT_FEATURE_INVALID);
}
ContactList::~ContactList()
diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx
index d900cb61d724..de87a5212092 100644
--- a/tubes/source/manager.cxx
+++ b/tubes/source/manager.cxx
@@ -83,11 +83,11 @@ using namespace osl;
class TeleManagerImpl
{
public:
- TpAutomaticClientFactory* mpFactory;
+ TpSimpleClientFactory* mpFactory;
TpBaseClient* mpClient;
TpBaseClient* mpFileTransferClient;
TpAccountManager* mpAccountManager;
- TeleManager::AccountManagerStatus meAccountManagerStatus;
+ bool mbAccountManagerReady : 1;
bool mbAccountManagerReadyHandlerInvoked : 1;
bool mbChannelReadyHandlerInvoked : 1;
ContactList* mpContactList;
@@ -441,7 +441,6 @@ bool TeleManager::init( bool bListen )
{
if (createAccountManager())
{
- prepareAccountManager();
if (bListen && !registerClients())
SAL_WARN( "tubes", "TeleManager::init: Could not register client handlers." );
@@ -478,22 +477,41 @@ bool TeleManager::createAccountManager()
return false;
}
- pImpl->mpFactory = tp_automatic_client_factory_new( pDBus);
+ pImpl->mpFactory = TP_SIMPLE_CLIENT_FACTORY( tp_automatic_client_factory_new( pDBus));
g_object_unref( pDBus);
SAL_WARN_IF( !pImpl->mpFactory, "tubes", "TeleManager::createAccountManager: no client factory");
if (!pImpl->mpFactory)
return false;
- TpAccountManager* pAccountManager = tp_account_manager_new_with_factory (
- TP_SIMPLE_CLIENT_FACTORY (pImpl->mpFactory));
- tp_account_manager_set_default( pAccountManager);
-
- /* Takes our ref. */
- pImpl->mpAccountManager = pAccountManager;
+ /* Tell the client factory (which creates and prepares proxy objects) to
+ * get the features we need ready before giving us any objects.
+ */
+ /* We need every online account's connection object to be available... */
+ tp_simple_client_factory_add_account_features_varargs (pImpl->mpFactory,
+ TP_ACCOUNT_FEATURE_CONNECTION,
+ 0);
+ /* ...and we want those connection objects to have the contact list
+ * available... */
+ tp_simple_client_factory_add_connection_features_varargs (pImpl->mpFactory,
+ TP_CONNECTION_FEATURE_CONTACT_LIST,
+ 0);
+ /* ...and those contacts should have their alias and their capabilities
+ * available.
+ */
+ tp_simple_client_factory_add_contact_features_varargs (pImpl->mpFactory,
+ TP_CONTACT_FEATURE_ALIAS,
+ TP_CONTACT_FEATURE_AVATAR_DATA,
+ TP_CONTACT_FEATURE_CAPABILITIES,
+ TP_CONTACT_FEATURE_PRESENCE,
+ TP_CONTACT_FEATURE_INVALID);
- pImpl->mpContactList = new ContactList(pAccountManager);
+ pImpl->mpAccountManager = tp_account_manager_new_with_factory (pImpl->mpFactory);
+ tp_account_manager_set_default (pImpl->mpAccountManager);
- return true;
+ setAccountManagerReadyHandlerInvoked( false);
+ tp_proxy_prepare_async( pImpl->mpAccountManager, NULL, TeleManager_AccountManagerReadyHandler, NULL);
+ lcl_iterateLoop( &TeleManager::isAccountManagerReadyHandlerInvoked);
+ return pImpl->mbAccountManagerReady;
}
bool TeleManager::registerClients()
@@ -508,7 +526,7 @@ bool TeleManager::registerClients()
return true;
pImpl->mpClient = tp_simple_handler_new_with_factory(
- TP_SIMPLE_CLIENT_FACTORY (pImpl->mpFactory), // factory
+ pImpl->mpFactory, // factory
FALSE, // bypass_approval
FALSE, // requests
getFullClientName().getStr(), // name
@@ -556,7 +574,7 @@ bool TeleManager::registerClients()
* user isn't prompted before the channel gets passed to us.
*/
pImpl->mpFileTransferClient = tp_simple_handler_new_with_factory (
- TP_SIMPLE_CLIENT_FACTORY( pImpl->mpFactory), // factory
+ pImpl->mpFactory, // factory
TRUE, // bypass_approval
FALSE, // requests
getFullClientName().getStr(), // name
@@ -731,45 +749,6 @@ TeleConference* TeleManager::startBuddySession( TpAccount *pAccount, TpContact *
return pConference;
}
-void TeleManager::prepareAccountManager()
-{
- INFO_LOGGER_F( "TeleManager::prepareAccountManager");
-
- MutexGuard aGuard( GetMutex());
-
- SAL_INFO_IF( pImpl->meAccountManagerStatus == AMS_PREPARED, "tubes",
- "TeleManager::prepareAccountManager: already prepared");
- if (pImpl->meAccountManagerStatus == AMS_PREPARED)
- return;
-
- SAL_WARN_IF( pImpl->meAccountManagerStatus == AMS_INPREPARATION, "tubes",
- "TeleManager::prepareAccountManager: already in preparation");
- if (pImpl->meAccountManagerStatus == AMS_INPREPARATION)
- return;
-
- SAL_WARN_IF( pImpl->meAccountManagerStatus != AMS_UNINITIALIZED, "tubes",
- "TeleManager::prepareAccountManager: yet another attempt");
-
- SAL_WARN_IF( !pImpl->mpAccountManager, "tubes",
- "TeleManager::prepareAccountManager: called before ::connect()");
- if (!pImpl->mpAccountManager)
- return;
-
- pImpl->meAccountManagerStatus = AMS_INPREPARATION;
- setAccountManagerReadyHandlerInvoked( false);
-
- tp_proxy_prepare_async( pImpl->mpAccountManager, NULL, TeleManager_AccountManagerReadyHandler, NULL);
-
- lcl_iterateLoop( &TeleManager::isAccountManagerReadyHandlerInvoked);
-}
-
-
-TeleManager::AccountManagerStatus TeleManager::getAccountManagerStatus()
-{
- return pImpl->meAccountManagerStatus;
-}
-
-
void TeleManager::setAccountManagerReadyHandlerInvoked( bool b )
{
pImpl->mbAccountManagerReadyHandlerInvoked = b;
@@ -792,6 +771,9 @@ bool TeleManager::isChannelReadyHandlerInvoked()
ContactList* TeleManager::getContactList()
{
+ if (!pImpl->mpContactList)
+ pImpl->mpContactList = new ContactList (pImpl->mpAccountManager);
+
return pImpl->mpContactList;
}
@@ -799,9 +781,9 @@ TpAccount* TeleManager::getAccount( const rtl::OString& rAccountID )
{
INFO_LOGGER_F( "TeleManager::getMyAccount");
- SAL_WARN_IF( pImpl->meAccountManagerStatus != AMS_PREPARED, "tubes",
+ SAL_WARN_IF( !pImpl->mbAccountManagerReady, "tubes",
"TeleManager::getMyAccount: Account Manager not prepared");
- if (pImpl->meAccountManagerStatus != AMS_PREPARED)
+ if (!pImpl->mbAccountManagerReady)
return NULL;
GList* pAccounts = tp_account_manager_get_valid_accounts( pImpl->mpAccountManager);
@@ -832,7 +814,7 @@ TpAccount* TeleManager::getAccount( const rtl::OString& rAccountID )
void TeleManager::setAccountManagerReady( bool bPrepared)
{
- pImpl->meAccountManagerStatus = (bPrepared ? AMS_PREPARED : AMS_UNPREPARABLE);
+ pImpl->mbAccountManagerReady = bPrepared;
}
@@ -898,9 +880,10 @@ TeleManagerImpl::TeleManagerImpl()
mpClient( NULL),
mpFileTransferClient( NULL),
mpAccountManager( NULL),
- meAccountManagerStatus( TeleManager::AMS_UNINITIALIZED),
+ mbAccountManagerReady( false),
mbAccountManagerReadyHandlerInvoked( false),
- mbChannelReadyHandlerInvoked( false)
+ mbChannelReadyHandlerInvoked( false),
+ mpContactList( NULL)
{
g_type_init();
}