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
This commit is contained in:
chrisparker126 2012-10-15 20:31:56 +00:00
parent 57407fb8ae
commit fed6507320
4 changed files with 129 additions and 37 deletions

View File

@ -78,6 +78,8 @@ void RsGenExchange::tick()
mNotifications.clear();
}
// implemented service tick function
service_tick();
}
bool RsGenExchange::acknowledgeTokenMsg(const uint32_t& token,

View File

@ -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

View File

@ -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<RsGxsGroupId>& grpIds)
void RsGxsIfaceImpl::groupsChanged(std::list<RsGxsGroupId> &grpIds)
{
RsStackMutex stack(mGxsIfaceMutex);
while(!mGroupChange.empty())
{
RsGxsGroupChange* gc = mGroupChange.back();
std::list<RsGxsGroupId>& gList = gc->grpIdList;
std::list<RsGxsGroupId>::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<RsGxsGroupId,
std::vector<RsGxsMessageId> >& msgs)
bool changed = (!mGroupChange.empty() || !mMsgChange.empty());
return changed;
}
void RsGxsIfaceImpl::msgsChanged(std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgs)
{
RsStackMutex stack(mGxsIfaceMutex);
while(!mMsgChange.empty())
{
RsGxsMsgChange* mc = mMsgChange.back();
msgs = mc->msgChangeMap;
mMsgChange.pop_back();
delete mc;
}
}
void RsGxsIfaceImpl::receiveChanges(std::vector<RsGxsNotify *> &changes)
{
RsStackMutex stack(mGxsIfaceMutex);
std::vector<RsGxsNotify*>::iterator vit = changes.begin();
for(; vit != changes.end(); vit++)
{
RsGxsNotify* n = *vit;
RsGxsGroupChange* gc;
RsGxsMsgChange* mc;
if((mc = dynamic_cast<RsGxsMsgChange*>(n)) != NULL)
{
mMsgChange.push_back(mc);
}
else if((gc = dynamic_cast<RsGxsGroupChange*>(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<RsGxsGroupId> &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<RsGroupMetaData> &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<RsGxsGroupId, RsGxsMessageId>& msgId)
{
return false;
return mGxs->acknowledgeTokenMsg(token, msgId);
}
bool RsGxsIfaceImpl::acknowledgeGrp(const uint32_t& token, RsGxsGroupId& grpId)
{
return false;
return mGxs->acknowledgeTokenGrp(token, grpId);
}

View File

@ -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<RsGxsNotify*>& 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<RsGxsGroupId>& grpIds);
virtual void groupsChanged(std::list<RsGxsGroupId>& 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<RsGxsGroupId,
virtual void msgsChanged(std::map<RsGxsGroupId,
std::vector<RsGxsMessageId> >& 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<RsGxsGroupId> &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<RsGxsGroupChange*> mGroupChange;
std::vector<RsGxsMsgChange*> mMsgChange;
RsMutex mGxsIfaceMutex;
};
#endif // RSGXSIFACEIMPL_H