From 0b41b5062e2076dda6ad21013de29d10fb1680d3 Mon Sep 17 00:00:00 2001 From: Egon Zemmer Date: Tue, 16 Jun 2015 12:01:07 +0200 Subject: [PATCH] Solves some bugs. Bump to version 0.7.3. --- README.md | 2 +- websocket-rails-client/channel.cpp | 10 ++--- websocket-rails-client/channel.hpp | 2 +- websocket-rails-client/event.cpp | 2 +- websocket-rails-client/event.hpp | 2 +- websocket-rails-client/websocket.hpp | 2 +- .../websocket_connection.cpp | 2 +- .../websocket_connection.hpp | 2 +- websocket-rails-client/websocket_rails.cpp | 40 +++++++++++-------- websocket-rails-client/websocket_rails.hpp | 4 +- 10 files changed, 39 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index caa10d9..c104f52 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# WebsocketRailsClient++ (v0.7.2) +# WebsocketRailsClient++ (v0.7.3) WebsocketRailsClient++ is a C++ library that uses the implementation of RFC6455 (The WebSocket Protocol) implemented in the WebSocket++ library, the Json++ light-weight JSON parser and the Boost library. It allows diff --git a/websocket-rails-client/channel.cpp b/websocket-rails-client/channel.cpp index 39cb0a3..d674031 100644 --- a/websocket-rails-client/channel.cpp +++ b/websocket-rails-client/channel.cpp @@ -1,7 +1,7 @@ /** * * Name : channel.cpp - * Version : v0.7.2 + * Version : v0.7.3 * Description : Channel Class in C++, Ansi-style * Author : Egon Zemmer * Company : Phlegx Systems @@ -54,7 +54,7 @@ Channel::Channel(std::string name, WebsocketRails & dispatcher, bool is_private, ************************************/ void Channel::destroy(cb_func success_callback, cb_func failure_callback) { - if(this->connection_id == (this->dispatcher->getConn() != 0 ? this->dispatcher->getConn()->getConnectionId() : "")) { + if(this->connection_id == (this->dispatcher->getConn() != NULL ? this->dispatcher->getConn()->getConnectionId() : "")) { std::string event_name = "websocket_rails.unsubscribe"; jsonxx::Array data = this->initEventData(event_name); Event event(data, success_callback, failure_callback); @@ -118,7 +118,7 @@ map_vec_cb_func Channel::getCallbacks() { void Channel::setCallbacks(map_vec_cb_func callbacks) { - this-> callbacks = callbacks; + this->callbacks = callbacks; } @@ -129,7 +129,7 @@ bool Channel::isPrivate() { void Channel::dispatch(std::string event_name, jsonxx::Object event_data) { if(event_name == "websocket_rails.channel_token") { - this->connection_id = this->dispatcher->getConn() != 0 ? this->dispatcher->getConn()->getConnectionId() : ""; + this->connection_id = this->dispatcher->getConn() != NULL ? this->dispatcher->getConn()->getConnectionId() : ""; this->token = event_data.get("token"); this->flush_queue(); } else { @@ -159,7 +159,7 @@ void Channel::initObject() { } else { event_name = "websocket_rails.subscribe"; } - this->connection_id = this->dispatcher->getConn() != 0 ? this->dispatcher->getConn()->getConnectionId() : ""; + this->connection_id = this->dispatcher->getConn() != NULL ? this->dispatcher->getConn()->getConnectionId() : ""; jsonxx::Array data = this->initEventData(event_name); Event event(data, this->on_success, this->on_failure); this->dispatcher->triggerEvent(event); diff --git a/websocket-rails-client/channel.hpp b/websocket-rails-client/channel.hpp index 0e075d7..fb0a229 100644 --- a/websocket-rails-client/channel.hpp +++ b/websocket-rails-client/channel.hpp @@ -1,7 +1,7 @@ /** * * Name : channel.hpp - * Version : v0.7.2 + * Version : v0.7.3 * Description : Channel Header Class in C++, Ansi-style * Author : Egon Zemmer * Company : Phlegx Systems diff --git a/websocket-rails-client/event.cpp b/websocket-rails-client/event.cpp index f3da739..6a629d7 100644 --- a/websocket-rails-client/event.cpp +++ b/websocket-rails-client/event.cpp @@ -1,7 +1,7 @@ /** * * Name : event.cpp - * Version : v0.7.2 + * Version : v0.7.3 * Description : Event Class in C++, Ansi-style * Author : Egon Zemmer * Company : Phlegx Systems diff --git a/websocket-rails-client/event.hpp b/websocket-rails-client/event.hpp index 8503de2..0665454 100644 --- a/websocket-rails-client/event.hpp +++ b/websocket-rails-client/event.hpp @@ -1,7 +1,7 @@ /** * * Name : event.hpp - * Version : v0.7.2 + * Version : v0.7.3 * Description : Event Header Class in C++, Ansi-style * Author : Egon Zemmer * Company : Phlegx Systems diff --git a/websocket-rails-client/websocket.hpp b/websocket-rails-client/websocket.hpp index 824070a..e0188c8 100644 --- a/websocket-rails-client/websocket.hpp +++ b/websocket-rails-client/websocket.hpp @@ -1,7 +1,7 @@ /** * * Name : websocket.hpp - * Version : v0.7.2 + * Version : v0.7.3 * Description : Websocket Header File in C++, Ansi-style * Author : Egon Zemmer * Company : Phlegx Systems diff --git a/websocket-rails-client/websocket_connection.cpp b/websocket-rails-client/websocket_connection.cpp index 4caa814..a9362fa 100644 --- a/websocket-rails-client/websocket_connection.cpp +++ b/websocket-rails-client/websocket_connection.cpp @@ -1,7 +1,7 @@ /** * * Name : websocket.cpp - * Version : v0.7.2 + * Version : v0.7.3 * Description : WebsocketConnection Class in C++, Ansi-style * Author : Egon Zemmer * Company : Phlegx Systems diff --git a/websocket-rails-client/websocket_connection.hpp b/websocket-rails-client/websocket_connection.hpp index cfcfbc8..f303625 100644 --- a/websocket-rails-client/websocket_connection.hpp +++ b/websocket-rails-client/websocket_connection.hpp @@ -1,7 +1,7 @@ /** * * Name : websocket.hpp - * Version : v0.7.2 + * Version : v0.7.3 * Description : WebsocketConnection Header Class in C++, Ansi-style * Author : Egon Zemmer * Company : Phlegx Systems diff --git a/websocket-rails-client/websocket_rails.cpp b/websocket-rails-client/websocket_rails.cpp index 09835f5..addb7df 100644 --- a/websocket-rails-client/websocket_rails.cpp +++ b/websocket-rails-client/websocket_rails.cpp @@ -1,7 +1,7 @@ /** * * Name : websocket_rails.cpp - * Version : v0.7.2 + * Version : v0.7.3 * Description : WebsocketRails Class in C++, Ansi-style * Author : Egon Zemmer * Company : Phlegx Systems @@ -40,8 +40,8 @@ WebsocketRails::WebsocketRails(std::string url) : url(url), conn() {} std::string WebsocketRails::connect() { this->state = "connecting"; - this->conn = new WebsocketConnection(this->url, *this); - this->websocket_connection_thread = boost::thread(&WebsocketConnection::run, this->conn); + this->setConn(new WebsocketConnection(this->url, *this)); + this->websocket_connection_thread = boost::thread(&WebsocketConnection::run, this->getConn()); int count = 0; while(!this->isConnected()) { boost::posix_time::seconds workTime(1); @@ -56,12 +56,14 @@ std::string WebsocketRails::connect() { std::string WebsocketRails::disconnect() { - if(this->conn != 0) { + if(this->getConn() != NULL) { if(this->isConnected()) { - this->conn->close(); + this->getConn()->close(); } + this->websocket_connection_thread.interrupt(); this->websocket_connection_thread.join(); - delete this->conn; + delete this->getConn(); + this->setConn(NULL); } return this->state = "disconnected"; } @@ -69,7 +71,7 @@ std::string WebsocketRails::disconnect() { WebsocketRails::connection WebsocketRails::reconnect() { connection conn_struct; - std::string oldconnection_id = this->conn != 0 ? this->conn->getConnectionId() : ""; + std::string oldconnection_id = this->getConn() != NULL ? this->getConn()->getConnectionId() : ""; this->disconnect(); if(this->connect() == "connected") { for(auto& x: this->event_queue) { @@ -184,7 +186,7 @@ void WebsocketRails::unbindAll(std::string event_name) { void WebsocketRails::trigger(std::string event_name, jsonxx::Object event_data) { jsonxx::Array data; - data << event_name << event_data << (this->conn != 0 ? this->conn->getConnectionId() : ""); + data << event_name << event_data << (this->getConn() != NULL ? this->getConn()->getConnectionId() : ""); Event event(data); this->triggerEvent(event); } @@ -192,7 +194,7 @@ void WebsocketRails::trigger(std::string event_name, jsonxx::Object event_data) void WebsocketRails::trigger(std::string event_name, jsonxx::Object event_data, cb_func success_callback, cb_func failure_callback) { jsonxx::Array data; - data << event_name << event_data << (this->conn != 0 ? this->conn->getConnectionId() : ""); + data << event_name << event_data << (this->getConn() != NULL ? this->getConn()->getConnectionId() : ""); Event event(data, success_callback, failure_callback); this->triggerEvent(event); } @@ -202,8 +204,8 @@ void WebsocketRails::triggerEvent(Event event) { if(this->event_queue.find(event.getId()) == this->event_queue.end()) { this->event_queue[event.getId()] = event; } - if(this->conn != 0) { - this->conn->trigger(event); + if(this->getConn() != NULL) { + this->getConn()->trigger(event); } } @@ -284,10 +286,15 @@ void WebsocketRails::unsubscribe(std::string channel_name, cb_func success_callb ********************************************************/ +void WebsocketRails::setConn(WebsocketConnection * conn) { + this->conn = conn; +} + + void WebsocketRails::connectionEstablished(jsonxx::Object event_data) { this->state = "connected"; - this->conn->setConnectionId(event_data.get("connection_id")); - this->conn->flushQueue(); + this->getConn()->setConnectionId(event_data.get("connection_id")); + this->getConn()->flushQueue(); if(this->on_open_callback) { this->on_open_callback(event_data); } @@ -316,9 +323,9 @@ void WebsocketRails::dispatchChannel(Event event) { void WebsocketRails::pong() { jsonxx::Array data; - data << "websocket_rails.pong" << jsonxx::Object() << (this->conn != 0 ? this->conn->getConnectionId() : ""); + data << "websocket_rails.pong" << jsonxx::Object() << (this->getConn() != NULL ? this->getConn()->getConnectionId() : ""); Event pong(data); - this->conn->trigger(pong); + this->getConn()->trigger(pong); } @@ -329,7 +336,8 @@ bool WebsocketRails::connectionStale() { std::vector WebsocketRails::reconnectChannels() { std::vector results; - for(auto& x: this->channel_queue) { + std::tr1::unordered_map channel_queue_old = this->channel_queue; + for(auto& x: channel_queue_old) { Channel channel = x.second; map_vec_cb_func callbacks = channel.getCallbacks(); cb_func success_callback, failure_callback; diff --git a/websocket-rails-client/websocket_rails.hpp b/websocket-rails-client/websocket_rails.hpp index c07461a..807d34a 100644 --- a/websocket-rails-client/websocket_rails.hpp +++ b/websocket-rails-client/websocket_rails.hpp @@ -1,7 +1,7 @@ /** * * Name : websocket_rails.hpp - * Version : v0.7.2 + * Version : v0.7.3 * Description : WesocketRails Header Class in C++, Ansi-style * Author : Egon Zemmer * Company : Phlegx Systems @@ -107,6 +107,8 @@ class WebsocketRails { /** * Functions **/ + Channel processSubscribe(std::string channel_name, bool is_private); + void setConn(WebsocketConnection * conn); void connectionEstablished(jsonxx::Object data); void dispatch(Event event); void dispatchChannel(Event event);