From: Mika Laitio Date: Thu, 16 Jun 2011 17:28:33 +0000 (+0300) Subject: cleanups X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=f6bd0d4fefd6459f2e8e5e7b813933be2d87dd47;p=libplpbus.git cleanups --- diff --git a/src/plpbus/BusClient.cc b/src/plpbus/BusClient.cc index 2ab2a2d..5c20d5d 100644 --- a/src/plpbus/BusClient.cc +++ b/src/plpbus/BusClient.cc @@ -99,7 +99,7 @@ int BusClient::init(const char *server_name) { if (CORBA::is_nil(server_obj) == false) { _server = plpbus_orb::OrbServer::_narrow(server_obj); if (CORBA::is_nil(_server) == false) { - log_info("CORBA service found: %s", server_name); + log_info("CORBA service found: %s\n", server_name); ret_val = PLP_OK; } } @@ -114,7 +114,7 @@ int BusClient::init(const char *server_name) { } int BusClient::add_client_listener(IClientListener *listener_param) { - log_debug("add_client_listener() started\n"); + log_debug("started\n"); if (_poa == NULL) { OrbClientImpl *client_cb; PortableServer::ObjectId_var oid; @@ -126,7 +126,7 @@ int BusClient::add_client_listener(IClientListener *listener_param) { client_cb->_remove_ref(); _server->add_event_listener(_client, "event_message", CONST_DEFAULT_EVENT_INTERVAL); } - log_debug("add_client_listener() done\n"); + log_debug("done\n"); return 0; } @@ -198,7 +198,7 @@ PortableServer::POA_var BusClient::create_poa(CORBA::ORB_var orb) { } } else { - cerr << "Failed to create RootPOA." << endl; + log_error("Failed to create RootPOA\n"); } return ret_val; } @@ -218,16 +218,16 @@ CosNaming::NamingContext_var BusClient::get_name_service_context(CORBA::ORB_var } catch (CORBA::ORB::InvalidName&) { // This should not happen! - cerr << "Could not find name service." << endl; + log_error("Could not find name service.\n"); } catch(CORBA::TRANSIENT& ex) { - cerr << "Could not find name service, verify that name service is running. " << endl; + log_error("Could not find name service, verify that name service is running.\n"); } catch (CORBA::NO_RESOURCES&) { - cerr << "Could not find name service, verify that name service is running. " << endl; + log_error("Could not find name service, verify that name service is running.\n"); } catch(CORBA::SystemException& ex) { - cerr << "Could not find name service, unknown reason. " << endl; + log_error("Could not find name service, unknown reason.\n"); } return ret_val; } diff --git a/src/plpbus/BusMessage.cc b/src/plpbus/BusMessage.cc index 0b1d901..99d32a0 100644 --- a/src/plpbus/BusMessage.cc +++ b/src/plpbus/BusMessage.cc @@ -43,7 +43,7 @@ BusMessage::~BusMessage() { long cnt; DataItemSequence *seq; - log_debug("BusMessage DESTRUCTOR\n"); + log_debug("\n"); seq = (DataItemSequence *)_dataItemSeq; if (seq != NULL) { cnt = seq->length(); diff --git a/src/plpbus/BusMessageInternal.cc b/src/plpbus/BusMessageInternal.cc index be06076..083fa5b 100644 --- a/src/plpbus/BusMessageInternal.cc +++ b/src/plpbus/BusMessageInternal.cc @@ -21,5 +21,5 @@ BusMessageInternal::BusMessageInternal(DataItemSequence seq_param) : BusMessage( } BusMessageInternal::~BusMessageInternal() { - log_debug("BusMessageInternal() DESTRUCTOR\n"); + log_debug("\n"); } diff --git a/src/plpbus/BusServer.cc b/src/plpbus/BusServer.cc index 993c995..e53023c 100644 --- a/src/plpbus/BusServer.cc +++ b/src/plpbus/BusServer.cc @@ -4,13 +4,11 @@ using namespace std; using namespace plpbus; -BusServer::BusServer() -{ +BusServer::BusServer() { orbServer = new OrbServerImpl(); } -BusServer::~BusServer() -{ +BusServer::~BusServer() { cout << "BusServer() destroyed." << endl; } @@ -24,8 +22,7 @@ int BusServer::init() { return retVal; } -int BusServer::launch(const char *server_name) -{ +int BusServer::launch(const char *server_name) { int retVal; OrbServerImpl *impl; @@ -34,8 +31,7 @@ int BusServer::launch(const char *server_name) return retVal; } -int BusServer::add_server_listener(IServerListener *listener_param) -{ +int BusServer::add_server_listener(IServerListener *listener_param) { int retVal; OrbServerImpl *impl; @@ -44,8 +40,7 @@ int BusServer::add_server_listener(IServerListener *listener_param) return retVal; } -void BusServer::shutdown() -{ +void BusServer::shutdown() { OrbServerImpl *impl; impl = (OrbServerImpl *)orbServer; diff --git a/src/plpbus/OrbServerImpl.cc b/src/plpbus/OrbServerImpl.cc index 57dcac4..0a037f2 100644 --- a/src/plpbus/OrbServerImpl.cc +++ b/src/plpbus/OrbServerImpl.cc @@ -30,7 +30,7 @@ OrbServerImpl::OrbServerImpl() OrbServerImpl::~OrbServerImpl() { - log_info("OrbServerImpl destroyed.\n"); + log_info("done\n"); } void OrbServerImpl::send_message_and_request_response(OrbClient_ptr response_listener_param, @@ -205,7 +205,7 @@ int OrbServerImpl::launch(const char *server_name) server_id = _poa->activate_object(&server_impl); server_ref = server_impl._this(); //this->_remove_ref(); - naming_cntx = get_service_naming_context(CONST_CONTEXT_NAME__PLPBUS, CONST_CONTEXT_KIND__PLPBUS); + naming_cntx = get_naming_service_context(CONST_CONTEXT_NAME__PLPBUS, CONST_CONTEXT_KIND__PLPBUS); if (naming_cntx != NULL) { ok_flg = bind_naming_context_and_service(naming_cntx, server_ref, @@ -233,7 +233,7 @@ PortableServer::POA_var OrbServerImpl::create_poa(CORBA::ORB_var orb) { PortableServer::POA_var rootpoa; ret_val = NULL; - log_debug("started"); + log_debug("started\n"); try { poa_obj = orb->resolve_initial_references(CONST_ROOT_POA_NAME); log_debug("received initial reference to %s\n", CONST_ROOT_POA_NAME); @@ -266,7 +266,7 @@ PortableServer::POA_var OrbServerImpl::create_poa(CORBA::ORB_var orb) { return ret_val; } -CosNaming::NamingContext_var OrbServerImpl::get_service_naming_context(const char *service_name_param, +CosNaming::NamingContext_var OrbServerImpl::get_naming_service_context(const char *service_name_param, const char *service_kind_param) { CosNaming::NamingContext_var ret_val; @@ -278,72 +278,65 @@ CosNaming::NamingContext_var OrbServerImpl::get_service_naming_context(const cha ret_val = NULL; try { // get nameservice reference - log_debug("1\n"); + log_debug("started\n"); ns_obj = _orb->resolve_initial_references(CONST_NAME_SERVICE_NAME); if (CORBA::is_nil(ns_obj) == false) { - log_debug("2\n"); - // get name service context + // get naming service context ns_cntx = CosNaming::NamingContext::_narrow(ns_obj); - log_debug("3\n"); if (CORBA::is_nil(ns_cntx) == false) { cntx_dta.length(1); cntx_dta[0].id = CORBA::string_dup(service_name_param); cntx_dta[0].kind = CORBA::string_dup(service_kind_param); - log_debug("4\n"); try { service_obj = ns_cntx->resolve(cntx_dta); } catch(CosNaming::NamingContext::NotFound& ex) { - log_error("Trying to create new name service context %s.\n", service_name_param); + log_error("Trying to create new naming service context %s.\n", service_name_param); } try { - log_debug("5\n"); if (CORBA::is_nil(service_obj)) { - // not found, try to bind the new context to name service - log_debug("6\n"); + // not found, try to bind new context from naming service ret_val = ns_cntx->bind_new_context(cntx_dta); - log_debug("7\n"); if (CORBA::is_nil(ret_val) ) { log_error("Failed to create new context to name service for %s.\n", service_name_param); } } else { - log_debug("8\n"); ret_val = CosNaming::NamingContext::_narrow(service_obj); if (CORBA::is_nil(ret_val) ) { - log_error("Failed to get name service context for %s, narrowing failed for resolved service context.\n", service_name_param); + log_error("Failed to get naming service context for %s, narrowing failed for resolved service context.\n", service_name_param); } - log_debug("9\n"); } } catch(CosNaming::NamingContext::AlreadyBound& ex) { - log_error("Failed to get name service context for %s. Context with same name already exist.\n", service_name_param); + log_error("Failed to get naming service context for %s. Context with same name already exist.\n", service_name_param); } } else { - log_error("Failed to get name service context for %s. Could not narrow the name service.\n", service_name_param); + log_error("Failed to get naming service context for %s. Could not narrow the name service.\n", service_name_param); } + //CORBA::release(ns_obj); } else { - log_error("Failed to get name service context for %s. Could not get reference to name service.\n", service_name_param); + log_error("Failed to get naming service context for %s. Could not get reference to name service.\n", service_name_param); } } catch (CORBA::ORB::InvalidName&) { // This should not happen! - log_error("Failed to get name service context for %s, name service does not exist.\n", service_name_param); + log_error("Failed to get naming service context for %s, name service does not exist.\n", service_name_param); } catch(CORBA::TRANSIENT& ex) { - log_error("Failed to get name service context for %s, verify that name service is running.\n", service_name_param); + log_error("Failed to get naming service context for %s, verify that name service is running.\n", service_name_param); } catch (CORBA::NO_RESOURCES&) { - log_error("Failed to get context from name service for %s, Name service is not running or has configuration problem.\n", service_name_param); + log_error("Failed to get context from name service for %s, Naming service is not running or has configuration problem.\n", service_name_param); log_error("Check-list:\n"); log_error("If you have OMNIORB_CONFIG environment variable defined, verify that omniORB.cfg file exist in that location.\n"); log_error("If you do not have OMNIORB_CONFIG environment variable defined, verify that you have /etc/omniORB.cfg file\n"); log_error("Verify that InitRef line is defined in omniORB.cfg file.\n"); } catch(CORBA::SystemException& ex) { - log_error("Failed to get name service context for %s, system error.\n", service_name_param); + log_error("Failed to get naming service context for %s, system error.\n", service_name_param); } log_debug("done\n"); return ret_val; diff --git a/src/plpbus/OrbServerImpl.hh b/src/plpbus/OrbServerImpl.hh index a73e7bf..ec270e8 100644 --- a/src/plpbus/OrbServerImpl.hh +++ b/src/plpbus/OrbServerImpl.hh @@ -43,8 +43,8 @@ namespace plpbus { /** * Gets naming context from the name service. If the naming context does not yet exist, create it. */ - CosNaming::NamingContext_var get_service_naming_context(const char *leafcontext_name, - const char *leafcontext_kind); + CosNaming::NamingContext_var get_naming_service_context(const char *service_name_param, + const char *service_kind_param); /** * Bind service to naming context. * If service with same name has already been binded, replace the existing service with the new one. diff --git a/src/plpbus/ServerEventThread.cc b/src/plpbus/ServerEventThread.cc index fadb9f5..9660597 100644 --- a/src/plpbus/ServerEventThread.cc +++ b/src/plpbus/ServerEventThread.cc @@ -16,10 +16,9 @@ using namespace std; using namespace plpbus; ServerEventThread::ServerEventThread(plpbus_orb::OrbClient_ptr client, - const char *msg, - int period, - OrbServerImpl *server_obj) -{ + const char *msg, + int period, + OrbServerImpl *server_obj) { this->_orb_client = plpbus_orb::OrbClient::_duplicate(client); this->_orb_msg = msg; this->_interval = period; @@ -27,8 +26,7 @@ ServerEventThread::ServerEventThread(plpbus_orb::OrbClient_ptr client, _orb_client->receive_event_message("event_listener_started"); } -void ServerEventThread::run(void* arg) -{ +void ServerEventThread::run(void* arg) { try { while(_server_obj->is_shutdown_pending() == 0) { omni_thread::sleep(_interval); @@ -39,5 +37,7 @@ void ServerEventThread::run(void* arg) log_error("server_thread failed, could not connect to client!\n"); } log_debug("server_thread, closing\n"); - _server_obj->server_thread_closed(); + if (_server_obj != NULL) { + _server_obj->server_thread_closed(); + } }