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
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
00048 class ChannelSwitch : public Multichannel<Sink>
00049 {
00050 public:
00051 ChannelSwitch() {}
00052 ChannelSwitch(BufferedTransformation &destination)
00053 {
00054 AddDefaultRoute(destination);
00055 }
00056 ChannelSwitch(BufferedTransformation &destination, const std::string &outChannel)
00057 {
00058 AddDefaultRoute(destination, outChannel);
00059 }
00060
00061 unsigned int ChannelPut2(const std::string &channel, const byte *begin, unsigned int length, int messageEnd, bool blocking);
00062 unsigned int ChannelPutModifiable2(const std::string &channel, byte *begin, unsigned int length, int messageEnd, bool blocking);
00063
00064 void ChannelInitialize(const std::string &channel, const NameValuePairs ¶meters=g_nullNameValuePairs, int propagation=-1);
00065 bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true);
00066 bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
00067
00068 byte * ChannelCreatePutSpace(const std::string &channel, unsigned int &size);
00069
00070 void AddDefaultRoute(BufferedTransformation &destination);
00071 void RemoveDefaultRoute(BufferedTransformation &destination);
00072 void AddDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
00073 void RemoveDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
00074 void AddRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
00075 void RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
00076
00077 private:
00078 typedef std::pair<BufferedTransformation *, std::string> Route;
00079 typedef std::multimap<std::string, Route> RouteMap;
00080 RouteMap m_routeMap;
00081
00082 typedef std::pair<BufferedTransformation *, value_ptr<std::string> > DefaultRoute;
00083 typedef std::list<DefaultRoute> DefaultRouteList;
00084 DefaultRouteList m_defaultRoutes;
00085
00086 friend class ChannelRouteIterator;
00087 };
00088
00089 NAMESPACE_END
00090
00091 #endif