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