mirror of https://github.com/aria2/aria2
2010-04-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added aria2.forcePause XML-RPC command. * src/XmlRpcMethodFactory.cc * src/XmlRpcMethodImpl.cc * src/XmlRpcMethodImpl.hpull/1/head
parent
f02e08629e
commit
2e6a517aaa
|
@ -1,3 +1,10 @@
|
||||||
|
2010-04-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Added aria2.forcePause XML-RPC command.
|
||||||
|
* src/XmlRpcMethodFactory.cc
|
||||||
|
* src/XmlRpcMethodImpl.cc
|
||||||
|
* src/XmlRpcMethodImpl.h
|
||||||
|
|
||||||
2010-04-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2010-04-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Use global::wallclock
|
Use global::wallclock
|
||||||
|
|
|
@ -60,6 +60,8 @@ XmlRpcMethodFactory::create(const std::string& methodName)
|
||||||
return SharedHandle<XmlRpcMethod>(new RemoveXmlRpcMethod());
|
return SharedHandle<XmlRpcMethod>(new RemoveXmlRpcMethod());
|
||||||
} else if(methodName == PauseXmlRpcMethod::getMethodName()) {
|
} else if(methodName == PauseXmlRpcMethod::getMethodName()) {
|
||||||
return SharedHandle<XmlRpcMethod>(new PauseXmlRpcMethod());
|
return SharedHandle<XmlRpcMethod>(new PauseXmlRpcMethod());
|
||||||
|
} else if(methodName == ForcePauseXmlRpcMethod::getMethodName()) {
|
||||||
|
return SharedHandle<XmlRpcMethod>(new ForcePauseXmlRpcMethod());
|
||||||
} else if(methodName == UnpauseXmlRpcMethod::getMethodName()) {
|
} else if(methodName == UnpauseXmlRpcMethod::getMethodName()) {
|
||||||
return SharedHandle<XmlRpcMethod>(new UnpauseXmlRpcMethod());
|
return SharedHandle<XmlRpcMethod>(new UnpauseXmlRpcMethod());
|
||||||
} else if(methodName == ForceRemoveXmlRpcMethod::getMethodName()) {
|
} else if(methodName == ForceRemoveXmlRpcMethod::getMethodName()) {
|
||||||
|
|
|
@ -152,6 +152,17 @@ static BDE addRequestGroup(const SharedHandle<RequestGroup>& group,
|
||||||
return createGIDResponse(group->getGID());
|
return createGIDResponse(group->getGID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
SharedHandle<RequestGroup>
|
||||||
|
findRequestGroup(const SharedHandle<RequestGroupMan>& rgman, gid_t gid)
|
||||||
|
{
|
||||||
|
SharedHandle<RequestGroup> group = rgman->findRequestGroup(gid);
|
||||||
|
if(group.isNull()) {
|
||||||
|
group = rgman->findReservedGroup(gid);
|
||||||
|
}
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
static bool hasDictParam(const BDE& params, size_t index)
|
static bool hasDictParam(const BDE& params, size_t index)
|
||||||
{
|
{
|
||||||
return params.size() > index && params[index].isDict();
|
return params.size() > index && params[index].isDict();
|
||||||
|
@ -337,7 +348,21 @@ BDE ForceRemoveXmlRpcMethod::process
|
||||||
return removeDownload(req, e, true);
|
return removeDownload(req, e, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
BDE PauseXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
|
static void pauseRequestGroup
|
||||||
|
(const SharedHandle<RequestGroup>& group, bool forcePause)
|
||||||
|
{
|
||||||
|
// Call setHaltRequested before setPauseRequested because
|
||||||
|
// setHaltRequested calls setPauseRequested(false) internally.
|
||||||
|
if(forcePause) {
|
||||||
|
group->setForceHaltRequested(true, RequestGroup::USER_REQUEST);
|
||||||
|
} else {
|
||||||
|
group->setHaltRequested(true, RequestGroup::USER_REQUEST);
|
||||||
|
}
|
||||||
|
group->setPauseRequested(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static BDE pauseDownload
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e, bool forcePause)
|
||||||
{
|
{
|
||||||
const BDE& params = req._params;
|
const BDE& params = req._params;
|
||||||
assert(params.isList());
|
assert(params.isList());
|
||||||
|
@ -345,20 +370,27 @@ BDE PauseXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
|
||||||
throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
|
throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
|
||||||
}
|
}
|
||||||
gid_t gid = util::parseLLInt(params[0].s());
|
gid_t gid = util::parseLLInt(params[0].s());
|
||||||
SharedHandle<RequestGroup> group = e->_requestGroupMan->findRequestGroup(gid);
|
SharedHandle<RequestGroup> group = findRequestGroup(e->_requestGroupMan, gid);
|
||||||
if(group.isNull() || group->isHaltRequested()) {
|
if(group.isNull() || group->isHaltRequested()) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(StringFormat("GID#%s cannot be paused now",
|
(StringFormat("GID#%s cannot be paused now",
|
||||||
util::itos(gid).c_str()).str());
|
util::itos(gid).c_str()).str());
|
||||||
} else {
|
} else {
|
||||||
// Call setHaltRequested before setPauseRequested because
|
pauseRequestGroup(group, forcePause);
|
||||||
// setHaltRequested calls setPauseRequested(false) internally.
|
|
||||||
group->setHaltRequested(true, RequestGroup::USER_REQUEST);
|
|
||||||
group->setPauseRequested(true);
|
|
||||||
}
|
}
|
||||||
return createGIDResponse(gid);
|
return createGIDResponse(gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BDE PauseXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
|
||||||
|
{
|
||||||
|
return pauseDownload(req, e, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
BDE ForcePauseXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
|
||||||
|
{
|
||||||
|
return pauseDownload(req, e, true);
|
||||||
|
}
|
||||||
|
|
||||||
BDE UnpauseXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
|
BDE UnpauseXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
|
||||||
{
|
{
|
||||||
const BDE& params = req._params;
|
const BDE& params = req._params;
|
||||||
|
@ -587,17 +619,6 @@ void gatherStoppedDownload
|
||||||
entryDict[KEY_FILES] = files;
|
entryDict[KEY_FILES] = files;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
|
||||||
SharedHandle<RequestGroup>
|
|
||||||
findRequestGroup(const SharedHandle<RequestGroupMan>& rgman, gid_t gid)
|
|
||||||
{
|
|
||||||
SharedHandle<RequestGroup> group = rgman->findRequestGroup(gid);
|
|
||||||
if(group.isNull()) {
|
|
||||||
group = rgman->findReservedGroup(gid);
|
|
||||||
}
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE GetFilesXmlRpcMethod::process
|
BDE GetFilesXmlRpcMethod::process
|
||||||
(const XmlRpcRequest& req, DownloadEngine* e)
|
(const XmlRpcRequest& req, DownloadEngine* e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -95,6 +95,17 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ForcePauseXmlRpcMethod:public XmlRpcMethod {
|
||||||
|
protected:
|
||||||
|
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
|
public:
|
||||||
|
static const std::string& getMethodName()
|
||||||
|
{
|
||||||
|
static std::string methodName = "aria2.forcePause";
|
||||||
|
return methodName;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class UnpauseXmlRpcMethod:public XmlRpcMethod {
|
class UnpauseXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
|
|
Loading…
Reference in New Issue