libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
ScriptInfo.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29 */
30 
31 #ifndef ISCRIPTINFO_H_
32 #define ISCRIPTINFO_H_
33 
34 #include "../Sockets/ServerInfo.h"
35 #include "../Encoding/Http.h"
36 
37 #include <string>
38 #include <mutex>
39 #include <condition_variable>
40 #include <functional>
41 
42 #include "../Sockets/TcpSocket.h"
43 
44 namespace BaseLib
45 {
46 
48 typedef std::shared_ptr<RpcClientInfo> PRpcClientInfo;
49 
50 namespace ScriptEngine
51 {
52 
53 class ScriptInfo;
54 class ScriptInfoCli;
55 class ScriptInfoWeb;
56 class ScriptInfoDevice;
57 typedef std::shared_ptr<ScriptInfo> PScriptInfo;
58 typedef std::shared_ptr<ScriptInfoCli> PScriptInfoCli;
59 typedef std::shared_ptr<ScriptInfoWeb> PScriptInfoWeb;
60 typedef std::shared_ptr<ScriptInfoDevice> PScriptInfoDevice;
61 
66 {
67 public:
68  enum class ScriptType
69  {
70  cli,
71  device,
72  device2,
73  web,
74  simpleNode,
76  };
77 
78  int32_t id = 0;
79 
80  // {{{ Input parameters
81  std::string fullPath;
82  std::string relativePath;
83  std::string arguments;
84  int32_t customId = 0;
85  bool returnOutput = false;
86 
87  Http http; //Web
89  PRpcClientInfo clientInfo; //Web
90  std::string contentPath;
91 
92  std::string script; //Device
93  int64_t peerId = 0; //Device
94 
96  uint32_t inputPort = 0; //Node
98 
99  uint32_t maxThreadCount = 0; //Node
100  // }}}
101 
102  // {{{ Output parameters
103  bool started = false;
104  bool finished = false;
105  int32_t exitCode = -1;
106  std::string output;
107  // }}}
108 
109 
110  std::function<void(PScriptInfo& scriptInfo, std::string& output, bool error)> scriptOutputCallback;
111  std::function<void(PScriptInfo& scriptInfo, PVariable& headers)> scriptHeadersCallback;
112 
113  // {{{ Script finished notification. Can be combined.
114  // Option 1: Call scriptFinishedCallback
115  std::function<void(PScriptInfo& scriptInfo, int32_t exitCode)> scriptFinishedCallback;
116 
117  // Option 2: Wait for script
118  std::mutex requestMutex;
119  std::condition_variable requestConditionVariable;
120 
121  // Option 3: Write to socket
123  // }}}
124 
125  explicit ScriptInfo(ScriptType type);
126  ScriptInfo(ScriptType type, std::string& fullPath, std::string& relativePath, std::string& arguments);
127  ScriptInfo(ScriptType type, std::string& contentPath, std::string& fullPath, std::string& relativePath, Http& http, Rpc::PServerInfo& serverInfo, PRpcClientInfo& clientInfo);
128  ScriptInfo(BaseLib::SharedObjects* bl, ScriptType type, std::string& contentPath, std::string& fullPath, std::string& relativePath, PVariable http, PVariable serverInfo, PVariable clientInfo);
129  ScriptInfo(ScriptType type, std::string& fullPath, std::string& relativePath, std::string& script, std::string& arguments);
130  ScriptInfo(ScriptType type, std::string& fullPath, std::string& relativePath, std::string& script, std::string& arguments, int64_t peerId);
131  ScriptInfo(ScriptType type, PVariable nodeInfo, std::string& fullPath, std::string& relativePath, uint32_t inputPort, PVariable message);
132  ScriptInfo(ScriptType type, PVariable nodeInfo, std::string& fullPath, std::string& relativePath, uint32_t maxThreadCount);
133  virtual ~ScriptInfo() = default;
134  ScriptType getType() { return _type; }
135 protected:
137 };
138 }
139 }
140 #endif
141 
142 
std::string contentPath
Definition: ScriptInfo.h:90
uint32_t inputPort
Definition: ScriptInfo.h:96
ScriptInfo(ScriptType type)
Definition: ScriptInfo.cpp:43
This is the base library main class.
Definition: BaseLib.h:95
std::string script
Definition: ScriptInfo.h:92
std::string fullPath
Definition: ScriptInfo.h:81
int32_t customId
Definition: ScriptInfo.h:84
std::condition_variable requestConditionVariable
Definition: ScriptInfo.h:119
Definition: RpcClientInfo.h:72
std::function< void(PScriptInfo &scriptInfo, int32_t exitCode)> scriptFinishedCallback
Definition: ScriptInfo.h:115
Definition: BaseLib.cpp:34
ScriptType _type
Definition: ScriptInfo.h:136
Http http
Definition: ScriptInfo.h:87
std::shared_ptr< RpcClientInfo > PRpcClientInfo
Definition: ScriptInfo.h:47
std::shared_ptr< ScriptInfoWeb > PScriptInfoWeb
Definition: ScriptInfo.h:59
std::mutex requestMutex
Definition: ScriptInfo.h:118
bool returnOutput
Definition: ScriptInfo.h:85
PVariable message
Definition: ScriptInfo.h:97
std::shared_ptr< ScriptInfo > PScriptInfo
Definition: ScriptInfo.h:56
std::string arguments
Definition: ScriptInfo.h:83
std::function< void(PScriptInfo &scriptInfo, std::string &output, bool error)> scriptOutputCallback
Definition: ScriptInfo.h:110
bool started
Definition: ScriptInfo.h:103
std::shared_ptr< Variable > PVariable
Definition: PhysicalInterfaceSettings.h:41
PRpcClientInfo clientInfo
Definition: ScriptInfo.h:89
bool finished
Definition: ScriptInfo.h:104
std::string relativePath
Definition: ScriptInfo.h:82
Definition: Http.h:57
This class provides hooks into the script engine server so family modules can be notified about finis...
Definition: ScriptInfo.h:65
std::shared_ptr< ServerInfo::Info > PServerInfo
Definition: ServerInfo.h:118
Rpc::PServerInfo serverInfo
Definition: ScriptInfo.h:88
ScriptType
Definition: ScriptInfo.h:68
std::shared_ptr< ScriptInfoDevice > PScriptInfoDevice
Definition: ScriptInfo.h:60
int64_t peerId
Definition: ScriptInfo.h:93
PTcpSocket socket
Definition: ScriptInfo.h:122
std::function< void(PScriptInfo &scriptInfo, PVariable &headers)> scriptHeadersCallback
Definition: ScriptInfo.h:111
PVariable nodeInfo
Definition: ScriptInfo.h:95
uint32_t maxThreadCount
Definition: ScriptInfo.h:99
std::shared_ptr< ScriptInfoCli > PScriptInfoCli
Definition: ScriptInfo.h:58
int32_t exitCode
Definition: ScriptInfo.h:105
std::shared_ptr< BaseLib::TcpSocket > PTcpSocket
Definition: TcpSocket.h:697
std::string output
Definition: ScriptInfo.h:106
ScriptType getType()
Definition: ScriptInfo.h:134