Start&stop support added to DBusAccess
[platform/core/test/security-tests.git] / tests / common / dbus_access.cpp
1 /*
2  * Copyright (c) 2013-2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Bumjin Im <bj.im@samsung.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *   http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18 /*
19  * @file        dbus_access.cpp
20  * @author      Zbigniew Jasinski (z.jasinski@samsung.com)
21  * @version     1.0
22  * @brief       Functios used in security-tests package for restarting Security Server through
23  *              SystemD DBuS interface.
24  */
25
26 #include <dbus_access.h>
27 #include <dbus_access_impl.h>
28
29 namespace {
30 const char* const RESTART = "Restart";
31 const char* const STOP = "Stop";
32 const char* const START = "Start";
33 const char* const RESET_FAILED = "ResetFailed";
34
35 const char* const MODE_FAIL = "fail";
36
37 } // anonymous namespace
38
39 DBusAccess::DBusAccess(const char* const object)
40 {
41     m_impl.reset(new DBusAccess::Impl(object));
42 }
43
44 DBusAccess::~DBusAccess()
45 {
46 }
47
48 void DBusAccess::restart() {
49     /*
50      * Example:
51      * dbus-send --system --dest=org.freedesktop.systemd1 --print-reply
52      *  /org/freedesktop/systemd1/unit/central_2dkey_2dmanager_2eservice
53      *  org.freedesktop.systemd1.Unit.Restart string:fail
54      */
55     m_impl->newMethodCall(RESTART);
56     m_impl->setMode(MODE_FAIL);
57     m_impl->sendCommand();
58
59     m_impl->waitForJobEnd();
60
61     sendResetFailed();
62 }
63
64 void DBusAccess::start() {
65     m_impl->newMethodCall(START);
66     m_impl->setMode(MODE_FAIL);
67     m_impl->sendCommand();
68
69     m_impl->waitForJobEnd();
70
71     sendResetFailed();
72 }
73
74 void DBusAccess::stop() {
75     m_impl->newMethodCall(STOP);
76     m_impl->setMode(MODE_FAIL);
77     m_impl->sendCommand();
78
79     m_impl->waitForJobEnd();
80
81     sendResetFailed();
82 }
83
84 void DBusAccess::sendResetFailed() {
85     m_impl->newMethodCall(RESET_FAILED);
86     m_impl->sendCommand(false);
87 }