TaskOutcomeWriter.cpp
Go to the documentation of this file.
1#include "TaskOutcomeWriter.h"
2
4
7
8#include <RobotAPI/libraries/armem_task_outcome/aron/TaskOutcome.aron.generated.h>
11
13{
14
18
20
21 void
26
27 void
29 {
30 ARMARX_VERBOSE << "Connecting TaskOutcomeWriter ...";
32 ARMARX_VERBOSE << "TaskOutcomeWriter connected.";
33 }
34
35 bool
37 const std::string& provider,
38 const armem::Time& referencedTime)
39 {
40 return this->commitTaskOutcomes({outcome}, provider, referencedTime);
41 }
42
43 bool
44 TaskOutcomeWriter::commitTaskOutcomes(const std::vector<TaskOutcome>& outcomes,
45 const std::string& provider,
46 const armem::Time& referencedTime)
47 {
48 if (outcomes.empty())
49 {
50 ARMARX_WARNING << "No task outcomes to commit";
51 return false;
52 }
53
54 try
55 {
56 for (const TaskOutcome& outcome : outcomes)
57 {
58 // Convert BO -> DTO
59 armarx::task_outcome::arondto::TaskOutcome outcomeAron;
60 toAron(outcomeAron, outcome);
61
62 // Create entity ID: group by task name
65 .withProviderSegmentName(provider)
66 .withEntityName(outcome.taskName);
67
68 // Create entity update
70 .entityID = entityId,
71 .instancesData = {outcomeAron.toAron()},
72 .referencedTime = referencedTime,
73 .confidence = 1.0F,
74 .sentTime = armarx::armem::Time::Now(),
75 .arrivedTime = armarx::armem::Time::Now(),
76 };
77
78 // Commit the update
79 armem::Commit commit;
80 commit.add(update);
81
82 ARMARX_DEBUG << "Committing task outcome for '" << outcome.taskName
83 << "' (type: " << static_cast<int>(outcome.taskType) << ")";
84
85 memoryWriter().commit(commit);
86 }
87
88 return true;
89 }
90 catch (...)
91 {
92 ARMARX_WARNING << "Failed to commit task outcomes: "
94 return false;
95 }
96 }
97
98} // namespace armarx::armem::task_outcome::client
The memory name system (MNS) client.
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition Writer.cpp:68
void connect(armarx::armem::client::MemoryNameSystem &mns)
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
bool commitTaskOutcome(const TaskOutcome &outcome, const std::string &provider, const armem::Time &referencedTime)
bool commitTaskOutcomes(const std::vector< TaskOutcome > &outcomes, const std::string &provider, const armem::Time &referencedTime)
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
static DateTime Now()
Definition DateTime.cpp:51
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
void toAron(armarx::task_outcome::arondto::TaskOutcomeType &dto, const TaskOutcomeType &bo)
armarx::core::time::DateTime Time
const armem::MemoryID TaskOutcomeCoreSegmentID
Definition memory_ids.cpp:8
std::string GetHandledExceptionString()
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
A bundle of updates to be sent to the memory.
Definition Commit.h:90
EntityUpdate & add()
Definition Commit.cpp:80
An update of an entity for a specific point in time.
Definition Commit.h:26