Changeset - f8a183661cfa
[Not reviewed]
0 3 0
Sarang Bharadwaj - 13 years ago 2012-06-06 13:12:27
sarang.bh@gmail.com
Polling users home timeline
3 files changed with 30 insertions and 1 deletions:
0 comments (0 inline, 0 general)
backends/twitter/Requests/TimelineRequest.cpp
Show inline comments
 
#include "TimelineRequest.h"
 
DEFINE_LOGGER(logger, "TimelineRequest")
 
void TimelineRequest::run()
 
{	
 
	
 
	bool success;
 
	
 
	if(userRequested != "") success = twitObj->timelineUserGet(false, false, 20, userRequested, false);
 
	else success = twitObj->timelineHomeGet();
 
	
 
	replyMsg = ""; 
 
	if( twitObj->timelineUserGet(false, false, 20, userRequested, false) ) {	
 
	if(success) {	
 
		LOG4CXX_INFO(logger, "Sending timeline request for user " << user)
 

	
 
		while(replyMsg.length() == 0) {
 
			twitObj->getLastWebResponse( replyMsg );
 
		}
 

	
backends/twitter/TwitterPlugin.cpp
Show inline comments
 
@@ -30,12 +30,16 @@ TwitterPlugin::TwitterPlugin(Config *config, Swift::SimpleEventLoop *loop, Stora
 
	m_conn = m_factories->getConnectionFactory()->createConnection();
 
	m_conn->onDataRead.connect(boost::bind(&TwitterPlugin::_handleDataRead, this, _1));
 
	m_conn->connect(Swift::HostAddressPort(Swift::HostAddress(host), port));
 

	
 
	tp = new ThreadPool(loop_, 10);
 
		
 
	m_timer = m_factories->getTimerFactory()->createTimer(60000);
 
	m_timer->onTick.connect(boost::bind(&TwitterPlugin::pollForTweets, this));
 
	m_timer->start();
 
	
 
	LOG4CXX_INFO(logger, "Starting the plugin.");
 
}
 

	
 
TwitterPlugin::~TwitterPlugin() 
 
{
 
	delete storagebackend;
 
@@ -92,12 +96,13 @@ void TwitterPlugin::handleLoginRequest(const std::string &user, const std::strin
 
// User logging out
 
void TwitterPlugin::handleLogoutRequest(const std::string &user, const std::string &legacyName) 
 
{
 
	delete sessions[user];
 
	sessions[user] = NULL;
 
	connectionState[user] = DISCONNECTED;
 
	onlineUsers.erase(user);
 
}
 

	
 

	
 
void TwitterPlugin::handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &xhtml) 
 
{
 
	
 
@@ -131,12 +136,25 @@ void TwitterPlugin::handleBuddyUpdatedRequest(const std::string &user, const std
 
void TwitterPlugin::handleBuddyRemovedRequest(const std::string &user, const std::string &buddyName, const std::vector<std::string> &groups) 
 
{
 

	
 
}
 

	
 

	
 
void TwitterPlugin::pollForTweets()
 
{
 
	boost::mutex::scoped_lock lock(userlock);
 
	std::set<std::string>::iterator it = onlineUsers.begin();
 
	while(it != onlineUsers.end()) {
 
		std::string user = *it;
 
		tp->runAsThread(new TimelineRequest(np, sessions[user], user, ""));
 
		it++;
 
	}
 
	m_timer->start();
 
}
 

	
 

	
 
bool TwitterPlugin::getUserOAuthKeyAndSecret(const std::string user, std::string &key, std::string &secret) 
 
{
 
	boost::mutex::scoped_lock lock(dblock);
 
	
 
	UserInfo info;
 
	if(storagebackend->getUser(user, info) == false) {
 
@@ -215,7 +233,8 @@ void TwitterPlugin::pinExchangeComplete(const std::string user, const std::strin
 
{
 
	boost::mutex::scoped_lock lock(userlock);	
 
		
 
	sessions[user]->getOAuth().setOAuthTokenKey( OAuthAccessTokenKey );
 
	sessions[user]->getOAuth().setOAuthTokenSecret( OAuthAccessTokenSecret );
 
	connectionState[user] = CONNECTED;
 
	onlineUsers.insert(user);
 
}	
backends/twitter/TwitterPlugin.h
Show inline comments
 
@@ -45,12 +45,13 @@ extern Swift::SimpleEventLoop *loop_; // Event Loop
 

	
 
class TwitterPlugin : public NetworkPlugin {
 
	public:
 
		Swift::BoostNetworkFactories *m_factories;
 
		Swift::BoostIOServiceThread m_boostIOServiceThread;
 
		boost::shared_ptr<Swift::Connection> m_conn;
 
		Swift::Timer::ref m_timer;
 
		StorageBackend *storagebackend;
 

	
 
		TwitterPlugin(Config *config, Swift::SimpleEventLoop *loop, StorageBackend *storagebackend, const std::string &host, int port);
 
		~TwitterPlugin();
 

	
 
		// Send data to NetworkPlugin server
 
@@ -68,12 +69,14 @@ class TwitterPlugin : public NetworkPlugin {
 
		void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &xhtml = "");
 

	
 
		void handleBuddyUpdatedRequest(const std::string &user, const std::string &buddyName, const std::string &alias, const std::vector<std::string> &groups);
 

	
 
		void handleBuddyRemovedRequest(const std::string &user, const std::string &buddyName, const std::vector<std::string> &groups);
 
		
 
		void pollForTweets();
 
		
 
		bool getUserOAuthKeyAndSecret(const std::string user, std::string &key, std::string &secret);
 
		
 
		bool storeUserOAuthKeyAndSecret(const std::string user, const std::string OAuthKey, const std::string OAuthSecret);
 
		
 
		void initUserSession(const std::string user, const std::string password);
 
		
 
@@ -93,9 +96,10 @@ class TwitterPlugin : public NetworkPlugin {
 

	
 
		boost::mutex dblock, userlock;
 

	
 
		ThreadPool *tp;
 
		std::map<std::string, twitCurl*> sessions;		
 
		std::map<std::string, status> connectionState;
 
		std::set<std::string> onlineUsers;
 
};
 

	
 
#endif
0 comments (0 inline, 0 general)