Added AMB (automotive-message-broker) to meta-ivi-common layer
[AGL/meta-agl.git] / meta-ivi-common / recipes-automotive / automotive-message-broker / automotive-message-broker / amb_allow_sessionbus.patch
1 diff --git a/plugins/dbus/abstractdbusinterface.cpp b/plugins/dbus/abstractdbusinterface.cpp
2 index 9dd8566..19ef606 100644
3 --- a/plugins/dbus/abstractdbusinterface.cpp
4 +++ b/plugins/dbus/abstractdbusinterface.cpp
5 @@ -17,6 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
6  */
7  
8  #include "abstractdbusinterface.h"
9 +#include "dbusplugin.h"
10  
11  #include <abstractroutingengine.h>
12  #include <debugout.h>
13 @@ -37,7 +38,7 @@ list<string> AbstractDBusInterface::mimplementedProperties;
14  const uint getPid(const char *owner)
15  {
16         GError* error = nullptr;
17 -       GDBusProxy* dbus = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
18 +       GDBusProxy* dbus = g_dbus_proxy_new_for_bus_sync(bustype, G_DBUS_PROXY_FLAGS_NONE, NULL,
19                                                                                                          "org.freedesktop.DBus",
20                                                                                                          "/",
21                                                                                                          "org.freedesktop.DBus",
22 diff --git a/plugins/dbus/automotivemanager.cpp b/plugins/dbus/automotivemanager.cpp
23 index b5fb149..edbe1bd 100644
24 --- a/plugins/dbus/automotivemanager.cpp
25 +++ b/plugins/dbus/automotivemanager.cpp
26 @@ -1,3 +1,4 @@
27 +#include "dbusplugin.h"
28  #include "automotivemanager.h"
29  #include "abstractdbusinterface.h"
30  #include "listplusplus.h"
31 @@ -341,7 +342,7 @@ static void signalCallback( GDBusConnection *connection,
32                         AbstractDBusInterface* iface = i.first;
33                         for(auto n : i.second)
34                         {
35 -                               if(n == name)
36 +                               if(n == name && !persistent)
37                                 {
38                                         DebugOut()<<"unreferencing "<<n<<" from the subscription of "<<iface->objectPath()<<endl;
39                                         manager->subscribedProcesses[iface].remove(n);
40 @@ -398,7 +399,7 @@ AutomotiveManager::AutomotiveManager(GDBusConnection *connection)
41  
42         g_assert(regId > 0);
43  
44 -       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL,NULL), "org.freedesktop.DBus", "org.freedesktop.DBus",
45 +       g_dbus_connection_signal_subscribe(g_bus_get_sync(bustype, NULL,NULL), "org.freedesktop.DBus", "org.freedesktop.DBus",
46                                                                                                                                                                            "NameOwnerChanged", "/org/freedesktop/DBus", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
47                                                                                                                                                                            signalCallback, this, NULL);
48  }
49 diff --git a/plugins/dbus/dbusinterfacemanager.cpp b/plugins/dbus/dbusinterfacemanager.cpp
50 index 0c8a645..07e6786 100644
51 --- a/plugins/dbus/dbusinterfacemanager.cpp
52 +++ b/plugins/dbus/dbusinterfacemanager.cpp
53 @@ -236,7 +236,7 @@ on_name_lost (GDBusConnection *connection, const gchar *name, gpointer user_data
54  DBusInterfaceManager::DBusInterfaceManager(AbstractRoutingEngine* engine,std::map<std::string,std::string> config)
55         :AbstractSink(engine,config),re(engine), connection(nullptr)
56  {
57 -       ownerId = g_bus_own_name(G_BUS_TYPE_SYSTEM,
58 +       ownerId = g_bus_own_name(bustype,
59                                         DBusServiceName,
60                                         G_BUS_NAME_OWNER_FLAGS_NONE,
61                                         on_bus_acquired,
62 diff --git a/plugins/dbus/dbusplugin.cpp b/plugins/dbus/dbusplugin.cpp
63 index 7fa31c1..0b75d69 100644
64 --- a/plugins/dbus/dbusplugin.cpp
65 +++ b/plugins/dbus/dbusplugin.cpp
66 @@ -24,8 +24,21 @@
67  #include "debugout.h"
68  #include "listplusplus.h"
69  
70 +bool persistent=false;
71 +GBusType bustype=G_BUS_TYPE_SYSTEM;
72 +
73  extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, map<string, string> config)
74  {
75 +       if(config.find("sessionbus") != config.end())
76 +        {
77 +               bustype=G_BUS_TYPE_SESSION;
78 +        }
79 +
80 +       if(config.find("persistent") != config.end())
81 +        {
82 +               persistent=true;
83 +        }
84 +
85         return new DBusSinkManager(routingengine, config);
86  }
87  
88 diff --git a/plugins/dbus/dbusplugin.h b/plugins/dbus/dbusplugin.h
89 index 337f2f6..92e6255 100644
90 --- a/plugins/dbus/dbusplugin.h
91 +++ b/plugins/dbus/dbusplugin.h
92 @@ -29,6 +29,9 @@
93  
94  typedef std::map<VehicleProperty::Property, VariantType*> PropertyDBusMap;
95  
96 +extern GBusType bustype;
97 +extern bool persistent;
98 +
99  class DBusSink : public AbstractSink, public AbstractDBusInterface
100  {
101  
102 diff --git a/tests/amb-get b/tests/amb-get
103 index 0835a64..7fb48ea 100755
104 --- a/tests/amb-get
105 +++ b/tests/amb-get
106 @@ -5,12 +5,17 @@ import sys
107  import argparse
108  
109  parser = argparse.ArgumentParser()
110 +parser.add_argument("--sessionbus", help="use session bus", action='store_true')
111  parser.add_argument("get", help="get {objectName}")
112  args = parser.parse_args()
113  
114  objectName = args.get
115  
116 -bus = dbus.SystemBus()
117 +if (args.sessionbus):
118 +       bus = dbus.SessionBus()
119 +else:
120 +       bus = dbus.SystemBus()
121 +
122  managerObject = bus.get_object("org.automotive.message.broker", "/");
123  managerInterface = dbus.Interface(managerObject, "org.automotive.Manager")
124