From 4245d1b8a55a8f461634e94d9bac9e0043a9612b Mon Sep 17 00:00:00 2001 From: Mika Laitio Date: Wed, 2 Mar 2011 01:35:09 +0200 Subject: [PATCH] cleaned up public headers available for bus client and server implementators. Signed-off-by: Mika Laitio --- src/Makefile.am | 4 +- src/plpbus/BusClient.cc | 17 +++- src/plpbus/BusClient.hh | 1 - src/plpbus/BusMessage.cc | 151 +++++++++++++++++-------------- src/plpbus/BusMessage.hh | 6 +- src/plpbus/BusMessageInternal.cc | 10 +- src/plpbus/BusMessageInternal.hh | 1 + src/plpbus/BusServer.hh | 1 - src/plpbus/OrbServerImpl.cc | 26 ++++-- src/plpbus/OrbServerImpl.hh | 1 - src/plpbus/ServerEventThread.cc | 9 +- src_test/test_server.cc | 13 ++- 12 files changed, 136 insertions(+), 104 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 515e06a..4ca4618 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,5 +19,7 @@ libplpbusinclude_HEADERS = \ plpbus/BusServer.hh \ plpbus/BusClient.hh \ plpbus/BusMessage.hh \ - plpbus/IServerListener.hh + plpbus/IClientListener.hh \ + plpbus/IServerListener.hh \ + idl/RequestResponseBus.hh diff --git a/src/plpbus/BusClient.cc b/src/plpbus/BusClient.cc index 2a84727..42c47f7 100644 --- a/src/plpbus/BusClient.cc +++ b/src/plpbus/BusClient.cc @@ -8,13 +8,15 @@ #include #include "BusClient.hh" +#include "ClientServerCommon.hh" #include "BusMessageInternal.hh" +#include "RequestResponseBus.hh" using namespace std; using namespace plpbus; +using namespace plpbus_orb; -class OrbClientImpl : public virtual POA_plpbus_orb::OrbClient -{ +class OrbClientImpl : public virtual POA_plpbus_orb::OrbClient { private: IClientListener *listener; public: @@ -127,15 +129,20 @@ int BusClient::send_message_and_wait_response(const char *msg_req_param, char ** } int BusClient::send_message_and_request_response(BusMessage *msg_req_param) { - _server->send_dataitem_message_and_request_response(_client, msg_req_param->_dataItemSeq); + DataItemSequence *seq; + + seq = (DataItemSequence *)msg_req_param->_dataItemSeq; + _server->send_dataitem_message_and_request_response(_client, *seq); return 0; } int BusClient::send_message_and_wait_response(BusMessage *msg_req_param, BusMessage **msg_rsp_param) { - plpbus_orb::DataItemSequence *seq_rsp; + DataItemSequence *seq_rsp; + DataItemSequence *seq; seq_rsp = NULL; - _server->send_dataitem_message_and_wait_response(msg_req_param->_dataItemSeq, seq_rsp); + seq = (DataItemSequence *)msg_req_param->_dataItemSeq; + _server->send_dataitem_message_and_wait_response(*seq, seq_rsp); return 0; } diff --git a/src/plpbus/BusClient.hh b/src/plpbus/BusClient.hh index a1fe5dc..c71778b 100644 --- a/src/plpbus/BusClient.hh +++ b/src/plpbus/BusClient.hh @@ -13,7 +13,6 @@ #include "RequestResponseBus.hh" #include "IClientListener.hh" -#include "ClientServerCommon.hh" #include "BusMessage.hh" namespace plpbus { diff --git a/src/plpbus/BusMessage.cc b/src/plpbus/BusMessage.cc index 84cd386..1743d4c 100644 --- a/src/plpbus/BusMessage.cc +++ b/src/plpbus/BusMessage.cc @@ -8,60 +8,61 @@ #include #include "BusMessage.hh" +#include "RequestResponseBus.hh" using namespace std; using namespace plpbus_orb; using namespace plpbus; using namespace CORBA; -BusMessage::BusMessage() -{ - _dataItemSeq.length(0); - +BusMessage::BusMessage() { + _dataItemSeq = new DataItemSequence(); + log_debug("new BusMessage()\n"); } -BusMessage::BusMessage(const char *name_param, const char *value_param) -{ - DataItem *item; +BusMessage::BusMessage(const char *name_param, const char *value_param) { + DataItem *item; + DataItemSequence *seq; if (name_param != NULL) { item = new DataItem(); item->name = strdup(name_param); item->value <<= strdup(value_param); - _dataItemSeq.length(1); - _dataItemSeq[0] = *item; + seq = new DataItemSequence(0); + seq->length(1); + (*seq)[0] = *item; + _dataItemSeq = seq; } else { - _dataItemSeq.length(0); + _dataItemSeq = new DataItemSequence(0); } - } -BusMessage::~BusMessage() -{ - // TODO Auto-generated destructor stub +BusMessage::~BusMessage() { } int BusMessage::add_string_parameter(const char *name_param, const char *value_param) { - long length; - int ret_val; - DataItem *item; + long length; + int ret_val; + DataItem *item; + DataItemSequence *seq; ret_val = 0; + seq = (DataItemSequence *)_dataItemSeq; if (name_param != NULL) { - length = _dataItemSeq.length(); + length = seq->length(); item = new DataItem(); - item->name = strdup(name_param); + item->name = strdup(name_param); if (value_param != NULL) { item->value <<= strdup(value_param); - _dataItemSeq.length(length + 1); - _dataItemSeq[length] = *item; + seq->length(length + 1); + (*seq)[length] = *item; } } else { - _dataItemSeq.length(0); + seq->length(0); ret_val = -1; } return ret_val; @@ -69,22 +70,24 @@ int BusMessage::add_string_parameter(const char *name_param, const char *value_p int BusMessage::add_long_parameter(const char *name_param, long value_param) { - long length; - int ret_val; - DataItem *item; + long length; + int ret_val; + DataItem *item; + DataItemSequence *seq; ret_val = 0; + seq = (DataItemSequence *)_dataItemSeq; if (name_param != NULL) { - length = _dataItemSeq.length(); + length = seq->length(); item = new DataItem(); item->name = strdup(name_param); item->value <<= value_param; - _dataItemSeq.length(length + 1); - _dataItemSeq[length] = *item; + seq->length(length + 1); + (*seq)[length] = *item; } else { - _dataItemSeq.length(0); + seq->length(0); ret_val = -1; } return ret_val; @@ -92,22 +95,24 @@ int BusMessage::add_long_parameter(const char *name_param, long value_param) int BusMessage::add_int_parameter(const char *name_param, int value_param) { - long length; - int ret_val; - DataItem *item; + long length; + int ret_val; + DataItem *item; + DataItemSequence *seq; ret_val = 0; + seq = (DataItemSequence *)_dataItemSeq; if (name_param != NULL) { - length = _dataItemSeq.length(); + length = seq->length(); item = new DataItem(); item->name = strdup(name_param); item->value <<= (long)value_param; - _dataItemSeq.length(length + 1); - _dataItemSeq[length] = *item; + seq->length(length + 1); + (*seq)[length] = *item; } else { - _dataItemSeq.length(0); + seq->length(0); ret_val = -1; } return ret_val; @@ -115,110 +120,120 @@ int BusMessage::add_int_parameter(const char *name_param, int value_param) int BusMessage::add_double_parameter(const char *name_param, double value_param) { - long length; - int ret_val; - DataItem *item; + long length; + int ret_val; + DataItem *item; + DataItemSequence *seq; ret_val = 0; + log_debug("add_double_parameter() started\n"); + seq = (DataItemSequence *)_dataItemSeq; if (name_param != NULL) { - length = _dataItemSeq.length(); + length = seq->length(); item = new DataItem(); item->name = strdup(name_param); item->value <<= (long)value_param; - _dataItemSeq.length(length + 1); - _dataItemSeq[length] = *item; + seq->length(length + 1); + (*seq)[length] = *item; } else { - _dataItemSeq.length(0); + seq->length(0); ret_val = -1; } + log_debug("add_double_parameter() done\n"); return ret_val; } int BusMessage::add_float_parameter(const char *name_param, float value_param) { - long length; - int ret_val; - DataItem *item; + long length; + int ret_val; + DataItem *item; + DataItemSequence *seq; ret_val = 0; + seq = (DataItemSequence *)_dataItemSeq; if (name_param != NULL) { - length = _dataItemSeq.length(); + length = seq->length(); item = new DataItem(); item->name = strdup(name_param); item->value <<= (long)value_param; - _dataItemSeq.length(length + 1); - _dataItemSeq[length] = *item; + seq->length(length + 1); + (*seq)[length] = *item; } else { - _dataItemSeq.length(0); + seq->length(0); ret_val = -1; } return ret_val; } -void BusMessage::printout_dataitem(long index, plpbus_orb::DataItem *item) { +void BusMessage::printout_dataitem(long index, void *item) { CORBA::TCKind kind; + DataItem *dataitem; + dataitem = (DataItem *)item; if (item != NULL) { - if (item->name != NULL) { - kind = item->value.type()->kind(); + if (dataitem->name != NULL) { + kind = dataitem->value.type()->kind(); switch(kind) { case tk_string: { const char *val; - item->value >>= val; - log_debug(" [%ld], value: %s\n", index, val); + dataitem->value >>= val; + log_debug("\t[%ld], value: %s\n", index, val); } break; case tk_long: { long val; - item->value >>= val; - log_debug(" [%ld], value: %ld\n", index, val); + dataitem->value >>= val; + log_debug("\t[%ld], value: %ld\n", index, val); //val_str = strdup("long"); } break; case tk_double: { double val; - item->value >>= val; - log_debug(" [%ld], value: %f\n", index, val); + dataitem->value >>= val; + log_debug("\t[%ld], value: %f\n", index, val); //val_str = strdup("double"); } break; case tk_float: { float val; - item->value >>= val; - log_debug(" [l%ld] value: %f\n", index, val); + dataitem->value >>= val; + log_debug("\t[l%ld] value: %f\n", index, val); //val_str = strdup("float"); } break; default: - log_error(" [%ld], value unknown\n", index); + log_error("\t[%ld], value unknown\n", index); } } else { - log_error(" [%ld] Invalid data item name name or value\n", index); + log_error("\t[%ld] Invalid data item name name or value\n", index); } } else { - log_error(" [%ld] dataItem NULL.", index); + log_error("\t[%ld] dataItem NULL.", index); } } void BusMessage::printout() { - long int count; - DataItem item; + long int count; + DataItem item; + DataItemSequence *seq; - count = _dataItemSeq.length(); + seq = (DataItemSequence *)_dataItemSeq; + count = seq->length(); log_debug("BusMessage.printout(): parameter count: %ld\n", count); for (long ii = 0; ii < count; ii++) { - item = _dataItemSeq[ii]; + item = (*seq)[ii]; printout_dataitem(ii, &item); } log_debug("BusMessage.printout() done\n");; diff --git a/src/plpbus/BusMessage.hh b/src/plpbus/BusMessage.hh index cdc72a1..1f9f48a 100644 --- a/src/plpbus/BusMessage.hh +++ b/src/plpbus/BusMessage.hh @@ -8,13 +8,11 @@ #ifndef BUSMESSAGE_H_ #define BUSMESSAGE_H_ -#include "RequestResponseBus.hh" - namespace plpbus { class BusMessage { public: - plpbus_orb::DataItemSequence _dataItemSeq; + void *_dataItemSeq; BusMessage(); BusMessage(const char *name_param, const char *string_value_param); @@ -26,7 +24,7 @@ namespace plpbus { int add_float_parameter(const char *name_param, float value_param); void printout(); private: - void printout_dataitem(long index, plpbus_orb::DataItem *item); + void printout_dataitem(long index, void *item); }; } diff --git a/src/plpbus/BusMessageInternal.cc b/src/plpbus/BusMessageInternal.cc index 6839f79..b66f18e 100644 --- a/src/plpbus/BusMessageInternal.cc +++ b/src/plpbus/BusMessageInternal.cc @@ -7,13 +7,13 @@ #include "BusMessageInternal.hh" +using namespace plpbus_orb; + namespace plpbus { - BusMessageInternal::BusMessageInternal(plpbus_orb::DataItemSequence seq_param) { - _dataItemSeq = seq_param; + BusMessageInternal::BusMessageInternal(DataItemSequence seq_param) { + _dataItemSeq = new DataItemSequence(seq_param); } - BusMessageInternal::~BusMessageInternal() - { - // TODO Auto-generated destructor stub + BusMessageInternal::~BusMessageInternal() { } } diff --git a/src/plpbus/BusMessageInternal.hh b/src/plpbus/BusMessageInternal.hh index e3fa771..76994e8 100644 --- a/src/plpbus/BusMessageInternal.hh +++ b/src/plpbus/BusMessageInternal.hh @@ -9,6 +9,7 @@ #define BUSMESSAGEINTERNAL_HH_ #include "BusMessage.hh" +#include "RequestResponseBus.hh" namespace plpbus { class BusMessageInternal: public plpbus::BusMessage diff --git a/src/plpbus/BusServer.hh b/src/plpbus/BusServer.hh index e644480..577fe4b 100644 --- a/src/plpbus/BusServer.hh +++ b/src/plpbus/BusServer.hh @@ -2,7 +2,6 @@ #define BUSSERVER_HH_ #include "IServerListener.hh" -//#include "OrbServerImpl.hh" namespace plpbus { class BusServer { diff --git a/src/plpbus/OrbServerImpl.cc b/src/plpbus/OrbServerImpl.cc index 4317ff1..1c8bfb5 100644 --- a/src/plpbus/OrbServerImpl.cc +++ b/src/plpbus/OrbServerImpl.cc @@ -43,6 +43,7 @@ void OrbServerImpl::send_message_and_request_response(OrbClient_ptr response_lis if (_listener != NULL) { 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 { @@ -75,8 +76,9 @@ 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) { @@ -86,9 +88,10 @@ void OrbServerImpl::send_dataitem_message_and_request_response(OrbClient_ptr res msg_req->printout(); msg_rsp = NULL; _listener->request_received(msg_req, &msg_rsp); - log_debug("msg_rsp length: %ld\n", msg_rsp->_dataItemSeq.length()); + 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 { log_error("send_dataitem_message_and_request_response() error, server_callback == NULL\n"); @@ -97,15 +100,17 @@ void OrbServerImpl::send_dataitem_message_and_request_response(OrbClient_ptr res } 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); msg_rsp = NULL; _listener->request_received(msg_req, &msg_rsp); //rsp_seq_param = new DataItemSequence_out(msg_rsp._dataItemSeq); - rsp_seq_param._data = &(msg_rsp->_dataItemSeq); + seq = (DataItemSequence *)msg_rsp->_dataItemSeq; + rsp_seq_param._data = seq; return 0; } @@ -179,7 +184,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(); diff --git a/src/plpbus/OrbServerImpl.hh b/src/plpbus/OrbServerImpl.hh index 3ca7d7a..a73e7bf 100644 --- a/src/plpbus/OrbServerImpl.hh +++ b/src/plpbus/OrbServerImpl.hh @@ -20,7 +20,6 @@ namespace plpbus { public: OrbServerImpl(); virtual ~OrbServerImpl(); - virtual void send_message_and_request_response(plpbus_orb::OrbClient_ptr response_listener_param, const char* msg_req_param); virtual void send_dataitem_message_and_request_response(plpbus_orb::OrbClient_ptr response_listener_param, const ::plpbus_orb::DataItemSequence& req_seq_param); virtual char *send_message_and_wait_response(const char* msg_req_param, ::CORBA::Long& err_flg); diff --git a/src/plpbus/ServerEventThread.cc b/src/plpbus/ServerEventThread.cc index f0cb4dc..fadb9f5 100644 --- a/src/plpbus/ServerEventThread.cc +++ b/src/plpbus/ServerEventThread.cc @@ -5,12 +5,13 @@ * Author: lamikr */ -////////////////////////////////////////////////////////////////////// - // A thread object used to server clients registered // using the plpbus_orb::OrbServer::register() method. +#include + #include "BusServer.hh" #include "ServerEventThread.hh" + using namespace std; using namespace plpbus; @@ -35,8 +36,8 @@ void ServerEventThread::run(void* arg) } } catch(...) { - cout << "server_thread failed, could not connect to client!" << endl; + log_error("server_thread failed, could not connect to client!\n"); } - cout << "server_thread, closing" << endl; + log_debug("server_thread, closing\n"); _server_obj->server_thread_closed(); } diff --git a/src_test/test_server.cc b/src_test/test_server.cc index c59d76e..1a6a17f 100644 --- a/src_test/test_server.cc +++ b/src_test/test_server.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include "plpbus/BusServer.hh" @@ -15,16 +16,18 @@ class ServerListenerImpl : public IServerListener }; int ServerListenerImpl::request_received(const char *msg_req_param, char **msg_rsp_param) { - cout << "request_received(char *" << msg_req_param << ") " << endl; + log_debug("request_received(), request_param: %s\n", msg_req_param); *msg_rsp_param = strdup("jee"); + log_debug("request_received(), response param set: %s\n", *msg_rsp_param); return 0; } int ServerListenerImpl::request_received(const BusMessage *msg_req_param, BusMessage **msg_rsp_param) { - cout << "request_received(BusMessage *) " << endl; + log_debug("request_received(BusMessage *) started\n"); *msg_rsp_param = new BusMessage(); double dbl = (double)1.0; (*msg_rsp_param)->add_double_parameter("rsp_param_double", dbl); + log_debug("request_received(BusMessage *) done\n"); return 0; } @@ -34,7 +37,7 @@ int main(int argc, char** argv) ServerListenerImpl *listener; if (argc >= 2) { - cout << "starting server" << endl; + log_info("starting server\n"); server = new BusServer(); server->init(); listener = new ServerListenerImpl(); @@ -42,7 +45,7 @@ int main(int argc, char** argv) server->launch(argv[1]); } else { - cout << "usage: give server name as a parameter" << endl; + log_info("usage: give server name as a parameter\n"); } return 0; } -- 2.41.1