diff --git a/libretroshare/src/rsiface/rsstatus.h b/libretroshare/src/rsiface/rsstatus.h index 8ced61bc5..537aac1ce 100644 --- a/libretroshare/src/rsiface/rsstatus.h +++ b/libretroshare/src/rsiface/rsstatus.h @@ -35,12 +35,14 @@ extern RsStatus *rsStatus; #include #include -const uint32_t RS_STATUS_OFFLINE = 0x0001; -const uint32_t RS_STATUS_AWAY = 0x0002; -const uint32_t RS_STATUS_BUSY = 0x0003; -const uint32_t RS_STATUS_ONLINE = 0x0004; - +const uint32_t RS_STATUS_AWAY = 0x0001; +const uint32_t RS_STATUS_BUSY = 0x0002; +const uint32_t RS_STATUS_ONLINE = 0x0003; +//! data object for peer status information +/*! + * data object used for peer status information + */ class StatusInfo { public: @@ -49,14 +51,39 @@ class StatusInfo time_t time_stamp; /// for owner time set, and for their peers time sent }; + +//! Interface to retroshare for Rs status +/*! + * Provides an interface for retroshare's status functionality + */ class RsStatus { public: -virtual bool getStatus(std::list& statusInfo) = 0; -virtual bool sendStatus(StatusInfo& statusInfo) = 0; -virtual bool statusAvailable() = 0; -virtual void getStatusString(uint32_t status, std::string& statusString) = 0; + /** + * This retrieves the status info on the client's peers + * @param statusInfo is populated with client's peer's status + */ + virtual bool getStatus(std::list& statusInfo) = 0; + + /** + * send the client's status to his/her peers + * @param statusInfo the status of the peers + * @return will return false if status info does not belong to client + */ + virtual bool sendStatus(StatusInfo& statusInfo) = 0; + + /** + * checks to see if any status items have been received + */ + virtual bool statusAvailable() = 0; + + /** + * translates the status field of a peer to a string + * @status the status id that needs to be translated + * @statusString the string translation is passed here + */ + virtual void getStatusString(uint32_t status, std::string& statusString) = 0; }; diff --git a/libretroshare/src/rsserver/p3status.cc b/libretroshare/src/rsserver/p3status.cc index 73126246e..63656bc03 100644 --- a/libretroshare/src/rsserver/p3status.cc +++ b/libretroshare/src/rsserver/p3status.cc @@ -55,11 +55,7 @@ bool p3Status::statusAvailable(){ void p3Status::getStatusString(uint32_t status, std::string& statusString){ - if (status == RS_STATUS_OFFLINE){ - - statusString = "Offline"; - - }else if (status == RS_STATUS_AWAY){ + if (status == RS_STATUS_AWAY){ statusString = "Away"; diff --git a/libretroshare/src/services/p3statusservice.cc b/libretroshare/src/services/p3statusservice.cc index 69a567e28..ca80907f8 100644 --- a/libretroshare/src/services/p3statusservice.cc +++ b/libretroshare/src/services/p3statusservice.cc @@ -127,6 +127,7 @@ bool p3StatusService::getStatus(std::list& statusInfo) for(mit = mStatusInfoMap.begin(); mit != mStatusInfoMap.end(); mit++){ statusInfo.push_back(mit->second); } + } return true; @@ -142,18 +143,25 @@ bool p3StatusService::sendStatus(StatusInfo& statusInfo) if(statusInfo.id != mConnMgr->getOwnId()) return false; - mStatusInfoMap[statusInfo.id] = statusInfo; + // If your id is not set, set it + if(mStatusInfoMap.find(statusInfo.id) == mStatusInfoMap.end()){ + + std::pair pr(statusInfo.id, statusInfo); + mStatusInfoMap.insert(pr); + IndicateConfigChanged(); + }else + if(mStatusInfoMap[statusInfo.id].status != statusInfo.status){ + + IndicateConfigChanged(); + mStatusInfoMap[statusInfo.id] = statusInfo; + } + + mConnMgr->getOnlineList(onlineList); } - - - //statusItem->PeerId(statusInfo.id); - std::list::iterator it; - - #ifdef STATUS_DEBUG std::cerr << "p3StatusService::sendStatus() " << std::endl; std::cerr << statusInfo; @@ -252,25 +260,27 @@ bool p3StatusService::loadList(std::list load){ // load your status from last rs session StatusInfo own_info; - std::list::iterator it = load.begin(); + std::list::const_iterator it = load.begin(); if(it == load.end()){ std::cerr << "p3StatusService::loadList(): Failed to load " << std::endl; return false; } + for(; it != load.end(); it++){ RsStatusItem* own_status = dynamic_cast(*it); if(own_status != NULL){ - own_info.id = own_status->PeerId(); + own_info.id = mConnMgr->getOwnId(); own_info.status = own_status->status; own_info.time_stamp = own_status->sendTime; + delete own_status; { RsStackMutex stack(mStatusMtx); - std::pair pr(own_info.id, own_info); + std::pair pr(mConnMgr->getOwnId(), own_info); mStatusInfoMap.insert(pr); } @@ -280,6 +290,7 @@ bool p3StatusService::loadList(std::list load){ << std::endl; } + } return false; } diff --git a/libretroshare/src/services/p3statusservice.h b/libretroshare/src/services/p3statusservice.h index 552b837e2..41f180444 100644 --- a/libretroshare/src/services/p3statusservice.h +++ b/libretroshare/src/services/p3statusservice.h @@ -54,6 +54,9 @@ virtual int status(); /********* RsStatus ***********/ +/** + * Status is set to offline as default if no info received from relevant peer + */ virtual bool getStatus(std::list& statusInfo); virtual bool sendStatus(StatusInfo& statusInfo); virtual bool statusAvailable();