}
GDBusInterfaceInfo* mInterfaceInfo = g_dbus_node_info_lookup_interface(introspection, mInterfaceName.c_str());
-
- const GDBusInterfaceVTable vtable = { NULL, AbstractDBusInterface::getProperty, AbstractDBusInterface::setProperty };
-
+
+ auto fakeMethodCb = [](GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data) { };
+
+ const GDBusInterfaceVTable vtable = { fakeMethodCb, AbstractDBusInterface::getProperty, AbstractDBusInterface::setProperty };
+
regId = g_dbus_connection_register_object(mConnection, mObjectPath.c_str(), mInterfaceInfo, &vtable, NULL, NULL, &error);
if(error) throw -1;
GVariant* AbstractDBusInterface::getProperty(GDBusConnection* connection, const gchar* sender, const gchar* objectPath, const gchar* interfaceName, const gchar* propertyName, GError** error, gpointer userData)
{
- *error = NULL;
if(interfaceMap.count(interfaceName))
{
GVariant* value = interfaceMap[interfaceName]->getProperty(propertyName);
#include "custompropertyinterface.h"
#include "vehicleproperty.h"
#include "varianttype.h"
+#include "listplusplus.h"
-CustomPropertyInterface::CustomPropertyInterface(AbstractRoutingEngine *re, GDBusConnection *connection)
- :DBusSink("org.automotive.custom","/org/automotive/custom", re, connection, map<string, string>())
+CustomPropertyInterface::CustomPropertyInterface(VehicleProperty::Property prop, AbstractRoutingEngine *re, GDBusConnection *connection)
+ :DBusSink("org.automotive."+prop,"/org/automotive/custom/"+prop, re, connection, map<string, string>())
{
PropertyList list = VehicleProperty::customProperties();
- for (auto itr = list.begin(); itr != list.end(); itr++)
- {
- VehicleProperty::Property prop = *itr;
+ if(ListPlusPlus<VehicleProperty::Property>(&list).contains(prop))
+ {
propertyDBusMap[prop] = new VariantType(re, prop, VariantType::ReadWrite, this);
}
class CustomPropertyInterface: DBusSink
{
public:
- CustomPropertyInterface(AbstractRoutingEngine* re, GDBusConnection* connection);
+ CustomPropertyInterface(VehicleProperty::Property, AbstractRoutingEngine* re, GDBusConnection* connection);
};
ConstructProperty(HornProperty);
ConstructProperty(FuelProperty);
ConstructProperty(EngineOilProperty);
- ConstructProperty(CustomPropertyInterface);
+
+ PropertyList list = VehicleProperty::customProperties();
+
+ for (auto itr = list.begin(); itr != list.end(); itr++)
+ {
+ VehicleProperty::Property prop = *itr;
+
+ new CustomPropertyInterface(prop,iface->re,connection);
+ }
+
}
AsyncPropertyReply *OBD2Source::setProperty(AsyncSetPropertyRequest request )
{
AsyncPropertyReply* reply = new AsyncPropertyReply (request);
- reply->success = false;
+
+ if(request.property == Obd2Connected)
+ {
+ if(request.value->value<bool>() == true)
+ {
+ CommandRequest *req = new CommandRequest();
+ req->req = "connectifnot";
+ g_async_queue_push(commandQueue,req);
+ }
+ else
+ {
+ CommandRequest *req = new CommandRequest();
+ req->req = "disconnect";
+ g_async_queue_push(commandQueue,req);
+ }
+
+ reply->success = true;
+ }
+
+ else
+ {
+ reply->success = false;
+ }
+
try
{
reply->completed(reply);