2012-01-11 18:01:29 -05:00
|
|
|
#ifndef RSGDP_H
|
|
|
|
#define RSGDP_H
|
|
|
|
|
2012-01-15 08:07:31 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/gxp: gxp.h
|
|
|
|
*
|
|
|
|
* General Data service, interface for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2011-2011 by Robert Fernie, Evi-Parker Christopher
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-01-18 18:20:53 -05:00
|
|
|
#include <set>
|
|
|
|
#include <map>
|
2012-01-11 18:01:29 -05:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "inttypes.h"
|
2012-01-19 18:32:27 -05:00
|
|
|
#include "rsgnp.h"
|
2012-01-11 18:01:29 -05:00
|
|
|
|
2012-01-18 18:20:53 -05:00
|
|
|
typedef std::map<std::string, std::set<std::string> > MsgGrpId;
|
|
|
|
typedef std::map<std::string, std::set<RsGxsSignedMessage*> > SignedMsgGrp;
|
2012-01-15 08:07:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2012-01-19 18:32:27 -05:00
|
|
|
* The main role of GDP is the preparation and handing out of messages requested from
|
|
|
|
* RsGeneralExchangeService and RsGeneralExchangeService
|
2012-01-18 18:20:53 -05:00
|
|
|
*
|
2012-01-19 18:32:27 -05:00
|
|
|
* It also acts as a layer between RsGeneralStorageService and its parent RsGeneralExchangeService
|
2012-01-18 18:20:53 -05:00
|
|
|
* thus allowing for non-blocking requests, etc.
|
|
|
|
* It also provides caching ability
|
2012-01-19 18:32:27 -05:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Caching feature:
|
|
|
|
* - A cache index should be maintained which is faster than normal message request
|
|
|
|
* - This should allow fast retrieval of message based on grp id or msg id
|
2012-01-11 18:01:29 -05:00
|
|
|
*/
|
2012-01-18 18:20:53 -05:00
|
|
|
class RsGeneralDataService
|
2012-01-11 18:01:29 -05:00
|
|
|
{
|
|
|
|
public:
|
2012-01-18 18:20:53 -05:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Retrieves signed message
|
|
|
|
* @param msgGrp this contains grp and the message to retrieve
|
|
|
|
* @return request code to be redeemed later
|
|
|
|
*/
|
|
|
|
virtual int request(const MsgGrpId& msgGrp, SignedMsgGrp& result, bool decrypted) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* allows for more complex queries specific to the service
|
|
|
|
* Service should implement method taking case
|
|
|
|
* @param filter generally stores parameters needed for query
|
|
|
|
* @param cacheRequest set to true to cache the messages requested
|
|
|
|
* @return request code to be redeemed later
|
|
|
|
*/
|
|
|
|
virtual int request(RequestFilter* filter, SignedMsgGrp& msgs, bool cacheRequest) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* stores signed message
|
|
|
|
* @param msgs signed messages to store
|
|
|
|
*/
|
|
|
|
virtual bool store(SignedMsgGrp& msgs) = 0;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @param grpIds set with grpIds available from storage
|
|
|
|
* @return request code to be redeemed later
|
|
|
|
*/
|
|
|
|
virtual int getGroups(std::set<std::string>& grpIds) = 0;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
*
|
|
|
|
* @param msgIds gets message ids in storage
|
|
|
|
* @return request code to be redeemed later
|
|
|
|
*/
|
|
|
|
virtual int getMessageIds(std::set<std::string>& msgIds) = 0;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* caches message for faster retrieval later
|
|
|
|
* @return false if caching failed, msg may not exist, false otherwise
|
|
|
|
*/
|
|
|
|
virtual bool cacheMsg(const std::string& grpId, const std::string& msgId) = 0;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* caches all messages of this grpId for faster retrieval later
|
|
|
|
* @param grpId all message of this grpId are cached
|
|
|
|
* @return false if caching failed, msg may not exist, false otherwise
|
|
|
|
*/
|
|
|
|
bool cacheGrp(const std::string& grpId) = 0;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* checks if msg is cached
|
|
|
|
* @param msgId message to check if cached
|
|
|
|
* @param grpId
|
|
|
|
* @return false if caching failed, msg may not exist, false otherwise
|
|
|
|
*/
|
|
|
|
bool msgCached(const std::string& grpId, const std::string& msgId) = 0;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* check if messages of the grpId are cached
|
|
|
|
* @param grpId all message of this grpId are checked
|
|
|
|
* @return false if caching failed, msg may not exist, false otherwise
|
|
|
|
*/
|
|
|
|
bool grpCached(const std::string& grpId) = 0;
|
|
|
|
|
2012-01-11 18:01:29 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-01-18 18:20:53 -05:00
|
|
|
/*!
|
|
|
|
* Might be better off simply sending request codes
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class RequestFilter {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
virtual int code() = 0;
|
2012-01-11 18:01:29 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
2012-01-18 18:20:53 -05:00
|
|
|
*
|
2012-01-19 18:32:27 -05:00
|
|
|
* This is implemented by the concrete GXS class to represent and define how \n
|
|
|
|
* RsGxsSignedMessage is stored and retrieved from disk \n
|
2012-01-18 18:20:53 -05:00
|
|
|
* More complicated queries are enabled through the use of \n
|
2012-01-19 18:32:27 -05:00
|
|
|
* RequestFilter which through rtti store generic parameters used by the RsGeneralStorageService implementation \n
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* The main reason for layering RsGeneralDataService between this and RsGeneralExchangeService implementer \n
|
|
|
|
* is to avoid the overhead of storage access and while allowing a rich variety of implementations not having to \n
|
|
|
|
* worry about efficiency \n
|
2012-01-11 18:01:29 -05:00
|
|
|
*/
|
2012-01-18 18:20:53 -05:00
|
|
|
class RsGeneralStorageService {
|
2012-01-11 18:01:29 -05:00
|
|
|
|
|
|
|
public:
|
2012-01-18 18:20:53 -05:00
|
|
|
|
2012-01-11 18:01:29 -05:00
|
|
|
|
|
|
|
/*!
|
2012-01-18 18:20:53 -05:00
|
|
|
* Retrieves signed messages from storage
|
|
|
|
* @param msgGrp this contains grp and the message to retrieve
|
|
|
|
*/
|
|
|
|
virtual void retrieve(const MsgGrpId& msgGrp, SignedMsgGrp& result, bool decrypted) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* allows for more complex queries specific to the service
|
|
|
|
* Service should implement method taking case
|
|
|
|
* @param filter
|
|
|
|
*/
|
|
|
|
virtual void retrieve(RequestFilter* filter, SignedMsgGrp& msgs) = 0;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* stores signed message in internal storage
|
|
|
|
* @param msgs signed messages to store
|
|
|
|
*/
|
|
|
|
virtual void store(SignedMsgGrp& msgs) = 0;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* retrieves the group ids from storage
|
|
|
|
* @param grpIds set with grpIds available from storage
|
2012-01-11 18:01:29 -05:00
|
|
|
*/
|
2012-01-18 18:20:53 -05:00
|
|
|
virtual void getGroups(std::set<std::string>& grpIds) = 0;
|
2012-01-11 18:01:29 -05:00
|
|
|
|
|
|
|
/*!
|
2012-01-18 18:20:53 -05:00
|
|
|
* retrieve message in this stored in this storage
|
|
|
|
* @param msgIds gets message ids in storage
|
2012-01-11 18:01:29 -05:00
|
|
|
*/
|
2012-01-18 18:20:53 -05:00
|
|
|
virtual bool getMessageIds(std::set<std::string>& msgIds) = 0;
|
2012-01-11 18:01:29 -05:00
|
|
|
|
2012-01-15 08:07:31 -05:00
|
|
|
/*!
|
|
|
|
* Use this find out if Rss i/o status
|
|
|
|
* @return the io status
|
|
|
|
*/
|
2012-01-18 18:20:53 -05:00
|
|
|
virtual uint8_t getIoStat() = 0;
|
2012-01-11 18:01:29 -05:00
|
|
|
|
2012-01-18 18:20:53 -05:00
|
|
|
static uint8_t IOSTAT_READ_ONLY;
|
|
|
|
static uint8_t IOSTAT_READ_AND_WRITE;
|
2012-01-11 18:01:29 -05:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // RSGDP_H
|