diff options
author | Matúš Kukan <matus.kukan@gmail.com> | 2012-07-13 19:06:34 +0200 |
---|---|---|
committer | Matúš Kukan <matus.kukan@gmail.com> | 2012-07-17 16:40:23 +0200 |
commit | fd9d7f35d9cec7584061d9930c05189ec5838036 (patch) | |
tree | d5e8d93bad595c4ad5eca2a94e8d2ef5de066685 /tubes | |
parent | 17c549221427bde2390368be39f48134409a933f (diff) |
tubes: split TeleManager::connect method.
Use createAccountManager instead.
Optionally also register clients for accepting tubes. Will be used more later.
Change-Id: I353d45e95fa130c0c578b74d016b650039358ea7
Diffstat (limited to 'tubes')
-rw-r--r-- | tubes/inc/tubes/manager.hxx | 12 | ||||
-rw-r--r-- | tubes/qa/test_manager.cxx | 32 | ||||
-rw-r--r-- | tubes/source/manager.cxx | 62 |
3 files changed, 69 insertions, 37 deletions
diff --git a/tubes/inc/tubes/manager.hxx b/tubes/inc/tubes/manager.hxx index ee743432f46c..f926ec122ef1 100644 --- a/tubes/inc/tubes/manager.hxx +++ b/tubes/inc/tubes/manager.hxx @@ -86,7 +86,14 @@ public: static TeleManager *get( bool bAcceptIncoming ); void unref(); - /** Prepare the Telepathy Account Manager. Requires connect() to have succeeded. + /** Connect to DBus and create AccountManager. */ + bool createAccountManager(); + + /** Setup client handlers. */ + 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. @@ -131,9 +138,6 @@ public: void unregisterConference( TeleConferencePtr pConference ); - /** Connect to DBus and setup client handler. */ - bool connect(); - void disconnect(); /** Send data to all registered conferences. diff --git a/tubes/qa/test_manager.cxx b/tubes/qa/test_manager.cxx index dcfbb4707f3a..1254973a7ef9 100644 --- a/tubes/qa/test_manager.cxx +++ b/tubes/qa/test_manager.cxx @@ -50,8 +50,10 @@ public: ~TestTeleTubes(); void testSetupManager1(); void testSetupManager2(); - void testConnect1(); - void testConnect2(); + void testCreateAccountManager1(); + void testCreateAccountManager2(); + void testRegisterClients1(); + void testRegisterClients2(); void testContactList(); void testPrepareAccountManager1(); void testPrepareAccountManager2(); @@ -77,8 +79,10 @@ public: CPPUNIT_TEST_SUITE( TestTeleTubes ); CPPUNIT_TEST( testSetupManager1 ); CPPUNIT_TEST( testSetupManager2 ); - CPPUNIT_TEST( testConnect1 ); - CPPUNIT_TEST( testConnect2 ); + CPPUNIT_TEST( testCreateAccountManager1 ); + CPPUNIT_TEST( testCreateAccountManager2 ); + CPPUNIT_TEST( testRegisterClients1 ); + CPPUNIT_TEST( testRegisterClients2 ); CPPUNIT_TEST( testPrepareAccountManager1 ); CPPUNIT_TEST( testPrepareAccountManager2 ); CPPUNIT_TEST( testContactList ); @@ -257,18 +261,30 @@ void TestTeleTubes::testStartBuddySession2() //CPPUNIT_ASSERT( bStarted == true); } -void TestTeleTubes::testConnect1() +void TestTeleTubes::testCreateAccountManager1() { - bool bConnected = mpManager1->connect(); + bool bConnected = mpManager1->createAccountManager(); CPPUNIT_ASSERT( bConnected == true); } -void TestTeleTubes::testConnect2() +void TestTeleTubes::testCreateAccountManager2() { - bool bConnected = mpManager2->connect(); + bool bConnected = mpManager2->createAccountManager(); CPPUNIT_ASSERT( bConnected == true); } +void TestTeleTubes::testRegisterClients1() +{ + bool bRegistered = mpManager1->registerClients(); + CPPUNIT_ASSERT( bRegistered == true); +} + +void TestTeleTubes::testRegisterClients2() +{ + bool bRegistered = mpManager2->registerClients(); + CPPUNIT_ASSERT( bRegistered == true); +} + void TestTeleTubes::testSendPacket() { TelePacket aPacket( "", RTL_CONSTASCII_STRINGPARAM( "from 1 to 2")); diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx index 06b153303057..047e54abf98c 100644 --- a/tubes/source/manager.cxx +++ b/tubes/source/manager.cxx @@ -79,7 +79,7 @@ class TeleManagerImpl { public: GMainLoop* mpLoop; - TpDBusDaemon* mpDBus; + TpAutomaticClientFactory* mpFactory; TpBaseClient* mpClient; TpBaseClient* mpFileTransferClient; TpAccountManager* mpAccountManager; @@ -380,34 +380,34 @@ TeleManager::unref() } -bool TeleManager::connect() +bool TeleManager::createAccountManager() { - INFO_LOGGER( "TeleManager::connect"); + INFO_LOGGER( "TeleManager::createAccountManager"); MutexGuard aGuard( GetMutex()); - /* TODO: also check whether client could be registered and retry if not? */ - SAL_INFO_IF( pImpl->mpDBus && pImpl->mpClient, "tubes", "TeleManager::connect: already connected"); - if (pImpl->mpDBus && pImpl->mpClient) + SAL_INFO_IF( pImpl->mpAccountManager, "tubes", "TeleManager::createAccountManager: already connected"); + if (pImpl->mpAccountManager) return true; GError* pError = NULL; - pImpl->mpDBus = tp_dbus_daemon_dup( &pError); - SAL_WARN_IF( !pImpl->mpDBus, "tubes", "TeleManager::connect: no dbus daemon"); - if (!pImpl->mpDBus || pError) + TpDBusDaemon *pDBus = tp_dbus_daemon_dup( &pError); + SAL_WARN_IF( !pDBus, "tubes", "TeleManager::createAccountManager: no dbus daemon"); + if (!pDBus || pError) { - SAL_WARN_IF( pError, "tubes", "TeleManager::connect: dbus daemon error: " << pError->message); + SAL_WARN_IF( pError, "tubes", "TeleManager::createAccountManager: dbus daemon error: " << pError->message); g_error_free( pError); return false; } - TpAutomaticClientFactory* pFactory = tp_automatic_client_factory_new( pImpl->mpDBus); - SAL_WARN_IF( !pFactory, "tubes", "TeleManager::connect: no client factory"); - if (!pFactory) + pImpl->mpFactory = 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 (pFactory)); + TP_SIMPLE_CLIENT_FACTORY (pImpl->mpFactory)); tp_account_manager_set_default( pAccountManager); /* Takes our ref. */ @@ -415,11 +415,22 @@ bool TeleManager::connect() pImpl->mpContactList = new ContactList(pAccountManager); - if (!mbAcceptIncoming) + return true; +} + +bool TeleManager::registerClients() +{ + INFO_LOGGER( "TeleManager::registerClients"); + + MutexGuard aGuard( GetMutex()); + + /* TODO: also check whether client could be registered and retry if not? */ + SAL_INFO_IF( pImpl->mpClient && pImpl->mpFileTransferClient, "tubes", "TeleManager::registerClients: already registered"); + if (pImpl->mpClient && pImpl->mpFileTransferClient) return true; pImpl->mpClient = tp_simple_handler_new_with_factory( - TP_SIMPLE_CLIENT_FACTORY (pFactory), // factory + TP_SIMPLE_CLIENT_FACTORY (pImpl->mpFactory), // factory FALSE, // bypass_approval FALSE, // requests getFullClientName().getStr(), // name @@ -428,7 +439,7 @@ bool TeleManager::connect() this, // user_data NULL // destroy ); - SAL_WARN_IF( !pImpl->mpClient, "tubes", "TeleManager::connect: no client"); + SAL_WARN_IF( !pImpl->mpClient, "tubes", "TeleManager::registerClients: no client"); if (!pImpl->mpClient) return false; @@ -450,15 +461,16 @@ bool TeleManager::connect() TP_PROP_CHANNEL_TYPE_DBUS_TUBE_SERVICE_NAME, G_TYPE_STRING, getFullServiceName().getStr(), NULL)); + GError* pError = NULL; if (!tp_base_client_register( pImpl->mpClient, &pError)) { - SAL_WARN( "tubes", "TeleManager::connect: error registering client handler: " << pError->message); + SAL_WARN( "tubes", "TeleManager::registerClients: error registering client handler: " << pError->message); g_error_free( pError); return false; } - SAL_INFO( "tubes", "TeleManager::connect: bus name: " << tp_base_client_get_bus_name( pImpl->mpClient)); - SAL_INFO( "tubes", "TeleManager::connect: object path: " << tp_base_client_get_object_path( pImpl->mpClient)); + SAL_INFO( "tubes", "TeleManager::registerClients: bus name: " << tp_base_client_get_bus_name( pImpl->mpClient)); + SAL_INFO( "tubes", "TeleManager::registerClients: object path: " << tp_base_client_get_object_path( pImpl->mpClient)); /* Register a second "head" for incoming file transfers. This uses a more * specific filter than Empathy's handler by matching on the file @@ -466,7 +478,7 @@ bool TeleManager::connect() * user isn't prompted before the channel gets passed to us. */ pImpl->mpFileTransferClient = tp_simple_handler_new_with_factory ( - TP_SIMPLE_CLIENT_FACTORY( pFactory), // factory + TP_SIMPLE_CLIENT_FACTORY( pImpl->mpFactory), // factory TRUE, // bypass_approval FALSE, // requests getFullClientName().getStr(), // name @@ -485,7 +497,7 @@ bool TeleManager::connect() if (!tp_base_client_register( pImpl->mpFileTransferClient, &pError)) { /* This shouldn't fail if registering the main handler succeeded */ - SAL_WARN( "tubes", "TeleManager::connect: error registering file transfer handler: " << pError->message); + SAL_WARN( "tubes", "TeleManager::registerClients: error registering file transfer handler: " << pError->message); g_error_free( pError); return false; } @@ -945,7 +957,7 @@ void TeleManager::addSuffixToNames( const char* pName ) TeleManagerImpl::TeleManagerImpl() : mpLoop( NULL), - mpDBus( NULL), + mpFactory( NULL), mpClient( NULL), mpFileTransferClient( NULL), mpAccountManager( NULL), @@ -957,12 +969,12 @@ TeleManagerImpl::TeleManagerImpl() TeleManagerImpl::~TeleManagerImpl() { + if (mpFactory) + g_object_unref( mpFactory); if (mpClient) g_object_unref( mpClient); if (mpFileTransferClient) g_object_unref( mpFileTransferClient); - if (mpDBus) - g_object_unref( mpDBus); if (mpAccountManager) g_object_unref( mpAccountManager); if (mpContactList) |