]> pilppa.com Git - libplpbus.git/commitdiff
Force to add type_id identifier for messages. Receiver can then use the
authorMika Laitio <lamikr@pilppa.org>
Wed, 2 Mar 2011 19:33:06 +0000 (21:33 +0200)
committerMika Laitio <lamikr@pilppa.org>
Wed, 2 Mar 2011 19:33:06 +0000 (21:33 +0200)
type-id for identifying the messages from each others.

Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src/plpbus/BusMessage.cc
src/plpbus/BusMessage.hh
src/plpbus/BusMessageInternal.cc
src_test/test_client.cc
src_test/test_server.cc

index 1743d4c8c807dc82ba7f47898c5f95a81bf15754..18fc487496a638a4dd00366fd264ad12c7100ac4 100644 (file)
@@ -16,33 +16,27 @@ using namespace plpbus;
 using namespace CORBA;
 
 BusMessage::BusMessage() {
-       _dataItemSeq    = new DataItemSequence();
-       log_debug("new BusMessage()\n");
+       _dataItemSeq    = new DataItemSequence(0);
 }
 
-BusMessage::BusMessage(const char *name_param, const char *value_param) {
-       DataItem                *item;
-       DataItemSequence        *seq;
+BusMessage::BusMessage(long type_param) {
+       _dataItemSeq    = new DataItemSequence(0);
 
-       if (name_param != NULL) {
-               item            = new DataItem();
-               item->name      = strdup(name_param);
-               item->value     <<= strdup(value_param);
+       add_long_parameter(CONST_MSG_ID_KEY_NAME, type_param);
+}
 
-               seq     = new DataItemSequence(0);
-               seq->length(1);
-               (*seq)[0]       = *item;
-               _dataItemSeq    = seq;
-       }
-       else {
-               _dataItemSeq    = new DataItemSequence(0);
-       }
+BusMessage::BusMessage(long type_param,
+                       const char *arg_name_param,
+                       const char *arg_string_value_param) {
+       _dataItemSeq    = new DataItemSequence(0);
+       add_long_parameter(CONST_MSG_ID_KEY_NAME, type_param);
+       add_string_parameter(arg_name_param, arg_string_value_param);
 }
 
 BusMessage::~BusMessage() {
 }
 
-int BusMessage::add_string_parameter(const char *name_param, const char *value_param)
+int BusMessage::add_string_parameter(const char *arg_name_param, const char *value_param)
 {
        long                    length;
        int                     ret_val;
@@ -51,10 +45,10 @@ int BusMessage::add_string_parameter(const char *name_param, const char *value_p
 
        ret_val = 0;
        seq     = (DataItemSequence *)_dataItemSeq;
-       if (name_param != NULL) {
+       if (arg_name_param != NULL) {
                length          = seq->length();
                item            = new DataItem();
-               item->name      = strdup(name_param);
+               item->name      = strdup(arg_name_param);
                if (value_param != NULL) {
                        item->value     <<= strdup(value_param);
                        seq->length(length + 1);
@@ -62,13 +56,12 @@ int BusMessage::add_string_parameter(const char *name_param, const char *value_p
                }
        }
        else {
-               seq->length(0);
                ret_val = -1;
        }
        return ret_val;
 }
 
-int BusMessage::add_long_parameter(const char *name_param, long value_param)
+int BusMessage::add_long_parameter(const char *arg_name_param, long value_param)
 {
        long                    length;
        int                     ret_val;
@@ -77,23 +70,22 @@ int BusMessage::add_long_parameter(const char *name_param, long value_param)
 
        ret_val = 0;
        seq     = (DataItemSequence *)_dataItemSeq;
-       if (name_param != NULL) {
+       if (arg_name_param != NULL) {
                length          = seq->length();
                item            = new DataItem();
-               item->name      = strdup(name_param);
+               item->name      = strdup(arg_name_param);
                item->value     <<= value_param;
 
                seq->length(length + 1);
                (*seq)[length]  = *item;
        }
        else {
-               seq->length(0);
                ret_val = -1;
        }
        return ret_val;
 }
 
-int BusMessage::add_int_parameter(const char *name_param, int value_param)
+int BusMessage::add_int_parameter(const char *arg_name_param, int value_param)
 {
        long                    length;
        int                     ret_val;
@@ -102,23 +94,22 @@ int BusMessage::add_int_parameter(const char *name_param, int value_param)
 
        ret_val = 0;
        seq     = (DataItemSequence *)_dataItemSeq;
-       if (name_param != NULL) {
+       if (arg_name_param != NULL) {
                length          = seq->length();
                item            = new DataItem();
-               item->name      = strdup(name_param);
+               item->name      = strdup(arg_name_param);
                item->value     <<= (long)value_param;
 
                seq->length(length + 1);
                (*seq)[length]  = *item;
        }
        else {
-               seq->length(0);
                ret_val = -1;
        }
        return ret_val;
 }
 
-int BusMessage::add_double_parameter(const char *name_param, double value_param)
+int BusMessage::add_double_parameter(const char *arg_name_param, double value_param)
 {
        long                    length;
        int                     ret_val;
@@ -128,24 +119,23 @@ int BusMessage::add_double_parameter(const char *name_param, double value_param)
        ret_val = 0;
        log_debug("add_double_parameter() started\n");
        seq     = (DataItemSequence *)_dataItemSeq;
-       if (name_param != NULL) {
+       if (arg_name_param != NULL) {
                length          = seq->length();
                item            = new DataItem();
-               item->name      = strdup(name_param);
+               item->name      = strdup(arg_name_param);
                item->value     <<= (long)value_param;
 
                seq->length(length + 1);
                (*seq)[length]  = *item;
        }
        else {
-               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)
+int BusMessage::add_float_parameter(const char *arg_name_param, float value_param)
 {
        long                    length;
        int                     ret_val;
@@ -154,17 +144,16 @@ int BusMessage::add_float_parameter(const char *name_param, float value_param)
 
        ret_val = 0;
        seq     = (DataItemSequence *)_dataItemSeq;
-       if (name_param != NULL) {
+       if (arg_name_param != NULL) {
                length          = seq->length();
                item            = new DataItem();
-               item->name      = strdup(name_param);
+               item->name      = strdup(arg_name_param);
                item->value     <<= (long)value_param;
 
                seq->length(length + 1);
                (*seq)[length]  = *item;
        }
        else {
-               seq->length(0);
                ret_val = -1;
        }
        return ret_val;
index 1f9f48a4180792e9b54e7034a002c8e8b53ad737..855a39937b2b3269796e6280d2b5b9629918cc49 100644 (file)
@@ -8,22 +8,25 @@
 #ifndef BUSMESSAGE_H_
 #define BUSMESSAGE_H_
 
+#define CONST_MSG_ID_KEY_NAME  "_msgid"
+
 namespace plpbus {
        class BusMessage
        {
                public:
                        void    *_dataItemSeq;
 
-                       BusMessage();
-                       BusMessage(const char *name_param, const char *string_value_param);
+                       BusMessage(long type_param);
+                       BusMessage(long type_param, const char *arg_name_param, const char *arg_string_value_param);
                        virtual ~BusMessage();
-                       int add_string_parameter(const char *name_param, const char *string_value_param);
-                       int add_long_parameter(const char *name_param, long value_param);
-                       int add_int_parameter(const char *name_param, int value_param);
-                       int add_double_parameter(const char *name_param, double value_param);
-                       int add_float_parameter(const char *name_param, float value_param);
+                       int add_string_parameter(const char *arg_name_param, const char *string_value_param);
+                       int add_long_parameter(const char *arg_name_param, long value_param);
+                       int add_int_parameter(const char *arg_name_param, int value_param);
+                       int add_double_parameter(const char *arg_name_param, double value_param);
+                       int add_float_parameter(const char *arg_name_param, float value_param);
                        void printout();
-               private:
+               protected:
+                       BusMessage();
                        void printout_dataitem(long index, void *item);
        };
 }
index b66f18e0dd5ec9d765f860df27df443440bee8e8..ee1a25f3a70ae631bd791e34fce91713586acaac 100644 (file)
 using namespace plpbus_orb;
 
 namespace plpbus {
-       BusMessageInternal::BusMessageInternal(DataItemSequence seq_param) {
+       BusMessageInternal::BusMessageInternal(DataItemSequence seq_param) : BusMessage() {
+               DataItemSequence        *seq;
+
+               seq     = (DataItemSequence *)_dataItemSeq;
+               delete(seq);
                _dataItemSeq    = new DataItemSequence(seq_param);
        }
 
index aeca5109cb6b13ef30ccfdfa322cbdb9e1db69c8..03cdcd7139c20eac49523a2baf8d99ed9cbe19d7 100644 (file)
@@ -12,6 +12,8 @@
 using namespace std;
 using namespace plpbus;
 
+#define MSG_ID_HELLO   0
+
 class ClientListenerImpl : public IClientListener
 {
        public:
@@ -61,7 +63,7 @@ int main(int argc, char** argv)
                                int     err_flg;
                                char    *rsp;
 
-                               busmsg  = new BusMessage();
+                               busmsg  = new BusMessage(MSG_ID_HELLO);
                                busmsg->add_string_parameter("a", "hello");
                                busmsg->add_string_parameter("b", "world");
                                client->send_message_and_request_response(busmsg);
index 1a6a17f1113190e720b4ad4cb909b6631f861a0c..a310b1d95abe4683ec107e53d27f8bc78ce9547d 100644 (file)
@@ -6,6 +6,8 @@
 using namespace std;
 using namespace plpbus;
 
+#define MSG_ID_HELLO   0
+
 class ServerListenerImpl : public IServerListener
 {
        public:
@@ -24,7 +26,7 @@ int ServerListenerImpl::request_received(const char *msg_req_param, char **msg_r
 
 int ServerListenerImpl::request_received(const BusMessage *msg_req_param, BusMessage **msg_rsp_param) {
        log_debug("request_received(BusMessage *) started\n");
-       *msg_rsp_param = new BusMessage();
+       *msg_rsp_param = new BusMessage(MSG_ID_HELLO);
        double dbl = (double)1.0;
        (*msg_rsp_param)->add_double_parameter("rsp_param_double", dbl);
        log_debug("request_received(BusMessage *) done\n");