Skip to content

Commit

Permalink
core: add on_any (#402)
Browse files Browse the repository at this point in the history
* Add on_any

* Update style in sio_socket.cpp

To keep the style. "ifs" with element can be put in one line if they fit. Otherwise they should use the bracket style.

---------

Co-authored-by: Joan Marcè i Igual <[email protected]>
  • Loading branch information
Nukoooo and jmigual authored Nov 8, 2023
1 parent ee6e423 commit 2c3f49a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Makefile
cmake_install.cmake
install_manifest.txt
libsioclient.a
.DS_Store
.DS_Store
.cache/
27 changes: 27 additions & 0 deletions src/sio_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ namespace sio

void on(std::string const& event_name,event_listener const& func);

void on_any(event_listener_aux const& func);

void on_any(event_listener const& func);

void off(std::string const& event_name);

void off_all();
Expand Down Expand Up @@ -179,6 +183,8 @@ namespace sio

std::map<std::string, event_listener> m_event_binding;

event_listener m_event_listener;

error_listener m_error_listener;

std::unique_ptr<asio::steady_timer> m_connection_timer;
Expand All @@ -203,6 +209,16 @@ namespace sio
m_event_binding[event_name] = func;
}

void socket::impl::on_any(event_listener_aux const& func)
{
m_event_listener = event_adapter::do_adapt(func);
}

void socket::impl::on_any(event_listener const& func)
{
m_event_listener = func;
}

void socket::impl::off(std::string const& event_name)
{
std::lock_guard<std::mutex> guard(m_event_mutex);
Expand Down Expand Up @@ -443,6 +459,7 @@ namespace sio
event ev = event_adapter::create_event(nsp,name, std::move(message),needAck);
event_listener func = this->get_bind_listener_locked(name);
if(func)func(ev);
if (m_event_listener) m_event_listener(ev);
if(needAck)
{
this->ack(msgId, name, ev.get_ack_message());
Expand Down Expand Up @@ -545,6 +562,16 @@ namespace sio
m_impl->on(event_name, func);
}

void socket::on_any(event_listener_aux const& func)
{
m_impl->on_any(func);
}

void socket::on_any(event_listener const& func)
{
m_impl->on_any(func);
}

void socket::off(std::string const& event_name)
{
m_impl->off(event_name);
Expand Down
4 changes: 4 additions & 0 deletions src/sio_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ namespace sio

void off(std::string const& event_name);

void on_any(event_listener const& func);

void on_any(event_listener_aux const& func);

void off_all();

void close();
Expand Down

0 comments on commit 2c3f49a

Please sign in to comment.