2 * Copyright (c) copyright 2011-2012 Aricent® Group and its licensors
3 * Copyright (c) 2012 BMW
5 * \author Sampreeth Ramavana
6 * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
9 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction,
10 * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
15 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 * For further information see http://www.genivi.org/.
20 #include "CAmDbusSend.h"
21 #include "shared/CAmDltWrapper.h"
26 DLT_IMPORT_CONTEXT(routingDbus)
28 CAmRoutingDbusSend::CAmRoutingDbusSend(DBusConnection* conn, std::string bus_name, std::string path, std::string interface, std::string method) :
29 mpDbusMessage(NULL), //
30 mpDbusConnection(conn), //
31 mDbusMessageIter(), //
34 dbus_error_init(&mDBusError);
35 mpDbusMessage = dbus_message_new_method_call(bus_name.c_str(), path.c_str(), interface.c_str(), method.c_str());
36 if (NULL == mpDbusMessage)
38 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingDbusSend::CAmRoutingDbusSend dbus error:", mDBusError.message);
39 this->~CAmRoutingDbusSend();
43 CAmRoutingDbusSend::~CAmRoutingDbusSend()
47 void CAmRoutingDbusSend::append(std::string string)
49 dbus_message_iter_init_append(mpDbusMessage, &mDbusMessageIter);
50 if (!dbus_message_iter_append_basic(&mDbusMessageIter, DBUS_TYPE_STRING, string.c_str()))
52 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingDbusSend::append no more memory");
53 this->~CAmRoutingDbusSend();
57 void CAmRoutingDbusSend::append(uint16_t integer)
59 dbus_message_iter_init_append(mpDbusMessage, &mDbusMessageIter);
60 if (!dbus_message_iter_append_basic(&mDbusMessageIter, DBUS_TYPE_UINT16, &integer))
62 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingDbusSend::append no more memory");
63 this->~CAmRoutingDbusSend();
67 void CAmRoutingDbusSend::append(int16_t integer)
69 dbus_message_iter_init_append(mpDbusMessage, &mDbusMessageIter);
70 if (!dbus_message_iter_append_basic(&mDbusMessageIter, DBUS_TYPE_INT16, &integer))
72 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingDbusSend::append no more memory");
73 this->~CAmRoutingDbusSend();
77 void CAmRoutingDbusSend::append(std::vector<am_SoundProperty_s> listSoundProperties)
79 DBusMessageIter arrayIter;
80 DBusMessageIter structIter;
81 std::vector<am_SoundProperty_s>::const_iterator listIterator = listSoundProperties.begin();
82 dbus_bool_t success = true;
84 success = success && dbus_message_iter_open_container(&mDbusMessageIter, DBUS_TYPE_ARRAY, "(nn)", &arrayIter);
85 for (; listIterator < listSoundProperties.end(); ++listIterator)
87 success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter);
88 success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->type);
89 success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->value);
90 success = success && dbus_message_iter_close_container(&arrayIter, &structIter);
92 success = success && dbus_message_iter_close_container(&mDbusMessageIter, &arrayIter);
96 log(&routingDbus, DLT_LOG_ERROR, "DBusMessageHandler::append error", mDBusError.message);
100 void CAmRoutingDbusSend::append(am_SoundProperty_s soundProperty)
102 DBusMessageIter structIter;
103 dbus_bool_t success = true;
105 success = success && dbus_message_iter_open_container(&mDbusMessageIter, DBUS_TYPE_STRUCT, NULL, &structIter);
106 success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &soundProperty.type);
107 success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &soundProperty.value);
108 success = success && dbus_message_iter_close_container(&mDbusMessageIter, &structIter);
112 log(&routingDbus, DLT_LOG_ERROR, "DBusMessageHandler::append error", mDBusError.message);
116 am_Error_e CAmRoutingDbusSend::send()
120 DBusMessage* reply(dbus_connection_send_with_reply_and_block(mpDbusConnection, mpDbusMessage, -1, &mDBusError));
123 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingDbusSend::send failed, dbus error", mDBusError.message);
126 if(!dbus_message_get_args(reply, &mDBusError, //
127 DBUS_TYPE_INT16, &error, //
130 dbus_message_unref(reply);
131 return (static_cast<am_Error_e>(error));