comparison Framework/SmartLoader.cpp @ 300:b4abaeb783b1 am-callable-and-promise

messaging refactoring almost complete: works fine in native
author am@osimis.io
date Tue, 18 Sep 2018 15:23:21 +0200
parents 3897f9f28cfa
children b66d13708f40
comparison
equal deleted inserted replaced
299:3897f9f28cfa 300:b4abaeb783b1
19 **/ 19 **/
20 20
21 21
22 #include "SmartLoader.h" 22 #include "SmartLoader.h"
23 #include "Layers/OrthancFrameLayerSource.h" 23 #include "Layers/OrthancFrameLayerSource.h"
24 #include "Messages/MessageForwarder.h"
24 25
25 namespace OrthancStone 26 namespace OrthancStone
26 { 27 {
27 SmartLoader::SmartLoader(MessageBroker& broker, IWebService& webService) : 28 SmartLoader::SmartLoader(MessageBroker& broker, IWebService& webService) :
28 IObservable(broker), 29 IObservable(broker),
29 IObserver(broker), 30 IObserver(broker),
30 imageQuality_(SliceImageQuality_FullPam), 31 imageQuality_(SliceImageQuality_FullPam),
31 webService_(webService), 32 webService_(webService),
32 orthancApiClient_(broker, webService) 33 orthancApiClient_(broker, webService)
33 { 34 {
34 // DeclareHandledMessage(MessageType_LayerSource_GeometryReady);
35 // DeclareHandledMessage(MessageType_LayerSource_LayerReady);
36 // DeclareIgnoredMessage(MessageType_LayerSource_GeometryError);
37 // DeclareIgnoredMessage(MessageType_LayerSource_ContentChanged);
38 // DeclareIgnoredMessage(MessageType_LayerSource_SliceChanged);
39
40 // DeclareHandledMessage(MessageType_OrthancApi_InternalGetJsonResponseReady);
41 // DeclareIgnoredMessage(MessageType_OrthancApi_InternalGetJsonResponseError);
42 }
43
44 void SmartLoader::HandleMessage(IObservable& from, const IMessage& message)
45 {
46 switch (message.GetType()) {
47 case MessageType_LayerSource_GeometryReady:
48 {
49 //const OrthancFrameLayerSource* layerSource=dynamic_cast<const OrthancFrameLayerSource*>(&from);
50 // TODO keep track of objects that have been loaded already
51 }; break;
52 case MessageType_LayerSource_LayerReady:
53 {
54 //const OrthancFrameLayerSource* layerSource=dynamic_cast<const OrthancFrameLayerSource*>(&from);
55 // TODO keep track of objects that have been loaded already
56 }; break;
57 // case MessageType_OrthancApi_GetStudyIds_Ready:
58 // {
59
60 // const OrthancApiClient::GetJsonResponseReadyMessage& msg = dynamic_cast<OrthancApiClient::GetJsonResponseReadyMessage&>(message);
61
62 // }; break;
63 default:
64 VLOG("unhandled message type" << message.GetType());
65 }
66
67 // forward messages to its own observers
68 // TODO TODO TODO IObservable::broker_.EmitMessage(from, IObservable::observers_, message);
69 } 35 }
70 36
71 ILayerSource* SmartLoader::GetFrame(const std::string& instanceId, unsigned int frame) 37 ILayerSource* SmartLoader::GetFrame(const std::string& instanceId, unsigned int frame)
72 { 38 {
73 // TODO: check if this frame has already been loaded or is already being loaded. 39 // TODO: check if this frame has already been loaded or is already being loaded.
74 // - if already loaded: create a "clone" that will emit the GeometryReady/ImageReady messages "immediately" 40 // - if already loaded: create a "clone" that will emit the GeometryReady/ImageReady messages "immediately"
75 // (it can not be immediate because Observers needs to register first and this is done after this method returns) 41 // (it can not be immediate because Observers needs to register first and this is done after this method returns)
76 // - if currently loading, we need to return an object that will observe the existing LayerSource and forward 42 // - if currently loading, we need to return an object that will observe the existing LayerSource and forward
77 // the messages to its observables 43 // the messages to its observables
78 // in both cases, we must be carefull about objects lifecycle !!! 44 // in both cases, we must be carefull about objects lifecycle !!!
79 std::auto_ptr<OrthancFrameLayerSource> layerSource (new OrthancFrameLayerSource(IObserver::broker_, webService_)); 45 std::auto_ptr<OrthancFrameLayerSource> layerSource (new OrthancFrameLayerSource(IObserver::broker_, orthancApiClient_));
80 layerSource->SetImageQuality(imageQuality_); 46 layerSource->SetImageQuality(imageQuality_);
81 //layerSource->RegisterObserverCallback(new Callable<SmartLoader, ILayerSource::GeometryReadyMessage>(*this, &SmartLoader::....)); 47 layerSource->RegisterObserverCallback(new MessageForwarder<ILayerSource::GeometryReadyMessage>(IObserver::broker_, *this));
48 layerSource->RegisterObserverCallback(new MessageForwarder<ILayerSource::LayerReadyMessage>(IObserver::broker_, *this));
82 layerSource->LoadFrame(instanceId, frame); 49 layerSource->LoadFrame(instanceId, frame);
83 50
84 return layerSource.release(); 51 return layerSource.release();
85 } 52 }
86 53