functional-dag
Loading...
Searching...
No Matches
lib_utils.h
1#pragma once
12
13#include <filesystem>
14#include <functional_dag/dag_interface.hpp>
15#include <functional_dag/filter_sys.hpp>
16#include <functional_dag/guid_impl.hpp>
17#include <map>
18#include <string>
19#include <vector>
20
21#include "fb_gen/lib_spec_generated.h"
22
23namespace fn_dag {
24using namespace std;
25namespace fs = std::filesystem;
26
27using construction_signature = bool(dag_manager<string> &, const node_spec &);
28
31typedef struct option_spec {
33 OPTION_TYPE type = OPTION_TYPE_UNDEFINED;
35 string name;
41
43typedef struct node_prop_spec {
48 NODE_TYPE module_type = NODE_TYPE::NODE_TYPE_UNDEFINED;
50 vector<option_spec> construction_types;
52
60class library {
61 protected:
65 map<GUID<node_spec>, function<construction_signature>> m_constructors;
66
70 map<GUID<node_spec>, vector<option_spec>> m_options;
71
80 expected<bool, fn_dag::error_codes> _create_node(
81 dag_manager<string> &_manager, const fn_dag::node_spec *const _spec);
82
83 public:
84 library() = default;
85
97 [[nodiscard]] static bool preflight_lib(const fs::path _lib_path);
98
112 [[nodiscard]] expected<bool, fn_dag::error_codes> load_lib(
113 const fs::path _lib_path);
114
122 void load_all_available_libs(const fs::directory_entry &_library_path);
123
135 [[nodiscard]] expected<fn_dag::dag_manager<string> *, fn_dag::error_codes>
136 fsys_deserialize(const string &_json_in);
137};
138
148[[nodiscard]] expected<vector<fs::directory_entry>, error_codes>
149get_all_available_libs(const fs::directory_entry &_library_path);
150
164expected<string, error_codes> fsys_serialize(const uint8_t *const _buffer_in);
165
168typedef struct library_spec {
172 vector<node_prop_spec> available_nodes;
174
175using get_library_fn_type = library_spec();
176} // namespace fn_dag
(Utility) For defining a globally unique UUIDv4 identifier.
Definition guid_impl.hpp:32
The DAG manager manages all of the dags created by the user.
Definition filter_sys.hpp:29
static bool preflight_lib(const fs::path _lib_path)
A quick and easy function to test whether a dynamic library conforms to the library specifications.
expected< bool, fn_dag::error_codes > load_lib(const fs::path _lib_path)
This function loads the library and keeps the constructor around for subsequent asks to create the no...
map< GUID< node_spec >, vector< option_spec > > m_options
This is a parallel data structure that ensures that whatever options/parameters are passed to it at r...
Definition lib_utils.h:70
expected< bool, fn_dag::error_codes > _create_node(dag_manager< string > &_manager, const fn_dag::node_spec *const _spec)
Private function to verify parameters, create the node, and attach it.
expected< fn_dag::dag_manager< string > *, fn_dag::error_codes > fsys_deserialize(const string &_json_in)
Takes highly structured JSON in and turns it into a lambda dag.
map< GUID< node_spec >, function< construction_signature > > m_constructors
A mapping between IDs to the constructors that create the nodes; The user will need to define these l...
Definition lib_utils.h:65
void load_all_available_libs(const fs::directory_entry &_library_path)
This function is for convenience.
Definition guid_generated.h:16
expected< vector< fs::directory_entry >, error_codes > get_all_available_libs(const fs::directory_entry &_library_path)
Similar to load_all_available_libs, this function will retreive compatible libraries in the directory...
struct fn_dag::library_spec library_spec
(Library related) A library spec defines the interface a dynamicly loaded library must define to part...
struct fn_dag::node_prop_spec node_prop_spec
(Library related) A node spec defines the basic properties of a node.
error_codes
Error codes used by the functional dag.
Definition error_codes.h:19
expected< string, error_codes > fsys_serialize(const uint8_t *const _buffer_in)
(Beta) This function will take a spec in and serialize it back out to JSON.
NODE_TYPE
A library is a list of functions that instantiate node sources and transmission nodes.
Definition lib_spec_generated.h:46
struct fn_dag::option_spec option_spec
(Library related) This defines the options to a node, eg: how to configure it.
(Library related) A library spec defines the interface a dynamicly loaded library must define to part...
Definition lib_utils.h:168
vector< node_prop_spec > available_nodes
Which nodes are available in this library.
Definition lib_utils.h:172
GUID< library > guid
The unique identifier of the library.
Definition lib_utils.h:170
(Library related) A node spec defines the basic properties of a node.
Definition lib_utils.h:43
vector< option_spec > construction_types
The options that should be specified to create the node.
Definition lib_utils.h:50
GUID< node_prop_spec > guid
The node's unique identifier.
Definition lib_utils.h:45
NODE_TYPE module_type
The type of module - whether it generates data from a sensor or processes data.
Definition lib_utils.h:48
(Library related) This defines the options to a node, eg: how to configure it.
Definition lib_utils.h:31
string option_prompt
A prompt to be used if the user is asked to specify the param.
Definition lib_utils.h:37
string name
The parameters variable name.
Definition lib_utils.h:35
string short_description
A short description of what the parameter is.
Definition lib_utils.h:39
OPTION_TYPE type
The type of the option - i.e. integer, string, etc.
Definition lib_utils.h:33