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
27
28
29// Simox
30#include <SimoxUtility/json.h>
31
32// ArmarX
34
38
39void
41{
42 if (not m_configs_json.empty())
43 {
44 std::map<std::string, imrec::Config> configs = nlohmann::json::parse(m_configs_json);
45 m_configs = configs;
46 }
47}
48
49void
53
54void
58
59void
63
64void
66 const std::map<std::string, imrec::Config>& configs,
67 const Ice::Current&)
68{
69 std::unique_lock l{m_configs_mx};
70
71 if (not configs.empty())
72 {
73 m_configs = configs;
74 }
75 else
76 {
77 m_configs.reset();
78 }
79}
80
81void
83 const Ice::Current& c)
84{
85 const std::map<std::string, imrec::Config>& configs = nlohmann::json::parse(configs_json);
86 configureRecordings(configs, c);
87}
88
89std::map<std::string, visionx::imrec::Config>
91{
92 std::shared_lock l{m_configs_mx};
93
94 if (not m_configs.has_value())
95 {
97 }
98
99 return m_configs.value();
100}
101
102bool
104{
105 std::shared_lock l{m_configs_mx};
106 return m_configs.has_value();
107}
108
109std::map<std::string, visionx::imrecman::StartStopStatus>
111{
113 ARMARX_DEBUG << "Starting recordings...";
114
115 std::shared_lock l{m_configs_mx};
116
117 std::map<std::string, visionx::imrecman::StartStopStatus> statuses;
118
119 if (not m_configs.has_value())
120 {
122 }
123
124 for (auto [proxy_name, config] : m_configs.value())
125 {
126 StartStopStatus status;
127 try
128 {
129 ARMARX_DEBUG << "Calling startRecording on image provider '" << proxy_name << "'.";
130 const bool call_status = getProxy<RecordingImageProviderInterfacePrx>(proxy_name)
131 ->startImageRecording(config);
132 ARMARX_DEBUG << "Got response from image provider.";
134 }
135 catch (...)
136 {
137 ARMARX_DEBUG << "Image provider '" << proxy_name << "' offline.";
139 }
140 statuses[proxy_name] = status;
141 }
142
143 ARMARX_DEBUG << "Done delegating call.";
144
145 return statuses;
146}
147
148std::map<std::string, visionx::imrec::Status>
150{
152 ARMARX_DEBUG << "Fetching statuses...";
153
154 std::shared_lock l{m_configs_mx};
155
156 std::map<std::string, visionx::imrec::Status> statuses;
157
158 if (not m_configs.has_value())
159 {
161 }
162
163 for (auto& [proxy_name, config] : m_configs.value())
164 {
165 imrec::Status status;
166 try
167 {
168 ARMARX_DEBUG << "Calling getRecordingStatus on image provider '" << proxy_name << "'.";
169 status =
170 getProxy<RecordingImageProviderInterfacePrx>(proxy_name)->getImageRecordingStatus();
171 ARMARX_DEBUG << "Got response from image provider.";
172 }
173 catch (...)
174 {
175 ARMARX_DEBUG << "Image provider '" << proxy_name << "' offline.";
176 status.type = imrec::State::offline;
177 status.framesBuffered = -1;
178 status.framesWritten = -1;
179 }
180 statuses[proxy_name] = status;
181 }
182
183 ARMARX_DEBUG << "Done delegating call.";
184
185 return statuses;
186}
187
188std::map<std::string, visionx::imrecman::StartStopStatus>
190{
192 ARMARX_DEBUG << "Stopping recordings...";
193
194 std::shared_lock l{m_configs_mx};
195
196 std::map<std::string, visionx::imrecman::StartStopStatus> statuses;
197
198 if (not m_configs.has_value())
199 {
201 }
202
203 std::map<std::string, Ice::AsyncResultPtr> promises;
204
205 for (auto& [proxy_name, config] : m_configs.value())
206 {
207 try
208 {
209 ARMARX_DEBUG << "Calling stopRecording on image provider '" << proxy_name << "'.";
210 promises[proxy_name] = getProxy<RecordingImageProviderInterfacePrx>(proxy_name)
211 ->begin_stopImageRecording();
212 }
213 catch (...)
214 {
215 promises[proxy_name] = nullptr;
216 }
217 }
218
219 for (auto& [proxy_name, promise] : promises)
220 {
221 StartStopStatus status;
222 try
223 {
224 if (promise)
225 {
226 const bool call_status = getProxy<RecordingImageProviderInterfacePrx>(proxy_name)
227 ->end_stopImageRecording(promise);
228 ARMARX_DEBUG << "Got response from image provider.";
230 }
231 else
232 {
233 ARMARX_DEBUG << "Image provider '" << proxy_name << "' offline.";
235 }
236 }
237 catch (...)
238 {
239 ARMARX_DEBUG << "Image provider '" << proxy_name << "' offline.";
241 }
242 statuses[proxy_name] = status;
243 }
244
245 ARMARX_DEBUG << "Done delegating stopRecording call.";
246
247 return statuses;
248}
249
250std::string
252{
253 return "ImageRecordingManager";
254}
255
256std::string
261
264{
267
268 defs->optional(m_configs_json, "config_json", "JSON to initialize default config from.");
269
270 return defs;
271}
272
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
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