added communitation between service and GUI part of VOIP plugin.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4990 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-02-25 18:15:36 +00:00
parent 12b3ed02f1
commit db07053214
9 changed files with 107 additions and 7 deletions

View File

@ -17,6 +17,8 @@ SOURCES = services/p3vors.cc \
gui/audiodevicehelper.cpp \
gui/VoipStatistics.cpp \
gui/AudioPopupChatDialog.cpp \
gui/PluginGUIHandler.cpp \
gui/PluginNotifier.cpp \
VOIPPlugin.cpp
HEADERS = services/p3vors.h \
@ -28,6 +30,8 @@ HEADERS = services/p3vors.h \
gui/audiodevicehelper.h \
gui/VoipStatistics.h \
gui/AudioPopupChatDialog.h \
gui/PluginGUIHandler.h \
gui/PluginNotifier.h \
interface/rsvoip.h
FORMS = gui/AudioInputConfig.ui \

View File

@ -10,10 +10,18 @@
#include "gui/VoipStatistics.h"
#include "gui/AudioInputConfig.h"
#include "gui/AudioPopupChatDialog.h"
#include "gui/PluginGUIHandler.h"
#include "gui/PluginNotifier.h"
static void *inited = new VOIPPlugin() ;
extern "C" {
// This is *the* function required by RS plugin system to give RS access to the plugin.
// Be careful to:
// - always respect the C linkage convention
// - always return an object of type RsPlugin*
//
void *RETROSHARE_PLUGIN_provide()
{
static VOIPPlugin *p = new VOIPPlugin() ;
@ -35,6 +43,12 @@ VOIPPlugin::VOIPPlugin()
mPlugInHandler = NULL;
mPeers = NULL;
config_page = NULL ;
mPluginGUIHandler = new PluginGUIHandler ;
mPluginNotifier = new PluginNotifier ;
QObject::connect(mPluginNotifier,SIGNAL(voipInvitationReceived(const QString&)),mPluginGUIHandler,SLOT(ReceivedInvitation(const QString&)),Qt::QueuedConnection) ;
QObject::connect(mPluginNotifier,SIGNAL(voipDataReceived(const QString&)),mPluginGUIHandler,SLOT(ReceivedVoipData(const QString&)),Qt::QueuedConnection) ;
}
void VOIPPlugin::setInterfaces(RsPlugInInterfaces &interfaces)
@ -65,7 +79,7 @@ RsPQIService *VOIPPlugin::rs_pqi_service() const
{
if(mVoip == NULL)
{
mVoip = new p3VoRS(mPlugInHandler) ; // , 3600 * 24 * 30 * 6); // 6 Months
mVoip = new p3VoRS(mPlugInHandler,mPluginNotifier) ; // , 3600 * 24 * 30 * 6); // 6 Months
rsVoip = mVoip ;
}

View File

@ -3,6 +3,9 @@
#include <retroshare/rsplugin.h>
#include "services/p3vors.h"
class PluginGUIHandler ;
class PluginNotifier ;
class VOIPPlugin: public RsPlugin
{
public:
@ -32,5 +35,8 @@ class VOIPPlugin: public RsPlugin
mutable RsPluginHandler *mPlugInHandler;
mutable RsPeers* mPeers;
mutable ConfigPage *config_page ;
PluginNotifier *mPluginNotifier ;
PluginGUIHandler *mPluginGUIHandler ;
};

View File

@ -0,0 +1,13 @@
#include <iostream>
#include "PluginGUIHandler.h"
void PluginGUIHandler::ReceivedInvitation(const QString& peer_id)
{
std::cerr << "****** Plugin GUI handler: received data!" << std::endl;
}
void PluginGUIHandler::ReceivedVoipData(const QString& peer_id)
{
std::cerr << "****** Plugin GUI handler: received invitation!" << std::endl;
}

View File

@ -0,0 +1,17 @@
// This class receives async-ed signals from the plugin notifier,
// and executes GUI requests.
//
// It is never called directly: it is called by Qt signal-received callback,
// in the main GUI thread.
//
#include <QObject>
class PluginGUIHandler: public QObject
{
Q_OBJECT
public slots:
void ReceivedInvitation(const QString& peer_id) ;
void ReceivedVoipData(const QString& peer_id) ;
};

View File

@ -0,0 +1,10 @@
#include "PluginNotifier.h"
void PluginNotifier::notifyReceivedVoipInvite(const std::string& peer_id)
{
emit voipInvitationReceived(QString::fromStdString(peer_id)) ;
}
void PluginNotifier::notifyReceivedVoipData(const std::string& peer_id)
{
emit voipDataReceived(QString::fromStdString(peer_id)) ;
}

View File

@ -0,0 +1,21 @@
// This class is a Qt object to get notification from the plugin's service threads,
// and responsible to pass the info the the GUI part.
//
// Because the GUI part is async-ed with the service, it is crucial to use the
// QObject connect system to communicate between the p3Service and the gui part (handled by Qt)
//
#include <QObject>
class PluginNotifier: public QObject
{
Q_OBJECT
public:
void notifyReceivedVoipData(const std::string& peer_id) ;
void notifyReceivedVoipInvite(const std::string& peer_id) ;
signals:
void voipInvitationReceived(const QString&) ; // signal emitted when an invitation has been received
void voipDataReceived(const QString&) ; // signal emitted when some voip data has been received
};

View File

@ -35,6 +35,7 @@
#include "services/p3vors.h"
#include "services/rsvoipitems.h"
#include "gui/PluginNotifier.h"
#include <sys/time.h>
@ -142,8 +143,8 @@ static double convert64bitsToTs(uint64_t bits)
return ts;
}
p3VoRS::p3VoRS(RsPluginHandler *handler)
: RsPQIService(RS_SERVICE_TYPE_VOIP_PLUGIN,CONFIG_TYPE_VOIP_PLUGIN,0,handler), mVorsMtx("p3VoRS"), mLinkMgr(handler->getLinkMgr())
p3VoRS::p3VoRS(RsPluginHandler *handler,PluginNotifier *notifier)
: RsPQIService(RS_SERVICE_TYPE_VOIP_PLUGIN,CONFIG_TYPE_VOIP_PLUGIN,0,handler), mVorsMtx("p3VoRS"), mLinkMgr(handler->getLinkMgr()) , mNotify(notifier)
{
addSerialType(new RsVoipSerialiser());
@ -301,7 +302,19 @@ void p3VoRS::handleProtocol(RsVoipProtocolItem *item)
// we notify the notifier that something occurred.
// mNotify->notifyPluginAction(mPluginId, PluginSignalId, (void *)data_to_send_upward);
switch(item->protocol)
{
case RsVoipProtocolItem::VoipProtocol_Ring: std::cerr << "Received protocol ring item." << std::endl;
mNotify->notifyReceivedVoipInvite(item->PeerId());
break ;
case RsVoipProtocolItem::VoipProtocol_Ackn:
case RsVoipProtocolItem::VoipProtocol_Close:
default:
std::cerr << "Received protocol item # " << item->protocol << ": not handled yet ! Sorry" << std::endl;
break ;
}
}
void p3VoRS::handleData(RsVoipDataItem *item)
@ -321,7 +334,7 @@ void p3VoRS::handleData(RsVoipDataItem *item)
{
it->second.incoming_queue.push_back(item) ; // be careful with the delete action!
// notify->notifyPluginAction(mPluginId, PluginSignalId, (void *)data_to_send_upward);
mNotify->notifyReceivedVoipData(item->PeerId());
}
}

View File

@ -36,6 +36,7 @@
#include <interface/rsvoip.h>
class p3LinkMgr;
class PluginNotifier ;
class VorsPeerInfo
{
@ -67,7 +68,7 @@ class p3VoRS: public RsPQIService, public RsVoip
//, public p3Config, public pqiMonitor
{
public:
p3VoRS(RsPluginHandler *cm);
p3VoRS(RsPluginHandler *cm,PluginNotifier *);
/***** overloaded from rsVoip *****/
@ -127,7 +128,7 @@ class p3VoRS: public RsPQIService, public RsVoip
virtual bool loadList(std::list<RsItem*>& load) ;
private:
int sendPackets();
int sendPackets();
void sendPingMeasurements();
int processIncoming();
@ -152,6 +153,7 @@ class p3VoRS: public RsPQIService, public RsVoip
uint32_t mCounter;
p3LinkMgr *mLinkMgr;
PluginNotifier *mNotify ;
int _atransmit ;
int _voice_hold ;