RsAutoUpdatePage

- Changed the timer of RsAutoUpdatePage to a single-shot timer.
  The update can take longer than the given timer interval.

Changed status service:
- send status when the peer connects (new monitor)
- send status to all online peers only when user changed it (not in every timer tick)

MessengerWindow:
- remove load and save of custom state string in settings

p3ChatService::sendCustomState
- send empty custom state string too

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3307 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-07-20 19:45:07 +00:00
parent f7282edf33
commit e3e4c97369
15 changed files with 145 additions and 133 deletions

View file

@ -47,6 +47,13 @@ const uint32_t RS_STATUS_INACTIVE = 0x0004;
*/
class StatusInfo
{
public:
StatusInfo()
{
status = 0;
time_stamp = 0;
}
public:
std::string id;
uint32_t status;
@ -62,6 +69,12 @@ class RsStatus
{
public:
/**
* This retrieves the own status info
* @param statusInfo is populated with own status
*/
virtual bool getOwnStatus(StatusInfo& statusInfo) = 0;
/**
* This retrieves the status info on the client's peers
* @param statusInfo is populated with client's peer's status
@ -70,10 +83,11 @@ class RsStatus
/**
* send the client's status to his/her peers
* @param statusInfo the status of the peers
* @param id the peer to send the status (empty, send to all)
* @param status the status of the peers
* @return will return false if status info does not belong to client
*/
virtual bool sendStatus(StatusInfo& statusInfo) = 0;
virtual bool sendStatus(std::string id, uint32_t status) = 0;
/**
* checks to see if any status items have been received

View file

@ -37,15 +37,19 @@ p3Status::~p3Status(){
return;
}
bool p3Status::getOwnStatus(StatusInfo& statusInfo){
return mStatusSrv->getOwnStatus(statusInfo);
}
bool p3Status::getStatus(std::list<StatusInfo >& statusInfo){
return mStatusSrv->getStatus(statusInfo);
}
bool p3Status::sendStatus(std::string id, uint32_t status){
bool p3Status::sendStatus(StatusInfo& statusInfo){
return mStatusSrv->sendStatus(statusInfo);
return mStatusSrv->sendStatus(id, status);
}
bool p3Status::statusAvailable(){

View file

@ -43,8 +43,9 @@ public:
virtual ~p3Status();
virtual bool getOwnStatus(StatusInfo& statusInfo);
virtual bool getStatus(std::list<StatusInfo>& statusInfo);
virtual bool sendStatus(StatusInfo& statusInfo);
virtual bool sendStatus(std::string id, uint32_t status);
virtual bool statusAvailable();
virtual void getStatusString(uint32_t status, std::string& statusString);

View file

@ -2243,6 +2243,7 @@ int RsServer::StartupRetroShare()
mConnMgr->addMonitor(mCacheStrapper);
mConnMgr->addMonitor(ad);
mConnMgr->addMonitor(msgSrv);
mConnMgr->addMonitor(mStatusSrv);
/* must also add the controller as a Monitor...
* a little hack to get it to work.

View file

@ -654,16 +654,10 @@ void p3ChatService::sendCustomState(const std::string& peer_id){
std::cerr << "p3chatservice: sending requested status string for peer " << peer_id << std::endl ;
#endif
if(_custom_status_string != ""){
RsChatStatusItem *cs = makeOwnCustomStateStringItem();
cs->PeerId(peer_id);
RsChatStatusItem *cs = makeOwnCustomStateStringItem();
cs->PeerId(peer_id);
sendItem(cs);
}else{
#ifdef CHAT_DEBUG
std::cerr << "doing nothing" << std::endl;
#endif
}
sendItem(cs);
}
bool p3ChatService::loadList(std::list<RsItem*> load)

View file

@ -53,6 +53,23 @@ p3StatusService::~p3StatusService()
{
}
bool p3StatusService::getOwnStatus(StatusInfo& statusInfo)
{
std::map<std::string, StatusInfo>::iterator it;
std::string ownId = mConnMgr->getOwnId();
RsStackMutex stack(mStatusMtx);
it = mStatusInfoMap.find(ownId);
if (it == mStatusInfoMap.end()){
std::cerr << "p3StatusService::saveList() :" << "Did not find your status" << ownId << std::endl;
return false;
}
statusInfo = it->second;
return true;
}
bool p3StatusService::getStatus(std::list<StatusInfo>& statusInfo)
{
@ -128,15 +145,17 @@ bool p3StatusService::getStatus(std::list<StatusInfo>& statusInfo)
return true;
}
bool p3StatusService::sendStatus(StatusInfo& statusInfo)
/* id = "", status is sent to all online peers */
bool p3StatusService::sendStatus(const std::string &id, uint32_t status)
{
StatusInfo statusInfo;
std::list<std::string> onlineList;
{
RsStackMutex stack(mStatusMtx);
if(statusInfo.id != mConnMgr->getOwnId())
return false;
statusInfo.id = mConnMgr->getOwnId();
statusInfo.status = status;
// don't save inactive status
if(statusInfo.status != RS_STATUS_INACTIVE){
@ -147,15 +166,18 @@ bool p3StatusService::sendStatus(StatusInfo& statusInfo)
std::pair<std::string, StatusInfo> pr(statusInfo.id, statusInfo);
mStatusInfoMap.insert(pr);
IndicateConfigChanged();
}else
if(mStatusInfoMap[statusInfo.id].status != statusInfo.status){
} else if(mStatusInfoMap[statusInfo.id].status != statusInfo.status){
IndicateConfigChanged();
mStatusInfoMap[statusInfo.id] = statusInfo;
}
}
mConnMgr->getOnlineList(onlineList);
if (id.empty()) {
mConnMgr->getOnlineList(onlineList);
} else {
onlineList.push_back(id);
}
}
std::list<std::string>::iterator it;
@ -174,11 +196,9 @@ bool p3StatusService::sendStatus(StatusInfo& statusInfo)
sendItem(statusItem);
}
return true;
}
bool p3StatusService::statusAvailable(){
return receivedItems();
}
@ -301,5 +321,18 @@ int p3StatusService::status(){
return 1;
}
/*************** pqiMonitor callback ***********************/
void p3StatusService::statusChange(const std::list<pqipeer> &plist)
{
StatusInfo statusInfo;
std::list<pqipeer>::const_iterator it;
for (it = plist.begin(); it != plist.end(); it++) {
if ((it->state & RS_PEER_S_FRIEND) && (it->state & RS_PEER_CONNECTED)) {
/* send current status */
if (statusInfo.id.empty() == false || getOwnStatus(statusInfo)) {
sendStatus(it->id, statusInfo.status);
}
}
}
}

View file

@ -41,7 +41,7 @@
* custom string.
* @see rsiface/rsstatus.h for status constants
*/
class p3StatusService: public p3Service, public p3Config
class p3StatusService: public p3Service, public p3Config, public pqiMonitor
{
public:
@ -52,13 +52,18 @@ virtual ~p3StatusService();
virtual int tick();
virtual int status();
/*************** pqiMonitor callback ***********************/
virtual void statusChange(const std::list<pqipeer> &plist);
/********* RsStatus ***********/
/**
* Status is set to offline as default if no info received from relevant peer
*/
virtual bool getOwnStatus(StatusInfo& statusInfo);
virtual bool getStatus(std::list<StatusInfo>& statusInfo);
virtual bool sendStatus(StatusInfo& statusInfo);
/* id = "", status is sent to all online peers */
virtual bool sendStatus(const std::string &id, uint32_t status);
virtual bool statusAvailable();
/******************************/