Skip to content

Commit

Permalink
Merge pull request #59 from macq-vraman/ack_javascript_compliant
Browse files Browse the repository at this point in the history
Changed ack from message::ptr to message::list
  • Loading branch information
melode11 committed Sep 10, 2015
2 parents 34b949e + 3500e7b commit 3aee49c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 35 deletions.
8 changes: 4 additions & 4 deletions examples/Console/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ socket::ptr current_socket;

void bind_events(socket::ptr &socket)
{
current_socket->on("new message", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::ptr &ack_resp)
current_socket->on("new message", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::list &ack_resp)
{
_lock.lock();
string user = data->get_map()["username"]->get_string();
Expand All @@ -80,7 +80,7 @@ void bind_events(socket::ptr &socket)
_lock.unlock();
}));

current_socket->on("user joined",sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::ptr &ack_resp)
current_socket->on("user joined",sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::list &ack_resp)
{
_lock.lock();
string user = data->get_map()["username"]->get_string();
Expand All @@ -91,7 +91,7 @@ void bind_events(socket::ptr &socket)
HIGHLIGHT(user<<" joined"<<"\nthere"<<(plural?" are ":"'s ")<< participants<<(plural?" participants":" participant"));
_lock.unlock();
}));
current_socket->on("user left", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::ptr &ack_resp)
current_socket->on("user left", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::list &ack_resp)
{
_lock.lock();
string user = data->get_map()["username"]->get_string();
Expand Down Expand Up @@ -126,7 +126,7 @@ MAIN_FUNC

getline(cin, nickname);
}
current_socket->on("login", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::ptr &ack_resp){
current_socket->on("login", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::list &ack_resp){
_lock.lock();
participants = data->get_map()["numUsers"]->get_int();
bool plural = participants !=1;
Expand Down
12 changes: 6 additions & 6 deletions examples/QT/SioChatDemo/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void MainWindow::RemoveListItem(QListWidgetItem* item)
}


void MainWindow::OnNewMessage(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp)
void MainWindow::OnNewMessage(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp)
{

if(data->get_flag() == message::flag_object)
Expand All @@ -152,7 +152,7 @@ void MainWindow::OnNewMessage(std::string const& name,message::ptr const& data,b
}
}

void MainWindow::OnUserJoined(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp)
void MainWindow::OnUserJoined(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp)
{
if(data->get_flag() == message::flag_object)
{
Expand Down Expand Up @@ -181,7 +181,7 @@ void MainWindow::OnUserJoined(std::string const& name,message::ptr const& data,b

}

void MainWindow::OnUserLeft(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp)
void MainWindow::OnUserLeft(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp)
{
if(data->get_flag() == message::flag_object)
{
Expand Down Expand Up @@ -209,7 +209,7 @@ void MainWindow::OnUserLeft(std::string const& name,message::ptr const& data,boo
}
}

void MainWindow::OnTyping(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp)
void MainWindow::OnTyping(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp)
{
if(m_typingItem == NULL)
{
Expand All @@ -223,7 +223,7 @@ void MainWindow::OnTyping(std::string const& name,message::ptr const& data,bool
}
}

void MainWindow::OnStopTyping(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp)
void MainWindow::OnStopTyping(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp)
{
if(m_typingItem != NULL)
{
Expand All @@ -232,7 +232,7 @@ void MainWindow::OnStopTyping(std::string const& name,message::ptr const& data,b
}
}

void MainWindow::OnLogin(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp)
void MainWindow::OnLogin(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp)
{
Q_EMIT RequestToggleInputs(true);
int numUser = data->get_map()["numUsers"]->get_int();
Expand Down
12 changes: 6 additions & 6 deletions examples/QT/SioChatDemo/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ private Q_SLOTS:
void NicknameAccept();
void NicknameCancelled();
private:
void OnNewMessage(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp);
void OnUserJoined(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp);
void OnUserLeft(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp);
void OnTyping(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp);
void OnStopTyping(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp);
void OnLogin(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp);
void OnNewMessage(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp);
void OnUserJoined(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp);
void OnUserLeft(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp);
void OnTyping(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp);
void OnStopTyping(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp);
void OnLogin(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp);
void OnConnected(std::string const& nsp);
void OnClosed(client::close_reason const& reason);
void OnFailed();
Expand Down
12 changes: 6 additions & 6 deletions examples/iOS/SioChatDemo/SioChatDemo/CRViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ -(void) updateUser:(NSString*)user count:(NSInteger) num joinOrLeft:(BOOL) isJoi

using namespace sio;

void OnNewMessage(CFTypeRef ctrl,string const& name,sio::message::ptr const& data,bool needACK,sio::message::ptr ackResp)
void OnNewMessage(CFTypeRef ctrl,string const& name,sio::message::ptr const& data,bool needACK,sio::message::list ackResp)
{
if(data->get_flag() == message::flag_object)
{
Expand All @@ -82,7 +82,7 @@ void OnNewMessage(CFTypeRef ctrl,string const& name,sio::message::ptr const& dat

}

void OnTyping(CFTypeRef ctrl,string const& name,sio::message::ptr const& data,bool needACK,sio::message::ptr ackResp)
void OnTyping(CFTypeRef ctrl,string const& name,sio::message::ptr const& data,bool needACK,sio::message::list ackResp)
{
if(data->get_flag() == message::flag_object)
{
Expand All @@ -93,7 +93,7 @@ void OnTyping(CFTypeRef ctrl,string const& name,sio::message::ptr const& data,bo
}
}

void OnStopTyping(CFTypeRef ctrl,string const& name,sio::message::ptr const& data,bool needACK,sio::message::ptr ackResp)
void OnStopTyping(CFTypeRef ctrl,string const& name,sio::message::ptr const& data,bool needACK,sio::message::list ackResp)
{
if(data->get_flag() == message::flag_object)
{
Expand All @@ -104,7 +104,7 @@ void OnStopTyping(CFTypeRef ctrl,string const& name,sio::message::ptr const& dat
}
}

void OnUserJoined(CFTypeRef ctrl, string const& name, sio::message::ptr const& data, bool needACK, sio::message::ptr ackResp)
void OnUserJoined(CFTypeRef ctrl, string const& name, sio::message::ptr const& data, bool needACK, sio::message::list ackResp)
{
if(data->get_flag() == message::flag_object)
{
Expand All @@ -116,7 +116,7 @@ void OnUserJoined(CFTypeRef ctrl, string const& name, sio::message::ptr const& d
}
}

void OnUserLeft(CFTypeRef ctrl, string const& name, sio::message::ptr const& data, bool needACK, sio::message::ptr ackResp)
void OnUserLeft(CFTypeRef ctrl, string const& name, sio::message::ptr const& data, bool needACK, sio::message::list ackResp)
{
if(data->get_flag() == message::flag_object)
{
Expand All @@ -129,7 +129,7 @@ void OnUserLeft(CFTypeRef ctrl, string const& name, sio::message::ptr const& dat
}


void OnLogin(CFTypeRef ctrl, string const& name, sio::message::ptr const& data, bool needACK, sio::message::ptr ackResp)
void OnLogin(CFTypeRef ctrl, string const& name, sio::message::ptr const& data, bool needACK, sio::message::list ackResp)
{
if(data->get_flag() == message::flag_object)
{
Expand Down
13 changes: 13 additions & 0 deletions src/sio_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ namespace sio
m_vector(std::move(rhs.m_vector))
{

}

list & operator= (const message::list && rhs)
{
m_vector = std::move(rhs.m_vector);
return *this;
}

template <typename T>
Expand Down Expand Up @@ -369,6 +375,13 @@ namespace sio
return arr;
}

message::ptr to_array_message() const
{
message::ptr arr = array_message::create();
arr->get_vector().insert(arr->get_vector().end(),m_vector.begin(),m_vector.end());
return arr;
}

private:
vector<message::ptr> m_vector;
};
Expand Down
15 changes: 7 additions & 8 deletions src/sio_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ namespace sio
return m_need_ack;
}

void event::put_ack_message(message::ptr const& ack_message)
void event::put_ack_message(message::list const& ack_message)
{
if(m_need_ack)
m_ack_message = ack_message;
m_ack_message = std::move(ack_message);
}

inline
Expand All @@ -91,13 +91,13 @@ namespace sio
{
}

message::ptr const& event::get_ack_message() const
message::list const& event::get_ack_message() const
{
return m_ack_message;
}

inline
message::ptr& event::get_ack_message_impl()
message::list& event::get_ack_message_impl()
{
return m_ack_message;
}
Expand Down Expand Up @@ -155,7 +155,7 @@ namespace sio

event_listener get_bind_listener_locked(string const& event);

void ack(int msgId,string const& name,message::ptr const& ack_message);
void ack(int msgId,string const& name,message::list const& ack_message);

void timeout_connection(const boost::system::error_code &ec);

Expand Down Expand Up @@ -449,10 +449,9 @@ namespace sio
}
}

void socket::impl::ack(int msgId, const string &name, const message::ptr &ack_message)
void socket::impl::ack(int msgId, const string &name, const message::list &ack_message)
{
message::list li(ack_message);
packet p(m_nsp, li.to_array_message(name),msgId,true);
packet p(m_nsp, ack_message.to_array_message(),msgId,true);
send_packet(p);
}

Expand Down
10 changes: 5 additions & 5 deletions src/sio_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ namespace sio

bool need_ack() const;

void put_ack_message(message::ptr const& ack_message);
void put_ack_message(message::list const& ack_message);

message::ptr const& get_ack_message() const;
message::list const& get_ack_message() const;

protected:
event(std::string const& nsp,std::string const& name,message::list const& messages,bool need_ack);
event(std::string const& nsp,std::string const& name,message::list&& messages,bool need_ack);

message::ptr& get_ack_message_impl();
message::list& get_ack_message_impl();

private:
const std::string m_nsp;
const std::string m_name;
const message::list m_messages;
const bool m_need_ack;
message::ptr m_ack_message;
message::list m_ack_message;

friend class event_adapter;
};
Expand All @@ -46,7 +46,7 @@ namespace sio
class socket
{
public:
typedef std::function<void(const std::string& name,message::ptr const& message,bool need_ack, message::ptr& ack_message)> event_listener_aux;
typedef std::function<void(const std::string& name,message::ptr const& message,bool need_ack, message::list& ack_message)> event_listener_aux;

typedef std::function<void(event& event)> event_listener;

Expand Down

0 comments on commit 3aee49c

Please sign in to comment.