3d727c0ee9ba192d77477b8c06d3785295cbf111
[platform/framework/web/wrt-commons.git] / modules / dbus / include / dpl / dbus / object_proxy.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file    object_proxy.h
18  * @author  Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
19  * @version 1.0
20  * @brief
21  */
22
23 #ifndef DPL_DBUS_OBJECT_PROXY_H
24 #define DPL_DBUS_OBJECT_PROXY_H
25
26 #include <string>
27 #include <gio/gio.h>
28 #include <dpl/dbus/exception.h>
29 #include <dpl/dbus/method_proxy.h>
30
31 namespace DPL {
32 namespace DBus {
33
34 class Connection;
35
36 /**
37  * Represents a remote object attached to a DBus service.
38  */
39 class ObjectProxy
40 {
41 public:
42     ~ObjectProxy();
43
44     /**
45      * Creates method proxy object.
46      *
47      * The object is used to call remote methods.
48      *
49      * @param interface Name of the DBus interface.
50      * @param name Name of the method to call.
51      * @return Proxy to remote method.
52      * @throw DBus::ConnectionClosedException If connection is closed.
53      */
54     template<typename Result, typename ...Args>
55     MethodProxyPtr<Result, Args...> createMethodProxy(
56             const std::string& interface,
57             const std::string& name)
58     {
59         if (g_dbus_connection_is_closed(m_connection))
60         {
61             ThrowMsg(DBus::ConnectionClosedException, "Connection closed.");
62         }
63
64         return MethodProxyPtr<Result, Args...>(
65                 new MethodProxy<Result, Args...>(m_connection,
66                                                  m_serviceName,
67                                                  m_objectPath,
68                                                  interface,
69                                                  name));
70     }
71
72 private:
73     friend class Connection;
74
75     ObjectProxy(GDBusConnection* connection,
76                 const std::string& serviceName,
77                 const std::string& objectPath);
78
79     GDBusConnection* m_connection;
80     std::string m_serviceName;
81     std::string m_objectPath;
82 };
83
84 }
85 }
86
87 #endif