Line data Source code
1 :
2 : /* Copyright (c) 2005-2015, Stefan Eilemann <eile@equalizergraphics.com>
3 : *
4 : * This file is part of Collage <https://github.com/Eyescale/Collage>
5 : *
6 : * This library is free software; you can redistribute it and/or modify it under
7 : * the terms of the GNU Lesser General Public License version 2.1 as published
8 : * by the Free Software Foundation.
9 : *
10 : * This library is distributed in the hope that it will be useful, but WITHOUT
11 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 : * details.
14 : *
15 : * You should have received a copy of the GNU Lesser General Public License
16 : * along with this library; if not, write to the Free Software Foundation, Inc.,
17 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 : */
19 :
20 : #ifndef CO_CONNECTIONDESCRIPTION_H
21 : #define CO_CONNECTIONDESCRIPTION_H
22 :
23 : #include <co/api.h>
24 : #include <co/connectionType.h> // member enum
25 : #include <co/types.h>
26 :
27 : #include <lunchbox/referenced.h> // base class
28 :
29 : namespace co
30 : {
31 : /** Describes Connection parameters. */
32 : class ConnectionDescription : public lunchbox::Referenced
33 : {
34 : public:
35 : /** The network protocol for the connection. @version 1.0 */
36 : ConnectionType type;
37 :
38 : /** The bandwidth in kilobyte per second. @version 1.0 */
39 : int32_t bandwidth;
40 :
41 : /** The listening port (TCPIP, IB, MCIP, RDMA). @version 1.0 */
42 : uint16_t port;
43 :
44 : /** Use a random, instead of fixed, multicast port. @version 1.2 */
45 : static const uint16_t RANDOM_MULTICAST_PORT = 1;
46 :
47 : /** The hostname to bind or connect to. @version 1.0 */
48 : std::string hostname;
49 :
50 : /** The host name of the interface (multicast). @version 1.0 */
51 : std::string interfacename;
52 :
53 : /** The filename used for named pipes. @version 1.0 */
54 : std::string filename;
55 :
56 : /** Construct a new, default description. @version 1.0 */
57 576 : ConnectionDescription()
58 : : type( CONNECTIONTYPE_TCPIP )
59 : , bandwidth( 0 )
60 : , port( 0 )
61 576 : , filename( "default" )
62 576 : {}
63 :
64 : /**
65 : * Construct a description from a string representation.
66 : *
67 : * The given data is consumed, that is, the data string should be empty
68 : * on return when a single description was given.
69 : *
70 : * @sa fromString()
71 : * @version 1.0
72 : */
73 : explicit ConnectionDescription( std::string& data );
74 :
75 : /** Serialize this description to a std::ostream. @version 1.0 */
76 : CO_API void serialize( std::ostream& os ) const;
77 :
78 : /** @return this description as a string. @version 1.0 */
79 : CO_API std::string toString() const;
80 :
81 : /**
82 : * Read the connection description from a string.
83 : *
84 : * The string is consumed as the description is parsed. Two different
85 : * formats are recognized, a human-readable and a machine-readable. The
86 : * human-readable version has the format
87 : * <code>hostname[:port][:type]</code> or
88 : * <code>filename:PIPE</code>. The <code>type</code> parameter can be
89 : * TCPIP, IB, MCIP, UDT or RSP. The machine-readable format
90 : * contains all connection description parameters, is not documented and
91 : * subject to change.
92 : *
93 : * @param data the string containing the connection description.
94 : * @return true if the information was read correctly, false if not.
95 : * @version 1.0
96 : */
97 : CO_API bool fromString( std::string& data );
98 :
99 : /** @name Data Access */
100 : //@{
101 : /** @internal
102 : * @return true if the two descriptions configure the same mc group.
103 : */
104 : CO_API bool isSameMulticastGroup( ConstConnectionDescriptionPtr rhs );
105 :
106 : /** @return true if the two descriptions have the same values. */
107 : CO_API bool operator == ( const ConnectionDescription& rhs ) const;
108 :
109 : /** @return true if the two descriptions have the different values. */
110 0 : bool operator != ( const ConnectionDescription& rhs ) const
111 0 : { return !( *this == rhs ); }
112 : //@}
113 :
114 : /** @deprecated @name Deprecated Data Access */
115 : //@{
116 : CO_API void setHostname( const std::string& hostname );
117 : CO_API const std::string& getHostname() const;
118 :
119 : CO_API void setInterface( const std::string& interfacename );
120 : CO_API const std::string& getInterface() const;
121 :
122 : CO_API void setFilename( const std::string& filename );
123 : CO_API const std::string& getFilename() const;
124 : //@}
125 :
126 : protected:
127 1134 : virtual ~ConnectionDescription() {}
128 : };
129 :
130 : /** Output the given description in human-readable format. */
131 : CO_API std::ostream& operator << ( std::ostream&,
132 : const ConnectionDescription& );
133 :
134 : /** Serialize a vector of connection descriptions to a string. */
135 : CO_API std::string serialize( const ConnectionDescriptions& );
136 :
137 : /**
138 : * Deserialize a vector or connection descriptions from a string.
139 : *
140 : * Consumes the data.
141 : *
142 : * @param data The serialized connection descriptions.
143 : * @param descriptions return value, deserialized connection descriptions.
144 : * @return true on successful parsing, false otherwise.
145 : */
146 : CO_API bool deserialize( std::string& data,
147 : ConnectionDescriptions& descriptions );
148 : }
149 :
150 : #endif // CO_CONNECTION_DESCRIPTION_H
|