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
diff --git a/meta-ivi-common/recipes-automotive/automotive-message-broker/automotive-message-broker/amb_allow_sessionbus.patch b/meta-ivi-common/recipes-automotive/automotive-message-broker/automotive-message-broker/amb_allow_sessionbus.patch
new file mode 100644 (file)
index 0000000..d9b77c8
--- /dev/null
@@ -0,0 +1,124 @@
+diff --git a/plugins/dbus/abstractdbusinterface.cpp b/plugins/dbus/abstractdbusinterface.cpp
+index 9dd8566..19ef606 100644
+--- a/plugins/dbus/abstractdbusinterface.cpp
++++ b/plugins/dbus/abstractdbusinterface.cpp
+@@ -17,6 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+ #include "abstractdbusinterface.h"
++#include "dbusplugin.h"
+ #include <abstractroutingengine.h>
+ #include <debugout.h>
+@@ -37,7 +38,7 @@ list<string> AbstractDBusInterface::mimplementedProperties;
+ const uint getPid(const char *owner)
+ {
+       GError* error = nullptr;
+-      GDBusProxy* dbus = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
++      GDBusProxy* dbus = g_dbus_proxy_new_for_bus_sync(bustype, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                                                                                                        "org.freedesktop.DBus",
+                                                                                                        "/",
+                                                                                                        "org.freedesktop.DBus",
+diff --git a/plugins/dbus/automotivemanager.cpp b/plugins/dbus/automotivemanager.cpp
+index b5fb149..edbe1bd 100644
+--- a/plugins/dbus/automotivemanager.cpp
++++ b/plugins/dbus/automotivemanager.cpp
+@@ -1,3 +1,4 @@
++#include "dbusplugin.h"
+ #include "automotivemanager.h"
+ #include "abstractdbusinterface.h"
+ #include "listplusplus.h"
+@@ -341,7 +342,7 @@ static void signalCallback( GDBusConnection *connection,
+                       AbstractDBusInterface* iface = i.first;
+                       for(auto n : i.second)
+                       {
+-                              if(n == name)
++                              if(n == name && !persistent)
+                               {
+                                       DebugOut()<<"unreferencing "<<n<<" from the subscription of "<<iface->objectPath()<<endl;
+                                       manager->subscribedProcesses[iface].remove(n);
+@@ -398,7 +399,7 @@ AutomotiveManager::AutomotiveManager(GDBusConnection *connection)
+       g_assert(regId > 0);
+-      g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL,NULL), "org.freedesktop.DBus", "org.freedesktop.DBus",
++      g_dbus_connection_signal_subscribe(g_bus_get_sync(bustype, NULL,NULL), "org.freedesktop.DBus", "org.freedesktop.DBus",
+                                                                                                                                                                          "NameOwnerChanged", "/org/freedesktop/DBus", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                                                                                                          signalCallback, this, NULL);
+ }
+diff --git a/plugins/dbus/dbusinterfacemanager.cpp b/plugins/dbus/dbusinterfacemanager.cpp
+index 0c8a645..07e6786 100644
+--- a/plugins/dbus/dbusinterfacemanager.cpp
++++ b/plugins/dbus/dbusinterfacemanager.cpp
+@@ -236,7 +236,7 @@ on_name_lost (GDBusConnection *connection, const gchar *name, gpointer user_data
+ DBusInterfaceManager::DBusInterfaceManager(AbstractRoutingEngine* engine,std::map<std::string,std::string> config)
+       :AbstractSink(engine,config),re(engine), connection(nullptr)
+ {
+-      ownerId = g_bus_own_name(G_BUS_TYPE_SYSTEM,
++      ownerId = g_bus_own_name(bustype,
+                                       DBusServiceName,
+                                       G_BUS_NAME_OWNER_FLAGS_NONE,
+                                       on_bus_acquired,
+diff --git a/plugins/dbus/dbusplugin.cpp b/plugins/dbus/dbusplugin.cpp
+index 7fa31c1..0b75d69 100644
+--- a/plugins/dbus/dbusplugin.cpp
++++ b/plugins/dbus/dbusplugin.cpp
+@@ -24,8 +24,21 @@
+ #include "debugout.h"
+ #include "listplusplus.h"
++bool persistent=false;
++GBusType bustype=G_BUS_TYPE_SYSTEM;
++
+ extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, map<string, string> config)
+ {
++      if(config.find("sessionbus") != config.end())
++        {
++              bustype=G_BUS_TYPE_SESSION;
++        }
++
++      if(config.find("persistent") != config.end())
++        {
++              persistent=true;
++        }
++
+       return new DBusSinkManager(routingengine, config);
+ }
+diff --git a/plugins/dbus/dbusplugin.h b/plugins/dbus/dbusplugin.h
+index 337f2f6..92e6255 100644
+--- a/plugins/dbus/dbusplugin.h
++++ b/plugins/dbus/dbusplugin.h
+@@ -29,6 +29,9 @@
+ typedef std::map<VehicleProperty::Property, VariantType*> PropertyDBusMap;
++extern GBusType bustype;
++extern bool persistent;
++
+ class DBusSink : public AbstractSink, public AbstractDBusInterface
+ {
+diff --git a/tests/amb-get b/tests/amb-get
+index 0835a64..7fb48ea 100755
+--- a/tests/amb-get
++++ b/tests/amb-get
+@@ -5,12 +5,17 @@ import sys
+ import argparse
+ parser = argparse.ArgumentParser()
++parser.add_argument("--sessionbus", help="use session bus", action='store_true')
+ parser.add_argument("get", help="get {objectName}")
+ args = parser.parse_args()
+ objectName = args.get
+-bus = dbus.SystemBus()
++if (args.sessionbus):
++      bus = dbus.SessionBus()
++else:
++      bus = dbus.SystemBus()
++
+ managerObject = bus.get_object("org.automotive.message.broker", "/");
+ managerInterface = dbus.Interface(managerObject, "org.automotive.Manager")