X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Fcomm%2FCommunicator.cpp;h=eb115a19fba9239899721df4910a7007d8c885c7;hb=5a6cba5fde2b2f538a7515f8293cc0a8d9589dfa;hp=07cb224bc50f6cf52fe5a1e00f3123ae182fcbef;hpb=39033fd99e58e994a5e98c1060dcc79e0d81f9c9;p=anna.git diff --git a/source/comm/Communicator.cpp b/source/comm/Communicator.cpp index 07cb224..eb115a1 100644 --- a/source/comm/Communicator.cpp +++ b/source/comm/Communicator.cpp @@ -1,37 +1,9 @@ -// ANNA - Anna is Not Nothingness Anymore -// -// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo -// -// http://redmine.teslayout.com/projects/anna-suite -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of the copyright holder nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Authors: eduardo.ramos.testillano@gmail.com -// cisco.tierra@gmail.com +// ANNA - Anna is Not Nothingness Anymore // +// // +// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo // +// // +// See project site at http://redmine.teslayout.com/projects/anna-suite // +// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE // #include @@ -117,7 +89,7 @@ Communicator::~Communicator() { } void Communicator::setRecoveryTime(const Millisecond &recoveryTime) -throw(RuntimeException) { +noexcept(false) { if(recoveryTime < MinRecoveryTime || recoveryTime > MaxRecoveryTime) { string msg("comm::Communicator::setRecoveryTime | "); msg += functions::asString("RecoveryTime (%d ms) must be between %d ms and %d ms", recoveryTime.getValue(), MinRecoveryTime.getValue(), MaxRecoveryTime.getValue()); @@ -128,7 +100,7 @@ throw(RuntimeException) { } void Communicator::setTryingConnectionTime(const Millisecond &tryingConnectionTime) -throw(RuntimeException) { +noexcept(false) { if(tryingConnectionTime < MinTryingConnectionTime || tryingConnectionTime > MaxTryingConnectionTime) { string msg("comm::Communicator::setTryingConnectionTime | "); msg += functions::asString("TryingConnectionTime (%d ms) must be between %d ms and %d ms", tryingConnectionTime.getValue(), MinTryingConnectionTime.getValue(), MaxTryingConnectionTime.getValue()); @@ -140,7 +112,7 @@ throw(RuntimeException) { //static void Communicator::setReceivingChunkSize(const int receivingChunkSize) -throw(RuntimeException) { +noexcept(false) { if(receivingChunkSize < MinReceivingChunkSize || receivingChunkSize > MaxReceivingChunkSize) { string msg("comm::Communicator::setReceivingChunkSize | "); msg += functions::asString("ReceivingChunkSize (%d bytes) must be between %d bytes and %d bytes", receivingChunkSize, MinReceivingChunkSize, MaxReceivingChunkSize); @@ -152,7 +124,7 @@ throw(RuntimeException) { } void Communicator::setLevelOfDenialService(const int levelOfDenialService) -throw(RuntimeException) { +noexcept(false) { const int min(comm::CongestionController::MaxLevel - 2); const int max(comm::CongestionController::MaxLevel); @@ -166,7 +138,7 @@ throw(RuntimeException) { } void Communicator::attach(ServerSocket* serverSocket) -throw(RuntimeException) { +noexcept(false) { if(serverSocket == NULL) throw RuntimeException("Cannot attach a NULL comm::ServerSocket", ANNA_FILE_LOCATION); @@ -184,7 +156,7 @@ throw(RuntimeException) { } void Communicator::attach(BinderSocket* binderSocket) -throw(RuntimeException) { +noexcept(false) { if(binderSocket == NULL) throw RuntimeException("Cannot attach a NULL comm::BinderSocket", ANNA_FILE_LOCATION); @@ -204,7 +176,7 @@ throw(RuntimeException) { * Se invoca desde comm::handler::ServerSocket::accept [Tx] -> */ void Communicator::attach(LocalConnection* localConnection) -throw(RuntimeException) { +noexcept(false) { if(localConnection == NULL) throw RuntimeException("Cannot attach a NULL comm::LocalConnection", ANNA_FILE_LOCATION); @@ -258,7 +230,7 @@ throw(RuntimeException) { * los métodos Communicator::attach. */ void Communicator::attach(RemoteConnection* remoteConnection) -throw(RuntimeException) { +noexcept(false) { if(remoteConnection == NULL) throw RuntimeException("Cannot attach a NULL comm::RemoteConnection", ANNA_FILE_LOCATION); @@ -273,7 +245,7 @@ throw(RuntimeException) { } void Communicator::attach(ClientSocket* socket) -throw(RuntimeException) { +noexcept(false) { if(socket == NULL) throw RuntimeException("Cannot attach a NULL comm::ClientSocket", ANNA_FILE_LOCATION); @@ -288,7 +260,7 @@ throw(RuntimeException) { } void Communicator::attach(DatagramSocket* socket) -throw(RuntimeException) { +noexcept(false) { if(socket == NULL) throw RuntimeException("Cannot attach a NULL comm::DatagramSocket", ANNA_FILE_LOCATION); @@ -303,7 +275,7 @@ throw(RuntimeException) { } void Communicator::attach(Handler* handler) -throw(RuntimeException) { +noexcept(false) { if(handler == NULL) throw RuntimeException("Cannot attach a NULL comm::Handler", ANNA_FILE_LOCATION); @@ -320,7 +292,7 @@ throw(RuntimeException) { } void Communicator::attach(Service* service) -throw(RuntimeException) { +noexcept(false) { if(service == NULL) throw RuntimeException("Cannot attach a NULL comm::Service", ANNA_FILE_LOCATION); @@ -340,7 +312,7 @@ throw(RuntimeException) { } void Communicator::insert(Handler* handler) -throw(RuntimeException) { +noexcept(false) { handler->initialize(); if(handler->getfd() < 0) { @@ -373,7 +345,7 @@ throw(RuntimeException) { } void Communicator::detach(ServerSocket* serverSocket) -throw() { +{ if(serverSocket == NULL) return; @@ -385,7 +357,7 @@ throw() { } void Communicator::detach(ClientSocket* clientSocket) -throw() { +{ if(clientSocket == NULL) return; @@ -393,7 +365,7 @@ throw() { } void Communicator::detach(BinderSocket* binderSocket) -throw() { +{ if(binderSocket == NULL) return; @@ -405,7 +377,7 @@ throw() { * (1) Si se cierra la conexion con el cliente que al que atencia este proceso clonado => debe terminar la ejecucion. */ void Communicator::detach(Handler* handler) -throw() { +{ if(handler == NULL) return; @@ -440,7 +412,7 @@ throw() { } const Handler* Communicator::getHandler(const ClientSocket& clientSocket) -throw(RuntimeException) { +noexcept(false) { Guard guard(this, "comm::Communicator::getHandler"); Handler* result = find(clientSocket.getfd()); @@ -451,6 +423,7 @@ throw(RuntimeException) { case Handler::Type::Custom: result = NULL; break; + default: break; } } @@ -465,7 +438,7 @@ throw(RuntimeException) { // streams pero la forma de recorrer el bucle nos blinda (un poco) de anomalias. //---------------------------------------------------------------------------------------------- void Communicator::accept() -throw(RuntimeException) { +noexcept(false) { LOGMETHOD(TraceMethod traceMethod("comm::Communicator", "accept", ANNA_FILE_LOCATION)); if(isServing() == true) @@ -492,7 +465,7 @@ throw(RuntimeException) { } void Communicator::singlethreadedAccept() -throw(RuntimeException) { +noexcept(false) { LOGMETHOD(TraceMethod traceMethod(Logger::Local7, "comm::Communicator", "singlethreadedAccept", ANNA_FILE_LOCATION)); Handler* handler; Microsecond maxTime; @@ -567,7 +540,7 @@ throw(RuntimeException) { } void Communicator::multithreadedAccept() -throw(RuntimeException) { +noexcept(false) { LOGMETHOD(TraceMethod traceMethod(Logger::Local7, "comm::Communicator", "multithreadedAccept", ANNA_FILE_LOCATION)); { Guard guard(this, "comm::Communicator::multithreadedAccept"); @@ -602,7 +575,7 @@ throw(RuntimeException) { } void Communicator::requestStop() -throw() { +{ if(a_requestedStop == true) return; @@ -628,7 +601,7 @@ throw() { } bool Communicator::isUsable(const ClientSocket* clientSocket) -throw() { +{ if(clientSocket == NULL) return false; @@ -643,7 +616,7 @@ throw() { } void Communicator::setStatus(const Status& status) -throw() { +{ Guard guard(this, "comm::Communicator::setStatus"); if(a_status != status) @@ -657,7 +630,7 @@ throw() { } void Communicator::eventBreakAddress(const in_addr_t& address) -throw() { +{ Device* device = Network::instantiate().find(address); if(device->getStatus() == Device::Status::Down) @@ -701,7 +674,7 @@ throw() { } void Communicator::eventRecoverAddress(const in_addr_t& address) -throw() { +{ Device* device = Network::instantiate().find(address); if(device->getStatus() == Device::Status::Up) @@ -721,7 +694,7 @@ throw() { } bool Communicator::eventAcceptConnection(const ClientSocket& clientSocket) -throw(RuntimeException) { +noexcept(false) { LOGMETHOD(TraceMethod traceMethod(Logger::Local7, "comm::Communicator", "eventAcceptConnection", ANNA_FILE_LOCATION)); if(a_requestedStop == true) { @@ -758,7 +731,7 @@ throw(RuntimeException) { // (3) Solo si todos los servicios "Criticos" estan disponibles pasara a estar "Activo". //-------------------------------------------------------------------------------------------------------- void Communicator::eventCreateConnection(const Server* server) -throw() { +{ if(server == NULL) return; @@ -805,7 +778,7 @@ throw() { } void Communicator::eventCreateConnection(const Service* service) -throw() { +{ if(service == NULL) return; @@ -820,7 +793,7 @@ throw() { * Se invoca desde handler::RemoteConnection:[Tx] -> Communicator */ void Communicator::eventBreakConnection(const Server* server) -throw() { +{ if(server == NULL) return; @@ -850,7 +823,7 @@ throw() { } void Communicator::eventBreakConnection(const Service* service) -throw() { +{ if(service == NULL) return; @@ -863,7 +836,7 @@ throw() { } void Communicator::eventShutdown() -throw() { +{ LOGWARNING( string msg("comm::Communicator::eventShutdown | "); msg += asString(); @@ -888,7 +861,7 @@ throw() { } std::string Communicator::asString() const -throw() { +{ string result("comm::Communicator { "); result += Component::asString(); result += " | RequestedStop: "; @@ -901,7 +874,7 @@ throw() { } xml::Node* Communicator::asXML(xml::Node* parent) const -throw() { +{ parent = app::Component::asXML(parent); xml::Node* result = parent->createChild("comm.Communicator"); result->createAttribute("RequestedStop", anna::functions::asString(a_requestedStop)); @@ -944,7 +917,7 @@ throw() { * el proceso hijo y sigue atendiendo peticiones de conexion. */ void Communicator::do_cloneParent() -throw(RuntimeException) { +noexcept(false) { LOGMETHOD(TraceMethod traceMethod("comm::Communicator", "do_cloneParent", ANNA_FILE_LOCATION)); Handler* handler; Handler::Type::_v type; @@ -982,7 +955,7 @@ throw(RuntimeException) { * con ese handler => el programa terminara la ejecucion. */ void Communicator::do_cloneChild() -throw() { +{ LOGMETHOD(TraceMethod traceMethod("comm::Communicator", "do_cloneChild", ANNA_FILE_LOCATION)); LOGINFORMATION( string msg("comm::Communicator::do_cloneChild | MainHandler: "); @@ -1032,7 +1005,7 @@ throw() { } int Communicator::SortByFileDescriptor::value(const Handler* handler) -throw() { +{ return handler->getfd(); }