00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "ServerVis.h"
00040
00041 namespace ariba {
00042 namespace utility {
00043
00044 use_logging_cpp(ServerVis);
00045 unsigned int ServerVis::nodecolor = 0;
00046
00047 typedef enum _NETWORK_ID {
00048 NETWORK_ID_BASE_COMMUNICATION = 1,
00049 NETWORK_ID_BASE_OVERLAY = 2,
00050 NETWORK_ID_EONSON = 3,
00051 NETWORK_ID_MCPO = 4,
00052 NETWORK_ID_CLIO = 5,
00053 NETWORK_ID_VIDEOSTREAM = 6,
00054 NETWORK_ID_GAME = 7,
00055 NETWORK_ID_SECURITY = 8,
00056 } NETWORK_ID;
00057
00058 string ServerVis::getNetworkName(NETWORK_ID network) const {
00059 switch(network){
00060 case NETWORK_ID_BASE_COMMUNICATION : return "BaseCommunication";
00061 case NETWORK_ID_BASE_OVERLAY : return "BaseOverlay";
00062 case NETWORK_ID_EONSON : return "Eonson";
00063 case NETWORK_ID_MCPO : return "MCPO";
00064 case NETWORK_ID_CLIO : return "CLIO";
00065 case NETWORK_ID_VIDEOSTREAM : return "Video";
00066 case NETWORK_ID_GAME : return "Game";
00067 case NETWORK_ID_SECURITY : return "Security";
00068 default : return "<undefined>";
00069 }
00070 }
00071
00072 void ServerVis::configure(string ip, unsigned int port, unsigned int _color){
00073 nodecolor = _color;
00074 if( ip.length() == 0 ) return;
00075
00076 ostringstream sport;
00077 sport << port;
00078 logging_debug( "connecting to visualization server " << ip << " on " << sport.str());
00079
00080 tcp::resolver resolver(io_service);
00081 tcp::resolver::query query(
00082 ip, sport.str(),
00083 tcp::resolver::query::passive |
00084 tcp::resolver::query::address_configured |
00085 tcp::resolver::query::numeric_service);
00086
00087 tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
00088 tcp::resolver::iterator end;
00089
00090 boost::system::error_code error = boost::asio::error::host_not_found;
00091 while (error && endpoint_iterator != end){
00092 socket.close();
00093 socket.connect(*endpoint_iterator++, error);
00094 }
00095
00096 if (error){
00097 logging_warn( "visualization could not connect to visualization server" );
00098 } else {
00099 logging_info( "connected to visualization server on " << ip << ":" << port );
00100 socketOpened = true;
00101 }
00102 }
00103
00104 ServerVis::ServerVis() : socket(io_service), socketOpened(false) {
00105 }
00106
00107 ServerVis::~ServerVis(){
00108 socket.close();
00109 }
00110
00111 void ServerVis::sendSocket(const string& msg){
00112 if( socket.is_open()==false || socketOpened==false ) return;
00113 logging_debug("sending visual command: " << msg);
00114
00115 try{
00116 socket.send( boost::asio::buffer(msg) );
00117 }catch( std::exception& e ){
00118 logging_warn("visual connection failed");
00119 socket.close();
00120 socketOpened = false;
00121 }
00122 }
00123
00124 }}