Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

# channels.h

    00001 #ifndef CRYPTOPP_CHANNELS_H
    00002 #define CRYPTOPP_CHANNELS_H
    00003
    00004 #include "simple.h"
    00005 #include "smartptr.h"
    00006 #include <map>
    00007 #include <list>
    00008
    00009 NAMESPACE_BEGIN(CryptoPP)
    00010
    00011 #if 0
    00012 //! Route input on default channel to different and/or multiple channels based on message sequence number
    00013 class MessageSwitch : public Sink
    00014 {
    00015 public:
    00016         void AddDefaultRoute(BufferedTransformation &destination, const std::string &channel);
    00017         void AddRoute(unsigned int begin, unsigned int end, BufferedTransformation &destination, const std::string &channel);
    00018
    00019         void Put(byte inByte);
    00020         void Put(const byte *inString, unsigned int length);
    00021
    00022         void Flush(bool completeFlush, int propagation=-1);
    00023         void MessageEnd(int propagation=-1);
    00024         void PutMessageEnd(const byte *inString, unsigned int length, int propagation=-1);
    00025         void MessageSeriesEnd(int propagation=-1);
    00026
    00027 private:
    00028         typedef std::pair<BufferedTransformation *, std::string> Route;
    00029         struct RangeRoute
    00030         {
    00031                 RangeRoute(unsigned int begin, unsigned int end, const Route &route)
    00032                         : begin(begin), end(end), route(route) {}
    00033                 bool operator<(const RangeRoute &rhs) const {return begin < rhs.begin;}
    00034                 unsigned int begin, end;
    00035                 Route route;
    00036         };
    00037
    00038         typedef std::list<RangeRoute> RouteList;
    00039         typedef std::list<Route> DefaultRouteList;
    00040
    00041         RouteList m_routes;
    00042         DefaultRouteList m_defaultRoutes;
    00043         unsigned int m_nCurrentMessage;
    00044 };
    00045 #endif
    00046
    00047 class ChannelSwitchTypedefs
    00048 {
    00049 public:
    00050         typedef std::pair<BufferedTransformation *, std::string> Route;
    00051         typedef std::multimap<std::string, Route> RouteMap;
    00052
    00053         typedef std::pair<BufferedTransformation *, value_ptr<std::string> > DefaultRoute;
    00054         typedef std::list<DefaultRoute> DefaultRouteList;
    00055
    00056         typedef RouteMap::const_iterator MapIterator;
    00057         typedef DefaultRouteList::const_iterator ListIterator;
    00058 };
    00059
    00060 class ChannelSwitch;
    00061
    00062 class ChannelRouteIterator : public ChannelSwitchTypedefs
    00063 {
    00064 public:
    00065         ChannelSwitch& m_cs;
    00066         std::string m_channel;
    00067         bool m_useDefault;
    00068         MapIterator m_itMapCurrent, m_itMapEnd;
    00069         ListIterator m_itListCurrent, m_itListEnd;
    00070
    00071         ChannelRouteIterator(ChannelSwitch &cs) : m_cs(cs) {}
    00072         void Reset(const std::string &channel);
    00073         bool End() const;
    00074         void Next();
    00075         BufferedTransformation & Destination();
    00076         const std::string & Channel();
    00077 };
    00078
    00079 //! Route input to different and/or multiple channels based on channel ID
    00080 class CRYPTOPP_DLL ChannelSwitch : public Multichannel<Sink>, public ChannelSwitchTypedefs
    00081 {
    00082 public:
    00083         ChannelSwitch() : m_it(*this), m_blocked(false) {}
    00084         ChannelSwitch(BufferedTransformation &destination) : m_it(*this), m_blocked(false)
    00085         {
    00086                 AddDefaultRoute(destination);
    00087         }
    00088         ChannelSwitch(BufferedTransformation &destination, const std::string &outChannel) : m_it(*this), m_blocked(false)
    00089         {
    00090                 AddDefaultRoute(destination, outChannel);
    00091         }
    00092
    00093         void IsolatedInitialize(const NameValuePairs &parameters=g_nullNameValuePairs);
    00094
    00095         unsigned int ChannelPut2(const std::string &channel, const byte *begin, unsigned int length, int messageEnd, bool blocking);
    00096         unsigned int ChannelPutModifiable2(const std::string &channel, byte *begin, unsigned int length, int messageEnd, bool blocking);
    00097
    00098         bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true);
    00099         bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
    00100
    00101         byte * ChannelCreatePutSpace(const std::string &channel, unsigned int &size);
    00102
    00103         void AddDefaultRoute(BufferedTransformation &destination);
    00104         void RemoveDefaultRoute(BufferedTransformation &destination);
    00105         void AddDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
    00106         void RemoveDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
    00107         void AddRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
    00108         void RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
    00109
    00110 private:
    00111         RouteMap m_routeMap;
    00112         DefaultRouteList m_defaultRoutes;
    00113
    00114         ChannelRouteIterator m_it;
    00115         bool m_blocked;
    00116
    00117         friend class ChannelRouteIterator;
    00118 };
    00119
    00120 NAMESPACE_END
    00121
    00122 #endif