functional-dag
Loading...
Searching...
No Matches
lib_utils.h
1#pragma once
2// ---------------------------------------------
3// ___ .___
4// |_ \ __| _/____ ____
5// / \ ______ / __ |\__ \ / ___\
6// / /\ \ /_____/ / /_/ | / __ \_/ /_/ >
7// /_/ \__\ \____ |(____ /\___ /
8// \/ \//_____/
9// ---------------------------------------------
10// @author ndepalma@alum.mit.edu
11
12#include <string>
13#include <vector>
14#include <filesystem>
15#include <unordered_map>
16#include <functional_dag/dag_interface.hpp>
17#include <functional_dag/filter_sys.hpp>
18#include <functional_dag/dlpack.h>
19
20using namespace std;
21namespace fs = std::filesystem;
22
23namespace fn_dag {
24 typedef enum {
25 SOURCE, FILTER, COMBINER, SINK, UNDEFINED
26 } MODULE_TYPE;
27
28 typedef fn_dag::dag_source<DLTensor> module_source;
29 typedef fn_dag::dag_node<DLTensor, DLTensor> module_transmit;
30
31 class module {
32 public:
33 module();
34 virtual ~module() = default;
35
36 virtual MODULE_TYPE get_type();
37 virtual std::vector<std::string> const get_available_slots();
38 virtual module_source *get_handle_as_source();
39 virtual module_transmit *get_slot_handle_as_mapping(const std::string &_slot_name);
40 };
41
42 class source_handler : public module {
43 public:
46
47 MODULE_TYPE get_type();
48 module_source *get_handle_as_source();
49 private:
50 module_source *handler;
51 };
52
53 class module_handler : public module {
54 public:
57
58 MODULE_TYPE get_type();
59 module_transmit *get_slot_handle_as_mapping(const std::string &_slot_name);
60 private:
61 module_transmit *handler;
62 };
63
64 typedef enum {
65 STRING, INT, BOOL
66 } OPTION_TYPE;
67
68 typedef struct {
69 OPTION_TYPE type;
70 union {
71 const char * string_value;
72 int int_value;
73 bool bool_value;
74 } value;
75 uint32_t serial_id;
76 string option_prompt;
77 string short_description;
79
81 // using module_getter_fn = module* (*)(const lib_options *);
82
83 typedef struct {
84 uint32_t lib_guid;
85 string name;
86 string parent_name;
87 bool is_source;
88 lib_options instantiation_options;
90
91 using instantiate_fn = std::function<shared_ptr<module>(const lib_options * const)>;
92 // using instantiate_fn = module* (*)(const lib_options * const);
93}
94
95std::string fsys_serialize(const vector<fn_dag::library_spec> * const);
96fn_dag::dag_manager<std::string> *fsys_deserialize(const std::string &json_in, const std::unordered_map<uint32_t, fn_dag::instantiate_fn> &library);
97
98bool preflight_lib(const fs::path _lib_path);
99shared_ptr< vector<fs::directory_entry> > get_all_available_libs(const fs::directory_entry &library_path);
The main DAG function that encapulates generation and mapping of the data across the DAG.
Definition dag_impl.hpp:59
Definition lib_utils.h:53
Definition lib_utils.h:31
Definition lib_utils.h:42
Definition lib_utils.h:68
Definition lib_utils.h:83