memory_definitions.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "detail/Prediction.h"
5 
13 
15 
16 #include <mutex>
17 
18 
20 {
24 
27 
28 
29  /// @see base::EntityBase
30  class Entity :
31  public base::EntityBase<EntitySnapshot, Entity>
32  , public detail::MaxHistorySize
34  {
35  public:
36 
38 
39 
40  /**
41  * @brief Sets the maximum history size.
42  *
43  * The current history is truncated if necessary.
44  */
45  void setMaxHistorySize(long maxSize);
46 
47  UpdateResult update(const EntityUpdate& update);
48 
49 
50  protected:
51 
52  /// If maximum size is set, ensure `history`'s is not higher.
53  std::vector<EntitySnapshotT> truncate();
54 
55  };
56 
57 
58 
59  /// @see base::ProviderSegmentBase
61  public base::ProviderSegmentBase<Entity, ProviderSegment>
62  , public detail::MaxHistorySizeParent<ProviderSegment>
63  , public armem::wm::detail::FindInstanceDataMixin<ProviderSegment>
64  , public armem::server::wm::detail::Prediction<ProviderSegment>
65  {
66  public:
67 
69 
70 
71  using ProviderSegmentBase::addEntity;
72 
73  template <class ...Args>
74  Entity& addEntity(const std::string& name, Args... args)
75  {
76  Entity& added = ProviderSegmentBase::addEntity(name, args...);
77  added.setMaxHistorySize(this->getMaxHistorySize());
78  return added;
79  }
80 
81  };
82 
83 
84 
85  /// @brief base::CoreSegmentBase
86  class CoreSegment :
87  public base::CoreSegmentBase<ProviderSegment, CoreSegment>
88  , public detail::MaxHistorySizeParent<CoreSegment>
89  , public armem::wm::detail::FindInstanceDataMixin<CoreSegment>
91  {
93 
94  public:
95 
97 
98  /// @see base::CoreSegmentBase::addProviderSegment()
99  using CoreSegmentBase::addProviderSegment;
100  template <class ...Args>
101  ProviderSegment& addProviderSegment(const std::string& name, Args... args)
102  {
103  ProviderSegmentT& added = CoreSegmentBase::addProviderSegment(name, args...);
104  int maxHistorySize = this->getMaxHistorySize();
105  if(maxHistorySize < 0){
106  ARMARX_INFO << "The maxHistorySize for this core segment is set to < 0. "
107  << "This means nothing will ever be forgotten in working memory. "
108  << "This may slow down the memory server. \n"
109  << "Core Segment Name: "
110  << (this->id()).str();
111  }
112  added.setMaxHistorySize(maxHistorySize);
113  return added;
114  }
115 
116 
117  // Locking interface
118 
119  template <class FunctionT>
120  auto doLocked(FunctionT&& function) const
121  {
122  std::scoped_lock lock(_mutex);
123  return function();
124  }
125 
126 
127  private:
128 
129  mutable std::mutex _mutex;
130 
131  };
132 
133 
134 
135  /// @see base::MemoryBase
136  class Memory :
137  public base::MemoryBase<CoreSegment, Memory>
140  {
142 
143  public:
144 
145  using Base::MemoryBase;
146 
147 
148  /**
149  * @brief Perform the commit, locking the core segments.
150  *
151  * Groups the commits by core segment, and updates each core segment
152  * in a batch, locking the core segment.
153  */
154  std::vector<Base::UpdateResult> updateLocking(const Commit& commit);
155 
156  /**
157  * @brief Update the memory, locking the updated core segment.
158  */
159  Base::UpdateResult updateLocking(const EntityUpdate& update);
160 
161  };
162 
163 }
164 
armarx::armem::base::ProviderSegmentBase
Data of a provider segment containing multiple entities.
Definition: ProviderSegmentBase.h:22
armarx::armem::base::CoreSegmentBase< ProviderSegment, CoreSegment >::CoreSegmentBase
CoreSegmentBase()
Definition: CoreSegmentBase.h:68
EntitySnapshotBase.h
armarx::armem::base::MemoryBase< CoreSegment, Memory >::MemoryBase
MemoryBase()
Definition: MemoryBase.h:67
armarx::armem::base::CoreSegmentBase< ProviderSegment, CoreSegment >::name
std::string & name()
Definition: CoreSegmentBase.h:103
armarx::armem::server::wm::EntityInstance
armem::wm::EntityInstance EntityInstance
Definition: forward_declarations.h:64
str
std::string str(const T &t)
Definition: UserAssistedSegmenterGuiWidgetController.cpp:42
MemoryBase.h
armarx::armem::Commit
A bundle of updates to be sent to the memory.
Definition: Commit.h:89
armarx::armem::server::wm::detail::PredictionContainer
Can do predictions itself and has children it could delegate predictions to.
Definition: Prediction.h:158
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::armem::server::wm::detail::MaxHistorySizeParent
Definition: MaxHistorySize.h:36
EntityInstanceBase.h
armarx::armem::server::wm::Entity::truncate
std::vector< EntitySnapshotT > truncate()
If maximum size is set, ensure history's is not higher.
Definition: memory_definitions.cpp:33
armarx::armem::base::ProviderSegmentBase< Entity, ProviderSegment >::name
std::string & name()
Definition: ProviderSegmentBase.h:95
armarx::armem::wm::detail::FindInstanceDataMixin
Definition: data_lookup_mixins.h:81
armarx::armem::base::EntityBase
An entity over a period of time.
Definition: EntityBase.h:43
armarx::armem::server::wm::Entity
Definition: memory_definitions.h:30
armarx::armem::server::wm
Definition: forward_declarations.h:62
MaxHistorySize.h
armarx::armem::base::CoreSegmentBase
Data of a core segment containing multiple provider segments.
Definition: CoreSegmentBase.h:22
armarx::armem::server::wm::Memory
Definition: memory_definitions.h:136
Prediction.h
armarx::armem::base::CoreSegmentBase< ProviderSegment, CoreSegment >::ProviderSegmentT
ProviderSegment ProviderSegmentT
Definition: CoreSegmentBase.h:40
ProviderSegmentBase.h
armarx::armem::server::wm::detail::MaxHistorySize::getMaxHistorySize
long getMaxHistorySize() const
Definition: MaxHistorySize.cpp:26
EntityBase.h
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:27
armarx::armem::server::wm::detail::MaxHistorySize
Definition: MaxHistorySize.h:7
armarx::armem::server::wm::ProviderSegment::addEntity
Entity & addEntity(const std::string &name, Args... args)
Definition: memory_definitions.h:74
armarx::armem::wm::detail::FindInstanceDataMixinForEntity
Definition: data_lookup_mixins.h:58
armarx::armem::base::MemoryBase
Data of a memory consisting of multiple core segments.
Definition: MemoryBase.h:19
armarx::armem::wm::EntitySnapshot
Client-side working memory entity snapshot.
Definition: memory_definitions.h:80
armarx::armem::base::detail::MemoryItem::id
MemoryID & id()
Definition: MemoryItem.h:27
armarx::armem::server::wm::ProviderSegment
Definition: memory_definitions.h:60
armarx::armem::server::wm::CoreSegment::doLocked
auto doLocked(FunctionT &&function) const
Definition: memory_definitions.h:120
memory_definitions.h
armarx::armem::server::wm::CoreSegment
base::CoreSegmentBase
Definition: memory_definitions.h:86
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::armem::server::wm::EntitySnapshot
armem::wm::EntitySnapshot EntitySnapshot
Definition: forward_declarations.h:65
armarx::armem::server::wm::Entity::setMaxHistorySize
void setMaxHistorySize(long maxSize)
Sets the maximum history size.
Definition: memory_definitions.cpp:17
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::armem::server::wm::detail::Prediction
Can do predictions, but has no children it could delegate predictions to.
Definition: Prediction.h:52
armarx::armem::base::EntityInstanceMetadata
Metadata of an entity instance.
Definition: EntityInstanceBase.h:34
CoreSegmentBase.h
data_lookup_mixins.h
armarx::armem::base::MemoryBase< CoreSegment, Memory >::update
std::vector< UpdateResult > update(const Commit &commit, const bool addMissingCoreSegmentDuringUpdate=false, const bool checkMemoryName=true)
Store all updates in commit.
Definition: MemoryBase.h:297
armarx::armem::server::wm::EntityInstanceMetadata
base::EntityInstanceMetadata EntityInstanceMetadata
Definition: memory_definitions.h:21
armarx::armem::server::wm::CoreSegment::addProviderSegment
ProviderSegment & addProviderSegment(const std::string &name, Args... args)
Definition: memory_definitions.h:101
armarx::armem::server::wm::Memory::updateLocking
std::vector< Base::UpdateResult > updateLocking(const Commit &commit)
Perform the commit, locking the core segments.
Definition: memory_definitions.cpp:51
armarx::armem::server::wm::EntityInstanceDataPtr
armarx::aron::data::DictPtr EntityInstanceDataPtr
Definition: memory_definitions.h:23
armarx::aron::data::Dict
Definition: Dict.h:44
armarx::armem::server::wm::Entity::update
UpdateResult update(const EntityUpdate &update)
Definition: memory_definitions.cpp:25