mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-17 19:09:29 -04:00
New methods for calculating the count of peers and messages. It should be faster than getting all data in std::list.
Now used in MainWindow.cpp, MessagesDialog.cpp and peerstatus.cpp void p3Peers::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount); void p3Msgs::getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox); git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2898 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e5667a915d
commit
84a87fa11b
15 changed files with 99 additions and 61 deletions
|
@ -1523,6 +1523,23 @@ void p3ConnectMgr::getFriendList(std::list<std::string> &peers)
|
|||
//}
|
||||
|
||||
|
||||
void p3ConnectMgr::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount)
|
||||
{
|
||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
if (pnFriendCount) *pnFriendCount = mFriendList.size();
|
||||
if (pnOnlineCount) {
|
||||
*pnOnlineCount = 0;
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++) {
|
||||
if (it->second.state & RS_PEER_S_CONNECTED) {
|
||||
(*pnOnlineCount)++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool p3ConnectMgr::connectAttempt(std::string id, struct sockaddr_in &addr,
|
||||
uint32_t &delay, uint32_t &period, uint32_t &type)
|
||||
|
|
|
@ -258,6 +258,7 @@ bool getOthersNetStatus(std::string id, peerConnectState &state);
|
|||
void getOnlineList(std::list<std::string> &ssl_peers);
|
||||
void getFriendList(std::list<std::string> &ssl_peers);
|
||||
//void getOthersList(std::list<std::string> &peers); /deprecated
|
||||
void getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount);
|
||||
|
||||
|
||||
/**************** handle monitors *****************/
|
||||
|
|
|
@ -121,6 +121,7 @@ virtual ~RsMsgs() { return; }
|
|||
|
||||
virtual bool getMessageSummaries(std::list<MsgInfoSummary> &msgList) = 0;
|
||||
virtual bool getMessage(std::string mId, MessageInfo &msg) = 0;
|
||||
virtual void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox) = 0;
|
||||
|
||||
virtual bool MessageSend(MessageInfo &info) = 0;
|
||||
virtual bool MessageDelete(std::string mid) = 0;
|
||||
|
|
|
@ -138,6 +138,7 @@ virtual std::string getOwnId() = 0;
|
|||
virtual bool getOnlineList(std::list<std::string> &ssl_ids) = 0;
|
||||
virtual bool getFriendList(std::list<std::string> &ssl_ids) = 0;
|
||||
//virtual bool getOthersList(std::list<std::string> &ssl_ids) = 0;
|
||||
virtual void getPeerCount (unsigned int *pnFriendCount, unsigned int *pnnOnlineCount) = 0;
|
||||
|
||||
virtual bool isOnline(std::string ssl_id) = 0;
|
||||
virtual bool isFriend(std::string ssl_id) = 0;
|
||||
|
|
|
@ -62,7 +62,10 @@ bool p3Msgs::getMessage(std::string mid, MessageInfo &msg)
|
|||
return mMsgSrv->getMessage(mid, msg);
|
||||
}
|
||||
|
||||
|
||||
void p3Msgs::getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox)
|
||||
{
|
||||
mMsgSrv->getMessageCount(pnInbox, pnInboxNew, pnOutbox, pnDraftbox, pnSentbox);
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
/****************************************/
|
||||
|
|
|
@ -55,6 +55,7 @@ class p3Msgs: public RsMsgs
|
|||
*/
|
||||
virtual bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
|
||||
virtual bool getMessage(std::string mId, MessageInfo &msg);
|
||||
virtual void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox);
|
||||
|
||||
virtual bool MessageSend(MessageInfo &info);
|
||||
virtual bool MessageDelete(std::string mid);
|
||||
|
|
|
@ -221,6 +221,16 @@ bool p3Peers::getFriendList(std::list<std::string> &ids)
|
|||
// return true;
|
||||
//}
|
||||
|
||||
void p3Peers::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getPeerCount()" << std::endl;
|
||||
#endif
|
||||
|
||||
/* get from mConnectMgr */
|
||||
mConnMgr->getPeerCount(pnFriendCount, pnOnlineCount);
|
||||
}
|
||||
|
||||
bool p3Peers::isOnline(std::string id)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
|
|
|
@ -46,6 +46,7 @@ virtual std::string getOwnId();
|
|||
virtual bool getOnlineList(std::list<std::string> &ids);
|
||||
virtual bool getFriendList(std::list<std::string> &ids);
|
||||
//virtual bool getOthersList(std::list<std::string> &ids);
|
||||
virtual void getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount);
|
||||
|
||||
virtual bool isOnline(std::string id);
|
||||
virtual bool isFriend(std::string id);
|
||||
|
|
|
@ -455,7 +455,7 @@ bool p3MsgService::getMessageSummaries(std::list<MsgInfoSummary> &msgList)
|
|||
initRsMIS(mit->second, mis);
|
||||
msgList.push_back(mis);
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -481,6 +481,44 @@ bool p3MsgService::getMessage(std::string mId, MessageInfo &msg)
|
|||
return true;
|
||||
}
|
||||
|
||||
void p3MsgService::getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox)
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
if (pnInbox) *pnInbox = 0;
|
||||
if (pnInboxNew) *pnInboxNew = 0;
|
||||
if (pnOutbox) *pnOutbox = 0;
|
||||
if (pnDraftbox) *pnDraftbox = 0;
|
||||
if (pnSentbox) *pnSentbox = 0;
|
||||
|
||||
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
||||
std::map<uint32_t, RsMsgItem *> *apMsg [2] = { &imsg, &msgOutgoing };
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (mit = apMsg [i]->begin(); mit != apMsg [i]->end(); mit++) {
|
||||
MsgInfoSummary mis;
|
||||
initRsMIS(mit->second, mis);
|
||||
|
||||
switch (mis.msgflags & RS_MSG_BOXMASK) {
|
||||
case RS_MSG_INBOX:
|
||||
if (pnInbox) (*pnInbox)++;
|
||||
if ((mis.msgflags & RS_MSG_NEW) == RS_MSG_NEW) {
|
||||
if (pnInboxNew) (*pnInboxNew)++;
|
||||
}
|
||||
break;
|
||||
case RS_MSG_OUTBOX:
|
||||
if (pnOutbox) (*pnOutbox)++;
|
||||
break;
|
||||
case RS_MSG_DRAFTBOX:
|
||||
if (pnDraftbox) (*pnDraftbox)++;
|
||||
break;
|
||||
case RS_MSG_SENTBOX:
|
||||
if (pnSentbox) (*pnSentbox)++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* remove based on the unique mid (stored in sid) */
|
||||
bool p3MsgService::removeMsgId(std::string mid)
|
||||
|
|
|
@ -57,6 +57,7 @@ bool getMessageNotifications(std::list<MsgInfoSummary> ¬eList);
|
|||
|
||||
bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
|
||||
bool getMessage(std::string mid, MessageInfo &msg);
|
||||
void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox);
|
||||
|
||||
bool removeMsgId(std::string mid);
|
||||
bool markMsgIdRead(std::string mid);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue