only export dbus properties that are supported 10/2310/1
authorKevron Rees <kevron_m_rees@linux.intel.com>
Fri, 12 Oct 2012 22:34:37 +0000 (15:34 -0700)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Fri, 12 Oct 2012 22:34:37 +0000 (15:34 -0700)
lib/vehicleproperty.cpp
lib/vehicleproperty.h
plugins/dbus/CMakeLists.txt
plugins/dbus/abstractdbusinterface.cpp
plugins/dbus/abstractdbusinterface.h
plugins/dbus/abstractproperty.cpp
plugins/dbus/amb.conf [new file with mode: 0644]
plugins/dbus/dbusinterfacemanager.cpp
plugins/dbus/dbusplugin.cpp
plugins/dbus/properties.h

index 851cea0..ad6ef68 100644 (file)
@@ -35,6 +35,7 @@ const VehicleProperty::Property VehicleProperty::VehicleSpeed = "VehicleSpeed";
 const VehicleProperty::Property VehicleProperty::EngineSpeed = "EngineSpeed";
 const VehicleProperty::Property VehicleProperty::TransmissionShiftPosition = "TransmissionShiftPosition";
 const VehicleProperty::Property VehicleProperty::TransmissionGearPosition = "TransmissionGearPostion";
+const VehicleProperty::Property VehicleProperty::TransmissionMode = "TransmissionMode";
 const VehicleProperty::Property VehicleProperty::ThrottlePosition = "ThrottlePosition";
 const VehicleProperty::Property VehicleProperty::WheelBrake = "WheelBrake";
 const VehicleProperty::Property VehicleProperty::SteeringWheelAngle = "SteeringWheelAngle";
@@ -71,6 +72,7 @@ VehicleProperty::VehicleProperty()
        registerProperty(EngineSpeed, [](){ return new EngineSpeedType(0); });
        registerProperty(TransmissionShiftPosition, [](){ return new TransmissionShiftPositionType(Transmission::Neutral); });
        registerProperty(TransmissionGearPosition, [](){ return new TransmissionGearPositionType(Transmission::Neutral); });
+       REGISTERPROPERTY(TransmissionMode,Transmission::Normal);
        registerProperty(ThrottlePosition, [](){ return new ThrottlePositionType(0); });
        registerProperty(WheelBrake, [](){ return new WheelBrakeType(false); });
        registerProperty(SteeringWheelAngle, [](){ return new SteeringWheelAngleType(0); });
index 9ba25d3..e0b089c 100644 (file)
@@ -78,6 +78,13 @@ enum TransmissionPositions
        Park = 255
 
 };
+enum Mode {
+       Normal=0,
+       Sports = 1,
+       Economy = 2,
+       OEMCustom1 = 3,
+       OEMCustom2 = 4
+};
 }
 
 namespace Power {
@@ -136,6 +143,9 @@ public:
        static const Property TransmissionGearPosition;
        typedef BasicPropertyType<Transmission::TransmissionPositions> TransmissionGearPositionType;
 
+       static const Property TransmissionMode;
+       typedef BasicPropertyType<Transmission::Mode> TransmissionModeType;
+
        /**< Throttle position 0-100% */
        static const Property ThrottlePosition;
        typedef BasicPropertyType<uint16_t> ThrottlePositionType;
index eae6d21..696b7d3 100644 (file)
@@ -11,3 +11,4 @@ set_target_properties(dbussinkplugin PROPERTIES PREFIX "")
 target_link_libraries(dbussinkplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${gio_LIBRARIES})
 
 install (TARGETS dbussinkplugin LIBRARY DESTINATION lib/automotive-message-broker)
+install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/amb.conf DESTINATION /etc/dbus-1/system.d )
index 9ee9d81..fcebdc3 100644 (file)
@@ -30,8 +30,7 @@ AbstractDBusInterface::AbstractDBusInterface(string interfaceName, string object
        : mInterfaceName(interfaceName), mObjectPath(objectPath), mConnection(connection)
 {
        interfaceMap[interfaceName] = this;
-       introspectionXml ="<node>" ;
-       introspectionXml += "<interface name='"+ interfaceName + "' >";
+       startRegistration();
 }
 
 void AbstractDBusInterface::addProperty(AbstractProperty* property)
@@ -91,13 +90,18 @@ void AbstractDBusInterface::registerObject()
        
        const GDBusInterfaceVTable vtable = { NULL, AbstractDBusInterface::getProperty, AbstractDBusInterface::setProperty };
        
-       guint regId = g_dbus_connection_register_object(mConnection, mObjectPath.c_str(), mInterfaceInfo, &vtable, NULL, NULL, &error);
+       regId = g_dbus_connection_register_object(mConnection, mObjectPath.c_str(), mInterfaceInfo, &vtable, NULL, NULL, &error);
        
        if(error) throw -1;
        
        g_assert(regId > 0);
 }
 
