Mercurial > hg > orthanc
annotate OrthancServer/LuaScripting.cpp @ 1444:b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 01 Jul 2015 12:09:58 +0200 |
parents | f3672356c121 |
children | d26c8a93d05a |
rev | line source |
---|---|
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * This program is free software: you can redistribute it and/or |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * modify it under the terms of the GNU General Public License as |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * published by the Free Software Foundation, either version 3 of the |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * License, or (at your option) any later version. |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * In addition, as a special exception, the copyright holders of this |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * program give permission to link the code of its release with the |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * that use the same license as the "OpenSSL" library), and distribute |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * the linked executables. You must obey the GNU General Public License |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * in all respects for all of the code used other than "OpenSSL". If you |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * modify file(s) with this exception, you may extend this exception to |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * your version of the file(s), but you are not obligated to do so. If |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * you do not wish to do so, delete this exception statement from your |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * version. If you delete this exception statement from all source files |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * in the program, then also delete it here. |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * This program is distributed in the hope that it will be useful, but |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * WITHOUT ANY WARRANTY; without even the implied warranty of |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * General Public License for more details. |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * You should have received a copy of the GNU General Public License |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 **/ |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 #include "PrecompiledHeadersServer.h" |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 #include "LuaScripting.h" |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 #include "ServerContext.h" |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 #include "OrthancInitialization.h" |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 #include "../Core/Lua/LuaFunctionCall.h" |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
39 #include "../Core/HttpServer/StringHttpOutput.h" |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 #include "Scheduler/DeleteInstanceCommand.h" |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 #include "Scheduler/StoreScuCommand.h" |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 #include "Scheduler/StorePeerCommand.h" |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 #include "Scheduler/ModifyInstanceCommand.h" |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 #include "Scheduler/CallSystemCommand.h" |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 #include "OrthancRestApi/OrthancRestApi.h" |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 #include <glog/logging.h> |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 #include <EmbeddedResources.h> |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 namespace Orthanc |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 { |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
54 ServerContext* LuaScripting::GetServerContext(lua_State *state) |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
55 { |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
56 const void* value = LuaContext::GetGlobalVariable(state, "_ServerContext"); |
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
57 return const_cast<ServerContext*>(reinterpret_cast<const ServerContext*>(value)); |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
58 } |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
59 |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
60 |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
61 int LuaScripting::RestApiGet(lua_State *state) |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
62 { |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
63 ServerContext* serverContext = GetServerContext(state); |
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
64 if (serverContext == NULL) |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
65 { |
1440 | 66 LOG(ERROR) << "Lua: The Orthanc API is unavailable"; |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
67 lua_pushnil(state); |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
68 return 1; |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
69 } |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
70 |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
71 // Check the types of the arguments |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
72 int nArgs = lua_gettop(state); |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
73 if ((nArgs != 1 && nArgs != 2) || |
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
74 !lua_isstring(state, 1) || // URI |
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
75 (nArgs == 2 && !lua_isboolean(state, 2))) // Restrict to built-in API? |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
76 { |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
77 LOG(ERROR) << "Lua: Bad parameters to RestApiGet()"; |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
78 lua_pushnil(state); |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
79 return 1; |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
80 } |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
81 |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
82 const char* uri = lua_tostring(state, 1); |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
83 bool builtin = (nArgs == 2 ? lua_toboolean(state, 2) : false); |
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
84 |
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
85 IHttpHandler& handler = (builtin ? |
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
86 serverContext->GetHttpHandler().GetOrthancRestApi() : |
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
87 serverContext->GetHttpHandler()); |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
88 |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
89 std::string str; |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
90 if (HttpToolbox::SimpleGet(str, handler, uri)) |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
91 { |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
92 lua_pushstring(state, str.c_str()); |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
93 } |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
94 else |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
95 { |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
96 LOG(ERROR) << "Lua: Error in RestApiGet() for URI " << uri; |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
97 lua_pushnil(state); |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
98 } |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
99 |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
100 return 1; |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
101 } |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
102 |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
103 |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 IServerCommand* LuaScripting::ParseOperation(const std::string& operation, |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 const Json::Value& parameters) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 if (operation == "delete") |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 { |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
109 LOG(INFO) << "Lua script to delete resource " << parameters["Resource"].asString(); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 return new DeleteInstanceCommand(context_); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 if (operation == "store-scu") |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 std::string localAet; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 if (parameters.isMember("LocalAet")) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 localAet = parameters["LocalAet"].asString(); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 else |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 localAet = context_.GetDefaultLocalApplicationEntityTitle(); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 std::string modality = parameters["Modality"].asString(); |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
126 LOG(INFO) << "Lua script to send resource " << parameters["Resource"].asString() |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 << " to modality " << modality << " using Store-SCU"; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 return new StoreScuCommand(context_, localAet, |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 Configuration::GetModalityUsingSymbolicName(modality), true); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 if (operation == "store-peer") |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 std::string peer = parameters["Peer"].asString(); |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
135 LOG(INFO) << "Lua script to send resource " << parameters["Resource"].asString() |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 << " to peer " << peer << " using HTTP"; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 OrthancPeerParameters parameters; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 Configuration::GetOrthancPeer(parameters, peer); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 return new StorePeerCommand(context_, parameters, true); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 if (operation == "modify") |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 { |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
145 LOG(INFO) << "Lua script to modify resource " << parameters["Resource"].asString(); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 DicomModification modification; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 OrthancRestApi::ParseModifyRequest(modification, parameters); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 std::auto_ptr<ModifyInstanceCommand> command(new ModifyInstanceCommand(context_, modification)); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 return command.release(); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 if (operation == "call-system") |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 { |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
155 LOG(INFO) << "Lua script to call system command on " << parameters["Resource"].asString(); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 const Json::Value& argsIn = parameters["Arguments"]; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 if (argsIn.type() != Json::arrayValue) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 throw OrthancException(ErrorCode_BadParameterType); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 std::vector<std::string> args; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 args.reserve(argsIn.size()); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 for (Json::Value::ArrayIndex i = 0; i < argsIn.size(); ++i) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 // http://jsoncpp.sourceforge.net/namespace_json.html#7d654b75c16a57007925868e38212b4e |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 switch (argsIn[i].type()) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 case Json::stringValue: |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 args.push_back(argsIn[i].asString()); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 break; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 case Json::intValue: |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asInt())); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 break; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 case Json::uintValue: |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asUInt())); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 break; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 case Json::realValue: |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asFloat())); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 break; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 default: |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 throw OrthancException(ErrorCode_BadParameterType); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 return new CallSystemCommand(context_, parameters["Command"].asString(), args); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 throw OrthancException(ErrorCode_ParameterOutOfRange); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
198 void LuaScripting::InitializeJob() |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
199 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
200 lua_.Execute("_InitializeJob()"); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
201 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
202 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
203 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
204 void LuaScripting::SubmitJob(const std::string& description) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
205 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
206 Json::Value operations; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
207 LuaFunctionCall call2(lua_, "_AccessJob"); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
208 call2.ExecuteToJson(operations); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
209 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
210 if (operations.type() != Json::arrayValue) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
211 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
212 throw OrthancException(ErrorCode_InternalError); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
213 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
214 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
215 ServerJob job; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
216 ServerCommandInstance* previousCommand = NULL; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
217 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
218 for (Json::Value::ArrayIndex i = 0; i < operations.size(); ++i) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
219 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
220 if (operations[i].type() != Json::objectValue || |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
221 !operations[i].isMember("Operation")) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
222 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
223 throw OrthancException(ErrorCode_InternalError); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
224 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
225 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
226 const Json::Value& parameters = operations[i]; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
227 std::string operation = parameters["Operation"].asString(); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
228 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
229 ServerCommandInstance& command = job.AddCommand(ParseOperation(operation, operations[i])); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
230 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
231 if (!parameters.isMember("Resource")) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
232 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
233 throw OrthancException(ErrorCode_InternalError); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
234 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
235 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
236 std::string resource = parameters["Resource"].asString(); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
237 if (resource.empty()) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
238 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
239 previousCommand->ConnectOutput(command); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
240 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
241 else |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
242 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
243 command.AddInput(resource); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
244 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
245 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
246 previousCommand = &command; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
247 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
248 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
249 job.SetDescription(description); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
250 context_.GetScheduler().Submit(job); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
251 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
252 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
253 |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
254 LuaScripting::LuaScripting(ServerContext& context) : context_(context) |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 { |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
256 lua_.SetGlobalVariable("_ServerContext", &context); |
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
257 lua_.RegisterFunction("RestApiGet", RestApiGet); |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
258 |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
260 lua_.SetHttpProxy(Configuration::GetGlobalStringParameter("HttpProxy", "")); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 void LuaScripting::ApplyOnStoredInstance(const std::string& instanceId, |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 const Json::Value& simplifiedTags, |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 const Json::Value& metadata, |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 const std::string& remoteAet, |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 const std::string& calledAet) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 { |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
270 static const char* NAME = "OnStoredInstance"; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
271 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
272 if (lua_.IsExistingFunction(NAME)) |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
273 { |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
274 InitializeJob(); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
275 |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
276 LuaFunctionCall call(lua_, NAME); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
277 call.PushString(instanceId); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
278 call.PushJson(simplifiedTags); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
279 call.PushJson(metadata); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
280 call.PushJson(remoteAet); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
281 call.PushJson(calledAet); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
282 call.Execute(); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
283 |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
284 SubmitJob(std::string("Lua script: ") + NAME); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
285 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
286 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
287 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
288 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
289 void LuaScripting::SignalStoredInstance(const std::string& publicId, |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
290 DicomInstanceToStore& instance, |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
291 const Json::Value& simplifiedTags) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
292 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 boost::mutex::scoped_lock lock(mutex_); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
294 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
295 Json::Value metadata = Json::objectValue; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
296 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
297 for (ServerIndex::MetadataMap::const_iterator |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
298 it = instance.GetMetadata().begin(); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
299 it != instance.GetMetadata().end(); ++it) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
300 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
301 if (it->first.first == ResourceType_Instance) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
302 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
303 metadata[EnumerationToString(it->first.second)] = it->second; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
304 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
305 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
306 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
307 ApplyOnStoredInstance(publicId, simplifiedTags, metadata, |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
308 instance.GetRemoteAet(), instance.GetCalledAet()); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
309 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
310 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
311 |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
312 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
313 void LuaScripting::OnStableResource(const ServerIndexChange& change) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
314 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
315 const char* name; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
316 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
317 switch (change.GetChangeType()) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
318 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
319 case ChangeType_StablePatient: |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
320 name = "OnStablePatient"; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
321 break; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
322 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
323 case ChangeType_StableStudy: |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
324 name = "OnStableStudy"; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
325 break; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
326 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
327 case ChangeType_StableSeries: |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
328 name = "OnStableSeries"; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
329 break; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
330 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
331 default: |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
332 throw OrthancException(ErrorCode_InternalError); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
333 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
334 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
335 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
336 Json::Value tags; |
1436
0a3e3be59094
uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1435
diff
changeset
|
337 if (context_.GetIndex().LookupResource(tags, change.GetPublicId(), change.GetResourceType())) |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
338 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
339 boost::mutex::scoped_lock lock(mutex_); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
340 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
341 if (lua_.IsExistingFunction(name)) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
342 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
343 InitializeJob(); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
344 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
345 LuaFunctionCall call(lua_, name); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
346 call.PushString(change.GetPublicId()); |
1436
0a3e3be59094
uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1435
diff
changeset
|
347 call.PushJson(tags["MainDicomTags"]); |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
348 call.Execute(); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
349 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
350 SubmitJob(std::string("Lua script: ") + name); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
351 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
352 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
353 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
354 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
355 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
356 |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
357 void LuaScripting::SignalChange(const ServerIndexChange& change) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
358 { |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
359 if (change.GetChangeType() == ChangeType_StablePatient || |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
360 change.GetChangeType() == ChangeType_StableStudy || |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
361 change.GetChangeType() == ChangeType_StableSeries) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
362 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
363 OnStableResource(change); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
364 } |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
365 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
366 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
367 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
368 bool LuaScripting::FilterIncomingInstance(const Json::Value& simplified, |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
369 const std::string& remoteAet) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
370 { |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
371 static const char* NAME = "ReceivedInstanceFilter"; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
372 |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
373 boost::mutex::scoped_lock lock(mutex_); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
374 |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
375 if (lua_.IsExistingFunction(NAME)) |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
376 { |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
377 LuaFunctionCall call(lua_, NAME); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
378 call.PushJson(simplified); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
379 call.PushString(remoteAet); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
380 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
381 if (!call.ExecutePredicate()) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
382 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
383 return false; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
384 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
385 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
386 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
387 return true; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
388 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
389 } |