/* */ #ifndef _D_BT_REGISTRY_H_ #define _D_BT_REGISTRY_H_ #include "common.h" #include "BtContext.h" #include "PeerStorage.h" #include "PieceStorage.h" #include "BtAnnounce.h" #include "BtRuntime.h" #include "BtProgressInfoFile.h" #include "PeerObject.h" #include "HandleRegistry.h" #include 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 BtContextHandle getBtContext(const string& key); static void registerBtContext(const string& key, const BtContextHandle& btContext); static PeerStorageHandle getPeerStorage(const string& key); static void registerPeerStorage(const string& key, const PeerStorageHandle& peer); static PieceStorageHandle getPieceStorage(const string& key); static void registerPieceStorage(const string& key, const PieceStorageHandle& pieceStorage); static BtRuntimeHandle getBtRuntime(const string& key); static void registerBtRuntime(const string& key, const BtRuntimeHandle& btRuntime); static BtAnnounceHandle getBtAnnounce(const string& key); static void registerBtAnnounce(const string& key, const BtAnnounceHandle& btAnnounce); static BtProgressInfoFileHandle getBtProgressInfoFile(const string& key); static void registerBtProgressInfoFile(const string& key, const BtProgressInfoFileHandle& btProgressInfoFile); // for PeerObject static PeerObjectClusterHandle getPeerObjectCluster(const string& key); static void registerPeerObjectCluster(const string& key, const PeerObjectClusterHandle& cluster); static void unregisterPeerObjectCluster(const string& key); static void unregisterAll(); static void unregister(const 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 #endif // _D_BT_REGISTRY_H_