MemoryXController.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package MemoryX::gui-plugins::SceneEditor
19  * @date 2015
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #pragma once
25 
26 #include <exception>
27 #include <string>
28 #include <vector>
29 
30 // MemoryXInterface
31 #include <MemoryX/interface/components/LongtermMemoryInterface.h>
32 #include <MemoryX/interface/core/EntityBase.h>
34 
35 /* Boost headers */
36 #include <memory>
37 
40 #include "../controller/Controller.h"
41 #include "../controller/Operation.h"
42 
44 {
47  /**
48  * @brief
49  *
50  */
52  {
53  public:
54  /**
55  * @brief Constructor.
56  *
57  * Creates an instance of this class.
58  */
60  /**
61  * @brief Destructor
62  *
63  */
65  /**
66  * @brief Initialisates the MemoryXController.
67  *
68  * @param priorKnowledgePrx the proxy to the priorknowledge
69  * @param workingMemoryPrx the proxy to the working memory
70  * @param workingMemoryUpdatesTopic the name of the topic where changes of the working memory are reported
71  * @param objectInstancesSegmentName the name of the segment in the working memory where the object instances are stored
72  * @param longtermMemoryPrx the proxy to the longtermmemory where snapshots are stored
73  * @param mainController the controller of this programm
74  *
75  * @see controller::Controller
76  */
77  void init(const memoryx::PriorKnowledgeInterfacePrx& priorKnowledgePrx,
78  const memoryx::WorkingMemoryInterfacePrx& workingMemoryPrx,
79  const std::string& workingMemoryUpdatesTopic,
80  const std::string& objectInstancesSegmentName,
81  const memoryx::LongtermMemoryInterfacePrx& longtermMemoryPrx,
82  const controller::ControllerPtr& mainController);
83  /**
84  * @brief Saves the whole content of the working memory in a snapshot with the given name.
85  *
86  * If the given name does not start with 'Snapshot_', this prefix will be added.
87  *
88  * @param snapshotName the name of the snapshot
89  * @return bool true when the saving was successful
90  */
91  bool saveSceneInSnapshot(std::string& snapshotName);
92  /**
93  * @brief Saves all object instances whose ids are given in a snapshot with the given name.
94  *
95  * @param snapshotName the name of the snapshot
96  * @param objectIds the list with the ids of the object instances that shold be saved
97  * @return bool true when the saving was successful
98  */
99  bool saveObjectsInSnapshot(std::string& snapshotName, const std::vector<std::string>& objectIds);
100  /**
101  * @brief Loads the content of the snapshot with the given name and add it to the current working memory.
102  *
103  * Returns a list with the ids of the added object instances.
104  * If there is no snapshot with the given name nothing is added to the working memory.
105  *
106  * @param snapshotName the name of the snapshot that should be loaded
107  * @return std::vector<std::string> the list with the ids of the added object instances
108  */
109  std::vector<std::string> loadSnapshot(const std::string& snapshotName);
110  /**
111  * @brief Returns a shared pointer to the WorkingMemoryController.
112  *
113  * @return IceInternal::Handle<WorkingMemoryController> the pointer to the WorkingMemoryController
114  */
116  /**
117  * @brief Returns a shared pointer to the PriorKnowledgeController.
118  *
119  * @return std::shared_ptr<PriorKnowledgeController> the pointer to the PriorKnowledgeController
120  */
121  std::shared_ptr<PriorKnowledgeController> getPriorKnowlegdeController() const;
122  /**
123  * @brief Returns a list with the names of all existing snapshots
124  *
125  * @return std::vector<std::string> list of names of all existing snapshots
126  */
127  std::vector<std::string> getAllSnapshots();
128  /**
129  * @brief Returns the main controller of this plugin.
130  *
131  * @return controller::ControllerPtr the pointer to the main controller
132  */
134 
135  private:
136  memoryx::LongtermMemoryInterfacePrx longtermMemoryPrx;
137  IceInternal::Handle<WorkingMemoryController> workingMemoryController;
138  std::shared_ptr<PriorKnowledgeController> priorKnowledgeController;
139  controller::ControllerWeakPtr mainController;
140 
141  /**
142  * @brief LONGTERM_SNAPSHOT_PREFIX is set to "Snapshot_" and needs to be the prefix of each Snapshot name
143  */
144  const std::string LONGTERM_SNAPSHOT_PREFIX;
145  };
146  using MemoryXControllerPtr = std::shared_ptr<MemoryXController>;
147 }
148 
WorkingMemoryController.h
memoryxcontroller::MemoryXController::getController
controller::ControllerPtr getController() const
Returns the main controller of this plugin.
Definition: MemoryXController.cpp:150
memoryxcontroller::MemoryXController::init
void init(const memoryx::PriorKnowledgeInterfacePrx &priorKnowledgePrx, const memoryx::WorkingMemoryInterfacePrx &workingMemoryPrx, const std::string &workingMemoryUpdatesTopic, const std::string &objectInstancesSegmentName, const memoryx::LongtermMemoryInterfacePrx &longtermMemoryPrx, const controller::ControllerPtr &mainController)
Initialisates the MemoryXController.
Definition: MemoryXController.cpp:58
memoryxcontroller::MemoryXController::getWorkingMemoryController
IceInternal::Handle< WorkingMemoryController > getWorkingMemoryController() const
Returns a shared pointer to the WorkingMemoryController.
Definition: MemoryXController.cpp:140
memoryxcontroller::MemoryXController::MemoryXController
MemoryXController()
Constructor.
Definition: MemoryXController.cpp:45
memoryxcontroller::MemoryXController
Definition: MemoryXController.h:51
ObjectClass.h
controller::ControllerWeakPtr
std::weak_ptr< Controller > ControllerWeakPtr
Definition: ClassDefinitions.h:42
IceInternal::Handle
Definition: forward_declarations.h:8
memoryxcontroller::MemoryXController::getAllSnapshots
std::vector< std::string > getAllSnapshots()
Returns a list with the names of all existing snapshots.
Definition: MemoryXController.cpp:155
memoryxcontroller::WorkingMemoryController
The controller for the communication with the working memory.
Definition: WorkingMemoryController.h:57
controller::ControllerPtr
std::shared_ptr< Controller > ControllerPtr
Definition: ClassDefinitions.h:41
memoryxcontroller
Definition: MemoryXController.h:43
memoryxcontroller::MemoryXController::getPriorKnowlegdeController
std::shared_ptr< PriorKnowledgeController > getPriorKnowlegdeController() const
Returns a shared pointer to the PriorKnowledgeController.
Definition: MemoryXController.cpp:145
memoryxcontroller::MemoryXController::saveSceneInSnapshot
bool saveSceneInSnapshot(std::string &snapshotName)
Saves the whole content of the working memory in a snapshot with the given name.
Definition: MemoryXController.cpp:71
memoryxcontroller::MemoryXController::~MemoryXController
~MemoryXController()
Destructor.
Definition: MemoryXController.cpp:50
memoryxcontroller::PriorKnowledgeController
The controller for the communication with the priorknowledge.
Definition: PriorKnowledgeController.h:55
memoryxcontroller::MemoryXController::saveObjectsInSnapshot
bool saveObjectsInSnapshot(std::string &snapshotName, const std::vector< std::string > &objectIds)
Saves all object instances whose ids are given in a snapshot with the given name.
Definition: MemoryXController.cpp:88
PriorKnowledgeController.h
memoryxcontroller::MemoryXController::loadSnapshot
std::vector< std::string > loadSnapshot(const std::string &snapshotName)
Loads the content of the snapshot with the given name and add it to the current working memory.
Definition: MemoryXController.cpp:105
memoryxcontroller::MemoryXControllerPtr
std::shared_ptr< MemoryXController > MemoryXControllerPtr
Definition: MemoryXController.h:146