Access control tests
[platform/core/test/security-tests.git] / tests / common / dbus_access.h
1 /*
2  * Copyright (c) 2013 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.h
20  * @author      Zbigniew Jasinski (z.jasinski@samsung.com)
21  * @version     1.0
22  * @brief       Starts, stops or restarts services (e.g. security-server.service)
23  *              using dbus interface to communicate with systemd.
24  */
25 #ifndef _DBUS_ACCESS_H_
26 #define _DBUS_ACCESS_H_
27
28 #include <dbus/dbus.h>
29 #include <dbus-glib.h>
30 #include <glib-object.h>
31
32 #include <string>
33
34 class DBusAccess {
35 public:
36     DBusAccess() = delete;
37     DBusAccess(const char *service_name);
38
39     void startService();
40     void stopService();
41     void restartService();
42
43     virtual ~DBusAccess();
44 private:
45     void connect();
46     void requestName();
47     void newMethodCall(const char *method);
48     void appendToMsg(const char *argument);
49     void sendMsgWithReply();
50     void getMsgReply();
51     void handleMsgReply();
52
53     void connectToDBus();
54     void sendGetUnitToSystemd(const char *service_name);
55     void sendToService(const char *method);
56     void sendResetFailedToService();
57
58     DBusConnection *m_conn;
59     DBusMessage *m_msg;
60     DBusError m_err;
61     DBusPendingCall *m_pending;
62
63     std::string m_signal_type;
64     std::string m_signal_interface;
65     std::string m_signal_member;
66     std::string m_signal_path;
67
68     std::string m_signal_match;
69
70     std::string m_dbus_client_name;
71
72     std::string m_service_name;
73
74     bool m_handled;
75 };
76
77 #endif // _DBUS_ACCESS_H_