Mercurial > hg > orthanc-stone
comparison Samples/Sdl/Loader.cpp @ 641:392783c90607
renames
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 10 May 2019 10:59:37 +0200 |
parents | e706188d6078 |
children | 7ca8dc7ec17b |
comparison
equal
deleted
inserted
replaced
640:e706188d6078 | 641:392783c90607 |
---|---|
60 { | 60 { |
61 public: | 61 public: |
62 enum Type | 62 enum Type |
63 { | 63 { |
64 Type_OrthancRestApi, | 64 Type_OrthancRestApi, |
65 Type_DecodeOrthancImage, | 65 Type_GetOrthancImage, |
66 Type_DecodeOrthancWebViewerJpeg | 66 Type_GetOrthancWebViewerJpeg |
67 }; | 67 }; |
68 | 68 |
69 virtual ~IOracleCommand() | 69 virtual ~IOracleCommand() |
70 { | 70 { |
71 } | 71 } |
310 }; | 310 }; |
311 | 311 |
312 | 312 |
313 | 313 |
314 | 314 |
315 class DecodeOrthancImageCommand : public OracleCommandWithPayload | 315 class GetOrthancImageCommand : public OracleCommandWithPayload |
316 { | 316 { |
317 public: | 317 public: |
318 class SuccessMessage : public OrthancStone::OriginMessage<OrthancStone::MessageType_ImageReady, // TODO | 318 class SuccessMessage : public OrthancStone::OriginMessage<OrthancStone::MessageType_ImageReady, // TODO |
319 DecodeOrthancImageCommand> | 319 GetOrthancImageCommand> |
320 { | 320 { |
321 private: | 321 private: |
322 std::auto_ptr<Orthanc::ImageAccessor> image_; | 322 std::auto_ptr<Orthanc::ImageAccessor> image_; |
323 Orthanc::MimeType mime_; | 323 Orthanc::MimeType mime_; |
324 | 324 |
325 public: | 325 public: |
326 SuccessMessage(const DecodeOrthancImageCommand& command, | 326 SuccessMessage(const GetOrthancImageCommand& command, |
327 Orthanc::ImageAccessor* image, // Takes ownership | 327 Orthanc::ImageAccessor* image, // Takes ownership |
328 Orthanc::MimeType mime) : | 328 Orthanc::MimeType mime) : |
329 OriginMessage(command), | 329 OriginMessage(command), |
330 image_(image), | 330 image_(image), |
331 mime_(mime) | 331 mime_(mime) |
355 | 355 |
356 std::auto_ptr< OrthancStone::MessageHandler<SuccessMessage> > successCallback_; | 356 std::auto_ptr< OrthancStone::MessageHandler<SuccessMessage> > successCallback_; |
357 std::auto_ptr< OrthancStone::MessageHandler<OracleCommandExceptionMessage> > failureCallback_; | 357 std::auto_ptr< OrthancStone::MessageHandler<OracleCommandExceptionMessage> > failureCallback_; |
358 | 358 |
359 public: | 359 public: |
360 DecodeOrthancImageCommand() : | 360 GetOrthancImageCommand() : |
361 uri_("/"), | 361 uri_("/"), |
362 timeout_(10) | 362 timeout_(10) |
363 { | 363 { |
364 } | 364 } |
365 | 365 |
366 virtual Type GetType() const | 366 virtual Type GetType() const |
367 { | 367 { |
368 return Type_DecodeOrthancImage; | 368 return Type_GetOrthancImage; |
369 } | 369 } |
370 | 370 |
371 void SetUri(const std::string& uri) | 371 void SetUri(const std::string& uri) |
372 { | 372 { |
373 uri_ = uri; | 373 uri_ = uri; |
448 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, | 448 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, |
449 "Unsupported HTTP Content-Type for an image: " + | 449 "Unsupported HTTP Content-Type for an image: " + |
450 std::string(Orthanc::EnumerationToString(contentType))); | 450 std::string(Orthanc::EnumerationToString(contentType))); |
451 } | 451 } |
452 | 452 |
453 DecodeOrthancImageCommand::SuccessMessage message(*this, image.release(), contentType); | 453 GetOrthancImageCommand::SuccessMessage message(*this, image.release(), contentType); |
454 emitter.EmitMessage(receiver, message); | 454 emitter.EmitMessage(receiver, message); |
455 } | 455 } |
456 }; | 456 }; |
457 | 457 |
458 | 458 |
459 | 459 |
460 class DecodeOrthancWebViewerJpegCommand : public OracleCommandWithPayload | 460 class GetOrthancWebViewerJpegCommand : public OracleCommandWithPayload |
461 { | 461 { |
462 public: | 462 public: |
463 class SuccessMessage : public OrthancStone::OriginMessage<OrthancStone::MessageType_ImageReady, // TODO | 463 class SuccessMessage : public OrthancStone::OriginMessage<OrthancStone::MessageType_ImageReady, // TODO |
464 DecodeOrthancWebViewerJpegCommand> | 464 GetOrthancWebViewerJpegCommand> |
465 { | 465 { |
466 private: | 466 private: |
467 std::auto_ptr<Orthanc::ImageAccessor> image_; | 467 std::auto_ptr<Orthanc::ImageAccessor> image_; |
468 | 468 |
469 public: | 469 public: |
470 SuccessMessage(const DecodeOrthancWebViewerJpegCommand& command, | 470 SuccessMessage(const GetOrthancWebViewerJpegCommand& command, |
471 Orthanc::ImageAccessor* image) : // Takes ownership | 471 Orthanc::ImageAccessor* image) : // Takes ownership |
472 OriginMessage(command), | 472 OriginMessage(command), |
473 image_(image) | 473 image_(image) |
474 { | 474 { |
475 if (image == NULL) | 475 if (image == NULL) |
493 | 493 |
494 std::auto_ptr< OrthancStone::MessageHandler<SuccessMessage> > successCallback_; | 494 std::auto_ptr< OrthancStone::MessageHandler<SuccessMessage> > successCallback_; |
495 std::auto_ptr< OrthancStone::MessageHandler<OracleCommandExceptionMessage> > failureCallback_; | 495 std::auto_ptr< OrthancStone::MessageHandler<OracleCommandExceptionMessage> > failureCallback_; |
496 | 496 |
497 public: | 497 public: |
498 DecodeOrthancWebViewerJpegCommand() : | 498 GetOrthancWebViewerJpegCommand() : |
499 frame_(0), | 499 frame_(0), |
500 quality_(95), | 500 quality_(95), |
501 timeout_(10) | 501 timeout_(10) |
502 { | 502 { |
503 } | 503 } |
504 | 504 |
505 virtual Type GetType() const | 505 virtual Type GetType() const |
506 { | 506 { |
507 return Type_DecodeOrthancWebViewerJpeg; | 507 return Type_GetOrthancWebViewerJpeg; |
508 } | 508 } |
509 | 509 |
510 void SetInstance(const std::string& instanceId) | 510 void SetInstance(const std::string& instanceId) |
511 { | 511 { |
512 instanceId_ = instanceId; | 512 instanceId_ = instanceId; |
581 if (!reader.parse(answer, value)) | 581 if (!reader.parse(answer, value)) |
582 { | 582 { |
583 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | 583 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
584 } | 584 } |
585 | 585 |
586 //DecodeOrthancWebViewerJpegCommand::SuccessMessage message(command, image.release(), contentType); | 586 //GetOrthancWebViewerJpegCommand::SuccessMessage message(command, image.release(), contentType); |
587 //emitter.EmitMessage(receiver, message); | 587 //emitter.EmitMessage(receiver, message); |
588 } | 588 } |
589 }; | 589 }; |
590 | 590 |
591 | 591 |
716 emitter_.EmitMessage(receiver, message); | 716 emitter_.EmitMessage(receiver, message); |
717 } | 717 } |
718 | 718 |
719 | 719 |
720 void Execute(const OrthancStone::IObserver& receiver, | 720 void Execute(const OrthancStone::IObserver& receiver, |
721 const DecodeOrthancImageCommand& command) | 721 const GetOrthancImageCommand& command) |
722 { | 722 { |
723 Orthanc::HttpClient client(orthanc_, command.GetUri()); | 723 Orthanc::HttpClient client(orthanc_, command.GetUri()); |
724 client.SetTimeout(command.GetTimeout()); | 724 client.SetTimeout(command.GetTimeout()); |
725 | 725 |
726 CopyHttpHeaders(client, command.GetHttpHeaders()); | 726 CopyHttpHeaders(client, command.GetHttpHeaders()); |
734 command.ProcessHttpAnswer(emitter_, receiver, answer, answerHeaders); | 734 command.ProcessHttpAnswer(emitter_, receiver, answer, answerHeaders); |
735 } | 735 } |
736 | 736 |
737 | 737 |
738 void Execute(const OrthancStone::IObserver& receiver, | 738 void Execute(const OrthancStone::IObserver& receiver, |
739 const DecodeOrthancWebViewerJpegCommand& command) | 739 const GetOrthancWebViewerJpegCommand& command) |
740 { | 740 { |
741 Orthanc::HttpClient client(orthanc_, command.GetUri()); | 741 Orthanc::HttpClient client(orthanc_, command.GetUri()); |
742 client.SetTimeout(command.GetTimeout()); | 742 client.SetTimeout(command.GetTimeout()); |
743 | 743 |
744 CopyHttpHeaders(client, command.GetHttpHeaders()); | 744 CopyHttpHeaders(client, command.GetHttpHeaders()); |
749 | 749 |
750 DecodeAnswer(answer, answerHeaders); | 750 DecodeAnswer(answer, answerHeaders); |
751 | 751 |
752 command.ProcessHttpAnswer(emitter_, receiver, answer); | 752 command.ProcessHttpAnswer(emitter_, receiver, answer); |
753 } | 753 } |
754 | |
755 | 754 |
756 | 755 |
757 void Step() | 756 void Step() |
758 { | 757 { |
759 std::auto_ptr<Orthanc::IDynamicObject> object(queue_.Dequeue(100)); | 758 std::auto_ptr<Orthanc::IDynamicObject> object(queue_.Dequeue(100)); |
769 case IOracleCommand::Type_OrthancRestApi: | 768 case IOracleCommand::Type_OrthancRestApi: |
770 Execute(item.GetReceiver(), | 769 Execute(item.GetReceiver(), |
771 dynamic_cast<const OrthancRestApiCommand&>(item.GetCommand())); | 770 dynamic_cast<const OrthancRestApiCommand&>(item.GetCommand())); |
772 break; | 771 break; |
773 | 772 |
774 case IOracleCommand::Type_DecodeOrthancImage: | 773 case IOracleCommand::Type_GetOrthancImage: |
775 Execute(item.GetReceiver(), | 774 Execute(item.GetReceiver(), |
776 dynamic_cast<const DecodeOrthancImageCommand&>(item.GetCommand())); | 775 dynamic_cast<const GetOrthancImageCommand&>(item.GetCommand())); |
777 break; | 776 break; |
778 | 777 |
779 case IOracleCommand::Type_DecodeOrthancWebViewerJpeg: | 778 case IOracleCommand::Type_GetOrthancWebViewerJpeg: |
780 Execute(item.GetReceiver(), | 779 Execute(item.GetReceiver(), |
781 dynamic_cast<const DecodeOrthancWebViewerJpegCommand&>(item.GetCommand())); | 780 dynamic_cast<const GetOrthancWebViewerJpegCommand&>(item.GetCommand())); |
782 break; | 781 break; |
783 | 782 |
784 default: | 783 default: |
785 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 784 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
786 } | 785 } |
1457 message.ParseJsonBody(v); | 1456 message.ParseJsonBody(v); |
1458 | 1457 |
1459 printf("ICI [%s]\n", v.toStyledString().c_str()); | 1458 printf("ICI [%s]\n", v.toStyledString().c_str()); |
1460 } | 1459 } |
1461 | 1460 |
1462 void Handle(const Refactoring::DecodeOrthancImageCommand::SuccessMessage& message) | 1461 void Handle(const Refactoring::GetOrthancImageCommand::SuccessMessage& message) |
1463 { | 1462 { |
1464 printf("IMAGE %dx%d\n", message.GetImage().GetWidth(), message.GetImage().GetHeight()); | 1463 printf("IMAGE %dx%d\n", message.GetImage().GetWidth(), message.GetImage().GetHeight()); |
1465 } | 1464 } |
1466 | 1465 |
1467 void Handle(const Refactoring::OracleCommandExceptionMessage& message) | 1466 void Handle(const Refactoring::OracleCommandExceptionMessage& message) |
1468 { | 1467 { |
1469 printf("EXCEPTION: [%s] on command type %d\n", message.GetException().What(), message.GetCommand().GetType()); | 1468 printf("EXCEPTION: [%s] on command type %d\n", message.GetException().What(), message.GetCommand().GetType()); |
1470 | 1469 |
1471 switch (message.GetCommand().GetType()) | 1470 switch (message.GetCommand().GetType()) |
1472 { | 1471 { |
1473 case Refactoring::IOracleCommand::Type_DecodeOrthancWebViewerJpeg: | 1472 case Refactoring::IOracleCommand::Type_GetOrthancWebViewerJpeg: |
1474 printf("URI: [%s]\n", dynamic_cast<const Refactoring::DecodeOrthancWebViewerJpegCommand&> | 1473 printf("URI: [%s]\n", dynamic_cast<const Refactoring::GetOrthancWebViewerJpegCommand&> |
1475 (message.GetCommand()).GetUri().c_str()); | 1474 (message.GetCommand()).GetUri().c_str()); |
1476 break; | 1475 break; |
1477 | 1476 |
1478 default: | 1477 default: |
1479 break; | 1478 break; |
1488 (new OrthancStone::Callable | 1487 (new OrthancStone::Callable |
1489 <Toto, Refactoring::OrthancRestApiCommand::SuccessMessage>(*this, &Toto::Handle)); | 1488 <Toto, Refactoring::OrthancRestApiCommand::SuccessMessage>(*this, &Toto::Handle)); |
1490 | 1489 |
1491 oracle.RegisterObserverCallback | 1490 oracle.RegisterObserverCallback |
1492 (new OrthancStone::Callable | 1491 (new OrthancStone::Callable |
1493 <Toto, Refactoring::DecodeOrthancImageCommand::SuccessMessage>(*this, &Toto::Handle)); | 1492 <Toto, Refactoring::GetOrthancImageCommand::SuccessMessage>(*this, &Toto::Handle)); |
1494 | 1493 |
1495 oracle.RegisterObserverCallback | 1494 oracle.RegisterObserverCallback |
1496 (new OrthancStone::Callable | 1495 (new OrthancStone::Callable |
1497 <Toto, Refactoring::OracleCommandExceptionMessage>(*this, &Toto::Handle)); | 1496 <Toto, Refactoring::OracleCommandExceptionMessage>(*this, &Toto::Handle)); |
1498 } | 1497 } |
1536 oracle.Schedule(*toto, command.release()); | 1535 oracle.Schedule(*toto, command.release()); |
1537 } | 1536 } |
1538 | 1537 |
1539 if (0) | 1538 if (0) |
1540 { | 1539 { |
1541 std::auto_ptr<Refactoring::DecodeOrthancImageCommand> command(new Refactoring::DecodeOrthancImageCommand); | 1540 std::auto_ptr<Refactoring::GetOrthancImageCommand> command(new Refactoring::GetOrthancImageCommand); |
1542 command->SetHttpHeader("Accept", std::string(Orthanc::EnumerationToString(Orthanc::MimeType_Jpeg))); | 1541 command->SetHttpHeader("Accept", std::string(Orthanc::EnumerationToString(Orthanc::MimeType_Jpeg))); |
1543 command->SetUri("/instances/6687cc73-07cae193-52ff29c8-f646cb16-0753ed92/preview"); | 1542 command->SetUri("/instances/6687cc73-07cae193-52ff29c8-f646cb16-0753ed92/preview"); |
1544 oracle.Schedule(*toto, command.release()); | 1543 oracle.Schedule(*toto, command.release()); |
1545 } | 1544 } |
1546 | 1545 |
1547 if (0) | 1546 if (0) |
1548 { | 1547 { |
1549 std::auto_ptr<Refactoring::DecodeOrthancImageCommand> command(new Refactoring::DecodeOrthancImageCommand); | 1548 std::auto_ptr<Refactoring::GetOrthancImageCommand> command(new Refactoring::GetOrthancImageCommand); |
1550 command->SetHttpHeader("Accept", std::string(Orthanc::EnumerationToString(Orthanc::MimeType_Png))); | 1549 command->SetHttpHeader("Accept", std::string(Orthanc::EnumerationToString(Orthanc::MimeType_Png))); |
1551 command->SetUri("/instances/6687cc73-07cae193-52ff29c8-f646cb16-0753ed92/preview"); | 1550 command->SetUri("/instances/6687cc73-07cae193-52ff29c8-f646cb16-0753ed92/preview"); |
1552 oracle.Schedule(*toto, command.release()); | 1551 oracle.Schedule(*toto, command.release()); |
1553 } | 1552 } |
1554 | 1553 |
1555 if (1) | 1554 if (1) |
1556 { | 1555 { |
1557 std::auto_ptr<Refactoring::DecodeOrthancImageCommand> command(new Refactoring::DecodeOrthancImageCommand); | 1556 std::auto_ptr<Refactoring::GetOrthancImageCommand> command(new Refactoring::GetOrthancImageCommand); |
1558 command->SetHttpHeader("Accept", std::string(Orthanc::EnumerationToString(Orthanc::MimeType_Png))); | 1557 command->SetHttpHeader("Accept", std::string(Orthanc::EnumerationToString(Orthanc::MimeType_Png))); |
1559 command->SetUri("/instances/6687cc73-07cae193-52ff29c8-f646cb16-0753ed92/image-uint16"); | 1558 command->SetUri("/instances/6687cc73-07cae193-52ff29c8-f646cb16-0753ed92/image-uint16"); |
1560 oracle.Schedule(*toto, command.release()); | 1559 oracle.Schedule(*toto, command.release()); |
1561 } | 1560 } |
1562 | 1561 |
1563 if (1) | 1562 if (1) |
1564 { | 1563 { |
1565 std::auto_ptr<Refactoring::DecodeOrthancImageCommand> command(new Refactoring::DecodeOrthancImageCommand); | 1564 std::auto_ptr<Refactoring::GetOrthancImageCommand> command(new Refactoring::GetOrthancImageCommand); |
1566 command->SetHttpHeader("Accept-Encoding", "gzip"); | 1565 command->SetHttpHeader("Accept-Encoding", "gzip"); |
1567 command->SetHttpHeader("Accept", std::string(Orthanc::EnumerationToString(Orthanc::MimeType_Pam))); | 1566 command->SetHttpHeader("Accept", std::string(Orthanc::EnumerationToString(Orthanc::MimeType_Pam))); |
1568 command->SetUri("/instances/6687cc73-07cae193-52ff29c8-f646cb16-0753ed92/image-uint16"); | 1567 command->SetUri("/instances/6687cc73-07cae193-52ff29c8-f646cb16-0753ed92/image-uint16"); |
1569 oracle.Schedule(*toto, command.release()); | 1568 oracle.Schedule(*toto, command.release()); |
1570 } | 1569 } |
1571 | 1570 |
1572 if (1) | 1571 if (1) |
1573 { | 1572 { |
1574 std::auto_ptr<Refactoring::DecodeOrthancImageCommand> command(new Refactoring::DecodeOrthancImageCommand); | 1573 std::auto_ptr<Refactoring::GetOrthancImageCommand> command(new Refactoring::GetOrthancImageCommand); |
1575 command->SetHttpHeader("Accept", std::string(Orthanc::EnumerationToString(Orthanc::MimeType_Pam))); | 1574 command->SetHttpHeader("Accept", std::string(Orthanc::EnumerationToString(Orthanc::MimeType_Pam))); |
1576 command->SetUri("/instances/6687cc73-07cae193-52ff29c8-f646cb16-0753ed92/image-uint16"); | 1575 command->SetUri("/instances/6687cc73-07cae193-52ff29c8-f646cb16-0753ed92/image-uint16"); |
1577 oracle.Schedule(*toto, command.release()); | 1576 oracle.Schedule(*toto, command.release()); |
1578 } | 1577 } |
1579 | 1578 |
1580 if (1) | 1579 if (1) |
1581 { | 1580 { |
1582 std::auto_ptr<Refactoring::DecodeOrthancWebViewerJpegCommand> command(new Refactoring::DecodeOrthancWebViewerJpegCommand); | 1581 std::auto_ptr<Refactoring::GetOrthancWebViewerJpegCommand> command(new Refactoring::GetOrthancWebViewerJpegCommand); |
1583 command->SetHttpHeader("Accept-Encoding", "gzip"); | 1582 command->SetHttpHeader("Accept-Encoding", "gzip"); |
1584 command->SetInstance("e6c7c20b-c9f65d7e-0d76f2e2-830186f2-3e3c600e"); | 1583 command->SetInstance("e6c7c20b-c9f65d7e-0d76f2e2-830186f2-3e3c600e"); |
1585 command->SetQuality(90); | 1584 command->SetQuality(90); |
1586 oracle.Schedule(*toto, command.release()); | 1585 oracle.Schedule(*toto, command.release()); |
1587 } | 1586 } |