iCub-main
Loading...
Searching...
No Matches
posServiceConfiguration.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
6#ifndef ICUB_POS_SERVICE_CONFIGURATION_H
7#define ICUB_POS_SERVICE_CONFIGURATION_H
8
9#include "EoManagement.h"
10
11#include <mutex>
12
13namespace eth {
14
15// Owned by one Ethernet resource, so a dependency can only be resolved from
16// standalone POS activated on the same board. It never changes the wire format.
18{
19public:
20 bool prepare(eOmn_serv_category_t category, const eOmn_serv_parameter_t* requested,
21 eOmn_serv_parameter_t& prepared) const
22 {
23 prepared = requested ? *requested : eOmn_serv_parameter_t{};
24 if(!requested || (category != eomn_serv_category_mc) ||
25 (prepared.configuration.type != eomn_serv_MC_mc4plusfaps))
26 {
27 return true;
28 }
29
30 auto& dependency = prepared.configuration.data.mc.mc4plusfaps.pos;
31 std::lock_guard<std::mutex> lock(mutex);
32 if(!available)
33 {
34 return false;
35 }
36 dependency = configuration;
37 return true;
38 }
39
40 // Call only after standalone POS verification/activation succeeds.
41 void rememberActivated(eOmn_serv_category_t category, const eOmn_serv_parameter_t* parameter)
42 {
43 if(!parameter || (category != eomn_serv_category_pos) ||
44 (parameter->configuration.type != eomn_serv_AS_pos))
45 {
46 return;
47 }
48 std::lock_guard<std::mutex> lock(mutex);
49 // Firmware keeps its first active POS configuration when another owner
50 // verifies a compatible service. Mirror that behavior in the host cache.
51 if(!available)
52 {
53 configuration = parameter->configuration.data.as.pos;
54 available = true;
55 }
56 }
57
58 void clearOnStop(eOmn_serv_category_t category)
59 {
60 if((category == eomn_serv_category_pos) || (category == eomn_serv_category_all))
61 {
62 std::lock_guard<std::mutex> lock(mutex);
63 configuration = {};
64 available = false;
65 }
66 }
67
68private:
69 mutable std::mutex mutex;
70 eOmn_serv_config_data_as_pos_t configuration {};
71 bool available {false};
72};
73
74} // namespace eth
75
76#endif
void clearOnStop(eOmn_serv_category_t category)
void rememberActivated(eOmn_serv_category_t category, const eOmn_serv_parameter_t *parameter)
bool prepare(eOmn_serv_category_t category, const eOmn_serv_parameter_t *requested, eOmn_serv_parameter_t &prepared) const