SkillManagerWrapper.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <mutex>
4 
5 #include <QObject>
6 
11 #include <RobotAPI/interface/skills/SkillManagerInterface.h>
12 
13 namespace armarx::skills::gui
14 {
15  using StatusMap = std::map<skills::SkillExecutionID, skills::SkillStatusUpdate>;
16  using SkillMap =
17  std::map<skills::ProviderID, std::map<skills::SkillID, skills::SkillDescription>>;
18 
19  class SkillManagerWrapper : public QObject
20  {
21  Q_OBJECT
22  public:
23  SkillManagerWrapper(skills::manager::dti::SkillManagerInterfacePrx& _memory,
24  QObject* parent = nullptr) :
25  QObject(parent), memory(_memory)
26  {
27  }
28 
29  // We can instantiate the proxy without memory, if it's not connected yet.
30  SkillManagerWrapper(QObject* parent = nullptr) : QObject(parent)
31  {
32  }
33 
34  /**
35  * @brief Updates the memory pointer. This should be called whenever the GUI connects/reconnects.
36  */
37  void connectMemory(skills::manager::dti::SkillManagerInterfacePrx const& updatedMemory);
38 
39  // Basic functions to work with. These will produce Ice calls!
40  /**
41  * @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.
42  * @param skillId The skill to execute.
43  * @param params The parameters to execute with.
44  */
46 
47  /**
48  * @brief Attempts to stop an execution. If this doesn't succeed, it will retry.
49  * @param executionId The ExecutionID to abort.
50  * @param max_retries The amount of times to retry, if aborting fails.
51  */
52  void stopExecution(skills::SkillExecutionID const& executionId,
53  const unsigned int max_retries = 0);
54 
55  static const std::optional<skills::ProviderID> findFirstProvider(SkillMap const& map,
56  SkillID const& skillId);
57 
58  /**
59  * @brief Returns the latest skills snapshot.
60  * @return The map representing all currently known skills.
61  */
63 
64  /**
65  * @brief Returns the latest status snapshot.
66  * @return The map containing status updates for all execution ids.
67  */
69 
70  struct Snapshot
71  {
74 
75  // default constructor (construct empty)
76  Snapshot() : statuses({}), skills({})
77  {
78  }
79  };
80 
81  signals:
82  void connectionUpdate(std::string const& message, std::string const& error);
83  void updateAvailable(Snapshot update);
84  void searchAccepted();
85 
86  public slots:
87  /**
88  * @brief Disconnects the interface from memory.
89  */
90  void disconnectMemory();
91 
92  /**
93  * @brief Applies the search word to the update filter.
94  * @param search The search word.
95  */
96  void acceptSearchRequest(std::string const& search);
97 
98  /**
99  * @brief Stops all available (and running) executions.
100  */
101  void stopAllExecutions();
102 
103  /**
104  * @brief Requests this wrapper to overwrite its own state from memory.
105  */
106  void updateFromMemory();
107 
108  private:
109  mutable std::mutex mutex_memory;
110  mutable std::mutex mutex_snapshot;
111 
112  armarx::skills::manager::dti::SkillManagerInterfacePrx memory;
113  std::string currentSkillSearch = "";
114 
115  Snapshot snapshot;
116 
117  /**
118  * @brief Fetches and returns the latest skills update from memory.
119  * @return The map representing all skills in memory. Empty, if error occurred.
120  */
121  SkillMap fetchSkillsFromMemory();
122 
123  /**
124  * @brief Fetches and returns the latest status update from memory.
125  * @return The map containing status updates for all execution ids. Empty, if error occurred.
126  */
127  StatusMap fetchExecutionsFromMemory();
128 
129  /**
130  * @brief Returns the given snapshot, matching the search.
131  * @param update The snapshot to modify.
132  */
133  Snapshot filterUpdate(Snapshot update);
134 
135  // config
136  // TODO: perhaps use proper config file for the gui
137 
138  // should we do an ice call to use the latest information when requesting an execution?
139  static constexpr bool UPDATE_ON_EXECUTION_REQUEST = true;
140 
141  // ---
142  };
143 } // namespace armarx::skills::gui
armarx::skills::SkillExecutionID
Definition: SkillExecutionID.h:19
ProviderID.h
armarx::skills::gui::SkillManagerWrapper::startExecutionWithParams
void startExecutionWithParams(skills::SkillID &skillId, aron::data::DictPtr const params)
Attempts to start an execution with given parameters.
Definition: SkillManagerWrapper.cpp:334
armarx::skills::gui::SkillManagerWrapper::updateAvailable
void updateAvailable(Snapshot update)
SkillStatusUpdate.h
armarx::skills::gui::SkillManagerWrapper::updateFromMemory
void updateFromMemory()
Requests this wrapper to overwrite its own state from memory.
Definition: SkillManagerWrapper.cpp:227
armarx::skills::gui::StatusMap
std::map< skills::SkillExecutionID, skills::SkillStatusUpdate > StatusMap
Definition: SkillExecutionTreeWidget.h:12
armarx::skills::gui::SkillManagerWrapper::disconnectMemory
void disconnectMemory()
Disconnects the interface from memory.
Definition: SkillManagerWrapper.cpp:180
armarx::skills::gui::SkillManagerWrapper::connectionUpdate
void connectionUpdate(std::string const &message, std::string const &error)
message
message(STATUS "Boost-Library-Dir: " "${Boost_LIBRARY_DIRS}") message(STATUS "Boost-LIBRARIES
Definition: CMakeLists.txt:8
SkillExecutionID.h
armarx::skills::gui::SkillManagerWrapper::searchAccepted
void searchAccepted()
armarx::memory
Brief description of class memory.
Definition: memory.h:39
armarx::skills::gui::SkillManagerWrapper::findFirstProvider
static const std::optional< skills::ProviderID > findFirstProvider(SkillMap const &map, SkillID const &skillId)
Definition: SkillManagerWrapper.cpp:239
armarx::skills::gui::SkillManagerWrapper::getExecutions
StatusMap getExecutions()
Returns the latest status snapshot.
Definition: SkillManagerWrapper.cpp:273
armarx::skills::gui::SkillManagerWrapper::SkillManagerWrapper
SkillManagerWrapper(skills::manager::dti::SkillManagerInterfacePrx &_memory, QObject *parent=nullptr)
Definition: SkillManagerWrapper.h:23
armarx::skills::gui::SkillManagerWrapper::Snapshot
Definition: SkillManagerWrapper.h:70
armarx::skills::gui::SkillManagerWrapper::Snapshot::Snapshot
Snapshot()
Definition: SkillManagerWrapper.h:76
armarx::skills::gui::SkillManagerWrapper::Snapshot::skills
SkillMap skills
Definition: SkillManagerWrapper.h:73
armarx::skills::gui::SkillMap
std::map< skills::ProviderID, std::map< skills::SkillID, skills::SkillDescription > > SkillMap
Definition: SkillManagerWrapper.cpp:11
armarx::skills::gui
Definition: PeriodicUpdateWidget.cpp:11
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::skills::gui::SkillManagerWrapper::Snapshot::statuses
StatusMap statuses
Definition: SkillManagerWrapper.h:72
armarx::skills::gui::SkillManagerWrapper::stopAllExecutions
void stopAllExecutions()
Stops all available (and running) executions.
Definition: SkillManagerWrapper.cpp:196
armarx::skills::SkillID
Definition: SkillID.h:17
armarx::skills::gui::SkillManagerWrapper::getSkills
SkillMap getSkills()
Returns the latest skills snapshot.
Definition: SkillManagerWrapper.cpp:263
armarx::skills::gui::SkillManagerWrapper::acceptSearchRequest
void acceptSearchRequest(std::string const &search)
Applies the search word to the update filter.
Definition: SkillManagerWrapper.cpp:189
SkillDescription.h
armarx::skills::gui::SkillManagerWrapper::connectMemory
void connectMemory(skills::manager::dti::SkillManagerInterfacePrx const &updatedMemory)
Updates the memory pointer.
Definition: SkillManagerWrapper.cpp:172
armarx::skills::gui::SkillManagerWrapper
Definition: SkillManagerWrapper.h:19
armarx::skills::gui::SkillManagerWrapper::stopExecution
void stopExecution(skills::SkillExecutionID const &executionId, const unsigned int max_retries=0)
Attempts to stop an execution.
Definition: SkillManagerWrapper.cpp:280
armarx::skills::gui::SkillManagerWrapper::SkillManagerWrapper
SkillManagerWrapper(QObject *parent=nullptr)
Definition: SkillManagerWrapper.h:30