From 7c06b903f3493db95fcf4bd42cccc59e3b4d0692 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 11 Jul 2013 21:09:51 +0900 Subject: [PATCH] Use std::unique_ptr for ValueBase object hierarchy --- src/BtPostDownloadHandler.cc | 4 +- src/DHTAnnouncePeerMessage.cc | 2 +- src/DHTAnnouncePeerMessage.h | 2 +- src/DHTAnnouncePeerReplyMessage.cc | 4 +- src/DHTAnnouncePeerReplyMessage.h | 2 +- src/DHTFindNodeMessage.cc | 2 +- src/DHTFindNodeMessage.h | 2 +- src/DHTFindNodeReplyMessage.cc | 2 +- src/DHTFindNodeReplyMessage.h | 2 +- src/DHTGetPeersMessage.cc | 2 +- src/DHTGetPeersMessage.h | 2 +- src/DHTGetPeersReplyMessage.cc | 4 +- src/DHTGetPeersReplyMessage.h | 2 +- src/DHTPingMessage.cc | 2 +- src/DHTPingMessage.h | 2 +- src/DHTPingReplyMessage.cc | 2 +- src/DHTPingReplyMessage.h | 2 +- src/DHTQueryMessage.h | 2 +- src/DHTResponseMessage.h | 2 +- src/DefaultBtAnnounce.cc | 7 +- src/GenericParser.h | 2 +- src/HandshakeExtensionMessage.cc | 4 +- src/HttpServerBodyCommand.cc | 17 +- src/HttpServerBodyCommand.h | 6 - src/RpcMethod.cc | 13 +- src/RpcMethod.h | 6 +- src/RpcMethodImpl.cc | 516 ++++++++++---------- src/RpcMethodImpl.h | 94 ++-- src/RpcRequest.cc | 34 +- src/RpcRequest.h | 21 +- src/RpcResponse.cc | 62 +-- src/RpcResponse.h | 16 +- src/ValueBase.cc | 177 ++++--- src/ValueBase.h | 118 ++--- src/ValueBaseDiskWriter.h | 2 +- src/ValueBaseStructParserStateMachine.cc | 32 +- src/ValueBaseStructParserStateMachine.h | 15 +- src/WebSocketSession.cc | 17 +- src/WebSocketSession.h | 4 +- src/WebSocketSessionMan.cc | 12 +- src/XmlRpcDiskWriter.cc | 8 +- src/XmlRpcDiskWriter.h | 2 +- src/XmlRpcRequestParserController.cc | 35 +- src/XmlRpcRequestParserController.h | 15 +- src/XmlRpcRequestParserStateMachine.cc | 12 +- src/XmlRpcRequestParserStateMachine.h | 5 +- src/bencode2.cc | 15 +- src/bencode2.h | 12 +- src/bittorrent_helper.cc | 43 +- src/bittorrent_helper.h | 9 +- src/download_helper.cc | 11 +- src/download_helper.h | 2 +- src/json.cc | 4 +- src/json.h | 21 +- src/magnet.cc | 11 +- src/magnet.h | 11 +- src/rpc_helper.cc | 44 +- src/rpc_helper.h | 4 +- test/Bencode2Test.cc | 12 +- test/BittorrentHelperTest.cc | 52 +- test/DHTAnnouncePeerMessageTest.cc | 2 +- test/DHTAnnouncePeerReplyMessageTest.cc | 4 +- test/DHTFindNodeMessageTest.cc | 2 +- test/DHTFindNodeReplyMessageTest.cc | 8 +- test/DHTGetPeersMessageTest.cc | 2 +- test/DHTGetPeersReplyMessageTest.cc | 23 +- test/DHTMessageFactoryImplTest.cc | 30 +- test/DHTPingMessageTest.cc | 2 +- test/DHTPingReplyMessageTest.cc | 4 +- test/DefaultBtAnnounceTest.cc | 51 +- test/JsonTest.cc | 24 +- test/MagnetTest.cc | 4 +- test/MockDHTMessage.h | 4 +- test/RpcMethodTest.cc | 589 ++++++++++++----------- test/RpcResponseTest.cc | 57 ++- test/ValueBaseJsonParserTest.cc | 122 ++--- test/ValueBaseTest.cc | 32 +- 77 files changed, 1242 insertions(+), 1265 deletions(-) diff --git a/src/BtPostDownloadHandler.cc b/src/BtPostDownloadHandler.cc index 05d09f2e..0b2e73ea 100644 --- a/src/BtPostDownloadHandler.cc +++ b/src/BtPostDownloadHandler.cc @@ -71,7 +71,7 @@ void BtPostDownloadHandler::getNextRequestGroups { A2_LOG_INFO(fmt("Generating RequestGroups for Torrent file %s", requestGroup->getFirstFilePath().c_str())); - std::shared_ptr torrent; + std::unique_ptr torrent; if(requestGroup->inMemoryDownload()) { auto& dw = static_cast (requestGroup->getPieceStorage()->getDiskAdaptor().get()) @@ -104,7 +104,7 @@ void BtPostDownloadHandler::getNextRequestGroups createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(), std::vector(), "", - torrent); + torrent.get()); requestGroup->followedBy(newRgs.begin(), newRgs.end()); std::shared_ptr mi = createMetadataInfoFromFirstFileEntry(requestGroup->getGroupId(), diff --git a/src/DHTAnnouncePeerMessage.cc b/src/DHTAnnouncePeerMessage.cc index 07f69517..ef4c84fe 100644 --- a/src/DHTAnnouncePeerMessage.cc +++ b/src/DHTAnnouncePeerMessage.cc @@ -86,7 +86,7 @@ void DHTAnnouncePeerMessage::doReceivedAction() (getRemoteNode(), getTransactionID())); } -std::shared_ptr DHTAnnouncePeerMessage::getArgument() +std::unique_ptr DHTAnnouncePeerMessage::getArgument() { auto aDict = Dict::g(); aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH)); diff --git a/src/DHTAnnouncePeerMessage.h b/src/DHTAnnouncePeerMessage.h index b8045a26..84100a62 100644 --- a/src/DHTAnnouncePeerMessage.h +++ b/src/DHTAnnouncePeerMessage.h @@ -67,7 +67,7 @@ public: virtual void doReceivedAction() CXX11_OVERRIDE; - virtual std::shared_ptr getArgument() CXX11_OVERRIDE; + virtual std::unique_ptr getArgument() CXX11_OVERRIDE; virtual const std::string& getMessageType() const CXX11_OVERRIDE; diff --git a/src/DHTAnnouncePeerReplyMessage.cc b/src/DHTAnnouncePeerReplyMessage.cc index 3b094eb5..b4f0f852 100644 --- a/src/DHTAnnouncePeerReplyMessage.cc +++ b/src/DHTAnnouncePeerReplyMessage.cc @@ -50,9 +50,9 @@ DHTAnnouncePeerReplyMessage::~DHTAnnouncePeerReplyMessage() {} void DHTAnnouncePeerReplyMessage::doReceivedAction() {} -std::shared_ptr DHTAnnouncePeerReplyMessage::getResponse() +std::unique_ptr DHTAnnouncePeerReplyMessage::getResponse() { - std::shared_ptr rDict = Dict::g(); + auto rDict = Dict::g(); rDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH)); return rDict; } diff --git a/src/DHTAnnouncePeerReplyMessage.h b/src/DHTAnnouncePeerReplyMessage.h index 99dbe7ca..70cab67a 100644 --- a/src/DHTAnnouncePeerReplyMessage.h +++ b/src/DHTAnnouncePeerReplyMessage.h @@ -49,7 +49,7 @@ public: virtual void doReceivedAction() CXX11_OVERRIDE; - virtual std::shared_ptr getResponse() CXX11_OVERRIDE; + virtual std::unique_ptr getResponse() CXX11_OVERRIDE; virtual const std::string& getMessageType() const CXX11_OVERRIDE; diff --git a/src/DHTFindNodeMessage.cc b/src/DHTFindNodeMessage.cc index 1d0c0d78..69ea7fb2 100644 --- a/src/DHTFindNodeMessage.cc +++ b/src/DHTFindNodeMessage.cc @@ -69,7 +69,7 @@ void DHTFindNodeMessage::doReceivedAction() (getRemoteNode(), std::move(nodes), getTransactionID())); } -std::shared_ptr DHTFindNodeMessage::getArgument() +std::unique_ptr DHTFindNodeMessage::getArgument() { auto aDict = Dict::g(); aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH)); diff --git a/src/DHTFindNodeMessage.h b/src/DHTFindNodeMessage.h index 4101b74b..10f4263a 100644 --- a/src/DHTFindNodeMessage.h +++ b/src/DHTFindNodeMessage.h @@ -53,7 +53,7 @@ public: virtual void doReceivedAction() CXX11_OVERRIDE; - virtual std::shared_ptr getArgument() CXX11_OVERRIDE; + virtual std::unique_ptr getArgument() CXX11_OVERRIDE; virtual const std::string& getMessageType() const CXX11_OVERRIDE; diff --git a/src/DHTFindNodeReplyMessage.cc b/src/DHTFindNodeReplyMessage.cc index 8f2fcda7..45eded94 100644 --- a/src/DHTFindNodeReplyMessage.cc +++ b/src/DHTFindNodeReplyMessage.cc @@ -71,7 +71,7 @@ void DHTFindNodeReplyMessage::doReceivedAction() } } -std::shared_ptr DHTFindNodeReplyMessage::getResponse() +std::unique_ptr DHTFindNodeReplyMessage::getResponse() { auto aDict = Dict::g(); aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH)); diff --git a/src/DHTFindNodeReplyMessage.h b/src/DHTFindNodeReplyMessage.h index 7f0b57b2..cee8c731 100644 --- a/src/DHTFindNodeReplyMessage.h +++ b/src/DHTFindNodeReplyMessage.h @@ -55,7 +55,7 @@ public: virtual void doReceivedAction() CXX11_OVERRIDE; - virtual std::shared_ptr getResponse() CXX11_OVERRIDE; + virtual std::unique_ptr getResponse() CXX11_OVERRIDE; virtual const std::string& getMessageType() const CXX11_OVERRIDE; diff --git a/src/DHTGetPeersMessage.cc b/src/DHTGetPeersMessage.cc index 13abd754..42a380fa 100644 --- a/src/DHTGetPeersMessage.cc +++ b/src/DHTGetPeersMessage.cc @@ -80,7 +80,7 @@ void DHTGetPeersMessage::doReceivedAction() getTransactionID())); } -std::shared_ptr DHTGetPeersMessage::getArgument() +std::unique_ptr DHTGetPeersMessage::getArgument() { auto aDict = Dict::g(); aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH)); diff --git a/src/DHTGetPeersMessage.h b/src/DHTGetPeersMessage.h index 66fce078..a35e6e47 100644 --- a/src/DHTGetPeersMessage.h +++ b/src/DHTGetPeersMessage.h @@ -61,7 +61,7 @@ public: virtual void doReceivedAction() CXX11_OVERRIDE; - virtual std::shared_ptr getArgument() CXX11_OVERRIDE; + virtual std::unique_ptr getArgument() CXX11_OVERRIDE; virtual const std::string& getMessageType() const CXX11_OVERRIDE; diff --git a/src/DHTGetPeersReplyMessage.cc b/src/DHTGetPeersReplyMessage.cc index c88fd5cb..1366696a 100644 --- a/src/DHTGetPeersReplyMessage.cc +++ b/src/DHTGetPeersReplyMessage.cc @@ -75,7 +75,7 @@ void DHTGetPeersReplyMessage::doReceivedAction() // Returned peers and nodes are handled in DHTPeerLookupTask. } -std::shared_ptr DHTGetPeersReplyMessage::getResponse() +std::unique_ptr DHTGetPeersReplyMessage::getResponse() { auto rDict = Dict::g(); rDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH)); @@ -136,7 +136,7 @@ std::shared_ptr DHTGetPeersReplyMessage::getResponse() valuesList->append(String::g(compact, compactlen)); } } - rDict->put(VALUES, valuesList); + rDict->put(VALUES, std::move(valuesList)); } return rDict; } diff --git a/src/DHTGetPeersReplyMessage.h b/src/DHTGetPeersReplyMessage.h index 3b2c5a99..739bd9ed 100644 --- a/src/DHTGetPeersReplyMessage.h +++ b/src/DHTGetPeersReplyMessage.h @@ -65,7 +65,7 @@ public: virtual void doReceivedAction() CXX11_OVERRIDE; - virtual std::shared_ptr getResponse() CXX11_OVERRIDE; + virtual std::unique_ptr getResponse() CXX11_OVERRIDE; virtual const std::string& getMessageType() const CXX11_OVERRIDE; diff --git a/src/DHTPingMessage.cc b/src/DHTPingMessage.cc index bf7d97b5..6f718b74 100644 --- a/src/DHTPingMessage.cc +++ b/src/DHTPingMessage.cc @@ -57,7 +57,7 @@ void DHTPingMessage::doReceivedAction() (getRemoteNode(), getLocalNode()->getID(), getTransactionID())); } -std::shared_ptr DHTPingMessage::getArgument() +std::unique_ptr DHTPingMessage::getArgument() { auto aDict = Dict::g(); aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH)); diff --git a/src/DHTPingMessage.h b/src/DHTPingMessage.h index b5be6b3d..e96f5d9d 100644 --- a/src/DHTPingMessage.h +++ b/src/DHTPingMessage.h @@ -48,7 +48,7 @@ public: virtual void doReceivedAction() CXX11_OVERRIDE; - virtual std::shared_ptr getArgument() CXX11_OVERRIDE; + virtual std::unique_ptr getArgument() CXX11_OVERRIDE; virtual const std::string& getMessageType() const CXX11_OVERRIDE; diff --git a/src/DHTPingReplyMessage.cc b/src/DHTPingReplyMessage.cc index a7b3129c..38630dac 100644 --- a/src/DHTPingReplyMessage.cc +++ b/src/DHTPingReplyMessage.cc @@ -55,7 +55,7 @@ DHTPingReplyMessage::DHTPingReplyMessage void DHTPingReplyMessage::doReceivedAction() {} -std::shared_ptr DHTPingReplyMessage::getResponse() +std::unique_ptr DHTPingReplyMessage::getResponse() { auto rDict = Dict::g(); rDict->put(DHTMessage::ID, String::g(id_, DHT_ID_LENGTH)); diff --git a/src/DHTPingReplyMessage.h b/src/DHTPingReplyMessage.h index 71494e94..0169315f 100644 --- a/src/DHTPingReplyMessage.h +++ b/src/DHTPingReplyMessage.h @@ -51,7 +51,7 @@ public: virtual void doReceivedAction() CXX11_OVERRIDE; - virtual std::shared_ptr getResponse() CXX11_OVERRIDE; + virtual std::unique_ptr getResponse() CXX11_OVERRIDE; virtual const std::string& getMessageType() const CXX11_OVERRIDE; diff --git a/src/DHTQueryMessage.h b/src/DHTQueryMessage.h index e85067a1..bb8e1a92 100644 --- a/src/DHTQueryMessage.h +++ b/src/DHTQueryMessage.h @@ -55,7 +55,7 @@ public: virtual void fillMessage(Dict* msgDict) CXX11_OVERRIDE; - virtual std::shared_ptr getArgument() = 0; + virtual std::unique_ptr getArgument() = 0; virtual bool isReply() const CXX11_OVERRIDE; diff --git a/src/DHTResponseMessage.h b/src/DHTResponseMessage.h index 495fff2c..f42c3be0 100644 --- a/src/DHTResponseMessage.h +++ b/src/DHTResponseMessage.h @@ -57,7 +57,7 @@ public: virtual void fillMessage(Dict* msgDict) CXX11_OVERRIDE; - virtual std::shared_ptr getResponse() = 0; + virtual std::unique_ptr getResponse() = 0; virtual bool isReply() const CXX11_OVERRIDE; diff --git a/src/DefaultBtAnnounce.cc b/src/DefaultBtAnnounce.cc index b7f22c2e..af1630ca 100644 --- a/src/DefaultBtAnnounce.cc +++ b/src/DefaultBtAnnounce.cc @@ -283,8 +283,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse, size_t trackerResponseLength) { A2_LOG_DEBUG("Now processing tracker response."); - std::shared_ptr decodedValue = - bencode2::decode(trackerResponse, trackerResponseLength); + auto decodedValue = bencode2::decode(trackerResponse, trackerResponseLength); const Dict* dict = downcast(decodedValue); if(!dict) { throw DL_ABORT_EX(MSG_NULL_TRACKER_RESPONSE); @@ -327,7 +326,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse, incomplete_ = incomp->i(); A2_LOG_DEBUG(fmt("Incomplete:%d", incomplete_)); } - const std::shared_ptr& peerData = dict->get(BtAnnounce::PEERS); + auto peerData = dict->get(BtAnnounce::PEERS); if(!peerData) { A2_LOG_INFO(MSG_NO_PEER_LIST_RECEIVED); } else { @@ -337,7 +336,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse, peerStorage_->addPeer(peers); } } - const std::shared_ptr& peer6Data = dict->get(BtAnnounce::PEERS6); + auto peer6Data = dict->get(BtAnnounce::PEERS6); if(!peer6Data) { A2_LOG_INFO("No peers6 received."); } else { diff --git a/src/GenericParser.h b/src/GenericParser.h index 1870328a..60f4e86d 100644 --- a/src/GenericParser.h +++ b/src/GenericParser.h @@ -45,7 +45,7 @@ template class GenericParser { public: GenericParser() - : parser_(&psm_) + : parser_{&psm_} {} ~GenericParser() diff --git a/src/HandshakeExtensionMessage.cc b/src/HandshakeExtensionMessage.cc index b31ef418..c4944219 100644 --- a/src/HandshakeExtensionMessage.cc +++ b/src/HandshakeExtensionMessage.cc @@ -64,14 +64,14 @@ std::string HandshakeExtensionMessage::getPayload() if(tcpPort_ > 0) { dict.put("p", Integer::g(tcpPort_)); } - std::shared_ptr extDict = Dict::g(); + auto extDict = Dict::g(); for(int i = 0; i < ExtensionMessageRegistry::MAX_EXTENSION; ++i) { int id = extreg_.getExtensionMessageID(i); if(id) { extDict->put(strBtExtension(i), Integer::g(id)); } } - dict.put("m", extDict); + dict.put("m", std::move(extDict)); if(metadataSize_) { dict.put("metadata_size", Integer::g(metadataSize_)); } diff --git a/src/HttpServerBodyCommand.cc b/src/HttpServerBodyCommand.cc index 13e327be..67d660db 100644 --- a/src/HttpServerBodyCommand.cc +++ b/src/HttpServerBodyCommand.cc @@ -226,10 +226,9 @@ bool HttpServerBodyCommand::execute() addHttpServerResponseCommand(); return true; } - std::shared_ptr method = - rpc::RpcMethodFactory::create(req.methodName); + auto method = rpc::RpcMethodFactory::create(req.methodName); A2_LOG_INFO(fmt("Executing RPC method %s", req.methodName.c_str())); - rpc::RpcResponse res = method->execute(req, e_); + rpc::RpcResponse res = method->execute(std::move(req), e_); bool gzip = httpServer_->supportsGZip(); std::string responseData = rpc::toXml(res, gzip); httpServer_->feedResponse(std::move(responseData), "text/xml"); @@ -243,7 +242,7 @@ bool HttpServerBodyCommand::execute() case RPC_TYPE_JSON: case RPC_TYPE_JSONP: { std::string callback; - std::shared_ptr json; + std::unique_ptr json; ssize_t error = 0; if(httpServer_->getRequestType() == RPC_TYPE_JSONP) { json::JsonGetParam param = json::decodeGetParams(query); @@ -272,22 +271,20 @@ bool HttpServerBodyCommand::execute() sendJsonRpcResponse(res, callback); return true; } - const Dict* jsondict = downcast(json); + Dict* jsondict = downcast(json); if(jsondict) { rpc::RpcResponse res = rpc::processJsonRpcRequest(jsondict, e_); sendJsonRpcResponse(res, callback); } else { - const List* jsonlist = downcast(json); + List* jsonlist = downcast(json); if(jsonlist) { // This is batch call std::vector results; for(List::ValueType::const_iterator i = jsonlist->begin(), eoi = jsonlist->end(); i != eoi; ++i) { - const Dict* jsondict = downcast(*i); + Dict* jsondict = downcast(*i); if(jsondict) { - rpc::RpcResponse r = - rpc::processJsonRpcRequest(jsondict, e_); - results.push_back(r); + results.push_back(rpc::processJsonRpcRequest(jsondict, e_)); } } sendJsonRpcBatchResponse(results, callback); diff --git a/src/HttpServerBodyCommand.h b/src/HttpServerBodyCommand.h index a3086353..7817c048 100644 --- a/src/HttpServerBodyCommand.h +++ b/src/HttpServerBodyCommand.h @@ -57,12 +57,6 @@ private: Timer timeoutTimer_; bool writeCheck_; - void sendJsonRpcErrorResponse - (const std::string& httpStatus, - int code, - const std::string& message, - const std::shared_ptr& id, - const std::string& callback); void sendJsonRpcResponse (const rpc::RpcResponse& res, const std::string& callback); diff --git a/src/RpcMethod.cc b/src/RpcMethod.cc index 892ba87d..dc90bb1a 100644 --- a/src/RpcMethod.cc +++ b/src/RpcMethod.cc @@ -59,23 +59,22 @@ RpcMethod::RpcMethod() RpcMethod::~RpcMethod() {} -std::shared_ptr RpcMethod::createErrorResponse +std::unique_ptr RpcMethod::createErrorResponse (const Exception& e, const RpcRequest& req) { - std::shared_ptr params = Dict::g(); + auto params = Dict::g(); params->put((req.jsonRpc ? "code" : "faultCode"), Integer::g(1)); params->put((req.jsonRpc ? "message" : "faultString"), std::string(e.what())); - return params; + return std::move(params); } -RpcResponse RpcMethod::execute -(const RpcRequest& req, DownloadEngine* e) +RpcResponse RpcMethod::execute(RpcRequest req, DownloadEngine* e) { try { - return RpcResponse(0, process(req, e), req.id); + return RpcResponse(0, process(req, e), std::move(req.id)); } catch(RecoverableException& ex) { A2_LOG_DEBUG_EX(EX_EXCEPTION_CAUGHT, ex); - return RpcResponse(1, createErrorResponse(ex, req), req.id); + return RpcResponse(1, createErrorResponse(ex, req), std::move(req.id)); } } diff --git a/src/RpcMethod.h b/src/RpcMethod.h index 7f610731..a710aab4 100644 --- a/src/RpcMethod.h +++ b/src/RpcMethod.h @@ -69,7 +69,7 @@ protected: // Subclass must implement this function to fulfil RpcRequest req. // The return value of this method is used as a return value of RPC // request. - virtual std::shared_ptr process + virtual std::unique_ptr process (const RpcRequest& req, DownloadEngine* e) = 0; void gatherRequestOption(Option* option, const Dict* optionsDict); @@ -81,7 +81,7 @@ protected: void gatherChangeableGlobalOption(Option* option, const Dict* optionDict); - std::shared_ptr createErrorResponse + std::unique_ptr createErrorResponse (const Exception& e, const RpcRequest& req); const std::shared_ptr& getOptionParser() const @@ -95,7 +95,7 @@ public: // Do work to fulfill RpcRequest req and returns its result as // RpcResponse. This method delegates to process() method. - RpcResponse execute(const RpcRequest& req, DownloadEngine* e); + RpcResponse execute(RpcRequest req, DownloadEngine* e); }; } // namespace rpc diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc index 53ddf1ea..1edccd63 100644 --- a/src/RpcMethodImpl.cc +++ b/src/RpcMethodImpl.cc @@ -83,17 +83,17 @@ namespace aria2 { namespace rpc { namespace { -const std::shared_ptr VLB_TRUE = String::g("true"); -const std::shared_ptr VLB_FALSE = String::g("false"); -const std::shared_ptr VLB_OK = String::g("OK"); -const std::shared_ptr VLB_ACTIVE = String::g("active"); -const std::shared_ptr VLB_WAITING = String::g("waiting"); -const std::shared_ptr VLB_PAUSED = String::g("paused"); -const std::shared_ptr VLB_REMOVED = String::g("removed"); -const std::shared_ptr VLB_ERROR = String::g("error"); -const std::shared_ptr VLB_COMPLETE = String::g("complete"); -const std::shared_ptr VLB_USED = String::g("used"); -const std::shared_ptr VLB_ZERO = String::g("0"); +const char VLB_TRUE[] = "true"; +const char VLB_FALSE[] = "false"; +const char VLB_OK[] = "OK"; +const char VLB_ACTIVE[] = "active"; +const char VLB_WAITING[] = "waiting"; +const char VLB_PAUSED[] = "paused"; +const char VLB_REMOVED[] = "removed"; +const char VLB_ERROR[] = "error"; +const char VLB_COMPLETE[] = "complete"; +const char VLB_USED[] = "used"; +const char VLB_ZERO[] = "0"; const std::string KEY_GID = "gid"; const std::string KEY_ERROR_CODE = "errorCode"; @@ -145,14 +145,21 @@ const std::string KEY_NUM_ACTIVE = "numActive"; } // namespace namespace { -std::shared_ptr createGIDResponse(a2_gid_t gid) +std::unique_ptr createGIDResponse(a2_gid_t gid) { return String::g(GroupId::toHex(gid)); } } // namespace namespace { -std::shared_ptr +std::unique_ptr createOKResponse() +{ + return String::g("OK"); +} +} // namespace + +namespace { +std::unique_ptr addRequestGroup(const std::shared_ptr& group, DownloadEngine* e, bool posGiven, int pos) @@ -216,7 +223,7 @@ void extractUris(OutputIterator out, const List* src) } } // namespace -std::shared_ptr AddUriRpcMethod::process +std::unique_ptr AddUriRpcMethod::process (const RpcRequest& req, DownloadEngine* e) { const List* urisParam = checkRequiredParam(req, 0); @@ -229,13 +236,13 @@ std::shared_ptr AddUriRpcMethod::process throw DL_ABORT_EX("URI is not provided."); } - std::shared_ptr