comparison OrthancServer/ServerContext.h @ 1433:461e7554bff7

refactoring: LuaScripting
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Jun 2015 15:09:34 +0200
parents d710ea64f0fd
children f9cd40166269
comparison
equal deleted inserted replaced
1432:0ac74fa21db8 1433:461e7554bff7
31 31
32 32
33 #pragma once 33 #pragma once
34 34
35 #include "../Core/Cache/MemoryCache.h" 35 #include "../Core/Cache/MemoryCache.h"
36 #include "../Core/Cache/SharedArchive.h"
36 #include "../Core/FileStorage/CompressedFileStorageAccessor.h" 37 #include "../Core/FileStorage/CompressedFileStorageAccessor.h"
37 #include "../Core/FileStorage/IStorageArea.h" 38 #include "../Core/FileStorage/IStorageArea.h"
39 #include "../Core/Lua/LuaContext.h"
38 #include "../Core/RestApi/RestApiOutput.h" 40 #include "../Core/RestApi/RestApiOutput.h"
39 #include "../Core/Lua/LuaContext.h" 41 #include "../Plugins/Engine/OrthancPlugins.h"
42 #include "../Plugins/Engine/PluginsManager.h"
43 #include "DicomInstanceToStore.h"
44 #include "DicomProtocol/ReusableDicomUserConnection.h"
45 #include "IServerListener.h"
46 #include "LuaScripting.h"
47 #include "ParsedDicomFile.h"
48 #include "Scheduler/ServerScheduler.h"
40 #include "ServerIndex.h" 49 #include "ServerIndex.h"
41 #include "ParsedDicomFile.h"
42 #include "DicomProtocol/ReusableDicomUserConnection.h"
43 #include "Scheduler/ServerScheduler.h"
44 #include "DicomInstanceToStore.h"
45 #include "ServerIndexChange.h"
46 #include "../Core/Cache/SharedArchive.h"
47 50
48 #include <boost/filesystem.hpp> 51 #include <boost/filesystem.hpp>
49 52
50 namespace Orthanc 53 namespace Orthanc
51 { 54 {
52 class OrthancPlugins;
53 class PluginsManager;
54
55 /** 55 /**
56 * This class is responsible for maintaining the storage area on the 56 * This class is responsible for maintaining the storage area on the
57 * filesystem (including compression), as well as the index of the 57 * filesystem (including compression), as well as the index of the
58 * DICOM store. It implements the required locking mechanisms. 58 * DICOM store. It implements the required locking mechanisms.
59 **/ 59 **/
71 } 71 }
72 72
73 virtual IDynamicObject* Provide(const std::string& id); 73 virtual IDynamicObject* Provide(const std::string& id);
74 }; 74 };
75 75
76 bool ApplyReceivedInstanceFilter(const Json::Value& simplified, 76 class ServerListener
77 const std::string& remoteAet); 77 {
78 78 private:
79 void ApplyLuaOnStoredInstance(const std::string& instanceId, 79 IServerListener *listener_;
80 const Json::Value& simplifiedDicom, 80 std::string description_;
81 const Json::Value& metadata, 81
82 const std::string& remoteAet, 82 public:
83 const std::string& calledAet); 83 ServerListener(IServerListener& listener,
84 const std::string& description) :
85 listener_(&listener),
86 description_(description)
87 {
88 }
89
90 IServerListener& GetListener()
91 {
92 return *listener_;
93 }
94
95 const std::string& GetDescription()
96 {
97 return description_;
98 }
99 };
100
101 typedef std::list<ServerListener> ServerListeners;
102
84 103
85 ServerIndex index_; 104 ServerIndex index_;
86 CompressedFileStorageAccessor accessor_; 105 CompressedFileStorageAccessor accessor_;
87 bool compressionEnabled_; 106 bool compressionEnabled_;
88 107
90 boost::mutex dicomCacheMutex_; 109 boost::mutex dicomCacheMutex_;
91 MemoryCache dicomCache_; 110 MemoryCache dicomCache_;
92 ReusableDicomUserConnection scu_; 111 ReusableDicomUserConnection scu_;
93 ServerScheduler scheduler_; 112 ServerScheduler scheduler_;
94 113
95 boost::mutex luaMutex_; 114 LuaScripting lua_;
96 LuaContext lua_; 115 OrthancPlugins* plugins_;
97 OrthancPlugins* plugins_; // TODO Turn it into a listener pattern (idem for Lua callbacks) 116 ServerListeners listeners_;
98 const PluginsManager* pluginsManager_; 117 const PluginsManager* pluginsManager_;
99 118
100 SharedArchive queryRetrieveArchive_; 119 SharedArchive queryRetrieveArchive_;
101 std::string defaultLocalAet_; 120 std::string defaultLocalAet_;
102 121
117 ParsedDicomFile& GetDicom() 136 ParsedDicomFile& GetDicom()
118 { 137 {
119 return *dicom_; 138 return *dicom_;
120 } 139 }
121 }; 140 };
122
123 class LuaContextLocker : public boost::noncopyable
124 {
125 private:
126 ServerContext& that_;
127
128 public:
129 LuaContextLocker(ServerContext& that) : that_(that)
130 {
131 that.luaMutex_.lock();
132 }
133
134 ~LuaContextLocker()
135 {
136 that_.luaMutex_.unlock();
137 }
138
139 LuaContext& GetLua()
140 {
141 return that_.lua_;
142 }
143 };
144
145 141
146 ServerContext(IDatabaseWrapper& database); 142 ServerContext(IDatabaseWrapper& database);
147 143
148 void SetStorageArea(IStorageArea& storage) 144 void SetStorageArea(IStorageArea& storage)
149 { 145 {
206 void SetOrthancPlugins(const PluginsManager& manager, 202 void SetOrthancPlugins(const PluginsManager& manager,
207 OrthancPlugins& plugins) 203 OrthancPlugins& plugins)
208 { 204 {
209 pluginsManager_ = &manager; 205 pluginsManager_ = &manager;
210 plugins_ = &plugins; 206 plugins_ = &plugins;
207 listeners_.clear();
208 listeners_.push_back(ServerListener(lua_, "Lua")); // TODO REFACTOR THIS
209 listeners_.push_back(ServerListener(plugins, "plugin")); // TODO REFACTOR THIS
211 } 210 }
212 211
213 void ResetOrthancPlugins() 212 void ResetOrthancPlugins()
214 { 213 {
215 pluginsManager_ = NULL; 214 pluginsManager_ = NULL;
216 plugins_ = NULL; 215 plugins_ = NULL;
216 listeners_.clear();
217 listeners_.push_back(ServerListener(lua_, "Lua")); // TODO REFACTOR THIS
217 } 218 }
218 219
219 bool DeleteResource(Json::Value& target, 220 bool DeleteResource(Json::Value& target,
220 const std::string& uuid, 221 const std::string& uuid,
221 ResourceType expectedType); 222 ResourceType expectedType);
235 236
236 const std::string& GetDefaultLocalApplicationEntityTitle() const 237 const std::string& GetDefaultLocalApplicationEntityTitle() const
237 { 238 {
238 return defaultLocalAet_; 239 return defaultLocalAet_;
239 } 240 }
241
242 LuaScripting& GetLua()
243 {
244 return lua_;
245 }
240 }; 246 };
241 } 247 }