annotate OrthancServer/LuaScripting.cpp @ 3636:bce6ee64f2a4 storage-commitment

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 31 Jan 2020 14:29:35 +0100
parents dd1e68f2d0c0
children 94f4a18a79cc
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
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1698
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
3060
4e43e67f8ecf preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * 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
18 * modify file(s) with this exception, you may extend this exception to
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * 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
20 * 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
21 * version. If you delete this exception statement from all source files
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * 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
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
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
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "PrecompiledHeadersServer.h"
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "LuaScripting.h"
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
37 #include "OrthancConfiguration.h"
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
38 #include "OrthancRestApi/OrthancRestApi.h"
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include "ServerContext.h"
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
40
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
41 #include "../Core/HttpServer/StringHttpOutput.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1465
diff changeset
42 #include "../Core/Logging.h"
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
43 #include "../Core/Lua/LuaFunctionCall.h"
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 #include <EmbeddedResources.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
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 namespace Orthanc
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
50 class LuaScripting::IEvent : public IDynamicObject
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
51 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
52 public:
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
53 virtual void Apply(LuaScripting& lock) = 0;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
54 };
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
55
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
56
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
57 class LuaScripting::OnStoredInstanceEvent : public LuaScripting::IEvent
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
58 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
59 private:
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
60 std::string instanceId_;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
61 Json::Value simplifiedTags_;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
62 Json::Value metadata_;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
63 Json::Value origin_;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
64
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
65 public:
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
66 OnStoredInstanceEvent(const std::string& instanceId,
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
67 const Json::Value& simplifiedTags,
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
68 const Json::Value& metadata,
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
69 const DicomInstanceToStore& instance) :
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
70 instanceId_(instanceId),
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
71 simplifiedTags_(simplifiedTags),
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
72 metadata_(metadata)
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
73 {
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2638
diff changeset
74 instance.GetOrigin().Format(origin_);
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
75 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
76
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
77 virtual void Apply(LuaScripting& that)
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
78 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
79 static const char* NAME = "OnStoredInstance";
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
80
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
81 LuaScripting::Lock lock(that);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
82
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
83 if (lock.GetLua().IsExistingFunction(NAME))
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
84 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
85 that.InitializeJob();
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
86
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
87 LuaFunctionCall call(lock.GetLua(), NAME);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
88 call.PushString(instanceId_);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
89 call.PushJson(simplifiedTags_);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
90 call.PushJson(metadata_);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
91 call.PushJson(origin_);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
92 call.Execute();
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
93
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
94 that.SubmitJob();
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
95 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
96 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
97 };
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
98
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
99
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
100 class LuaScripting::ExecuteEvent : public LuaScripting::IEvent
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
101 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
102 private:
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
103 std::string command_;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
104
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
105 public:
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
106 ExecuteEvent(const std::string& command) :
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
107 command_(command)
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
108 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
109 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
110
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
111 virtual void Apply(LuaScripting& that)
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
112 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
113 LuaScripting::Lock lock(that);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
114
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
115 if (lock.GetLua().IsExistingFunction(command_.c_str()))
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
116 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
117 LuaFunctionCall call(lock.GetLua(), command_.c_str());
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
118 call.Execute();
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
119 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
120 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
121 };
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
122
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
123
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
124 class LuaScripting::StableResourceEvent : public LuaScripting::IEvent
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
125 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
126 private:
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
127 ServerIndexChange change_;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
128
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
129 public:
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
130 StableResourceEvent(const ServerIndexChange& change) :
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
131 change_(change)
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
132 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
133 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
134
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
135 virtual void Apply(LuaScripting& that)
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
136 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
137 const char* name;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
138
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
139 switch (change_.GetChangeType())
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
140 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
141 case ChangeType_StablePatient:
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
142 name = "OnStablePatient";
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
143 break;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
144
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
145 case ChangeType_StableStudy:
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
146 name = "OnStableStudy";
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
147 break;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
148
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
149 case ChangeType_StableSeries:
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
150 name = "OnStableSeries";
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
151 break;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
152
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
153 default:
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
154 throw OrthancException(ErrorCode_InternalError);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
155 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
156
2638
25ae209dcea9 Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
157 {
25ae209dcea9 Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
158 // Avoid unnecessary calls to the database if there's no Lua callback
25ae209dcea9 Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
159 LuaScripting::Lock lock(that);
25ae209dcea9 Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
160
25ae209dcea9 Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
161 if (!lock.GetLua().IsExistingFunction(name))
25ae209dcea9 Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
162 {
25ae209dcea9 Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
163 return;
25ae209dcea9 Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
164 }
25ae209dcea9 Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
165 }
25ae209dcea9 Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
166
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
167 Json::Value tags;
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
168
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
169 if (that.context_.GetIndex().LookupResource(tags, change_.GetPublicId(), change_.GetResourceType()))
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
170 {
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
171 std::map<MetadataType, std::string> metadata;
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
172 that.context_.GetIndex().GetAllMetadata(metadata, change_.GetPublicId());
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
173
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
174 Json::Value formattedMetadata = Json::objectValue;
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
175
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
176 for (std::map<MetadataType, std::string>::const_iterator
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
177 it = metadata.begin(); it != metadata.end(); ++it)
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
178 {
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
179 std::string key = EnumerationToString(it->first);
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
180 formattedMetadata[key] = it->second;
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
181 }
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
182
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
183 {
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
184 LuaScripting::Lock lock(that);
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
185
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
186 if (lock.GetLua().IsExistingFunction(name))
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
187 {
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
188 that.InitializeJob();
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
189
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
190 LuaFunctionCall call(lock.GetLua(), name);
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
191 call.PushString(change_.GetPublicId());
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
192 call.PushJson(tags["MainDicomTags"]);
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
193 call.PushJson(formattedMetadata);
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
194 call.Execute();
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
195
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
196 that.SubmitJob();
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
197 }
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
198 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
199 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
200 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
201 };
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
202
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
203
2675
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
204 class LuaScripting::JobEvent : public LuaScripting::IEvent
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
205 {
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
206 public:
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
207 enum Type
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
208 {
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
209 Type_Failure,
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
210 Type_Submitted,
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
211 Type_Success
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
212 };
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
213
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
214 private:
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
215 Type type_;
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
216 std::string jobId_;
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
217
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
218 public:
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
219 JobEvent(Type type,
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
220 const std::string& jobId) :
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
221 type_(type),
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
222 jobId_(jobId)
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
223 {
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
224 }
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
225
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
226 virtual void Apply(LuaScripting& that)
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
227 {
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
228 std::string functionName;
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
229
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
230 switch (type_)
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
231 {
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
232 case Type_Failure:
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
233 functionName = "OnJobFailure";
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
234 break;
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
235
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
236 case Type_Submitted:
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
237 functionName = "OnJobSubmitted";
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
238 break;
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
239
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
240 case Type_Success:
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
241 functionName = "OnJobSuccess";
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
242 break;
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
243
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
244 default:
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
245 throw OrthancException(ErrorCode_InternalError);
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
246 }
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
247
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
248 {
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
249 LuaScripting::Lock lock(that);
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
250
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
251 if (lock.GetLua().IsExistingFunction(functionName.c_str()))
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
252 {
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
253 LuaFunctionCall call(lock.GetLua(), functionName.c_str());
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
254 call.PushString(jobId_);
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
255 call.Execute();
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
256 }
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
257 }
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
258 }
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
259 };
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
260
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
261
1444
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
262 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
263 {
1444
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
264 const void* value = LuaContext::GetGlobalVariable(state, "_ServerContext");
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
265 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
266 }
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
267
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
268
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
269 // Syntax in Lua: RestApiGet(uri, builtin)
1444
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
270 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
271 {
1444
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
272 ServerContext* serverContext = GetServerContext(state);
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
273 if (serverContext == NULL)
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
274 {
1440
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
275 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
276 lua_pushnil(state);
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
277 return 1;
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
278 }
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
279
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
280 // Check the types of the arguments
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
281 int nArgs = lua_gettop(state);
3442
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
282 if (nArgs < 1 || nArgs > 3 ||
1444
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
283 !lua_isstring(state, 1) || // URI
3442
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
284 (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
285 {
1444
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
286 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
287 lua_pushnil(state);
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
288 return 1;
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
289 }
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
290
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
291 const char* uri = lua_tostring(state, 1);
1545
33d34bc4ac15 fix msvc warnings
jodogne
parents: 1486
diff changeset
292 bool builtin = (nArgs == 2 ? lua_toboolean(state, 2) != 0 : false);
1444
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
293
3442
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
294 std::map<std::string, std::string> headers;
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
295 LuaContext::GetDictionaryArgument(headers, state, 3, true /* HTTP header key to lower case */);
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
296
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
297 try
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
298 {
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
299 std::string result;
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
300 if (HttpToolbox::SimpleGet(result, serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin),
3442
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
301 RequestOrigin_Lua, uri, headers))
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
302 {
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
303 lua_pushlstring(state, result.c_str(), result.size());
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
304 return 1;
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
305 }
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
306 }
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
307 catch (OrthancException& e)
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
308 {
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
309 LOG(ERROR) << "Lua: " << e.What();
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
310 }
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
311
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
312 LOG(ERROR) << "Lua: Error in RestApiGet() for URI: " << uri;
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
313 lua_pushnil(state);
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
314 return 1;
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
315 }
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
316
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
317
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
318 int LuaScripting::RestApiPostOrPut(lua_State *state,
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
319 bool isPost)
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
320 {
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
321 ServerContext* serverContext = GetServerContext(state);
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
322 if (serverContext == NULL)
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
323 {
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
324 LOG(ERROR) << "Lua: The Orthanc API is unavailable";
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
325 lua_pushnil(state);
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
326 return 1;
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
327 }
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
328
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
329 // Check the types of the arguments
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
330 int nArgs = lua_gettop(state);
3442
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
331 if (nArgs < 2 || nArgs > 4 ||
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
332 !lua_isstring(state, 1) || // URI
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
333 !lua_isstring(state, 2) || // Body
3442
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
334 (nArgs >= 3 && !lua_isboolean(state, 3))) // Restrict to built-in API?
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
335 {
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
336 LOG(ERROR) << "Lua: Bad parameters to " << (isPost ? "RestApiPost()" : "RestApiPut()");
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
337 lua_pushnil(state);
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
338 return 1;
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
339 }
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
340
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
341 const char* uri = lua_tostring(state, 1);
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
342 size_t bodySize = 0;
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
343 const char* bodyData = lua_tolstring(state, 2, &bodySize);
1545
33d34bc4ac15 fix msvc warnings
jodogne
parents: 1486
diff changeset
344 bool builtin = (nArgs == 3 ? lua_toboolean(state, 3) != 0 : false);
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
345
3442
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
346 std::map<std::string, std::string> headers;
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
347 LuaContext::GetDictionaryArgument(headers, state, 4, true /* HTTP header key to lower case */);
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
348
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
349 try
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
350 {
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
351 std::string result;
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
352 if (isPost ?
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
353 HttpToolbox::SimplePost(result, serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin),
3442
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
354 RequestOrigin_Lua, uri, bodyData, bodySize, headers) :
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
355 HttpToolbox::SimplePut(result, serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin),
3442
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
356 RequestOrigin_Lua, uri, bodyData, bodySize, headers))
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
357 {
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
358 lua_pushlstring(state, result.c_str(), result.size());
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
359 return 1;
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
360 }
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
361 }
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
362 catch (OrthancException& e)
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
363 {
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
364 LOG(ERROR) << "Lua: " << e.What();
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
365 }
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
366
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
367 LOG(ERROR) << "Lua: Error in " << (isPost ? "RestApiPost()" : "RestApiPut()") << " for URI: " << uri;
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
368 lua_pushnil(state);
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
369 return 1;
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
370 }
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
371
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
372
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
373 // Syntax in Lua: RestApiPost(uri, body, builtin)
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
374 int LuaScripting::RestApiPost(lua_State *state)
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
375 {
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
376 return RestApiPostOrPut(state, true);
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
377 }
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
378
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
379
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
380 // Syntax in Lua: RestApiPut(uri, body, builtin)
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
381 int LuaScripting::RestApiPut(lua_State *state)
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
382 {
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
383 return RestApiPostOrPut(state, false);
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
384 }
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
385
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
386
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
387 // Syntax in Lua: RestApiDelete(uri, builtin)
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
388 int LuaScripting::RestApiDelete(lua_State *state)
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
389 {
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
390 ServerContext* serverContext = GetServerContext(state);
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
391 if (serverContext == NULL)
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
392 {
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
393 LOG(ERROR) << "Lua: The Orthanc API is unavailable";
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
394 lua_pushnil(state);
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
395 return 1;
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
396 }
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
397
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
398 // Check the types of the arguments
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
399 int nArgs = lua_gettop(state);
3442
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
400 if (nArgs < 1 || nArgs > 3 ||
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
401 !lua_isstring(state, 1) || // URI
3442
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
402 (nArgs >= 2 && !lua_isboolean(state, 2))) // Restrict to built-in API?
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
403 {
1449
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
404 LOG(ERROR) << "Lua: Bad parameters to RestApiDelete()";
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
405 lua_pushnil(state);
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
406 return 1;
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
407 }
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
408
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
409 const char* uri = lua_tostring(state, 1);
1545
33d34bc4ac15 fix msvc warnings
jodogne
parents: 1486
diff changeset
410 bool builtin = (nArgs == 2 ? lua_toboolean(state, 2) != 0 : false);
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
411
3442
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
412 std::map<std::string, std::string> headers;
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
413 LuaContext::GetDictionaryArgument(headers, state, 3, true /* HTTP header key to lower case */);
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
414
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
415 try
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
416 {
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
417 if (HttpToolbox::SimpleDelete(serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin),
3442
dd1e68f2d0c0 Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
418 RequestOrigin_Lua, uri, headers))
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
419 {
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
420 lua_pushboolean(state, 1);
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
421 return 1;
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
422 }
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
423 }
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
424 catch (OrthancException& e)
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
425 {
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
426 LOG(ERROR) << "Lua: " << e.What();
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
427 }
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
428
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
429 LOG(ERROR) << "Lua: Error in RestApiDelete() for URI: " << uri;
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
430 lua_pushnil(state);
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
431
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
432 return 1;
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
433 }
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
434
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
435
1587
d7e569640d09 New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1574
diff changeset
436 // Syntax in Lua: GetOrthancConfiguration()
d7e569640d09 New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1574
diff changeset
437 int LuaScripting::GetOrthancConfiguration(lua_State *state)
d7e569640d09 New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1574
diff changeset
438 {
d7e569640d09 New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1574
diff changeset
439 Json::Value configuration;
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
440
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
441 {
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
442 OrthancConfiguration::ReaderLock lock;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
443 configuration = lock.GetJson();
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
444 }
1587
d7e569640d09 New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1574
diff changeset
445
d7e569640d09 New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1574
diff changeset
446 LuaContext::GetLuaContext(state).PushJson(configuration);
d7e569640d09 New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1574
diff changeset
447
d7e569640d09 New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1574
diff changeset
448 return 1;
d7e569640d09 New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1574
diff changeset
449 }
d7e569640d09 New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1574
diff changeset
450
d7e569640d09 New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1574
diff changeset
451
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
452 size_t LuaScripting::ParseOperation(LuaJobManager::Lock& lock,
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
453 const std::string& operation,
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
454 const Json::Value& parameters)
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 if (operation == "delete")
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 {
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
458 LOG(INFO) << "Lua script to delete resource " << parameters["Resource"].asString();
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
459 return lock.AddDeleteResourceOperation(context_);
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 if (operation == "store-scu")
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 std::string localAet;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 if (parameters.isMember("LocalAet"))
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 localAet = parameters["LocalAet"].asString();
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 else
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 localAet = context_.GetDefaultLocalApplicationEntityTitle();
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
474 std::string name = parameters["Modality"].asString();
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
475 RemoteModalityParameters modality;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
476
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
477 {
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
478 OrthancConfiguration::ReaderLock configLock;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
479 modality = configLock.GetConfiguration().GetModalityUsingSymbolicName(name);
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
480 }
2222
21713ce8717b Fix handling of Move Originator AET and ID in C-MOVE SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2020
diff changeset
481
21713ce8717b Fix handling of Move Originator AET and ID in C-MOVE SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2020
diff changeset
482 // This is not a C-MOVE: No need to call "StoreScuCommand::SetMoveOriginator()"
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
483 return lock.AddStoreScuOperation(localAet, modality);
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 if (operation == "store-peer")
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 {
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
488 OrthancConfiguration::ReaderLock configLock;
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
489 std::string name = parameters["Peer"].asString();
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
491 WebServiceParameters peer;
2944
f395460af74d simplifying OrthancConfiguration for modalities/peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
492 if (configLock.GetConfiguration().LookupOrthancPeer(peer, name))
2799
6e3a60b85da6 New primitives to access Orthanc peers from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2738
diff changeset
493 {
6e3a60b85da6 New primitives to access Orthanc peers from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2738
diff changeset
494 return lock.AddStorePeerOperation(peer);
6e3a60b85da6 New primitives to access Orthanc peers from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2738
diff changeset
495 }
6e3a60b85da6 New primitives to access Orthanc peers from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2738
diff changeset
496 else
6e3a60b85da6 New primitives to access Orthanc peers from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2738
diff changeset
497 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2944
diff changeset
498 throw OrthancException(ErrorCode_UnknownResource,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2944
diff changeset
499 "No peer with symbolic name: " + name);
2799
6e3a60b85da6 New primitives to access Orthanc peers from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2738
diff changeset
500 }
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 if (operation == "modify")
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 {
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1658
diff changeset
505 std::auto_ptr<DicomModification> modification(new DicomModification);
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
506 modification->ParseModifyRequest(parameters);
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
508 return lock.AddModifyInstanceOperation(context_, modification.release());
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 if (operation == "call-system")
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 {
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
513 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
514
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 const Json::Value& argsIn = parameters["Arguments"];
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 if (argsIn.type() != Json::arrayValue)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 throw OrthancException(ErrorCode_BadParameterType);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 std::vector<std::string> args;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 args.reserve(argsIn.size());
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 for (Json::Value::ArrayIndex i = 0; i < argsIn.size(); ++i)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 // http://jsoncpp.sourceforge.net/namespace_json.html#7d654b75c16a57007925868e38212b4e
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 switch (argsIn[i].type())
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 case Json::stringValue:
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 args.push_back(argsIn[i].asString());
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 break;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 case Json::intValue:
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asInt()));
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 break;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 case Json::uintValue:
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asUInt()));
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 break;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 case Json::realValue:
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asFloat()));
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 break;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 default:
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 throw OrthancException(ErrorCode_BadParameterType);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
549 std::string command = parameters["Command"].asString();
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
550 std::vector<std::string> postArgs;
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
551
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
552 return lock.AddSystemCallOperation(command, args, postArgs);
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 throw OrthancException(ErrorCode_ParameterOutOfRange);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
559 void LuaScripting::InitializeJob()
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
560 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
561 lua_.Execute("_InitializeJob()");
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
562 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
563
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
564
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
565 void LuaScripting::SubmitJob()
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
566 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
567 Json::Value operations;
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
568 LuaFunctionCall call2(lua_, "_AccessJob");
1658
54bafe0e7e7b Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
569 call2.ExecuteToJson(operations, false);
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
570
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
571 if (operations.type() != Json::arrayValue)
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
572 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
573 throw OrthancException(ErrorCode_InternalError);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
574 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
575
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
576 LuaJobManager::Lock lock(jobManager_, context_.GetJobsEngine());
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
577
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
578 bool isFirst = true;
2727
815e30657dad fix warning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2675
diff changeset
579 size_t previous = 0; // Dummy initialization to avoid warning
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
580
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
581 for (Json::Value::ArrayIndex i = 0; i < operations.size(); ++i)
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
582 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
583 if (operations[i].type() != Json::objectValue ||
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
584 !operations[i].isMember("Operation"))
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
585 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
586 throw OrthancException(ErrorCode_InternalError);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
587 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
588
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
589 const Json::Value& parameters = operations[i];
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
590 if (!parameters.isMember("Resource"))
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
591 {
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
592 throw OrthancException(ErrorCode_InternalError);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
593 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
594
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
595 std::string operation = parameters["Operation"].asString();
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
596 size_t index = ParseOperation(lock, operation, operations[i]);
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
597
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
598 std::string resource = parameters["Resource"].asString();
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
599 if (!resource.empty())
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
600 {
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
601 lock.AddDicomInstanceInput(index, context_, resource);
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
602 }
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
603 else if (!isFirst)
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
604 {
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
605 lock.Connect(previous, index);
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
606 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
607
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
608 isFirst = false;
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
609 previous = index;
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
610 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
611 }
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
612
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
613
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
614 LuaScripting::LuaScripting(ServerContext& context) :
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
615 context_(context),
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2649
diff changeset
616 state_(State_Setup)
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 {
1444
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
618 lua_.SetGlobalVariable("_ServerContext", &context);
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
619 lua_.RegisterFunction("RestApiGet", RestApiGet);
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
620 lua_.RegisterFunction("RestApiPost", RestApiPost);
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
621 lua_.RegisterFunction("RestApiPut", RestApiPut);
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
622 lua_.RegisterFunction("RestApiDelete", RestApiDelete);
1587
d7e569640d09 New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1574
diff changeset
623 lua_.RegisterFunction("GetOrthancConfiguration", GetOrthancConfiguration);
2738
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2727
diff changeset
624
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2727
diff changeset
625 LOG(INFO) << "Initializing Lua for the event handler";
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2727
diff changeset
626 LoadGlobalConfiguration();
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
627 }
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
628
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
629
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
630 LuaScripting::~LuaScripting()
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
631 {
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2649
diff changeset
632 if (state_ == State_Running)
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
633 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
634 LOG(ERROR) << "INTERNAL ERROR: LuaScripting::Stop() should be invoked manually to avoid mess in the destruction order!";
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
635 Stop();
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
636 }
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
640 void LuaScripting::EventThread(LuaScripting* that)
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 {
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
642 for (;;)
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
643 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
644 std::auto_ptr<IDynamicObject> event(that->pendingEvents_.Dequeue(100));
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
645
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
646 if (event.get() == NULL)
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
647 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
648 // The event queue is empty, check whether we should stop
2618
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
649 boost::recursive_mutex::scoped_lock lock(that->mutex_);
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
650
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2649
diff changeset
651 if (that->state_ != State_Running)
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
652 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
653 return;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
654 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
655 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
656 else
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
657 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
658 try
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
659 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
660 dynamic_cast<IEvent&>(*event).Apply(*that);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
661 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
662 catch (OrthancException& e)
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
663 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
664 LOG(ERROR) << "Error while processing Lua events: " << e.What();
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
665 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
666 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
667 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
668 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
669
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
671 void LuaScripting::Start()
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
672 {
2618
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
673 boost::recursive_mutex::scoped_lock lock(mutex_);
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
674
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2649
diff changeset
675 if (state_ != State_Setup ||
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
676 eventThread_.joinable() /* already started */)
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
677 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
678 throw OrthancException(ErrorCode_BadSequenceOfCalls);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
679 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
680 else
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
681 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
682 LOG(INFO) << "Starting the Lua engine";
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
683 eventThread_ = boost::thread(EventThread, this);
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
684 state_ = State_Running;
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
685 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
686 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
687
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
688
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
689 void LuaScripting::Stop()
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
690 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
691 {
2618
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
692 boost::recursive_mutex::scoped_lock lock(mutex_);
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
693
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2649
diff changeset
694 if (state_ != State_Running)
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
695 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
696 throw OrthancException(ErrorCode_BadSequenceOfCalls);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
697 }
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
698
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2649
diff changeset
699 state_ = State_Done;
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
700 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
701
2620
1232922c8793 speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2618
diff changeset
702 jobManager_.AwakeTrailingSleep();
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
704 if (eventThread_.joinable())
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
705 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
706 LOG(INFO) << "Stopping the Lua engine";
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
707 eventThread_.join();
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
708 LOG(INFO) << "The Lua engine has stopped";
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 void LuaScripting::SignalStoredInstance(const std::string& publicId,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 DicomInstanceToStore& instance,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 const Json::Value& simplifiedTags)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 Json::Value metadata = Json::objectValue;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 for (ServerIndex::MetadataMap::const_iterator
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720 it = instance.GetMetadata().begin();
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 it != instance.GetMetadata().end(); ++it)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 if (it->first.first == ResourceType_Instance)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 metadata[EnumerationToString(it->first.second)] = it->second;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
729 pendingEvents_.Enqueue(new OnStoredInstanceEvent(publicId, simplifiedTags, metadata, instance));
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 void LuaScripting::SignalChange(const ServerIndexChange& change)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 {
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
735 if (change.GetChangeType() == ChangeType_StablePatient ||
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
736 change.GetChangeType() == ChangeType_StableStudy ||
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
737 change.GetChangeType() == ChangeType_StableSeries)
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
738 {
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
739 pendingEvents_.Enqueue(new StableResourceEvent(change));
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
740 }
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743
1574
0c29ebe80ac9 give access to full request origin in ReceivedInstanceFilter (Lua)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
744 bool LuaScripting::FilterIncomingInstance(const DicomInstanceToStore& instance,
0c29ebe80ac9 give access to full request origin in ReceivedInstanceFilter (Lua)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
745 const Json::Value& simplified)
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 {
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
747 static const char* NAME = "ReceivedInstanceFilter";
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
748
1456
68827c07e683 fix recursive calls with Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
749 boost::recursive_mutex::scoped_lock lock(mutex_);
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
751 if (lua_.IsExistingFunction(NAME))
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 {
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
753 LuaFunctionCall call(lua_, NAME);
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 call.PushJson(simplified);
1574
0c29ebe80ac9 give access to full request origin in ReceivedInstanceFilter (Lua)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
755
0c29ebe80ac9 give access to full request origin in ReceivedInstanceFilter (Lua)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
756 Json::Value origin;
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2638
diff changeset
757 instance.GetOrigin().Format(origin);
1574
0c29ebe80ac9 give access to full request origin in ReceivedInstanceFilter (Lua)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
758 call.PushJson(origin);
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 if (!call.ExecutePredicate())
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 return false;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 return true;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 }
1455
a68545767975 Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1449
diff changeset
768
a68545767975 Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1449
diff changeset
769
a68545767975 Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1449
diff changeset
770 void LuaScripting::Execute(const std::string& command)
a68545767975 Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1449
diff changeset
771 {
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
772 pendingEvents_.Enqueue(new ExecuteEvent(command));
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
773 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
774
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
775
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
776 void LuaScripting::LoadGlobalConfiguration()
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
777 {
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
778 OrthancConfiguration::ReaderLock configLock;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
779
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
780 lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
781
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
782 std::list<std::string> luaScripts;
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
783 configLock.GetConfiguration().GetListOfStringsParameter(luaScripts, "LuaScripts");
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
784
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
785 LuaScripting::Lock lock(*this);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
786
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
787 for (std::list<std::string>::const_iterator
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
788 it = luaScripts.begin(); it != luaScripts.end(); ++it)
1455
a68545767975 Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1449
diff changeset
789 {
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2799
diff changeset
790 std::string path = configLock.GetConfiguration().InterpretStringParameterAsPath(*it);
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
791 LOG(INFO) << "Installing the Lua scripts from: " << path;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
792 std::string script;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
793 SystemToolbox::ReadFile(script, path);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
794
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
795 lock.GetLua().Execute(script);
1455
a68545767975 Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1449
diff changeset
796 }
a68545767975 Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1449
diff changeset
797 }
2675
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
798
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
799
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
800 void LuaScripting::SignalJobSubmitted(const std::string& jobId)
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
801 {
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
802 pendingEvents_.Enqueue(new JobEvent(JobEvent::Type_Submitted, jobId));
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
803 }
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
804
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
805
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
806 void LuaScripting::SignalJobSuccess(const std::string& jobId)
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
807 {
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
808 pendingEvents_.Enqueue(new JobEvent(JobEvent::Type_Success, jobId));
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
809 }
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
810
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
811
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
812 void LuaScripting::SignalJobFailure(const std::string& jobId)
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
813 {
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
814 pendingEvents_.Enqueue(new JobEvent(JobEvent::Type_Failure, jobId));
3fc310ceb6d4 lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
815 }
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 }