annotate OrthancServer/LuaScripting.h @ 1444:b2b09a3dbd8e

refactoring: OrthancHttpHandler inside OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 01 Jul 2015 12:09:58 +0200
parents f3672356c121
children 5ba7471780ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #pragma once
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "IServerListener.h"
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "../Core/Lua/LuaContext.h"
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "Scheduler/IServerCommand.h"
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 namespace Orthanc
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 class ServerContext;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 class LuaScripting : public IServerListener
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 private:
1444
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
46 static ServerContext* GetServerContext(lua_State *state);
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1435
diff changeset
47
1444
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
48 static int RestApiGet(lua_State *state);
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1435
diff changeset
49
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 void ApplyOnStoredInstance(const std::string& instanceId,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 const Json::Value& simplifiedDicom,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 const Json::Value& metadata,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 const std::string& remoteAet,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 const std::string& calledAet);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 IServerCommand* ParseOperation(const std::string& operation,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 const Json::Value& parameters);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
59 void InitializeJob();
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
60
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
61 void SubmitJob(const std::string& description);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
62
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
63 void OnStableResource(const ServerIndexChange& change);
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
64
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 boost::mutex mutex_;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 LuaContext lua_;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 ServerContext& context_;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 public:
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 class Locker : public boost::noncopyable
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 private:
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 LuaScripting& that_;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 public:
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 Locker(LuaScripting& that) : that_(that)
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 that.mutex_.lock();
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 ~Locker()
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 that_.mutex_.unlock();
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 LuaContext& GetLua()
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 return that_.lua_;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 };
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 LuaScripting(ServerContext& context);
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1435
diff changeset
93
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 virtual void SignalStoredInstance(const std::string& publicId,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 DicomInstanceToStore& instance,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 const Json::Value& simplifiedTags);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 virtual void SignalChange(const ServerIndexChange& change);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 virtual bool FilterIncomingInstance(const Json::Value& simplified,
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 const std::string& remoteAet);
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 };
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }