Added new libretroshare interface for switching between Operating Mode.

This is so people can use RS in limited bandwidth or background modes.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5887 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-11-25 14:59:42 +00:00
parent fd723bcea7
commit 696e7735a1
3 changed files with 124 additions and 0 deletions

View File

@ -117,6 +117,12 @@ extern RsServerConfig *rsConfig;
#define RS_CONFIG_ADVANCED 0x0101
#define RS_OPMODE_FULL 0x0001
#define RS_OPMODE_NOTURTLE 0x0002
#define RS_OPMODE_GAMING 0x0004
#define RS_OPMODE_MINIMAL 0x0008
class RsConfigStartup
{
public:
@ -267,6 +273,14 @@ virtual bool getConfigurationOption(uint32_t key, std::string &opt) = 0;
virtual bool setConfigurationOption(uint32_t key, const std::string &opt) = 0;
/* Operating Mode */
virtual uint32_t getOperatingMode() = 0;
virtual bool setOperatingMode(uint32_t opMode) = 0;
/* Data Rate Control - to be moved here */
virtual int SetDataRates( int downKb, int upKb ) = 0;
virtual int GetDataRates( float &inKb, float &outKb ) = 0;
};
#endif

View File

@ -278,4 +278,105 @@ uint32_t p3ServerConfig::getConnectModes()
return mNetMgr->getConnectModes();
}
/* Operating Mode */
#define RS_CONFIG_OPERATING_STRING "OperatingMode"
uint32_t p3ServerConfig::getOperatingMode()
{
std::string modestr = mGeneralConfig->getSetting(RS_CONFIG_OPERATING_STRING);
uint32_t mode = RS_OPMODE_FULL;
if (modestr == "FULL")
{
mode = RS_OPMODE_FULL;
}
else if (modestr == "NOTURTLE")
{
mode = RS_OPMODE_NOTURTLE;
}
else if (modestr == "GAMING")
{
mode = RS_OPMODE_GAMING;
}
else if (modestr == "MINIMAL_TRANSFER")
{
mode = RS_OPMODE_MINIMAL;
}
return mode;
}
bool p3ServerConfig::setOperatingMode(uint32_t opMode)
{
std::string modestr = "FULL";
switch(opMode)
{
case RS_OPMODE_FULL:
modestr = "FULL";
break;
case RS_OPMODE_NOTURTLE:
modestr = "NOTURTLE";
break;
case RS_OPMODE_GAMING:
modestr = "GAMING";
break;
case RS_OPMODE_MINIMAL:
modestr = "MINIMAL_TRANSFER";
break;
}
mGeneralConfig->setSetting(RS_CONFIG_OPERATING_STRING, modestr);
return switchToOperatingMode(opMode);
}
bool p3ServerConfig::switchToOperatingMode(uint32_t opMode)
{
switch (opMode)
{
default:
case RS_OPMODE_FULL:
/* switch on all transfers */
/* 100% bandwidth */
/* switch on popups, enable hashing */
break;
case RS_OPMODE_NOTURTLE:
/* switch on all transfers - except turtle, enable hashing */
/* 100% bandwidth */
/* switch on popups, enable hashing */
break;
case RS_OPMODE_GAMING:
/* switch on all transfers */
/* reduce bandwidth to 25% */
/* switch off popups, enable hashing */
break;
case RS_OPMODE_MINIMAL:
/* switch off all transfers */
/* reduce bandwidth to 10%, but make sure there is enough for VoIP */
/* switch on popups, enable hashing */
break;
}
return true;
}
/* handle data rates.
* Mutex must be handled at the lower levels: TODO */
int p3ServerConfig::SetDataRates( int downKb, int upKb ) /* in kbrates */
{
//pqih -> setMaxRate(true, totalDownload);
//pqih -> setMaxRate(false, totalUpload);
//pqih -> save_config();
return 1;
}
int p3ServerConfig::GetDataRates( float &inKb, float &outKb ) /* in kbrates */
{
//pqih -> getCurrentRates(inKb, outKb);
return 1;
}

View File

@ -84,10 +84,19 @@ virtual uint32_t getConnectModes();
virtual bool getConfigurationOption(uint32_t key, std::string &opt);
virtual bool setConfigurationOption(uint32_t key, const std::string &opt);
/* Operating Mode */
virtual uint32_t getOperatingMode();
virtual bool setOperatingMode(uint32_t opMode);
virtual int SetDataRates( int downKb, int upKb );
virtual int GetDataRates( float &inKb, float &outKb );
/********************* ABOVE is RsConfig Interface *******/
private:
bool switchToOperatingMode(uint32_t opMode);
bool findConfigurationOption(uint32_t key, std::string &keystr);
p3PeerMgr *mPeerMgr;