From 71842ba292f218a632714a2d65538f8a407451ab Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Fri, 12 Oct 2012 15:34:37 -0700 Subject: [PATCH] only export dbus properties that are supported --- lib/vehicleproperty.cpp | 2 ++ lib/vehicleproperty.h | 10 ++++++++++ plugins/dbus/CMakeLists.txt | 1 + plugins/dbus/abstractdbusinterface.cpp | 17 ++++++++++++++--- plugins/dbus/abstractdbusinterface.h | 4 ++++ plugins/dbus/abstractproperty.cpp | 2 +- plugins/dbus/amb.conf | 11 +++++++++++ plugins/dbus/dbusinterfacemanager.cpp | 6 ++---- plugins/dbus/dbusplugin.cpp | 2 ++ plugins/dbus/properties.h | 17 +++++++++++++++++ 10 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 plugins/dbus/amb.conf diff --git a/lib/vehicleproperty.cpp b/lib/vehicleproperty.cpp index 851cea0..ad6ef68 100644 --- a/lib/vehicleproperty.cpp +++ b/lib/vehicleproperty.cpp @@ -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); }); diff --git a/lib/vehicleproperty.h b/lib/vehicleproperty.h index 9ba25d3..e0b089c 100644 --- a/lib/vehicleproperty.h +++ b/lib/vehicleproperty.h @@ -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 TransmissionGearPositionType; + static const Property TransmissionMode; + typedef BasicPropertyType TransmissionModeType; + /**< Throttle position 0-100% */ static const Property ThrottlePosition; typedef BasicPropertyType ThrottlePositionType; diff --git a/plugins/dbus/CMakeLists.txt b/plugins/dbus/CMakeLists.txt index eae6d21..696b7d3 100644 --- a/plugins/dbus/CMakeLists.txt +++ b/plugins/dbus/CMakeLists.txt @@ -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 ) diff --git a/plugins/dbus/abstractdbusinterface.cpp b/plugins/dbus/abstractdbusinterface.cpp index 9ee9d81..fcebdc3 100644 --- a/plugins/dbus/abstractdbusinterface.cpp +++ b/plugins/dbus/abstractdbusinterface.cpp @@ -30,8 +30,7 @@ AbstractDBusInterface::AbstractDBusInterface(string interfaceName, string object : mInterfaceName(interfaceName), mObjectPath(objectPath), mConnection(connection) { interfaceMap[interfaceName] = this; - introspectionXml ="" ; - introspectionXml += ""; + 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 ="" ; + introspectionXml += ""; +} + GVariant* AbstractDBusInterface::getProperty(GDBusConnection* connection, const gchar* sender, const gchar* objectPath, const gchar* interfaceName, const gchar* propertyName, GError** error, gpointer userData) { *error = NULL; diff --git a/plugins/dbus/abstractdbusinterface.h b/plugins/dbus/abstractdbusinterface.h index fae9e19..9fea6cd 100644 --- a/plugins/dbus/abstractdbusinterface.h +++ b/plugins/dbus/abstractdbusinterface.h @@ -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 interfaceMap; + guint regId; }; #endif // ABSTRACTDBUSINTERFACE_H diff --git a/plugins/dbus/abstractproperty.cpp b/plugins/dbus/abstractproperty.cpp index 111f2bd..495a613 100644 --- a/plugins/dbus/abstractproperty.cpp +++ b/plugins/dbus/abstractproperty.cpp @@ -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 index 0000000..e91f788 --- /dev/null +++ b/plugins/dbus/amb.conf @@ -0,0 +1,11 @@ + + + + + + + + + + diff --git a/plugins/dbus/dbusinterfacemanager.cpp b/plugins/dbus/dbusinterfacemanager.cpp index 216fd09..43daf49 100644 --- a/plugins/dbus/dbusinterfacemanager.cpp +++ b/plugins/dbus/dbusinterfacemanager.cpp @@ -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() diff --git a/plugins/dbus/dbusplugin.cpp b/plugins/dbus/dbusplugin.cpp index e206fb9..fc83634 100644 --- a/plugins/dbus/dbusplugin.cpp +++ b/plugins/dbus/dbusplugin.cpp @@ -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(&supportedProperties).contains((*itr).first)) { routingEngine->subscribeToProperty((*itr).first, this); + addProperty((*itr).second); supported = true; } } diff --git a/plugins/dbus/properties.h b/plugins/dbus/properties.h index 5d1f30d..f99c500 100644 --- a/plugins/dbus/properties.h +++ b/plugins/dbus/properties.h @@ -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()) + { + wantProperty(VehicleProperty::TransmissionShiftPosition, + "ShiftPosition", "y", AbstractProperty::Read); + wantProperty(VehicleProperty::TransmissionGearPosition, + "GearPosition", "y", AbstractProperty::Read); + wantProperty(VehicleProperty::TransmissionMode, + "Mode", "y", AbstractProperty::Read); + + supportedChanged(re->supported()); + } +}; + #endif -- 2.7.4