publish all uncategorized properties on the bus
authorKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 15 May 2013 22:21:41 +0000 (15:21 -0700)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 15 May 2013 22:21:41 +0000 (15:21 -0700)
plugins/dbus/CMakeLists.txt
plugins/dbus/abstractdbusinterface.cpp
plugins/dbus/abstractdbusinterface.h
plugins/dbus/amb.conf
plugins/dbus/dbusinterfacemanager.cpp
plugins/dbus/dbusplugin.h
plugins/dbus/uncategorizedproperty.cpp [new file with mode: 0644]
plugins/dbus/uncategorizedproperty.h [new file with mode: 0644]
plugins/exampleplugin.cpp

index 5b36547..05535e8 100644 (file)
@@ -4,9 +4,9 @@ include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs})
 pkg_check_modules(gio REQUIRED gio-2.0)
 
 set(dbussinkplugin_headers dbusplugin.h abstractproperty.h abstractdbusinterface.h dbusinterfacemanager.h basicproperty.h runningstatus.h varianttype.h
-custompropertyinterface.h environmentproperties.h vehicleinfo.h maintenance.h parking.h fakeidlheader.h drivingsafety.h)
+custompropertyinterface.h uncategorizedproperty.h environmentproperties.h vehicleinfo.h maintenance.h parking.h fakeidlheader.h drivingsafety.h)
 set(dbussinkplugin_sources dbusplugin.cpp abstractproperty.cpp abstractdbusinterface.cpp dbusinterfacemanager.cpp basicproperty.cpp runningstatus.cpp
-varianttype.cpp custompropertyinterface.cpp environmentproperties.cpp vehicleinfo.cpp maintenance.cpp parking.cpp drivingsafety.cpp)
+varianttype.cpp custompropertyinterface.cpp uncategorizedproperty.cpp environmentproperties.cpp vehicleinfo.cpp maintenance.cpp parking.cpp drivingsafety.cpp)
 
 add_library(dbussinkplugin MODULE ${dbussinkplugin_sources})
 set_target_properties(dbussinkplugin PROPERTIES PREFIX "")
index 789af5a..08b8031 100644 (file)
@@ -21,9 +21,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 #include <boost/algorithm/string.hpp>
 #include <gio/gio.h>
 
+#include "listplusplus.h"
 #include "abstractproperty.h"
 
 unordered_map<string, AbstractDBusInterface*> AbstractDBusInterface::interfaceMap;
+list<string> AbstractDBusInterface::mimplementedProperties;
 
 AbstractDBusInterface::AbstractDBusInterface(string interfaceName, string objectPath,
                                                                                         GDBusConnection* connection)
@@ -56,6 +58,11 @@ void AbstractDBusInterface::addProperty(AbstractProperty* property)
        "</signal>";
        
        properties[property->name()] = property;
+
+       if(!ListPlusPlus<string>(&mimplementedProperties).contains(property->name()))
+       {
+               mimplementedProperties.push_back(property->name());
+       }
 }
 
 void AbstractDBusInterface::registerObject()
index 9fea6cd..db56219 100644 (file)
@@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 #include <string>
 #include <functional>
 #include <unordered_map>
+#include <list>
 #include <gio/gio.h>
 #include <boost/any.hpp>
 #include <nullptr.h>
@@ -48,6 +49,8 @@ public:
        void addProperty(AbstractProperty* property);
        virtual void updateValue(AbstractProperty* property);
        
+       static list<string> implementedProperties() { return mimplementedProperties; }
+
 protected:
 
        void startRegistration();
@@ -70,6 +73,7 @@ private:
        string introspectionXml;
        GDBusConnection * mConnection;
        static unordered_map<string, AbstractDBusInterface*> interfaceMap;
+       static list<string> mimplementedProperties;
        guint regId;
 };
 
index e91f788..42f962c 100644 (file)
@@ -3,9 +3,17 @@
 <busconfig>
 
   <policy context="default">
-    <!-- <deny send_destination="org.automotive.message.broker"/> -->
+    <allow own="org.automotive.message.broker"/>
     <allow send_destination="org.automotive.message.broker"/>
-       <allow own="org.automotive.message.broker"/>
+
+    <!-- Example: in the default context, this interface is denied write control -->
+    <deny send_destination="org.automotive.message.broker" send_interface="org.automotive.MachineGunTurretStatus" />
+
   </policy>
 
