Mercurial > hg > orthanc
comparison Plugins/Engine/PluginsManager.cpp @ 894:690aeb4cb899 plugins
REST callbacks
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 16 Jun 2014 17:31:09 +0200 |
parents | f57802f8b4dc |
children | c4053ac5db04 |
comparison
equal
deleted
inserted
replaced
893:f57802f8b4dc | 894:690aeb4cb899 |
---|---|
30 **/ | 30 **/ |
31 | 31 |
32 | 32 |
33 #include "PluginsManager.h" | 33 #include "PluginsManager.h" |
34 | 34 |
35 #include "../../Core/Toolbox.h" | |
36 | |
35 #include <glog/logging.h> | 37 #include <glog/logging.h> |
36 #include <cassert> | 38 #include <cassert> |
37 #include <memory> | 39 #include <memory> |
38 #include <boost/filesystem.hpp> | 40 #include <boost/filesystem.hpp> |
39 | 41 |
142 static void LogInfo(const char* str) | 144 static void LogInfo(const char* str) |
143 { | 145 { |
144 LOG(INFO) << str; | 146 LOG(INFO) << str; |
145 } | 147 } |
146 | 148 |
147 static int32_t InvokeService(const char* serviceName, | 149 void PluginsManager::RegisterRestCallback(const OrthancPluginContext* context, |
148 const void* serviceParameters) | 150 const char* path, |
151 OrthancRestCallback callback) | |
149 { | 152 { |
150 // TODO | 153 // TODO |
151 return 0; | 154 LOG(INFO) << "Plugin has registered a REST callback on: " << path; |
152 } | 155 |
156 PluginsManager* manager = reinterpret_cast<PluginsManager*>(context->pimpl); | |
157 manager->restCallbacks_.push_back(callback); | |
158 | |
159 | |
160 const char* pp = "/hello/world"; | |
161 | |
162 UriComponents components; | |
163 Toolbox::SplitUriComponents(components, pp); | |
164 | |
165 OrthancRestUrl url; | |
166 url.path = pp; | |
167 | |
168 std::vector<const char*> c(components.size()); | |
169 for (unsigned int i = 0; i < components.size(); i++) | |
170 { | |
171 c[i] = components[i].c_str(); | |
172 } | |
173 | |
174 if (components.size() == 0) | |
175 { | |
176 url.components = NULL; | |
177 url.componentsSize = 0; | |
178 } | |
179 else | |
180 { | |
181 url.components = &c[0]; | |
182 url.componentsSize = components.size(); | |
183 } | |
184 | |
185 // TODO | |
186 url.parameters = NULL; | |
187 url.parametersSize = 0; | |
188 | |
189 callback(NULL, OrthancHttpMethod_Get, &url, NULL, 0); | |
190 } | |
191 | |
192 | |
193 static void AnswerBuffer(OrthancRestOutput* output, | |
194 const char* answer, | |
195 uint32_t answerSize, | |
196 const char* mimeType) | |
197 { | |
198 std::cout << "MIME " << mimeType << ": " << answer << std::endl; | |
199 } | |
200 | |
153 | 201 |
154 PluginsManager::PluginsManager() | 202 PluginsManager::PluginsManager() |
155 { | 203 { |
204 memset(&context_, 0, sizeof(context_)); | |
205 context_.pimpl = this; | |
156 context_.orthancVersion = ORTHANC_VERSION; | 206 context_.orthancVersion = ORTHANC_VERSION; |
157 context_.InvokeService = InvokeService; | 207 context_.FreeBuffer = ::free; |
158 context_.LogError = LogError; | 208 context_.LogError = LogError; |
159 context_.LogWarning = LogWarning; | 209 context_.LogWarning = LogWarning; |
160 context_.LogInfo = LogInfo; | 210 context_.LogInfo = LogInfo; |
211 context_.RegisterRestCallback = RegisterRestCallback; | |
212 context_.AnswerBuffer = AnswerBuffer; | |
161 } | 213 } |
162 | 214 |
163 PluginsManager::~PluginsManager() | 215 PluginsManager::~PluginsManager() |
164 { | 216 { |
165 for (Plugins::iterator it = plugins_.begin(); it != plugins_.end(); it++) | 217 for (Plugins::iterator it = plugins_.begin(); it != plugins_.end(); it++) |