DebugOut()<<__FUNCTION__<<"() adding suport for property "<<VehicleProperty::name((*itr))<<endl;
mMasterPropertyList.push_back((*itr));
}
- }
+ }
}
{
SinkList list = propertySinkMap[property];
- DebugOut()<<__FUNCTION__<<"() there are "<<list.size()<<" sinks connected to property: "<<VehicleProperty::name(property)<<endl;
+ DebugOut()<<__FUNCTION__<<"() there are "<<list.size()<<" sinks connected to property: "<<property<<endl;
for(SinkList::iterator itr = list.begin(); itr != list.end(); itr++)
{
void setProperty(VehicleProperty::Property, boost::any);
void subscribeToProperty(VehicleProperty::Property, AbstractSink* self);
void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self);
+ PropertyList supported() { return mMasterPropertyList; }
protected:
~Core();
{
"sources" : [ "../plugins/examplesourceplugin.so" ],
- "sinks": [ "../plugins/examplesinkplugin.so" ]
+ "sinks": [ "../plugins/examplesinkplugin.so", "../plugins/dbus/dbussinkplugin.so" ]
}
virtual void setProperty(VehicleProperty::Property, boost::any) = 0;
virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
virtual void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
+ virtual PropertyList supported() = 0;
};
#endif // ABSTRACTROUTINGENGINE_H
ThrottlePosition, /**< Throttle position 0-100% */
WheelBrake, /**< Wheel brake position. Engaged = true, Idle = false */
- SteeringWheelAngle, /**< Steering wheel angle (0-360) */
+ SteeringWheelAngle, /**< Steering wheel angle (0-359) */
TurnSignal, /**< 0=off, 1=right, 2=left, 3=hazard */
- MachineGunTurretStatus /**< 0=off, 1=on */
+ MachineGunTurretStatus, /**< 0=off, 1=on */
+ AccelerationX, /**< Acceleration on the 'x' axis in 1/1000 gravitational acceleration "g-force" */
+ AccelerationY, /**< Acceleration on the 'y' axis in 1/1000 gravitational acceleration "g-force" */
+ AccelerationZ /**< Acceleration on the 'z' axis in 1/1000 gravitational acceleration "g-force" */
};
static std::string name(Property prop);
pkg_check_modules(gio REQUIRED gio-2.0)
-set(dbussinkplugin_headers dbusplugin.h abstractproperty.h abstractdbusinterface.h dbusinterfacemanager.h)
-set(dbussinkplugin_sources dbusplugin.cpp abstractproperty.cpp abstractdbusinterface.cpp dbusinterfacemanager.cpp)
+set(dbussinkplugin_headers dbusplugin.h abstractproperty.h abstractdbusinterface.h dbusinterfacemanager.h accelerationproperty.h basicproperty.h)
+set(dbussinkplugin_sources dbusplugin.cpp abstractproperty.cpp abstractdbusinterface.cpp dbusinterfacemanager.cpp accelerationproperty.cpp basicproperty.cpp)
add_library(dbussinkplugin MODULE ${dbussinkplugin_sources})
set_target_properties(dbussinkplugin PROPERTIES PREFIX "")
unordered_map<string, AbstractDBusInterface*> AbstractDBusInterface::interfaceMap;
-AbstractDBusInterface::AbstractDBusInterface(string interfaceName, string objectPath)
-: mInterfaceName(interfaceName), mObjectPath(objectPath)
+AbstractDBusInterface::AbstractDBusInterface(string interfaceName, string objectPath,
+ GDBusConnection* connection)
+ : mInterfaceName(interfaceName), mObjectPath(objectPath), mConnection(connection)
{
- mConnection = nullptr;
-
interfaceMap[interfaceName] = this;
introspectionXml ="<node>" ;
introspectionXml += "<interface name='"+ interfaceName + "' >";
string nameToLower = property->name();
boost::algorithm::to_lower<string>(nameToLower);
+ string access;
+
+ if(property->access() == AbstractProperty::Read)
+ access = "read";
+ else if(property->access() == AbstractProperty::Write)
+ access = "write";
+ else if(property->access() == AbstractProperty::ReadWrite)
+ access = "readwrite";
+ else throw -1; //FIXME: don't throw
+
///see which properties are supported:
- introspectionXml += "<property type='"+ property->signature() + "' name='"+ property->name()+"' access='read' />"
+ introspectionXml += "<property type='"+ property->signature() + "' name='"+ property->name()+"' access='"+access+"' />"
"<signal name='" + property->name() + "' >"
" <arg type='"+ property->signature() + "' name='" + nameToLower + "' direction='out' />"
"</signal>";
properties[property->name()] = property;
}
-void AbstractDBusInterface::registerObject(GDBusConnection* connection)
+void AbstractDBusInterface::registerObject()
{
- mConnection = connection;
+ if(!mConnection)
+ {
+ throw std::runtime_error("forgot to call setDBusConnection on AbstractDBusInterface");
+ }
if(introspectionXml.empty())
{
const GDBusInterfaceVTable vtable = { NULL, AbstractDBusInterface::getProperty, AbstractDBusInterface::setProperty };
- guint regId = g_dbus_connection_register_object(connection, mObjectPath.c_str(), mInterfaceInfo, &vtable, NULL, NULL, &error);
+ guint regId = g_dbus_connection_register_object(mConnection, mObjectPath.c_str(), mInterfaceInfo, &vtable, NULL, NULL, &error);
if(error) throw -1;
return false;
}
+void AbstractDBusInterface::setProperty(string propertyName, GVariant *value)
+{
+ if(properties.count(propertyName))
+ {
+ properties[propertyName]->fromGVariant(value);
+ }
+ else
+ {
+ throw -1;
+ }
+}
+
+GVariant *AbstractDBusInterface::getProperty(string propertyName)
+{
+ if(properties.count(propertyName))
+ return properties[propertyName]->toGVariant();
+ else
+ throw -1;
+}
+
{
public:
- AbstractDBusInterface(string interfaceName, string objectPath);
+ AbstractDBusInterface(string interfaceName, string objectPath, GDBusConnection* connection);
- void registerObject(GDBusConnection* connection);
+ void setDBusConnection(GDBusConnection* connection)
+ {
+ mConnection = connection;
+ }
+
+ void registerObject();
void addProperty(AbstractProperty* property);
virtual void updateValue(AbstractProperty* property);
const gchar *interfaceName, const gchar * propertyName, GVariant *value,
GError** error, gpointer userData);
- virtual void setProperty(string propertyName, GVariant * value) = 0;
- virtual GVariant * getProperty(string propertyName) = 0;
+ virtual void setProperty(string propertyName, GVariant * value);
+ virtual GVariant * getProperty(string propertyName);
unordered_map<string, AbstractProperty*> properties;
virtual GVariant* toGVariant() = 0;
virtual void fromGVariant(GVariant *value) = 0;
+ void setValue(boost::any val)
+ {
+ mValue = val;
+ }
+
template<typename T>
void setValue(T val)
{
--- /dev/null
+/*
+ Copyright (C) 2012 Intel Corporation
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "basicproperty.h"
+
+
+
+
+
--- /dev/null
+/*
+ Copyright (C) 2012 Intel Corporation
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef _BASICPROPERTY_H_
+#define _BASICPROPERTY_H_
+
+#include "abstractproperty.h"
+
+template <typename T>
+class BasicProperty: public AbstractProperty
+{
+public:
+ BasicProperty(string propertyName, string signature, Access access, AbstractDBusInterface *interface)
+ :AbstractProperty(propertyName,signature,access,interface)
+ {
+
+ }
+
+ void setValue(T val)
+ {
+ AbstractProperty::setValue<T>(val);
+ }
+
+ T value()
+ {
+ return AbstractProperty::value<T>();
+ }
+
+ virtual GVariant* toGVariant()
+ {
+ return g_variant_new(signature().c_str(), value());
+ }
+
+ virtual void fromGVariant(GVariant *value)
+ {
+
+ }
+};
+
+#endif
*/
#include "dbusinterfacemanager.h"
+
+
#include <gio/gio.h>
#include <string>
+///properties:
+#include "accelerationproperty.h"
+
using namespace std;
static void
on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data)
{
- //AbstractDBusInterface::iface()->registerObject(connection);
+ DBusInterfaceManager* iface = static_cast<DBusInterfaceManager*>(user_data);
+ AbstractDBusInterface* acceleration = new AccelerationPropertyInterface(iface->re, connection);
+
}
static void
-DBusInterfaceManager::DBusInterfaceManager()
+DBusInterfaceManager::DBusInterfaceManager(AbstractRoutingEngine* engine)
+ :re(engine)
{
g_type_init();
#ifndef DBUSINTERFACEMANAGER_H
#define DBUSINTERFACEMANAGER_H
+class AbstractRoutingEngine;
+
class DBusInterfaceManager
{
public:
- DBusInterfaceManager();
+ DBusInterfaceManager(AbstractRoutingEngine* re);
~DBusInterfaceManager();
-
+
+ AbstractRoutingEngine* re;
private:
unsigned int ownerId;
+
};
#endif // DBUSINTERFACEMANAGER_H
*/
-#include "dbusplugin.h".h"
+#include "dbusplugin.h"
#include "abstractroutingengine.h"
+#include "dbusinterfacemanager.h"
#include "debugout.h"
extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine)
return new DBusSinkManager(routingengine);
}
-DBusSink::DBusSink(AbstractRoutingEngine* engine): AbstractSink(engine)
-{
- routingEngine->subscribeToProperty(VehicleProperty::EngineSpeed, this);
- routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
-
- AsyncPropertyRequest velocityRequest;
- velocityRequest.property = VehicleProperty::VehicleSpeed;
- velocityRequest.completed = [](AsyncPropertyReply* reply) { DebugOut()<<"Velocity Async request completed: "<<boost::any_cast<uint16_t>(reply->value)<<endl; };
-
- AsyncPropertyReply* reply = routingEngine->getPropertyAsync(velocityRequest);
-}
-
-
-PropertyList DBusSink::subscriptions()
+DBusSink::DBusSink(AbstractRoutingEngine* engine)
+ : AbstractSink(engine)
{
}
-void DBusSink::supportedChanged(PropertyList supportedProperties)
+void DBusSink::propertyChanged(VehicleProperty::Property property, boost::any value, string uuid)
{
+ AbstractProperty* prop = propertyDBusMap[property];
+ prop->setValue(value);
}
-void DBusSink::propertyChanged(VehicleProperty::Property property, boost::any value, std::string uuid)
+std::string DBusSink::uuid()
{
- DebugOut()<<VehicleProperty::name(property)<<" value: "<<boost::any_cast<uint16_t>(value)<<endl;
+ return "c2e6cafa-eef5-4b8a-99a0-0f2c9be1057d";
}
-std::string DBusSink::uuid()
+DBusSinkManager::DBusSinkManager(AbstractRoutingEngine *engine)
+ :AbstractSinkManager(engine)
{
- return "c2e6cafa-eef5-4b8a-99a0-0f2c9be1057d";
+ DBusInterfaceManager* manager = new DBusInterfaceManager(engine);
}
+/*
+ Copyright (C) 2012 Intel Corporation
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef DBUSSINK_H_
+#define DBUSSINK_H_
+
#include "abstractsink.h"
+#include "abstractproperty.h"
+#include <map>
+typedef std::map<VehicleProperty::Property, AbstractProperty*> PropertyDBusMap;
class DBusSink : public AbstractSink
{
public:
DBusSink(AbstractRoutingEngine* engine);
- virtual PropertyList subscriptions();
- virtual void supportedChanged(PropertyList supportedProperties);
+ virtual void supportedChanged(PropertyList supportedProperties) = 0;
virtual void propertyChanged(VehicleProperty::Property property, boost::any value, std::string uuid);
virtual std::string uuid();
+
+protected:
+ PropertyDBusMap propertyDBusMap;
};
class DBusSinkManager: public AbstractSinkManager
{
public:
- DBusSinkManager(AbstractRoutingEngine* engine)
- :AbstractSinkManager(engine)
- {
- new DBusSink(engine);
- }
+ DBusSinkManager(AbstractRoutingEngine* engine);
};
+#endif
{\r
PRINT.pass("The browser is websocket capable");\r
\r
- this.socket = new WebSocket("ws://localhost:23000/echo");\r
+ this.socket = new WebSocket("ws://localhost:7681");\r
this.socket.onopen = function()\r
{\r
PRINT.pass("Connection OPEN");\r
{\r
self.receive(e.data);\r
};\r
- this.socket.onclose = function()\r
+ this.socket.onclose = function(e)\r
{\r
- PRINT.fail("Connection CLOSED");\r
+ PRINT.fail("Connection CLOSED: " + e.reason + " code: " + e.code);\r
};\r
+ this.socket.onerror = function(evt) {\r
+ alert(evt);\r
+ }\r
}\r
else\r
{\r