summaryrefslogtreecommitdiffstats
path: root/src/libs/engine
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-08-16 04:29:57 +0000
committerDavid Robillard <d@drobilla.net>2008-08-16 04:29:57 +0000
commitbf6f4d0a409ba76e65d375ef75533d6a6062a228 (patch)
tree9343fe271e8eeb731b80d954ae85d695e25dd667 /src/libs/engine
parenta8b36b5637acb3fa8eb29ef0f45bd11653f412fa (diff)
downloadingen-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/engine')
-rw-r--r--src/libs/engine/HTTPEngineReceiver.cpp64
1 files changed, 37 insertions, 27 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());
}