+  <!-- Example: the following is an example on how a specific interface can be protected using SMACK 
+  <policy smack="allow_write_machinegun" >
+    <allow send_desination="org.automotive.message.broker" send_interface="org.automotive.MachineGunTurret" />
+  </policy>  -->
+
 </busconfig>
index 1103cb3..4544453 100644 (file)
@@ -22,10 +22,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 #include <gio/gio.h>
 #include <string>
 
+#include "listplusplus.h"
+
 ///properties:
 #include "accelerationproperty.h"
 #include "runningstatus.h"
 #include "custompropertyinterface.h"
+#include "uncategorizedproperty.h"
 #include "environmentproperties.h"
 #include "vehicleinfo.h"
 #include "maintenance.h"
@@ -98,6 +101,22 @@ on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_d
        }
 
 
+       /// Create objects for unimplemented properties:
+
+       PropertyList capabilitiesList = VehicleProperty::capabilities();
+
+       for (auto itr = capabilitiesList.begin(); itr != capabilitiesList.end(); itr++)
+       {
+               VehicleProperty::Property prop = *itr;
+
+               PropertyList implemented = AbstractDBusInterface::implementedProperties();
+
+               if(!ListPlusPlus<VehicleProperty::Property>(&implemented).contains(prop))
+               {
+                       new UncategorizedPropertyInterface(prop, iface->re, connection);
+               }
+       }
+
 }
 
 static void
@@ -110,6 +129,12 @@ static void
 on_name_lost (GDBusConnection *connection, const gchar *name, gpointer user_data)
 {
 
+       DebugOut(0)<<"DBus: Lost bus name"<<endl;
+
+       if(!connection){
+               DebugOut(0)<<"DBus: Connection could not be established."<<endl;
+               throw std::runtime_error("Could not establish DBus connection.");
+       }
 }
 
 
index 5cc44dd..600e5da 100644 (file)
@@ -58,6 +58,7 @@ protected:
        }
 
        PropertyDBusMap propertyDBusMap;
+
 private:
 
        bool supported;
diff --git a/plugins/dbus/uncategorizedproperty.cpp b/plugins/dbus/uncategorizedproperty.cpp
new file mode 100644 (file)
index 0000000..fdbbe8b
--- /dev/null
@@ -0,0 +1,23 @@
+#include "uncategorizedproperty.h"
+#include "vehicleproperty.h"
+#include "varianttype.h"
+#include "listplusplus.h"
+
+UncategorizedPropertyInterface::UncategorizedPropertyInterface(VehicleProperty::Property prop, AbstractRoutingEngine *re, GDBusConnection *connection)
+       :DBusSink("org.automotive."+prop,"/org/automotive/uncategorized/"+prop, re, connection, map<string, string>())
+{
+       AbstractPropertyType* temp = VehicleProperty::getPropertyTypeForPropertyNameValue(prop);
+
+       if(!temp)
+       {
+               throw std::runtime_error("Cannot create uncategorized property: " + prop);
+       }
+
+       std::string signature = g_variant_get_type_string(temp->toVariant());
+
+       propertyDBusMap[prop] = new VariantType(re, signature, prop, VariantType::ReadWrite, this);
+
+       delete temp;
+
+       supportedChanged(re->supported());
+}
diff --git a/plugins/dbus/uncategorizedproperty.h b/plugins/dbus/uncategorizedproperty.h
new file mode 100644 (file)
index 0000000..3eed498
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef UncategorizedPropertyInterface_H_
+#define UncategorizedPropertyInterface_H_
+
+#include "dbusplugin.h"
+
+class UncategorizedPropertyInterface: DBusSink
+{
+public:
+       UncategorizedPropertyInterface(VehicleProperty::Property, AbstractRoutingEngine* re, GDBusConnection* connection);
+};
+
+
+#endif
index 99b2c31..d0668f5 100644 (file)
@@ -164,6 +164,13 @@ void ExampleSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
                reply->success = true;
                reply->completed(reply);
        }
+       else if(reply->property == VehicleProperty::MachineGunTurretStatus)
+       {
+               VehicleProperty::MachineGunTurretStatusType temp(true);
+               reply->value = &temp;
+               reply->success = true;
+               reply->completed(reply);
+       }
 }
 
 void ExampleSourcePlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply)
@@ -198,6 +205,7 @@ PropertyList ExampleSourcePlugin::supported()
        props.push_back(VehicleProperty::ExteriorBrightness);
        props.push_back(VehicleProperty::DoorsPerRow);
        props.push_back(VehicleProperty::AirbagStatus);
+       props.push_back(VehicleProperty::MachineGunTurretStatus);
        
        return props;
 }