Skip to content

Commit

Permalink
change code positin
Browse files Browse the repository at this point in the history
  • Loading branch information
FyS committed Nov 20, 2023
1 parent 04584a1 commit c865554
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 240 deletions.
36 changes: 19 additions & 17 deletions fabko/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ cmake_minimum_required(VERSION 3.22)
add_library(core STATIC)
target_sources(core
PUBLIC
core/blackboard.cpp
core/blackboard.hh
core/acl.hh
core/protocol/fap_request.hh
core/protocol/boardcom.cpp
core/protocol/boardcom.hh
core/common/logging.cpp
core/common/logging.hh
core/common/exception.hh
core/common/ranges_to.hh
core/common/visitor_utils.hh
core/common/string_utils.hh
# SAT solving logic (not sure its ever going to be useful)
core/logic/formula.cpp
core/logic/formula.hh
core/logic/sat/dimacs_compiler.cpp
Expand All @@ -27,35 +22,42 @@ target_sources(core
PRIVATE
core/logic/sat/helpers.hh
core/logic/sat/helpers.cpp
)
)
target_include_directories(core
PRIVATE
${RocksDB_INCLUDE_DIR}
PUBLIC
core
)
)
target_compile_definitions(core PUBLIC cxx_std_23)
target_link_libraries(core
PUBLIC
RocksDB::rocksdb fmt::fmt
PRIVATE
spdlog::spdlog
nlohmann_json::nlohmann_json)
nlohmann_json::nlohmann_json
)
add_library(fabko::core ALIAS core)

#
# Agent library
#
add_library(agent OBJECT)
target_sources(agent
PUBLIC
agent/agent.hh
agent/action.hh
agent/protocol/acl.hh
agent/protocol/fap_request.hh
agent/protocol/boardcom.hh
PRIVATE
agent/agent.cpp
agent/action.hh
PUBLIC
agent/agent.hh)
target_include_directories(agent PUBLIC
agent
)
agent/blackboard.cpp
agent/blackboard.hh
agent/protocol/boardcom_local.cpp
agent/protocol/boardcom_p2p.cpp
)
target_include_directories(agent PUBLIC agent)
target_compile_definitions(agent PUBLIC cxx_std_23)
target_link_libraries(agent PRIVATE fabko::core)
add_library(fabko::agent ALIAS agent)
Expand All @@ -77,7 +79,7 @@ target_include_directories(peerboard PUBLIC
peerboard
datastore
core
)
)
target_link_libraries(peerboard PRIVATE fabko::agent fabko::core)
target_compile_definitions(peerboard PUBLIC cxx_std_23)
add_library(fabko::peerboard ALIAS peerboard)
Expand All @@ -91,7 +93,7 @@ add_executable(fabko)
target_sources(fabko
PRIVATE
fabko.cpp
)
)
target_include_directories(fabko PUBLIC include)
target_link_libraries(fabko PRIVATE fabko::peerboard)
target_compile_definitions(fabko PUBLIC cxx_std_23)
20 changes: 8 additions & 12 deletions fabko/agent/agent.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,32 @@
#pragma once

#include <concepts>
#include <memory>
#include <expected>
#include <functional>
#include <memory>

namespace fabko {

template<typename action>
class agent {
struct impl;

public:
~agent() = default;

// extract requirement of the type on a static assertion as agent symbol is not available to the compiler at the
// template declaration level.
static_assert(
std::is_invocable_v<action, agent&>,
"The action function provided to the agent has to be with the following signature: void(agent&)");
template<typename action>
requires std::is_invocable_v<action, agent&>
explicit agent(action func) : _callback_on_action(std::move(func)) {}

~agent() = default;

[[nodiscard]] std::expected<>
// [[nodiscard]] std::expected<>;

private:
void execute_action() {
_callback_on_action(*this);
}

action _callback_on_action;
std::function<void(agent&)> _callback_on_action;

std::unique_ptr<impl> _pimpl;

};

} // namespace fabko
7 changes: 2 additions & 5 deletions fabko/core/blackboard.cpp → fabko/agent/blackboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@
#include <functional>

#include "blackboard.hh"
#include <common/visitor_utils.hh>
#include "common/visitor_utils.hh"

