/* */ #ifndef _D_BT_REGISTRY_H_ #define _D_BT_REGISTRY_H_ #include "common.h" #include "SharedHandle.h" #include "HandleRegistry.h" #include #include namespace aria2 { class PeerStorage; class PieceStorage; class BtAnnounce; class BtRuntime; class BtProgressInfoFile; class BtContext; class PeerObject; typedef HandleRegistry PeerStorageMap; typedef HandleRegistry PieceStorageMap; typedef HandleRegistry BtAnnounceMap; typedef HandleRegistry BtRuntimeMap; typedef HandleRegistry BtProgressInfoFileMap; typedef HandleRegistry BtContextMap; // for BtMessageFactory typedef HandleRegistry PeerObjectCluster; typedef SharedHandle PeerObjectClusterHandle; typedef HandleRegistry PeerObjectClusterRegistry; class BtRegistry { private: BtRegistry() {} static BtContextMap btContextMap; static PeerStorageMap peerStorageMap; static PieceStorageMap pieceStorageMap; static BtAnnounceMap btAnnounceMap; static BtRuntimeMap btRuntimeMap; static BtProgressInfoFileMap btProgressInfoFileMap; static PeerObjectClusterRegistry peerObjectClusterRegistry; public: static SharedHandle getBtContext(const std::string& key); static void registerBtContext(const std::string& key, const SharedHandle& btContext); static SharedHandle getPeerStorage(const std::string& key); static void registerPeerStorage(const std::string& key, const SharedHandle& peer); static SharedHandle getPieceStorage(const std::string& key); static void registerPieceStorage(const std::string& key, const SharedHandle& pieceStorage); static SharedHandle getBtRuntime(const std::string& key); static void registerBtRuntime(const std::string& key, const SharedHandle& btRuntime); static SharedHandle getBtAnnounce(const std::string& key); static void registerBtAnnounce(const std::string& key, const SharedHandle& btAnnounce); static SharedHandle getBtProgressInfoFile(const std::string& key); static void registerBtProgressInfoFile(const std::string& key, const SharedHandle& btProgressInfoFile); static std::deque > getAllBtContext(); // for PeerObject static PeerObjectClusterHandle getPeerObjectCluster(const std::string& key); static void registerPeerObjectCluster(const std::string& key, const PeerObjectClusterHandle& cluster); static void unregisterPeerObjectCluster(const std::string& key); static void unregisterAll(); static void unregister(const std::string& key); }; #define PEER_STORAGE(btContext) \ BtRegistry::getPeerStorage(btContext->getInfoHashAsString()) #define PIECE_STORAGE(btContext) \ BtRegistry::getPieceStorage(btContext->getInfoHashAsString()) #define BT_ANNOUNCE(btContext) \ BtRegistry::getBtAnnounce(btContext->getInfoHashAsString()) #define BT_RUNTIME(btContext) \ BtRegistry::getBtRuntime(btContext->getInfoHashAsString()) #define BT_PROGRESS_INFO_FILE(btContext) \ BtRegistry::getBtProgressInfoFile(btContext->getInfoHashAsString()) #define PEER_OBJECT_CLUSTER(btContext) \ BtRegistry::getPeerObjectCluster(btContext->getInfoHashAsString()) #define PEER_OBJECT(btContext, peer) \ PEER_OBJECT_CLUSTER(btContext)->getHandle(peer->getID()) #define BT_MESSAGE_DISPATCHER(btContext, peer) \ PEER_OBJECT(btContext, peer)->btMessageDispatcher #define BT_MESSAGE_RECEIVER(btContext, peer) \ PEER_OBJECT(btContext, peer)->btMessageReceiver #define BT_MESSAGE_FACTORY(btContext, peer) \ PEER_OBJECT(btContext, peer)->btMessageFactory #define BT_REQUEST_FACTORY(btContext, peer) \ PEER_OBJECT(btContext, peer)->btRequestFactory #define PEER_CONNECTION(btContext, peer) \ PEER_OBJECT(btContext, peer)->peerConnection #define EXTENSION_MESSAGE_FACTORY(btContext, peer) \ PEER_OBJECT(btContext, peer)->extensionMessageFactory } // namespace aria2 #endif // _D_BT_REGISTRY_H_