annotate OrthancServer/LuaScripting.cpp @ 1435:6406f5493d92

refactoring: Lua toolbox
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Jun 2015 16:46:23 +0200
parents 461e7554bff7
children 0a3e3be59094
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include "Scheduler/DeleteInstanceCommand.h"
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include "Scheduler/StoreScuCommand.h"
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include "Scheduler/StorePeerCommand.h"
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include "Scheduler/ModifyInstanceCommand.h"
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 #include "Scheduler/CallSystemCommand.h"
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 #include "OrthancRestApi/OrthancRestApi.h"
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 #include <glog/logging.h>
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 #include <EmbeddedResources.h>
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
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 namespace Orthanc
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 IServerCommand* LuaScripting::ParseOperation(const std::string& operation,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 const Json::Value& parameters)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 if (operation == "delete")
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
58 LOG(INFO) << "Lua script to delete resource " << parameters["Resource"].asString();
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 return new DeleteInstanceCommand(context_);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 if (operation == "store-scu")
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 std::string localAet;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 if (parameters.isMember("LocalAet"))
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 localAet = parameters["LocalAet"].asString();
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 else
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 localAet = context_.GetDefaultLocalApplicationEntityTitle();
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 std::string modality = parameters["Modality"].asString();
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
75 LOG(INFO) << "Lua script to send resource " << parameters["Resource"].asString()
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 << " to modality " << modality << " using Store-SCU";
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 return new StoreScuCommand(context_, localAet,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 Configuration::GetModalityUsingSymbolicName(modality), true);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 if (operation == "store-peer")
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 std::string peer = parameters["Peer"].asString();
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
84 LOG(INFO) << "Lua script to send resource " << parameters["Resource"].asString()
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 << " to peer " << peer << " using HTTP";
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 OrthancPeerParameters parameters;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 Configuration::GetOrthancPeer(parameters, peer);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 return new StorePeerCommand(context_, parameters, true);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 if (operation == "modify")
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
94 LOG(INFO) << "Lua script to modify resource " << parameters["Resource"].asString();
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 DicomModification modification;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 OrthancRestApi::ParseModifyRequest(modification, parameters);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 std::auto_ptr<ModifyInstanceCommand> command(new ModifyInstanceCommand(context_, modification));
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 return command.release();
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 if (operation == "call-system")
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
104 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
105
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 const Json::Value& argsIn = parameters["Arguments"];
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 if (argsIn.type() != Json::arrayValue)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 throw OrthancException(ErrorCode_BadParameterType);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
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 std::vector<std::string> args;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 args.reserve(argsIn.size());
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 for (Json::Value::ArrayIndex i = 0; i < argsIn.size(); ++i)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 // http://jsoncpp.sourceforge.net/namespace_json.html#7d654b75c16a57007925868e38212b4e
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 switch (argsIn[i].type())
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 case Json::stringValue:
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 args.push_back(argsIn[i].asString());
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 break;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 case Json::intValue:
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asInt()));
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 break;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 case Json::uintValue:
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asUInt()));
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 break;
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 case Json::realValue:
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asFloat()));
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 break;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 default:
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 throw OrthancException(ErrorCode_BadParameterType);
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 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 return new CallSystemCommand(context_, parameters["Command"].asString(), args);
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 throw OrthancException(ErrorCode_ParameterOutOfRange);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
147 void LuaScripting::InitializeJob()
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
148 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
149 lua_.Execute("_InitializeJob()");
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
150 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
151
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
152
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
153 void LuaScripting::SubmitJob(const std::string& description)
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
154 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
155 Json::Value operations;
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
156 LuaFunctionCall call2(lua_, "_AccessJob");
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
157 call2.ExecuteToJson(operations);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
158
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
159 if (operations.type() != Json::arrayValue)
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
160 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
161 throw OrthancException(ErrorCode_InternalError);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
162 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
163
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
164 ServerJob job;
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
165 ServerCommandInstance* previousCommand = NULL;
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
166
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
167 for (Json::Value::ArrayIndex i = 0; i < operations.size(); ++i)
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
168 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
169 if (operations[i].type() != Json::objectValue ||
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
170 !operations[i].isMember("Operation"))
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
171 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
172 throw OrthancException(ErrorCode_InternalError);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
173 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
174
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
175 const Json::Value& parameters = operations[i];
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
176 std::string operation = parameters["Operation"].asString();
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
177
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
178 ServerCommandInstance& command = job.AddCommand(ParseOperation(operation, operations[i]));
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
179
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
180 if (!parameters.isMember("Resource"))
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
181 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
182 throw OrthancException(ErrorCode_InternalError);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
183 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
184
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
185 std::string resource = parameters["Resource"].asString();
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
186 if (resource.empty())
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
187 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
188 previousCommand->ConnectOutput(command);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
189 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
190 else
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
191 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
192 command.AddInput(resource);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
193 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
194
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
195 previousCommand = &command;
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
196 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
197
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
198 job.SetDescription(description);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
199 context_.GetScheduler().Submit(job);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
200 }
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
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 LuaScripting::LuaScripting(ServerContext& context) : context_(context)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 lua_.SetHttpProxy(Configuration::GetGlobalStringParameter("HttpProxy", ""));
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 void LuaScripting::ApplyOnStoredInstance(const std::string& instanceId,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 const Json::Value& simplifiedTags,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 const Json::Value& metadata,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 const std::string& remoteAet,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 const std::string& calledAet)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 {
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
216 static const char* NAME = "OnStoredInstance";
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 if (lua_.IsExistingFunction(NAME))
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 {
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
220 InitializeJob();
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
222 LuaFunctionCall call(lua_, NAME);
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 call.PushString(instanceId);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 call.PushJson(simplifiedTags);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 call.PushJson(metadata);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 call.PushJson(remoteAet);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 call.PushJson(calledAet);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 call.Execute();
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
230 SubmitJob(std::string("Lua script: ") + NAME);
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 void LuaScripting::SignalStoredInstance(const std::string& publicId,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 DicomInstanceToStore& instance,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 const Json::Value& simplifiedTags)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 boost::mutex::scoped_lock lock(mutex_);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 Json::Value metadata = Json::objectValue;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 for (ServerIndex::MetadataMap::const_iterator
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 it = instance.GetMetadata().begin();
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 it != instance.GetMetadata().end(); ++it)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 if (it->first.first == ResourceType_Instance)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 metadata[EnumerationToString(it->first.second)] = it->second;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 ApplyOnStoredInstance(publicId, simplifiedTags, metadata,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 instance.GetRemoteAet(), instance.GetCalledAet());
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
258
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
259 void LuaScripting::OnStableResource(const ServerIndexChange& change)
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
260 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
261 const char* name;
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
262
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
263 switch (change.GetChangeType())
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
264 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
265 case ChangeType_StablePatient:
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
266 name = "OnStablePatient";
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
267 break;
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
268
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
269 case ChangeType_StableStudy:
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
270 name = "OnStableStudy";
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
271 break;
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
272
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
273 case ChangeType_StableSeries:
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
274 name = "OnStableSeries";
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
275 break;
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
276
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
277 default:
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
278 throw OrthancException(ErrorCode_InternalError);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
279 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
280
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
281
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
282 Json::Value tags;
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
283 //if (context_.GetIndex().LookupResource(tags, change.GetPublicId(), change.GetResourceType()))
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
284 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
285 boost::mutex::scoped_lock lock(mutex_);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
286
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
287 if (lua_.IsExistingFunction(name))
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
288 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
289 InitializeJob();
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
290
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
291 LuaFunctionCall call(lua_, name);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
292 call.PushString(change.GetPublicId());
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
293 call.PushJson(tags);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
294 call.Execute();
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
295
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
296 SubmitJob(std::string("Lua script: ") + name);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
297 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
298 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
299 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
300
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
301
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
302
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 void LuaScripting::SignalChange(const ServerIndexChange& change)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 {
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
305 if (change.GetChangeType() == ChangeType_StablePatient ||
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
306 change.GetChangeType() == ChangeType_StableStudy ||
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
307 change.GetChangeType() == ChangeType_StableSeries)
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
308 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
309 OnStableResource(change);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
310 }
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 bool LuaScripting::FilterIncomingInstance(const Json::Value& simplified,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 const std::string& remoteAet)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 {
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
317 static const char* NAME = "ReceivedInstanceFilter";
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
318
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 boost::mutex::scoped_lock lock(mutex_);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
321 if (lua_.IsExistingFunction(NAME))
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 {
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
323 LuaFunctionCall call(lua_, NAME);
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 call.PushJson(simplified);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 call.PushString(remoteAet);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 if (!call.ExecutePredicate())
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 return false;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 return true;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 }