Skip to content

Commit

Permalink
Solves some bugs. Bump to version 0.7.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
phlegx committed Jun 16, 2015
1 parent c423735 commit 0b41b50
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions websocket-rails-client/channel.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -118,7 +118,7 @@ map_vec_cb_func Channel::getCallbacks() {


void Channel::setCallbacks(map_vec_cb_func callbacks) {
this-> callbacks = callbacks;
this->callbacks = callbacks;
}


Expand All @@ -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<jsonxx::String>("token");
this->flush_queue();
} else {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion websocket-rails-client/channel.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion websocket-rails-client/event.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion websocket-rails-client/event.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion websocket-rails-client/websocket.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion websocket-rails-client/websocket_connection.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion websocket-rails-client/websocket_connection.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
40 changes: 24 additions & 16 deletions websocket-rails-client/websocket_rails.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -56,20 +56,22 @@ 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";
}


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) {
Expand Down Expand Up @@ -184,15 +186,15 @@ 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);
}


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);
}
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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<jsonxx::String>("connection_id"));
this->conn->flushQueue();
this->getConn()->setConnectionId(event_data.get<jsonxx::String>("connection_id"));
this->getConn()->flushQueue();
if(this->on_open_callback) {
this->on_open_callback(event_data);
}
Expand Down Expand Up @@ -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);
}


Expand All @@ -329,7 +336,8 @@ bool WebsocketRails::connectionStale() {

std::vector<Channel> WebsocketRails::reconnectChannels() {
std::vector<Channel> results;
for(auto& x: this->channel_queue) {
std::tr1::unordered_map<std::string, Channel> 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;
Expand Down
4 changes: 3 additions & 1 deletion websocket-rails-client/websocket_rails.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0b41b50

Please sign in to comment.