1 | // |
---|
2 | // You received this file as part of Finroc |
---|
3 | // A framework for intelligent robot control |
---|
4 | // |
---|
5 | // Copyright (C) Finroc GbR (finroc.org) |
---|
6 | // |
---|
7 | // This program is free software; you can redistribute it and/or modify |
---|
8 | // it under the terms of the GNU General Public License as published by |
---|
9 | // the Free Software Foundation; either version 2 of the License, or |
---|
10 | // (at your option) any later version. |
---|
11 | // |
---|
12 | // This program is distributed in the hope that it will be useful, |
---|
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | // GNU General Public License for more details. |
---|
16 | // |
---|
17 | // You should have received a copy of the GNU General Public License along |
---|
18 | // with this program; if not, write to the Free Software Foundation, Inc., |
---|
19 | // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
---|
20 | // |
---|
21 | //---------------------------------------------------------------------- |
---|
22 | /*!\file plugins/runtime_construction/tAdministrationService.h |
---|
23 | * |
---|
24 | * \author Max Reichardt |
---|
25 | * |
---|
26 | * \date 2012-12-02 |
---|
27 | * |
---|
28 | * \brief Contains tAdministrationService |
---|
29 | * |
---|
30 | * \b tAdministrationService |
---|
31 | * |
---|
32 | * Service for administration. |
---|
33 | * It provides functions to create, modify and delete Finroc elements such |
---|
34 | * as groups, modules, ports and port connections at application runtime. |
---|
35 | * One port needs to be created to be able to edit application |
---|
36 | * structure using finstruct (currently done in dynamic_loading.cpp) |
---|
37 | * |
---|
38 | */ |
---|
39 | //---------------------------------------------------------------------- |
---|
40 | #ifndef __plugins__runtime_construction__tAdministrationService_h__ |
---|
41 | #define __plugins__runtime_construction__tAdministrationService_h__ |
---|
42 | |
---|
43 | //---------------------------------------------------------------------- |
---|
44 | // External includes (system with <>, local with "") |
---|
45 | //---------------------------------------------------------------------- |
---|
46 | #include "plugins/rpc_ports/tServerPort.h" |
---|
47 | |
---|
48 | //---------------------------------------------------------------------- |
---|
49 | // Internal includes with "" |
---|
50 | //---------------------------------------------------------------------- |
---|
51 | |
---|
52 | //---------------------------------------------------------------------- |
---|
53 | // Namespace declaration |
---|
54 | //---------------------------------------------------------------------- |
---|
55 | namespace finroc |
---|
56 | { |
---|
57 | namespace runtime_construction |
---|
58 | { |
---|
59 | |
---|
60 | //---------------------------------------------------------------------- |
---|
61 | // Forward declarations / typedefs / enums |
---|
62 | //---------------------------------------------------------------------- |
---|
63 | |
---|
64 | //---------------------------------------------------------------------- |
---|
65 | // Class declaration |
---|
66 | //---------------------------------------------------------------------- |
---|
67 | //! Service for administration |
---|
68 | /*! |
---|
69 | * Service for administration. |
---|
70 | * It provides functions to create, modify and delete Finroc elements such |
---|
71 | * as groups, modules, ports and port connections at application runtime. |
---|
72 | * One port needs to be created to be able to edit application |
---|
73 | * structure using finstruct (currently done in dynamic_loading.cpp) |
---|
74 | */ |
---|
75 | class tAdministrationService : public rpc_ports::tRPCInterface |
---|
76 | { |
---|
77 | |
---|
78 | //---------------------------------------------------------------------- |
---|
79 | // Public methods and typedefs |
---|
80 | //---------------------------------------------------------------------- |
---|
81 | public: |
---|
82 | |
---|
83 | /*! |
---|
84 | * Return values for IsExecuting |
---|
85 | */ |
---|
86 | enum class tExecutionStatus |
---|
87 | { |
---|
88 | NONE, |
---|
89 | PAUSED, |
---|
90 | RUNNING, |
---|
91 | BOTH |
---|
92 | }; |
---|
93 | |
---|
94 | |
---|
95 | tAdministrationService(); |
---|
96 | |
---|
97 | ~tAdministrationService(); |
---|
98 | |
---|
99 | |
---|
100 | /*! |
---|
101 | * Connect source port to destination port |
---|
102 | * |
---|
103 | * \param source_port_handle Handle of source port |
---|
104 | * \param destination_port_handle Handle of destination port |
---|
105 | */ |
---|
106 | void Connect(int source_port_handle, int destination_port_handle); |
---|
107 | |
---|
108 | /*! |
---|
109 | * Connect source port to destination port with connect options |
---|
110 | * (new connect method) |
---|
111 | * |
---|
112 | * \param source_port_handle Handle of source port |
---|
113 | * \param destination_port_handle Handle of destination port |
---|
114 | * \param connect_options Connect options |
---|
115 | * \return Returns error message if connecting failed. On success an empty string is returned. |
---|
116 | */ |
---|
117 | std::string ConnectPorts(int source_port_handle, int destination_port_handle, const core::tConnectOptions& connect_options); |
---|
118 | |
---|
119 | /*! |
---|
120 | * Instantiates port for administration |
---|
121 | */ |
---|
122 | static void CreateAdministrationPort(); |
---|
123 | |
---|
124 | /*! |
---|
125 | * Created module |
---|
126 | * |
---|
127 | * \param create_action_index Index of create action |
---|
128 | * \param module_name Name to give new module |
---|
129 | * \param parent_handle Handle of parent element |
---|
130 | * \param serialized_creation_parameters Serialized constructor parameters in case the module requires such - otherwise empty |
---|
131 | * \return Empty string if it worked - otherwise error message |
---|
132 | */ |
---|
133 | std::string CreateModule(uint32_t create_action_index, const std::string& module_name, int parent_handle, const rrlib::serialization::tMemoryBuffer& serialized_creation_parameters); |
---|
134 | |
---|
135 | /*! |
---|
136 | * Create URI connector connecting local port using one of the supported URI schemes (provided e.g. by network transports). |
---|
137 | * |
---|
138 | * \param local_port_handle Handle of local owner port |
---|
139 | * \param uri URI of partner port |
---|
140 | * \param connect_options Connect options |
---|
141 | * \return Returns error message if connecting failed. On success an empty string is returned. |
---|
142 | */ |
---|
143 | std::string CreateUriConnector(int local_port_handle, const rrlib::uri::tURI& uri, const core::tUriConnectOptions& connect_options); |
---|
144 | |
---|
145 | /*! |
---|
146 | * Deletes specified framework element |
---|
147 | * |
---|
148 | * \param element_handle Handle of framework element |
---|
149 | */ |
---|
150 | void DeleteElement(int element_handle); |
---|
151 | |
---|
152 | /*! |
---|
153 | * Delete URI connector |
---|
154 | * |
---|
155 | * \param local_port_handle Handle of local owner port |
---|
156 | * \param uri URI of partner port |
---|
157 | * \return Whether any connector was deleted |
---|
158 | */ |
---|
159 | bool DeleteUriConnector(int local_port_handle, const rrlib::uri::tURI& uri); |
---|
160 | |
---|
161 | /*! |
---|
162 | * Disconnect the two ports |
---|
163 | * |
---|
164 | * \param source_port_handle Handle of source port |
---|
165 | * \param destination_port_handle Handle of destination port |
---|
166 | */ |
---|
167 | void Disconnect(int source_port_handle, int destination_port_handle); |
---|
168 | |
---|
169 | /*! |
---|
170 | * Disconnect all ports from port with specified handle |
---|
171 | * |
---|
172 | * \param port_handle Port handle |
---|
173 | */ |
---|
174 | void DisconnectAll(int port_handle); |
---|
175 | |
---|
176 | /*! |
---|
177 | * Retrieve annotation from specified framework element |
---|
178 | * |
---|
179 | * \param element_handle Handle of framework element |
---|
180 | * \param annotation_type_name Name of annotation type |
---|
181 | * \return Serialized annotation |
---|
182 | */ |
---|
183 | rrlib::serialization::tMemoryBuffer GetAnnotation(int element_handle, const std::string& annotation_type_name); |
---|
184 | |
---|
185 | /*! |
---|
186 | * \return All actions for creating framework element currently registered in this runtime environment - serialized |
---|
187 | */ |
---|
188 | rrlib::serialization::tMemoryBuffer GetCreateModuleActions(); |
---|
189 | |
---|
190 | /*! |
---|
191 | * \return Available module libraries (.so files) that have not been loaded yet - serialized |
---|
192 | */ |
---|
193 | rrlib::serialization::tMemoryBuffer GetModuleLibraries(); |
---|
194 | |
---|
195 | /*! |
---|
196 | * \param root_element_handle Handle of root element to get parameter info below of |
---|
197 | * \return Serialized parameter info |
---|
198 | */ |
---|
199 | rrlib::serialization::tMemoryBuffer GetParameterInfo(int root_element_handle); |
---|
200 | |
---|
201 | /*! |
---|
202 | * \param element_handle Handle of framework element |
---|
203 | * \return Is specified framework element currently executing? |
---|
204 | */ |
---|
205 | tExecutionStatus IsExecuting(int element_handle); |
---|
206 | |
---|
207 | /*! |
---|
208 | * Dynamically loads specified module library (.so file) |
---|
209 | * |
---|
210 | * \param library_name File name of library to load |
---|
211 | * \return Available module libraries (.so files) that have not been loaded yet - serialized (Updated version) |
---|
212 | */ |
---|
213 | rrlib::serialization::tMemoryBuffer LoadModuleLibrary(const std::string& library_name); |
---|
214 | |
---|
215 | /*! |
---|
216 | * Connect local port to port in remote runtime environment using one of the |
---|
217 | * available network transport plugins. |
---|
218 | * |
---|
219 | * \param local_port_handle Handle of local port |
---|
220 | * \param preferred_transport ID of preferred network transport to be used (e.g. "tcp"). If specified, it will be attempted to create the connection using this transport first. |
---|
221 | * \param remote_runtime_uuid UUID of remote runtime |
---|
222 | * \param remote_port_handle Handle of remote port |
---|
223 | * \param remote_port_link Link of port in remote runtime environment |
---|
224 | * \param disconnect If 'false' the ports are connected - if 'true' the ports are disconnected |
---|
225 | * \return Returns error message if connecting failed. On success an empty string is returned. |
---|
226 | */ |
---|
227 | std::string NetworkConnect(int local_port_handle, const std::string& preferred_transport, const std::string& remote_runtime_uuid, |
---|
228 | int remote_port_handle, const std::string& remote_port_link, bool disconnect); |
---|
229 | |
---|
230 | /*! |
---|
231 | * Pauses execution of tasks in specified framework element |
---|
232 | * (possibly its parent thread container - if there is no such, then all children) |
---|
233 | * |
---|
234 | * \param element_handle Handle of framework element |
---|
235 | */ |
---|
236 | void PauseExecution(int element_handle); |
---|
237 | |
---|
238 | /*! |
---|
239 | * Saves all finstructable files in this runtime environment |
---|
240 | */ |
---|
241 | void SaveAllFinstructableFiles(); |
---|
242 | |
---|
243 | /*! |
---|
244 | * Save contents finstructable group to xml file |
---|
245 | * |
---|
246 | * \param group_handle Handle of group to save |
---|
247 | */ |
---|
248 | void SaveFinstructableGroup(int group_handle); |
---|
249 | |
---|
250 | /*! |
---|
251 | * Set/change annotation of specified framework element |
---|
252 | * |
---|
253 | * \param element_handle Handle of framework element |
---|
254 | * \param serialized_annotation Serialized annotation (including type of annotation) |
---|
255 | */ |
---|
256 | void SetAnnotation(int element_handle, const rrlib::serialization::tMemoryBuffer& serialized_annotation); |
---|
257 | |
---|
258 | /*! |
---|
259 | * Set value of port |
---|
260 | * |
---|
261 | * \param port_handle Port handle |
---|
262 | * \param serialized_new_value New value - serialized |
---|
263 | * \return Empty string if it worked - otherwise error message |
---|
264 | */ |
---|
265 | std::string SetPortValue(int port_handle, const rrlib::serialization::tMemoryBuffer& serialized_new_value); |
---|
266 | |
---|
267 | /*! |
---|
268 | * Starts executing tasks in specified framework element |
---|
269 | * (possibly its parent thread container - if there is no such, then all children) |
---|
270 | * |
---|
271 | * \param element_handle Handle of framework element |
---|
272 | */ |
---|
273 | void StartExecution(int element_handle); |
---|
274 | |
---|
275 | //---------------------------------------------------------------------- |
---|
276 | // Private fields and methods |
---|
277 | //---------------------------------------------------------------------- |
---|
278 | private: |
---|
279 | |
---|
280 | }; |
---|
281 | |
---|
282 | //---------------------------------------------------------------------- |
---|
283 | // End of namespace declaration |
---|
284 | //---------------------------------------------------------------------- |
---|
285 | } |
---|
286 | } |
---|
287 | |
---|
288 | |
---|
289 | #endif |
---|