2009-05-15 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Added changeGlobalOption command. Currently,
	max-overall-download-limit and max-overall-upload-limit option are
	available.
	* src/RequestGroupMan.h
	* src/XmlRpcMethod.cc
	* src/XmlRpcMethod.h
	* src/XmlRpcMethodFactory.cc
	* src/XmlRpcMethodImpl.cc
	* src/XmlRpcMethodImpl.h
	* test/XmlRpcMethodTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-05-14 15:44:59 +00:00
parent 850458f7b1
commit 3e2ccbf359
8 changed files with 103 additions and 1 deletions

View File

@ -1,3 +1,16 @@
2009-05-15 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added changeGlobalOption command. Currently,
max-overall-download-limit and max-overall-upload-limit option are
available.
* src/RequestGroupMan.h
* src/XmlRpcMethod.cc
* src/XmlRpcMethod.h
* src/XmlRpcMethodFactory.cc
* src/XmlRpcMethodImpl.cc
* src/XmlRpcMethodImpl.h
* test/XmlRpcMethodTest.cc
2009-05-15 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added changeOption command. Currently, max-download-limit,

View File

@ -193,10 +193,30 @@ public:
// _maxOverallDownloadSpeedLimit == 0. Otherwise returns false.
bool doesOverallDownloadSpeedExceed();
void setMaxOverallDownloadSpeedLimit(unsigned int speed)
{
_maxOverallDownloadSpeedLimit = speed;
}
unsigned int getMaxOverallDownloadSpeedLimit() const
{
return _maxOverallDownloadSpeedLimit;
}
// Returns true if current upload speed exceeds
// _maxOverallUploadSpeedLimit. Always returns false if
// _maxOverallUploadSpeedLimit == 0. Otherwise returns false.
bool doesOverallUploadSpeedExceed();
void setMaxOverallUploadSpeedLimit(unsigned int speed)
{
_maxOverallUploadSpeedLimit = speed;
}
unsigned int getMaxOverallUploadSpeedLimit() const
{
return _maxOverallUploadSpeedLimit;
}
};
typedef SharedHandle<RequestGroupMan> RequestGroupManHandle;

View File

@ -115,7 +115,7 @@ const std::vector<std::string>& listChangeableOptions()
PREF_MAX_DOWNLOAD_LIMIT,
};
static std::vector<std::string> options
(&OPTIONS[0], &OPTIONS[arrayLength(OPTIONS)]);;
(&OPTIONS[0], &OPTIONS[arrayLength(OPTIONS)]);
return options;
}
@ -126,6 +126,25 @@ void XmlRpcMethod::gatherChangeableOption
option, optionsDict, _optionParser);
}
const std::vector<std::string>& listChangeableGlobalOptions()
{
static const std::string OPTIONS[] = {
PREF_MAX_OVERALL_UPLOAD_LIMIT,
PREF_MAX_OVERALL_DOWNLOAD_LIMIT,
};
static std::vector<std::string> options
(&OPTIONS[0], &OPTIONS[arrayLength(OPTIONS)]);
return options;
}
void XmlRpcMethod::gatherChangeableGlobalOption
(const SharedHandle<Option>& option, const BDE& optionsDict)
{
gatherOption(listChangeableGlobalOptions().begin(),
listChangeableGlobalOptions().end(),
option, optionsDict, _optionParser);
}
} // namespace xmlrpc
} // namespace aria2

View File

@ -67,6 +67,9 @@ protected:
void gatherChangeableOption(const SharedHandle<Option>& option,
const BDE& optionDict);
void gatherChangeableGlobalOption(const SharedHandle<Option>& option,
const BDE& optionDict);
public:
XmlRpcMethod();

View File

@ -64,6 +64,8 @@ XmlRpcMethodFactory::create(const std::string& methodName)
return SharedHandle<XmlRpcMethod>(new TellActiveXmlRpcMethod());
} else if(methodName == "aria2.changeOption") {
return SharedHandle<XmlRpcMethod>(new ChangeOptionXmlRpcMethod());
} else if(methodName == "aria2.changeGlobalOption") {
return SharedHandle<XmlRpcMethod>(new ChangeGlobalOptionXmlRpcMethod());
} else if(methodName == "aria2.purgeDownloadResult") {
return SharedHandle<XmlRpcMethod>(new PurgeDownloadResultXmlRpcMethod());
} else {

View File

@ -488,6 +488,27 @@ BDE ChangeOptionXmlRpcMethod::process
return BDE("OK");
}
BDE ChangeGlobalOptionXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
{
const BDE& params = req._params;
assert(params.isList());
if(params.empty() || !params[0].isDict()) {
return BDE("OK");
}
SharedHandle<Option> option(new Option(*e->option));
gatherChangeableGlobalOption(option, params[0]);
if(option->defined(PREF_MAX_OVERALL_DOWNLOAD_LIMIT)) {
e->_requestGroupMan->setMaxOverallDownloadSpeedLimit
(option->getAsInt(PREF_MAX_OVERALL_DOWNLOAD_LIMIT));
}
if(option->defined(PREF_MAX_OVERALL_UPLOAD_LIMIT)) {
e->_requestGroupMan->setMaxOverallUploadSpeedLimit
(option->getAsInt(PREF_MAX_OVERALL_UPLOAD_LIMIT));
}
return BDE("OK");
}
BDE NoSuchMethodXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
{

View File

@ -96,6 +96,11 @@ protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
};
class ChangeGlobalOptionXmlRpcMethod:public XmlRpcMethod {
protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
};
class NoSuchMethodXmlRpcMethod:public XmlRpcMethod {
protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);

View File

@ -25,6 +25,7 @@ class XmlRpcMethodTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(XmlRpcMethodTest);
CPPUNIT_TEST(testAddUri);
CPPUNIT_TEST(testChangeOption);
CPPUNIT_TEST(testChangeGlobalOption);
CPPUNIT_TEST(testNoSuchMethod);
CPPUNIT_TEST_SUITE_END();
private:
@ -46,6 +47,7 @@ public:
void testAddUri();
void testChangeOption();
void testChangeGlobalOption();
void testNoSuchMethod();
};
@ -88,6 +90,23 @@ void XmlRpcMethodTest::testChangeOption()
CPPUNIT_ASSERT_EQUAL((unsigned int)50*1024, group->getMaxUploadSpeedLimit());
}
void XmlRpcMethodTest::testChangeGlobalOption()
{
ChangeGlobalOptionXmlRpcMethod m;
XmlRpcRequest req("aria2.changeGlobalOption", BDE::list());
BDE opt = BDE::dict();
opt[PREF_MAX_OVERALL_DOWNLOAD_LIMIT] = BDE("100K");
opt[PREF_MAX_OVERALL_UPLOAD_LIMIT] = BDE("50K");
req._params << opt;
XmlRpcResponse res = m.execute(req, _e.get());
CPPUNIT_ASSERT_EQUAL(0, res._code);
CPPUNIT_ASSERT_EQUAL((unsigned int)100*1024,
_e->_requestGroupMan->getMaxOverallDownloadSpeedLimit());
CPPUNIT_ASSERT_EQUAL((unsigned int)50*1024,
_e->_requestGroupMan->getMaxOverallUploadSpeedLimit());
}
void XmlRpcMethodTest::testNoSuchMethod()
{
NoSuchMethodXmlRpcMethod m;