From 073716a0136d654f826cee98cf0e78e355d4d826 Mon Sep 17 00:00:00 2001 From: Mika Laitio Date: Tue, 24 May 2011 01:48:46 +0300 Subject: [PATCH] more debug for error handling Signed-off-by: Mika Laitio --- src/plpbus/OrbServerImpl.cc | 134 +++++++++++++++++++----------------- src_test/test_server.cc | 2 +- 2 files changed, 71 insertions(+), 65 deletions(-) diff --git a/src/plpbus/OrbServerImpl.cc b/src/plpbus/OrbServerImpl.cc index 931c6cf..57dcac4 100644 --- a/src/plpbus/OrbServerImpl.cc +++ b/src/plpbus/OrbServerImpl.cc @@ -174,6 +174,7 @@ int OrbServerImpl::init() { argc = -1; argv = NULL; retVal = 0; + log_debug("started\n"); _orb = CORBA::ORB_init(argc, argv); if (_orb != NULL) { _poa = create_poa(_orb); @@ -197,22 +198,23 @@ int OrbServerImpl::launch(const char *server_name) PortableServer::ObjectId_var server_id; bool ok_flg; int ret_val; - CosNaming::NamingContext_var naming_context; + CosNaming::NamingContext_var naming_cntx; ret_val = -1; POA_plpbus_orb::OrbServer_tie server_impl(this); server_id = _poa->activate_object(&server_impl); server_ref = server_impl._this(); //this->_remove_ref(); - naming_context = get_service_naming_context(CONST_CONTEXT_NAME__PLPBUS, CONST_CONTEXT_KIND__PLPBUS); - if (naming_context != NULL) { - ok_flg = bind_naming_context_and_service(naming_context, + naming_cntx = get_service_naming_context(CONST_CONTEXT_NAME__PLPBUS, CONST_CONTEXT_KIND__PLPBUS); + if (naming_cntx != NULL) { + ok_flg = bind_naming_context_and_service(naming_cntx, server_ref, server_name, CONST_CONTEXT_KIND__PLPBUS); if (ok_flg == true) { log_debug("Registered to naming service: %s\n", server_name); _orb->run(); + log_debug("run stopped: %s\n", server_name); ret_val = 0; } else { @@ -232,38 +234,34 @@ PortableServer::POA_var OrbServerImpl::create_poa(CORBA::ORB_var orb) { ret_val = NULL; log_debug("started"); - poa_obj = orb->resolve_initial_references(CONST_ROOT_POA_NAME); - if (poa_obj != NULL) { + try { + poa_obj = orb->resolve_initial_references(CONST_ROOT_POA_NAME); log_debug("received initial reference to %s\n", CONST_ROOT_POA_NAME); rootpoa = PortableServer::POA::_narrow(poa_obj); - if (rootpoa != NULL) { - poa_man = rootpoa->the_POAManager(); - if (poa_man != NULL) { - poa_man->activate(); - // bidirectional policy - policy_list.length(1); - policyVal <<= BiDirPolicy::BOTH; - policy_list[0] = orb->create_policy(BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, policyVal); - ret_val = rootpoa->create_POA(CONST_ROOT_POA_BIDIR_POLICY_NAME, - poa_man, - policy_list); - if (CORBA::is_nil(ret_val) == false) { - log_info("Created root poa %s\n", CONST_ROOT_POA_NAME); - } - else { - log_error("Failed to create RootPOA %s\n", CONST_ROOT_POA_NAME); - } - } - else { - log_error("Failed to create RootPOA, could not create POAManager for the root poa %s\n", CONST_ROOT_POA_NAME); - } + poa_man = rootpoa->the_POAManager(); + poa_man->activate(); + // bidirectional policy + policy_list.length(1); + policyVal <<= BiDirPolicy::BOTH; + policy_list[0] = orb->create_policy(BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, policyVal); + ret_val = rootpoa->create_POA(CONST_ROOT_POA_BIDIR_POLICY_NAME, + poa_man, + policy_list); + if (CORBA::is_nil(ret_val) == false) { + log_info("Created root poa %s\n", CONST_ROOT_POA_NAME); } else { - log_error("Failed to create RootPOA, could not narrow root poa: %s\n", CONST_ROOT_POA_NAME); + log_error("Failed to create RootPOA %s\n", CONST_ROOT_POA_NAME); } } - else { - log_error("Failed to create RootPOA, could not resolve initial reference to %s.\n", CONST_ROOT_POA_NAME); + catch(CORBA::SystemException& ex) { + log_error("Failed to create RootPOA, received system exception CORBA::%s\n", ex._name()); + } + catch(CORBA::Exception& ex) { + log_error("Failed to create RootPOA, received exception CORBA::%s\n", ex._name()); + } + catch(omniORB::fatalException& ex) { + log_error("Failed to create RootPOA, received fatal exception CORBA::%s\n", ex.errmsg()); } return ret_val; } @@ -272,62 +270,70 @@ CosNaming::NamingContext_var OrbServerImpl::get_service_naming_context(const cha const char *service_kind_param) { CosNaming::NamingContext_var ret_val; - CosNaming::NamingContext_var ns_context; + CosNaming::NamingContext_var ns_cntx; CORBA::Object_var ns_obj; CORBA::Object_var service_obj; - CosNaming::Name context_data; + CosNaming::Name cntx_dta; ret_val = NULL; try { // get nameservice reference - log_debug("get_service_naming_context() 1\n"); + log_debug("1\n"); ns_obj = _orb->resolve_initial_references(CONST_NAME_SERVICE_NAME); if (CORBA::is_nil(ns_obj) == false) { - log_debug("get_service_naming_context() 2\n"); + log_debug("2\n"); // get name service context - ns_context = CosNaming::NamingContext::_narrow(ns_obj); - log_debug("get_service_naming_context() 3\n"); - if (CORBA::is_nil(ns_context) == false) { - context_data.length(1); - context_data[0].id = service_name_param; - context_data[0].kind = service_kind_param; - log_debug("get_service_naming_context() 4\n"); + 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_context->resolve(context_data); + service_obj = ns_cntx->resolve(cntx_dta); } catch(CosNaming::NamingContext::NotFound& ex) { - log_error("Failed to get context from name service for %s. Context does not yet exist, but will try to create.\n", service_name_param); + log_error("Trying to create new name service context %s.\n", service_name_param); } try { - log_debug("get_service_naming_context() 5\n"); + log_debug("5\n"); if (CORBA::is_nil(service_obj)) { // not found, try to bind the new context to name service - log_debug("get_service_naming_context() 6\n"); - ret_val = ns_context->bind_new_context(context_data); - log_debug("get_service_naming_context() 7\n"); + log_debug("6\n"); + 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 existing context from name service for %s, narrowing failed.\n", service_name_param); + log_error("Failed to get name 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 context from name service for %s. Context with same name already exist.\n", service_name_param); + log_error("Failed to get name 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); + } + } + else { + log_error("Failed to get name 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 context from name service for %s, name service does not exist.\n", service_name_param); + log_error("Failed to get name service context for %s, name service does not exist.\n", service_name_param); } catch(CORBA::TRANSIENT& ex) { - log_error("Failed to get context from name service for %s, verify that name service is running.\n", service_name_param); + log_error("Failed to get name 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); @@ -337,27 +343,27 @@ CosNaming::NamingContext_var OrbServerImpl::get_service_naming_context(const cha log_error("Verify that InitRef line is defined in omniORB.cfg file.\n"); } catch(CORBA::SystemException& ex) { - log_error("Failed to get context from name service for %s, system error.\n", service_name_param); + log_error("Failed to get name service context for %s, system error.\n", service_name_param); } - log_debug("get_service_naming_context() done\n"); + log_debug("done\n"); return ret_val; } -bool OrbServerImpl::bind_naming_context_and_service(CosNaming::NamingContext_var service_context_param, - CORBA::Object_ptr service_ref_param, - const char *service_name_param, - const char *service_kind_param) +bool OrbServerImpl::bind_naming_context_and_service(CosNaming::NamingContext_var srv_cntx_param, + CORBA::Object_ptr srv_ref_param, + const char *srv_name_param, + const char *srv_kind_param) { bool retVal; - CosNaming::Name context_data; + CosNaming::Name cntx_dta; retVal = false; try { - context_data.length(1); - context_data[0].id = service_name_param; - context_data[0].kind = service_kind_param; + cntx_dta.length(1); + cntx_dta[0].id = CORBA::string_dup(srv_name_param); + cntx_dta[0].kind = CORBA::string_dup(srv_kind_param); try { - service_context_param->bind(context_data, service_ref_param); + srv_cntx_param->bind(cntx_dta, srv_ref_param); retVal = true; } catch(CosNaming::NamingContext::AlreadyBound& ex) { @@ -365,8 +371,8 @@ bool OrbServerImpl::bind_naming_context_and_service(CosNaming::NamingContext_var * service existed already for the naming context with similar description. * Replace the existing one with a new one. */ - log_warning("service %s exist, replacing it\n", service_name_param); - service_context_param->rebind(context_data, service_ref_param); + log_warning("service %s exist, replacing it\n", srv_name_param); + srv_cntx_param->rebind(cntx_dta, srv_ref_param); retVal = true; } } diff --git a/src_test/test_server.cc b/src_test/test_server.cc index ae00f4f..abed30a 100644 --- a/src_test/test_server.cc +++ b/src_test/test_server.cc @@ -42,7 +42,7 @@ int main(int argc, char** argv) { if (argc >= 2) { log_info("starting server\n"); - server = new BusServer(); + server = new BusServer(); if (server != NULL) { server->init(); listener = new ServerListenerImpl(); -- 2.41.0