--- /dev/null
+/*
+ * Copyright (c) 2015 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_test_service_object.cpp
+ * @author Marcin Niesluchowski <m.niesluchow@samsungcom>
+ * @version 1.0
+ * @brief Definition of dbus test service object class for handling
+ * incoming messages
+ */
+
+#include <dbus_test_service_object.h>
+
+namespace DBusTest
+{
+
+ServiceObject::ServiceObject(const std::string &interface)
+ : m_interface(interface)
+{
+}
+
+const std::string& ServiceObject::interface() const
+{
+ return m_interface;
+}
+
+void ServiceObject::insertMethodHandler(const std::string &method,
+ const MessageHandler &messageHandler)
+{
+ m_methodHandlers[method] = messageHandler;
+}
+
+void ServiceObject::handleMessage(DBus::Connection &connection,
+ DBus::MessageIn &messageIn,
+ std::string &errorStr)
+{
+ for (auto &methodHandler : m_methodHandlers) {
+ if (messageIn.isMethodCall(m_interface, methodHandler.first)) {
+ methodHandler.second(connection, messageIn, errorStr);
+ return;
+ }
+ }
+ errorStr = "Received unregistered message";
+}
+
+} // namespace DBusTest
--- /dev/null
+/*
+ * Copyright (c) 2015 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_test_service_object.h
+ * @author Marcin Niesluchowski <m.niesluchow@samsungcom>
+ * @version 1.0
+ * @brief Declaration of dbus test service object class for handling
+ * incoming messages
+ */
+
+#ifndef DBUS_TESTS_COMMON_DBUS_TEST_SERVICE_OBJECT_H
+#define DBUS_TESTS_COMMON_DBUS_TEST_SERVICE_OBJECT_H
+
+#include <dbus_connection.h>
+#include <dbus_message_in.h>
+
+#include <functional>
+#include <map>
+#include <string>
+
+namespace DBusTest
+{
+
+using MessageHandler = std::function<void(DBus::Connection &connection,
+ DBus::MessageIn &messageIn,
+ std::string &errorStr)>;
+
+class ServiceObject
+{
+public:
+ ServiceObject(const std::string &interface);
+ ServiceObject(const ServiceObject &other) = delete;
+ ~ServiceObject() = default;
+
+ ServiceObject& operator=(const ServiceObject &other) = delete;
+
+ const std::string& interface() const;
+ void insertMethodHandler(const std::string &method,
+ const MessageHandler &messageHandler);
+ void handleMessage(DBus::Connection &connection,
+ DBus::MessageIn &messageIn,
+ std::string &errorStr);
+
+private:
+ std::map<std::string, MessageHandler> m_methodHandlers;
+ std::string m_interface;
+};
+
+} // namespace DBusTest
+
+#endif // DBUS_TESTS_COMMON_DBUS_TEST_SERVICE_OBJECT_H