X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Fcomm%2FCommunicator.cpp;h=eb115a19fba9239899721df4910a7007d8c885c7;hb=5a6cba5fde2b2f538a7515f8293cc0a8d9589dfa;hp=c89b6aaecc71f8a54b71767bd5bba31e05e8d767;hpb=4e12ac57e93c052f716a6305ad8fc099c45899d1;p=anna.git diff --git a/source/comm/Communicator.cpp b/source/comm/Communicator.cpp index c89b6aa..eb115a1 100644 --- a/source/comm/Communicator.cpp +++ b/source/comm/Communicator.cpp @@ -1,37 +1,9 @@ -// ANNA - Anna is Not 'N' Anymore -// -// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo -// -// https://bitbucket.org/testillano/anna -// -// 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 Google Inc. 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 @@ -50,6 +22,7 @@ #include #include #include +#include #include #include @@ -116,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()); @@ -127,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()); @@ -139,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); @@ -151,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); @@ -165,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); @@ -183,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); @@ -203,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); @@ -257,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); @@ -272,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); @@ -287,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); @@ -302,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); @@ -319,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); @@ -339,7 +312,7 @@ throw(RuntimeException) { } void Communicator::insert(Handler* handler) -throw(RuntimeException) { +noexcept(false) { handler->initialize(); if(handler->getfd() < 0) { @@ -372,7 +345,7 @@ throw(RuntimeException) { } void Communicator::detach(ServerSocket* serverSocket) -throw() { +{ if(serverSocket == NULL) return; @@ -384,7 +357,7 @@ throw() { } void Communicator::detach(ClientSocket* clientSocket) -throw() { +{ if(clientSocket == NULL) return; @@ -392,7 +365,7 @@ throw() { } void Communicator::detach(BinderSocket* binderSocket) -throw() { +{ if(binderSocket == NULL) return; @@ -404,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; @@ -439,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()); @@ -450,6 +423,7 @@ throw(RuntimeException) { case Handler::Type::Custom: result = NULL; break; + default: break; } } @@ -464,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) @@ -491,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; @@ -566,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"); @@ -601,7 +575,7 @@ throw(RuntimeException) { } void Communicator::requestStop() -throw() { +{ if(a_requestedStop == true) return; @@ -627,7 +601,7 @@ throw() { } bool Communicator::isUsable(const ClientSocket* clientSocket) -throw() { +{ if(clientSocket == NULL) return false; @@ -642,7 +616,7 @@ throw() { } void Communicator::setStatus(const Status& status) -throw() { +{ Guard guard(this, "comm::Communicator::setStatus"); if(a_status != status) @@ -656,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) @@ -700,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) @@ -720,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) { @@ -757,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; @@ -804,7 +778,7 @@ throw() { } void Communicator::eventCreateConnection(const Service* service) -throw() { +{ if(service == NULL) return; @@ -819,7 +793,7 @@ throw() { * Se invoca desde handler::RemoteConnection:[Tx] -> Communicator */ void Communicator::eventBreakConnection(const Server* server) -throw() { +{ if(server == NULL) return; @@ -849,7 +823,7 @@ throw() { } void Communicator::eventBreakConnection(const Service* service) -throw() { +{ if(service == NULL) return; @@ -862,7 +836,7 @@ throw() { } void Communicator::eventShutdown() -throw() { +{ LOGWARNING( string msg("comm::Communicator::eventShutdown | "); msg += asString(); @@ -887,7 +861,7 @@ throw() { } std::string Communicator::asString() const -throw() { +{ string result("comm::Communicator { "); result += Component::asString(); result += " | RequestedStop: "; @@ -900,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)); @@ -943,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; @@ -981,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: "); @@ -1031,7 +1005,7 @@ throw() { } int Communicator::SortByFileDescriptor::value(const Handler* handler) -throw() { +{ return handler->getfd(); }