* Author: lamikr
*/
+#include <malloc.h>
+#include <omniORB4/CORBA.h>
+
#include <plp/log.h>
+#include <plp/retval.h>
#include "BusMessage.hh"
#include "RequestResponseBus.hh"
BusMessage::~BusMessage() {
}
-int BusMessage::add_string_parameter(const char *arg_name_param, const char *value_param)
+int BusMessage::add_string_parameter(string arg_name_param, string value_param)
{
long length;
int ret_val;
ret_val = 0;
seq = (DataItemSequence *)_dataItemSeq;
- if (arg_name_param != NULL) {
+ if (arg_name_param.empty() == false) {
length = seq->length();
item = new DataItem();
- item->name = strdup(arg_name_param);
- if (value_param != NULL) {
- item->value <<= strdup(value_param);
- seq->length(length + 1);
- (*seq)[length] = *item;
- }
+ item->name = strdup(arg_name_param.c_str());
+ item->value <<= strdup(value_param.c_str());
+ seq->length(length + 1);
+ (*seq)[length] = *item;
}
else {
ret_val = -1;
return ret_val;
}
-int BusMessage::add_int_parameter(const char *arg_name_param, int value_param)
+int BusMessage::add_int_parameter(string arg_name_param, int value_param)
{
long length;
int ret_val;
ret_val = 0;
seq = (DataItemSequence *)_dataItemSeq;
- if (arg_name_param != NULL) {
+ if (arg_name_param.empty() == false) {
length = seq->length();
item = new DataItem();
- item->name = strdup(arg_name_param);
+ item->name = strdup(arg_name_param.c_str());
item->value <<= (long)value_param;
seq->length(length + 1);
return ret_val;
}
-static DataItem *get_dataitem_by_param_name(DataItemSequence *seq, const char *arg_name_param) {
+static DataItem *get_dataitem_by_param_name(DataItemSequence *seq, string arg_name_param) {
DataItem *ret_val;
long int count;
DataItem *item;
for (long ii = 0; ii < count; ii++) {
item = &(*seq)[ii];
item_name = item->name;
- if (strcmp(arg_name_param, item_name) == 0) {
+ if (strcmp(arg_name_param.c_str(), item_name) == 0) {
ret_val = item;
break;
}
return ret_val;
}
-bool BusMessage::get_type(long *type_param) {
- bool ret_val;
+long BusMessage::get_type(int *err_flg) {
+ long ret_val;
long res;
- ret_val = get_long_parameter(CONST_MSG_ID_KEY_NAME, &res);
- if (ret_val == true) {
- *type_param = res;
+ res = get_long_parameter(CONST_MSG_ID_KEY_NAME, err_flg);
+ if (*err_flg == PLP_OK) {
+ ret_val = res;
}
return ret_val;
}
-bool BusMessage::get_string_parameter(const char *arg_name_param, const char **value_param) {
- bool ret_val;
- DataItem *item;
- DataItemSequence *seq;
+string BusMessage::get_string_parameter(string arg_name_param, int *err_flg) {
+ string ret_val;
+ DataItem *item;
+ DataItemSequence *seq;
+ const char *ch;
- ret_val = false;
- seq = (DataItemSequence *)_dataItemSeq;
- item = get_dataitem_by_param_name(seq, arg_name_param);
+ *err_flg = PLP_ERR_DATA_NOT_FOUND;
+ seq = (DataItemSequence *)_dataItemSeq;
+ item = get_dataitem_by_param_name(seq, arg_name_param);
if (item != NULL) {
- item->value >>= *value_param;
- ret_val = true;
+ item->value >>= CORBA::Any::to_string(ch, 0);
+ ret_val = ch;
+ *err_flg = PLP_OK;
}
return ret_val;
}
-bool BusMessage::get_long_parameter(const char *arg_name_param, long *value_param) {
- bool ret_val;
+long BusMessage::get_long_parameter(string arg_name_param, int *err_flg) {
+ long ret_val;
DataItem *item;
DataItemSequence *seq;
- ret_val = false;
- seq = (DataItemSequence *)_dataItemSeq;
- item = get_dataitem_by_param_name(seq, arg_name_param);
+ *err_flg = PLP_ERR_DATA_NOT_FOUND;
+ seq = (DataItemSequence *)_dataItemSeq;
+ item = get_dataitem_by_param_name(seq, arg_name_param);
if (item != NULL) {
- item->value >>= *value_param;
- ret_val = true;
+ item->value >>= ret_val;
+ *err_flg = PLP_OK;
}
return ret_val;
}
-bool BusMessage::get_int_parameter(const char *arg_name_param, int *value_param) {
- bool ret_val;
+int BusMessage::get_int_parameter(string arg_name_param, int *err_flg) {
+ int ret_val;
DataItem *item;
DataItemSequence *seq;
long tmp;
- ret_val = false;
- seq = (DataItemSequence *)_dataItemSeq;
- item = get_dataitem_by_param_name(seq, arg_name_param);
+ *err_flg = PLP_ERR_DATA_NOT_FOUND;
+ seq = (DataItemSequence *)_dataItemSeq;
+ item = get_dataitem_by_param_name(seq, arg_name_param);
if (item != NULL) {
item->value >>= tmp;
- *value_param = (int)tmp;
- ret_val = true;
+ ret_val = (int)tmp;
+ *err_flg = PLP_OK;
}
return ret_val;
}
-bool BusMessage::get_double_parameter(const char *arg_name_param, double *value_param) {
- bool ret_val;
+double BusMessage::get_double_parameter(string arg_name_param, int *err_flg) {
+ double ret_val;
DataItem *item;
DataItemSequence *seq;
- ret_val = false;
- seq = (DataItemSequence *)_dataItemSeq;
- item = get_dataitem_by_param_name(seq, arg_name_param);
+ *err_flg = PLP_ERR_DATA_NOT_FOUND;
+ seq = (DataItemSequence *)_dataItemSeq;
+ item = get_dataitem_by_param_name(seq, arg_name_param);
if (item != NULL) {
- item->value >>= *value_param;
- ret_val = true;
+ item->value >>= ret_val;
+ *err_flg = PLP_OK;
}
return ret_val;
}
-bool BusMessage::get_float_parameter(const char *arg_name_param, float *value_param) {
- bool ret_val;
+float BusMessage::get_float_parameter(string arg_name_param, int *err_flg) {
+ float ret_val;
DataItem *item;
DataItemSequence *seq;
- ret_val = false;
- seq = (DataItemSequence *)_dataItemSeq;
- item = get_dataitem_by_param_name(seq, arg_name_param);
+ *err_flg = PLP_ERR_DATA_NOT_FOUND;
+ seq = (DataItemSequence *)_dataItemSeq;
+ item = get_dataitem_by_param_name(seq, arg_name_param);
if (item != NULL) {
- item->value >>= *value_param;
- ret_val = true;
+ item->value >>= ret_val;
+ *err_flg = PLP_OK;
}
return ret_val;
}
#ifndef BUSMESSAGE_H_
#define BUSMESSAGE_H_
+#include <string>
+
namespace plpbus {
class BusMessage
{
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 *arg_name_param, const char *string_value_param);
+ int add_string_parameter(std::string arg_name_param, std::string 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_int_parameter(std::string 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);
- bool get_type(long *type_param);
- bool get_string_parameter(const char *arg_name_param, const char **value_param);
- bool get_long_parameter(const char *arg_name_param, long *value_param);
- bool get_int_parameter(const char *arg_name_param, int *value_param);
- bool get_double_parameter(const char *arg_name_param, double *value_param);
- bool get_float_parameter(const char *arg_name_param, float *value_param);
+ long get_type(int *err_flg);
+ std::string get_string_parameter(std::string arg_name_param, int *err_flg);
+ long get_long_parameter(std::string arg_name_param, int *err_flg);
+ int get_int_parameter(std::string arg_name_param, int *err_flg);
+ double get_double_parameter(std::string arg_name_param, int *err_flg);
+ float get_float_parameter(std::string arg_name_param, int *err_flg);
void printout();
protected:
BusMessage();