+void AbstractDBusInterface::unregisterObject()
+{
+       g_dbus_connection_unregister_object(mConnection, regId);
+}
+
 void AbstractDBusInterface::updateValue(AbstractProperty *property)
 {
        if(mConnection == nullptr)
@@ -114,6 +118,13 @@ void AbstractDBusInterface::updateValue(AbstractProperty *property)
        }
 }
 
+void AbstractDBusInterface::startRegistration()
+{
+       unregisterObject();
+       introspectionXml ="<node>" ;
+       introspectionXml += "<interface name='"+ mInterfaceName + "' >";
+}
+
 GVariant* AbstractDBusInterface::getProperty(GDBusConnection* connection, const gchar* sender, const gchar* objectPath, const gchar* interfaceName, const gchar* propertyName, GError** error, gpointer userData)
 {
        *error = NULL;
index fae9e19..9fea6cd 100644 (file)
@@ -43,11 +43,14 @@ public:
        }
 
        void registerObject();
+       void unregisterObject();
        
        void addProperty(AbstractProperty* property);
        virtual void updateValue(AbstractProperty* property);
        
 protected:
+
+       void startRegistration();
        
        static GVariant *getProperty(GDBusConnection * connection, const gchar * sender, const gchar *objectPath,
                                                                 const gchar *interfaceName, const gchar * propertyName, GError** error,
@@ -67,6 +70,7 @@ private:
        string introspectionXml;
        GDBusConnection * mConnection;
        static unordered_map<string, AbstractDBusInterface*> interfaceMap;
+       guint regId;
 };
 
 #endif // ABSTRACTDBUSINTERFACE_H
index 111f2bd..495a613 100644 (file)
@@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 AbstractProperty::AbstractProperty(string pn, string sig, Access access, AbstractDBusInterface* interface)
        : mPropertyName(pn), mSignature(sig), mAccess(access), mInterface(interface)
 {
-       interface->addProperty(this);
+
 }
 
 void AbstractProperty::updateValue()
diff --git a/plugins/dbus/amb.conf b/plugins/dbus/amb.conf
new file mode 100644 (file)
index 0000000..e91f788
--- /dev/null
@@ -0,0 +1,11 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+
+  <policy context="default">
+    <!-- <deny send_destination="org.automotive.message.broker"/> -->
+    <allow send_destination="org.automotive.message.broker"/>
+       <allow own="org.automotive.message.broker"/>
+  </policy>
+
+</busconfig>
index 216fd09..43daf49 100644 (file)
@@ -41,8 +41,7 @@ on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_d
        AbstractDBusInterface* tirePressure = new TirePressureProperty(iface->re, connection);
        ConstructProperty(VehiclePowerModeProperty);
        ConstructProperty(TripMeterProperty);
-
-
+       ConstructProperty(TransmissionProperty);
 }
 
 static void
@@ -62,7 +61,7 @@ DBusInterfaceManager::DBusInterfaceManager(AbstractRoutingEngine* engine)
 {
        g_type_init();
 
-       ownerId = g_bus_own_name(G_BUS_TYPE_SESSION,
+       ownerId = g_bus_own_name(G_BUS_TYPE_SYSTEM,
                                        DBusServiceName,
                                        G_BUS_NAME_OWNER_FLAGS_NONE,
                                        on_bus_acquired,
@@ -71,7 +70,6 @@ DBusInterfaceManager::DBusInterfaceManager(AbstractRoutingEngine* engine)
                                        this,
                                        NULL);
 
-       ///TODO: instantiate other interfaces here!
 }
 
 DBusInterfaceManager::~DBusInterfaceManager()
index e206fb9..fc83634 100644 (file)
@@ -37,12 +37,14 @@ DBusSink::DBusSink(string interface, string path, AbstractRoutingEngine* engine,
 
 void DBusSink::supportedChanged(PropertyList supportedProperties)
 {
+       startRegistration();
 
        for(PropertyDBusMap::iterator itr = propertyDBusMap.begin(); itr != propertyDBusMap.end(); itr++)
        {
                if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains((*itr).first))
                {
                        routingEngine->subscribeToProperty((*itr).first, this);
+                       addProperty((*itr).second);
                        supported = true;
                }
        }
index 5d1f30d..f99c500 100644 (file)
@@ -87,4 +87,21 @@ public:
        }
 };
 
+class TransmissionProperty: public DBusSink
+{
+public:
+       TransmissionProperty(AbstractRoutingEngine *re, GDBusConnection *connection)
+       :DBusSink("org.automotive.transmission","/org/automotive/runningstatus/transmission", re, connection, map<string, string>())
+       {
+               wantProperty<Transmission::TransmissionPositions>(VehicleProperty::TransmissionShiftPosition,
+                                                                                                                 "ShiftPosition", "y", AbstractProperty::Read);
+               wantProperty<Transmission::TransmissionPositions>(VehicleProperty::TransmissionGearPosition,
+                                                                                                                 "GearPosition", "y", AbstractProperty::Read);
+               wantProperty<Transmission::TransmissionPositions>(VehicleProperty::TransmissionMode,
+                                                                                                                 "Mode", "y", AbstractProperty::Read);
+
+               supportedChanged(re->supported());
+       }
+};
+
 #endif