1 // This file may be redistributed and modified only under the terms of 2 // the GNU Lesser General Public License (See COPYING for details). 3 // Copyright (C) 2000-2001 Michael Day, Dmitry Derevyanko, Stefanus Du Toit 4 5 #ifndef ATLAS_NET_STREAM_H 6 #define ATLAS_NET_STREAM_H 7 8 #include <iosfwd> 9 #include <string> 10 #include <list> 11 12 #include <Atlas/Negotiate.h> 13 14 namespace Atlas { 15 16 class Bridge; 17 18 namespace Net { 19 20 /** Negotiation of codecs for an Atlas connection 21 22 non blocking negotiation of Codecs 23 requires a list of avalable Codecs, 24 along with the name of sender and a Socket 25 26 @see Connection 27 @see Codec 28 */ 29 30 class NegotiateHelper { 31 32 public: 33 34 NegotiateHelper(std::list<std::string> *names); 35 36 bool get(std::string &buf, const std::string & header); 37 void put(std::string &buf, const std::string & header); 38 39 private: 40 41 std::list<std::string> *names; 42 43 }; 44 45 class StreamConnect : public Atlas::Negotiate<std::iostream> 46 { 47 public: 48 49 StreamConnect(const std::string& name, std::iostream&, Atlas::Bridge*); 50 ~StreamConnect()51 virtual ~StreamConnect() {} 52 53 virtual void poll(bool can_read = true); 54 55 virtual State getState(); 56 virtual Atlas::Codec<std::iostream>* getCodec(); 57 58 private: 59 60 enum 61 { 62 SERVER_GREETING, 63 CLIENT_GREETING, 64 CLIENT_CODECS, 65 SERVER_CODECS, 66 DONE 67 }; 68 69 int state; 70 71 std::string outName; 72 std::string inName; 73 std::iostream& socket; 74 Atlas::Bridge* bridge; 75 std::list<std::string> inCodecs; 76 77 NegotiateHelper codecHelper; 78 std::string buf; 79 80 void processServerCodecs(); 81 82 bool m_canPacked; 83 bool m_canXml; 84 }; 85 86 class StreamAccept : public Atlas::Negotiate<std::iostream> 87 { 88 public: 89 90 StreamAccept(const std::string& name, std::iostream&, Atlas::Bridge*); 91 ~StreamAccept()92 virtual ~StreamAccept() {} 93 94 virtual void poll(bool can_read = true); 95 96 virtual State getState(); 97 virtual Atlas::Codec<std::iostream>* getCodec(); 98 99 private: 100 101 enum 102 { 103 SERVER_GREETING, 104 CLIENT_GREETING, 105 CLIENT_CODECS, 106 SERVER_CODECS, 107 DONE 108 }; 109 110 int state; 111 112 std::string outName; 113 std::string inName; 114 std::iostream& socket; 115 Atlas::Bridge* bridge; 116 std::list<std::string> inCodecs; 117 118 NegotiateHelper codecHelper; 119 std::string buf; 120 121 void processClientCodecs(); 122 123 bool m_canPacked; 124 bool m_canXml; 125 }; 126 127 } } // Atlas::Net 128 129 #endif 130 131