/* * BusMessage.cpp * * Created on: Aug 17, 2010 * Author: lamikr */ #include #include "BusMessage.hh" using namespace std; using namespace plpbus_orb; using namespace plpbus; using namespace CORBA; BusMessage::BusMessage() { _dataItemSeq.length(0); } BusMessage::BusMessage(const char *name_param, const char *value_param) { DataItem *item; if (name_param != NULL) { item = new DataItem(); item->name = strdup(name_param); item->value <<= strdup(value_param); _dataItemSeq.length(1); _dataItemSeq[0] = *item; } else { _dataItemSeq.length(0); } } BusMessage::~BusMessage() { // TODO Auto-generated destructor stub } int BusMessage::add_string_parameter(const char *name_param, const char *value_param) { long length; int ret_val; DataItem *item; ret_val = 0; if (name_param != NULL) { length = _dataItemSeq.length(); item = new DataItem(); item->name = strdup(name_param); if (value_param != NULL) { item->value <<= strdup(value_param); _dataItemSeq.length(length + 1); _dataItemSeq[length] = *item; } } else { _dataItemSeq.length(0); ret_val = -1; } return ret_val; } int BusMessage::add_long_parameter(const char *name_param, long value_param) { long length; int ret_val; DataItem *item; ret_val = 0; if (name_param != NULL) { length = _dataItemSeq.length(); item = new DataItem(); item->name = strdup(name_param); item->value <<= value_param; _dataItemSeq.length(length + 1); _dataItemSeq[length] = *item; } else { _dataItemSeq.length(0); ret_val = -1; } return ret_val; } int BusMessage::add_int_parameter(const char *name_param, int value_param) { long length; int ret_val; DataItem *item; ret_val = 0; if (name_param != NULL) { length = _dataItemSeq.length(); item = new DataItem(); item->name = strdup(name_param); item->value <<= (long)value_param; _dataItemSeq.length(length + 1); _dataItemSeq[length] = *item; } else { _dataItemSeq.length(0); ret_val = -1; } return ret_val; } int BusMessage::add_double_parameter(const char *name_param, double value_param) { long length; int ret_val; DataItem *item; ret_val = 0; if (name_param != NULL) { length = _dataItemSeq.length(); item = new DataItem(); item->name = strdup(name_param); item->value <<= (long)value_param; _dataItemSeq.length(length + 1); _dataItemSeq[length] = *item; } else { _dataItemSeq.length(0); ret_val = -1; } return ret_val; } int BusMessage::add_float_parameter(const char *name_param, float value_param) { long length; int ret_val; DataItem *item; ret_val = 0; if (name_param != NULL) { length = _dataItemSeq.length(); item = new DataItem(); item->name = strdup(name_param); item->value <<= (long)value_param; _dataItemSeq.length(length + 1); _dataItemSeq[length] = *item; } else { _dataItemSeq.length(0); ret_val = -1; } return ret_val; } void BusMessage::printout_dataitem(long index, plpbus_orb::DataItem *item) { CORBA::TCKind kind; if (item != NULL) { if (item->name != NULL) { kind = item->value.type()->kind(); switch(kind) { case tk_string: { const char *val; item->value >>= val; log_debug(" [%d], value: %s\n", index, val); } break; case tk_long: { long val; item->value >>= val; log_debug(" [%d], value: %ld\n", index, val); //val_str = strdup("long"); } break; case tk_double: { double val; item->value >>= val; log_debug(" [%d], value: %f\n", index, val); //val_str = strdup("double"); } break; case tk_float: { float val; item->value >>= val; log_debug(" [%d] name: %s, value: %f\n", index, val); //val_str = strdup("float"); } break; default: log_error(" [%d] name, value unknown\n", index); } } else { log_error(" [%d] Invalid data item name name or value\n", index); } } else { log_error(" [%d] dataItem NULL.", index); } } void BusMessage::printout() { long int count; DataItem item; count = _dataItemSeq.length(); log_debug("BusMessage.printout(): parameter count: %l\n", count); for (long ii = 0; ii < count; ii++) { item = _dataItemSeq[ii]; printout_dataitem(ii, &item); } log_debug("BusMessage.printout() done\n");; }