diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/engine/HTTPEngineReceiver.cpp | 64 | ||||
-rw-r--r-- | src/libs/shared/Makefile.am | 7 | ||||
-rw-r--r-- | src/libs/shared/Store.hpp | 6 | ||||
-rw-r--r-- | src/progs/ingen/main.cpp | 11 |
4 files changed, 54 insertions, 34 deletions
diff --git a/src/libs/engine/HTTPEngineReceiver.cpp b/src/libs/engine/HTTPEngineReceiver.cpp index 128b9e13..3c1f7333 100644 --- a/src/libs/engine/HTTPEngineReceiver.cpp +++ b/src/libs/engine/HTTPEngineReceiver.cpp @@ -95,45 +95,55 @@ HTTPEngineReceiver::message_callback(SoupServer* server, SoupMessage* msg, const { HTTPEngineReceiver* me = (HTTPEngineReceiver*)data; - if (msg->method != SOUP_METHOD_GET) { + if (msg->method != SOUP_METHOD_GET && msg->method != SOUP_METHOD_PUT) { soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED); return; } - SharedPtr<Serialiser> serialiser = me->_engine.world()->serialiser; - if (!serialiser) { - soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR); - return; - } - - // FIXME: not thread safe! - SharedPtr<Store> store = me->_engine.world()->store; assert(store); if (!Path::is_valid(path)) { soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST); return; } + + if (msg->method == SOUP_METHOD_GET) { + Glib::RWLock::ReaderLock lock(store->lock()); + + // Find object + Store::const_iterator start = store->find(path); + if (start == store->end()) { + soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND); + return; + } + + // Get serialiser + SharedPtr<Serialiser> serialiser = me->_engine.world()->serialiser; + if (!serialiser) { + soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR); + return; + } + + // Serialise object + string base_uri = string("ingen:").append(start->second->path()); + const string response = serialiser->to_string(start->second, base_uri, + GraphObject::Variables()); + soup_message_set_status (msg, SOUP_STATUS_OK); + soup_message_set_response (msg, "text/plain", SOUP_MEMORY_COPY, + response.c_str(), response.length()); - Store::const_iterator start = store->find(path); - if (start == store->end()) { - soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND); - return; + } else if (msg->method == SOUP_METHOD_PUT) { + Glib::RWLock::WriterLock lock(store->lock()); + + // Be sure object doesn't exist + Store::const_iterator start = store->find(path); + if (start != store->end()) { + soup_message_set_status (msg, SOUP_STATUS_CONFLICT); + return; + } + + soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED); } - -#if 0 - EngineStore::iterator end = store->find_descendants_end(start); - - string response; - for (EngineStore::iterator i = start; i != end; ++i) - response.append(i->first).append("\n"); -#endif - - const string response = serialiser->to_string(start->second, - "http://example.org/whatever", GraphObject::Variables()); - soup_message_set_status (msg, SOUP_STATUS_OK); - soup_message_set_response (msg, "text/plain", SOUP_MEMORY_COPY, - response.c_str(), response.length()); } diff --git a/src/libs/shared/Makefile.am b/src/libs/shared/Makefile.am index 6a073148..b7868bd1 100644 --- a/src/libs/shared/Makefile.am +++ b/src/libs/shared/Makefile.am @@ -1,6 +1,11 @@ noinst_LTLIBRARIES = libingen_shared.la -libingen_shared_la_CXXFLAGS = @INGEN_CFLAGS@ @REDLANDMM_CFLAGS@ @SLV2_CFLAGS@ @RAUL_CFLAGS@ +libingen_shared_la_CXXFLAGS = \ + @GLIBMM_CFLAGS@ \ + @INGEN_CFLAGS@ \ + @RAUL_CFLAGS@ \ + @REDLANDMM_CFLAGS@ \ + @SLV2_CFLAGS@ libingen_shared_la_SOURCES = \ LV2Features.cpp \ diff --git a/src/libs/shared/Store.hpp b/src/libs/shared/Store.hpp index ec29e7c0..f0a89024 100644 --- a/src/libs/shared/Store.hpp +++ b/src/libs/shared/Store.hpp @@ -19,6 +19,7 @@ #define COMMON_STORE_H #include <string> +#include <glibmm/thread.h> #include <raul/PathTable.hpp> #include "interface/GraphObject.hpp" @@ -39,6 +40,11 @@ public: SharedPtr<Shared::GraphObject> find_child(SharedPtr<Shared::GraphObject> parent, const std::string& child_name) const; + + Glib::RWLock& lock() { return _lock; } + +private: + Glib::RWLock _lock; }; diff --git a/src/progs/ingen/main.cpp b/src/progs/ingen/main.cpp index fe78468f..47f7a038 100644 --- a/src/progs/ingen/main.cpp +++ b/src/progs/ingen/main.cpp @@ -81,7 +81,6 @@ main(int argc, char** argv) SharedPtr<Glib::Module> client_module; SharedPtr<Glib::Module> gui_module; SharedPtr<Glib::Module> bindings_module; - SharedPtr<Glib::Module> serialisation_module; SharedPtr<Shared::EngineInterface> engine_interface; @@ -161,14 +160,14 @@ main(int argc, char** argv) parent_path = args.path_arg; bool found = false; - serialisation_module = Ingen::Shared::load_module("ingen_serialisation"); + world->serialisation_module = Ingen::Shared::load_module("ingen_serialisation"); Serialisation::Loader* (*new_loader)() = NULL; - if (serialisation_module) - found = serialisation_module->get_symbol("new_loader", (void*&)new_loader); + if (world->serialisation_module) + found = world->serialisation_module->get_symbol("new_loader", (void*&)new_loader); - if (serialisation_module && found) { + if (world->serialisation_module && found) { SharedPtr<Serialisation::Loader> loader(new_loader()); // Assumption: Containing ':' means URI, otherwise filename @@ -246,7 +245,7 @@ main(int argc, char** argv) engine_interface.reset(); client_module.reset(); - serialisation_module.reset(); + world->serialisation_module.reset(); gui_module.reset(); engine_module.reset(); |