Skip to content

Commit

Permalink
Create abstract interface for Priority to be serialized into json
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <[email protected]>
  • Loading branch information
aaronchongth committed Aug 19, 2024
1 parent 3190409 commit 237b2a5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 71 deletions.
2 changes: 2 additions & 0 deletions rmf_task/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ include(GNUInstallDirs)
find_package(rmf_utils REQUIRED)
find_package(rmf_traffic REQUIRED)
find_package(rmf_battery REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(Threads)

Expand All @@ -41,6 +42,7 @@ add_library(rmf_task SHARED
target_link_libraries(rmf_task
PUBLIC
rmf_battery::rmf_battery
nlohmann_json::nlohmann_json
Threads::Threads
$<$<CXX_COMPILER_ID:GNU>:stdc++fs>
)
Expand Down
13 changes: 10 additions & 3 deletions rmf_task/include/rmf_task/Priority.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@
#define RMF_TASK__PRIORITY_HPP

#include <memory>
#include <nlohmann/json.hpp>

namespace rmf_task {

//==============================================================================
// Forward declare abstract interface. The definition will remain as internal detail.
/// A class to specify the priority for a request
class Priority;
/// Abstract interface to specify the priority for a request
class Priority
{
public:

/// Serialize the priority as a json
virtual nlohmann::json serialize() const = 0;
};

using PriorityPtr = std::shared_ptr<Priority>;
using ConstPriorityPtr = std::shared_ptr<const Priority>;

Expand Down
1 change: 1 addition & 0 deletions rmf_task/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<depend>rmf_battery</depend>
<depend>rmf_utils</depend>
<depend>nlohmann-json-dev</depend>

<depend>eigen</depend>

Expand Down
9 changes: 9 additions & 0 deletions rmf_task/src/rmf_task/BinaryPriority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ std::size_t BinaryPriority::value() const
return _value;
}

//==============================================================================
nlohmann::json BinaryPriority::serialize() const
{
nlohmann::json priority;
priority["type"] = "binary";
priority["value"] = _value;
return priority;
}

}
7 changes: 6 additions & 1 deletion rmf_task/src/rmf_task/BinaryPriority.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#ifndef SRC__RMF_TASK__BINARYPRIORITY_HPP
#define SRC__RMF_TASK__BINARYPRIORITY_HPP

#include "Priority.hpp"
#include <nlohmann/json.hpp>

#include <rmf_task/Priority.hpp>

namespace rmf_task {

Expand All @@ -33,6 +35,9 @@ class BinaryPriority : public Priority
/// Get the value of this priority object
std::size_t value() const;

/// Serialize priority
nlohmann::json serialize() const override;

private:
std::size_t _value;
};
Expand Down
26 changes: 0 additions & 26 deletions rmf_task/src/rmf_task/Priority.cpp

This file was deleted.

41 changes: 0 additions & 41 deletions rmf_task/src/rmf_task/Priority.hpp

This file was deleted.

0 comments on commit 237b2a5

Please sign in to comment.