Start of Ice callbacks

git-svn-id: https://mumble.svn.sourceforge.net/svnroot/mumble/trunk@1509 05730e5d-ab1b-0410-a4ac-84af385074fa
This commit is contained in:
Thorvald Natvig 2009-02-10 13:01:12 +00:00
parent 6242768ab2
commit 8c97da4e69
5 changed files with 59 additions and 0 deletions

View File

@ -185,6 +185,21 @@ module Murmur
exception InvalidPlayerException extends MurmurException {};
/** This is thrown when you try to set an invalid texture. */
exception InvalidTextureException extends MurmurException {};
/** This is thrown when you supply an invalid callback. */
exception InvalidCallbackException extends MurmurException {};
/** Callback interface for servers. You can supply an implementation of this to receive notification
* messages from the server.
* If an added callback ever throws an exception or goes away, it will be automatically removed.
*/
["ami"] interface ServerCallback {
idempotent void newPlayer(Player p);
idempotent void changedPlayer(Player p);
idempotent void deletedPlayer(Player p);
idempotent void newChannel(Channel c);
idempotent void changedChannel(Channel c);
idempotent void deletedChannel(Channel c);
};
/** Per-server interface. This includes all methods for configuring and altering
* the state of a single virtual server. You can retrieve a pointer to this interface
@ -212,6 +227,18 @@ module Murmur
*/
idempotent int id();
/** Add a callback.
*
* @param cb Callback interface which receives messages.
*/
void addCallback(ServerCallback *cb) throws ServerBootedException, InvalidCallbackException;
/** Remove a callback.
*
* @param cb Callback interface to be removed.
*/
void removeCallback(ServerCallback *cb) throws ServerBootedException, InvalidCallbackException;
/** Retrieve configuration item.
* @param key Configuration key.
* @return Configuration value. If this is empty, see [Meta::getDefaultConf]

View File

@ -20,6 +20,9 @@ class ServerI : virtual public Server {
virtual void delete_async(const ::Murmur::AMD_Server_deletePtr&,
const Ice::Current&);
virtual void addCallback_async(const ::Murmur::AMD_Server_addCallbackPtr&, const ::Murmur::ServerCallbackPrx&, const ::Ice::Current&);
virtual void removeCallback_async(const ::Murmur::AMD_Server_removeCallbackPtr&, const ::Murmur::ServerCallbackPrx&, const ::Ice::Current&);
virtual void id_async(const ::Murmur::AMD_Server_idPtr&,
const Ice::Current&);

View File

@ -42,6 +42,7 @@ static MurmurIce *mi = NULL;
static Ice::ObjectPtr iopServer;
class IceEvent : public QEvent {
Q_DISABLE_COPY(IceEvent);
protected:
boost::function<void ()> func;
public:
@ -119,6 +120,12 @@ void MurmurIce::customEvent(QEvent *evt) {
}
}
void MurmurIce::serverDeleted(QObject *o) {
::Server *s = qobject_cast< ::Server *>(o);
if (s)
qmCallbacks.remove(s->iServerNum);
}
Ice::ObjectPtr ServerLocator::locate(const Ice::Current &, Ice::LocalObjectPtr &) {
return iopServer;
}
@ -258,6 +265,16 @@ static void impl_Server_delete(const ::Murmur::AMD_Server_deletePtr cb, int serv
cb->ice_response();
}
static void impl_Server_addCallback(const Murmur::AMD_Server_addCallbackPtr &cb, int server_id, const Murmur::ServerCallbackPrx& cbptr) {
NEED_SERVER;
mi->qmCallbacks[server_id].append(cbptr);
}
static void impl_Server_removeCallback(const Murmur::AMD_Server_removeCallbackPtr &cb, int server_id, const Murmur::ServerCallbackPrx& cbptr) {
NEED_SERVER;
mi->qmCallbacks[server_id].removeAll(cbptr);
}
static void impl_Server_id(const ::Murmur::AMD_Server_idPtr cb, int server_id) {
NEED_SERVER_EXISTS;
cb->ice_response(server_id);

View File

@ -35,6 +35,7 @@
#include <Ice/Ice.h>
#include <IceUtil/IceUtil.h>
#include "MurmurI.h"
#define ICE_QEVENT (QEvent::User + 959)
@ -48,7 +49,10 @@ class MurmurIce : public QObject {
Ice::CommunicatorPtr communicator;
void customEvent(QEvent *evt);
public:
QMap<int, QList< ::Murmur::ServerCallbackPrx> > qmCallbacks;
MurmurIce();
~MurmurIce();
public slots:
void serverDeleted(QObject *);
};
#endif

View File

@ -18,6 +18,14 @@ void ::Murmur::ServerI::id_async(const ::Murmur::AMD_Server_idPtr &cb, const ::I
IceEvent *ie = new IceEvent(boost::bind(&impl_Server_id, cb, QString::fromStdString(current.id.name).toInt()));
QCoreApplication::instance()->postEvent(mi, ie);
};
void ::Murmur::ServerI::addCallback_async(const ::Murmur::AMD_Server_addCallbackPtr &cb, const ::Murmur::ServerCallbackPrx& p1, const ::Ice::Current &current) {
IceEvent *ie = new IceEvent(boost::bind(&impl_Server_addCallback, cb, QString::fromStdString(current.id.name).toInt(), p1));
QCoreApplication::instance()->postEvent(mi, ie);
};
void ::Murmur::ServerI::removeCallback_async(const ::Murmur::AMD_Server_removeCallbackPtr &cb, const ::Murmur::ServerCallbackPrx& p1, const ::Ice::Current &current) {
IceEvent *ie = new IceEvent(boost::bind(&impl_Server_removeCallback, cb, QString::fromStdString(current.id.name).toInt(), p1));
QCoreApplication::instance()->postEvent(mi, ie);
};
void ::Murmur::ServerI::getConf_async(const ::Murmur::AMD_Server_getConfPtr &cb, const ::std::string& p1, const ::Ice::Current &current) {
IceEvent *ie = new IceEvent(boost::bind(&impl_Server_getConf, cb, QString::fromStdString(current.id.name).toInt(), p1));
QCoreApplication::instance()->postEvent(mi, ie);