Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supernova: /notify - return client id #1221

Merged
merged 1 commit into from
Oct 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions server/supernova/sc/sc_osc_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,25 +395,26 @@ void fire_notification(movable_array<char> & msg)
instance->send_notification(msg.data(), msg.size());
}

sc_notify_observers::error_code sc_notify_observers::add_observer(endpoint_ptr const & ep)
int sc_notify_observers::add_observer(endpoint_ptr const & ep)
{
observer_vector::iterator it = find(ep);
if (it != observers.end())
return already_registered;

observers.push_back(ep);
return no_error;
return observers.size() - 1;
}

sc_notify_observers::error_code sc_notify_observers::remove_observer(endpoint_ptr const & ep)
int sc_notify_observers::remove_observer(endpoint_ptr const & ep)
{
observer_vector::iterator it = find(ep);

if (it == observers.end())
return not_registered;

const int observerIndex = it - observers.begin();
observers.erase(it);
return no_error;
return observerIndex;
}

const char * sc_notify_observers::error_string(error_code error)
Expand Down Expand Up @@ -938,17 +939,22 @@ void handle_notify(received_message const & message, endpoint_ptr endpoint)
int enable = first_arg_as_int(message);

cmd_dispatcher<realtime>::fire_system_callback( [=]() {

int observer = 0;

if (enable) {
auto error_code = instance->add_observer(endpoint);
if (error_code)
send_fail_message(endpoint, "/notify", sc_notify_observers::error_string(error_code));
observer = instance->add_observer(endpoint);

if (observer < 0)
send_fail_message(endpoint, "/notify", sc_notify_observers::error_string( (sc_notify_observers::error_code)observer ));
} else {
auto error_code = instance->remove_observer(endpoint);
if (error_code)
send_fail_message(endpoint, "/notify", sc_notify_observers::error_string(error_code));
observer = instance->remove_observer(endpoint);
if (observer < 0)
send_fail_message(endpoint, "/notify", sc_notify_observers::error_string( (sc_notify_observers::error_code)observer ));
}

send_done_message(endpoint, "/notify");
if (observer >= 0)
send_done_message(endpoint, "/notify", observer);
});
}

Expand Down
8 changes: 4 additions & 4 deletions server/supernova/sc/sc_osc_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ class sc_notify_observers
public:
typedef enum {
no_error = 0,
already_registered,
not_registered
already_registered = -1,
not_registered = -2
} error_code;

sc_notify_observers(boost::asio::io_service & io_service):
udp_socket(io_service)
{}

error_code add_observer(endpoint_ptr const & ep);
error_code remove_observer(endpoint_ptr const & ep);
int add_observer(endpoint_ptr const & ep);
int remove_observer(endpoint_ptr const & ep);

/* @{ */
/** notifications, should be called from the real-time thread */
Expand Down