diff options
author | David Robillard <d@drobilla.net> | 2012-03-12 02:28:21 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-03-12 02:28:21 +0000 |
commit | e9d9569271ee962c09ab66c6babed1ca5655a6c6 (patch) | |
tree | f77142b08c2bf2488eb382e993da1477c0b94307 /src | |
parent | 7835b3d8c9b5b4a6f4959f56083d62826e6f7b8e (diff) | |
download | ingen-e9d9569271ee962c09ab66c6babed1ca5655a6c6.tar.gz ingen-e9d9569271ee962c09ab66c6babed1ca5655a6c6.tar.bz2 ingen-e9d9569271ee962c09ab66c6babed1ca5655a6c6.zip |
Unify event response mechanism and make it more appropriate for wire transmission.
The downside being more cryptic error messages until the client side error reporting stuff gets more fancy, but the important part is that belongs client side.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4053 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
39 files changed, 148 insertions, 408 deletions
diff --git a/src/bindings/Client.hpp b/src/bindings/Client.hpp index 703b4199..8a5b99aa 100644 --- a/src/bindings/Client.hpp +++ b/src/bindings/Client.hpp @@ -13,8 +13,7 @@ public: void bundle_begin() {} void bundle_end() {} - void response_ok(int32_t id) {} - void response_error(int32_t id, const std::string& msg) {} + void response(int32_t id, Status status) {} void error(const std::string& msg) {} void put(const Raul::URI& path, const Ingen::Resource::Properties& properties) {} void connect(const Raul::Path& src_port_path, const Raul::Path& dst_port_path) {} diff --git a/src/gui/App.cpp b/src/gui/App.cpp index 5a42af53..e23ef5a6 100644 --- a/src/gui/App.cpp +++ b/src/gui/App.cpp @@ -167,8 +167,8 @@ App::attach(SharedPtr<SigClientInterface> client) _patch_tree_window->init(*this, *_store); - _client->signal_response_error().connect( - sigc::mem_fun(this, &App::error_response)); + _client->signal_response().connect( + sigc::mem_fun(this, &App::response)); _client->signal_error().connect( sigc::mem_fun(this, &App::error_message)); _client->signal_property_change().connect( @@ -199,9 +199,11 @@ App::serialiser() } void -App::error_response(int32_t id, const string& str) +App::response(int32_t id, Status status) { - error_message(str); + if (status) { + error_message(ingen_status_string(status)); + } } void diff --git a/src/gui/App.hpp b/src/gui/App.hpp index 69bcd793..5ca767e9 100644 --- a/src/gui/App.hpp +++ b/src/gui/App.hpp @@ -28,6 +28,7 @@ #include "raul/SharedPtr.hpp" #include "raul/Deletable.hpp" +#include "ingen/Status.hpp" #include "ingen/shared/World.hpp" namespace Ingen { @@ -135,7 +136,7 @@ protected: App(Ingen::Shared::World* world); bool animate(); - void error_response(int32_t id, const std::string& str); + void response(int32_t id, Ingen::Status status); void property_change(const Raul::URI& subject, const Raul::URI& key, diff --git a/src/gui/ConnectWindow.cpp b/src/gui/ConnectWindow.cpp index e7a0aba1..0bfa1999 100644 --- a/src/gui/ConnectWindow.cpp +++ b/src/gui/ConnectWindow.cpp @@ -369,8 +369,8 @@ ConnectWindow::gtk_callback() if (_connect_stage == 0) { _attached = false; - _app->client()->signal_response_ok().connect( - sigc::mem_fun(this, &ConnectWindow::on_response)); + _app->client()->signal_response().connect( + sigc::mem_fun(this, &ConnectWindow::ingen_response)); _ping_id = abs(rand()) / 2 * 2; // avoid -1 _app->engine()->respond_to(_app->client().get(), _ping_id); diff --git a/src/gui/ConnectWindow.hpp b/src/gui/ConnectWindow.hpp index 9f82db32..9905b51a 100644 --- a/src/gui/ConnectWindow.hpp +++ b/src/gui/ConnectWindow.hpp @@ -45,7 +45,7 @@ public: void set_connected_to(SharedPtr<ServerInterface> engine); void start(App& app, Ingen::Shared::World* world); - void on_response(int32_t id) { _attached = true; } + void ingen_response(int32_t id, Status status) { _attached = true; } bool attached() const { return _finished_connecting; } bool quit_flag() const { return _quit_flag; } diff --git a/src/http/HTTPClientReceiver.cpp b/src/http/HTTPClientReceiver.cpp index dc1235e7..bb4b9c3b 100644 --- a/src/http/HTTPClientReceiver.cpp +++ b/src/http/HTTPClientReceiver.cpp @@ -166,14 +166,14 @@ HTTPClientReceiver::message_callback(SoupSession* session, SoupMessage* msg, voi } if (path == "/") { - me->_target->response_ok(0); + me->_target->response(0, SUCCESS); } else if (path == "/plugins") { if (msg->response_body->data == NULL) { LOG(error) << "Empty response" << endl; } else { Glib::Mutex::Lock lock(me->_mutex); - me->_target->response_ok(0); + me->_target->response(0, SUCCESS); me->_world->parser()->parse_string(me->_world, me->_target.get(), Glib::ustring(msg->response_body->data), me->_url); } @@ -183,7 +183,7 @@ HTTPClientReceiver::message_callback(SoupSession* session, SoupMessage* msg, voi LOG(error) << "Empty response" << endl; } else { Glib::Mutex::Lock lock(me->_mutex); - me->_target->response_ok(0); + me->_target->response(0, SUCCESS); me->_world->parser()->parse_string( me->_world, me->_target.get(), diff --git a/src/http/HTTPClientSender.cpp b/src/http/HTTPClientSender.cpp index 979d1e64..ea983ca4 100644 --- a/src/http/HTTPClientSender.cpp +++ b/src/http/HTTPClientSender.cpp @@ -36,14 +36,12 @@ namespace Ingen { namespace Server { void -HTTPClientSender::response_ok(int32_t id) +HTTPClientSender::response(int32_t id, Status status) { -} - -void -HTTPClientSender::response_error(int32_t id, const std::string& msg) -{ - warn << "HTTP Error " << id << " (" << msg << ")" << endl; + if (status) { + warn << "HTTP Error " << id + << " (" << ingen_status_string(status) << ")" << endl; + } } void diff --git a/src/http/HTTPClientSender.hpp b/src/http/HTTPClientSender.hpp index 761a60a6..c0af96df 100644 --- a/src/http/HTTPClientSender.hpp +++ b/src/http/HTTPClientSender.hpp @@ -63,8 +63,7 @@ public: /* *** ClientInterface Implementation Below *** */ - void response_ok(int32_t id); - void response_error(int32_t id, const std::string& msg); + void response(int32_t id, Status status); void error(const std::string& msg); diff --git a/src/osc/OSCClientReceiver.cpp b/src/osc/OSCClientReceiver.cpp index 249cf2a4..a0cd58b7 100644 --- a/src/osc/OSCClientReceiver.cpp +++ b/src/osc/OSCClientReceiver.cpp @@ -137,8 +137,7 @@ OSCClientReceiver::setup_callbacks() if (!_target) return; - lo_server_thread_add_method(_st, "/ok", "i", response_ok_cb, this); - lo_server_thread_add_method(_st, "/error", "is", response_error_cb, this); + lo_server_thread_add_method(_st, "/response", "ii", response_cb, this); lo_server_thread_add_method(_st, "/plugin", "sss", plugin_cb, this); lo_server_thread_add_method(_st, "/put", NULL, put_cb, this); lo_server_thread_add_method(_st, "/delta_begin", NULL, delta_begin_cb, this); @@ -282,20 +281,10 @@ OSCClientReceiver::_activity_cb(const char* path, const char* types, lo_arg** ar } int -OSCClientReceiver::_response_ok_cb(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg) +OSCClientReceiver::_response_cb(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg) { - assert(!strcmp(types, "i")); - _target->response_ok(argv[0]->i); - - return 0; -} - -int -OSCClientReceiver::_response_error_cb(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg) -{ - assert(!strcmp(types, "is")); - _target->response_error(argv[0]->i, &argv[1]->s); - + assert(!strcmp(types, "ii")); + _target->response(argv[0]->i, (Status)argv[1]->i); return 0; } diff --git a/src/osc/OSCClientReceiver.hpp b/src/osc/OSCClientReceiver.hpp index 46afc81a..a04ed5f5 100644 --- a/src/osc/OSCClientReceiver.hpp +++ b/src/osc/OSCClientReceiver.hpp @@ -66,8 +66,7 @@ private: int _listen_port; LO_HANDLER(OSCClientReceiver, error); - LO_HANDLER(OSCClientReceiver, response_ok); - LO_HANDLER(OSCClientReceiver, response_error); + LO_HANDLER(OSCClientReceiver, response); LO_HANDLER(OSCClientReceiver, plugin); LO_HANDLER(OSCClientReceiver, plugin_list_end); LO_HANDLER(OSCClientReceiver, new_patch); diff --git a/src/osc/OSCClientSender.cpp b/src/osc/OSCClientSender.cpp index a0b7979c..1a6289f4 100644 --- a/src/osc/OSCClientSender.cpp +++ b/src/osc/OSCClientSender.cpp @@ -39,41 +39,22 @@ namespace Server { */ /** @page client_osc_namespace - * <h2>/ok</h2> + * <h2>/response</h2> * @arg @p response-id :: Integer + * @arg @p status :: Integer * * @par - * Successful response to some command. + * Response to some command. */ void -OSCClientSender::response_ok(int32_t id) -{ - if (!_enabled) - return; - - if (lo_send(_address, "/ok", "i", id, LO_ARGS_END) < 0) { - Raul::error << "Unable to send OK " << id << "! (" - << lo_address_errstr(_address) << ")" << endl; - } -} - -/** @page client_osc_namespace - * <h2>/error</h2> - * @arg @p response-id :: Integer - * @arg @p message :: String - * - * @par - * Unsuccessful response to some command. - */ -void -OSCClientSender::response_error(int32_t id, const std::string& msg) +OSCClientSender::response(int32_t id, Status status) { if (!_enabled) return; - if (lo_send(_address, "/error", "is", id, msg.c_str(), LO_ARGS_END) < 0) { - Raul::error << "Unable to send error " << id << "! (" - << lo_address_errstr(_address) << ")" << endl; + if (lo_send(_address, "/response", "ii", id, status, LO_ARGS_END) < 0) { + Raul::error << "Unable to send response " << id << "! (" + << lo_address_errstr(_address) << ")" << endl; } } diff --git a/src/osc/OSCClientSender.hpp b/src/osc/OSCClientSender.hpp index c391e54a..67e76fee 100644 --- a/src/osc/OSCClientSender.hpp +++ b/src/osc/OSCClientSender.hpp @@ -66,8 +66,7 @@ public: /* *** ClientInterface Implementation Below *** */ - void response_ok(int32_t id); - void response_error(int32_t id, const std::string& msg); + void response(int32_t id, Status status); void error(const std::string& msg); diff --git a/src/server/ClientBroadcaster.hpp b/src/server/ClientBroadcaster.hpp index 3d49dc4a..c406bc49 100644 --- a/src/server/ClientBroadcaster.hpp +++ b/src/server/ClientBroadcaster.hpp @@ -115,10 +115,9 @@ public: Raul::URI uri() const { return "http://drobilla.net/ns/ingen#broadcaster"; } ///< N/A - void response_ok(int32_t id) {} ///< N/A - void response_error(int32_t id, const std::string& msg) {} ///< N/A + void response(int32_t id, Status status) {} ///< N/A - void error(const std::string& msg) { BROADCAST(error, msg); } + void error(const std::string& msg) { BROADCAST(error, msg); } void activity(const Raul::Path& path, const Raul::Atom& value) { diff --git a/src/server/Event.cpp b/src/server/Event.cpp index 76932550..95d0d052 100644 --- a/src/server/Event.cpp +++ b/src/server/Event.cpp @@ -63,18 +63,10 @@ Event::post_process() } void -Event::respond_ok() +Event::respond(Status status) { if (_request_client) { - _request_client->response_ok(_request_id); - } -} - -void -Event::respond_error(const std::string& msg) -{ - if (_request_client) { - _request_client->response_error(_request_id, msg); + _request_client->response(_request_id, status); } } diff --git a/src/server/Event.hpp b/src/server/Event.hpp index 5f9234bd..9572610c 100644 --- a/src/server/Event.hpp +++ b/src/server/Event.hpp @@ -24,6 +24,8 @@ #include "raul/Path.hpp" #include "raul/SharedPtr.hpp" +#include "ingen/Status.hpp" + #include "types.hpp" namespace Ingen { @@ -73,14 +75,11 @@ public: /** Set the next event to be processed after this one. */ void next(Event* ev) { _next = ev; } - /** Return the error status of this event. */ - int error() const { return _error; } - - /** Respond to the originating client successfully. */ - void respond_ok(); + /** Return the status (success or error code) of this event. */ + Status status() const { return _status; } - /** Respond to the originating client with an error. */ - void respond_error(const std::string& msg); + /** Respond to the originating client. */ + void respond(Status status); protected: Event(Engine& engine, ClientInterface* client, int32_t id, FrameTime time) @@ -88,7 +87,7 @@ protected: , _request_client(client) , _request_id(id) , _time(time) - , _error(0) // success + , _status(SUCCESS) , _pre_processed(false) , _executed(false) {} @@ -99,7 +98,7 @@ protected: , _request_client(NULL) , _request_id(-1) , _time(0) - , _error(0) // success + , _status(SUCCESS) , _pre_processed(false) , _executed(false) {} @@ -109,7 +108,7 @@ protected: ClientInterface* _request_client; int32_t _request_id; FrameTime _time; - int _error; + Status _status; bool _pre_processed; bool _executed; }; diff --git a/src/server/ServerInterfaceImpl.cpp b/src/server/ServerInterfaceImpl.cpp index 7715019f..cf08a8de 100644 --- a/src/server/ServerInterfaceImpl.cpp +++ b/src/server/ServerInterfaceImpl.cpp @@ -136,7 +136,7 @@ ServerInterfaceImpl::del(const URI& uri) { if (uri == "ingen:engine") { if (_request_client) { - _request_client->response_ok(_request_id); + _request_client->response(_request_id, SUCCESS); } _engine.quit(); } else { diff --git a/src/server/events/Connect.cpp b/src/server/events/Connect.cpp index 7a4dae0a..0cdd78dd 100644 --- a/src/server/events/Connect.cpp +++ b/src/server/events/Connect.cpp @@ -67,7 +67,7 @@ Connect::pre_process() PortImpl* src_port = _engine.engine_store()->find_port(_src_port_path); PortImpl* dst_port = _engine.engine_store()->find_port(_dst_port_path); if (!src_port || !dst_port) { - _error = PORT_NOT_FOUND; + _status = PORT_NOT_FOUND; Event::pre_process(); return; } @@ -75,7 +75,7 @@ Connect::pre_process() _dst_input_port = dynamic_cast<InputPort*>(dst_port); _src_output_port = dynamic_cast<OutputPort*>(src_port); if (!_dst_input_port || !_src_output_port) { - _error = DIRECTION_MISMATCH; + _status = DIRECTION_MISMATCH; Event::pre_process(); return; } @@ -83,7 +83,7 @@ Connect::pre_process() NodeImpl* const src_node = src_port->parent_node(); NodeImpl* const dst_node = dst_port->parent_node(); if (!src_node || !dst_node) { - _error = PARENTS_NOT_FOUND; + _status = PARENT_NOT_FOUND; Event::pre_process(); return; } @@ -91,13 +91,13 @@ Connect::pre_process() if (src_node->parent() != dst_node->parent() && src_node != dst_node->parent() && src_node->parent() != dst_node) { - _error = PARENT_PATCH_DIFFERENT; + _status = PARENT_DIFFERS; Event::pre_process(); return; } if (!ConnectionImpl::can_connect(_src_output_port, _dst_input_port)) { - _error = TYPE_MISMATCH; + _status = TYPE_MISMATCH; Event::pre_process(); return; } @@ -120,7 +120,7 @@ Connect::pre_process() } if (_patch->has_connection(_src_output_port, _dst_input_port)) { - _error = ALREADY_CONNECTED; + _status = EXISTS; Event::pre_process(); return; } @@ -161,7 +161,7 @@ Connect::execute(ProcessContext& context) { Event::execute(context); - if (_error == NO_ERROR) { + if (_status == SUCCESS) { // This must be inserted here, since they're actually used by the audio thread _dst_input_port->add_connection(_connection.get()); assert(_buffers); @@ -175,34 +175,10 @@ Connect::execute(ProcessContext& context) void Connect::post_process() { - std::ostringstream ss; - if (_error == NO_ERROR) { - respond_ok(); + respond(_status); + if (!_status) { _engine.broadcaster()->connect(_src_port_path, _dst_port_path); - return; - } - - ss << boost::format("Unable to make connection %1% -> %2% (") - % _src_port_path.chop_scheme() % _dst_port_path.chop_scheme(); - - switch (_error) { - case PARENT_PATCH_DIFFERENT: - ss << "Ports have mismatched parents"; break; - case PORT_NOT_FOUND: - ss << "Port not found"; break; - case TYPE_MISMATCH: - ss << "Type mismatch"; break; - case DIRECTION_MISMATCH: - ss << "Direction mismatch"; break; - case ALREADY_CONNECTED: - ss << "Already connected"; break; - case PARENTS_NOT_FOUND: - ss << "Parents not found"; break; - default: - ss << "Unknown error"; } - ss << ")"; - respond_error(ss.str()); } } // namespace Events diff --git a/src/server/events/Connect.hpp b/src/server/events/Connect.hpp index 92f8bcf4..c1218865 100644 --- a/src/server/events/Connect.hpp +++ b/src/server/events/Connect.hpp @@ -61,16 +61,6 @@ public: void post_process(); private: - enum ErrorType { - NO_ERROR, - PARENT_PATCH_DIFFERENT, - PORT_NOT_FOUND, - TYPE_MISMATCH, - DIRECTION_MISMATCH, - ALREADY_CONNECTED, - PARENTS_NOT_FOUND - }; - Raul::Path _src_port_path; Raul::Path _dst_port_path; diff --git a/src/server/events/CreateNode.cpp b/src/server/events/CreateNode.cpp index 04fef8b1..5fe7a86f 100644 --- a/src/server/events/CreateNode.cpp +++ b/src/server/events/CreateNode.cpp @@ -96,8 +96,9 @@ CreateNode::pre_process() } } - if (!_node) - _error = 1; + if (!_node) { + _status = FAILURE; + } Event::pre_process(); } @@ -116,22 +117,16 @@ CreateNode::execute(ProcessContext& context) void CreateNode::post_process() { - string msg; if (_node_already_exists) { - msg = string("Could not create node - ").append(_path.str());// + " already exists."; - respond_error(msg); - } else if (_patch == NULL) { - msg = "Could not find patch '" + _path.parent().str() +"' to add node."; - respond_error(msg); - } else if (_plugin == NULL) { - msg = "Unable to load node "; - msg += _path.str() + " (you're missing the plugin " + _plugin_uri.str() + ")"; - respond_error(msg); - } else if (_node == NULL) { - msg = "Failed to instantiate plugin " + _plugin_uri.str(); - respond_error(msg); + respond(EXISTS); + } else if (!_patch) { + respond(PARENT_NOT_FOUND); + } else if (!_plugin) { + respond(PLUGIN_NOT_FOUND); + } else if (!_node) { + respond(FAILURE); } else { - respond_ok(); + respond(SUCCESS); _engine.broadcaster()->send_object(_node, true); // yes, send ports } } diff --git a/src/server/events/CreatePatch.cpp b/src/server/events/CreatePatch.cpp index eda05ccd..6e261755 100644 --- a/src/server/events/CreatePatch.cpp +++ b/src/server/events/CreatePatch.cpp @@ -55,13 +55,13 @@ void CreatePatch::pre_process() { if (_path.is_root() || _engine.engine_store()->find_object(_path) != NULL) { - _error = OBJECT_EXISTS; + _status = EXISTS; Event::pre_process(); return; } if (_poly < 1) { - _error = INVALID_POLY; + _status = INVALID_POLY; Event::pre_process(); return; } @@ -70,7 +70,7 @@ CreatePatch::pre_process() _parent = _engine.engine_store()->find_patch(path.parent()); if (_parent == NULL) { - _error = PARENT_NOT_FOUND; + _status = PARENT_NOT_FOUND; Event::pre_process(); return; } @@ -126,32 +126,11 @@ CreatePatch::execute(ProcessContext& context) void CreatePatch::post_process() { - string msg; - switch (_error) { - case NO_ERROR: - respond_ok(); + respond(_status); + if (!_status) { // Don't send ports/nodes that have been added since prepare() // (otherwise they would be sent twice) _engine.broadcaster()->send_object(_patch, false); - break; - case OBJECT_EXISTS: - respond_ok(); - /*string msg = "Unable to create patch: "; - msg.append(_path).append(" already exists."); - respond_error(msg);*/ - break; - case PARENT_NOT_FOUND: - msg = "Unable to create patch: Parent "; - msg.append(Path(_path).parent().str()).append(" not found."); - respond_error(msg); - break; - case INVALID_POLY: - msg = "Unable to create patch "; - msg.append(_path.str()).append(": ").append("Invalid polyphony requested."); - respond_error(msg); - break; - default: - respond_error("Unable to load patch."); } } diff --git a/src/server/events/CreatePatch.hpp b/src/server/events/CreatePatch.hpp index 4addd524..66a81c20 100644 --- a/src/server/events/CreatePatch.hpp +++ b/src/server/events/CreatePatch.hpp @@ -49,8 +49,6 @@ public: void post_process(); private: - enum ErrorType { NO_ERROR, OBJECT_EXISTS, PARENT_NOT_FOUND, INVALID_POLY }; - const Raul::Path _path; PatchImpl* _patch; PatchImpl* _parent; diff --git a/src/server/events/CreatePort.cpp b/src/server/events/CreatePort.cpp index 9c519981..5080fb79 100644 --- a/src/server/events/CreatePort.cpp +++ b/src/server/events/CreatePort.cpp @@ -84,14 +84,14 @@ CreatePort::CreatePort(Engine& engine, } if (_data_type == PortType::UNKNOWN) { - _error = UNKNOWN_TYPE; + _status = UNKNOWN_TYPE; } } void CreatePort::pre_process() { - if (_error == UNKNOWN_TYPE || _engine.engine_store()->find_object(_path)) { + if (_status == UNKNOWN_TYPE || _engine.engine_store()->find_object(_path)) { Event::pre_process(); return; } @@ -115,7 +115,7 @@ CreatePort::pre_process() } else if (index_i->second.type() != Atom::INT || index_i->second.get_int32() != static_cast<int32_t>(old_num_ports)) { Event::pre_process(); - _error = BAD_INDEX; + _status = BAD_INDEX; return; } @@ -151,7 +151,7 @@ CreatePort::pre_process() assert(_ports_array->size() == _patch->num_ports()); } else { - _error = CREATION_FAILED; + _status = CREATION_FAILED; } } Event::pre_process(); @@ -175,24 +175,9 @@ CreatePort::execute(ProcessContext& context) void CreatePort::post_process() { - string msg; - switch (_error) { - case NO_ERROR: - respond_ok(); + respond(_status); + if (!_status) { _engine.broadcaster()->send_object(_patch_port, true); - break; - case BAD_INDEX: - msg = string("Could not create port ") + _path.str() + " (Illegal index given)"; - respond_error(msg); - break; - case UNKNOWN_TYPE: - msg = string("Could not create port ") + _path.str() + " (Unknown type)"; - respond_error(msg); - break; - case CREATION_FAILED: - msg = string("Could not create port ") + _path.str() + " (Creation failed)"; - respond_error(msg); - break; } } diff --git a/src/server/events/CreatePort.hpp b/src/server/events/CreatePort.hpp index 4113611f..fec23f0d 100644 --- a/src/server/events/CreatePort.hpp +++ b/src/server/events/CreatePort.hpp @@ -55,13 +55,6 @@ public: void post_process(); private: - enum ErrorType { - NO_ERROR, - UNKNOWN_TYPE, - BAD_INDEX, - CREATION_FAILED - }; - Raul::Path _path; Raul::URI _type; PortType _data_type; diff --git a/src/server/events/Deactivate.hpp b/src/server/events/Deactivate.hpp index b99a2568..33264795 100644 --- a/src/server/events/Deactivate.hpp +++ b/src/server/events/Deactivate.hpp @@ -40,7 +40,7 @@ public: {} void post_process() { - respond_ok(); + respond(SUCCESS); _engine.deactivate(); } }; diff --git a/src/server/events/Delete.cpp b/src/server/events/Delete.cpp index 53d77379..7138a40d 100644 --- a/src/server/events/Delete.cpp +++ b/src/server/events/Delete.cpp @@ -173,15 +173,13 @@ Delete::post_process() if (!Raul::Path::is_path(_uri) || _path.is_root() || _path == "path:/control_in" || _path == "path:/control_out") { - // XXX: Just ignore? - //respond_error(_path.chop_scheme() + " can not be deleted"); + // XXX: Report error? Silently ignore? } else if (!_node && !_port) { - string msg = string("Could not find object ") + _path.chop_scheme() + " to delete"; - respond_error(msg); + respond(NOT_FOUND); } else if (_patch_node_listnode) { assert(_node); _node->deactivate(); - respond_ok(); + respond(SUCCESS); _engine.broadcaster()->bundle_begin(); if (_disconnect_event) _disconnect_event->post_process(); @@ -190,7 +188,7 @@ Delete::post_process() _engine.maid()->push(_patch_node_listnode); } else if (_patch_port_listnode) { assert(_port); - respond_ok(); + respond(SUCCESS); _engine.broadcaster()->bundle_begin(); if (_disconnect_event) _disconnect_event->post_process(); @@ -198,7 +196,7 @@ Delete::post_process() _engine.broadcaster()->bundle_end(); _engine.maid()->push(_patch_port_listnode); } else { - respond_error("Unable to delete object " + _path.chop_scheme()); + respond(FAILURE); } if (_driver_port) diff --git a/src/server/events/Disconnect.cpp b/src/server/events/Disconnect.cpp index 01313208..81528d7c 100644 --- a/src/server/events/Disconnect.cpp +++ b/src/server/events/Disconnect.cpp @@ -119,7 +119,7 @@ Disconnect::pre_process() if (_src_port_path.parent().parent() != _dst_port_path.parent().parent() && _src_port_path.parent() != _dst_port_path.parent().parent() && _src_port_path.parent().parent() != _dst_port_path.parent()) { - _error = PARENT_PATCH_DIFFERENT; + _status = PARENT_DIFFERS; Event::pre_process(); return; } @@ -128,7 +128,7 @@ Disconnect::pre_process() _dst_port = _engine.engine_store()->find_port(_dst_port_path); if (_src_port == NULL || _dst_port == NULL) { - _error = PORT_NOT_FOUND; + _status = PORT_NOT_FOUND; Event::pre_process(); return; } @@ -157,13 +157,13 @@ Disconnect::pre_process() assert(_patch); if (!_patch->has_connection(_src_port, _dst_port)) { - _error = NOT_CONNECTED; + _status = NOT_FOUND; Event::pre_process(); return; } if (src_node == NULL || dst_node == NULL) { - _error = PARENTS_NOT_FOUND; + _status = PARENT_NOT_FOUND; Event::pre_process(); return; } @@ -213,9 +213,9 @@ Disconnect::execute(ProcessContext& context) { Event::execute(context); - if (_error == NO_ERROR) { + if (_status == SUCCESS) { if (!_impl->execute(context, true)) { - _error = CONNECTION_NOT_FOUND; + _status = NOT_FOUND; return; } @@ -227,37 +227,9 @@ Disconnect::execute(ProcessContext& context) void Disconnect::post_process() { - if (_error == NO_ERROR) { - respond_ok(); + respond(_status); + if (!_status) { _engine.broadcaster()->disconnect(_src_port->path(), _dst_port->path()); - } else { - string msg("Unable to disconnect "); - msg.append(_src_port_path.str() + " => " + _dst_port_path.str()); - msg.append(" ("); - switch (_error) { - case PARENT_PATCH_DIFFERENT: - msg.append("Ports exist in different patches"); - break; - case PORT_NOT_FOUND: - msg.append("Port not found"); - break; - case TYPE_MISMATCH: - msg.append("Ports have incompatible types"); - break; - case NOT_CONNECTED: - msg.append("Ports are not connected"); - break; - case PARENTS_NOT_FOUND: - msg.append("Parent node not found"); - break; - case CONNECTION_NOT_FOUND: - msg.append("Connection not found"); - break; - default: - break; - } - msg.append(")"); - respond_error(msg); } delete _impl; diff --git a/src/server/events/Disconnect.hpp b/src/server/events/Disconnect.hpp index 7b26e90c..726f5a98 100644 --- a/src/server/events/Disconnect.hpp +++ b/src/server/events/Disconnect.hpp @@ -78,16 +78,6 @@ public: }; private: - enum ErrorType { - NO_ERROR, - PARENT_PATCH_DIFFERENT, - PORT_NOT_FOUND, - TYPE_MISMATCH, - NOT_CONNECTED, - PARENTS_NOT_FOUND, - CONNECTION_NOT_FOUND - }; - const Raul::Path _src_port_path; const Raul::Path _dst_port_path; diff --git a/src/server/events/DisconnectAll.cpp b/src/server/events/DisconnectAll.cpp index 7bd9ee96..1538c93b 100644 --- a/src/server/events/DisconnectAll.cpp +++ b/src/server/events/DisconnectAll.cpp @@ -94,22 +94,21 @@ DisconnectAll::pre_process() _parent = _engine.engine_store()->find_patch(_parent_path); if (_parent == NULL) { - _error = PARENT_NOT_FOUND; + _status = PARENT_NOT_FOUND; Event::pre_process(); return; } GraphObjectImpl* object = _engine.engine_store()->find_object(_path); - - if (object == NULL) { - _error = OBJECT_NOT_FOUND; + if (!object) { + _status = NOT_FOUND; Event::pre_process(); return; } if (object->parent_patch() != _parent && object->parent()->parent_patch() != _parent) { - _error = INVALID_PARENT_PATH; + _status = INVALID_PARENT_PATH; Event::pre_process(); return; } @@ -159,7 +158,7 @@ DisconnectAll::execute(ProcessContext& context) { Event::execute(context); - if (_error == NO_ERROR) { + if (_status == SUCCESS) { for (Impls::iterator i = _impls.begin(); i != _impls.end(); ++i) { (*i)->execute(context, !_deleting || ((*i)->dst_port()->parent_node() != _node)); @@ -173,25 +172,9 @@ DisconnectAll::execute(ProcessContext& context) void DisconnectAll::post_process() { - if (_error == NO_ERROR) { - respond_ok(); + respond(_status); + if (!_status) { _engine.broadcaster()->disconnect_all(_parent_path, _path); - } else { - boost::format fmt("Unable to disconnect %1% (%2%)"); - fmt % _path; - switch (_error) { - case INVALID_PARENT_PATH: - fmt % string("Invalid parent path: ").append(_parent_path.str()); - break; - case PARENT_NOT_FOUND: - fmt % string("Unable to find parent: ").append(_parent_path.str()); - break; - case OBJECT_NOT_FOUND: - fmt % string("Unable to find object"); - default: - break; - } - respond_error(fmt.str()); } } diff --git a/src/server/events/DisconnectAll.hpp b/src/server/events/DisconnectAll.hpp index d3f84e96..e3cd2490 100644 --- a/src/server/events/DisconnectAll.hpp +++ b/src/server/events/DisconnectAll.hpp @@ -62,13 +62,6 @@ public: void post_process(); private: - enum ErrorType { - NO_ERROR, - INVALID_PARENT_PATH, - PARENT_NOT_FOUND, - OBJECT_NOT_FOUND, - }; - Raul::Path _parent_path; Raul::Path _path; PatchImpl* _parent; diff --git a/src/server/events/Get.cpp b/src/server/events/Get.cpp index c13054dc..08ac3e10 100644 --- a/src/server/events/Get.cpp +++ b/src/server/events/Get.cpp @@ -63,14 +63,14 @@ void Get::post_process() { if (_uri == "ingen:plugins") { - respond_ok(); + respond(SUCCESS); if (_request_client) { _engine.broadcaster()->send_plugins_to(_request_client, _plugins); } } else if (!_object && !_plugin) { - respond_error("Unable to find object requested."); + respond(NOT_FOUND); } else if (_request_client) { - respond_ok(); + respond(SUCCESS); if (_request_client) { if (_object) { ObjectSender::send_object(_request_client, _object, true); @@ -79,7 +79,7 @@ Get::post_process() } } } else { - respond_error("Unable to find client to send object."); + respond(CLIENT_NOT_FOUND); } _lock.release(); diff --git a/src/server/events/Move.cpp b/src/server/events/Move.cpp index 3991e636..878f21f0 100644 --- a/src/server/events/Move.cpp +++ b/src/server/events/Move.cpp @@ -58,19 +58,19 @@ Move::pre_process() Glib::RWLock::WriterLock lock(_engine.engine_store()->lock()); if (!_old_path.parent().is_parent_of(_new_path)) { - _error = PARENT_DIFFERS; + _status = PARENT_DIFFERS; Event::pre_process(); return; } _store_iterator = _engine.engine_store()->find(_old_path); if (_store_iterator == _engine.engine_store()->end()) { - _error = OBJECT_NOT_FOUND; + _status = NOT_FOUND; Event::pre_process(); return; } if (_engine.engine_store()->find_object(_new_path)) { - _error = OBJECT_EXISTS; + _status = EXISTS; Event::pre_process(); return; } @@ -115,22 +115,9 @@ Move::execute(ProcessContext& context) void Move::post_process() { - string msg = "Unable to rename object - "; - - if (_error == NO_ERROR) { - respond_ok(); + respond(_status); + if (!_status) { _engine.broadcaster()->move(_old_path, _new_path); - } else { - if (_error == OBJECT_EXISTS) - msg.append("Object already exists at ").append(_new_path.str()); - else if (_error == OBJECT_NOT_FOUND) - msg.append("Could not find object ").append(_old_path.str()); - else if (_error == OBJECT_NOT_RENAMABLE) - msg.append(_old_path.str()).append(" is not renamable"); - else if (_error == PARENT_DIFFERS) - msg.append(_new_path.str()).append(" is a child of a different patch"); - - respond_error(msg); } } diff --git a/src/server/events/Move.hpp b/src/server/events/Move.hpp index e8e99b25..4a167656 100644 --- a/src/server/events/Move.hpp +++ b/src/server/events/Move.hpp @@ -59,14 +59,6 @@ public: void post_process(); private: - enum ErrorType { - NO_ERROR, - OBJECT_NOT_FOUND, - OBJECT_EXISTS, - OBJECT_NOT_RENAMABLE, - PARENT_DIFFERS - }; - Raul::Path _old_path; Raul::Path _new_path; PatchImpl* _parent_patch; diff --git a/src/server/events/Ping.hpp b/src/server/events/Ping.hpp index 5017fd12..4a2a13dc 100644 --- a/src/server/events/Ping.hpp +++ b/src/server/events/Ping.hpp @@ -43,7 +43,7 @@ public: : Event(engine, client, id, timestamp) {} - void post_process() { respond_ok(); } + void post_process() { respond(SUCCESS); } }; } // namespace Server diff --git a/src/server/events/RegisterClient.cpp b/src/server/events/RegisterClient.cpp index a2c0b8be..c18afb72 100644 --- a/src/server/events/RegisterClient.cpp +++ b/src/server/events/RegisterClient.cpp @@ -48,7 +48,7 @@ RegisterClient::pre_process() void RegisterClient::post_process() { - respond_ok(); + respond(SUCCESS); /* Tell the client the engine's sample rate (which it needs to know to interpret control bounds for lv2:sampleRate ports). This is a bit of a diff --git a/src/server/events/SetMetadata.cpp b/src/server/events/SetMetadata.cpp index 720cf3ba..68bd24d5 100644 --- a/src/server/events/SetMetadata.cpp +++ b/src/server/events/SetMetadata.cpp @@ -112,7 +112,7 @@ SetMetadata::pre_process() : static_cast<Shared::ResourceImpl*>(_engine.node_factory()->plugin(_subject)); if (!_object && (!is_graph_object || !_create)) { - _error = NOT_FOUND; + _status = NOT_FOUND; Event::pre_process(); return; } @@ -144,7 +144,7 @@ SetMetadata::pre_process() // Grab the object for applying properties, if the create-event succeeded _object = _engine.engine_store()->find_object(Path(_subject.str())); } else { - _error = BAD_OBJECT_TYPE; + _status = BAD_OBJECT_TYPE; } } @@ -187,7 +187,7 @@ SetMetadata::pre_process() if (value.type() == Atom::BOOL) { op = ENABLE_BROADCAST; } else { - _error = BAD_VALUE_TYPE; + _status = BAD_VALUE_TYPE; } } else if (key == uris.ingen_value) { SetPortValue* ev = new SetPortValue( @@ -201,10 +201,10 @@ SetMetadata::pre_process() } else if (value.type() == Atom::DICT) { op = CONTROL_BINDING; } else { - _error = BAD_VALUE_TYPE; + _status = BAD_VALUE_TYPE; } } else { - _error = BAD_OBJECT_TYPE; + _status = BAD_OBJECT_TYPE; } } } else if ((_patch = dynamic_cast<PatchImpl*>(_object))) { @@ -215,14 +215,14 @@ SetMetadata::pre_process() if (value.get_bool() && !_patch->enabled()) _compiled_patch = _patch->compile(); } else { - _error = BAD_VALUE_TYPE; + _status = BAD_VALUE_TYPE; } } else if (key == uris.ingen_polyphony) { if (value.type() == Atom::INT) { op = POLYPHONY; _patch->prepare_internal_poly(*_engine.buffer_factory(), value.get_int32()); } else { - _error = BAD_VALUE_TYPE; + _status = BAD_VALUE_TYPE; } } } else if (key == uris.ingen_polyphonic) { @@ -240,15 +240,15 @@ SetMetadata::pre_process() obj->prepare_poly(*_engine.buffer_factory(), 1); } } else { - _error = BAD_VALUE_TYPE; + _status = BAD_VALUE_TYPE; } } else { - _error = BAD_OBJECT_TYPE; + _status = BAD_OBJECT_TYPE; } } } - if (_error != NO_ERROR) { + if (_status != SUCCESS) { _error_predicate += key.str(); break; } @@ -266,7 +266,7 @@ SetMetadata::pre_process() void SetMetadata::execute(ProcessContext& context) { - if (_error != NO_ERROR) { + if (_status != SUCCESS) { Event::execute(context); return; } @@ -318,7 +318,7 @@ SetMetadata::execute(ProcessContext& context) !_patch->apply_internal_poly(_engine.driver()->context(), *_engine.buffer_factory(), *_engine.maid(), value.get_int32())) { - _error = INTERNAL; + _status = INTERNAL_ERROR; } break; case CONTROL_BINDING: @@ -351,34 +351,19 @@ SetMetadata::post_process() for (SetEvents::iterator i = _set_events.begin(); i != _set_events.end(); ++i) (*i)->post_process(); - switch (_error) { - case NO_ERROR: + if (!_status) { if (_create_event) { _create_event->post_process(); } else { - respond_ok(); - if (_create) + respond(SUCCESS); + if (_create) { _engine.broadcaster()->put(_subject, _properties, _context); - else + } else { _engine.broadcaster()->delta(_subject, _remove, _properties); + } } - break; - case NOT_FOUND: - respond_error((boost::format( - "Unable to find object `%1%'") % _subject).str()); - break; - case INTERNAL: - respond_error("Internal error"); - break; - case BAD_OBJECT_TYPE: - respond_error((boost::format( - "Bad type for object `%1%'") % _subject).str()); - break; - case BAD_VALUE_TYPE: - respond_error((boost::format( - "Bad metadata value type for subject `%1%' predicate `%2%'") - % _subject % _error_predicate).str()); - break; + } else { + respond(_status); } if (_create_event) { diff --git a/src/server/events/SetMetadata.hpp b/src/server/events/SetMetadata.hpp index 512e35c0..bcc3ab4f 100644 --- a/src/server/events/SetMetadata.hpp +++ b/src/server/events/SetMetadata.hpp @@ -86,14 +86,6 @@ public: void post_process(); private: - enum ErrorType { - NO_ERROR, - NOT_FOUND, - INTERNAL, - BAD_OBJECT_TYPE, - BAD_VALUE_TYPE - }; - enum SpecialType { NONE, ENABLE, diff --git a/src/server/events/SetPortValue.cpp b/src/server/events/SetPortValue.cpp index f96649b9..bc4cd9bf 100644 --- a/src/server/events/SetPortValue.cpp +++ b/src/server/events/SetPortValue.cpp @@ -84,7 +84,7 @@ SetPortValue::pre_process() if (_port == NULL) _port = _engine.engine_store()->find_port(_port_path); if (_port == NULL) - _error = PORT_NOT_FOUND; + _status = PORT_NOT_FOUND; } // Port is a message context port, set its value and @@ -123,20 +123,20 @@ void SetPortValue::apply(Context& context) { uint32_t start = context.start(); - if (_error == NO_ERROR && !_port) + if (_status == SUCCESS && !_port) _port = _engine.engine_store()->find_port(_port_path); if (!_port) { - if (_error == NO_ERROR) - _error = PORT_NOT_FOUND; + if (_status == SUCCESS) + _status = PORT_NOT_FOUND; /*} else if (_port->buffer(0)->capacity() < _data_size) { - _error = NO_SPACE;*/ + _status = NO_SPACE;*/ } else { Buffer* const buf = _port->buffer(0).get(); AudioBuffer* const abuf = dynamic_cast<AudioBuffer*>(buf); if (abuf) { if (_value.type() != Atom::FLOAT) { - _error = TYPE_MISMATCH; + _status = TYPE_MISMATCH; return; } @@ -192,31 +192,12 @@ SetPortValue::apply(Context& context) void SetPortValue::post_process() { - string msg; - std::ostringstream ss; - switch (_error) { - case NO_ERROR: - assert(_port != NULL); - respond_ok(); - _engine.broadcaster()->set_property(_port_path, - _engine.world()->uris()->ingen_value, _value); - break; - case TYPE_MISMATCH: - ss << "Illegal value type " << _value.type() - << " for port " << _port_path << endl; - respond_error(ss.str()); - break; - case PORT_NOT_FOUND: - msg = "Unable to find port "; - msg.append(_port_path.str()).append(" to set value"); - respond_error(msg); - break; - case NO_SPACE: - ss << "Attempt to write " << _value.data_size() << " bytes to " - << _port_path.str() << ", with capacity " - << _port->buffer_size() << endl; - respond_error(ss.str()); - break; + respond(_status); + if (!_status) { + _engine.broadcaster()->set_property( + _port_path, + _engine.world()->uris()->ingen_value, + _value); } } diff --git a/src/server/events/SetPortValue.hpp b/src/server/events/SetPortValue.hpp index 2ceb37f6..71764568 100644 --- a/src/server/events/SetPortValue.hpp +++ b/src/server/events/SetPortValue.hpp @@ -65,13 +65,6 @@ public: void post_process(); private: - enum ErrorType { - NO_ERROR, - PORT_NOT_FOUND, - NO_SPACE, - TYPE_MISMATCH - }; - void apply(Context& context); bool _queued; @@ -81,8 +74,8 @@ private: ControlBindings::Key _binding; }; +} // namespace Events } // namespace Server } // namespace Ingen -} // namespace Events #endif // INGEN_EVENTS_SETPORTVALUE_HPP diff --git a/src/server/events/UnregisterClient.cpp b/src/server/events/UnregisterClient.cpp index 64c37fb8..a673c25a 100644 --- a/src/server/events/UnregisterClient.cpp +++ b/src/server/events/UnregisterClient.cpp @@ -39,10 +39,11 @@ UnregisterClient::UnregisterClient(Engine& engine, void UnregisterClient::post_process() { - if (_engine.broadcaster()->unregister_client(_uri)) - respond_ok(); - else - respond_error("Unable to unregister client"); + if (_engine.broadcaster()->unregister_client(_uri)) { + respond(SUCCESS); + } else { + respond(FAILURE); + } } } // namespace Server |