summaryrefslogtreecommitdiff
path: root/tubes
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2012-04-01 15:50:20 +0100
committerMatúš Kukan <matus.kukan@gmail.com>2012-07-17 16:40:08 +0200
commitaeacb83ecb0afc2f08c05ba7131d4052163a6e2e (patch)
tree9e74d715bd8c35a1afa77471866b7fd029cfe459 /tubes
parent1ffa61a4b3956d4af5770250a53b03991ac785fd (diff)
tubes: use tp_dbus_tube_channel_offer/accept_async
I added these to the recently-released telepathy-glib 0.18.0 mainly to let us simplify the code here. With this new API, tp-glib takes care of waiting for the state changes, creating the GDBusConnection, etc.
Diffstat (limited to 'tubes')
-rw-r--r--tubes/inc/tubes/conference.hxx18
-rw-r--r--tubes/source/conference.cxx149
2 files changed, 49 insertions, 118 deletions
diff --git a/tubes/inc/tubes/conference.hxx b/tubes/inc/tubes/conference.hxx
index fca6e2ed5278..088bf4b783d9 100644
--- a/tubes/inc/tubes/conference.hxx
+++ b/tubes/inc/tubes/conference.hxx
@@ -84,20 +84,14 @@ public:
bool offerTube();
bool acceptTube();
/// got tube accepted on other end as well?
- bool isTubeOpen() const { return meTubeChannelState == TP_TUBE_CHANNEL_STATE_OPEN; }
+ bool isTubeOpen() const { return mpTube != NULL; }
// Only for callbacks.
void setTubeOfferedHandlerInvoked( bool b ) { mbTubeOfferedHandlerInvoked = b; }
bool isTubeOfferedHandlerInvoked() const { return mbTubeOfferedHandlerInvoked; }
- bool isTubeChannelStateChangedToOpen() const
- { return meTubeChannelState == TP_TUBE_CHANNEL_STATE_OPEN; };
- void setTubeChannelState( TpTubeChannelState eState ) { meTubeChannelState = eState; }
-
- static void TubeChannelStateChangedHandler(TpChannel*, guint, void*, GObject*);
- static void TubeOfferedHandler(TpChannel* pChannel, const gchar* pAddress, const GError* pError,
- gpointer pUserData, GObject*pWeakObject);
- static void TubeAcceptedHandler(TpChannel* pChannel, const gchar* pAddress, const GError* pError,
- gpointer pUserData, GObject*pWeakObject);
+
+ static void TubeOfferedHandler(GObject* pSource, GAsyncResult* pResult, gpointer pUserData);
+ static void TubeAcceptedHandler(GObject* pSource, GAsyncResult* pResult, gpointer pUserData);
static void FTReady( EmpathyFTHandler *handler, GError *error, gpointer user_data);
static void methodCallHandler(GDBusConnection* pConnection,
@@ -110,9 +104,8 @@ public:
void* pUserData);
private:
- bool tryToOpen();
bool spinUntilTubeEstablished();
- bool setTube( const char* pTube );
+ bool setTube( GDBusConnection* pTube);
rtl::OString maSessionId;
TeleManager* mpManager;
@@ -122,7 +115,6 @@ private:
GDBusConnection* mpTube;
guint maObjectRegistrationId;
TelePacketQueue maPacketQueue;
- TpTubeChannelState meTubeChannelState;
bool mbTubeOfferedHandlerInvoked : 1;
diff --git a/tubes/source/conference.cxx b/tubes/source/conference.cxx
index 1cd9248b466f..3df23c6db198 100644
--- a/tubes/source/conference.cxx
+++ b/tubes/source/conference.cxx
@@ -142,80 +142,62 @@ static void TeleConference_ChannelCloseHandler(
void TeleConference::TubeOfferedHandler(
- TpChannel* pBaseChannel,
- const gchar* pAddress,
- const GError* pError,
- gpointer pUserData,
- GObject* /*weak_object*/
- )
+ GObject* pSource,
+ GAsyncResult* pResult,
+ gpointer pUserData)
{
INFO_LOGGER_F( "TeleConference::TubeOfferedHandler");
TeleConference* pConference = reinterpret_cast<TeleConference*>(pUserData);
- SAL_WARN_IF( !pConference, "tubes", "TeleConference_TubeOfferedHandler: no conference");
+ SAL_WARN_IF( !pConference, "tubes", "TeleConference::TubeOfferedHandler: no conference");
if (!pConference)
return;
pConference->setTubeOfferedHandlerInvoked( true);
+ TpDBusTubeChannel* pChannel = TP_DBUS_TUBE_CHANNEL( pSource);
+ GError* pError = NULL;
+ GDBusConnection* pTube = tp_dbus_tube_channel_offer_finish(
+ pChannel, pResult, &pError);
+
// "can't find contact ... presence" means contact is not a contact.
/* FIXME: detect and handle */
- SAL_WARN_IF( pError, "tubes", "TeleConference::TubeOfferedHandler: entered with error: " << pError->message);
- if (pError)
- return;
-
- SAL_WARN_IF( !pAddress, "tubes", "TeleConference::TubeOfferedHandler: no address");
- if (!pAddress)
- return;
-
- TpDBusTubeChannel* pChannel = TP_DBUS_TUBE_CHANNEL( pBaseChannel);
- SAL_WARN_IF( pChannel != pConference->getChannel(), "tubes", "TeleConference::TubeOfferedHandler: not my channel");
- if ((pChannel) != pConference->getChannel())
+ SAL_WARN_IF( !pTube, "tubes", "TeleConference::TubeOfferedHandler: entered with error: " << pError->message);
+ if (pError) {
+ g_error_free( pError);
return;
+ }
- pConference->mpAddress = g_strdup( pAddress );
- pConference->tryToOpen();
+ pConference->setTube( pTube);
}
-bool TeleConference::tryToOpen()
-{
- if (mpTube)
- return true;
-
- if (!isTubeOpen())
- return false;
-
- if (!mpAddress)
- return false;
-
- return setTube( mpAddress);
-}
-
-void TeleConference::TubeChannelStateChangedHandler(
- TpChannel* pBaseChannel,
- guint nState,
- gpointer pUserData,
- GObject* /*weak_object*/
- )
+void TeleConference::TubeAcceptedHandler(
+ GObject* pSource,
+ GAsyncResult* pResult,
+ gpointer pUserData)
{
- INFO_LOGGER_F( "TeleConference::TubeChannelStateChangedHandler");
-
- SAL_INFO( "tubes", "TeleConference::TubeChannelStateChangedHandler: state: " << static_cast<sal_uInt32>(nState));
+ INFO_LOGGER_F( "TeleConference::TubeAcceptedHandler");
TeleConference* pConference = reinterpret_cast<TeleConference*>(pUserData);
- SAL_WARN_IF( !pConference, "tubes", "TeleConference_DBusMessageHandler: no conference");
+ SAL_WARN_IF( !pConference, "tubes", "TeleConference::TubeAcceptedHandler: no conference");
if (!pConference)
return;
- TpDBusTubeChannel* pChannel = TP_DBUS_TUBE_CHANNEL( pBaseChannel);
- SAL_WARN_IF( pChannel != pConference->getChannel(), "tubes",
- "TeleConference::TubeChannelStateChangedHandler: not my channel");
- if (pChannel != pConference->getChannel())
+ pConference->setTubeOfferedHandlerInvoked( true);
+
+ TpDBusTubeChannel* pChannel = TP_DBUS_TUBE_CHANNEL( pSource);
+ GError* pError = NULL;
+ GDBusConnection* pTube = tp_dbus_tube_channel_accept_finish(
+ pChannel, pResult, &pError);
+
+ SAL_WARN_IF( !pTube, "tubes", "TeleConference::TubeAcceptedHandler: entered with error: " << pError->message);
+ if (pError) {
+ g_error_free( pError);
return;
+ }
- pConference->setTubeChannelState( static_cast<TpTubeChannelState>(nState));
- pConference->tryToOpen();
+ pConference->setTube( pTube);
}
@@ -227,7 +209,6 @@ TeleConference::TeleConference( TeleManager* pManager, TpAccount* pAccount, TpDB
mpChannel( NULL),
mpAddress( NULL),
mpTube( NULL),
- meTubeChannelState( TP_TUBE_CHANNEL_STATE_NOT_OFFERED),
mbTubeOfferedHandlerInvoked( false)
{
setChannel( pAccount, pChannel );
@@ -249,28 +230,9 @@ void TeleConference::setChannel( TpAccount *pAccount, TpDBusTubeChannel* pChanne
g_object_unref( mpAccount);
mpChannel = pChannel;
- if (mpChannel) {
+ if (mpChannel)
g_object_ref( mpChannel);
- /* TODO: remember the TpProxySignalConnection and disconnect in finalize */
- GError* pError = NULL;
- TpProxySignalConnection* pProxySignalConnection =
- tp_cli_channel_interface_tube_connect_to_tube_channel_state_changed(
- TP_CHANNEL( mpChannel),
- &TeleConference::TubeChannelStateChangedHandler,
- this,
- NULL,
- NULL,
- &pError);
-
- if (!pProxySignalConnection || pError)
- {
- SAL_WARN_IF( pError, "tubes",
- "TeleConference::setChannel: channel state changed error: " << pError->message);
- g_error_free( pError);
- }
- }
-
mpAccount = pAccount;
if (mpAccount)
g_object_ref( mpAccount);
@@ -280,7 +242,6 @@ void TeleConference::setChannel( TpAccount *pAccount, TpDBusTubeChannel* pChanne
bool TeleConference::spinUntilTubeEstablished()
{
mpManager->iterateLoop( this, &TeleConference::isTubeOfferedHandlerInvoked);
- mpManager->iterateLoop( this, &TeleConference::isTubeChannelStateChangedToOpen);
bool bOpen = isTubeOpen();
SAL_INFO( "tubes", "TeleConference::spinUntilTubeEstablished: tube open: " << bOpen);
@@ -297,10 +258,9 @@ bool TeleConference::acceptTube()
if (!mpChannel || mpTube)
return false;
- tp_cli_channel_type_dbus_tube_call_accept( TP_CHANNEL( mpChannel), -1,
- TP_SOCKET_ACCESS_CONTROL_CREDENTIALS,
- &TeleConference::TubeOfferedHandler,
- this, NULL, NULL);
+ tp_dbus_tube_channel_accept_async( mpChannel,
+ &TeleConference::TubeAcceptedHandler,
+ this);
return spinUntilTubeEstablished();
}
@@ -313,44 +273,23 @@ bool TeleConference::offerTube()
if (!mpChannel)
return false;
- // We must pass a hash table, it could be empty though.
- /* TODO: anything meaningful to go in here? */
- GHashTable* pParams = tp_asv_new(
- "LibreOffice", G_TYPE_STRING, "Collaboration",
- NULL);
-
- tp_cli_channel_type_dbus_tube_call_offer(
- TP_CHANNEL( mpChannel), // proxy
- -1, // timeout_ms
- pParams, // in_parameters
- TP_SOCKET_ACCESS_CONTROL_CREDENTIALS, // in_access_control
- &TeleConference::TubeOfferedHandler, // callback
- this, // user_data
- NULL, // destroy
- NULL); // weak_object
-
- g_hash_table_unref( pParams);
+ tp_dbus_tube_channel_offer_async(
+ mpChannel,
+ NULL, // no parameters for now
+ &TeleConference::TubeOfferedHandler,
+ this);
+
return spinUntilTubeEstablished();
}
-bool TeleConference::setTube( const char* pAddress )
+bool TeleConference::setTube( GDBusConnection* pTube)
{
INFO_LOGGER( "TeleConference::setTube");
OSL_ENSURE( !mpTube, "TeleConference::setTube: already tubed");
- GError *aError = NULL;
-
- mpTube = g_dbus_connection_new_for_address_sync( pAddress,
- G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
- NULL, NULL, &aError);
- if (!mpTube)
- {
- SAL_WARN( "tubes", "TeleConference::setTube: no dbus connection: " << aError->message);
- g_clear_error( &aError);
- return false;
- }
+ mpTube = pTube;
GDBusNodeInfo *introspection_data;
guint registration_id;