comparison Plugins/Samples/Basic/Plugin.c @ 2981:eff50153a7b3 db-changes

integration mainline->db-changes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 Dec 2018 15:58:08 +0100
parents ccf61f6e22ef
children 5a6a2c5bf73f
comparison
equal deleted inserted replaced
2896:3fabf9a673f6 2981:eff50153a7b3
34 const OrthancPluginHttpRequest* request) 34 const OrthancPluginHttpRequest* request)
35 { 35 {
36 char buffer[1024]; 36 char buffer[1024];
37 uint32_t i; 37 uint32_t i;
38 38
39 if (request->method != OrthancPluginHttpMethod_Get)
40 {
41 // NB: Calling "OrthancPluginSendMethodNotAllowed(context, output, "GET");"
42 // is preferable. This is a sample to demonstrate "OrthancPluginSetHttpErrorDetails()".
43 OrthancPluginSetHttpErrorDetails(context, output, "This Callback1() can only be used by a GET call");
44 return OrthancPluginErrorCode_ParameterOutOfRange;
45 }
46
39 sprintf(buffer, "Callback on URL [%s] with body [%s]\n", url, request->body); 47 sprintf(buffer, "Callback on URL [%s] with body [%s]\n", url, request->body);
40 OrthancPluginLogWarning(context, buffer); 48 OrthancPluginLogWarning(context, buffer);
41 49
42 OrthancPluginSetCookie(context, output, "hello", "world"); 50 OrthancPluginSetCookie(context, output, "hello", "world");
43 OrthancPluginAnswerBuffer(context, output, buffer, strlen(buffer), "text/plain"); 51 OrthancPluginAnswerBuffer(context, output, buffer, strlen(buffer), "text/plain");
182 int isBuiltIn, error; 190 int isBuiltIn, error;
183 191
184 if (request->method != OrthancPluginHttpMethod_Get) 192 if (request->method != OrthancPluginHttpMethod_Get)
185 { 193 {
186 OrthancPluginSendMethodNotAllowed(context, output, "GET"); 194 OrthancPluginSendMethodNotAllowed(context, output, "GET");
187 return 0; 195 return OrthancPluginErrorCode_Success;
188 } 196 }
189 197
190 isBuiltIn = strcmp("plugins", request->groups[0]); 198 isBuiltIn = strcmp("plugins", request->groups[0]);
191 199
192 if (isBuiltIn) 200 if (isBuiltIn)
299 307
300 ORTHANC_PLUGINS_API OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType, 308 ORTHANC_PLUGINS_API OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType,
301 OrthancPluginResourceType resourceType, 309 OrthancPluginResourceType resourceType,
302 const char* resourceId) 310 const char* resourceId)
303 { 311 {
312 OrthancPluginMemoryBuffer tmp;
313 memset(&tmp, 0, sizeof(tmp));
314
304 char info[1024]; 315 char info[1024];
305 OrthancPluginMemoryBuffer tmp; 316 sprintf(info, "Change %d on resource %s of type %d", changeType,
306 317 (resourceId == NULL ? "<none>" : resourceId), resourceType);
307 sprintf(info, "Change %d on resource %s of type %d", changeType, resourceId, resourceType);
308 OrthancPluginLogWarning(context, info); 318 OrthancPluginLogWarning(context, info);
309 319
310 if (changeType == OrthancPluginChangeType_NewInstance) 320 switch (changeType)
311 { 321 {
312 sprintf(info, "/instances/%s/metadata/AnonymizedFrom", resourceId); 322 case OrthancPluginChangeType_NewInstance:
313 if (OrthancPluginRestApiGet(context, &tmp, info) == 0) 323 {
314 { 324 sprintf(info, "/instances/%s/metadata/AnonymizedFrom", resourceId);
315 sprintf(info, " Instance %s comes from the anonymization of instance", resourceId); 325 if (OrthancPluginRestApiGet(context, &tmp, info) == 0)
316 strncat(info, (const char*) tmp.data, tmp.size); 326 {
317 OrthancPluginLogWarning(context, info); 327 sprintf(info, " Instance %s comes from the anonymization of instance", resourceId);
328 strncat(info, (const char*) tmp.data, tmp.size);
329 OrthancPluginLogWarning(context, info);
330 OrthancPluginFreeMemoryBuffer(context, &tmp);
331 }
332
333 break;
334 }
335
336 case OrthancPluginChangeType_OrthancStarted:
337 {
338 /* Make REST requests to the built-in Orthanc API */
339 OrthancPluginRestApiGet(context, &tmp, "/changes");
318 OrthancPluginFreeMemoryBuffer(context, &tmp); 340 OrthancPluginFreeMemoryBuffer(context, &tmp);
319 } 341 OrthancPluginRestApiGet(context, &tmp, "/changes?limit=1");
342 OrthancPluginFreeMemoryBuffer(context, &tmp);
343
344 /* Play with PUT by defining a new target modality. */
345 sprintf(info, "[ \"STORESCP\", \"localhost\", 2000 ]");
346 OrthancPluginRestApiPut(context, &tmp, "/modalities/demo", info, strlen(info));
347
348 break;
349 }
350
351 case OrthancPluginChangeType_OrthancStopped:
352 OrthancPluginLogWarning(context, "Orthanc has stopped");
353 break;
354
355 default:
356 break;
320 } 357 }
321 358
322 return OrthancPluginErrorCode_Success; 359 return OrthancPluginErrorCode_Success;
323 } 360 }
324 361
355 } 392 }
356 393
357 394
358 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) 395 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
359 { 396 {
360 OrthancPluginMemoryBuffer tmp;
361 char info[1024], *s; 397 char info[1024], *s;
362 int counter, i; 398 int counter, i;
363 OrthancPluginDictionaryEntry entry; 399 OrthancPluginDictionaryEntry entry;
364 400
365 context = c; 401 context = c;
423 /* Declare several properties of the plugin */ 459 /* Declare several properties of the plugin */
424 OrthancPluginSetRootUri(context, "/plugin/hello"); 460 OrthancPluginSetRootUri(context, "/plugin/hello");
425 OrthancPluginSetDescription(context, "This is the description of the sample plugin that can be seen in Orthanc Explorer."); 461 OrthancPluginSetDescription(context, "This is the description of the sample plugin that can be seen in Orthanc Explorer.");
426 OrthancPluginExtendOrthancExplorer(context, "alert('Hello Orthanc! From sample plugin with love.');"); 462 OrthancPluginExtendOrthancExplorer(context, "alert('Hello Orthanc! From sample plugin with love.');");
427 463
428 /* Make REST requests to the built-in Orthanc API */ 464 customError = OrthancPluginRegisterErrorCode(context, 4, 402, "Hello world");
429 memset(&tmp, 0, sizeof(tmp));
430 OrthancPluginRestApiGet(context, &tmp, "/changes");
431 OrthancPluginFreeMemoryBuffer(context, &tmp);
432 OrthancPluginRestApiGet(context, &tmp, "/changes?limit=1");
433 OrthancPluginFreeMemoryBuffer(context, &tmp);
434 465
435 /* Play with PUT by defining a new target modality. */
436 sprintf(info, "[ \"STORESCP\", \"localhost\", 2000 ]");
437 OrthancPluginRestApiPut(context, &tmp, "/modalities/demo", info, strlen(info));
438
439 customError = OrthancPluginRegisterErrorCode(context, 4, 402, "Hello world");
440
441 OrthancPluginRegisterDictionaryTag(context, 0x0014, 0x1020, OrthancPluginValueRepresentation_DA, 466 OrthancPluginRegisterDictionaryTag(context, 0x0014, 0x1020, OrthancPluginValueRepresentation_DA,
442 "ValidationExpiryDate", 1, 1); 467 "ValidationExpiryDate", 1, 1);
443 468
444 OrthancPluginLookupDictionary(context, &entry, "ValidationExpiryDate"); 469 OrthancPluginLookupDictionary(context, &entry, "ValidationExpiryDate");
445 OrthancPluginLookupDictionary(context, &entry, "0010-0010"); 470 OrthancPluginLookupDictionary(context, &entry, "0010-0010");