* Author: lamikr
*/
+#include <malloc.h>
#include <plp/log.h>
+#include <plp/retval.h>
#include "BusClient.hh"
#include "ClientServerCommon.hh"
}
virtual void receive_response_dataitem_sequence(const ::plpbus_orb::DataItemSequence& msg_rsp_param) {
- BusMessageInternal *bus_msg;
+ const BusMessageInternal *bus_msg;
if (listener != NULL) {
bus_msg = new BusMessageInternal(msg_rsp_param);
listener->response_received(bus_msg);
+ delete(bus_msg);
}
}
};
BusClient::~BusClient()
{
+ if (_poa != NULL) {
+ //_poa->destroy(true, true);
+ }
if (_orb != NULL) {
_orb->destroy();
_orb = NULL;
int argc;
char **argv;
CORBA::Object_var server_obj;
+ int ret_val;
argc = 0;
argv = NULL;
- log_info("init() started\n");;
+ ret_val = PLP_ERR;
+ log_info("CORBA client init() started\n");
_orb = CORBA::ORB_init(argc, argv);
- if (_orb != NULL) {
+ if (CORBA::is_nil(_orb) == false) {
log_debug("ORB_init() done, finding server: %s\n", server_name);
server_obj = find_server_object_by_name(_orb,
CONST_CONTEXT_NAME__PLPBUS,
CONST_CONTEXT_NAME__PLPBUS);
if (CORBA::is_nil(server_obj) == false) {
_server = plpbus_orb::OrbServer::_narrow(server_obj);
- log_info("Server object found: %s", server_name);
+ if (CORBA::is_nil(_server) == false) {
+ log_info("CORBA service found: %s", server_name);
+ ret_val = PLP_OK;
+ }
}
else {
- log_error("Could not find server object: %s\n", server_name);
+ log_error("Could not find CORBA service: %s\n", server_name);
}
}
- return 0;
+ else {
+ log_error("Could not init CORBA client\n");
+ }
+ return ret_val;
}
int BusClient::add_client_listener(IClientListener *listener_param) {
int BusClient::send_message_and_wait_response(const char *msg_req_param, char **msg_rsp_param) {
CORBA::Long ret_val;
+ char *rsp;
- *msg_rsp_param = _server->send_message_and_wait_response(msg_req_param, ret_val);
+ rsp = _server->send_message_and_wait_response(msg_req_param, ret_val);
+ *msg_rsp_param = strdup(rsp);
+ CORBA::string_free(rsp);
return ret_val;
}
return ret_val;
}
-CosNaming::NamingContext_var BusClient::get_name_service_context(CORBA::ORB_var orb_param) {
+CosNaming::NamingContext_var BusClient::get_name_service_context(CORBA::ORB_var orb_param,
+ const char *nameservice_name_param) {
CORBA::Object_var ns_obj;
CosNaming::NamingContext_var ret_val;
ret_val = NULL;
try {
- ns_obj = orb_param->resolve_initial_references(CONST_NAME_SERVICE_NAME);
+ ns_obj = orb_param->resolve_initial_references(nameservice_name_param);
if (CORBA::is_nil(ns_obj) == false) {
// narrow the object reference
ret_val = CosNaming::NamingContext::_narrow(ns_obj);
CORBA::Object_var ret_val;
CosNaming::NamingContext_var ns_root_context;
CosNaming::Name service_data;
+ char *n;
- ret_val = CORBA::Object::_nil();
- ns_root_context = get_name_service_context(orb_param);
+ ret_val = CORBA::Object::_nil();
+ n = strdup(CONST_NAME_SERVICE_NAME);
+ ns_root_context = get_name_service_context(orb_param, n);
+ free(n);
if (CORBA::is_nil(ns_root_context) == false) {
// define search criteria
service_data.length(2);
if (_listener != NULL) {
log_debug("send_message_and_wait_response(): %s, server_callback != NULL\n", msg_req_param);
_listener->request_received(msg_req_param, &msg_rsp);
+ //ret_val = CORBA::string_dup(msg_rsp);
+ ret_val = CORBA::string_dup(msg_rsp);
}
else {
log_error("send_message_and_wait_response() error, server callback == NULL\n");
- msg_rsp = strdup(msg_req_param);
+ ret_val = CORBA::string_dup(msg_req_param);
err_flg = -1;
}
- ret_val = CORBA::string_dup(msg_rsp);
return ret_val;
}
}
}
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) ) {
log_error("Failed to get existing context from name service for %s, narrowing failed.\n", service_name_param);
}