diff --git a/source/RobotAPI/libraries/armem_objects/CMakeLists.txt b/source/RobotAPI/libraries/armem_objects/CMakeLists.txt index 63da8444d40d90e6c4e73a1a4fd755082f4914f9..bbb52cc2b5f473d71cbf1d7c73e39002368f71ad 100644 --- a/source/RobotAPI/libraries/armem_objects/CMakeLists.txt +++ b/source/RobotAPI/libraries/armem_objects/CMakeLists.txt @@ -36,6 +36,8 @@ armarx_add_library( server/attachments/Segment.h + client/class/ClassReader.h + client/class/ClassWriter.h client/articulated_object/Reader.h client/articulated_object/Writer.h client/articulated_object/ArticulatedObjectReader.h @@ -55,6 +57,8 @@ armarx_add_library( types.cpp utils.cpp + client/class/ClassReader.cpp + client/class/ClassWriter.cpp client/articulated_object/Reader.cpp client/articulated_object/Writer.cpp client/articulated_object/ArticulatedObjectReader.cpp diff --git a/source/RobotAPI/libraries/armem_objects/client/class/ClassReader.cpp b/source/RobotAPI/libraries/armem_objects/client/class/ClassReader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bceba7d960ffbe41a620c36d47a5d8fc0897c157 --- /dev/null +++ b/source/RobotAPI/libraries/armem_objects/client/class/ClassReader.cpp @@ -0,0 +1,45 @@ +#include "ClassReader.h" + +namespace armarx::armem::obj::clazz +{ + std::optional<armem::clazz::ObjectClass> + ClassReader::getObjectClass(const std::string& providerName, const ObjectID& id) + { + auto mid = armarx::armem::MemoryID(); + mid.memoryName = properties().memoryName; + mid.coreSegmentName = properties().coreSegmentName; + mid.providerSegmentName = providerName; + mid.entityName = id.str(); + + auto i = this->memoryReader().getLatestSnapshotIn(mid); + + if (i.has_value() && i->size() == 1) + { + auto& instance = i->getInstance(0); + auto aron = instance.dataAs<armarx::armem::arondto::ObjectClass>(); + + armem::clazz::ObjectClass objClass; + armarx::armem::clazz::fromAron(aron, objClass); + + return objClass; + } + + return std::nullopt; + } + + std::string + ClassReader::propertyPrefix() const + { + return "classReader."; + } + + client::util::SimpleReaderBase::Properties + ClassReader::defaultProperties() const + { + client::util::SimpleReaderBase::Properties p; + p.memoryName = "Object"; + p.coreSegmentName = "Class"; + return p; + } + +} // namespace armarx::armem::obj::clazz diff --git a/source/RobotAPI/libraries/armem_objects/client/class/ClassReader.h b/source/RobotAPI/libraries/armem_objects/client/class/ClassReader.h new file mode 100644 index 0000000000000000000000000000000000000000..4d2805b4f03e81bb6b58b65d73997eeae56755ab --- /dev/null +++ b/source/RobotAPI/libraries/armem_objects/client/class/ClassReader.h @@ -0,0 +1,49 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Reister ( fabian dot reister at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <mutex> +#include <optional> + +#include <RobotAPI/libraries/armem/client/util/SimpleReaderBase.h> +#include <RobotAPI/libraries/armem_objects/aron_conversions.h> +#include <RobotAPI/libraries/armem_objects/types.h> + +namespace armarx::armem::obj::clazz +{ + class ClassReader : public armem::client::util::SimpleReaderBase + { + public: + ClassReader() = default; + + std::optional<armem::clazz::ObjectClass> getObjectClass(const std::string& providerName, + const armarx::ObjectID& id); + + protected: + std::string propertyPrefix() const final; + Properties defaultProperties() const final; + + private: + }; + + +} // namespace armarx::armem::obj::clazz diff --git a/source/RobotAPI/libraries/armem_objects/client/class/ClassWriter.cpp b/source/RobotAPI/libraries/armem_objects/client/class/ClassWriter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f9f1d109bca843610638ab3473314ab5fe1c4a03 --- /dev/null +++ b/source/RobotAPI/libraries/armem_objects/client/class/ClassWriter.cpp @@ -0,0 +1,48 @@ +#include "ClassWriter.h" + +namespace armarx::armem::obj::clazz +{ + bool + ClassWriter::commitObjectClass(const armarx::armem::clazz::ObjectClass& c, + const armarx::core::time::DateTime& referenceTime) + { + armarx::armem::arondto::ObjectClass objClassAron; + armarx::armem::clazz::toAron(objClassAron, c); + + armarx::armem::MemoryID mid; + mid.memoryName = properties().memoryName; + mid.coreSegmentName = properties().coreSegmentName; + mid.providerSegmentName = properties().providerName; + mid.entityName = c.id.str(); + + auto commit = armarx::armem::Commit(); + auto& update = commit.add(); + + update.confidence = 1.0f; + update.referencedTime = referenceTime; + update.sentTime = armarx::core::time::DateTime::Now(); + update.entityID = mid; + update.instancesData = {objClassAron.toAron()}; + + auto res = this->memoryWriter().commit(commit); + + return res.allSuccess(); + } + + std::string + ClassWriter::propertyPrefix() const + { + return "classWriter."; + } + + client::util::SimpleWriterBase::Properties + ClassWriter::defaultProperties() const + { + client::util::SimpleWriterBase::Properties p; + p.memoryName = "Object"; + p.coreSegmentName = "Class"; + p.providerName = providerName; + return p; + } + +} // namespace armarx::armem::obj::clazz diff --git a/source/RobotAPI/libraries/armem_objects/client/class/ClassWriter.h b/source/RobotAPI/libraries/armem_objects/client/class/ClassWriter.h new file mode 100644 index 0000000000000000000000000000000000000000..db17223ba7f8dc550283fb2aa5c1ed3d11872f7e --- /dev/null +++ b/source/RobotAPI/libraries/armem_objects/client/class/ClassWriter.h @@ -0,0 +1,50 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Reister ( fabian dot reister at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <mutex> +#include <optional> + +#include <RobotAPI/libraries/armem/client/util/SimpleWriterBase.h> +#include <RobotAPI/libraries/armem_objects/aron_conversions.h> +#include <RobotAPI/libraries/armem_objects/types.h> + +namespace armarx::armem::obj::clazz +{ + class ClassWriter : public armem::client::util::SimpleWriterBase + { + public: + ClassWriter(const std::string& p) : providerName(p){}; + + bool commitObjectClass(const armarx::armem::clazz::ObjectClass& c, + const armarx::core::time::DateTime& referenceTime); + + protected: + std::string propertyPrefix() const final; + Properties defaultProperties() const final; + + private: + const std::string providerName; + }; + + +} // namespace armarx::armem::obj::clazz