summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-07-29 02:11:08 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-07-29 02:11:08 +0200
commitb15c16f12ca6838e5ebefc80c11dcf7933bce8bc (patch)
tree62e0b4028d99d3ef4aa06a65b8b6379b2fee6cc6
parent37c21678743c752cbbc2297871c47a3117303309 (diff)
downloadgmrf-b15c16f12ca6838e5ebefc80c11dcf7933bce8bc.tar
gmrf-b15c16f12ca6838e5ebefc80c11dcf7933bce8bc.zip
Move protocol-specific interface state into iface_t
-rw-r--r--include/gmrf/gmrf.h7
-rw-r--r--include/mmss/protocol.h4
-rw-r--r--mmss/context.cpp2
-rw-r--r--mmss/iface.cpp2
-rw-r--r--mmss/iface.hpp6
-rw-r--r--mmss/node.hpp8
-rw-r--r--mmss/protocol.hpp8
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> iface_t::add(const std::shared_ptr<node_t> &node, const
std::shared_ptr<iface_t> iface = std::shared_ptr<iface_t>(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<iface_t> &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_t> &iface) {
+ gmrf_iface_state_t* add_iface(const std::shared_ptr<iface_t> &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_t> &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<const protocol_t> load(context_t *mmss, const std::string &module);