diff options
Diffstat (limited to 'mmss/mmss.hpp')
-rw-r--r-- | mmss/mmss.hpp | 108 |
1 files changed, 71 insertions, 37 deletions
diff --git a/mmss/mmss.hpp b/mmss/mmss.hpp index 78c93be..4045c40 100644 --- a/mmss/mmss.hpp +++ b/mmss/mmss.hpp @@ -29,9 +29,67 @@ #include "queue.hpp" +#include <list> #include <memory> +struct gmrf { +private: + gmrf(MMSS::context_t *mmss0, const std::string &name0, unsigned rand_seed0, const MMSS::protocol_t *proto0) : + mmss(mmss0), name(name0), rand_seed(rand_seed0), proto(proto0) {} + gmrf(gmrf const&) = delete; + gmrf& operator=(gmrf const&) = delete; + +public: + static std::shared_ptr<MMSS::node_t> create(MMSS::context_t *mmss, const std::string &name, unsigned rand_seed, const MMSS::protocol_t *proto) { + MMSS::node_t *node = new MMSS::node_t(mmss, name, rand_seed, proto); + + std::shared_ptr<MMSS::node_t> ptr(node); + node->node = ptr; + + return ptr; + } + + std::weak_ptr<MMSS::node_t> node; + + MMSS::context_t *mmss; + + std::string name; + + gmrf_context_t *ctx; + std::list<std::shared_ptr<MMSS::iface_t>> interfaces; + + unsigned rand_seed; + + const MMSS::protocol_t *proto; +}; + +struct gmrf_iface { +private: + gmrf_iface() {} + gmrf_iface(gmrf_iface const&) = delete; + gmrf_iface& operator=(gmrf_iface const&) = delete; + +public: + static std::shared_ptr<MMSS::iface_t> create() { + MMSS::iface_t *iface = new MMSS::iface_t; + + std::shared_ptr<MMSS::iface_t> ptr(iface); + iface->iface = ptr; + + return ptr; + } + + std::weak_ptr<MMSS::iface_t> iface; + + std::string name; + gmrf_addr_t address; + + std::weak_ptr<MMSS::node_t> node; + std::weak_ptr<MMSS::network_t> net; +}; + + namespace MMSS { class context_t { @@ -45,17 +103,15 @@ public: class config_t { public: - network_t *networks; - gmrf_t *nodes; + std::list<std::shared_ptr<network_t>> network; + std::list<std::shared_ptr<node_t>> nodes; }; class network_t { public: - network_t *next; + std::string name; - char *name; - - gmrf_iface_t *interfaces; + std::list<std::shared_ptr<iface_t>> interfaces; size_t mtu; }; @@ -63,8 +119,8 @@ class packet_t { public: uint64_t sent; - gmrf_iface_t *source; - gmrf_iface_t *dest; + std::weak_ptr<iface_t> source; + std::weak_ptr<iface_t> dest; size_t len; std::unique_ptr<uint8_t> data; @@ -72,7 +128,7 @@ public: class scheduled_t { public: - gmrf_t *node; + std::shared_ptr<node_t> node; gmrf_scheduled_func f; void *arg; }; @@ -80,20 +136,15 @@ public: const protocol_t* load_protocol(const char *module); -namespace Config { - -void add_network(context_t *mmss, config_t *conf, const char *name); - -} - bool read_config(context_t *mmss, config_t *conf, const char *filename); -void add_iface(gmrf_t *node, network_t *net, const char *name, const gmrf_addr_t *address); +void add_iface(std::shared_ptr<node_t> node, std::shared_ptr<network_t> net, const std::string &name, const gmrf_addr_t *address); uint64_t now(const context_t *mmss); void dispatch(std::shared_ptr<packet_t> packet); void run_scheduled(std::shared_ptr<scheduled_t> scheduled); +void enqueue(context_t *mmss, std::shared_ptr<iface_t> source, std::shared_ptr<iface_t> dest, const void *data, size_t len); void logf(context_t *mmss, int priority, const char *format, ...); @@ -111,31 +162,14 @@ static inline size_t alignto(size_t l, size_t a) { return ((l+a-1)/a)*a; } -} - -struct gmrf { - gmrf_t *next; - - char *name; - MMSS::context_t *mmss; - gmrf_context_t *ctx; - gmrf_iface_t *interfaces; - - unsigned rand_seed; +namespace Config { - const MMSS::protocol_t *proto; -}; +void add_network(context_t *mmss, config_t *conf, const char *name); -struct gmrf_iface { - gmrf_iface_t *node_next; - gmrf_iface_t *network_next; +} - char *name; - gmrf_addr_t address; +} - gmrf_t *node; - MMSS::network_t *net; -}; #endif /* _GMRF_MMSS_MMSS_HPP_ */ |