summaryrefslogtreecommitdiff
path: root/tubes
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@gmail.com>2012-07-23 19:50:19 +0200
committerMatúš Kukan <matus.kukan@gmail.com>2012-07-23 21:43:52 +0200
commitabeb02c02d6d2cf5ac48d75b04563d3376d71677 (patch)
tree6ab1f9653d2a2f8f775a9de44fc0ec7446195172 /tubes
parent955bbbb54c153dc50daca1f35d738acfe1d823a5 (diff)
tubes: create TeleConferenceImpl to hide more details from public
Change-Id: If1be001e336991218893e3bc455a16e73ecaab0f
Diffstat (limited to 'tubes')
-rw-r--r--tubes/inc/tubes/conference.hxx37
-rw-r--r--tubes/source/conference.cxx94
-rw-r--r--tubes/source/manager.cxx4
3 files changed, 74 insertions, 61 deletions
diff --git a/tubes/inc/tubes/conference.hxx b/tubes/inc/tubes/conference.hxx
index 89544578eeed..a66d65b024db 100644
--- a/tubes/inc/tubes/conference.hxx
+++ b/tubes/inc/tubes/conference.hxx
@@ -33,10 +33,10 @@
#include "tubes/tubesdllapi.h"
#include <rtl/ustring.hxx>
#include <telepathy-glib/telepathy-glib.h>
-#include <queue>
#include <tubes/warnings_guard_boost_signals2.hpp>
class TeleManager;
+class TeleConferenceImpl;
/** Conference setup by TeleManager */
class TeleConference
@@ -52,17 +52,11 @@ public:
/// Unrefs, unregisters from manager and calls dtor if last reference!
void finalize();
- TeleManager* getManager() const { return mpManager; }
-
TUBES_DLLPUBLIC bool sendPacket( const OString& rPacket );
/** Pop a received packet. */
bool popPacket( OString& rPacket );
- /** Queue incoming data as OString */
- void queue( const char* pPacket, int nSize );
- void queue( const OString& rPacket );
-
TUBES_DLLPUBLIC void invite( TpContact *pContact );
/** Emitted when a packet is received. */
@@ -71,37 +65,36 @@ public:
typedef void (*FileSentCallback)( bool aSuccess, void* pUserData);
TUBES_DLLPUBLIC void sendFile( rtl::OUString &localUri, FileSentCallback pCallback, void* pUserData);
TUBES_DLLPUBLIC const OString& getUuid() const { return msUuid; }
- void setUuid( const OString& rUuid ) { msUuid = rUuid; }
// --- following only to be called only by manager's callbacks ---
// TODO: make friends instead
-
void setChannel( TpAccount* pAccount, TpDBusTubeChannel* pChannel );
- TpDBusTubeChannel* getChannel() const { return mpChannel; }
bool offerTube();
bool acceptTube();
- bool setTube( GDBusConnection* pTube );
- /// got tube accepted on other end as well?
- bool isTubeOpen() const { return mpTube != NULL; }
+ TeleManager* getManager() const { return mpManager; }
// Only for callbacks.
- void setTubeOfferedHandlerInvoked( bool b ) { mbTubeOfferedHandlerInvoked = b; }
- bool isTubeOfferedHandlerInvoked() const { return mbTubeOfferedHandlerInvoked; }
+ bool setTube( GDBusConnection* pTube );
+ void setTubeOfferedHandlerInvoked( bool b );
+ bool isTubeOfferedHandlerInvoked() const;
+ /** Queue incoming data as OString */
+ void queue( const OString& rPacket );
+ void setUuid( const OString& rUuid ) { msUuid = rUuid; }
private:
- typedef ::std::queue<OString> TelePacketQueue;
+ friend class TeleManager;
+ // Used only by TeleManager:
+ /// got tube accepted on other end as well?
+ bool isReady() const;
+
+ // Private:
bool spinUntilTubeEstablished();
TeleManager* mpManager;
TpAccount* mpAccount;
TpDBusTubeChannel* mpChannel;
OString msUuid;
- gchar* mpAddress;
- GDBusConnection* mpTube;
- guint maObjectRegistrationId;
- TelePacketQueue maPacketQueue;
-
- bool mbTubeOfferedHandlerInvoked : 1;
+ TeleConferenceImpl* pImpl;
};
#endif // INCLUDED_TUBES_CONFERENCE_HXX
diff --git a/tubes/source/conference.cxx b/tubes/source/conference.cxx
index 7dc531dca804..a2fafd23f7a1 100644
--- a/tubes/source/conference.cxx
+++ b/tubes/source/conference.cxx
@@ -31,6 +31,8 @@
#include <tubes/constants.h>
#include <tubes/file-transfer-helper.h>
+#include <queue>
+
#if defined SAL_LOG_INFO
namespace
{
@@ -58,6 +60,24 @@ struct InfoLogger
#define INFO_LOGGER(s)
#endif // SAL_LOG_INFO
+class TeleConferenceImpl
+{
+ typedef ::std::queue<OString> TelePacketQueue;
+
+public:
+ guint maObjectRegistrationId;
+ TelePacketQueue maPacketQueue;
+ GDBusConnection* mpTube;
+ bool mbTubeOfferedHandlerInvoked : 1;
+
+ TeleConferenceImpl() :
+ mpTube( NULL ),
+ mbTubeOfferedHandlerInvoked( false )
+ {}
+
+ ~TeleConferenceImpl() {}
+};
+
static void TeleConference_MethodCallHandler(
GDBusConnection* /*pConnection*/,
const gchar* pSender,
@@ -110,7 +130,7 @@ static void TeleConference_MethodCallHandler(
SAL_INFO( "tubes", "TeleConference_MethodCallHandler: received packet from sender "
<< (pSender ? pSender : "(null)") << " with size " << nPacketSize);
- pConference->queue( pPacketData, nPacketSize );
+ pConference->queue( OString( pPacketData, nPacketSize ) );
g_dbus_method_invocation_return_value( pInvocation, 0 );
g_variant_unref( ay);
@@ -211,9 +231,7 @@ TeleConference::TeleConference( TeleManager* pManager, TpAccount* pAccount, TpDB
mpAccount( NULL),
mpChannel( NULL),
msUuid( sUuid),
- mpAddress( NULL),
- mpTube( NULL),
- mbTubeOfferedHandlerInvoked( false)
+ pImpl( new TeleConferenceImpl() )
{
setChannel( pAccount, pChannel );
}
@@ -221,7 +239,8 @@ TeleConference::TeleConference( TeleManager* pManager, TpAccount* pAccount, TpDB
TeleConference::~TeleConference()
{
- // Do nothing here, we're destructed from finalize()
+ // We're destructed from finalize()
+ delete pImpl;
}
@@ -247,7 +266,7 @@ bool TeleConference::spinUntilTubeEstablished()
{
mpManager->iterateLoop( this, &TeleConference::isTubeOfferedHandlerInvoked);
- bool bOpen = isTubeOpen();
+ bool bOpen = pImpl->mpTube != NULL;
SAL_INFO( "tubes", "TeleConference::spinUntilTubeEstablished: tube open: " << bOpen);
return bOpen;
}
@@ -258,8 +277,8 @@ bool TeleConference::acceptTube()
INFO_LOGGER( "TeleConference::acceptTube");
SAL_WARN_IF( !mpChannel, "tubes", "TeleConference::acceptTube: no channel setup");
- SAL_WARN_IF( mpTube, "tubes", "TeleConference::acceptTube: already tubed");
- if (!mpChannel || mpTube)
+ SAL_WARN_IF( pImpl->mpTube, "tubes", "TeleConference::acceptTube: already tubed");
+ if (!mpChannel || pImpl->mpTube)
return false;
tp_dbus_tube_channel_accept_async( mpChannel,
@@ -295,12 +314,11 @@ bool TeleConference::setTube( GDBusConnection* pTube)
{
INFO_LOGGER( "TeleConference::setTube");
- OSL_ENSURE( !mpTube, "TeleConference::setTube: already tubed");
+ OSL_ENSURE( !pImpl->mpTube, "TeleConference::setTube: already tubed");
- mpTube = pTube;
+ pImpl->mpTube = pTube;
GDBusNodeInfo *introspection_data;
- guint registration_id;
static const GDBusInterfaceVTable interface_vtable =
{
TeleConference_MethodCallHandler,
@@ -320,16 +338,30 @@ bool TeleConference::setTube( GDBusConnection* pTube)
introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
g_assert (introspection_data != NULL);
- registration_id = g_dbus_connection_register_object( mpTube,
+ pImpl->maObjectRegistrationId = g_dbus_connection_register_object( pImpl->mpTube,
LIBO_TUBES_DBUS_PATH, introspection_data->interfaces[0],
&interface_vtable, this, NULL, NULL);
- g_assert (registration_id > 0);
+ g_assert (pImpl->maObjectRegistrationId > 0);
g_dbus_node_info_unref (introspection_data);
return true;
}
+void TeleConference::setTubeOfferedHandlerInvoked( bool b )
+{
+ pImpl->mbTubeOfferedHandlerInvoked = b;
+}
+
+bool TeleConference::isTubeOfferedHandlerInvoked() const
+{
+ return pImpl->mbTubeOfferedHandlerInvoked;
+}
+
+bool TeleConference::isReady() const
+{
+ return mpChannel && pImpl->mpTube;
+}
void TeleConference::close()
{
@@ -358,18 +390,12 @@ void TeleConference::finalize()
mpAccount = NULL;
}
- if (mpTube)
+ if (pImpl->mpTube)
{
- g_dbus_connection_unregister_object( mpTube, maObjectRegistrationId);
- g_dbus_connection_close_sync( mpTube, NULL, NULL );
- g_object_unref( mpTube );
- mpTube = NULL;
- }
-
- if (mpAddress)
- {
- g_free( mpAddress);
- mpAddress = NULL;
+ g_dbus_connection_unregister_object( pImpl->mpTube, pImpl->maObjectRegistrationId);
+ g_dbus_connection_close_sync( pImpl->mpTube, NULL, NULL );
+ g_object_unref( pImpl->mpTube );
+ pImpl->mpTube = NULL;
}
//! *this gets destructed here!
@@ -381,8 +407,8 @@ bool TeleConference::sendPacket( const OString& rPacket )
INFO_LOGGER( "TeleConference::sendPacket");
OSL_ENSURE( mpManager, "tubes: TeleConference::sendPacket: no TeleManager");
- SAL_WARN_IF( !mpTube, "tubes", "TeleConference::sendPacket: no tube");
- if (!(mpManager && mpTube))
+ SAL_WARN_IF( !pImpl->mpTube, "tubes", "TeleConference::sendPacket: no tube");
+ if (!(mpManager && pImpl->mpTube))
return false;
/* FIXME: in GLib 2.32 we can use g_variant_new_fixed_array(). It does
@@ -394,7 +420,7 @@ bool TeleConference::sendPacket( const OString& rPacket )
FALSE,
g_free, pData);
- g_dbus_connection_call( mpTube,
+ g_dbus_connection_call( pImpl->mpTube,
NULL, /* bus name; in multi-user case we'd address this to the master. */
LIBO_TUBES_DBUS_PATH,
LIBO_TUBES_DBUS_INTERFACE,
@@ -415,18 +441,12 @@ void TeleConference::queue( const OString &rPacket )
{
INFO_LOGGER( "TeleConference::queue");
- maPacketQueue.push( rPacket);
+ pImpl->maPacketQueue.push( rPacket);
sigPacketReceived( rPacket );
}
-void TeleConference::queue( const char* pPacketData, int nPacketSize )
-{
- OString aPacket( pPacketData, nPacketSize );
- queue( aPacket );
-}
-
void TeleConference::invite( TpContact *pContact )
{
INFO_LOGGER( "TeleConference::invite" );
@@ -514,10 +534,10 @@ bool TeleConference::popPacket( OString& rPacket )
{
INFO_LOGGER( "TeleConference::popPacket");
- if (maPacketQueue.empty())
+ if (pImpl->maPacketQueue.empty())
return false;
- rPacket = maPacketQueue.front();
- maPacketQueue.pop();
+ rPacket = pImpl->maPacketQueue.front();
+ pImpl->maPacketQueue.pop();
return true;
}
diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx
index 86d2f5d19fbd..4abed6b2f4bb 100644
--- a/tubes/source/manager.cxx
+++ b/tubes/source/manager.cxx
@@ -619,7 +619,7 @@ TeleConference* TeleManager::startGroupSession( TpAccount *pAccount,
g_object_unref( pChannelRequest);
g_hash_table_unref( pRequest);
- if (!pConference->getChannel() || !pConference->isTubeOpen())
+ if (!pConference->isReady())
return NULL;
return pConference;
@@ -694,7 +694,7 @@ TeleConference* TeleManager::startBuddySession( TpAccount *pAccount, TpContact *
g_object_unref( pChannelRequest);
g_hash_table_unref( pRequest);
- if (!pConference->getChannel() || !pConference->isTubeOpen())
+ if (!pConference->isReady())
return NULL;
return pConference;