From b15c16f12ca6838e5ebefc80c11dcf7933bce8bc Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 29 Jul 2013 02:11:08 +0200 Subject: Move protocol-specific interface state into iface_t --- include/gmrf/gmrf.h | 7 ++++--- include/mmss/protocol.h | 4 ++-- mmss/context.cpp | 2 +- mmss/iface.cpp | 2 +- mmss/iface.hpp | 6 ++++++ mmss/node.hpp | 8 ++++---- mmss/protocol.hpp | 8 ++++---- 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/gmrf/gmrf.h b/include/gmrf/gmrf.h index 742848c..19f115a 100644 --- a/include/gmrf/gmrf.h +++ b/include/gmrf/gmrf.h @@ -37,6 +37,7 @@ typedef struct gmrf gmrf_t; typedef struct gmrf_context gmrf_context_t; typedef struct gmrf_iface gmrf_iface_t; +typedef struct gmrf_iface_state gmrf_iface_state_t; #define GMRF_ADDR_LEN 8 @@ -68,7 +69,7 @@ size_t gmrf_iface_get_mtu(gmrf_t *gmrf, gmrf_iface_t *iface); bool gmrf_iface_send(gmrf_t *gmrf, gmrf_iface_t *iface, const void *data, size_t len, const gmrf_addr_t *dest); bool gmrf_iface_send_bc(gmrf_t *gmrf, gmrf_iface_t *iface, const void *data, size_t len); -typedef void (*gmrf_scheduled_func)(gmrf_t *gmrf, gmrf_context_t *ctx, void *arg); +typedef void (*gmrf_scheduled_func)(gmrf_context_t *ctx, void *arg); void gmrf_schedule(gmrf_t *gmrf, gmrf_scheduled_func f, void *arg, unsigned delay); @@ -77,7 +78,7 @@ extern const char *gmrf_protocol_name; extern const char *gmrf_protocol_version; gmrf_context_t* gmrf_protocol_init(gmrf_t *gmrf); -void gmrf_protocol_add_iface(gmrf_t *gmrf, gmrf_context_t *ctx, gmrf_iface_t *iface); -void gmrf_protocol_handle_packet(gmrf_t *gmrf, gmrf_context_t *ctx, gmrf_iface_t *iface, const gmrf_addr_t *source, const void *data, size_t len); +gmrf_iface_state_t* gmrf_protocol_add_iface(gmrf_context_t *ctx, gmrf_iface_t *iface); +void gmrf_protocol_handle_packet(gmrf_context_t *ctx, gmrf_iface_state_t *iface, const gmrf_addr_t *source, const void *data, size_t len); #endif /* _GMRF_GMRF_H_ */ diff --git a/include/mmss/protocol.h b/include/mmss/protocol.h index 3ddd094..277e325 100644 --- a/include/mmss/protocol.h +++ b/include/mmss/protocol.h @@ -35,8 +35,8 @@ typedef struct mmss_protocol { const char* (*get_version)(void); gmrf_context_t* (*init)(gmrf_t *gmrf); - void (*add_iface)(gmrf_t *gmrf, gmrf_context_t *ctx, gmrf_iface_t *iface); - void (*handle_packet)(gmrf_t *gmrf, gmrf_context_t *ctx, gmrf_iface_t *iface, const gmrf_addr_t *source, const void *data, size_t len); + gmrf_iface_state_t* (*add_iface)(gmrf_context_t *ctx, gmrf_iface_t *iface); + void (*handle_packet)(gmrf_context_t *ctx, gmrf_iface_state_t *iface, const gmrf_addr_t *source, const void *data, size_t len); } mmss_protocol_t; #endif /* _GMRF_MMSS_PROTOCOL_H_ */ diff --git a/mmss/context.cpp b/mmss/context.cpp index d1e01c0..a6a24e7 100644 --- a/mmss/context.cpp +++ b/mmss/context.cpp @@ -105,7 +105,7 @@ void context_t::run(int argc, char *argv[]) { int timeout = event_queue.timeout(); if (timeout < 0) { - fprintf(stderr, "nothing queued, deadlock occured.\n"); + logf(LOG_ERR, "nothing queued, deadlock occured"); break; } diff --git a/mmss/iface.cpp b/mmss/iface.cpp index a7a174e..77b5872 100644 --- a/mmss/iface.cpp +++ b/mmss/iface.cpp @@ -38,7 +38,7 @@ std::shared_ptr iface_t::add(const std::shared_ptr &node, const std::shared_ptr iface = std::shared_ptr(new iface_t(node.get(), net.get(), name, address)); net->add_iface(iface); - node->add_iface(iface); + iface->state = node->add_iface(iface); return iface; } diff --git a/mmss/iface.hpp b/mmss/iface.hpp index 2f464bd..3b8cc0b 100644 --- a/mmss/iface.hpp +++ b/mmss/iface.hpp @@ -42,6 +42,8 @@ private: std::string name; gmrf_addr_t address; + gmrf_iface_state *state; + void enqueue(context_t *mmss, const std::shared_ptr &dest, const void *data, size_t len); iface_t(node_t *node0, network_t *net0, const std::string &name0, const gmrf_addr_t *address0) @@ -64,6 +66,10 @@ public: return &address; } + gmrf_iface_state* get_state() const { + return state; + } + void send(const void *data, size_t len, const gmrf_addr_t *dest) { net->send(data, len, this, dest); } diff --git a/mmss/node.hpp b/mmss/node.hpp index c561cfc..1243c14 100644 --- a/mmss/node.hpp +++ b/mmss/node.hpp @@ -62,9 +62,9 @@ public: return node; } - void add_iface(const std::shared_ptr &iface) { + gmrf_iface_state_t* add_iface(const std::shared_ptr &iface) { interfaces.insert(iface); - proto->add_iface(this, gmrf_ctx, iface.get()); + return proto->add_iface(gmrf_ctx, iface.get()); } context_t* get_context() const { @@ -80,11 +80,11 @@ public: } void handle_packet(const std::shared_ptr &iface, const gmrf_addr_t *source, const void *data, size_t len) { - proto->handle_packet(this, gmrf_ctx, iface.get(), source, data, len); + proto->handle_packet(gmrf_ctx, iface->get_state(), source, data, len); } void handle_scheduled(gmrf_scheduled_func f, void *arg) { - f(this, gmrf_ctx, arg); + f(gmrf_ctx, arg); } }; diff --git a/mmss/protocol.hpp b/mmss/protocol.hpp index fcf54ae..0bdc60b 100644 --- a/mmss/protocol.hpp +++ b/mmss/protocol.hpp @@ -61,12 +61,12 @@ public: return proto->init(gmrf); } - void add_iface(gmrf_t *gmrf, gmrf_context_t *ctx, gmrf_iface_t *iface) const { - return proto->add_iface(gmrf, ctx, iface); + gmrf_iface_state_t* add_iface(gmrf_context_t *ctx, gmrf_iface_t *iface) const { + return proto->add_iface(ctx, iface); } - void handle_packet(gmrf_t *gmrf, gmrf_context_t *ctx, gmrf_iface_t *iface, const gmrf_addr_t *source, const void *data, size_t len) const { - return proto->handle_packet(gmrf, ctx, iface, source, data, len); + void handle_packet(gmrf_context_t *ctx, gmrf_iface_state_t *iface, const gmrf_addr_t *source, const void *data, size_t len) const { + proto->handle_packet(ctx, iface, source, data, len); } static std::shared_ptr load(context_t *mmss, const std::string &module); -- cgit v1.2.3