Main page in Markdown format
[platform/core/security/vasum.git] / zone-daemon / daemon-connection.hpp
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Jan Olszak <j.olszak@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 /**
20  * @file
21  * @author  Jan Olszak (j.olszak@samsung.com)
22  * @brief   Declaration of a class for communication between zone and server
23  */
24
25
26 #ifndef ZONE_DAEMON_DAEMON_CONNECTION_HPP
27 #define ZONE_DAEMON_DAEMON_CONNECTION_HPP
28
29 #include "dbus/connection.hpp"
30
31 #include <mutex>
32 #include <condition_variable>
33
34
35 namespace vasum {
36 namespace zone_daemon {
37
38
39 class DaemonConnection {
40
41 public:
42     typedef std::function<void()> NameLostCallback;
43     typedef std::function<void()> GainFocusCallback;
44     typedef std::function<void()> LoseFocusCallback;
45
46     DaemonConnection(const NameLostCallback&  nameLostCallback,
47                      const GainFocusCallback& gainFocusCallback,
48                      const LoseFocusCallback& loseFocusCallback);
49     ~DaemonConnection();
50
51
52 private:
53     dbus::DbusConnection::Pointer mDbusConnection;
54     std::mutex mNameMutex;
55     std::condition_variable mNameCondition;
56     bool mNameAcquired;
57     bool mNameLost;
58
59     NameLostCallback  mNameLostCallback;
60     GainFocusCallback mGainFocusCallback;
61     LoseFocusCallback mLoseFocusCallback;
62
63     void onNameAcquired();
64     void onNameLost();
65     bool waitForNameAndSetCallback(const unsigned int timeoutMs, const NameLostCallback& callback);
66
67     void onMessageCall(const std::string& objectPath,
68                        const std::string& interface,
69                        const std::string& methodName,
70                        GVariant* parameters,
71                        dbus::MethodResultBuilder::Pointer result);
72 };
73
74
75 } // namespace zone_daemon
76 } // namespace vasum
77
78
79 #endif // ZONE_DAEMON_DAEMON_CONNECTION_HPP