mirror of https://github.com/aria2/aria2
2009-06-24 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added tellWaiting XML-RPC method. * src/SingleFileDownloadContext.cc * src/XmlRpcMethodFactory.cc * src/XmlRpcMethodImpl.cc * src/XmlRpcMethodImpl.h * test/XmlRpcMethodTest.ccpull/1/head
parent
100ed86b5c
commit
6b2ab3ffc0
|
@ -1,3 +1,12 @@
|
||||||
|
2009-06-24 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Added tellWaiting XML-RPC method.
|
||||||
|
* src/SingleFileDownloadContext.cc
|
||||||
|
* src/XmlRpcMethodFactory.cc
|
||||||
|
* src/XmlRpcMethodImpl.cc
|
||||||
|
* src/XmlRpcMethodImpl.h
|
||||||
|
* test/XmlRpcMethodTest.cc
|
||||||
|
|
||||||
2009-06-24 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-06-24 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Updated CookieStorageTest
|
Updated CookieStorageTest
|
||||||
|
|
|
@ -83,7 +83,11 @@ bool SingleFileDownloadContext::knowsTotalLength() const
|
||||||
|
|
||||||
size_t SingleFileDownloadContext::getNumPieces() const
|
size_t SingleFileDownloadContext::getNumPieces() const
|
||||||
{
|
{
|
||||||
return (_fileEntries.front()->getLength()+_pieceLength-1)/_pieceLength;
|
if(_pieceLength == 0) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return (_fileEntries.front()->getLength()+_pieceLength-1)/_pieceLength;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SingleFileDownloadContext::getActualBasePath() const
|
std::string SingleFileDownloadContext::getActualBasePath() const
|
||||||
|
|
|
@ -71,6 +71,8 @@ XmlRpcMethodFactory::create(const std::string& methodName)
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
} else if(methodName == "aria2.tellActive") {
|
} else if(methodName == "aria2.tellActive") {
|
||||||
return SharedHandle<XmlRpcMethod>(new TellActiveXmlRpcMethod());
|
return SharedHandle<XmlRpcMethod>(new TellActiveXmlRpcMethod());
|
||||||
|
} else if(methodName == "aria2.tellWaiting") {
|
||||||
|
return SharedHandle<XmlRpcMethod>(new TellWaitingXmlRpcMethod());
|
||||||
} else if(methodName == "aria2.changeOption") {
|
} else if(methodName == "aria2.changeOption") {
|
||||||
return SharedHandle<XmlRpcMethod>(new ChangeOptionXmlRpcMethod());
|
return SharedHandle<XmlRpcMethod>(new ChangeOptionXmlRpcMethod());
|
||||||
} else if(methodName == "aria2.changeGlobalOption") {
|
} else if(methodName == "aria2.changeGlobalOption") {
|
||||||
|
|
|
@ -521,6 +521,48 @@ BDE TellActiveXmlRpcMethod::process
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BDE TellWaitingXmlRpcMethod::process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e)
|
||||||
|
{
|
||||||
|
const BDE& params = req._params;
|
||||||
|
assert(params.isList());
|
||||||
|
|
||||||
|
if(params.size() != 2 ||
|
||||||
|
!params[0].isInteger() || !params[1].isInteger() ||
|
||||||
|
params[0].i() < 0 || params[1].i() < 0) {
|
||||||
|
throw DL_ABORT_EX("Invalid argument. Specify offset and num in integer.");
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t offset = params[0].i();
|
||||||
|
size_t num = params[1].i();
|
||||||
|
|
||||||
|
BDE list = BDE::list();
|
||||||
|
const std::deque<SharedHandle<RequestGroup> >& waitings =
|
||||||
|
e->_requestGroupMan->getReservedGroups();
|
||||||
|
if(waitings.size() <= offset) {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
size_t lastDistance;
|
||||||
|
if(waitings.size() < offset+num) {
|
||||||
|
lastDistance = waitings.size();
|
||||||
|
} else {
|
||||||
|
lastDistance = offset+num;
|
||||||
|
}
|
||||||
|
std::deque<SharedHandle<RequestGroup> >::const_iterator first =
|
||||||
|
waitings.begin();
|
||||||
|
std::advance(first, offset);
|
||||||
|
std::deque<SharedHandle<RequestGroup> >::const_iterator last =
|
||||||
|
waitings.begin();
|
||||||
|
std::advance(last, lastDistance);
|
||||||
|
for(; first != last; ++first) {
|
||||||
|
BDE entryDict = BDE::dict();
|
||||||
|
entryDict["status"] = BDE_WAITING;
|
||||||
|
gatherProgress(entryDict, *first, e);
|
||||||
|
list << entryDict;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
BDE PurgeDownloadResultXmlRpcMethod::process
|
BDE PurgeDownloadResultXmlRpcMethod::process
|
||||||
(const XmlRpcRequest& req, DownloadEngine* e)
|
(const XmlRpcRequest& req, DownloadEngine* e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -97,6 +97,11 @@ protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TellWaitingXmlRpcMethod:public XmlRpcMethod {
|
||||||
|
protected:
|
||||||
|
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
|
};
|
||||||
|
|
||||||
class ChangeOptionXmlRpcMethod:public XmlRpcMethod {
|
class ChangeOptionXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
|
|
|
@ -49,6 +49,8 @@ class XmlRpcMethodTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testChangeGlobalOption);
|
CPPUNIT_TEST(testChangeGlobalOption);
|
||||||
CPPUNIT_TEST(testChangeGlobalOption_withBadOption);
|
CPPUNIT_TEST(testChangeGlobalOption_withBadOption);
|
||||||
CPPUNIT_TEST(testTellStatus_withoutGid);
|
CPPUNIT_TEST(testTellStatus_withoutGid);
|
||||||
|
CPPUNIT_TEST(testTellWaiting);
|
||||||
|
CPPUNIT_TEST(testTellWaiting_fail);
|
||||||
CPPUNIT_TEST(testNoSuchMethod);
|
CPPUNIT_TEST(testNoSuchMethod);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
private:
|
||||||
|
@ -60,6 +62,7 @@ public:
|
||||||
RequestGroup::resetGIDCounter();
|
RequestGroup::resetGIDCounter();
|
||||||
_option.reset(new Option());
|
_option.reset(new Option());
|
||||||
_option->put(PREF_DIR, "/tmp");
|
_option->put(PREF_DIR, "/tmp");
|
||||||
|
_option->put(PREF_SEGMENT_SIZE, "1048576");
|
||||||
_e.reset(new DownloadEngine(SharedHandle<EventPoll>(new SelectEventPoll())));
|
_e.reset(new DownloadEngine(SharedHandle<EventPoll>(new SelectEventPoll())));
|
||||||
_e->option = _option.get();
|
_e->option = _option.get();
|
||||||
_e->_requestGroupMan.reset
|
_e->_requestGroupMan.reset
|
||||||
|
@ -93,6 +96,8 @@ public:
|
||||||
void testChangeGlobalOption();
|
void testChangeGlobalOption();
|
||||||
void testChangeGlobalOption_withBadOption();
|
void testChangeGlobalOption_withBadOption();
|
||||||
void testTellStatus_withoutGid();
|
void testTellStatus_withoutGid();
|
||||||
|
void testTellWaiting();
|
||||||
|
void testTellWaiting_fail();
|
||||||
void testNoSuchMethod();
|
void testNoSuchMethod();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -461,6 +466,56 @@ void XmlRpcMethodTest::testTellStatus_withoutGid()
|
||||||
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void addUri(const std::string& uri,
|
||||||
|
const SharedHandle<DownloadEngine>& e)
|
||||||
|
{
|
||||||
|
AddUriXmlRpcMethod m;
|
||||||
|
XmlRpcRequest req("aria2.addUri", BDE::list());
|
||||||
|
req._params << BDE::list();
|
||||||
|
req._params[0] << BDE(uri);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(0, m.execute(req, e.get())._code);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlRpcMethodTest::testTellWaiting()
|
||||||
|
{
|
||||||
|
addUri("http://1/", _e);
|
||||||
|
addUri("http://2/", _e);
|
||||||
|
addUri("http://3/", _e);
|
||||||
|
addUri("http://4/", _e);
|
||||||
|
|
||||||
|
TellWaitingXmlRpcMethod m;
|
||||||
|
XmlRpcRequest req("aria2.tellWaiting", BDE::list());
|
||||||
|
req._params << BDE((int64_t)1);
|
||||||
|
req._params << BDE((int64_t)2);
|
||||||
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(0, res._code);
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)2, res._param.size());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("2"), res._param[0]["gid"].s());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("3"), res._param[1]["gid"].s());
|
||||||
|
// waiting.size() == offset+num
|
||||||
|
req = XmlRpcRequest("aria2.tellWaiting", BDE::list());
|
||||||
|
req._params << BDE((int64_t)1);
|
||||||
|
req._params << BDE((int64_t)3);
|
||||||
|
res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(0, res._code);
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)3, res._param.size());
|
||||||
|
// waiting.size() < offset+num
|
||||||
|
req = XmlRpcRequest("aria2.tellWaiting", BDE::list());
|
||||||
|
req._params << BDE((int64_t)1);
|
||||||
|
req._params << BDE((int64_t)4);
|
||||||
|
res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(0, res._code);
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)3, res._param.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlRpcMethodTest::testTellWaiting_fail()
|
||||||
|
{
|
||||||
|
TellWaitingXmlRpcMethod m;
|
||||||
|
XmlRpcRequest req("aria2.tellWaiting", BDE::list());
|
||||||
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace xmlrpc
|
} // namespace xmlrpc
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue