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

Defined const BDEs to avoid duplicate instantiation.
	Defined MSG_GID_NOT_PROVIDED.
	* src/XmlRpcMethodImpl.cc
	* src/message.h
pull/1/head
Tatsuhiro Tsujikawa 2009-05-15 08:53:05 +00:00
parent 409aa477ee
commit 389866621f
3 changed files with 40 additions and 22 deletions

View File

@ -1,3 +1,10 @@
2009-05-15 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Defined const BDEs to avoid duplicate instantiation.
Defined MSG_GID_NOT_PROVIDED.
* src/XmlRpcMethodImpl.cc
* src/message.h
2009-05-15 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2009-05-15 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Code cleanup Code cleanup

View File

@ -61,11 +61,21 @@
#include "BtRuntime.h" #include "BtRuntime.h"
#include "BtAnnounce.h" #include "BtAnnounce.h"
#include "prefs.h" #include "prefs.h"
#include "message.h"
namespace aria2 { namespace aria2 {
namespace xmlrpc { namespace xmlrpc {
static const BDE BDE_TRUE = BDE("true");
static const BDE BDE_FALSE = BDE("false");
static const BDE BDE_OK = BDE("OK");
static const BDE BDE_ACTIVE = BDE("active");
static const BDE BDE_WAITING = BDE("waiting");
static const BDE BDE_REMOVED = BDE("removed");
static const BDE BDE_ERROR = BDE("error");
static const BDE BDE_COMPLETE = BDE("complete");
static BDE createGIDResponse(int32_t gid) static BDE createGIDResponse(int32_t gid)
{ {
return BDE(Util::itos(gid)); return BDE(Util::itos(gid));
@ -174,7 +184,7 @@ BDE RemoveXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
assert(params.isList()); assert(params.isList());
if(params.empty() || !params[0].isString()) { if(params.empty() || !params[0].isString()) {
throw DlAbortEx("GID is not provided."); throw DlAbortEx(MSG_GID_NOT_PROVIDED);
} }
int32_t gid = Util::parseInt(params[0].s()); int32_t gid = Util::parseInt(params[0].s());
@ -244,12 +254,12 @@ static void gatherPeer(BDE& peers, const SharedHandle<PeerStorage>& ps)
peerEntry["port"] = Util::uitos((*i)->port); peerEntry["port"] = Util::uitos((*i)->port);
peerEntry["bitfield"] = Util::toHex((*i)->getBitfield(), peerEntry["bitfield"] = Util::toHex((*i)->getBitfield(),
(*i)->getBitfieldLength()); (*i)->getBitfieldLength());
peerEntry["amChoking"] = (*i)->amChoking()?BDE("true"):BDE("false"); peerEntry["amChoking"] = (*i)->amChoking()?BDE_TRUE:BDE_FALSE;
peerEntry["peerChoking"] = (*i)->peerChoking()?BDE("true"):BDE("false"); peerEntry["peerChoking"] = (*i)->peerChoking()?BDE_TRUE:BDE_FALSE;
TransferStat stat = ps->getTransferStatFor(*i); TransferStat stat = ps->getTransferStatFor(*i);
peerEntry["downloadSpeed"] = Util::uitos(stat.getDownloadSpeed()); peerEntry["downloadSpeed"] = Util::uitos(stat.getDownloadSpeed());
peerEntry["uploadSpeed"] = Util::uitos(stat.getUploadSpeed()); peerEntry["uploadSpeed"] = Util::uitos(stat.getUploadSpeed());
peerEntry["seeder"] = (*i)->isSeeder()?BDE("true"):BDE("false"); peerEntry["seeder"] = (*i)->isSeeder()?BDE_TRUE:BDE_FALSE;
peers << peerEntry; peers << peerEntry;
} }
} }
@ -270,11 +280,11 @@ static void gatherStoppedDownload
{ {
entryDict["gid"] = Util::itos(ds->gid); entryDict["gid"] = Util::itos(ds->gid);
if(ds->result == DownloadResult::IN_PROGRESS) { if(ds->result == DownloadResult::IN_PROGRESS) {
entryDict["status"] = BDE("removed"); entryDict["status"] = BDE_REMOVED;
} else if(ds->result == DownloadResult::FINISHED) { } else if(ds->result == DownloadResult::FINISHED) {
entryDict["status"] = BDE("complete"); entryDict["status"] = BDE_COMPLETE;
} else { } else {
entryDict["status"] = BDE("error"); entryDict["status"] = BDE_ERROR;
} }
} }
@ -297,7 +307,7 @@ static void createFileEntry(BDE& files, InputIterator first, InputIterator last)
BDE entry = BDE::dict(); BDE entry = BDE::dict();
entry["index"] = Util::uitos(index); entry["index"] = Util::uitos(index);
entry["path"] = (*first)->getPath(); entry["path"] = (*first)->getPath();
entry["selected"] = (*first)->isRequested()?BDE("true"):BDE("false"); entry["selected"] = (*first)->isRequested()?BDE_TRUE:BDE_FALSE;
entry["length"] = Util::uitos((*first)->getLength()); entry["length"] = Util::uitos((*first)->getLength());
files << entry; files << entry;
} }
@ -310,7 +320,7 @@ BDE GetFilesXmlRpcMethod::process
assert(params.isList()); assert(params.isList());
if(params.empty() || !params[0].isString()) { if(params.empty() || !params[0].isString()) {
throw DlAbortEx("GID is not provided."); throw DlAbortEx(MSG_GID_NOT_PROVIDED);
} }
int32_t gid = Util::parseInt(params[0].s()); int32_t gid = Util::parseInt(params[0].s());
@ -341,7 +351,7 @@ BDE GetUrisXmlRpcMethod::process
assert(params.isList()); assert(params.isList());
if(params.empty() || !params[0].isString()) { if(params.empty() || !params[0].isString()) {
throw DlAbortEx("GID is not provided."); throw DlAbortEx(MSG_GID_NOT_PROVIDED);
} }
int32_t gid = Util::parseInt(params[0].s()); int32_t gid = Util::parseInt(params[0].s());
@ -370,7 +380,7 @@ BDE GetPeersXmlRpcMethod::process
assert(params.isList()); assert(params.isList());
if(params.empty() || !params[0].isString()) { if(params.empty() || !params[0].isString()) {
throw DlAbortEx("GID is not provided."); throw DlAbortEx(MSG_GID_NOT_PROVIDED);
} }
int32_t gid = Util::parseInt(params[0].s()); int32_t gid = Util::parseInt(params[0].s());
@ -402,7 +412,7 @@ BDE TellStatusXmlRpcMethod::process
assert(params.isList()); assert(params.isList());
if(params.empty() || !params[0].isString()) { if(params.empty() || !params[0].isString()) {
throw DlAbortEx("GID is not provided."); throw DlAbortEx(MSG_GID_NOT_PROVIDED);
} }
int32_t gid = Util::parseInt(params[0].s()); int32_t gid = Util::parseInt(params[0].s());
@ -421,11 +431,11 @@ BDE TellStatusXmlRpcMethod::process
} }
gatherStoppedDownload(entryDict, ds); gatherStoppedDownload(entryDict, ds);
} else { } else {
entryDict["status"] = BDE("waiting"); entryDict["status"] = BDE_WAITING;
gatherProgress(entryDict, group, e); gatherProgress(entryDict, group, e);
} }
} else { } else {
entryDict["status"] = BDE("active"); entryDict["status"] = BDE_ACTIVE;
gatherProgress(entryDict, group, e); gatherProgress(entryDict, group, e);
} }
return entryDict; return entryDict;
@ -440,7 +450,7 @@ BDE TellActiveXmlRpcMethod::process
for(std::deque<SharedHandle<RequestGroup> >::const_iterator i = for(std::deque<SharedHandle<RequestGroup> >::const_iterator i =
groups.begin(); i != groups.end(); ++i) { groups.begin(); i != groups.end(); ++i) {
BDE entryDict = BDE::dict(); BDE entryDict = BDE::dict();
entryDict["status"] = BDE("active"); entryDict["status"] = BDE_ACTIVE;
gatherProgress(entryDict, *i, e); gatherProgress(entryDict, *i, e);
list << entryDict; list << entryDict;
} }
@ -456,7 +466,7 @@ BDE TellAllXmlRpcMethod::process
for(std::deque<SharedHandle<RequestGroup> >::const_iterator i = for(std::deque<SharedHandle<RequestGroup> >::const_iterator i =
groups.begin(); i != groups.end(); ++i) { groups.begin(); i != groups.end(); ++i) {
BDE entryDict = BDE::dict(); BDE entryDict = BDE::dict();
entryDict["status"] = BDE("active"); entryDict["status"] = BDE_ACTIVE;
gatherProgress(entryDict, *i, e); gatherProgress(entryDict, *i, e);
list << entryDict; list << entryDict;
} }
@ -465,7 +475,7 @@ BDE TellAllXmlRpcMethod::process
for(std::deque<SharedHandle<RequestGroup> >::const_iterator i = for(std::deque<SharedHandle<RequestGroup> >::const_iterator i =
waiting.begin(); i != waiting.end(); ++i) { waiting.begin(); i != waiting.end(); ++i) {
BDE entryDict = BDE::dict(); BDE entryDict = BDE::dict();
entryDict["status"] = BDE("waiting"); entryDict["status"] = BDE_WAITING;
gatherProgress(entryDict, *i, e); gatherProgress(entryDict, *i, e);
list << entryDict; list << entryDict;
} }
@ -484,7 +494,7 @@ BDE PurgeDownloadResultXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e) (const XmlRpcRequest& req, DownloadEngine* e)
{ {
e->_requestGroupMan->purgeDownloadResult(); e->_requestGroupMan->purgeDownloadResult();
return BDE("OK"); return BDE_OK;
} }
BDE ChangeOptionXmlRpcMethod::process BDE ChangeOptionXmlRpcMethod::process
@ -493,7 +503,7 @@ BDE ChangeOptionXmlRpcMethod::process
const BDE& params = req._params; const BDE& params = req._params;
assert(params.isList()); assert(params.isList());
if(params.empty() || !params[0].isString()) { if(params.empty() || !params[0].isString()) {
throw DlAbortEx("GID is not provided."); throw DlAbortEx(MSG_GID_NOT_PROVIDED);
} }
int32_t gid = Util::parseInt(params[0].s()); int32_t gid = Util::parseInt(params[0].s());
@ -512,7 +522,7 @@ BDE ChangeOptionXmlRpcMethod::process
if(option->defined(PREF_MAX_UPLOAD_LIMIT)) { if(option->defined(PREF_MAX_UPLOAD_LIMIT)) {
group->setMaxUploadSpeedLimit(option->getAsInt(PREF_MAX_UPLOAD_LIMIT)); group->setMaxUploadSpeedLimit(option->getAsInt(PREF_MAX_UPLOAD_LIMIT));
} }
return BDE("OK"); return BDE_OK;
} }
BDE ChangeGlobalOptionXmlRpcMethod::process BDE ChangeGlobalOptionXmlRpcMethod::process
@ -521,7 +531,7 @@ BDE ChangeGlobalOptionXmlRpcMethod::process
const BDE& params = req._params; const BDE& params = req._params;
assert(params.isList()); assert(params.isList());
if(params.empty() || !params[0].isDict()) { if(params.empty() || !params[0].isDict()) {
return BDE("OK"); return BDE_OK;
} }
SharedHandle<Option> option(new Option(*e->option)); SharedHandle<Option> option(new Option(*e->option));
gatherChangeableGlobalOption(option, params[0]); gatherChangeableGlobalOption(option, params[0]);
@ -533,7 +543,7 @@ BDE ChangeGlobalOptionXmlRpcMethod::process
e->_requestGroupMan->setMaxOverallUploadSpeedLimit e->_requestGroupMan->setMaxOverallUploadSpeedLimit
(option->getAsInt(PREF_MAX_OVERALL_UPLOAD_LIMIT)); (option->getAsInt(PREF_MAX_OVERALL_UPLOAD_LIMIT));
} }
return BDE("OK"); return BDE_OK;
} }
BDE NoSuchMethodXmlRpcMethod::process BDE NoSuchMethodXmlRpcMethod::process

View File

@ -170,6 +170,7 @@
#define MSG_SHOW_FILES _("Printing the contents of file '%s'...") #define MSG_SHOW_FILES _("Printing the contents of file '%s'...")
#define MSG_NOT_TORRENT_METALINK _("This file is neither Torrent nor Metalink"\ #define MSG_NOT_TORRENT_METALINK _("This file is neither Torrent nor Metalink"\
" file. Skipping.") " file. Skipping.")
#define MSG_GID_NOT_PROVIDED "GID is not provided."
#define EX_TIME_OUT _("Timeout.") #define EX_TIME_OUT _("Timeout.")
#define EX_INVALID_CHUNK_SIZE _("Invalid chunk size.") #define EX_INVALID_CHUNK_SIZE _("Invalid chunk size.")