A
download StatusInterface.cpp
Language: C++
LOC: 144
Project Info
grub.org - Distributed Internet Crawler(grub)
Server: SourceForge
Type: cvs
...ge\g\grub\grub\client\util\
   alt_ftw.c
   alt_ftw.h
   bin_test_util.dsp
   clog.cpp
   clog.h
   ConfigFileInfo.h
   crc.h
   crc_32.c
   crc_32.cpp
   crc_32.h
   crc_test.c
   crc_test.cpp
   crc32.c
   crc32.h
   dbl_list.c
   dbl_list.h
   delay.cpp
   delay.h
   diagnose.h
   fc32.c
   file_data.c
   file_data.h
   getopt.c
   getopt.h
   grubconf.c
   grubconf.h
   GrubExp.cpp
   GrubExp.h
   Gui.cpp
   Gui.h
   intl.h
   lib_util.dsp
   lockfile.cpp
   lockfile.h
   Makefile.am
   parsecfg.c
   parsecfg.h
   platform.h
   rmfiles.c
   rmfiles.h
   ServerSettings.cpp
   ServerSettings.h
   sniptype.h
   StatusInterface.cpp
   StatusInterface.h
   strip_url.c
   strip_url.h
   test_util.cpp

#include "StatusInterface.h"

using namespace std;

// create the two structs that contain all our settings and statistics -
// these are GLOBAL structs, with Config_Info contained in the ConfigFileInfo.h
// and Status_Info contained in StatusInterface.h, both get initilized in the
// Status_Info constructor, which is a *little* confusing.
Config_Info Config_File_Info;
Status_Info Crawler_Status_Info;
Status Crawler_Status;

Status::Status() : BaseFace()
{
}

Status::~Status()
{
}

void Status::pauseCrawler(bool state)
{
	Crawler_Status_Info.crawler_pause = state;
}

void Status::softShutdown()
{
	// add logging to these routines if you end up using them
	Crawler_Status_Info.gui_quit = true;
	Crawler_Status_Info.coordinator_quit = true;
}

void Status::hardShutdown()
{ 
#ifdef GRUB_UNIX
	// add logging to these routines if you end up using them
	Crawler_Status_Info.gui_quit = true;
	Crawler_Status_Info.coordinator_quit = true;
	Crawler_Status_Info.crawler_quit = true;
	Crawler_Status_Info.protocol_quit = true;
#else
	_exit(1);
#endif
}

// returns true if bandwidth was set successfully or false, if not
bool Status::setBandwidthLimit(int new_band_limit)
{
	if (new_band_limit > 0)
	{ 
		Config_File_Info.MaxAmountOfBandwidth = new_band_limit;
		return true;
	}
	else
	{
		return false;
	}
}

// return current bandwidth usage in kilobits/sec
int Status::getBandwidth()
{
	return Crawler_Status_Info.usage;
}

// return current bandwidth limit in kilobits/sec
int Status::getBandwidthLimit()
{
	return Config_File_Info.MaxAmountOfBandwidth;
}

// return the number of crawler to spawn for crawling
int Status::getNumberCrawlers()
{
	return Config_File_Info.NumOfCrawlersToRun;
}

// returns true if the new number of crawlers was set, false if not
bool Status::setNumberCrawlers(int new_number_crawlers)
{
	// need to add sanity checking for more than 100 crawlers
	if(new_number_crawlers > 0)
	{
		Config_File_Info.NumOfCrawlersToRun = new_number_crawlers;
		return true;
	}
	return false;
}

void Status::EventResume()
{
	// flip the value
	Crawler_Status_Info.slave_should_wait ^= 1;
}

void Status::EventSetBandwidth(int Bandwidth)
{
	setBandwidthLimit(Bandwidth);
}

void Status::EventSetCrawlerCount(int Count)
{
	setNumberCrawlers(Count);
}

void Status::EventShutdownHard()
{
	hardShutdown();
}

void Status::EventShutdownSoft()
{
	softShutdown();
}

void Status::EventClientID(int ClientID)
{
	Config_File_Info.ClientID = ClientID;
}

void Status::EventAltClientID(int AltClientID)
{
	Config_File_Info.AltClientID = (unsigned int)AltClientID;
}

void Status::EventMaxThreadsPerHost(int MaxThreadsPerHost)
{
	Config_File_Info.ThreadsPerHost = MaxThreadsPerHost;
}

void Status::EventDynamicThreshBytes(int DynamicThreshBytes)
{
	Config_File_Info.DynamicThreshBytes = DynamicThreshBytes;
}

void Status::EventPortNum(int PortNum)
{
	Config_File_Info.PortNumber = PortNum;
}

void Status::EventSetProxy(const char *Host, int Port)
{
	if ( Config_File_Info.Proxy ) free(Config_File_Info.Proxy);

	Config_File_Info.Proxy = strdup(Host);
	Config_File_Info.ProxyPort = Port;
}

void Status::EventSetProxyAuth(const char *User,
	const char *Password)
{
	if ( Config_File_Info.ProxyUserName ) free(Config_File_Info.ProxyUserName);
	if ( Config_File_Info.ProxyPassword ) free(Config_File_Info.ProxyPassword);

	Config_File_Info.ProxyUserName = strdup(User);
	Config_File_Info.ProxyPassword = strdup(Password);
}

void Status::EventGetBandwidth()
{	
	int Bandwidth;
	Bandwidth = getBandwidth();
	PostGetBandwidth (Bandwidth);	
}

void Status::EventGetBandwidthLimit()
{
	int BandwidthLimit;
	BandwidthLimit = getBandwidthLimit();
	PostGetBandwidthLimit(BandwidthLimit);
}

void Status::EventGetCrawlerCount()
{
	int CrawlerCount;
	CrawlerCount = getNumberCrawlers();
	PostGetCrawlerCount(CrawlerCount);
}

void Status::EventGetStatus()
{	int Status;
	PostGetStatus(Status);
}

void Status::errorCallback( const char *msg )
{
	/* connection with ConsoleFace went dead; we are going to
	 * kill ourselves as our master is gone */
	hardShutdown();
}

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us