server/connectionDescription.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "connectionDescription.h"
00019
00020 #include "global.h"
00021 #include <eq/base/log.h>
00022 #include <eq/net/connection.h>
00023
00024 using namespace eq::base;
00025 using namespace std;
00026
00027 namespace eq
00028 {
00029 namespace server
00030 {
00031 #define MAKE_ATTR_STRING( attr ) ( string("EQ_CONNECTION_") + #attr )
00032
00033 std::string ConnectionDescription::_sAttributeStrings[SATTR_ALL] = {
00034 MAKE_ATTR_STRING( SATTR_HOSTNAME ),
00035 MAKE_ATTR_STRING( SATTR_PIPE_FILENAME ),
00036 MAKE_ATTR_STRING( SATTR_LAUNCH_COMMAND ),
00037 MAKE_ATTR_STRING( SATTR_FILL1 ),
00038 MAKE_ATTR_STRING( SATTR_FILL2 )
00039 };
00040 std::string ConnectionDescription::_cAttributeStrings[CATTR_ALL] = {
00041 MAKE_ATTR_STRING( CATTR_LAUNCH_COMMAND_QUOTE ),
00042 MAKE_ATTR_STRING( CATTR_FILL1 ),
00043 MAKE_ATTR_STRING( CATTR_FILL2 )
00044 };
00045 std::string ConnectionDescription::_iAttributeStrings[IATTR_ALL] = {
00046 MAKE_ATTR_STRING( IATTR_TYPE ),
00047 MAKE_ATTR_STRING( IATTR_TCPIP_PORT ),
00048 MAKE_ATTR_STRING( IATTR_LAUNCH_TIMEOUT ),
00049 MAKE_ATTR_STRING( IATTR_BANDWIDTH ),
00050 MAKE_ATTR_STRING( IATTR_FILL1 ),
00051 MAKE_ATTR_STRING( IATTR_FILL2 )
00052 };
00053
00054 ConnectionDescription::ConnectionDescription()
00055 {
00056 const Global* global = Global::instance();
00057
00058 setHostname( global->getConnectionSAttribute( SATTR_HOSTNAME ));
00059 setLaunchCommand( global->getConnectionSAttribute( SATTR_LAUNCH_COMMAND ));
00060
00061 launchCommandQuote = global->getConnectionCAttribute(
00062 CATTR_LAUNCH_COMMAND_QUOTE );
00063
00064 launchTimeout = global->getConnectionIAttribute( IATTR_LAUNCH_TIMEOUT );
00065 type = static_cast< net::ConnectionType >(
00066 global->getConnectionIAttribute( IATTR_TYPE ));
00067
00068 bandwidth = global->getConnectionIAttribute( IATTR_BANDWIDTH );
00069
00070 switch( type )
00071 {
00072 case net::CONNECTIONTYPE_TCPIP:
00073 case net::CONNECTIONTYPE_SDP:
00074 TCPIP.port = global->getConnectionIAttribute( IATTR_TCPIP_PORT );
00075 break;
00076 case net::CONNECTIONTYPE_NAMEDPIPE:
00077 setFilename( global->getConnectionSAttribute( SATTR_PIPE_FILENAME ));
00078 break;
00079 default:
00080 break;
00081 }
00082 }
00083
00084 std::ostream& operator << ( std::ostream& os,
00085 const ConnectionDescription* desc )
00086 {
00087 os << disableFlush << "connection" << endl;
00088 os << "{" << endl << indent;
00089
00090 const Global* global = Global::instance();
00091
00092 if( desc->type != global->getConnectionIAttribute(
00093 ConnectionDescription::IATTR_TYPE ))
00094 os << "type "
00095 << ( desc->type == net::CONNECTIONTYPE_TCPIP ? "TCPIP" :
00096 desc->type == net::CONNECTIONTYPE_SDP ? "SDP" :
00097 desc->type == net::CONNECTIONTYPE_PIPE ? "ANON_PIPE" :
00098 desc->type == net::CONNECTIONTYPE_NAMEDPIPE ? "PIPE" :
00099 "ERROR" ) << endl;
00100
00101 if (( desc->type == net::CONNECTIONTYPE_TCPIP ) ||
00102 ( desc->type == net::CONNECTIONTYPE_SDP ))
00103 {
00104 if( desc->TCPIP.port != global->getConnectionIAttribute(
00105 ConnectionDescription::IATTR_TCPIP_PORT ))
00106 os << "TCPIP_port " << desc->TCPIP.port << endl;
00107 }
00108
00109 if ( desc->type == net::CONNECTIONTYPE_NAMEDPIPE )
00110 {
00111 if( desc->getFilename() != global->getConnectionSAttribute(
00112 ConnectionDescription::SATTR_PIPE_FILENAME ))
00113 os << "PIPE_filename \"" << desc->getFilename() << "\"" << endl;
00114 }
00115
00116 if( desc->bandwidth != global->getConnectionIAttribute(
00117 ConnectionDescription::IATTR_BANDWIDTH ))
00118 os << "bandwidth " << desc->bandwidth << endl;
00119
00120 if( desc->launchTimeout != global->getConnectionIAttribute(
00121 ConnectionDescription::IATTR_LAUNCH_TIMEOUT ))
00122 os << "timeout " << desc->launchTimeout << endl;
00123
00124 if (( desc->type == net::CONNECTIONTYPE_TCPIP ) ||
00125 ( desc->type == net::CONNECTIONTYPE_SDP ))
00126 {
00127 if( desc->getHostname() != global->getConnectionSAttribute(
00128 ConnectionDescription::SATTR_HOSTNAME ))
00129 os << "hostname \"" << desc->getHostname() << "\"" << endl;
00130 }
00131
00132 if( desc->getLaunchCommand() != global->getConnectionSAttribute(
00133 ConnectionDescription::SATTR_LAUNCH_COMMAND ))
00134 os << "command \"" << desc->getLaunchCommand() << "\"" << endl;
00135
00136 if( desc->launchCommandQuote != global->getConnectionCAttribute(
00137 ConnectionDescription::CATTR_LAUNCH_COMMAND_QUOTE ))
00138 os << "command_quote '" << desc->launchCommandQuote << "'" << endl;
00139
00140 os << exdent << "}" << enableFlush << endl;
00141
00142 return os;
00143 }
00144
00145 }
00146 }