mirror of https://github.com/aria2/aria2
2009-05-15 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added changeOption command. Currently, max-download-limit, max-upload-limit option are available in this command. * src/RequestGroup.h * src/XmlRpcMethod.cc * src/XmlRpcMethod.h * src/XmlRpcMethodFactory.cc * src/XmlRpcMethodImpl.cc * src/XmlRpcMethodImpl.h * test/XmlRpcMethodTest.ccpull/1/head
parent
692c4eaf3e
commit
850458f7b1
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2009-05-15 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Added changeOption command. Currently, max-download-limit,
|
||||
max-upload-limit option are available in this command.
|
||||
* src/RequestGroup.h
|
||||
* src/XmlRpcMethod.cc
|
||||
* src/XmlRpcMethod.h
|
||||
* src/XmlRpcMethodFactory.cc
|
||||
* src/XmlRpcMethodImpl.cc
|
||||
* src/XmlRpcMethodImpl.h
|
||||
* test/XmlRpcMethodTest.cc
|
||||
|
||||
2009-05-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Added purgeDownloadResult command.
|
||||
|
|
|
@ -473,10 +473,22 @@ public:
|
|||
return _maxDownloadSpeedLimit;
|
||||
}
|
||||
|
||||
void setMaxDownloadSpeedLimit(unsigned int speed)
|
||||
{
|
||||
_maxDownloadSpeedLimit = speed;
|
||||
}
|
||||
|
||||
unsigned int getMaxUploadSpeedLimit() const
|
||||
{
|
||||
return _maxUploadSpeedLimit;
|
||||
}
|
||||
|
||||
void setMaxUploadSpeedLimit(unsigned int speed)
|
||||
{
|
||||
_maxUploadSpeedLimit = speed;
|
||||
}
|
||||
|
||||
static void resetGIDCounter() { _gidCounter = 0; }
|
||||
};
|
||||
|
||||
typedef SharedHandle<RequestGroup> RequestGroupHandle;
|
||||
|
|
|
@ -74,16 +74,20 @@ XmlRpcResponse XmlRpcMethod::execute
|
|||
}
|
||||
}
|
||||
|
||||
void XmlRpcMethod::gatherRequestOption
|
||||
(const SharedHandle<Option>& option, const BDE& optionsDict)
|
||||
|
||||
template<typename InputIterator>
|
||||
static void gatherOption
|
||||
(InputIterator first, InputIterator last,
|
||||
const SharedHandle<Option>& option, const BDE& optionsDict,
|
||||
const SharedHandle<OptionParser>& optionParser)
|
||||
{
|
||||
for(std::vector<std::string>::const_iterator i = listRequestOptions().begin();
|
||||
i != listRequestOptions().end(); ++i) {
|
||||
if(optionsDict.containsKey(*i)) {
|
||||
const BDE& value = optionsDict[*i];
|
||||
SharedHandle<OptionHandler> optionHandler = _optionParser->findByName(*i);
|
||||
for(; first != last; ++first) {
|
||||
if(optionsDict.containsKey(*first)) {
|
||||
const BDE& value = optionsDict[*first];
|
||||
SharedHandle<OptionHandler> optionHandler =
|
||||
optionParser->findByName(*first);
|
||||
// header and index-out option can take array as value
|
||||
if((*i == PREF_HEADER || *i == PREF_INDEX_OUT) && value.isList()) {
|
||||
if((*first == PREF_HEADER || *first == PREF_INDEX_OUT) && value.isList()){
|
||||
for(BDE::List::const_iterator argiter = value.listBegin();
|
||||
argiter != value.listEnd(); ++argiter) {
|
||||
if((*argiter).isString()) {
|
||||
|
@ -94,7 +98,32 @@ void XmlRpcMethod::gatherRequestOption
|
|||
optionHandler->parse(*option.get(), value.s());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void XmlRpcMethod::gatherRequestOption
|
||||
(const SharedHandle<Option>& option, const BDE& optionsDict)
|
||||
{
|
||||
gatherOption(listRequestOptions().begin(), listRequestOptions().end(),
|
||||
option, optionsDict, _optionParser);
|
||||
}
|
||||
|
||||
const std::vector<std::string>& listChangeableOptions()
|
||||
{
|
||||
static const std::string OPTIONS[] = {
|
||||
PREF_MAX_UPLOAD_LIMIT,
|
||||
PREF_MAX_DOWNLOAD_LIMIT,
|
||||
};
|
||||
static std::vector<std::string> options
|
||||
(&OPTIONS[0], &OPTIONS[arrayLength(OPTIONS)]);;
|
||||
return options;
|
||||
}
|
||||
|
||||
void XmlRpcMethod::gatherChangeableOption
|
||||
(const SharedHandle<Option>& option, const BDE& optionsDict)
|
||||
{
|
||||
gatherOption(listChangeableOptions().begin(), listChangeableOptions().end(),
|
||||
option, optionsDict, _optionParser);
|
||||
}
|
||||
|
||||
} // namespace xmlrpc
|
||||
|
|
|
@ -64,6 +64,9 @@ protected:
|
|||
|
||||
void gatherRequestOption(const SharedHandle<Option>& option,
|
||||
const BDE& optionsDict);
|
||||
|
||||
void gatherChangeableOption(const SharedHandle<Option>& option,
|
||||
const BDE& optionDict);
|
||||
public:
|
||||
XmlRpcMethod();
|
||||
|
||||
|
|
|
@ -62,6 +62,8 @@ XmlRpcMethodFactory::create(const std::string& methodName)
|
|||
return SharedHandle<XmlRpcMethod>(new GetPeersXmlRpcMethod());
|
||||
} else if(methodName == "aria2.tellActive") {
|
||||
return SharedHandle<XmlRpcMethod>(new TellActiveXmlRpcMethod());
|
||||
} else if(methodName == "aria2.changeOption") {
|
||||
return SharedHandle<XmlRpcMethod>(new ChangeOptionXmlRpcMethod());
|
||||
} else if(methodName == "aria2.purgeDownloadResult") {
|
||||
return SharedHandle<XmlRpcMethod>(new PurgeDownloadResultXmlRpcMethod());
|
||||
} else {
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
#include "BtProgressInfoFile.h"
|
||||
#include "BtRuntime.h"
|
||||
#include "BtAnnounce.h"
|
||||
#include "prefs.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -459,6 +460,34 @@ BDE PurgeDownloadResultXmlRpcMethod::process
|
|||
return BDE("OK");
|
||||
}
|
||||
|
||||
BDE ChangeOptionXmlRpcMethod::process
|
||||
(const XmlRpcRequest& req, DownloadEngine* e)
|
||||
{
|
||||
const BDE& params = req._params;
|
||||
assert(params.isList());
|
||||
if(params.empty() || !params[0].isString()) {
|
||||
throw DlAbortEx("GID is not provided.");
|
||||
}
|
||||
int32_t gid = Util::parseInt(params[0].s());
|
||||
|
||||
SharedHandle<RequestGroup> group = findRequestGroup(e->_requestGroupMan, gid);
|
||||
if(group.isNull()) {
|
||||
throw DlAbortEx
|
||||
(StringFormat("Cannot change option for GID#%d", gid).str());
|
||||
}
|
||||
SharedHandle<Option> option(new Option(*group->getOption().get()));
|
||||
if(params.size() > 1 && params[1].isDict()) {
|
||||
gatherChangeableOption(option, params[1]);
|
||||
}
|
||||
if(option->defined(PREF_MAX_DOWNLOAD_LIMIT)) {
|
||||
group->setMaxDownloadSpeedLimit(option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT));
|
||||
}
|
||||
if(option->defined(PREF_MAX_UPLOAD_LIMIT)) {
|
||||
group->setMaxUploadSpeedLimit(option->getAsInt(PREF_MAX_UPLOAD_LIMIT));
|
||||
}
|
||||
return BDE("OK");
|
||||
}
|
||||
|
||||
BDE NoSuchMethodXmlRpcMethod::process
|
||||
(const XmlRpcRequest& req, DownloadEngine* e)
|
||||
{
|
||||
|
|
|
@ -91,6 +91,11 @@ protected:
|
|||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||
};
|
||||
|
||||
class ChangeOptionXmlRpcMethod:public XmlRpcMethod {
|
||||
protected:
|
||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||
};
|
||||
|
||||
class NoSuchMethodXmlRpcMethod:public XmlRpcMethod {
|
||||
protected:
|
||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "OptionHandler.h"
|
||||
#include "XmlRpcRequest.h"
|
||||
#include "XmlRpcResponse.h"
|
||||
#include "prefs.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -23,6 +24,7 @@ class XmlRpcMethodTest:public CppUnit::TestFixture {
|
|||
|
||||
CPPUNIT_TEST_SUITE(XmlRpcMethodTest);
|
||||
CPPUNIT_TEST(testAddUri);
|
||||
CPPUNIT_TEST(testChangeOption);
|
||||
CPPUNIT_TEST(testNoSuchMethod);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
@ -31,6 +33,7 @@ private:
|
|||
public:
|
||||
void setUp()
|
||||
{
|
||||
RequestGroup::resetGIDCounter();
|
||||
_option.reset(new Option());
|
||||
_e.reset(new DownloadEngine(SharedHandle<EventPoll>(new SelectEventPoll())));
|
||||
_e->option = _option.get();
|
||||
|
@ -42,6 +45,7 @@ public:
|
|||
void tearDown() {}
|
||||
|
||||
void testAddUri();
|
||||
void testChangeOption();
|
||||
void testNoSuchMethod();
|
||||
};
|
||||
|
||||
|
@ -63,6 +67,27 @@ void XmlRpcMethodTest::testAddUri()
|
|||
rgs.front()->getRemainingUris().front());
|
||||
}
|
||||
|
||||
void XmlRpcMethodTest::testChangeOption()
|
||||
{
|
||||
SharedHandle<RequestGroup> group
|
||||
(new RequestGroup(_option, std::deque<std::string>()));
|
||||
_e->_requestGroupMan->addReservedGroup(group);
|
||||
|
||||
ChangeOptionXmlRpcMethod m;
|
||||
XmlRpcRequest req("aria2.changeOption", BDE::list());
|
||||
req._params << BDE("1");
|
||||
BDE opt = BDE::dict();
|
||||
opt[PREF_MAX_DOWNLOAD_LIMIT] = BDE("100K");
|
||||
opt[PREF_MAX_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,
|
||||
group->getMaxDownloadSpeedLimit());
|
||||
CPPUNIT_ASSERT_EQUAL((unsigned int)50*1024, group->getMaxUploadSpeedLimit());
|
||||
}
|
||||
|
||||
void XmlRpcMethodTest::testNoSuchMethod()
|
||||
{
|
||||
NoSuchMethodXmlRpcMethod m;
|
||||
|
|
Loading…
Reference in New Issue