mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-09 15:12:43 -04:00
finished status service
- can be called use rs interface rstatus - does not save last rs session status yet git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2715 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
2eb3d560e0
commit
300952d2a6
11 changed files with 560 additions and 19 deletions
|
@ -146,7 +146,8 @@ virtual ~CacheSource() {}
|
||||||
*/
|
*/
|
||||||
virtual bool cachesAvailable(RsPeerId pid, std::map<CacheId, CacheData> &ids);
|
virtual bool cachesAvailable(RsPeerId pid, std::map<CacheId, CacheData> &ids);
|
||||||
|
|
||||||
/* function called at startup to load from
|
/*!
|
||||||
|
* function called at startup to load from
|
||||||
* configuration file....
|
* configuration file....
|
||||||
* to be overloaded by inherited class
|
* to be overloaded by inherited class
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -16,7 +16,7 @@ debug {
|
||||||
# DEFINES *= NET_DEBUG
|
# DEFINES *= NET_DEBUG
|
||||||
# DEFINES *= DISTRIB_DEBUG
|
# DEFINES *= DISTRIB_DEBUG
|
||||||
# DEFINES *= P3TURTLE_DEBUG FT_DEBUG DEBUG_FTCHUNK MPLEX_DEBUG
|
# DEFINES *= P3TURTLE_DEBUG FT_DEBUG DEBUG_FTCHUNK MPLEX_DEBUG
|
||||||
# DEFINES *= CONN_DEBUG
|
# DEFINES *= STATUS_DEBUG SERV_DEBUG RSSERIAL_DEBUG #CONN_DEBUG
|
||||||
|
|
||||||
QMAKE_CXXFLAGS -= -fomit-frame-pointer
|
QMAKE_CXXFLAGS -= -fomit-frame-pointer
|
||||||
QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer
|
QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer
|
||||||
|
@ -238,6 +238,7 @@ HEADERS += dbase/cachestrapper.h \
|
||||||
rsserver/p3peers.h \
|
rsserver/p3peers.h \
|
||||||
rsserver/p3photo.h \
|
rsserver/p3photo.h \
|
||||||
rsserver/p3rank.h \
|
rsserver/p3rank.h \
|
||||||
|
rsserver/p3status.h \
|
||||||
serialiser/rsbaseitems.h \
|
serialiser/rsbaseitems.h \
|
||||||
serialiser/rsbaseserial.h \
|
serialiser/rsbaseserial.h \
|
||||||
serialiser/rschannelitems.h \
|
serialiser/rschannelitems.h \
|
||||||
|
@ -275,7 +276,7 @@ HEADERS += dbase/cachestrapper.h \
|
||||||
services/p3blogs.h \
|
services/p3blogs.h \
|
||||||
services/p3ranking.h \
|
services/p3ranking.h \
|
||||||
services/p3service.h \
|
services/p3service.h \
|
||||||
services/p3status.h \
|
services/p3statusservice.h \
|
||||||
turtle/p3turtle.h \
|
turtle/p3turtle.h \
|
||||||
turtle/turtletypes.h \
|
turtle/turtletypes.h \
|
||||||
turtle/rsturtleitem.h \
|
turtle/rsturtleitem.h \
|
||||||
|
@ -312,6 +313,7 @@ SOURCES += \
|
||||||
rsserver/p3photo.cc \
|
rsserver/p3photo.cc \
|
||||||
rsserver/p3rank.cc \
|
rsserver/p3rank.cc \
|
||||||
rsserver/p3peers.cc \
|
rsserver/p3peers.cc \
|
||||||
|
rsserver/p3status.cc \
|
||||||
ft/ftcontroller.cc \
|
ft/ftcontroller.cc \
|
||||||
ft/ftserver.cc \
|
ft/ftserver.cc \
|
||||||
ft/ftdbase.cc \
|
ft/ftdbase.cc \
|
||||||
|
@ -333,7 +335,7 @@ SOURCES += \
|
||||||
services/p3forums.cc \
|
services/p3forums.cc \
|
||||||
services/p3blogs.cc \
|
services/p3blogs.cc \
|
||||||
services/p3Qblog.cc \
|
services/p3Qblog.cc \
|
||||||
services/p3status.cc \
|
services/p3statusservice.cc \
|
||||||
services/p3distrib.cc \
|
services/p3distrib.cc \
|
||||||
services/p3photoservice.cc \
|
services/p3photoservice.cc \
|
||||||
services/p3disc.cc \
|
services/p3disc.cc \
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*
|
*
|
||||||
* RetroShare C++ .
|
* RetroShare C++ .
|
||||||
*
|
*
|
||||||
* Copyright 2007-2008 by Vinny Do.
|
* Copyright 2007-2008 by Vinny Do, Chris Evi-Parker.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
@ -33,29 +33,32 @@ extern RsStatus *rsStatus;
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
const uint32_t RS_STATUS_OFFLINE = 0x0001;
|
const uint32_t RS_STATUS_OFFLINE = 0x0001;
|
||||||
const uint32_t RS_STATUS_AWAY = 0x0002;
|
const uint32_t RS_STATUS_AWAY = 0x0002;
|
||||||
const uint32_t RS_STATUS_BUSY = 0x0003;
|
const uint32_t RS_STATUS_BUSY = 0x0003;
|
||||||
const uint32_t RS_STATUS_ONLINE = 0x0004;
|
const uint32_t RS_STATUS_ONLINE = 0x0004;
|
||||||
|
|
||||||
std::string RsStatusString(uint32_t status);
|
|
||||||
|
|
||||||
class StatusInfo
|
class StatusInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string id;
|
std::string id;
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
|
time_t time_stamp; /// for owner time set, and for their peers time sent
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsStatus
|
class RsStatus
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool getStatus(std::string id, StatusInfo& statusInfo) = 0;
|
virtual bool getStatus(std::list<StatusInfo>& statusInfo) = 0;
|
||||||
virtual bool setStatus(StatusInfo& statusInfo) = 0;
|
virtual bool sendStatus(StatusInfo& statusInfo) = 0;
|
||||||
|
virtual bool statusAvailable() = 0;
|
||||||
|
|
||||||
|
virtual void getStatusString(uint32_t status, std::string& statusString) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& out, const StatusInfo& statusInfo);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include "services/p3ranking.h"
|
#include "services/p3ranking.h"
|
||||||
#include "services/p3Qblog.h"
|
#include "services/p3Qblog.h"
|
||||||
#include "services/p3blogs.h"
|
#include "services/p3blogs.h"
|
||||||
|
#include "services/p3statusservice.h"
|
||||||
|
|
||||||
|
|
||||||
/* The Main Interface Class - for controlling the server */
|
/* The Main Interface Class - for controlling the server */
|
||||||
|
@ -172,6 +173,7 @@ class RsServer: public RsControl, public RsThread
|
||||||
p3disc *ad;
|
p3disc *ad;
|
||||||
p3MsgService *msgSrv;
|
p3MsgService *msgSrv;
|
||||||
p3ChatService *chatSrv;
|
p3ChatService *chatSrv;
|
||||||
|
p3StatusService *mStatusSrv;
|
||||||
|
|
||||||
/* caches (that need ticking) */
|
/* caches (that need ticking) */
|
||||||
p3Ranking *mRanking;
|
p3Ranking *mRanking;
|
||||||
|
|
76
libretroshare/src/rsserver/p3status.cc
Normal file
76
libretroshare/src/rsserver/p3status.cc
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* libretroshare/src/rsserver: p3msgs.h
|
||||||
|
*
|
||||||
|
* RetroShare C++ Interface.
|
||||||
|
*
|
||||||
|
* Copyright 2007-2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "p3status.h"
|
||||||
|
#include "services/p3statusservice.h"
|
||||||
|
|
||||||
|
p3Status::p3Status(p3StatusService* statusSrv)
|
||||||
|
: mStatusSrv(statusSrv) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
p3Status::~p3Status(){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool p3Status::getStatus(std::list<StatusInfo >& statusInfo){
|
||||||
|
|
||||||
|
return mStatusSrv->getStatus(statusInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool p3Status::sendStatus(StatusInfo& statusInfo){
|
||||||
|
|
||||||
|
return mStatusSrv->sendStatus(statusInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool p3Status::statusAvailable(){
|
||||||
|
|
||||||
|
return mStatusSrv->statusAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3Status::getStatusString(uint32_t status, std::string& statusString){
|
||||||
|
|
||||||
|
if (status == RS_STATUS_OFFLINE){
|
||||||
|
|
||||||
|
statusString = "Offline";
|
||||||
|
|
||||||
|
}else if (status == RS_STATUS_AWAY){
|
||||||
|
|
||||||
|
statusString = "Away";
|
||||||
|
|
||||||
|
}else if (status == RS_STATUS_BUSY){
|
||||||
|
|
||||||
|
statusString = "Busy";
|
||||||
|
|
||||||
|
}else if (status == RS_STATUS_ONLINE){
|
||||||
|
|
||||||
|
statusString = "Online";
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
58
libretroshare/src/rsserver/p3status.h
Normal file
58
libretroshare/src/rsserver/p3status.h
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#ifndef RS_P3STATUS_INTERFACE_H
|
||||||
|
#define RS_P3STATUS_INTERFACE_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/rsserver: p3status.h
|
||||||
|
*
|
||||||
|
* RetroShare C++ Interface.
|
||||||
|
*
|
||||||
|
* Copyright 2007-2008 by Chris Evi-Parker.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "rsiface/rsstatus.h"
|
||||||
|
|
||||||
|
|
||||||
|
class p3StatusService;
|
||||||
|
|
||||||
|
//! Implements abstract interface rsStatus
|
||||||
|
/*!
|
||||||
|
* Interfaces with p3StatusService
|
||||||
|
*/
|
||||||
|
class p3Status : public RsStatus
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
p3Status(p3StatusService* statusSrv);
|
||||||
|
virtual ~p3Status();
|
||||||
|
|
||||||
|
|
||||||
|
virtual bool getStatus(std::list<StatusInfo>& statusInfo);
|
||||||
|
virtual bool sendStatus(StatusInfo& statusInfo);
|
||||||
|
virtual bool statusAvailable();
|
||||||
|
|
||||||
|
virtual void getStatusString(uint32_t status, std::string& statusString);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
p3StatusService* mStatusSrv;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* RS_P3STATUS_INTERFACE_H */
|
|
@ -1818,7 +1818,7 @@ RsTurtle *rsTurtle = NULL ;
|
||||||
#include "services/p3photoservice.h"
|
#include "services/p3photoservice.h"
|
||||||
#include "services/p3forums.h"
|
#include "services/p3forums.h"
|
||||||
#include "services/p3channels.h"
|
#include "services/p3channels.h"
|
||||||
#include "services/p3status.h"
|
#include "services/p3statusservice.h"
|
||||||
#include "services/p3Qblog.h"
|
#include "services/p3Qblog.h"
|
||||||
#include "services/p3blogs.h"
|
#include "services/p3blogs.h"
|
||||||
#include "turtle/p3turtle.h"
|
#include "turtle/p3turtle.h"
|
||||||
|
@ -1839,6 +1839,7 @@ RsTurtle *rsTurtle = NULL ;
|
||||||
#include "rsserver/p3discovery.h"
|
#include "rsserver/p3discovery.h"
|
||||||
#include "rsserver/p3photo.h"
|
#include "rsserver/p3photo.h"
|
||||||
#include "rsserver/p3blog.h"
|
#include "rsserver/p3blog.h"
|
||||||
|
#include "rsserver/p3status.h"
|
||||||
#include "rsiface/rsgame.h"
|
#include "rsiface/rsgame.h"
|
||||||
|
|
||||||
#include "pqi/p3notify.h" // HACK - moved to pqi for compilation order.
|
#include "pqi/p3notify.h" // HACK - moved to pqi for compilation order.
|
||||||
|
@ -1848,7 +1849,7 @@ RsTurtle *rsTurtle = NULL ;
|
||||||
#define RS_RELEASE 1
|
#define RS_RELEASE 1
|
||||||
****/
|
****/
|
||||||
|
|
||||||
#define RS_RELEASE 1
|
//#define RS_RELEASE 1
|
||||||
|
|
||||||
|
|
||||||
RsControl *createRsControl(RsIface &iface, NotifyBase ¬ify)
|
RsControl *createRsControl(RsIface &iface, NotifyBase ¬ify)
|
||||||
|
@ -1975,6 +1976,7 @@ int RsServer::StartupRetroShare()
|
||||||
ad = new p3disc(mConnMgr, pqih);
|
ad = new p3disc(mConnMgr, pqih);
|
||||||
msgSrv = new p3MsgService(mConnMgr);
|
msgSrv = new p3MsgService(mConnMgr);
|
||||||
chatSrv = new p3ChatService(mConnMgr);
|
chatSrv = new p3ChatService(mConnMgr);
|
||||||
|
mStatusSrv = new p3StatusService(mConnMgr);
|
||||||
|
|
||||||
p3tunnel *tn = new p3tunnel(mConnMgr, pqih);
|
p3tunnel *tn = new p3tunnel(mConnMgr, pqih);
|
||||||
pqih -> addService(tn);
|
pqih -> addService(tn);
|
||||||
|
@ -1988,6 +1990,7 @@ int RsServer::StartupRetroShare()
|
||||||
pqih -> addService(ad);
|
pqih -> addService(ad);
|
||||||
pqih -> addService(msgSrv);
|
pqih -> addService(msgSrv);
|
||||||
pqih -> addService(chatSrv);
|
pqih -> addService(chatSrv);
|
||||||
|
pqih ->addService(mStatusSrv);
|
||||||
|
|
||||||
/* create Cache Services */
|
/* create Cache Services */
|
||||||
std::string config_dir = RsInitConfig::configDir;
|
std::string config_dir = RsInitConfig::configDir;
|
||||||
|
@ -2091,6 +2094,7 @@ int RsServer::StartupRetroShare()
|
||||||
mConfigMgr->addConfiguration("channels.cfg", mChannels);
|
mConfigMgr->addConfiguration("channels.cfg", mChannels);
|
||||||
mConfigMgr->addConfiguration("turtle.cfg", tr);
|
mConfigMgr->addConfiguration("turtle.cfg", tr);
|
||||||
mConfigMgr->addConfiguration("p3disc.cfg", ad);
|
mConfigMgr->addConfiguration("p3disc.cfg", ad);
|
||||||
|
mConfigMgr->addConfiguration("p3Status.cfg", mStatusSrv);
|
||||||
|
|
||||||
ftserver->addConfiguration(mConfigMgr);
|
ftserver->addConfiguration(mConfigMgr);
|
||||||
|
|
||||||
|
@ -2207,7 +2211,7 @@ int RsServer::StartupRetroShare()
|
||||||
#ifndef RS_RELEASE
|
#ifndef RS_RELEASE
|
||||||
rsGameLauncher = gameLauncher;
|
rsGameLauncher = gameLauncher;
|
||||||
rsPhoto = new p3Photo(photoService);
|
rsPhoto = new p3Photo(photoService);
|
||||||
rsStatus = new p3Status();
|
rsStatus = new p3Status(mStatusSrv);
|
||||||
rsQblog = new p3Blog(mQblog);
|
rsQblog = new p3Blog(mQblog);
|
||||||
#else
|
#else
|
||||||
rsGameLauncher = NULL;
|
rsGameLauncher = NULL;
|
||||||
|
|
|
@ -26,8 +26,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include "serialiser/rsserviceids.h"
|
#include "serialiser/rsserviceids.h"
|
||||||
#include "serialiser/rsserial.h"
|
#include "serialiser/rsserial.h"
|
||||||
|
|
||||||
|
|
|
@ -57,14 +57,22 @@ class p3ChatService: public p3Service, public p3Config
|
||||||
void setOwnCustomStateString(const std::string&) ;
|
void setOwnCustomStateString(const std::string&) ;
|
||||||
std::string getOwnCustomStateString() ;
|
std::string getOwnCustomStateString() ;
|
||||||
|
|
||||||
/// gets the peer's avatar in jpeg format, if available. Null otherwise. Also asks the peer to send
|
/*! gets the peer's avatar in jpeg format, if available. Null otherwise. Also asks the peer to send
|
||||||
/// its avatar, if not already available. Creates a new unsigned char array. It's the caller's
|
* its avatar, if not already available. Creates a new unsigned char array. It's the caller's
|
||||||
/// responsibility to delete this ones used.
|
* responsibility to delete this ones used.
|
||||||
///
|
*/
|
||||||
void getAvatarJpegData(const std::string& peer_id,unsigned char *& data,int& size) ;
|
void getAvatarJpegData(const std::string& peer_id,unsigned char *& data,int& size) ;
|
||||||
|
|
||||||
/// Sets the avatar data and size. Data is copied, so should be destroyed by the caller.
|
/*!
|
||||||
|
* Sets the avatar data and size for client's account
|
||||||
|
* @param data is copied, so should be destroyed by the caller
|
||||||
|
*
|
||||||
|
*/
|
||||||
void setOwnAvatarJpegData(const unsigned char *data,int size) ;
|
void setOwnAvatarJpegData(const unsigned char *data,int size) ;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Gets the avatar data for clients account
|
||||||
|
*/
|
||||||
void getOwnAvatarJpegData(unsigned char *& data,int& size) ;
|
void getOwnAvatarJpegData(unsigned char *& data,int& size) ;
|
||||||
|
|
||||||
std::list<RsChatMsgItem *> getChatQueue();
|
std::list<RsChatMsgItem *> getChatQueue();
|
||||||
|
|
296
libretroshare/src/services/p3statusservice.cc
Normal file
296
libretroshare/src/services/p3statusservice.cc
Normal file
|
@ -0,0 +1,296 @@
|
||||||
|
/*
|
||||||
|
* libretroshare/src/services: p3statusservice.cc
|
||||||
|
*
|
||||||
|
* RetroShare C++ .
|
||||||
|
*
|
||||||
|
* Copyright 2008 by Vinny Do, Chris Evi-Parker.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "services/p3statusservice.h"
|
||||||
|
#include "serialiser/rsstatusitems.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& out, const StatusInfo& si)
|
||||||
|
{
|
||||||
|
out << "StatusInfo: " << std::endl;
|
||||||
|
out << "id: " << si.id << std::endl;
|
||||||
|
out << "status: " << si.status << std::endl;
|
||||||
|
out << "time_stamp: " << si.time_stamp << std::endl;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsStatus *rsStatus = NULL;
|
||||||
|
|
||||||
|
p3StatusService::p3StatusService(p3ConnectMgr *cm)
|
||||||
|
:p3Service(RS_SERVICE_TYPE_STATUS), p3Config(CONFIG_TYPE_STATUS), mConnMgr(cm)
|
||||||
|
{
|
||||||
|
addSerialType(new RsStatusSerialiser());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
p3StatusService::~p3StatusService()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool p3StatusService::getStatus(std::list<StatusInfo>& statusInfo)
|
||||||
|
{
|
||||||
|
|
||||||
|
time_t time_now = time(NULL);
|
||||||
|
|
||||||
|
#ifdef STATUS_DEBUG
|
||||||
|
std::cerr << "p3StatusService::getStatus() " << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
statusInfo.clear();
|
||||||
|
|
||||||
|
std::list<RsStatusItem* > status_items = getStatusQueue();
|
||||||
|
std::list<RsStatusItem* >::iterator rit;
|
||||||
|
std::map<std::string, StatusInfo>::iterator mit;
|
||||||
|
std::list<std::string> peers, peersOnline;
|
||||||
|
std::list<std::string>::iterator pit, pit_online;
|
||||||
|
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mStatusMtx);
|
||||||
|
|
||||||
|
/* first update map */
|
||||||
|
|
||||||
|
mConnMgr->getFriendList(peers);
|
||||||
|
mConnMgr->getOnlineList(peersOnline);
|
||||||
|
pit_online = peersOnline.begin();
|
||||||
|
|
||||||
|
// ensure member map is up to date with all client's peers
|
||||||
|
for(pit = peers.begin(); pit != peers.end(); pit++){
|
||||||
|
|
||||||
|
mit = mStatusInfoMap.find(*pit);
|
||||||
|
|
||||||
|
if(mit == mStatusInfoMap.end()){
|
||||||
|
|
||||||
|
StatusInfo info;
|
||||||
|
info.id = *pit;
|
||||||
|
info.status = RS_STATUS_ONLINE;
|
||||||
|
info.time_stamp = time_now;
|
||||||
|
std::pair<std::string, StatusInfo> pr(*pit, info);
|
||||||
|
mStatusInfoMap.insert(pr);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// now note members who have sent specific status updates
|
||||||
|
for(rit = status_items.begin(); rit != status_items.end(); rit++){
|
||||||
|
|
||||||
|
RsStatusItem* si = dynamic_cast<RsStatusItem* >(*rit);
|
||||||
|
|
||||||
|
if(si == NULL){
|
||||||
|
std::cerr << "p3Status::getStatus() " << "Failed to cast Item \n" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mit = mStatusInfoMap.find(si->PeerId());
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef STATUS_DEBUG
|
||||||
|
if(mit == mStatusInfoMap.end()){
|
||||||
|
std::cerr << "p3GetStatus() " << "Could not find Peer" << si->PeerId();
|
||||||
|
std::cerr << std::endl;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mit->second.id = si->PeerId();
|
||||||
|
mit->second.status = si->status;
|
||||||
|
mit->second.time_stamp = si->sendTime;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// then fill up statusInfo list with this information
|
||||||
|
for(mit = mStatusInfoMap.begin(); mit != mStatusInfoMap.end(); mit++){
|
||||||
|
statusInfo.push_back(mit->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool p3StatusService::sendStatus(StatusInfo& statusInfo)
|
||||||
|
{
|
||||||
|
std::list<std::string> onlineList;
|
||||||
|
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mStatusMtx);
|
||||||
|
|
||||||
|
if(statusInfo.id != mConnMgr->getOwnId())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
mStatusInfoMap[statusInfo.id] = statusInfo;
|
||||||
|
mConnMgr->getOnlineList(onlineList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//statusItem->PeerId(statusInfo.id);
|
||||||
|
|
||||||
|
std::list<std::string>::iterator it;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef STATUS_DEBUG
|
||||||
|
std::cerr << "p3StatusService::sendStatus() " << std::endl;
|
||||||
|
std::cerr << statusInfo;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// send to all peers online
|
||||||
|
for(it = onlineList.begin(); it != onlineList.end(); it++){
|
||||||
|
RsStatusItem* statusItem = new RsStatusItem();
|
||||||
|
statusItem->sendTime = time(NULL);
|
||||||
|
statusItem->status = statusInfo.status;
|
||||||
|
statusItem->PeerId(*it);
|
||||||
|
sendItem(statusItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool p3StatusService::statusAvailable(){
|
||||||
|
return receivedItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************/
|
||||||
|
|
||||||
|
std::list<RsStatusItem* > p3StatusService::getStatusQueue(){
|
||||||
|
|
||||||
|
|
||||||
|
time_t time_now = time(NULL);
|
||||||
|
|
||||||
|
RsItem* item;
|
||||||
|
std::list<RsStatusItem* > ilist;
|
||||||
|
|
||||||
|
while(NULL != (item = recvItem())){
|
||||||
|
|
||||||
|
RsStatusItem* status_item = dynamic_cast<RsStatusItem*>(item);
|
||||||
|
|
||||||
|
if(status_item != NULL){
|
||||||
|
#ifdef STATUS_DEBUG
|
||||||
|
std::cerr << "p3StatusService::getStatusQueue()" << std::endl;
|
||||||
|
std::cerr << "PeerId : " << status_item->PeerId() << std::endl;
|
||||||
|
std::cerr << "Status: " << status_item->status << std::endl;
|
||||||
|
std::cerr << "Got status Item" << std::endl;
|
||||||
|
#endif
|
||||||
|
status_item->recvTime = time_now;
|
||||||
|
ilist.push_back(status_item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ilist;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* p3Config */
|
||||||
|
|
||||||
|
RsSerialiser* p3StatusService::setupSerialiser(){
|
||||||
|
|
||||||
|
RsSerialiser *rss = new RsSerialiser;
|
||||||
|
rss->addSerialType(new RsStatusSerialiser);
|
||||||
|
|
||||||
|
return rss;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<RsItem*> p3StatusService::saveList(bool& cleanup){
|
||||||
|
|
||||||
|
// save your status before quiting
|
||||||
|
cleanup = true;
|
||||||
|
RsStatusItem* own_status = new RsStatusItem;
|
||||||
|
StatusInfo own_info;
|
||||||
|
std::list<RsItem*> ilist;
|
||||||
|
std::map<std::string, StatusInfo>::iterator it;
|
||||||
|
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mStatusMtx);
|
||||||
|
it = mStatusInfoMap.find(mConnMgr->getOwnId());
|
||||||
|
|
||||||
|
if(it == mStatusInfoMap.end()){
|
||||||
|
std::cerr << "p3StatusService::saveList() :" << "Did not find your status"
|
||||||
|
<< mConnMgr->getOwnId() << std::endl;
|
||||||
|
delete own_status;
|
||||||
|
return ilist;
|
||||||
|
}
|
||||||
|
|
||||||
|
own_info = it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
own_status->PeerId(own_info.id);
|
||||||
|
own_status->sendTime = own_info.time_stamp;
|
||||||
|
own_status->status = own_info.status;
|
||||||
|
|
||||||
|
ilist.push_back(own_status);
|
||||||
|
|
||||||
|
return ilist;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool p3StatusService::loadList(std::list<RsItem*> load){
|
||||||
|
|
||||||
|
// load your status from last rs session
|
||||||
|
StatusInfo own_info;
|
||||||
|
std::list<RsItem*>::iterator it = load.begin();
|
||||||
|
|
||||||
|
if(it == load.end()){
|
||||||
|
std::cerr << "p3StatusService::loadList(): Failed to load " << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsStatusItem* own_status = dynamic_cast<RsStatusItem* >(*it);
|
||||||
|
|
||||||
|
|
||||||
|
if(own_status != NULL){
|
||||||
|
|
||||||
|
own_info.id = own_status->PeerId();
|
||||||
|
own_info.status = own_status->status;
|
||||||
|
own_info.time_stamp = own_status->sendTime;
|
||||||
|
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mStatusMtx);
|
||||||
|
std::pair<std::string, StatusInfo> pr(own_info.id, own_info);
|
||||||
|
mStatusInfoMap.insert(pr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
std::cerr << "p3StatusService::loadList " << "Failed to load list "
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int p3StatusService::tick(){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int p3StatusService::status(){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
93
libretroshare/src/services/p3statusservice.h
Normal file
93
libretroshare/src/services/p3statusservice.h
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
#ifndef RS_P3_STATUS_INTERFACE_H
|
||||||
|
#define RS_P3_STATUS_INTERFACE_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/services: p3statusService.h
|
||||||
|
*
|
||||||
|
* RetroShare C++
|
||||||
|
*
|
||||||
|
* Copyright 2008 by Vinny Do, Chris Evi-Parker.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
#include "serialiser/rsstatusitems.h"
|
||||||
|
#include "rsiface/rsstatus.h"
|
||||||
|
#include "services/p3service.h"
|
||||||
|
#include "pqi/p3connmgr.h"
|
||||||
|
|
||||||
|
//! handles standard status messages (busy, away, online, offline) set by user
|
||||||
|
/*!
|
||||||
|
* The is a retroshare service which allows peers
|
||||||
|
* to inform each other about their status in a standard way, as opposed to
|
||||||
|
* custom string.
|
||||||
|
* @see rsiface/rsstatus.h for status constants
|
||||||
|
*/
|
||||||
|
class p3StatusService: public p3Service, public p3Config
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
p3StatusService(p3ConnectMgr* );
|
||||||
|
virtual ~p3StatusService();
|
||||||
|
|
||||||
|
/***** overloaded from p3Service *****/
|
||||||
|
virtual int tick();
|
||||||
|
virtual int status();
|
||||||
|
|
||||||
|
/********* RsStatus ***********/
|
||||||
|
|
||||||
|
virtual bool getStatus(std::list<StatusInfo>& statusInfo);
|
||||||
|
virtual bool sendStatus(StatusInfo& statusInfo);
|
||||||
|
virtual bool statusAvailable();
|
||||||
|
|
||||||
|
/******************************/
|
||||||
|
|
||||||
|
|
||||||
|
/** implemented from p3Config **/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @return The serialiser the enables storage of save info
|
||||||
|
*/
|
||||||
|
virtual RsSerialiser *setupSerialiser();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* This stores information on what your status was before you exited rs
|
||||||
|
*/
|
||||||
|
virtual std::list<RsItem*> saveList(bool& cleanup);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @param load Should contain a single item which is clients status from last rs session
|
||||||
|
*/
|
||||||
|
virtual bool loadList(std::list<RsItem*> load);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
virtual std::list<RsStatusItem* > getStatusQueue();
|
||||||
|
|
||||||
|
p3ConnectMgr *mConnMgr;
|
||||||
|
|
||||||
|
std::map<std::string, StatusInfo> mStatusInfoMap;
|
||||||
|
|
||||||
|
RsMutex mStatusMtx;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue