From ad2bffab0f71afc9f572dad6794f3ae74517ef96 Mon Sep 17 00:00:00 2001 From: Sangjung Woo Date: Tue, 16 Aug 2016 13:33:20 +0900 Subject: [PATCH] Change libwebsockets APIs libwebsockets APIs are changed from 1.6.0 version Change-Id: I454008ab6782a5ce6a35544ffc99353b8e21c8c9 Signed-off-by: Sangjung Woo --- packaging/automotive-message-broker.spec | 2 +- plugins/cangenplugin/CMakeLists.txt | 2 +- plugins/cangenplugin/cangenplugin.cpp | 6 ++-- plugins/cangenplugin/cangenplugin.h | 12 ++++---- plugins/cangenplugin/test/CMakeLists.txt | 2 +- plugins/cangenplugin/websockets.cpp | 30 +++++++++---------- plugins/cangenplugin/websockets.h | 10 +++---- plugins/websocket/CMakeLists.txt | 2 +- plugins/websocket/common.cpp | 8 +++--- plugins/websocket/common.h | 4 +-- plugins/websocket/websocketsink.cpp | 2 +- plugins/websocket/websocketsink.h | 6 ++-- plugins/websocket/websocketsinkmanager.cpp | 36 +++++++++++------------ plugins/websocket/websocketsinkmanager.h | 14 ++++----- plugins/websocket/websocketsource.cpp | 46 ++++++++++++++++-------------- plugins/websocket/websocketsource.h | 2 +- 16 files changed, 94 insertions(+), 90 deletions(-) diff --git a/packaging/automotive-message-broker.spec b/packaging/automotive-message-broker.spec index bbe989a..db66c64 100644 --- a/packaging/automotive-message-broker.spec +++ b/packaging/automotive-message-broker.spec @@ -22,7 +22,7 @@ BuildRequires: cmake 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) diff --git a/plugins/cangenplugin/CMakeLists.txt b/plugins/cangenplugin/CMakeLists.txt index 761ecbf..3604588 100644 --- a/plugins/cangenplugin/CMakeLists.txt +++ b/plugins/cangenplugin/CMakeLists.txt @@ -1,7 +1,7 @@ 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}) diff --git a/plugins/cangenplugin/cangenplugin.cpp b/plugins/cangenplugin/cangenplugin.cpp index 93d2e71..bc65f4e 100644 --- a/plugins/cangenplugin/cangenplugin.cpp +++ b/plugins/cangenplugin/cangenplugin.cpp @@ -212,7 +212,7 @@ bool CANGenPlugin::sendValue(const std::string& interface, AbstractPropertyType* 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(); @@ -261,7 +261,7 @@ void CANGenPlugin::getValue(libwebsocket* socket, const std::string& property, i 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); @@ -286,7 +286,7 @@ void CANGenPlugin::setValue(libwebsocket* socket, const std::string& property, c 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; diff --git a/plugins/cangenplugin/cangenplugin.h b/plugins/cangenplugin/cangenplugin.h index 163cde0..b972fb8 100644 --- a/plugins/cangenplugin/cangenplugin.h +++ b/plugins/cangenplugin/cangenplugin.h @@ -155,12 +155,12 @@ public: /*! * 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: @@ -185,18 +185,18 @@ private: /*! * \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. @@ -204,7 +204,7 @@ private: * \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. diff --git a/plugins/cangenplugin/test/CMakeLists.txt b/plugins/cangenplugin/test/CMakeLists.txt index 23a0684..da928ca 100644 --- a/plugins/cangenplugin/test/CMakeLists.txt +++ b/plugins/cangenplugin/test/CMakeLists.txt @@ -6,7 +6,7 @@ find_path(libtool_INCLUDE_DIR ltdl.h DOC "Libtool headers") 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") diff --git a/plugins/cangenplugin/websockets.cpp b/plugins/cangenplugin/websockets.cpp index 560282a..bdf9e9e 100644 --- a/plugins/cangenplugin/websockets.cpp +++ b/plugins/cangenplugin/websockets.cpp @@ -26,9 +26,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #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(libwebsocket_context_user (context)); + WebSockets *ws = static_cast(lws_context_user (lws_get_context(wsi))); WebSocketsObserver* observer = &ws->getObserver(); DebugOut(5) << __SMALLFILE__ << ":" << __LINE__ << "websocket_callback:" << reason << " ,user:" << reinterpret_cast(user) << endl; @@ -77,20 +77,20 @@ static int websocket_callback( { //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; @@ -134,8 +134,8 @@ static bool gioPollingFunc(GIOChannel *source, GIOCondition condition, gpointer pollstruct.fd = newfd; pollstruct.events = condition; pollstruct.revents = condition; - //libwebsocket_context* context = sinkManager->lwscontext(); - libwebsocket_service_fd(static_cast(data)->getContext(),&pollstruct); + //lws_context* context = sinkManager->lwscontext(); + lws_service_fd(static_cast(data)->getContext(),&pollstruct); if(pollstruct.revents & G_IO_ERR) { @@ -156,8 +156,8 @@ static bool gioPollingFunc(GIOChannel *source, GIOCondition condition, gpointer 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 }; @@ -167,18 +167,18 @@ WebSockets::WebSockets(WebSocketsObserver& observer, Type t, int port, string ip 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); } } @@ -200,7 +200,7 @@ WebSockets::~WebSockets() 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 buffer(new char[LWS_SEND_BUFFER_PRE_PADDING + strToWrite.length() + LWS_SEND_BUFFER_POST_PADDING]); @@ -208,7 +208,7 @@ int WebSockets::Write(struct libwebsocket *lws, const std::string& strToWrite) strcpy(buf, strToWrite.c_str()); //NOTE: delete[] on buffer is not needed since std::unique_ptr 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) diff --git a/plugins/cangenplugin/websockets.h b/plugins/cangenplugin/websockets.h index add00bc..b456aaa 100644 --- a/plugins/cangenplugin/websockets.h +++ b/plugins/cangenplugin/websockets.h @@ -49,7 +49,7 @@ public: * \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; }; /*! @@ -104,7 +104,7 @@ public: * \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 @@ -136,7 +136,7 @@ public: * \return Pointer to libwebsocket_context * \internal */ - inline libwebsocket_context* getContext() { return context.get(); } + inline lws_context* getContext() { return context.get(); } private: @@ -152,13 +152,13 @@ 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 lwsContextPtr; + typedef std::unique_ptr lwsContextPtr; /*! * Pointer to libwebsocket_context diff --git a/plugins/websocket/CMakeLists.txt b/plugins/websocket/CMakeLists.txt index 9745e67..aaf114a 100644 --- a/plugins/websocket/CMakeLists.txt +++ b/plugins/websocket/CMakeLists.txt @@ -16,7 +16,7 @@ if(Qt5Core_FOUND) 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}) diff --git a/plugins/websocket/common.cpp b/plugins/websocket/common.cpp index e4e49d0..6781aec 100644 --- a/plugins/websocket/common.cpp +++ b/plugins/websocket/common.cpp @@ -7,7 +7,7 @@ bool doBinary = false; -int lwsWrite(libwebsocket *lws, QByteArray d) +int lwsWrite(lws *lws, QByteArray d) { if(!lws) { @@ -48,7 +48,7 @@ int lwsWrite(libwebsocket *lws, QByteArray d) 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 { @@ -56,13 +56,13 @@ int lwsWrite(libwebsocket *lws, QByteArray d) 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) diff --git a/plugins/websocket/common.h b/plugins/websocket/common.h index b4af8f3..c07380c 100644 --- a/plugins/websocket/common.h +++ b/plugins/websocket/common.h @@ -10,7 +10,7 @@ extern bool 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 diff --git a/plugins/websocket/websocketsink.cpp b/plugins/websocket/websocketsink.cpp index 5cdfb72..6e4d1d2 100644 --- a/plugins/websocket/websocketsink.cpp +++ b/plugins/websocket/websocketsink.cpp @@ -34,7 +34,7 @@ #include #include -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 ()) { m_amdbproperty = ambdproperty; diff --git a/plugins/websocket/websocketsink.h b/plugins/websocket/websocketsink.h index 1ddd73b..58ca22a 100644 --- a/plugins/websocket/websocketsink.h +++ b/plugins/websocket/websocketsink.h @@ -29,19 +29,19 @@ class WebSocketSink : public AbstractSink { 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; }; diff --git a/plugins/websocket/websocketsinkmanager.cpp b/plugins/websocket/websocketsinkmanager.cpp index 2fc6f91..f9219ab 100644 --- a/plugins/websocket/websocketsinkmanager.cpp +++ b/plugins/websocket/websocketsinkmanager.cpp @@ -37,9 +37,9 @@ //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 config) @@ -58,8 +58,8 @@ WebSocketSinkManager::WebSocketSinkManager(AbstractRoutingEngine* engine, map config) { if((*i).second == "true") { - info.extensions = libwebsocket_get_internal_extensions(); + info.extensions = lws_get_internal_extensions(); } else info.extensions = nullptr; } @@ -141,11 +141,11 @@ void WebSocketSinkManager::setConfiguration(map config) 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; @@ -183,7 +183,7 @@ void WebSocketSinkManager::addSingleShotSink(libwebsocket* socket, VehicleProper 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; @@ -225,7 +225,7 @@ void WebSocketSinkManager::addSingleShotRangedSink(libwebsocket* socket, Propert 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()) { @@ -246,7 +246,7 @@ void WebSocketSinkManager::removeSink(libwebsocket* socket,VehicleProperty::Prop 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); @@ -284,7 +284,7 @@ void WebSocketSinkManager::setValue(libwebsocket* socket, VehicleProperty::Prope delete type; } -void WebSocketSinkManager::addSink(libwebsocket* socket, VehicleProperty::Property property, string uuid) +void WebSocketSinkManager::addSink(lws* socket, VehicleProperty::Property property, string uuid) { QVariantMap reply; @@ -303,7 +303,7 @@ extern "C" void create(AbstractRoutingEngine* routingengine, map sinkManager = new WebSocketSinkManager(routingengine, config); sinkManager->init(); } -void WebSocketSinkManager::disconnectAll(libwebsocket* socket) +void WebSocketSinkManager::disconnectAll(lws* socket) { std::list toDeleteList; @@ -381,7 +381,7 @@ void WebSocketSinkManager::removePoll(int fd) } } -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; @@ -576,7 +576,7 @@ static int websocket_callback(struct libwebsocket_context *context,struct libweb if (sinkManager != 0) { //sinkManager->addPoll((int)(long)user); - sinkManager->addPoll(libwebsocket_get_socket_fd(wsi)); + sinkManager->addPoll(lws_get_socket_fd(wsi)); } else { @@ -586,15 +586,15 @@ static int websocket_callback(struct libwebsocket_context *context,struct libweb } 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; @@ -635,7 +635,7 @@ bool gioPollingFunc(GIOChannel *source, GIOCondition condition, gpointer data) pollstruct.fd = newfd; pollstruct.events = condition; pollstruct.revents = condition; - libwebsocket_service_fd(context,&pollstruct); + lws_service_fd(context,&pollstruct); return true; } diff --git a/plugins/websocket/websocketsinkmanager.h b/plugins/websocket/websocketsinkmanager.h index 1b2fba6..d9cc6b2 100644 --- a/plugins/websocket/websocketsinkmanager.h +++ b/plugins/websocket/websocketsinkmanager.h @@ -35,17 +35,17 @@ class WebSocketSinkManager { public: WebSocketSinkManager(AbstractRoutingEngine* engine, map 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 > m_sinkMap; void setConfiguration(map 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; } @@ -58,7 +58,7 @@ private: std::map m_ioChannelMap; std::map m_ioSourceMap; AbstractRoutingEngine *m_engine; - struct libwebsocket_protocols protocollist[2]; + struct lws_protocols protocollist[2]; AbstractRoutingEngine * routingEngine; std::map configuration; diff --git a/plugins/websocket/websocketsource.cpp b/plugins/websocket/websocketsource.cpp index a52cdb1..d4e3146 100644 --- a/plugins/websocket/websocketsource.cpp +++ b/plugins/websocket/websocketsource.cpp @@ -37,7 +37,7 @@ #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; @@ -148,20 +148,24 @@ private: 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. @@ -232,7 +236,7 @@ void WebSocketSource::setConfiguration(map config) 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) @@ -260,7 +264,7 @@ bool gioPollingFunc(GIOChannel *source, GIOCondition condition, gpointer data) 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. @@ -321,7 +325,7 @@ static int checkTimeouts(gpointer data) 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; @@ -639,7 +643,7 @@ static int callback_http_only(libwebsocket_context *context, struct libwebsocket { 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 @@ -678,7 +682,7 @@ WebSocketSource::WebSocketSource(AbstractRoutingEngine *re, map if(config.find("useExtensions") != config.end() && config["useExtensions"] == "true") { - info.extensions = libwebsocket_get_internal_extensions(); + info.extensions = lws_get_internal_extensions(); } info.gid = -1; @@ -686,7 +690,7 @@ WebSocketSource::WebSocketSource(AbstractRoutingEngine *re, map info.port = CONTEXT_PORT_NO_LISTEN; info.user = this; - context = libwebsocket_create_context(&info); + context = lws_create_context(&info); setConfiguration(config); diff --git a/plugins/websocket/websocketsource.h b/plugins/websocket/websocketsource.h index 966fee3..053ba9c 100644 --- a/plugins/websocket/websocketsource.h +++ b/plugins/websocket/websocketsource.h @@ -42,7 +42,7 @@ public: int supportedOperations(); - libwebsocket *clientsocket; + lws *clientsocket; PropertyList queuedRequests; bool clientConnected; void checkSubscriptions(); -- 2.7.4