ImageRecordingManager.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package VisionX::ArmarXObjects::RecordingManager
17 * @author Christian R. G. Dreher <c.dreher@kit.edu>
18 * @date 2020
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23
25
26
27// Simox
28#include <SimoxUtility/json.h>
29
30// ArmarX
32
36
37void
39{
40 if (not m_configs_json.empty())
41 {
42 std::map<std::string, imrec::Config> configs = nlohmann::json::parse(m_configs_json);
43 m_configs = configs;
44 }
45}
46
47void
51
52void
56
57void
61
62void
64 const std::map<std::string, imrec::Config>& configs,
65 const Ice::Current&)
66{
67 std::unique_lock l{m_configs_mx};
68
69 if (not configs.empty())
70 {
71 m_configs = configs;
72 }
73 else
74 {
75 m_configs.reset();
76 }
77}
78
79void
81 const Ice::Current& c)
82{
83 const std::map<std::string, imrec::Config>& configs = nlohmann::json::parse(configs_json);
84 configureRecordings(configs, c);
85}
86
87std::map<std::string, visionx::imrec::Config>
89{
90 std::shared_lock l{m_configs_mx};
91
92 if (not m_configs.has_value())
93 {
95 }
96
97 return m_configs.value();
98}
99
100bool
102{
103 std::shared_lock l{m_configs_mx};
104 return m_configs.has_value();
105}
106
107std::map<std::string, visionx::imrecman::StartStopStatus>
109{
111 ARMARX_DEBUG << "Starting recordings...";
112
113 std::shared_lock l{m_configs_mx};
114
115 std::map<std::string, visionx::imrecman::StartStopStatus> statuses;
116
117 if (not m_configs.has_value())
118 {
120 }
121
122 for (auto [proxy_name, config] : m_configs.value())
123 {
124 StartStopStatus status;
125 try
126 {
127 ARMARX_DEBUG << "Calling startRecording on image provider '" << proxy_name << "'.";
128 const bool call_status = getProxy<RecordingImageProviderInterfacePrx>(proxy_name)
129 ->startImageRecording(config);
130 ARMARX_DEBUG << "Got response from image provider.";
132 }
133 catch (...)
134 {
135 ARMARX_DEBUG << "Image provider '" << proxy_name << "' offline.";
137 }
138 statuses[proxy_name] = status;
139 }
140
141 ARMARX_DEBUG << "Done delegating call.";
142
143 return statuses;
144}
145
146std::map<std::string, visionx::imrec::Status>
148{
150 ARMARX_DEBUG << "Fetching statuses...";
151
152 std::shared_lock l{m_configs_mx};
153
154 std::map<std::string, visionx::imrec::Status> statuses;
155
156 if (not m_configs.has_value())
157 {
159 }
160
161 for (auto& [proxy_name, config] : m_configs.value())
162 {
163 imrec::Status status;
164 try
165 {
166 ARMARX_DEBUG << "Calling getRecordingStatus on image provider '" << proxy_name << "'.";
167 status =
168 getProxy<RecordingImageProviderInterfacePrx>(proxy_name)->getImageRecordingStatus();
169 ARMARX_DEBUG << "Got response from image provider.";
170 }
171 catch (...)
172 {
173 ARMARX_DEBUG << "Image provider '" << proxy_name << "' offline.";
174 status.type = imrec::State::offline;
175 status.framesBuffered = -1;
176 status.framesWritten = -1;
177 }
178 statuses[proxy_name] = status;
179 }
180
181 ARMARX_DEBUG << "Done delegating call.";
182
183 return statuses;
184}
185
186std::map<std::string, visionx::imrecman::StartStopStatus>
188{
190 ARMARX_DEBUG << "Stopping recordings...";
191
192 std::shared_lock l{m_configs_mx};
193
194 std::map<std::string, visionx::imrecman::StartStopStatus> statuses;
195
196 if (not m_configs.has_value())
197 {
199 }
200
201 std::map<std::string, Ice::AsyncResultPtr> promises;
202
203 for (auto& [proxy_name, config] : m_configs.value())
204 {
205 try
206 {
207 ARMARX_DEBUG << "Calling stopRecording on image provider '" << proxy_name << "'.";
208 promises[proxy_name] = getProxy<RecordingImageProviderInterfacePrx>(proxy_name)
209 ->begin_stopImageRecording();
210 }
211 catch (...)
212 {
213 promises[proxy_name] = nullptr;
214 }
215 }
216
217 for (auto& [proxy_name, promise] : promises)
218 {
219 StartStopStatus status;
220 try
221 {
222 if (promise)
223 {
224 const bool call_status = getProxy<RecordingImageProviderInterfacePrx>(proxy_name)
225 ->end_stopImageRecording(promise);
226 ARMARX_DEBUG << "Got response from image provider.";
228 }
229 else
230 {
231 ARMARX_DEBUG << "Image provider '" << proxy_name << "' offline.";
233 }
234 }
235 catch (...)
236 {
237 ARMARX_DEBUG << "Image provider '" << proxy_name << "' offline.";
239 }
240 statuses[proxy_name] = status;
241 }
242
243 ARMARX_DEBUG << "Done delegating stopRecording call.";
244
245 return statuses;
246}
247
248std::string
250{
251 return "ImageRecordingManager";
252}
253
254std::string
259
262{
265
266 defs->optional(m_configs_json, "config_json", "JSON to initialize default config from.");
267
268 return defs;
269}
constexpr T c
Default component property definition container.
Definition Component.h:70
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
void onInitComponent() override
Pure virtual hook for the subclass.
void configureRecordings(const std::map< std::string, imrec::Config > &, const Ice::Current &) override
void onDisconnectComponent() override
Hook for subclass.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void configureRecordingsFromJson(const std::string &, const Ice::Current &) override
void onConnectComponent() override
Pure virtual hook for the subclass.
void onExitComponent() override
Hook for subclass.
std::string getDefaultName() const override
Retrieve default name of component.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
imrecman::StartStopStatusesMap stopRecordings()
imrec::StatusesMap getRecordingStatuses()
imrecman::StartStopStatusesMap startRecordings()
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
#define ARMARX_TRACE
Definition trace.h:77