Program Listing for File ParticipantRegistry.hpp
↰ Return to documentation for file (include/rmf_traffic_ros2/schedule/ParticipantRegistry.hpp
)
/*
* Copyright (C) 2020 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef RMF_TRAFFIC_ROS2__PARTICIPANT_REGISTRY_HPP
#define RMF_TRAFFIC_ROS2__PARTICIPANT_REGISTRY_HPP
#include <rmf_traffic_ros2/Profile.hpp>
#include <rmf_traffic_ros2/geometry/ConvexShape.hpp>
#include <rmf_traffic/schedule/Database.hpp>
#include <string>
#include <yaml-cpp/yaml.h>
#include <unordered_map>
namespace rmf_traffic_ros2 {
namespace schedule {
using Database = rmf_traffic::schedule::Database;
using ParticipantId = rmf_traffic::schedule::ParticipantId;
using ParticipantDescription = rmf_traffic::schedule::ParticipantDescription;
//=============================================================================
struct AtomicOperation
{
enum class OpType : uint8_t
{
Add = 0,
Update = 1
};
OpType operation;
ParticipantDescription description;
};
//=============================================================================
class AbstractParticipantLogger
{
public:
virtual void write_operation(AtomicOperation operation) = 0;
virtual std::optional<AtomicOperation> read_next_record() = 0;
virtual ~AbstractParticipantLogger() = default;
};
//=============================================================================
class YamlLogger : public AbstractParticipantLogger
{
public:
YamlLogger(std::string filename);
void write_operation(AtomicOperation operation) override;
std::optional<AtomicOperation> read_next_record() override;
class Implementation;
private:
rmf_utils::unique_impl_ptr<Implementation> _pimpl;
};
//=============================================================================
class ParticipantRegistry
{
public:
ParticipantRegistry(
std::unique_ptr<AbstractParticipantLogger> logger,
std::shared_ptr<Database> database);
using Registration = rmf_traffic::schedule::Writer::Registration;
Registration add_or_retrieve_participant(ParticipantDescription description);
class Implementation;
private:
rmf_utils::unique_impl_ptr<Implementation> _pimpl;
};
} // namespace schedule
} // namespace rmf_traffic_ros2
#endif