simplified qblog for blogging only, hopefully test everything out soon

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@731 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2008-09-21 20:30:34 +00:00
parent a52c34a551
commit d14a1ffb39
6 changed files with 223 additions and 478 deletions

View file

@ -31,7 +31,7 @@
#include <list>
#include <map>
#include "rsiface/rstypes.h"
#include "../rsiface/rstypes.h"
/* delcare interafce for everyone o use */
@ -48,30 +48,6 @@ extern RsQblog *rsQblog;
virtual ~RsQblog() { return; }
/**
* choose whether to filter or not
* @param filterSwitch
*/
virtual bool setFilterSwitch(bool &filterSwitch) = 0;
/**
* retrieve usrs filterSwitch status
*/
virtual bool getFilterSwitch(void) = 0;
/**
* add user id to filter list
* @param usr id to add to filter list
*/
virtual bool addToFilter(std::string &usrId) = 0;
/**
* remove friend from filter list
* @param id The user's frined's id
*/
virtual bool removeFiltFriend(std::string &usrId) = 0;
/**
* send blog info, will send to a data structure for transmission
* @param msg The msg the usr wants to send
@ -84,19 +60,6 @@ extern RsQblog *rsQblog;
*/
virtual bool getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs) = 0;
/**
* set usr profile, send an empty second pair to delete entry
* @param entry profile entry
*/
virtual bool setProfile(std::pair<std::wstring, std::wstring> entry) = 0;
/**
* add fav file, send file info with only name to delete that entry
* @param entry file info entry
*/
virtual bool setFavorites(FileInfo favFile) = 0;
/**
* Stuff DrBob Added for Profile View!
*/
@ -107,22 +70,8 @@ extern RsQblog *rsQblog;
* @param ts Timestamp of the Blog Post.
* @param post the actual Blog Post.
*/
virtual bool getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post) = 0;
/**
* get users Profile.
* @param id the user id
* @param entries set of profile information.
*/
virtual bool getPeerProfile(std::string id, std::list< std::pair<std::wstring, std::wstring> > &entries) = 0;
/**
* get users fav files
* @param id the user whose info you want.
* @param favs list of Files
*/
virtual bool getPeerFavourites(std::string id, std::list<FileInfo> &favs) = 0;
};
#endif /*RSQBLOG_H_*/

View file

@ -23,7 +23,7 @@
*
*/
#include "rsserver/p3Blog.h"
#include "../rsserver/p3Blog.h"
RsQblog* rsQblog = NULL;
@ -33,60 +33,26 @@ mQblog(qblog)
return;
}
p3Blog::~p3Blog()
{
return;
}
bool p3Blog::addToFilter(std::string &usrId)
{
return mQblog->addToFilter(usrId);
}
bool p3Blog::getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs)
{
return mQblog->getBlogs(blogs);
}
bool p3Blog::getFilterSwitch(void)
{
return mQblog->getFilterSwitch();
}
bool p3Blog::sendBlog(const std::wstring &msg)
{
return mQblog->sendBlog(msg);
}
bool p3Blog::setFilterSwitch(bool &filterSwitch)
{
return mQblog->setFilterSwitch(filterSwitch);
}
bool p3Blog::removeFiltFriend(std::string &usrId)
{
return mQblog->removeFiltFriend(usrId);
}
bool p3Blog::setFavorites(FileInfo favFile)
{
//TODO
//return mQblog->setFavorites(favFile);
}
bool p3Blog::setProfile(std::pair<std::wstring, std::wstring> entry)
{
//TODO
//return mQblog->setProfile(entry);
}
bool p3Blog::getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post)
{
//return mQblog->getPeerLatestBlog(id, ts, post);
// dummy info.
ts = time(NULL);
post = L"Hmmm, not much, just eating prawn crackers at the moment... but I'll post this every second if you want ;)";
@ -94,42 +60,3 @@ bool p3Blog::getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post)
}
bool p3Blog::getPeerProfile(std::string id, std::list< std::pair<std::wstring, std::wstring> > &entries)
{
//return mQblog->getPeerProfile(id, entries);
std::wstring a = L"phone number";
std::wstring b = L"0845 XXX 43639434363878735453";
entries.push_back(make_pair(a,b));
a = L"Favourite Film";
b = L"Prawn Crackers revenge";
entries.push_back(make_pair(a,b));
a = L"Favourite Music";
b = L"Eric Clapton, Neil Diamond, Folk, Country and Western";
entries.push_back(make_pair(a,b));
return true;
}
bool p3Blog::getPeerFavourites(std::string id, std::list<FileInfo> &favs)
{
//return mQblog->getPeerFavourites(id, favs);
FileInfo a;
a.fname = "Prawn Crackers - Full Script.txt";
a.size = 1000553;
a.hash = "XXXXXXXXXXXXXXXXXXXXXX";
favs.push_back(a);
return true;
}

View file

