00001 /* 00002 * Copyright (C) 2003-2009 Olivier Boudeville 00003 * 00004 * This file is part of the Ceylan library. 00005 * 00006 * The Ceylan library is free software: you can redistribute it and/or modify 00007 * it under the terms of either the GNU Lesser General Public License or 00008 * the GNU General Public License, as they are published by the Free Software 00009 * Foundation, either version 3 of these Licenses, or (at your option) 00010 * any later version. 00011 * 00012 * The Ceylan library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License and the GNU General Public License 00016 * for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License and the GNU General Public License along with the Ceylan library. 00020 * If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * Author: Olivier Boudeville (olivier.boudeville@esperide.com) 00023 * 00024 */ 00025 00026 00027 #include "CeylanAnonymousProtocolAwareStreamSocket.h" 00028 00029 00030 #include "CeylanLogPlug.h" // for LogPlug 00031 #include "CeylanOperators.h" // for toString 00032 #include "CeylanProtocolServer.h" // for ProtocolServer 00033 00034 00035 using namespace Ceylan ; 00036 using namespace Ceylan::System ; 00037 using namespace Ceylan::Middleware ; 00038 using namespace Ceylan::Network ; 00039 using namespace Ceylan::Log ; 00040 00041 00042 using std::string ; 00043 00044 00045 00046 00047 00048 AnonymousProtocolAwareStreamSocket::AnonymousProtocolAwareStreamSocket( 00049 System::FileDescriptor listeningFD, 00050 ProtocolServer & protocolServerToTrigger ) : 00051 AnonymousStreamSocket( listeningFD ), 00052 _protocolServer( & protocolServerToTrigger ) 00053 { 00054 00055 // Here the connection is accepted. 00056 00057 } 00058 00059 00060 00061 AnonymousProtocolAwareStreamSocket::AnonymousProtocolAwareStreamSocket( 00062 System::FileDescriptor listeningFD ) : 00063 AnonymousStreamSocket( listeningFD, /* blocking */ false ), 00064 _protocolServer( 0 ) 00065 { 00066 00067 // Here the connection is accepted. 00068 00069 } 00070 00071 00072 00073 AnonymousProtocolAwareStreamSocket::~AnonymousProtocolAwareStreamSocket() 00074 throw() 00075 { 00076 00077 if ( _protocolServer != 0 ) 00078 delete _protocolServer ; 00079 00080 } 00081 00082 00083 00084 bool AnonymousProtocolAwareStreamSocket::hasProtocolServer() const 00085 { 00086 00087 return _protocolServer != 0 ; 00088 00089 } 00090 00091 00092 00093 ProtocolServer & AnonymousProtocolAwareStreamSocket::getProtocolServer() 00094 { 00095 00096 if ( _protocolServer == 0 ) 00097 throw AnonymousStreamSocketException( 00098 "AnonymousProtocolAwareStreamSocket::getProtocolServer: " 00099 "no available protocol server." ) ; 00100 00101 return * _protocolServer ; 00102 00103 } 00104 00105 00106 00107 void AnonymousProtocolAwareStreamSocket::setProtocolServer( 00108 ProtocolServer & newProtocolServer ) 00109 { 00110 00111 if ( _protocolServer != 0 ) 00112 delete _protocolServer ; 00113 00114 _protocolServer = & newProtocolServer ; 00115 00116 } 00117 00118 00119 00120 const std::string AnonymousProtocolAwareStreamSocket::toString( 00121 Ceylan::VerbosityLevels level ) const 00122 { 00123 00124 string res= "AnonymousProtocolAwareStreamSocket" ; 00125 00126 if ( level != Ceylan::low ) 00127 { 00128 00129 /* 00130 * Avoid cycles in toString calls: 00131 * AnonymousProtocolAwareStreamSocket -> ProtocolServer 00132 * -> ProtocolEndpoint -> Marshaller 00133 * -> AnonymousProtocolAwareStreamSocket 00134 * 00135 */ 00136 00137 if ( _protocolServer != 0 ) 00138 res += " associated with " 00139 + _protocolServer->toString( Ceylan::low ) ; 00140 else 00141 res += " not associated with any protocol server" ; 00142 00143 } 00144 00145 res += ". It is an " + AnonymousStreamSocket::toString( level ) ; 00146 00147 return res ; 00148 00149 } 00150