BuildRequires: boost-devel
BuildRequires: pkgconfig(json-c)
BuildRequires: libtool-ltdl-devel
-BuildRequires: pkgconfig(libwebsockets)
+BuildRequires: pkgconfig(libwebsockets) >= 1.6.0
BuildRequires: pkgconfig(uuid)
BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(glib-2.0)
if(cangen_plugin)
############################################################################################################################################
-pkg_check_modules(websockets REQUIRED libwebsockets)
+pkg_check_modules(websockets REQUIRED libwebsockets>=1.6.0)
pkg_check_modules(json REQUIRED json-c)
include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${gio_INCLUDE_DIRS} ${gio-unix_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/plugins/common ${Boost_INCLUDE_DIRS} ${json_INCLUDE_DIRS})
return canBus->sendExtendedFrame(frame);
}
-void CANGenPlugin::getValue(libwebsocket* socket, const std::string& property, int zone, const std::string& id)
+void CANGenPlugin::getValue(lws* socket, const std::string& property, int zone, const std::string& id)
{
AsyncPropertyRequest request;
PropertyList foo = VehicleProperty::capabilities();
routingEngine->getPropertyAsync(request);
}
-void CANGenPlugin::setValue(libwebsocket* socket, const std::string& property, const std::string& value, int zone, const std::string& interface, const std::string& transactionId)
+void CANGenPlugin::setValue(lws* socket, const std::string& property, const std::string& value, int zone, const std::string& interface, const std::string& transactionId)
{
LOG_MESSAGE( "CANGenPlugin::setValue called with arguments:" << property << ", " << value << endl);
WebSockets::Write(socket, replystr);
}
-void CANGenPlugin::dataReceived(libwebsocket* socket, const char* data, size_t len)
+void CANGenPlugin::dataReceived(lws* socket, const char* data, size_t len)
{
if(!data || len == 0)
return;
/*!
* Called when data received from libwebsockets
* \fn dataReceived
- * \param socket libwebsocket* to be used to send any reply.
+ * \param socket lws* to be used to send any reply.
* \param data Received data pointer.
* \param len Length of the data.
* \return None
*/
- void dataReceived(libwebsocket* socket, const char* data, size_t len);
+ void dataReceived(lws* socket, const char* data, size_t len);
//
// Internal methods:
/*!
* \brief Simulator.get request handler function.
* Builds and sends reply with the property value, timestamp and sequence number in JSON format.
- * \param socket libwebsocket handle to be used to send reply.
+ * \param socket lws handle to be used to send reply.
* \param property Name of the property.
* \param zone Property's zone.
* \param uuid Request's transaction id.
* \private
*/
- void getValue(libwebsocket* socket, const std::string& property, int zone, const std::string& uuid);
+ void getValue(lws* socket, const std::string& property, int zone, const std::string& uuid);
/*!
* \brief Simulator.set request handler function.
* Formats property's value as a AMB's AbstractPropertyValue and passes it to sendValue. Reply to the Simulator with reply string in JSON format.
- * \param socket libwebsocket handle to be used to send reply.
+ * \param socket lws handle to be used to send reply.
* \param property Name of the property.
* \param value Property's new value to be simulated.
* \param zone Property's zone.
* \param transactionId Request's transaction id.
* \private
*/
- void setValue(libwebsocket* socket, const std::string& property, const std::string& value, int zone, const std::string& interface, const std::string& transactionId);
+ void setValue(lws* socket, const std::string& property, const std::string& value, int zone, const std::string& interface, const std::string& transactionId);
/*!
* \brief Build and sends CAN frame to CANSimPlugin.
pkg_check_modules(glib REQUIRED glib-2.0)
pkg_check_modules(json REQUIRED json-c)
-pkg_check_modules(websockets REQUIRED libwebsockets)
+pkg_check_modules(websockets REQUIRED libwebsockets>=1.6.0)
#find libcanbus.a library:
find_library(canbus_LIBRARY canbus PATHS $ENV{IVIPOC_HOME}/native/lib DOC "canbus library")
#define __SMALLFILE__ std::string(__FILE__).substr(std::string(__FILE__).rfind("/")+1)
static int websocket_callback(
- libwebsocket_context *context, libwebsocket *wsi, libwebsocket_callback_reasons reason, void *user,void *in, size_t len)
+ lws *wsi, lws_callback_reasons reason, void *user,void *in, size_t len)
{
- WebSockets *ws = static_cast<WebSockets*>(libwebsocket_context_user (context));
+ WebSockets *ws = static_cast<WebSockets*>(lws_context_user (lws_get_context(wsi)));
WebSocketsObserver* observer = &ws->getObserver();
DebugOut(5) << __SMALLFILE__ << ":" << __LINE__ <<
"websocket_callback:" << reason << " ,user:" << reinterpret_cast<uint64_t>(user) << endl;
{
//printf("Adding poll %i\n",sinkManager);
DebugOut(5) << __SMALLFILE__ <<":"<< __LINE__ << "Adding poll" << endl;
- ws->addPoll(libwebsocket_get_socket_fd(wsi));
+ ws->addPoll(lws_get_socket_fd(wsi));
break;
}
case LWS_CALLBACK_DEL_POLL_FD:
{
- ws->removePoll(libwebsocket_get_socket_fd(wsi));
+ ws->removePoll(lws_get_socket_fd(wsi));
break;
}
- case LWS_CALLBACK_SET_MODE_POLL_FD:
+ case LWS_CALLBACK_CHANGE_MODE_POLL_FD:
{
//Set the poll mode
break;
}
- case LWS_CALLBACK_CLEAR_MODE_POLL_FD:
+ case LWS_CALLBACK_UNLOCK_POLL:
{
//Don't handle this yet.
break;
pollstruct.fd = newfd;
pollstruct.events = condition;
pollstruct.revents = condition;
- //libwebsocket_context* context = sinkManager->lwscontext();
- libwebsocket_service_fd(static_cast<WebSockets*>(data)->getContext(),&pollstruct);
+ //lws_context* context = sinkManager->lwscontext();
+ lws_service_fd(static_cast<WebSockets*>(data)->getContext(),&pollstruct);
if(pollstruct.revents & G_IO_ERR)
{
WebSockets::WebSockets(WebSocketsObserver& observer, Type t, int port, string ip) :
observer(observer),
- protocollist({ { "http-only", websocket_callback, 0 }, { NULL, NULL, 0 } }),
- context(nullptr, &libwebsocket_context_destroy)
+ protocollist({ { .name = "http-only", .callback = websocket_callback, }, { .name = NULL, } }),
+ context(nullptr, &lws_context_destroy)
{
//Protocol list for libwebsockets.
//protocollist[0] = { "http-only", websocket_callback, 0 };
memset(&info, 0, sizeof info);
info.iface = "any";
info.protocols = protocollist;
- info.extensions = libwebsocket_get_internal_extensions();
+ info.extensions = lws_get_internal_extensions();
info.gid = -1;
info.uid = -1;
info.options = 0;
info.port = port;
info.user = this;
//context = libwebsocket_create_context(&info);
- context = lwsContextPtr(libwebsocket_create_context(&info), &libwebsocket_context_destroy);
+ context = lwsContextPtr(lws_create_context(&info), &lws_context_destroy);
if(t == WebSockets::Client)
{
- libwebsocket_client_connect(context.get(), ip.c_str(), port, false, "/", "localhost", "websocket", protocollist[0].name, -1);
+ lws_client_connect(context.get(), ip.c_str(), port, false, "/", "localhost", "websocket", protocollist[0].name, -1);
}
}
assert(m_ioSourceMap.empty() == true);
}
-int WebSockets::Write(struct libwebsocket *lws, const std::string& strToWrite)
+int WebSockets::Write(struct lws *lws, const std::string& strToWrite)
{
std::unique_ptr<char[]> buffer(new char[LWS_SEND_BUFFER_PRE_PADDING + strToWrite.length() + LWS_SEND_BUFFER_POST_PADDING]);
strcpy(buf, strToWrite.c_str());
//NOTE: delete[] on buffer is not needed since std::unique_ptr<char[]> is used
- return lws ? libwebsocket_write(lws, (unsigned char*)buf, strToWrite.length(), LWS_WRITE_TEXT) : 0;
+ return lws ? lws_write(lws, (unsigned char*)buf, strToWrite.length(), LWS_WRITE_TEXT) : 0;
}
void WebSockets::addPoll(int fd)
* \param data pointer to buffer where input data are stored
* \param len length in bytes of the input data in buffer
*/
- virtual void dataReceived(libwebsocket* socket, const char* data, size_t len) = 0;
+ virtual void dataReceived(lws* socket, const char* data, size_t len) = 0;
};
/*!
* \param strToWrite Data to be written.
* \return Number of the data bytes written.
*/
- static int Write(libwebsocket *lws, const std::string& strToWrite);
+ static int Write(lws *lws, const std::string& strToWrite);
/*!
* libwebsocket helper function, called on LWS_CALLBACK_ADD_POLL_FD
* \return Pointer to libwebsocket_context
* \internal
*/
- inline libwebsocket_context* getContext() { return context.get(); }
+ inline lws_context* getContext() { return context.get(); }
private:
* \var protocollist;
* \private
*/
- struct libwebsocket_protocols protocollist[2];
+ struct lws_protocols protocollist[2];
/*!
* libwebsocket_context pointer encapsulated in std::unique_ptr
* \private
*/
- typedef std::unique_ptr<libwebsocket_context, decltype(&libwebsocket_context_destroy)> lwsContextPtr;
+ typedef std::unique_ptr<lws_context, decltype(&lws_context_destroy)> lwsContextPtr;
/*!
* Pointer to libwebsocket_context
set(CMAKE_AUTOMOC ON)
endif(Qt5Core_FOUND)
-pkg_check_modules(websockets REQUIRED libwebsockets)
+pkg_check_modules(websockets REQUIRED libwebsockets>=1.6.0)
include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${QT_INCLUDE_DIRS})
bool doBinary = false;
-int lwsWrite(libwebsocket *lws, QByteArray d)
+int lwsWrite(lws *lws, QByteArray d)
{
if(!lws)
{
if(doBinary)
{
- retval = libwebsocket_write(lws, (unsigned char*)strToWrite, toWrite.length(), LWS_WRITE_BINARY);
+ retval = lws_write(lws, (unsigned char*)strToWrite, toWrite.length(), LWS_WRITE_BINARY);
}
else
{
char *buf = buffer.get() + LWS_SEND_BUFFER_PRE_PADDING;
memcpy(buf, strToWrite, toWrite.length());
- retval = libwebsocket_write(lws, (unsigned char*)strToWrite, toWrite.length(), LWS_WRITE_TEXT);
+ retval = lws_write(lws, (unsigned char*)strToWrite, toWrite.length(), LWS_WRITE_TEXT);
}
}
return retval;
}
-int lwsWriteVariant(libwebsocket *lws, QVariant d)
+int lwsWriteVariant(lws *lws, QVariant d)
{
QByteArray replystr;
if(doBinary)
void cleanJson(QByteArray &json);
// libwebsocket_write helper function
-int lwsWrite(struct libwebsocket *lws, QByteArray d);
-int lwsWriteVariant(struct libwebsocket *lws, QVariant d);
+int lwsWrite(struct lws *lws, QByteArray d);
+int lwsWriteVariant(struct lws *lws, QVariant d);
#endif
#include <QJsonDocument>
#include <QVariantMap>
-WebSocketSink::WebSocketSink(AbstractRoutingEngine* re, libwebsocket *wsi, string uuid, VehicleProperty::Property property, std::string ambdproperty)
+WebSocketSink::WebSocketSink(AbstractRoutingEngine* re, lws *wsi, string uuid, VehicleProperty::Property property, std::string ambdproperty)
: AbstractSink(re,map<string, string> ())
{
m_amdbproperty = ambdproperty;
{
public:
- WebSocketSink(AbstractRoutingEngine* re, libwebsocket *wsi, string uuid, VehicleProperty::Property property, std::string ambdproperty);
+ WebSocketSink(AbstractRoutingEngine* re, lws *wsi, string uuid, VehicleProperty::Property property, std::string ambdproperty);
~WebSocketSink();
const string uuid() ;
void propertyChanged(AbstractPropertyType *value);
void supportedChanged(const PropertyList & supportedProperties);
PropertyList subscriptions();
- libwebsocket *socket() { return m_wsi; }
+ lws *socket() { return m_wsi; }
private:
char *webSocketBuffer;
string m_amdbproperty;
AbstractRoutingEngine *m_re;
- libwebsocket *m_wsi;
+ lws *m_wsi;
string m_uuid;
string m_property;
};
//Global variables, these will be moved into the class
struct pollfd pollfds[100];
int count_pollfds = 0;
-libwebsocket_context *context;
+lws_context *context;
WebSocketSinkManager *sinkManager;
-static int websocket_callback(struct libwebsocket_context *context,struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, void *user,void *in, size_t len);
+static int websocket_callback(struct lws *wsi,enum lws_callback_reasons reason, void *user,void *in, size_t len);
bool gioPollingFunc(GIOChannel *source,GIOCondition condition,gpointer data);
WebSocketSinkManager::WebSocketSinkManager(AbstractRoutingEngine* engine, map<string, string> config)
void WebSocketSinkManager::init()
{
//Protocol list for libwebsockets.
- protocollist[0] = { "http-only", websocket_callback, 0 };
- protocollist[1] = { NULL, NULL, 0 };
+ protocollist[0] = { .name = "http-only", .callback = websocket_callback, };
+ protocollist[1] = { .name = NULL, .callback = NULL, };
setConfiguration(configuration);
{
if((*i).second == "true")
{
- info.extensions = libwebsocket_get_internal_extensions();
+ info.extensions = lws_get_internal_extensions();
}
else info.extensions = nullptr;
}
info.ssl_cert_filepath = ssl_cert_path.c_str();
info.ssl_private_key_filepath = ssl_key_path.c_str();
}
- context = libwebsocket_create_context(&info);
+ context = lws_create_context(&info);
}
-void WebSocketSinkManager::addSingleShotSink(libwebsocket* socket, VehicleProperty::Property property, Zone::Type zone, string id)
+void WebSocketSinkManager::addSingleShotSink(lws* socket, VehicleProperty::Property property, Zone::Type zone, string id)
{
AsyncPropertyRequest request;
AsyncPropertyReply* reply = routingEngine->getPropertyAsync(request);
}
-void WebSocketSinkManager::addSingleShotRangedSink(libwebsocket* socket, PropertyList properties, double start, double end, double seqstart,double seqend, string id)
+void WebSocketSinkManager::addSingleShotRangedSink(lws* socket, PropertyList properties, double start, double end, double seqstart,double seqend, string id)
{
AsyncRangePropertyRequest rangedRequest;
routingEngine->getRangePropertyAsync(rangedRequest);
}
-void WebSocketSinkManager::removeSink(libwebsocket* socket,VehicleProperty::Property property, string uuid)
+void WebSocketSinkManager::removeSink(lws* socket,VehicleProperty::Property property, string uuid)
{
if (m_sinkMap.find(property) != m_sinkMap.end())
{
lwsWriteVariant(socket, reply);
}
}
-void WebSocketSinkManager::setValue(libwebsocket* socket, VehicleProperty::Property property, string value,Zone::Type zone, string uuid)
+void WebSocketSinkManager::setValue(lws* socket, VehicleProperty::Property property, string value,Zone::Type zone, string uuid)
{
AbstractPropertyType* type = VehicleProperty::getPropertyTypeForPropertyNameValue(property, value);
delete type;
}
-void WebSocketSinkManager::addSink(libwebsocket* socket, VehicleProperty::Property property, string uuid)
+void WebSocketSinkManager::addSink(lws* socket, VehicleProperty::Property property, string uuid)
{
QVariantMap reply;
sinkManager = new WebSocketSinkManager(routingengine, config);
sinkManager->init();
}
-void WebSocketSinkManager::disconnectAll(libwebsocket* socket)
+void WebSocketSinkManager::disconnectAll(lws* socket)
{
std::list<WebSocketSink*> toDeleteList;
}
}
-static int websocket_callback(struct libwebsocket_context *context,struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, void *user,void *in, size_t len)
+static int websocket_callback(struct lws *wsi,enum lws_callback_reasons reason, void *user,void *in, size_t len)
{
//printf("Switch: %i\n",reason);
DebugOut(5) << __SMALLFILE__ << ":" << __LINE__ << "websocket_callback:" << reason << endl;
if (sinkManager != 0)
{
//sinkManager->addPoll((int)(long)user);
- sinkManager->addPoll(libwebsocket_get_socket_fd(wsi));
+ sinkManager->addPoll(lws_get_socket_fd(wsi));
}
else
{
}
case LWS_CALLBACK_DEL_POLL_FD:
{
- sinkManager->removePoll(libwebsocket_get_socket_fd(wsi));
+ sinkManager->removePoll(lws_get_socket_fd(wsi));
break;
}
- case LWS_CALLBACK_SET_MODE_POLL_FD:
+ case LWS_CALLBACK_CHANGE_MODE_POLL_FD:
{
//Set the poll mode
break;
}
- case LWS_CALLBACK_CLEAR_MODE_POLL_FD:
+ case LWS_CALLBACK_UNLOCK_POLL:
{
//Don't handle this yet.
break;
pollstruct.fd = newfd;
pollstruct.events = condition;
pollstruct.revents = condition;
- libwebsocket_service_fd(context,&pollstruct);
+ lws_service_fd(context,&pollstruct);
return true;
}
{
public:
WebSocketSinkManager(AbstractRoutingEngine* engine, map<string, string> config);
- void addSingleShotSink(libwebsocket* socket, VehicleProperty::Property property, Zone::Type zone, string id);
- void addSingleShotRangedSink(libwebsocket* socket, PropertyList properties,double start, double end, double seqstart,double seqend, string id);
- void addSink(libwebsocket* socket, VehicleProperty::Property property, string uuid);
- void disconnectAll(libwebsocket* socket);
- void removeSink(libwebsocket* socket, VehicleProperty::Property property, string uuid);
+ void addSingleShotSink(lws* socket, VehicleProperty::Property property, Zone::Type zone, string id);
+ void addSingleShotRangedSink(lws* socket, PropertyList properties,double start, double end, double seqstart,double seqend, string id);
+ void addSink(lws* socket, VehicleProperty::Property property, string uuid);
+ void disconnectAll(lws* socket);
+ void removeSink(lws* socket, VehicleProperty::Property property, string uuid);
void addPoll(int fd);
void removePoll(int fd);
void init();
std::map<std::string, list<WebSocketSink*> > m_sinkMap;
void setConfiguration(map<string, string> config);
- void setValue(libwebsocket* socket,VehicleProperty::Property property, string value, Zone::Type zone, string uuid);
+ void setValue(lws* socket,VehicleProperty::Property property, string value, Zone::Type zone, string uuid);
PropertyList getSupportedProperties();
AbstractRoutingEngine * router() { return routingEngine; }
std::map<int, GIOChannel*> m_ioChannelMap;
std::map<int, guint> m_ioSourceMap;
AbstractRoutingEngine *m_engine;
- struct libwebsocket_protocols protocollist[2];
+ struct lws_protocols protocollist[2];
AbstractRoutingEngine * routingEngine;
std::map<std::string, std::string> configuration;
#include "superptr.hpp"
#define __SMALLFILE__ std::string(__FILE__).substr(std::string(__FILE__).rfind("/")+1)
-libwebsocket_context *context = NULL;
+lws_context *context = NULL;
WebSocketSource *source;
AbstractRoutingEngine *m_re;
UniquePropertyCache properties;
-static int callback_http_only(libwebsocket_context *context,struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason,void *user, void *in, size_t len);
-static struct libwebsocket_protocols protocols[] = {
-{
- "http-only",
- callback_http_only,
- 0,
- 128,
-},
-{ /* end of list */
- NULL,
- NULL,
- 0,
- 0
-}
+static int callback_http_only(struct lws *wsi,enum lws_callback_reasons reason,void *user, void *in, size_t len);
+static struct lws_protocols protocols[] = {
+ {
+ "http-only",
+ callback_http_only,
+ 0,
+ 128,
+ 0,
+ NULL,
+ },
+ {
+ NULL,
+ NULL,
+ 0,
+ 0,
+ 0,
+ NULL,
+ }
};
//Called when a client connects, subscribes, or unsubscribes.
sslval = 2;
}
- clientsocket = libwebsocket_client_connect(context, ip.c_str(), port, sslval,"/", "localhost", "websocket", protocols[0].name, -1);
+ clientsocket = lws_client_connect(context, ip.c_str(), port, sslval,"/", "localhost", "websocket", protocols[0].name, -1);
}
PropertyInfo WebSocketSource::getPropertyInfo(const VehicleProperty::Property &property)
pollstruct.fd = newfd;
pollstruct.events = condition;
pollstruct.revents = condition;
- libwebsocket_service_fd(context,&pollstruct);
+ lws_service_fd(context,&pollstruct);
if (condition & G_IO_HUP)
{
//Hang up. Returning false closes out the GIOChannel.
return 0;
}
-static int callback_http_only(libwebsocket_context *context, struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, void *user, void *in, size_t len)
+static int callback_http_only(struct lws *wsi,enum lws_callback_reasons reason, void *user, void *in, size_t len)
{
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 4096 + LWS_SEND_BUFFER_POST_PADDING];
DebugOut() << __SMALLFILE__ << ":" << __LINE__ << reason << "callback_http_only" << endl;
{
DebugOut(5) << __SMALLFILE__ << ":" << __LINE__ << "Adding poll for websocket IO channel" << endl;
//Add a FD to the poll list.
- GIOChannel *chan = g_io_channel_unix_new(libwebsocket_get_socket_fd(wsi));
+ GIOChannel *chan = g_io_channel_unix_new(lws_get_socket_fd(wsi));
/// TODO: I changed this to be more consistent with the websocket sink end. it may not be correct. TEST
if(config.find("useExtensions") != config.end() && config["useExtensions"] == "true")
{
- info.extensions = libwebsocket_get_internal_extensions();
+ info.extensions = lws_get_internal_extensions();
}
info.gid = -1;
info.port = CONTEXT_PORT_NO_LISTEN;
info.user = this;
- context = libwebsocket_create_context(&info);
+ context = lws_create_context(&info);
setConfiguration(config);
int supportedOperations();
- libwebsocket *clientsocket;
+ lws *clientsocket;
PropertyList queuedRequests;
bool clientConnected;
void checkSubscriptions();