From fed65073208cbee8d72667386ea0749223259015 Mon Sep 17 00:00:00 2001 From: chrisparker126 Date: Mon, 15 Oct 2012 20:31:56 +0000 Subject: [PATCH] Implemented helper class RsGxsIfaceImpl Added calling of service_tick in RsGenExchange git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5681 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/gxs/rsgenexchange.cc | 2 + libretroshare/src/gxs/rsgenexchange.h | 24 ++++--- libretroshare/src/gxs/rsgxsifaceimpl.cc | 84 +++++++++++++++++++++---- libretroshare/src/gxs/rsgxsifaceimpl.h | 56 ++++++++++++----- 4 files changed, 129 insertions(+), 37 deletions(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index f84b2af42..58f9973d1 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -78,6 +78,8 @@ void RsGenExchange::tick() mNotifications.clear(); } + // implemented service tick function + service_tick(); } bool RsGenExchange::acknowledgeTokenMsg(const uint32_t& token, diff --git a/libretroshare/src/gxs/rsgenexchange.h b/libretroshare/src/gxs/rsgenexchange.h index dc66499d4..71a356b5a 100644 --- a/libretroshare/src/gxs/rsgenexchange.h +++ b/libretroshare/src/gxs/rsgenexchange.h @@ -112,7 +112,7 @@ public: */ RsTokenService* getTokenService(); -protected: +public: /** data access functions **/ @@ -146,6 +146,17 @@ protected: */ bool getMsgMeta(const uint32_t &token, GxsMsgMetaMap &msgInfo); + + + +protected: + + /*! + * @param grpItem + * @deprecated only here to temporarily to testing + */ + void createDummyGroup(RsGxsGrpItem* grpItem); + /*! * retrieves group data associated to a request token * @param token token to be redeemed for grpitem retrieval @@ -160,15 +171,6 @@ protected: */ bool getMsgData(const uint32_t &token, GxsMsgDataMap& msgItems); - - /*! - * @param grpItem - * @deprecated only here to temporarily to testing - */ - void createDummyGroup(RsGxsGrpItem* grpItem); - -protected: - /*! * Assigns a token value to passed integer * The status of the token can still be queried from request status feature @@ -248,6 +250,8 @@ protected: */ void publishMsg(uint32_t& token, RsGxsMsgItem* msgItem); +public: + /*! * sets the group subscribe flag * @param token this is set to token value associated to this request diff --git a/libretroshare/src/gxs/rsgxsifaceimpl.cc b/libretroshare/src/gxs/rsgxsifaceimpl.cc index b9f26dbf8..bfae83f85 100644 --- a/libretroshare/src/gxs/rsgxsifaceimpl.cc +++ b/libretroshare/src/gxs/rsgxsifaceimpl.cc @@ -1,23 +1,78 @@ #include "rsgxsifaceimpl.h" #include "gxs/rsgxs.h" +#include "gxs/rsgxsflags.h" RsGxsIfaceImpl::RsGxsIfaceImpl(RsGenExchange *gxs) - : mGxs(gxs) + : mGxsIfaceMutex("RsGxsIfaceImpl"), mGxs(gxs) { } -void RsGxsIfaceImpl::groupsChanged(std::list& grpIds) +void RsGxsIfaceImpl::groupsChanged(std::list &grpIds) { + RsStackMutex stack(mGxsIfaceMutex); + while(!mGroupChange.empty()) + { + RsGxsGroupChange* gc = mGroupChange.back(); + std::list& gList = gc->grpIdList; + std::list::iterator lit = gList.begin(); + for(; lit != gList.end(); lit++) + grpIds.push_back(*lit); + + mGroupChange.pop_back(); + delete gc; + } } +bool RsGxsIfaceImpl::updated() +{ + RsStackMutex stack(mGxsIfaceMutex); -void RsGxsIfaceImpl::msgsChanged(std::map >& msgs) + bool changed = (!mGroupChange.empty() || !mMsgChange.empty()); + + return changed; +} + +void RsGxsIfaceImpl::msgsChanged(std::map > &msgs) +{ + RsStackMutex stack(mGxsIfaceMutex); + + while(!mMsgChange.empty()) + { + RsGxsMsgChange* mc = mMsgChange.back(); + msgs = mc->msgChangeMap; + mMsgChange.pop_back(); + delete mc; + } +} + +void RsGxsIfaceImpl::receiveChanges(std::vector &changes) { + RsStackMutex stack(mGxsIfaceMutex); + + std::vector::iterator vit = changes.begin(); + + for(; vit != changes.end(); vit++) + { + RsGxsNotify* n = *vit; + RsGxsGroupChange* gc; + RsGxsMsgChange* mc; + if((mc = dynamic_cast(n)) != NULL) + { + mMsgChange.push_back(mc); + } + else if((gc = dynamic_cast(n)) != NULL) + { + mGroupChange.push_back(gc); + } + else + { + delete n; + } + } } RsTokenService* RsGxsIfaceImpl::getTokenService() @@ -29,14 +84,14 @@ bool RsGxsIfaceImpl::getGroupList(const uint32_t &token, std::list &groupIds) { - return false; + return mGxs->getGroupList(token, groupIds); } bool RsGxsIfaceImpl::getMsgList(const uint32_t &token, GxsMsgIdResult& msgIds) { - return false; + return mGxs->getMsgList(token, msgIds); } /* Generic Summary */ @@ -44,31 +99,34 @@ bool RsGxsIfaceImpl::getGroupSummary(const uint32_t &token, std::list &groupInfo) { - return false; + return mGxs->getGroupMeta(token, groupInfo); } bool RsGxsIfaceImpl::getMsgSummary(const uint32_t &token, GxsMsgMetaMap &msgInfo) { - return false; + return mGxs->getMsgMeta(token, msgInfo); } -bool RsGxsIfaceImpl::subscribeToAlbum(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe) +bool RsGxsIfaceImpl::subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe) { + if(subscribe) + mGxs->setGroupSubscribeFlag(token, grpId, GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED); + else + mGxs->setGroupSubscribeFlag(token, grpId, ~GXS_SERV::GROUP_SUBSCRIBE_MASK); - return false; - + return true; } bool RsGxsIfaceImpl::acknowledgeMsg(const uint32_t& token, std::pair& msgId) { - return false; + return mGxs->acknowledgeTokenMsg(token, msgId); } bool RsGxsIfaceImpl::acknowledgeGrp(const uint32_t& token, RsGxsGroupId& grpId) { - return false; + return mGxs->acknowledgeTokenGrp(token, grpId); } diff --git a/libretroshare/src/gxs/rsgxsifaceimpl.h b/libretroshare/src/gxs/rsgxsifaceimpl.h index d39060b8f..a1236421b 100644 --- a/libretroshare/src/gxs/rsgxsifaceimpl.h +++ b/libretroshare/src/gxs/rsgxsifaceimpl.h @@ -5,43 +5,68 @@ /*! * The simple idea of this class is to implement the simple interface functions - * of gen exchange + * of gen exchange. + * This class provides convenience implementations of: + * - Handle msg and group changes (client class must pass changes sent by RsGenExchange to it) + * - subscription to groups + * - retrieval of msgs and group ids and meta info */ class RsGxsIfaceImpl { public: + /*! + * + * @param gxs handle to RsGenExchange instance of service (Usually the service class itself) + */ RsGxsIfaceImpl(RsGenExchange* gxs); + /*! + * Gxs services should call this for automatic handling of + * changes, send + * @param changes + */ + void receiveChanges(std::vector& changes); /*! - * @return true if a change has occured + * Checks to see if a change has been received for + * for a message or group + * @return true if a change has occured for msg or group */ - bool updated(); + virtual bool updated(); public: - /** Requests **/ - /*! - * + * The groups changed. \n + * class can reimplement to use to tailor + * the group actually set for ui notification. + * If receivedChanges is not passed RsGxsNotify changes + * this function does nothing * @param grpIds */ - void groupsChanged(std::list& grpIds); + virtual void groupsChanged(std::list& grpIds); /*! - * + * The msg changed. \n + * class can reimplement to use to tailor + * the msg actually set for ui notification. + * If receivedChanges is not passed RsGxsNotify changes + * this function does nothing * @param msgs */ - void msgsChanged(std::map >& msgs); + /*! + * @return handle to token service for this GXS service + */ RsTokenService* getTokenService(); /* Generic Lists */ /*! - * + * Retrieve list of group ids associated to a request token * @param token token to be redeemed for this request * @param groupIds the ids return for given request token * @return false if request token is invalid, check token status for error report @@ -50,6 +75,7 @@ public: std::list &groupIds); /*! + * Retrieves list of msg ids associated to a request token * @param token token to be redeemed for this request * @param msgIds the ids return for given request token * @return false if request token is invalid, check token status for error report @@ -57,8 +83,6 @@ public: bool getMsgList(const uint32_t &token, GxsMsgIdResult& msgIds); - /* Generic Summary */ - /*! * @param token token to be redeemed for group summary request * @param groupInfo the ids returned for given request token @@ -81,7 +105,7 @@ public: * @param token token to redeem for acknowledgement * @param grpId the id of the group to subscribe to */ - virtual bool subscribeToAlbum(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe); + virtual bool subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe); /*! * This allows the client service to acknowledge that their msgs has @@ -102,10 +126,14 @@ public: bool acknowledgeGrp(const uint32_t& token, RsGxsGroupId& grpId); - private: RsGenExchange* mGxs; + + std::vector mGroupChange; + std::vector mMsgChange; + + RsMutex mGxsIfaceMutex; }; #endif // RSGXSIFACEIMPL_H