Fabcoin Core  0.16.2
P2P Digital Currency
channels.h
Go to the documentation of this file.
1 // channels.h - written and placed in the public domain by Wei Dai
2 
6 
7 #ifndef CRYPTOPP_CHANNELS_H
8 #define CRYPTOPP_CHANNELS_H
9 
10 #include "cryptlib.h"
11 #include "simple.h"
12 #include "smartptr.h"
13 #include "stdcpp.h"
14 
16 
17 #if 0
18 class MessageSwitch : public Sink
20 {
21 public:
22  void AddDefaultRoute(BufferedTransformation &destination, const std::string &channel);
23  void AddRoute(unsigned int begin, unsigned int end, BufferedTransformation &destination, const std::string &channel);
24 
25  void Put(byte inByte);
26  void Put(const byte *inString, unsigned int length);
27 
28  void Flush(bool completeFlush, int propagation=-1);
29  void MessageEnd(int propagation=-1);
30  void PutMessageEnd(const byte *inString, unsigned int length, int propagation=-1);
31  void MessageSeriesEnd(int propagation=-1);
32 
33 private:
34  typedef std::pair<BufferedTransformation *, std::string> Route;
35  struct RangeRoute
36  {
37  RangeRoute(unsigned int begin, unsigned int end, const Route &route)
38  : begin(begin), end(end), route(route) {}
39  bool operator<(const RangeRoute &rhs) const {return begin < rhs.begin;}
40  unsigned int begin, end;
41  Route route;
42  };
43 
44  typedef std::list<RangeRoute> RouteList;
45  typedef std::list<Route> DefaultRouteList;
46 
47  RouteList m_routes;
48  DefaultRouteList m_defaultRoutes;
49  unsigned int m_nCurrentMessage;
50 };
51 #endif
52 
54 {
55 public:
56  typedef std::pair<BufferedTransformation *, std::string> Route;
57  typedef std::multimap<std::string, Route> RouteMap;
58 
59  typedef std::pair<BufferedTransformation *, value_ptr<std::string> > DefaultRoute;
60  typedef std::list<DefaultRoute> DefaultRouteList;
61 
62  // SunCC workaround: can't use const_iterator here
63  typedef RouteMap::iterator MapIterator;
64  typedef DefaultRouteList::iterator ListIterator;
65 };
66 
67 class ChannelSwitch;
68 
70 {
71 public:
72  ChannelRouteIterator(ChannelSwitch &cs) : m_cs(cs), m_useDefault(false) {}
73 
74  void Reset(const std::string &channel);
75  bool End() const;
76  void Next();
77  BufferedTransformation & Destination();
78  const std::string & Channel();
79 
81  std::string m_channel;
83  MapIterator m_itMapCurrent, m_itMapEnd;
84  ListIterator m_itListCurrent, m_itListEnd;
85 
86 protected:
87  // Hide this to see if we break something...
89 };
90 
93 {
94 public:
95  ChannelSwitch() : m_it(*this), m_blocked(false) {}
96  ChannelSwitch(BufferedTransformation &destination) : m_it(*this), m_blocked(false)
97  {
98  AddDefaultRoute(destination);
99  }
100  ChannelSwitch(BufferedTransformation &destination, const std::string &outChannel) : m_it(*this), m_blocked(false)
101  {
102  AddDefaultRoute(destination, outChannel);
103  }
104 
105  void IsolatedInitialize(const NameValuePairs &parameters=g_nullNameValuePairs);
106 
107  size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
108  size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking);
109 
110  bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true);
111  bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
112 
113  byte * ChannelCreatePutSpace(const std::string &channel, size_t &size);
114 
115  void AddDefaultRoute(BufferedTransformation &destination);
116  void RemoveDefaultRoute(BufferedTransformation &destination);
117  void AddDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
118  void RemoveDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
119  void AddRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
120  void RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
121 
122 private:
124  DefaultRouteList m_defaultRoutes;
125 
127  bool m_blocked;
128 
129  friend class ChannelRouteIterator;
130 };
131 
133 
134 #endif
uint8_t byte
Definition: Common.h:57
bool m_blocked
Definition: channels.h:127
Classes providing basic library services.
std::pair< BufferedTransformation *, std::string > Route
Definition: channels.h:56
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
ChannelRouteIterator m_it
Definition: channels.h:126
std::string m_channel
Definition: channels.h:81
Abstract base classes that provide a uniform interface to this library.
Classes for automatic resource management.
RouteMap m_routeMap
Definition: channels.h:123
virtual bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
Marks the end of a series of messages, with signal propagation.
Definition: cryptlib.cpp:449
Interface for buffered transformations.
Definition: cryptlib.h:1352
ChannelSwitch(BufferedTransformation &destination, const std::string &outChannel)
Definition: channels.h:100
Route input to different and/or multiple channels based on channel ID.
Definition: channels.h:92
DefaultRouteList m_defaultRoutes
Definition: channels.h:124
std::list< DefaultRoute > DefaultRouteList
Definition: channels.h:60
bool MessageEnd(int propagation=-1, bool blocking=true)
Signals the end of messages to the object.
Definition: cryptlib.h:1434
ChannelSwitch & m_cs
Definition: channels.h:80
size_t Put(byte inByte, bool blocking=true)
Input a byte for processing.
Definition: cryptlib.h:1376
virtual bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
Definition: cryptlib.cpp:442
ChannelRouteIterator(ChannelSwitch &cs)
Definition: channels.h:72
ChannelSwitch(BufferedTransformation &destination)
Definition: channels.h:96
ListIterator m_itListEnd
Definition: channels.h:84
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
Definition: cryptlib.cpp:76
DefaultRouteList::iterator ListIterator
Definition: channels.h:64
std::multimap< std::string, Route > RouteMap
Definition: channels.h:57
uint8_t const size_t const size
Definition: sha3.h:20
MapIterator m_itMapEnd
Definition: channels.h:83
Implementation of BufferedTransformation&#39;s attachment interface.
Definition: simple.h:331
std::pair< BufferedTransformation *, value_ptr< std::string > > DefaultRoute
Definition: channels.h:59
size_t PutMessageEnd(const byte *inString, size_t length, int propagation=-1, bool blocking=true)
Input multiple bytes for processing and signal the end of a message.
Definition: cryptlib.h:1447
#define NAMESPACE_END
Definition: config.h:201
std::vector< char * > parameters
Definition: boostTest.cpp:46
#define CRYPTOPP_DLL
Definition: config.h:704
Multiple channels support for custom signal processing.
Definition: simple.h:215
RouteMap::iterator MapIterator
Definition: channels.h:63
bool operator<(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
Definition: asn.h:562
Interface for retrieving values given their names.
Definition: cryptlib.h:279