tizen 2.4 release
[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 class Connection;
34
35 /**
36  * Represents a remote object attached to a DBus service.
37  */
38 class ObjectProxy
39 {
40   public:
41     ~ObjectProxy();
42
43     /**
44      * Creates method proxy object.
45      *
46      * The object is used to call remote methods.
47      *
48      * @param interface Name of the DBus interface.
49      * @param name Name of the method to call.
50      * @return Proxy to remote method.
51      * @throw DBus::ConnectionClosedException If connection is closed.
52      */
53     template<typename Result, typename ... Args>
54     MethodProxyPtr<Result, Args ...> createMethodProxy(
55         const std::string& interface,
56         const std::string& name)
57     {
58         if (g_dbus_connection_is_closed(m_connection)) {
59             ThrowMsg(DBus::ConnectionClosedException, "Connection closed.");
60         }
61
62         return MethodProxyPtr<Result, Args ...>(
63                    new MethodProxy<Result, Args ...>(m_connection,
64                                                      m_serviceName,
65                                                      m_objectPath,
66                                                      interface,
67                                                      name));
68     }
69
70   private:
71     friend class Connection;
72
73     ObjectProxy(GDBusConnection* connection,
74                 const std::string& serviceName,
75                 const std::string& objectPath);
76
77     GDBusConnection* m_connection;
78     std::string m_serviceName;
79     std::string m_objectPath;
80 };
81 }
82 }
83
84 #endif