@ -29,8 +29,8 @@
*
*/
#include "rsiface/rsQblog.h"
#include "services/p3Qblog.h"
#include "../rsiface/rsQblog.h"
#include "../services/p3Qblog.h"
/*!
* Interface class using composition (p3Qblog is an attribute)
@ -43,17 +43,9 @@ class p3Blog : public RsQblog
p3Blog(p3Qblog* qblog);
virtual ~p3Blog();
virtual bool setFilterSwitch(bool &filterSwitch);
virtual bool getFilterSwitch(void);
virtual bool addToFilter(std::string &usrId);
virtual bool removeFiltFriend(std::string &usrId);
virtual bool sendBlog(const std::wstring &msg);
virtual bool getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs);
virtual bool setFavorites(FileInfo favFile);
virtual bool setProfile(std::pair<std::wstring, std::wstring> entry);
virtual bool getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post);
virtual bool getPeerProfile(std::string id, std::list< std::pair<std::wstring, std::wstring> > &entries);
virtual bool getPeerFavourites(std::string id, std::list<FileInfo> &favs);
private:

View file

@ -614,6 +614,7 @@ int RsServer::StartupRetroShare(RsInit *config)
CachePair cp3(mQblog, mQblog, CacheId(RS_SERVICE_TYPE_QBLOG, 0));
mCacheStrapper -> addCachePair(cp3);
p3Forums *mForums = new p3Forums(RS_SERVICE_TYPE_FORUM,
mCacheStrapper, mCacheTransfer,
localcachedir, remotecachedir);
@ -631,7 +632,7 @@ int RsServer::StartupRetroShare(RsInit *config)
pqih -> addService(mChannels); /* This must be also ticked as a service */
#else
mQblog = NULL;
//mQblog = NULL;
//mForums = NULL;
#endif

View file

