-WebSocketSink::WebSocketSink(AbstractRoutingEngine* re,libwebsocket *wsi,string uuid,VehicleProperty::Property property) : AbstractSink(re)
+WebSocketSink::WebSocketSink(AbstractRoutingEngine* re,libwebsocket *wsi,string uuid,VehicleProperty::Property property,std::string ambdproperty) : AbstractSink(re)
{
+ m_amdbproperty = ambdproperty;
m_uuid = uuid;
m_wsi = wsi;
m_property = property;
m_re = re;
- re->subscribeToProperty(property,this);
+ re->subscribeToProperty(ambdproperty,this);
}
string WebSocketSink::uuid()
{
stringstream s;
//TODO: Dirty hack hardcoded stuff, jsut to make it work.
- string tmpstr = "";
- if (property == VehicleProperty::VehicleSpeed)
+ std::string tmpstr="";
+ if (m_property != property)
{
- tmpstr = "running_status_speedometer";
- }
- else if (property == VehicleProperty::EngineSpeed)
- {
- tmpstr = "running_status_engine_speed";
- }
- else if (property == VehicleProperty::SteeringWheelAngle)
- {
- tmpstr = "running_status_steering_wheel_angle";
- }
- else if (property == VehicleProperty::TransmissionShiftPosition)
- {
- tmpstr = "running_status_transmission_gear_status";
+ tmpstr = m_property;
}
else
{
}
WebSocketSink::~WebSocketSink()
{
- m_re->unsubscribeToProperty(m_property,this);
+ m_re->unsubscribeToProperty(m_amdbproperty,this);
}
void WebSocketSink::supportedChanged(PropertyList supportedProperties)
{
void WebSocketSinkManager::addSingleShotSink(libwebsocket* socket, VehicleProperty::Property property,string id)
{
AsyncPropertyRequest velocityRequest;
- velocityRequest.property = property;
+ if (property == "running_status_speedometer")
+ {
+ velocityRequest.property = VehicleProperty::VehicleSpeed;
+ }
+ else if (property == "running_status_engine_speed")
+ {
+ velocityRequest.property = VehicleProperty::EngineSpeed;
+ }
+ else if ("running_status_steering_wheel_angle")
+ {
+ velocityRequest.property = VehicleProperty::SteeringWheelAngle;
+ }
+ else if ("running_status_transmission_gear_status")
+ {
+ velocityRequest.property = VehicleProperty::TransmissionShiftPosition;
+ }
+ else
+ {
+ PropertyList foo = VehicleProperty::capabilities();
+ if (ListPlusPlus<VehicleProperty::Property>(&foo).contains(property))
+ {
+ velocityRequest.property = property;
+ }
+ else
+ {
+ //Invalid property requested.
+ return;
+ }
+
+ }
velocityRequest.completed = [socket,id,property](AsyncPropertyReply* reply)
{
printf("Got property:%i\n",boost::any_cast<uint16_t>(reply->value));
//TODO: Dirty hack hardcoded stuff, jsut to make it work.
string tmpstr = "";
- if (property == VehicleProperty::VehicleSpeed)
+ /*if (property == VehicleProperty::VehicleSpeed)
{
tmpstr = "running_status_speedometer";
}
//{
//}
- }
+ }*/
+ tmpstr = property;
s << "{\"type\":\"methodReply\",\"name\":\"get\",\"data\":[{\"name\":\"" << tmpstr << "\",\"value\":\"" << velocity << "\"}],\"transactionid\":\"" << id << "\"}";
string replystr = s.str();
//TODO: Dirty hack hardcoded stuff, jsut to make it work.
string tmpstr = "";
- if (property == VehicleProperty::VehicleSpeed)
+ if (property == "running_status_speedometer")
{
- tmpstr = "running_status_speedometer";
+ tmpstr = VehicleProperty::VehicleSpeed;
}
- else if (property == VehicleProperty::EngineSpeed)
+ else if (property == "running_status_engine_speed")
{
- tmpstr = "running_status_engine_speed";
+ tmpstr = VehicleProperty::EngineSpeed;
}
- else if (property == VehicleProperty::SteeringWheelAngle)
+ else if ("running_status_steering_wheel_angle")
{
- tmpstr = "running_status_steering_wheel_angle";
+ tmpstr = VehicleProperty::SteeringWheelAngle;
}
- else if (property == VehicleProperty::TransmissionShiftPosition)
+ else if ("running_status_transmission_gear_status")
{
- tmpstr = "running_status_transmission_gear_status";
+ tmpstr = VehicleProperty::TransmissionShiftPosition;
}
else
{
- tmpstr = property;
+ PropertyList foo = VehicleProperty::capabilities();
+ if (ListPlusPlus<VehicleProperty::Property>(&foo).contains(property))
+ {
+ tmpstr = property;
+ }
+ else
+ {
+ //Invalid property requested.
+ return;
+ }
+
}
-
-
-
-
-
- s << "{\"type\":\"methodReply\",\"name\":\"subscribe\",\"data\":[\"" << tmpstr << "\"],\"transactionid\":\"" << uuid << "\"}";
+ s << "{\"type\":\"methodReply\",\"name\":\"subscribe\",\"data\":[\"" << property << "\"],\"transactionid\":\"" << uuid << "\"}";
string replystr = s.str();
printf("Reply: %s\n",replystr.c_str());
strcpy(new_response,replystr.c_str());
libwebsocket_write(socket, (unsigned char*)new_response, strlen(new_response), LWS_WRITE_TEXT);
- WebSocketSink *sink = new WebSocketSink(m_engine,socket,uuid,property);
+ WebSocketSink *sink = new WebSocketSink(m_engine,socket,uuid,property,tmpstr);
m_sinkMap[property] = sink;
}
{
//GetProperty is going to be a singleshot sink.
//string arg = arguments.front();
- if (data.front()== "running_status_speedometer")
+ sinkManager->addSingleShotSink(wsi,data.front(),id);
+ /*if (data.front()== "running_status_speedometer")
{
sinkManager->addSingleShotSink(wsi,VehicleProperty::VehicleSpeed,id);
}
{
sinkManager->addSingleShotSink(wsi,data.front(),id);
}
- }
+ }*/
}
else
{
}
else if (name == "subscribe")
{
+ sinkManager->addSink(wsi,data.front(),id);
+ /*
if (data.front()== "running_status_speedometer")
{
sinkManager->addSink(wsi,VehicleProperty::VehicleSpeed,id);
{
DebugOut() << __SMALLFILE__ << ":" << __LINE__ << " Unsupported subscription type:" << data.front();
}
- }
+ }*/
}
else if (name == "unsubscribe")
{
- if (data.front()== "running_status_speedometer")
+ sinkManager->removeSink(wsi,data.front(),id);
+ /*if (data.front()== "running_status_speedometer")
{
sinkManager->removeSink(wsi,VehicleProperty::VehicleSpeed,id);
}
//Unsupported unsubscribe
DebugOut() << __SMALLFILE__ << ":" << __LINE__ << " Unsupported unsubscription type:" << data.front();
}
- }
+ }*/
}
else if (name == "getSupportedEventTypes")
{