--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file dbus_message_out.cpp
+ * @author Marcin Niesluchowski (m.niesluchow@samsung.com)
+ * @version 1.0
+ * @brief DBus outgoing message wrapper class source file
+ */
+
+#include <dbus_message_out.h>
+
+#include <dpl/test/test_runner.h>
+
+namespace DBus
+{
+
+MessageOut::MessageOut(const std::string &destination,
+ const std::string &path,
+ const std::string &interface,
+ const std::string &method)
+{
+ m_message = dbus_message_new_method_call(destination.c_str(),
+ path.c_str(),
+ interface.c_str(),
+ method.c_str());
+ RUNNER_ASSERT_MSG(nullptr != m_message,
+ "Failed to create new method call. Not enough memory");
+}
+
+MessageOut::MessageOut(MessageOut &&other)
+ : m_message(other.m_message)
+{
+ other.m_message = nullptr;
+}
+
+MessageOut::~MessageOut()
+{
+ if (m_message != nullptr)
+ dbus_message_unref(m_message);
+}
+
+DBusMessage* MessageOut::getMessage() const
+{
+ return m_message;
+}
+
+void MessageOut::append(bool b)
+{
+ DBusMessageIter iter;
+ dbus_message_iter_init_append(m_message, &iter);
+
+ dbus_bool_t bArg = b ? TRUE : FALSE;
+ dbus_bool_t ret = dbus_message_iter_append_basic(&iter,
+ DBUS_TYPE_BOOLEAN,
+ &bArg);
+ RUNNER_ASSERT_MSG(ret != FALSE, "Failed to append basic boolean. Not enough memory");
+}
+
+void MessageOut::append(const char *cstr)
+{
+ DBusMessageIter iter;
+ dbus_message_iter_init_append(m_message, &iter);
+
+ dbus_bool_t ret = dbus_message_iter_append_basic(&iter,
+ DBUS_TYPE_STRING,
+ &cstr);
+ RUNNER_ASSERT_MSG(ret != FALSE, "Failed to append basic string. Not enough memory");
+}
+
+void MessageOut::append(const std::string &str)
+{
+ append(str.c_str());
+}
+
+void MessageOut::append(const std::vector<std::string> &strs)
+{
+ DBusMessageIter iter;
+ dbus_message_iter_init_append(m_message, &iter);
+
+ DBusMessageIter subIter;
+ dbus_bool_t ret = dbus_message_iter_open_container(&iter,
+ DBUS_TYPE_ARRAY,
+ DBUS_TYPE_STRING_AS_STRING,
+ &subIter);
+ RUNNER_ASSERT_MSG(ret != FALSE, "Failed to open container. Not enough memory");
+ for (const auto &str : strs) {
+ const char *cstr = str.c_str();
+ ret = dbus_message_iter_append_basic(&subIter, DBUS_TYPE_STRING, &cstr);
+ if (ret == FALSE) {
+ dbus_message_iter_abandon_container(&iter, &subIter);
+ RUNNER_FAIL_MSG("Failed to append basic string. Not enough memory");
+ }
+ }
+ ret = dbus_message_iter_close_container(&iter, &subIter);
+ RUNNER_ASSERT_MSG(ret != FALSE, "Failed to close container. Not enough memory");
+}
+
+} // namespace DBus
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file dbus_message_out.h
+ * @author Marcin Niesluchowski (m.niesluchow@samsung.com)
+ * @version 1.0
+ * @brief DBus outgoing message wrapper class header
+ */
+
+#ifndef COMMON_DBUS_MESSAGE_OUT_H
+#define COMMON_DBUS_MESSAGE_OUT_H
+
+#include <dbus/dbus.h>
+
+#include <string>
+#include <vector>
+
+namespace DBus
+{
+
+class MessageOut
+{
+public:
+ MessageOut(const std::string &destination,
+ const std::string &path,
+ const std::string &interface,
+ const std::string &method);
+ MessageOut(const MessageOut &other) = delete;
+ MessageOut(MessageOut &&other);
+ ~MessageOut();
+
+ MessageOut& operator=(const MessageOut &other) = delete;
+
+ DBusMessage* getMessage() const;
+
+ void append(bool b);
+ void append(const char *cstr);
+ void append(const std::string &str);
+ void append(const std::vector<std::string> &strs);
+
+private:
+ DBusMessage *m_message;
+};
+
+} // namespace DBus
+
+#endif // COMMON_DBUS_MESSAGE_OUT_H