/*
- * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2013-2014 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Bumjin Im <bj.im@samsung.com>
*
*/
/*
* @file dbus_access.cpp
- * @author Zbigniew Jasinski (z.jasinski@samsung.com)
- * @version 1.0
- * @brief Functios used in security-tests package for restarting Security Server through
- * SystemD DBuS interface.
+ * @author Zbigniew Jasinski <z.jasinski@samsung.com>
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version 1.1
+ * @brief Implementation of SystemD control class over dbus API
*/
#include <dpl/log/log.h>
: m_conn(nullptr)
, m_msg(nullptr)
, m_pending(nullptr)
- , m_handled(FALSE)
+ , m_dbus_client_name("tests.dbus.client")
+ , m_service_name(service_name)
+ , m_dbus_systemd_destination("org.freedesktop.systemd1")
+ , m_dbus_systemd_path("/org/freedesktop/systemd1")
+ , m_dbus_systemd_manager_interface("org.freedesktop.systemd1.Manager")
{
dbus_error_init(&m_err);
-
- m_signal_type = "signal";
- m_signal_interface = "org.freedesktop.systemd1.Manager";
- m_signal_member = "JobRemoved";
- m_signal_path = "/org/freedesktop/systemd1";
-
- m_signal_match = "type='" + m_signal_type + "',interface='" + m_signal_interface +
- "',member='" + m_signal_member + "',path='" + m_signal_path + "'";
-
- m_dbus_client_name = "tests.dbus.client";
-
- m_service_name = service_name;
-
connectToDBus();
}
}
void DBusAccess::newMethodCall(const char *method) {
- const std::string dbus_systemd_name = "org.freedesktop.systemd1";
- const std::string dbus_systemd_object = "/org/freedesktop/systemd1";
- const std::string dbus_systemd_interface = "org.freedesktop.systemd1.Manager";
- m_msg = dbus_message_new_method_call(dbus_systemd_name.c_str(),
- dbus_systemd_object.c_str(),
- dbus_systemd_interface.c_str(),
+ m_msg = dbus_message_new_method_call(m_dbus_systemd_destination.c_str(),
+ m_dbus_systemd_path.c_str(),
+ m_dbus_systemd_manager_interface.c_str(),
method);
RUNNER_ASSERT_MSG(nullptr != m_msg,
"Error in dbus_message_new_method_call");
"Error in dbus_pending_call_steal_reply");
}
-void DBusAccess::handleMsgReply() {
+std::string DBusAccess::handleObjectPathMsgReply() {
DBusMessageIter iter;
RUNNER_ASSERT_MSG(dbus_message_iter_init(m_msg, &iter) != 0,
"Message has no arguments");
if (DBUS_TYPE_OBJECT_PATH != dbus_message_iter_get_arg_type(&iter)) {
- RUNNER_FAIL_MSG("No job path in msg");
+ RUNNER_FAIL_MSG("Object path type expected");
}
+ char *tmp;
+ dbus_message_iter_get_basic(&iter, &tmp);
+ std::string ret(tmp);
+
+ finalizeMsgReply();
+ return ret;
+}
+
+void DBusAccess::finalizeMsgReply() {
dbus_message_unref(m_msg);
dbus_pending_call_unref(m_pending);
m_msg = nullptr;
appendToMsg("fail");
sendMsgWithReply();
getMsgReply();
- handleMsgReply();
+ handleObjectPathMsgReply();
usleep(50000);
}
appendToMsg(m_service_name.c_str());
sendMsgWithReply();
getMsgReply();
+ ignoreMsgReply();
}
void DBusAccess::startService() {
/*
- * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2013-2014 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Bumjin Im <bj.im@samsung.com>
*
*/
/*
* @file dbus_access.h
- * @author Zbigniew Jasinski (z.jasinski@samsung.com)
- * @version 1.0
- * @brief Starts, stops or restarts services (e.g. security-server.service)
- * using dbus interface to communicate with systemd.
+ * @author Zbigniew Jasinski <z.jasinski@samsung.com>
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version 1.1
+ * @brief System service control class using dbus interface to communicate with systemd
*/
#ifndef _DBUS_ACCESS_H_
#define _DBUS_ACCESS_H_
void appendToMsg(const char *argument);
void sendMsgWithReply();
void getMsgReply();
- void handleMsgReply();
+ std::string handleObjectPathMsgReply();
+ void finalizeMsgReply();
void connectToDBus();
- void sendGetUnitToSystemd(const char *service_name);
void sendToService(const char *method);
void sendResetFailedToService();
DBusError m_err;
DBusPendingCall *m_pending;
- std::string m_signal_type;
- std::string m_signal_interface;
- std::string m_signal_member;
- std::string m_signal_path;
+ const std::string m_dbus_client_name;
+ const std::string m_service_name;
- std::string m_signal_match;
-
- std::string m_dbus_client_name;
-
- std::string m_service_name;
-
- bool m_handled;
+ const std::string m_dbus_systemd_destination;
+ const std::string m_dbus_systemd_path;
+ const std::string m_dbus_systemd_manager_interface;
};
#endif // _DBUS_ACCESS_H_