BtRegistry.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #include "BtRegistry.h"
  36. #include "DlAbortEx.h"
  37. #include "BtContext.h"
  38. #include "PeerStorage.h"
  39. #include "PieceStorage.h"
  40. #include "BtAnnounce.h"
  41. #include "BtRuntime.h"
  42. #include "BtProgressInfoFile.h"
  43. #include "PeerObject.h"
  44. #include "BtMessageFactory.h"
  45. #include "BtRequestFactory.h"
  46. #include "BtMessageDispatcher.h"
  47. #include "BtMessageReceiver.h"
  48. #include "PeerConnection.h"
  49. #include "ExtensionMessageFactory.h"
  50. namespace aria2 {
  51. BtContextMap BtRegistry::btContextMap;
  52. PeerStorageMap BtRegistry::peerStorageMap;
  53. PieceStorageMap BtRegistry::pieceStorageMap;
  54. BtAnnounceMap BtRegistry::btAnnounceMap;
  55. BtRuntimeMap BtRegistry::btRuntimeMap;
  56. BtProgressInfoFileMap BtRegistry::btProgressInfoFileMap;
  57. PeerObjectClusterRegistry BtRegistry::peerObjectClusterRegistry;
  58. PeerStorageHandle BtRegistry::getPeerStorage(const std::string& key)
  59. {
  60. return peerStorageMap.getHandle(key);
  61. }
  62. void BtRegistry::registerPeerStorage(const std::string& key,
  63. const PeerStorageHandle& peerStorage)
  64. {
  65. peerStorageMap.registerHandle(key, peerStorage);
  66. }
  67. PieceStorageHandle
  68. BtRegistry::getPieceStorage(const std::string& key)
  69. {
  70. return pieceStorageMap.getHandle(key);
  71. }
  72. void
  73. BtRegistry::registerPieceStorage(const std::string& key,
  74. const PieceStorageHandle& pieceStorage)
  75. {
  76. pieceStorageMap.registerHandle(key, pieceStorage);
  77. }
  78. BtRuntimeHandle BtRegistry::getBtRuntime(const std::string& key)
  79. {
  80. return btRuntimeMap.getHandle(key);
  81. }
  82. void
  83. BtRegistry::registerBtRuntime(const std::string& key,
  84. const BtRuntimeHandle& btRuntime)
  85. {
  86. btRuntimeMap.registerHandle(key, btRuntime);
  87. }
  88. BtAnnounceHandle BtRegistry::getBtAnnounce(const std::string& key)
  89. {
  90. return btAnnounceMap.getHandle(key);
  91. }
  92. void
  93. BtRegistry::registerBtAnnounce(const std::string& key,
  94. const BtAnnounceHandle& btAnnounce)
  95. {
  96. btAnnounceMap.registerHandle(key, btAnnounce);
  97. }
  98. BtProgressInfoFileHandle BtRegistry::getBtProgressInfoFile(const std::string& key)
  99. {
  100. return btProgressInfoFileMap.getHandle(key);
  101. }
  102. void
  103. BtRegistry::registerBtProgressInfoFile(const std::string& key,
  104. const BtProgressInfoFileHandle& btProgressInfoFile)
  105. {
  106. btProgressInfoFileMap.registerHandle(key, btProgressInfoFile);
  107. }
  108. BtContextHandle
  109. BtRegistry::getBtContext(const std::string& key)
  110. {
  111. return btContextMap.getHandle(key);
  112. }
  113. void
  114. BtRegistry::registerBtContext(const std::string& key,
  115. const BtContextHandle& btContext)
  116. {
  117. btContextMap.registerHandle(key, btContext);
  118. }
  119. PeerObjectClusterHandle
  120. BtRegistry::getPeerObjectCluster(const std::string& key)
  121. {
  122. return peerObjectClusterRegistry.getHandle(key);
  123. }
  124. void
  125. BtRegistry::registerPeerObjectCluster(const std::string& key,
  126. const PeerObjectClusterHandle& cluster)
  127. {
  128. peerObjectClusterRegistry.registerHandle(key, cluster);
  129. }
  130. void
  131. BtRegistry::unregisterPeerObjectCluster(const std::string& key)
  132. {
  133. peerObjectClusterRegistry.unregisterHandle(key);
  134. }
  135. void BtRegistry::unregisterAll() {
  136. btContextMap.clear();
  137. peerStorageMap.clear();
  138. pieceStorageMap.clear();
  139. btAnnounceMap.clear();
  140. btRuntimeMap.clear();
  141. btProgressInfoFileMap.clear();
  142. peerObjectClusterRegistry.clear();
  143. }
  144. void BtRegistry::unregister(const std::string& key)
  145. {
  146. btContextMap.unregisterHandle(key);
  147. peerStorageMap.unregisterHandle(key);
  148. pieceStorageMap.unregisterHandle(key);
  149. btAnnounceMap.unregisterHandle(key);
  150. btRuntimeMap.unregisterHandle(key);
  151. btProgressInfoFileMap.unregisterHandle(key);
  152. peerObjectClusterRegistry.unregisterHandle(key);
  153. }
  154. } // namespace aria2