only export dbus properties that are supported
[profile/ivi/automotive-message-broker.git] / plugins / dbus / abstractdbusinterface.h
1 /*
2 Copyright (C) 2012 Intel Corporation
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19 #ifndef ABSTRACTDBUSINTERFACE_H
20 #define ABSTRACTDBUSINTERFACE_H
21
22 #include <string>
23 #include <functional>
24 #include <unordered_map>
25 #include <gio/gio.h>
26 #include <boost/any.hpp>
27 #include <nullptr.h>
28
29 class AbstractProperty;
30
31 using namespace std;
32
33 class AbstractDBusInterface
34 {
35
36 public:
37         AbstractDBusInterface(string interfaceName, string objectPath, GDBusConnection* connection);
38
39         
40         void setDBusConnection(GDBusConnection* connection)
41         {
42                 mConnection = connection;
43         }
44
45         void registerObject();
46         void unregisterObject();
47         
48         void addProperty(AbstractProperty* property);
49         virtual void updateValue(AbstractProperty* property);
50         
51 protected:
52
53         void startRegistration();
54         
55         static GVariant *getProperty(GDBusConnection * connection, const gchar * sender, const gchar *objectPath,
56                                                                  const gchar *interfaceName, const gchar * propertyName, GError** error,
57                                                                  gpointer userData);
58         static gboolean setProperty(GDBusConnection * connection, const gchar * sender, const gchar *objectPath,
59                                                                 const gchar *interfaceName, const gchar * propertyName, GVariant *value,
60                                                                 GError** error, gpointer userData);
61     
62         virtual void setProperty(string propertyName, GVariant * value);
63         virtual GVariant * getProperty(string propertyName);
64         
65         unordered_map<string, AbstractProperty*> properties;
66
67 private:
68         string mInterfaceName;
69         string mObjectPath;
70         string introspectionXml;
71         GDBusConnection * mConnection;
72         static unordered_map<string, AbstractDBusInterface*> interfaceMap;
73         guint regId;
74 };
75
76 #endif // ABSTRACTDBUSINTERFACE_H