diff options
author | David Robillard <d@drobilla.net> | 2008-08-16 04:29:57 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2008-08-16 04:29:57 +0000 |
commit | bf6f4d0a409ba76e65d375ef75533d6a6062a228 (patch) | |
tree | 9343fe271e8eeb731b80d954ae85d695e25dd667 /src/libs | |
parent | a8b36b5637acb3fa8eb29ef0f45bd11653f412fa (diff) | |
download | ingen-bf6f4d0a409ba76e65d375ef75533d6a6062a228.tar.gz ingen-bf6f4d0a409ba76e65d375ef75533d6a6062a228.tar.bz2 ingen-bf6f4d0a409ba76e65d375ef75533d6a6062a228.zip |
Only load one serialisation module, and store it in the world.
git-svn-id: http://svn.drobilla.net/lad/ingen@1398 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs')
-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 |
3 files changed, 49 insertions, 28 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; }; |