]> pilppa.com Git - libplpbus.git/commitdiff
cleaned up public headers available for bus client and server
authorMika Laitio <lamikr@pilppa.org>
Tue, 1 Mar 2011 23:35:09 +0000 (01:35 +0200)
committerMika Laitio <lamikr@pilppa.org>
Tue, 1 Mar 2011 23:35:09 +0000 (01:35 +0200)
implementators.

Signed-off-by: Mika Laitio <lamikr@pilppa.org>
12 files changed:
src/Makefile.am
src/plpbus/BusClient.cc
src/plpbus/BusClient.hh
src/plpbus/BusMessage.cc
src/plpbus/BusMessage.hh
src/plpbus/BusMessageInternal.cc
src/plpbus/BusMessageInternal.hh
src/plpbus/BusServer.hh
src/plpbus/OrbServerImpl.cc
src/plpbus/OrbServerImpl.hh
src/plpbus/ServerEventThread.cc
src_test/test_server.cc

index 515e06a432d36f4dae0f33d256e59521fb0dfe03..4ca46180433e901403225dce47f8f96207d42517 100644 (file)
@@ -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
 
index 2a847274d00f15cf287871f6f7b78968de8d7158..42c47f744d9715248cc25d73f6c159520903f812 100644 (file)
@@ -8,13 +8,15 @@
 #include <plp/log.h>
 
 #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;
 }
 
index a1fe5dce6cd1dd8eb2ceab0fe0ef3470fdf8262b..c71778b6f1a135b1b8b193bc59f29bfc7f4b6036 100644 (file)
@@ -13,7 +13,6 @@
 
 #include "RequestResponseBus.hh"
 #include "IClientListener.hh"
-#include "ClientServerCommon.hh"
 #include "BusMessage.hh"
 
 namespace plpbus {
index 84cd386f937bf68c94e5115a954af11fc4d9da3e..1743d4c8c807dc82ba7f47898c5f95a81bf15754 100644 (file)
@@ -8,60 +8,61 @@
 #include <plp/log.h>
 
 #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");;
index cdc72a109093d61c3d246bc6c624e729b61cc071..1f9f48a4180792e9b54e7034a002c8e8b53ad737 100644 (file)
@@ -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);
        };
 }
 
index 6839f794039c9f895ccb2af0e6346ca889d8bbf0..b66f18e0dd5ec9d765f860df27df443440bee8e8 100644 (file)
@@ -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() {
        }
 }
index e3fa7715ebdded0023f0e4c129aa61775d3169f3..76994e84232da8e8aa80596c873c58dd560ddc2d 100644 (file)
@@ -9,6 +9,7 @@
 #define BUSMESSAGEINTERNAL_HH_
 
 #include "BusMessage.hh"
+#include "RequestResponseBus.hh"
 
 namespace plpbus {
        class BusMessageInternal: public plpbus::BusMessage
index e6444809eb6ecf5aa63f9707bb07777b723fd943..577fe4bbf2bea698254b6c959f8fb4d99b194582 100644 (file)
@@ -2,7 +2,6 @@
 #define BUSSERVER_HH_
 
 #include "IServerListener.hh"
-//#include "OrbServerImpl.hh"
 
 namespace plpbus {
        class BusServer {
index 4317ff110e61fea7c073371dd734ccff2d149177..1c8bfb5724f16a785f45962c3c8d04289e12a072 100644 (file)
@@ -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();
index 3ca7d7a82bd7d77f7688e00eabb58aa5cef48020..a73e7bfba849596d872da5d8eb6a73463825f559 100644 (file)
@@ -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);
index f0cb4dce2f2d6c87c3f0473a5d7f131ed6094cb7..fadb9f5df43ddc4dd5e7bccb81ecc2e79f5d4cc3 100644 (file)
@@ -5,12 +5,13 @@
  *      Author: lamikr
  */
 
-//////////////////////////////////////////////////////////////////////
-
 // A thread object used to server clients registered
 // using the plpbus_orb::OrbServer::register() method.
+#include <plp/log.h>
+
 #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();
 }
index c59d76ee76280c6b072fe8a62d106d4293ee365d..1a6a17f1113190e720b4ad4cb909b6631f861a0c 100644 (file)
@@ -1,4 +1,5 @@
-#include <iostream>
+#include <string.h>
+#include <plp/log.h>
 
 #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;
 }