SkillManagerWrapper.h
Go to the documentation of this file.
1#pragma once
2
3#include <mutex>
4#include <vector>
5
6#include <QObject>
7
13#include <RobotAPI/interface/skills/SkillManagerInterface.h>
14
15namespace armarx::skills::gui
16{
17 using StatusMap = std::map<skills::SkillExecutionID, skills::SkillStatusUpdate>;
18 using SkillMap =
19 std::map<skills::ProviderID, std::map<skills::SkillID, skills::SkillDescription>>;
20
23 std::map<skills::SkillID, std::vector<Parameters>>;
24
25 class SkillManagerWrapper : public QObject
26 {
27 Q_OBJECT
28 public:
29 SkillManagerWrapper(skills::manager::dti::SkillManagerInterfacePrx& _memory,
30 QObject* parent = nullptr) :
31 QObject(parent), memory(_memory)
32 {
33 }
34
35 // We can instantiate the proxy without memory, if it's not connected yet.
36 SkillManagerWrapper(QObject* parent = nullptr) : QObject(parent)
37 {
38 }
39
40 /**
41 * @brief Updates the memory pointer. This should be called whenever the GUI connects/reconnects.
42 */
43 void connectMemory(skills::manager::dti::SkillManagerInterfacePrx const& updatedMemory);
44
45 // Basic functions to work with. These will produce Ice calls!
46 /**
47 * @brief Attempts to start an execution with given parameters. If an Ice exception is encountered, a message will be logged and the method will abort.
48 * @param skillId The skill to execute.
49 * @param params The parameters to execute with.
50 */
52
53 /**
54 * @brief Attempts to stop an execution. If this doesn't succeed, it will retry.
55 * @param executionId The ExecutionID to abort.
56 * @param max_retries The amount of times to retry, if aborting fails.
57 */
58 void stopExecution(skills::SkillExecutionID const& executionId,
59 const unsigned int max_retries = 0);
60
61 static const std::optional<skills::ProviderID> findFirstProvider(SkillMap const& map,
62 SkillID const& skillId);
63
64 /**
65 * @brief Returns the latest skills snapshot.
66 * @return The map representing all currently known skills.
67 */
69
70 /**
71 * @brief Returns the latest skills snapshot.
72 * @return The map representing all currently known skills.
73 */
75
76 /**
77 * @brief Returns the latest status snapshot.
78 * @return The map containing status updates for all execution ids.
79 */
81
82 struct Snapshot
83 {
86
87 // default constructor (construct empty)
89 {
90 }
91 };
92
93 signals:
95 void connectionUpdate(std::string const& message, std::string const& error);
98
99 public slots:
100 /**
101 * @brief Disconnects the interface from memory.
102 */
103 void disconnectMemory();
104
105 /**
106 * @brief Applies the search word to the update filter.
107 * @param search The search word.
108 */
109 void acceptSearchRequest(std::string const& search);
110
111 /**
112 * @brief Stops all available (and running) executions.
113 */
114 void stopAllExecutions();
115
116 /**
117 * @brief Requests this wrapper to overwrite its own state from memory.
118 */
119 void updateFromMemory();
120
121 // == Skill Parameters State ==
122
123 std::vector<Parameters> getParameterHistoryForSkill(const skills::SkillID& sid);
124 void addParametersToHistory(const skills::SkillID& sid, const Parameters& params);
125 std::optional<Parameters> getLatestParametersForSkill(const skills::SkillID& sid);
126
127 private:
128 mutable std::mutex mutex_memory;
129 mutable std::mutex mutex_snapshot;
130
131 armarx::skills::manager::dti::SkillManagerInterfacePrx memory;
132 std::string currentSkillSearch = "";
133
134 // Store a list of all execution parameters for each skill
135 SkillParameterMap skillParameterExecutionHistory;
136 SkillParameterMap lostParameterHistory;
137
138 Snapshot snapshot;
139
140 /**
141 * @brief Fetches and returns the latest skills update from memory.
142 * @return The map representing all skills in memory. Empty, if error occurred.
143 */
144 SkillMap fetchSkillsFromMemory();
145
146 /**
147 * @brief Fetches and returns the latest status update from memory.
148 * @return The map containing status updates for all execution ids. Empty, if error occurred.
149 */
150 StatusMap fetchExecutionsFromMemory();
151
152 /**
153 * @brief Returns the given snapshot, matching the search.
154 * @param update The snapshot to modify.
155 */
156 Snapshot filterUpdate(Snapshot update);
157
158 // config
159 // TODO: perhaps use proper config file for the gui
160
161 // should we do an ice call to use the latest information when requesting an execution?
162 static constexpr bool UPDATE_ON_EXECUTION_REQUEST = true;
163
164 // ---
165 };
166} // namespace armarx::skills::gui
void stopAllExecutions()
Stops all available (and running) executions.
void disconnectMemory()
Disconnects the interface from memory.
static const std::optional< skills::ProviderID > findFirstProvider(SkillMap const &map, SkillID const &skillId)
StatusMap getExecutions()
Returns the latest status snapshot.
void connectMemory(skills::manager::dti::SkillManagerInterfacePrx const &updatedMemory)
Updates the memory pointer.
void acceptSearchRequest(std::string const &search)
Applies the search word to the update filter.
SkillMap getSkillsFiltered()
Returns the latest skills snapshot.
SkillMap getSkills()
Returns the latest skills snapshot.
void stopExecution(skills::SkillExecutionID const &executionId, const unsigned int max_retries=0)
Attempts to stop an execution.
void startExecutionWithParams(skills::SkillID &skillId, aron::data::DictPtr const params)
Attempts to start an execution with given parameters.
void connectionUpdate(std::string const &message, std::string const &error)
void addParametersToHistory(const skills::SkillID &sid, const Parameters &params)
SkillManagerWrapper(skills::manager::dti::SkillManagerInterfacePrx &_memory, QObject *parent=nullptr)
std::optional< Parameters > getLatestParametersForSkill(const skills::SkillID &sid)
void updateFromMemory()
Requests this wrapper to overwrite its own state from memory.
std::vector< Parameters > getParameterHistoryForSkill(const skills::SkillID &sid)
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
std::map< skills::SkillExecutionID, skills::SkillStatusUpdate > StatusMap
std::map< skills::SkillID, std::vector< Parameters > > SkillParameterMap
aron::data::DictPtr Parameters
std::map< skills::ProviderID, std::map< skills::SkillID, skills::SkillDescription > > SkillMap
This file is part of ArmarX.