comparison Core/RestApi/RestApiHierarchy.cpp @ 975:c550e99c452b

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 30 Jun 2014 14:53:18 +0200
parents 83622b0f544c
children ce3106e5843f
comparison
equal deleted inserted replaced
974:83622b0f544c 975:c550e99c452b
30 **/ 30 **/
31 31
32 32
33 #include "RestApiHierarchy.h" 33 #include "RestApiHierarchy.h"
34 34
35 #include "../OrthancException.h"
36
35 #include <cassert> 37 #include <cassert>
36 38
37 namespace Orthanc 39 namespace Orthanc
38 { 40 {
39 RestApiHierarchy::Handlers::Handlers() : 41 RestApiHierarchy::Handlers::Handlers() :
161 child->RegisterInternal(path, handler, level + 1); 163 child->RegisterInternal(path, handler, level + 1);
162 } 164 }
163 } 165 }
164 166
165 167
166 bool RestApiHierarchy::LookupHandler(RestApiPath::Components& components, 168 bool RestApiHierarchy::LookupHandler(HttpHandler::Arguments& components,
167 const UriComponents& uri, 169 const UriComponents& uri,
168 ResourceCallback callback, 170 ResourceCallback callback,
169 size_t level, 171 size_t level,
170 void* call) 172 void* call)
171 { 173 {
196 198
197 // Try and go down in the hierarchy, using wildcard rules for children 199 // Try and go down in the hierarchy, using wildcard rules for children
198 for (child = wildcardChildren_.begin(); 200 for (child = wildcardChildren_.begin();
199 child != wildcardChildren_.end(); child++) 201 child != wildcardChildren_.end(); child++)
200 { 202 {
201 RestApiPath::Components subComponents = components; 203 HttpHandler::Arguments subComponents = components;
202 subComponents[child->first] = uri[level]; 204 subComponents[child->first] = uri[level];
203 205
204 if (child->second->LookupHandler(components, uri, callback, level + 1, call)) 206 if (child->second->LookupHandler(components, uri, callback, level + 1, call))
205 { 207 {
206 return true; 208 return true;
278 } 280 }
279 281
280 282
281 bool RestApiHierarchy::GetCallback(Handlers& handlers, 283 bool RestApiHierarchy::GetCallback(Handlers& handlers,
282 const UriComponents& uri, 284 const UriComponents& uri,
283 const RestApiPath::Components& components, 285 const HttpHandler::Arguments& components,
284 const UriComponents& trailing, 286 const UriComponents& trailing,
285 void* call) 287 void* call)
286 { 288 {
287 if (handlers.HasHandler(HttpMethod_Get)) 289 if (handlers.HasHandler(HttpMethod_Get))
288 { 290 {
296 } 298 }
297 299
298 300
299 bool RestApiHierarchy::PostCallback(Handlers& handlers, 301 bool RestApiHierarchy::PostCallback(Handlers& handlers,
300 const UriComponents& uri, 302 const UriComponents& uri,
301 const RestApiPath::Components& components, 303 const HttpHandler::Arguments& components,
302 const UriComponents& trailing, 304 const UriComponents& trailing,
303 void* call) 305 void* call)
304 { 306 {
305 if (handlers.HasHandler(HttpMethod_Post)) 307 if (handlers.HasHandler(HttpMethod_Post))
306 { 308 {
314 } 316 }
315 317
316 318
317 bool RestApiHierarchy::PutCallback(Handlers& handlers, 319 bool RestApiHierarchy::PutCallback(Handlers& handlers,
318 const UriComponents& uri, 320 const UriComponents& uri,
319 const RestApiPath::Components& components, 321 const HttpHandler::Arguments& components,
320 const UriComponents& trailing, 322 const UriComponents& trailing,
321 void* call) 323 void* call)
322 { 324 {
323 if (handlers.HasHandler(HttpMethod_Put)) 325 if (handlers.HasHandler(HttpMethod_Put))
324 { 326 {
332 } 334 }
333 335
334 336
335 bool RestApiHierarchy::DeleteCallback(Handlers& handlers, 337 bool RestApiHierarchy::DeleteCallback(Handlers& handlers,
336 const UriComponents& uri, 338 const UriComponents& uri,
337 const RestApiPath::Components& components, 339 const HttpHandler::Arguments& components,
338 const UriComponents& trailing, 340 const UriComponents& trailing,
339 void* call) 341 void* call)
340 { 342 {
341 if (handlers.HasHandler(HttpMethod_Delete)) 343 if (handlers.HasHandler(HttpMethod_Delete))
342 { 344 {
430 } 432 }
431 433
432 bool RestApiHierarchy::Handle(RestApiGetCall& call, 434 bool RestApiHierarchy::Handle(RestApiGetCall& call,
433 const UriComponents& uri) 435 const UriComponents& uri)
434 { 436 {
435 RestApiPath::Components components; 437 HttpHandler::Arguments components;
436 return LookupHandler(components, uri, GetCallback, 0, &call); 438 return LookupHandler(components, uri, GetCallback, 0, &call);
437 } 439 }
438 440
439 bool RestApiHierarchy::Handle(RestApiPutCall& call, 441 bool RestApiHierarchy::Handle(RestApiPutCall& call,
440 const UriComponents& uri) 442 const UriComponents& uri)
441 { 443 {
442 RestApiPath::Components components; 444 HttpHandler::Arguments components;
443 return LookupHandler(components, uri, PutCallback, 0, &call); 445 return LookupHandler(components, uri, PutCallback, 0, &call);
444 } 446 }
445 447
446 bool RestApiHierarchy::Handle(RestApiPostCall& call, 448 bool RestApiHierarchy::Handle(RestApiPostCall& call,
447 const UriComponents& uri) 449 const UriComponents& uri)
448 { 450 {
449 RestApiPath::Components components; 451 HttpHandler::Arguments components;
450 return LookupHandler(components, uri, PostCallback, 0, &call); 452 return LookupHandler(components, uri, PostCallback, 0, &call);
451 } 453 }
452 454
453 bool RestApiHierarchy::Handle(RestApiDeleteCall& call, 455 bool RestApiHierarchy::Handle(RestApiDeleteCall& call,
454 const UriComponents& uri) 456 const UriComponents& uri)
455 { 457 {
456 RestApiPath::Components components; 458 HttpHandler::Arguments components;
457 return LookupHandler(components, uri, DeleteCallback, 0, &call); 459 return LookupHandler(components, uri, DeleteCallback, 0, &call);
458 } 460 }
459 461
460 } 462 }