File indexing completed on 2025-01-05 04:37:12

0001 /*
0002     SPDX-FileCopyrightText: 2012 Joris Guisson <joris.guisson@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef DHT_RPCMSGFACTORY_H
0008 #define DHT_RPCMSGFACTORY_H
0009 
0010 #include "rpcmsg.h"
0011 #include <ktorrent_export.h>
0012 
0013 namespace dht
0014 {
0015 /**
0016  * Interface to resolve the method of an RPC call given an mtid
0017  */
0018 class RPCMethodResolver
0019 {
0020 public:
0021     virtual ~RPCMethodResolver()
0022     {
0023     }
0024 
0025     /// Return the method associated with an mtid
0026     virtual Method findMethod(const QByteArray &mtid) = 0;
0027 };
0028 
0029 /**
0030  * Creates RPC message objects out of a BDictNode
0031  */
0032 class KTORRENT_EXPORT RPCMsgFactory
0033 {
0034 public:
0035     RPCMsgFactory();
0036     virtual ~RPCMsgFactory();
0037 
0038     /**
0039      * Creates a message out of a BDictNode.
0040      * @param dict The BDictNode
0041      * @param srv The RPCMethodResolver
0042      * @return A newly created message
0043      * @throw bt::Error if something goes wrong
0044      */
0045     RPCMsg::Ptr build(bt::BDictNode *dict, RPCMethodResolver *method_resolver);
0046 
0047 private:
0048     RPCMsg::Ptr buildRequest(bt::BDictNode *dict);
0049     RPCMsg::Ptr buildResponse(bt::BDictNode *dict, RPCMethodResolver *method_resolver);
0050 };
0051 
0052 }
0053 
0054 #endif // DHT_RPCMSGFACTORY_H