@ -24,20 +24,19 @@
*/
#include "serialiser/rsqblogitems.h"
#include "services/p3Qblog.h"
#include "p3Qblog.h"
#include <utility>
#include <ctime>
#include <iomanip>
#include "pqi/pqibin.h"
#include "pqi/p3authmgr.h"
const uint32_t RANK_MAX_FWD_OFFSET = (60 * 60 * 24 * 2); /* 2 Days */
const uint32_t BLOG_MAX_FWD_OFFSET = (60 * 60 * 24 * 2); /* 2 Days */
const uint32_t FRIEND_QBLOG_REPOST_PERIOD = 60; /* every minute for testing */
/****
* #define QBLOG_DEBUG 1
****/
#define QBLOG_DEBUG 1
p3Qblog::p3Qblog(p3ConnectMgr *connMgr,
uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
@ -45,7 +44,7 @@ p3Qblog::p3Qblog(p3ConnectMgr *connMgr,
uint32_t storePeriod)
:CacheSource(type, true, cs, sourcedir),
CacheStore(type, true, cs, cft, storedir),
mConnMgr(connMgr), mFilterSwitch(false),
mConnMgr(connMgr),
mStorePeriod(storePeriod), mPostsUpdated(false), mProfileUpdated(false)
{
{
@ -168,7 +167,7 @@ bool p3Qblog::loadBlogFile(std::string filename, std::string src)
{ /********** STACK LOCKED MTX ******/
RsStackMutex stack(mBlogMtx);
min = now - mStorePeriod;
max = now + RANK_MAX_FWD_OFFSET;
max = now + BLOG_MAX_FWD_OFFSET;
} /********** STACK LOCKED MTX ******/
while(NULL != (item = stream->GetItem()))
@ -189,7 +188,7 @@ bool p3Qblog::loadBlogFile(std::string filename, std::string src)
delete item;
}
/* check timestamp */
/* check timestamp: delete if here longer than store period or more than two days */
else if (((time_t) newBlog->sendTime < min) ||
((time_t) newBlog->sendTime > max))
{
@ -241,7 +240,7 @@ bool p3Qblog::addBlog(RsQblogMsg *newBlog)
std::cerr << "\tmUsrBlogSet: blog" << newBlog->message;
std::cerr << std::endl;
#endif
mPostsUpdated = false; // need to figure how this should work/ wherre this should be placed
mPostsUpdated = false; // need to figure how this should work/ where this should be placed
}
return true;
@ -249,7 +248,6 @@ bool p3Qblog::addBlog(RsQblogMsg *newBlog)
bool p3Qblog::postBlogs(void)
{
#ifdef QBLOG_DEBUG
std::cerr << "p3Qblog::postBlogs()";
std::cerr << std::endl;
@ -265,8 +263,8 @@ bool p3Qblog::postBlogs(void)
std::string tmpname = out.str();
std::string fname = path + "/" + tmpname;
#ifdef RANK_DEBUG
std::cerr << "p3Ranking::publishMsgs() Storing to: " << fname;
#ifdef QBLOG_DEBUG
std::cerr << "p3Qblog::postBlogs() Storing to: " << fname;
std::cerr << std::endl;
#endif
@ -335,7 +333,7 @@ bool p3Qblog::postBlogs(void)
data.size = bio->bytecount();
data.recvd = time(NULL);
#ifdef RANK_DEBUG
#ifdef QBLOG_DEBUG
std::cerr << "p3Ranking::postBlogs() refreshing Cache";
std::cerr << std::endl;
std::cerr << "\tCache Path: " << data.path;
@ -365,82 +363,7 @@ p3Qblog::~p3Qblog()
return;
}
bool p3Qblog::getFilterSwitch(void)
{
{
RsStackMutex stack(mBlogMtx); // might be pointless
return mFilterSwitch;
}
}
bool p3Qblog::setFilterSwitch(bool &filterSwitch)
{
{
RsStackMutex stack(mBlogMtx);
mFilterSwitch = filterSwitch;
#ifdef QBLOG_DEBUG
std::cerr << "p3Qblog::setFilterSwitch() " << mFilterSwitch;
std::cerr << std::endl;
#endif
}
return true;
}
bool p3Qblog::removeFiltFriend(std::string &usrId)
{
std::list<std::string>::iterator it;
{
RsStackMutex stack(mBlogMtx);
/* search through list to remove friend */
for(it = mFilterList.begin(); it != mFilterList.end(); it++)
{
if(it->compare(usrId))
{
#ifdef QBLOG_DEBUG
std::cerr << "p3Qblog::removeFilterFriend() it " << *it;
std::cerr << std::endl;
#endif
mFilterList.erase(it); // remove friend from list
return true;
}
}
}
#ifdef QBLOG_DEBUG
std::cerr << "usr could not be found!" << std::endl;
#endif
return false; // could not find friend
}
bool p3Qblog::addToFilter(std::string& usrId)
{
{
RsStackMutex stack(mBlogMtx);
std::list<std::string>::iterator it;
/* search through list in case friend already exist */
for(it = mFilterList.begin(); it != mFilterList.end(); it++)
{
if(it->compare(usrId))
{
#ifdef QBLOG_DEBUG
std::cerr << "usr already in list!" << *it;
std::cerr << std::endl;
#endif
return false; // user already in list, not added
}
}
mFilterList.push_back(usrId);
}
return true;
}
bool p3Qblog::getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs)
{
@ -454,13 +377,15 @@ bool p3Qblog::getBlogs(std::map< std::string, std::multimap<long int, std::wstri
}
blogs = mUsrBlogSet;
return true;
#ifdef QBOG_DEBUG
#ifdef QBLOG_DEBUG
std::cerr << "p3Qblog::getBlogs() number of blogs: " << mUsrBlogSet.size();
std::cerr << std::endl;
#endif
}
return true;
}
bool p3Qblog::sendBlog(const std::wstring &msg)
@ -492,39 +417,6 @@ bool p3Qblog::sendBlog(const std::wstring &msg)
return true;
}
bool p3Qblog::getPeerProfile(std::string id, std::list< std::pair<std::wstring, std::wstring> > &entries)
{
// TODO
return true;
}
bool p3Qblog::setProfile(std::pair<std::wstring, std::wstring> entry)
{
//TODO
return true;
}
bool p3Qblog::setFavorites(FileInfo favFile)
{
//TODO
return true;
}
bool p3Qblog::getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post)
{
//TODO
return true;
}
bool p3Qblog::getPeerFavourites(std::string id, std::list<FileInfo> &favs)
{
//TODO
return true;
}
void p3Qblog::loadDummy(void)
{
std::list<std::string> peers;

View file

@ -42,7 +42,6 @@
#include "rsiface/rstypes.h"
class RsQblogMsg; /* to populate maps of blogs */
class RsQblogProfile; /* to populate profile information */
/*!
* contains definitions of the interface and blog information to be manipulated
@ -77,18 +76,9 @@ class RsQblogProfile; /* to populate profile information */
public:
virtual bool setFilterSwitch(bool &filterSwitch);
virtual bool getFilterSwitch(void);
virtual bool addToFilter(std::string &usrId);
virtual bool removeFiltFriend(std::string &usrId);
virtual bool sendBlog(const std::wstring &msg);
virtual bool getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs);
virtual bool getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post);
virtual bool getPeerProfile(std::string id, std::list< std::pair<std::wstring, std::wstring> > &entries);
virtual bool getPeerFavourites(std::string id, std::list<FileInfo> &favs);
virtual bool setFavorites(FileInfo favFile);
virtual bool setProfile(std::pair<std::wstring, std::wstring> entry);
/**
* to be run by server, update method
@ -131,16 +121,10 @@ class RsQblogProfile; /* to populate profile information */
RsMutex mBlogMtx;
/// the current usr
std::string mOwnId;
/// contains the list of ids usr only wants to see
std::list<std::string> mFilterList;
/// determines whether filter is activated or not
bool mFilterSwitch;
/// contain usrs and their blogs
std::map< std::string, std::multimap<long int, std::wstring> > mUsrBlogSet;
///fills up above sets
std::list<RsQblogMsg*> mBlogs;
///profile information
std::map<std::string, RsQblogProfile > mProfiles;
///how long to keep posts
uint32_t mStorePeriod;
/// to track blog updates