namespace fabko {

struct blackboard::blackboard_impl {

explicit blackboard_impl(agent_protocol::c_board_com auto&& bc, blackboard_data data)
: bc(std::forward<decltype(bc)>(bc)), data(std::move(data)) {}

blackboard_data instantiate_black_board(const std::string& request) {
std::visit(
overloaded{[&request](auto& b) -> std::string { return b.instantiate_black_board(request); }}, bc);
Expand All @@ -35,7 +32,7 @@ blackboard::~blackboard() = default;

template<agent_protocol::c_board_com BoardCommunication>
blackboard::blackboard(BoardCommunication&& bc, agent_protocol::request initial_request)
: _pimpl(std::forward<BoardCommunication>(bc), {.initial_request = std::move(initial_request)}) {
: _pimpl{std::forward<BoardCommunication>(bc), {.initial_request = std::move(initial_request)}} {
}

agent_protocol::propositions blackboard::request_propositions(const agent_protocol::request& request) {
Expand Down
File renamed without changes.
File renamed without changes.
82 changes: 82 additions & 0 deletions fabko/agent/protocol/boardcom.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Dual Licensing Either :
// - AGPL
// or
// - Subscription license for commercial usage (without requirement of licensing propagation).
// please contact [email protected] for additional information about this subscription commercial licensing.
//
// Created by FyS on 23/04/23. License 2022-2023
//
// In the case no license has been purchased for the use (modification or distribution in any way) of the software stack
// the APGL license is applying.
//

#pragma once

#include <memory>
#include <concepts>
#include <future>
#include <optional>
#include <string>
#include <variant>
#include <vector>

#include "fap_request.hh"

namespace fabko::agent_protocol {

struct proposition {
std::string id;
};

struct propositions {
std::optional<std::vector<proposition>> props;
status st{status::awaiting};
};

enum class decision_status {
SUCCESS,
RETRY,
CANCELLED,
};

/**
*
* @tparam T
*/
template<typename T>
concept c_board_com =
requires(T a) {
{ T::make_board(request{}) } -> std::convertible_to<std::string>;
{ a.propositions(std::string{}) } -> std::convertible_to<std::future<propositions>>;
{ a.commit_decision(std::string{}) } -> std::convertible_to<decision_status>;
} && std::movable<T>;

namespace p2p {
class board_protocol {
public:
static std::string instantiate_black_board(const std::string&);
std::future<propositions> request_propositions(const std::string&);
decision_status commit_decision(const std::string&);
};
} // namespace p2p

namespace local {
class board_protocol {
struct impl;

public:
~board_protocol();
board_protocol();

static std::string instantiate_black_board(const std::string&);
std::future<propositions> request_propositions(const std::string&);
decision_status commit_decision(const std::string&);

private:
std::unique_ptr<impl> _impl;
};
} // namespace local

using board_protocol = std::variant<local::board_protocol, p2p::board_protocol>;

} // namespace fabko::agent_protocol
38 changes: 38 additions & 0 deletions fabko/agent/protocol/boardcom_local.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// - AGPL
// or
// - Subscription license for commercial usage (without requirement of licensing propagation).
// please contact [email protected] for additional information about this subscription commercial licensing.
//
// Created by FyS on 23/04/23. License 2022-2023
//
// In the case no license has been purchased for the use (modification or distribution in any way) of the software stack
// the APGL license is applying.

#include <agent.hh>

#include "boardcom.hh"

namespace fabko::agent_protocol::local {

struct board_protocol::impl {
std::vector<std::shared_ptr<agent>> _agent_ring;
};

board_protocol::~board_protocol() = default;

std::string board_protocol::instantiate_black_board(const std::string&) {
return {};
}

std::future<propositions> board_protocol::request_propositions(const std::string&) {
return std::future<propositions>();
}

agent_protocol::decision_status board_protocol::commit_decision(const std::string&) {
return agent_protocol::decision_status::RETRY;
}

board_protocol::board_protocol(): _impl(std::make_unique<impl>()) {
}

}
14 changes: 3 additions & 11 deletions fabko/core/boardcom.cpp → fabko/agent/protocol/boardcom_p2p.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,14 @@

#include "boardcom.hh"

namespace fabko {
namespace fabko::agent_protocol::p2p {

std::string com::p2p::instantiate_black_board(const std::string&) {
std::string board_protocol::instantiate_black_board(const std::string&) {
return {};
}

std::string com::online::instantiate_black_board(const std::string&) {
std::future<agent_protocol::propositions> board_protocol::request_propositions(const std::string&) {
return {};
}

std::future<com::propositions> com::online::request_propositions(const std::string&) {
return {};
}

com::decision_status com::online::commit_decision(const std::string&) {
return com::decision_status::RETRY;
}

} // namespace fabko
File renamed without changes.
80 changes: 0 additions & 80 deletions fabko/core/boardcom.hh

This file was deleted.

Loading

0 comments on commit c865554

Please sign in to comment.