]> pilppa.org Git - libplpbus.git/blobdiff - src/plpbus/OrbServerImpl.cc
Crash fix for unhandled msg request case in server.
[libplpbus.git] / src / plpbus / OrbServerImpl.cc
index d12846e206c7f4b27637915c20a1b04696b5b9b2..3fa74a005dd95e1e05e5607617d68c8dcd4ddd2a 100644 (file)
@@ -5,6 +5,8 @@
  *      Author: lamikr
  */
 
+#include <plp/log.h>
+
 #include "ServerEventThread.hh"
 #include "OrbServerImpl.hh"
 #include "ClientServerCommon.hh"
@@ -28,7 +30,7 @@ OrbServerImpl::OrbServerImpl()
 
 OrbServerImpl::~OrbServerImpl()
 {
-       cout << "OrbServerImpl destroyed." << endl;
+       log_info("OrbServerImpl destroyed.\n");
 }
 
 void OrbServerImpl::send_message_and_request_response(OrbClient_ptr response_listener_param,
@@ -39,16 +41,17 @@ void OrbServerImpl::send_message_and_request_response(OrbClient_ptr response_lis
        msg_rsp = NULL;
        if (CORBA::is_nil(response_listener_param) == false) {
                if (_listener != NULL) {
-                       cout << "send_message_and_request_response(): " << msg_req << ", server_callback != NULL" << endl;
+                       log_debug("send_message_and_request_response(): %s, server callback != NULL\n", msg_req);
                        _listener->request_received(msg_req, &msg_rsp);
+                       log_debug("send_message_and_request_response(), request_received\n");
                        response_listener_param->receive_response_message(msg_rsp);
                }
                else {
-                       cout << "send_message_and_request_response() error! " << msg_req << ", server_callback == NULL" << endl;
+                       log_error("send_message_and_request_response() error, server callback == NULL\n");
                }
        }
        else {
-               cerr << "invalid callback object received.\n";
+               log_error("invalid callback object received.\n");
        }
 }
 
@@ -59,11 +62,11 @@ char *OrbServerImpl::send_message_and_wait_response(const char* msg_req_param, :
        err_flg = 0;
        msg_rsp = NULL;
        if (_listener != NULL) {
-               cout << "send_message_and_wait_response(): " << msg_req_param << ", server_callback != NULL" << endl;
+               log_debug("send_message_and_wait_response(): %s, server_callback != NULL\n", msg_req_param);
                _listener->request_received(msg_req_param, &msg_rsp);
        }
        else {
-               cout << "send_message_and_wait_response() error! " << msg_req_param << ", server_callback == NULL" << endl;
+               log_error("send_message_and_wait_response() error, server callback == NULL\n");
                msg_rsp = strdup(msg_req_param);
                err_flg = -1;
        }
@@ -73,37 +76,46 @@ char *OrbServerImpl::send_message_and_wait_response(const char* msg_req_param, :
 
 void OrbServerImpl::send_dataitem_message_and_request_response(OrbClient_ptr response_listener_param,
                                                        const ::DataItemSequence& msg_req_param) {
-       BusMessage      *msg_req;
-       BusMessage      *msg_rsp;
+       BusMessage              *msg_req;
+       BusMessage              *msg_rsp;
+       DataItemSequence        *seq;
 
        if (CORBA::is_nil(response_listener_param) == false) {
                if (_listener != NULL) {
                        msg_req = new BusMessageInternal(msg_req_param);
-                       cout << "send_dataitem_message_and_request_response(), server_callback != NULL" << endl;
-                       cout << "msg_req:" << endl;
+                       log_debug("send_dataitem_message_and_request_response(), server_callback != NULL\n");
+                       log_debug("msg_req:\n");
                        msg_req->printout();
                        msg_rsp = NULL;
                        _listener->request_received(msg_req, &msg_rsp);
-                       cout << "msg_rsp length:" << msg_rsp->_dataItemSeq.length() << endl;
+                       seq     = (DataItemSequence *)msg_rsp->_dataItemSeq;
+                       log_debug("msg_rsp length: %ld\n", seq->length());
                        msg_rsp->printout();
-                       response_listener_param->receive_response_dataitem_sequence(msg_rsp->_dataItemSeq);
+                       response_listener_param->receive_response_dataitem_sequence(*seq);
                }
                else {
-                       cout << "send_dataitem_message_and_request_response() error, server_callback == NULL" << endl;
+                       log_error("send_dataitem_message_and_request_response() error, server_callback == NULL\n");
                }
        }
 }
 
 CORBA::Long OrbServerImpl::send_dataitem_message_and_wait_response(const DataItemSequence& req_seq_param,
-               DataItemSequence_out rsp_seq_param) {
-       BusMessage      *msg_req;
-       BusMessage      *msg_rsp;
+                                                               DataItemSequence_out rsp_seq_param) {
+       BusMessage              *msg_req;
+       BusMessage              *msg_rsp;
+       DataItemSequence        *seq;
 
-       msg_req = new BusMessageInternal(req_seq_param);
+       seq     = NULL;
        msg_rsp = NULL;
+       msg_req = new BusMessageInternal(req_seq_param);
        _listener->request_received(msg_req, &msg_rsp);
-       //rsp_seq_param = new DataItemSequence_out(msg_rsp._dataItemSeq);
-       rsp_seq_param._data     = &(msg_rsp->_dataItemSeq);
+       if (msg_rsp != NULL) {
+               seq     = (DataItemSequence *)msg_rsp->_dataItemSeq;
+       }
+       else {
+               seq     = new DataItemSequence();
+       }
+       rsp_seq_param._data     = seq;
 
        return 0;
 }
@@ -115,7 +127,7 @@ void OrbServerImpl::add_event_listener(OrbClient_ptr client_param,
        ServerEventThread       *srvr_thread;
 
        if (CORBA::is_nil(client_param) == false) {
-               cout << "add_event_listener()" << endl;
+               log_debug("add_event_listener()\n");
                server_thread_mutex.lock();
                _server_thread_count++;
                server_thread_mutex.unlock();
@@ -177,7 +189,10 @@ int OrbServerImpl::launch(const char *server_name)
        //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, server_ref, server_name, CONST_CONTEXT_KIND__PLPBUS);
+               ok_flg  = bind_naming_context_and_service(naming_context,
+                                                       server_ref,
+                                                       server_name,
+                                                       CONST_CONTEXT_KIND__PLPBUS);
                if (ok_flg == true) {
                        cout << "Registered to naming service: " << server_name << endl;
                        _orb->run();
@@ -234,47 +249,66 @@ CosNaming::NamingContext_var OrbServerImpl::get_service_naming_context(const cha
        ret_val = NULL;
        try {
                // get nameservice reference
+               log_debug("get_service_naming_context() 1\n");
                ns_obj          = _orb->resolve_initial_references(CONST_NAME_SERVICE_NAME);
-               // get nameservice context
+               log_debug("get_service_naming_context() 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;
+                       context_data[0].id      = service_name_param;
+                       context_data[0].kind    = service_kind_param;
+                       log_debug("get_service_naming_context() 4\n");
                        try {
                                service_obj     = ns_context->resolve(context_data);
+                       }
+                       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);
+                       }
+                       try {
+                               log_debug("get_service_naming_context() 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");
                                        if (CORBA::is_nil(ret_val) ) {
-                                               cerr << "Failed to create new context to name service for " << service_name_param << "." << endl;
+                                               log_error("Failed to create new context to name service for %s.\n", service_name_param);
                                        }
                                }
                                else {
+                                       log_debug("get_service_naming_context() 8\n");
                                        ret_val = CosNaming::NamingContext::_narrow(service_obj);
+                                       log_debug("get_service_naming_context() 9\n");
                                        if (CORBA::is_nil(ret_val) ) {
-                                               cerr << "Failed to get existing context from name service for " << service_name_param << ", narrowing failed." << endl;
+                                               log_error("Failed to get existing context from name service for %s, narrowing failed.\n", service_name_param);
                                        }
                                }
                        }
                        catch(CosNaming::NamingContext::AlreadyBound& ex) {
-                               cerr << "Could not get context from nameservice for " << service_name_param << ". Context with same name already existed."<< endl;
+                               log_error("Failed to get context from name service for %s. Context with same name already exist.\n", service_name_param);
                        }
                }
        }
        catch (CORBA::ORB::InvalidName&) {
                // This should not happen!
-               cerr << "Could not get context from name service for " << service_name_param << ", name service does not exist." << endl;
+               log_error("Failed to get context from name service for %s, name service does not exist.\n", service_name_param);
        }
        catch(CORBA::TRANSIENT& ex) {
-               cerr << "Could not get context from name service for " << service_name_param << ",  verify that name service is running. " << service_name_param << endl;
+               log_error("Failed to get context from name service for %s, verify that name service is running.\n", service_name_param);
        }
        catch (CORBA::NO_RESOURCES&) {
-               cerr << "Could not get context from name service for " << service_name_param << ". Name service is not running or has configuration problem." << endl;
+               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("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) {
-               cerr << "Could not get context from name service for " << service_name_param << ", could not determine reason." << endl;
+               log_error("Failed to get context from name service for %s, system error.\n", service_name_param);
        }
+       log_debug("get_service_naming_context() done\n");
        return ret_val;
 }