Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
4.2 KiB

  1. // channels.h - written and placed in the public domain by Wei Dai
  2. //! \file
  3. //! \headerfile channels.h
  4. //! \brief Classes for multiple named channels
  5. #ifndef CRYPTOPP_CHANNELS_H
  6. #define CRYPTOPP_CHANNELS_H
  7. #include "cryptlib.h"
  8. #include "simple.h"
  9. #include "smartptr.h"
  10. #include "stdcpp.h"
  11. NAMESPACE_BEGIN(CryptoPP)
  12. #if 0
  13. //! Route input on default channel to different and/or multiple channels based on message sequence number
  14. class MessageSwitch : public Sink
  15. {
  16. public:
  17. void AddDefaultRoute(BufferedTransformation &destination, const std::string &channel);
  18. void AddRoute(unsigned int begin, unsigned int end, BufferedTransformation &destination, const std::string &channel);
  19. void Put(byte inByte);
  20. void Put(const byte *inString, unsigned int length);
  21. void Flush(bool completeFlush, int propagation=-1);
  22. void MessageEnd(int propagation=-1);
  23. void PutMessageEnd(const byte *inString, unsigned int length, int propagation=-1);
  24. void MessageSeriesEnd(int propagation=-1);
  25. private:
  26. typedef std::pair<BufferedTransformation *, std::string> Route;
  27. struct RangeRoute
  28. {
  29. RangeRoute(unsigned int begin, unsigned int end, const Route &route)
  30. : begin(begin), end(end), route(route) {}
  31. bool operator<(const RangeRoute &rhs) const {return begin < rhs.begin;}
  32. unsigned int begin, end;
  33. Route route;
  34. };
  35. typedef std::list<RangeRoute> RouteList;
  36. typedef std::list<Route> DefaultRouteList;
  37. RouteList m_routes;
  38. DefaultRouteList m_defaultRoutes;
  39. unsigned int m_nCurrentMessage;
  40. };
  41. #endif
  42. class ChannelSwitchTypedefs
  43. {
  44. public:
  45. typedef std::pair<BufferedTransformation *, std::string> Route;
  46. typedef std::multimap<std::string, Route> RouteMap;
  47. typedef std::pair<BufferedTransformation *, value_ptr<std::string> > DefaultRoute;
  48. typedef std::list<DefaultRoute> DefaultRouteList;
  49. // SunCC workaround: can't use const_iterator here
  50. typedef RouteMap::iterator MapIterator;
  51. typedef DefaultRouteList::iterator ListIterator;
  52. };
  53. class ChannelSwitch;
  54. class ChannelRouteIterator : public ChannelSwitchTypedefs
  55. {
  56. public:
  57. ChannelRouteIterator(ChannelSwitch &cs) : m_cs(cs), m_useDefault(false) {}
  58. void Reset(const std::string &channel);
  59. bool End() const;
  60. void Next();
  61. BufferedTransformation & Destination();
  62. const std::string & Channel();
  63. ChannelSwitch& m_cs;
  64. std::string m_channel;
  65. bool m_useDefault;
  66. MapIterator m_itMapCurrent, m_itMapEnd;
  67. ListIterator m_itListCurrent, m_itListEnd;
  68. protected:
  69. // Hide this to see if we break something...
  70. ChannelRouteIterator();
  71. };
  72. //! Route input to different and/or multiple channels based on channel ID
  73. class CRYPTOPP_DLL ChannelSwitch : public Multichannel<Sink>, public ChannelSwitchTypedefs
  74. {
  75. public:
  76. ChannelSwitch() : m_it(*this), m_blocked(false) {}
  77. ChannelSwitch(BufferedTransformation &destination) : m_it(*this), m_blocked(false)
  78. {
  79. AddDefaultRoute(destination);
  80. }
  81. ChannelSwitch(BufferedTransformation &destination, const std::string &outChannel) : m_it(*this), m_blocked(false)
  82. {
  83. AddDefaultRoute(destination, outChannel);
  84. }
  85. void IsolatedInitialize(const NameValuePairs &parameters=g_nullNameValuePairs);
  86. size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
  87. size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking);
  88. bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true);
  89. bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
  90. byte * ChannelCreatePutSpace(const std::string &channel, size_t &size);
  91. void AddDefaultRoute(BufferedTransformation &destination);
  92. void RemoveDefaultRoute(BufferedTransformation &destination);
  93. void AddDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
  94. void RemoveDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
  95. void AddRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
  96. void RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
  97. private:
  98. RouteMap m_routeMap;
  99. DefaultRouteList m_defaultRoutes;
  100. ChannelRouteIterator m_it;
  101. bool m_blocked;
  102. friend class ChannelRouteIterator;
  103. };
  104. NAMESPACE_END
  105. #endif