summaryrefslogtreecommitdiffstats
path: root/mmss/iface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mmss/iface.cpp')
-rw-r--r--mmss/iface.cpp64
1 files changed, 17 insertions, 47 deletions
diff --git a/mmss/iface.cpp b/mmss/iface.cpp
index e25eccd..602daa2 100644
--- a/mmss/iface.cpp
+++ b/mmss/iface.cpp
@@ -32,29 +32,34 @@
namespace MMSS {
void dispatch(std::shared_ptr<packet_t> packet) {
- packet->dest->node->proto->handle_packet(packet->dest->node, packet->dest->node->ctx, packet->dest,
- &packet->source->address, packet->data.get(), packet->len);
+ auto source = packet->source.lock();
+ auto dest = packet->dest.lock();
+ if (!source || !dest)
+ return;
+
+ auto node = dest->node.lock();
+ if (!node)
+ return;
+
+ node->proto->handle_packet(node.get(), node->ctx, dest.get(), &source->address, packet->data.get(), packet->len);
}
-void add_iface(gmrf_t *node, network_t *net, const char *name, const gmrf_addr_t *address) {
- gmrf_iface_t *iface = new gmrf_iface_t;
+void add_iface(std::shared_ptr<node_t> node, std::shared_ptr<network_t> net, const std::string &name, const gmrf_addr_t *address) {
+ std::shared_ptr<iface_t> iface = iface_t::create();
- iface->name = strdup(name);
+ iface->name = name;
iface->address = *address;
iface->node = node;
iface->net = net;
- iface->node_next = node->interfaces;
- node->interfaces = iface;
+ node->interfaces.push_back(iface);
+ net->interfaces.push_back(iface);
- iface->network_next = net->interfaces;
- net->interfaces = iface;
-
- node->proto->add_iface(node, node->ctx, iface);
+ node->proto->add_iface(node.get(), node->ctx, iface.get());
}
-static void enqueue(context_t *mmss, gmrf_iface_t *source, gmrf_iface_t *dest, const void *data, size_t len) {
+void enqueue(context_t *mmss, std::shared_ptr<iface_t> source, std::shared_ptr<iface_t> dest, const void *data, size_t len) {
std::shared_ptr<packet_t> packet = std::make_shared<packet_t>();
packet->sent = mmss->now;
@@ -69,38 +74,3 @@ static void enqueue(context_t *mmss, gmrf_iface_t *source, gmrf_iface_t *dest, c
}
}
-
-
-gmrf_addr_t gmrf_iface_get_addr(gmrf_t *gmrf, gmrf_iface_t *iface) {
- return iface->address;
-}
-
-const char* gmrf_iface_get_name(gmrf_t *gmrf, gmrf_iface_t *iface) {
- return iface->name;
-}
-
-size_t gmrf_iface_get_mtu(gmrf_t *gmrf, gmrf_iface_t *iface) {
- return iface->net->mtu;
-}
-
-bool gmrf_iface_send(gmrf_t *gmrf, gmrf_iface_t *iface, const void *data, size_t len, const gmrf_addr_t *dest) {
- gmrf_iface_t *dest_iface;
- for (dest_iface = iface->net->interfaces; dest_iface; dest_iface = dest_iface->network_next) {
- if (gmrf_addr_equal(&dest_iface->address, dest)) {
- MMSS::enqueue(gmrf->mmss, iface, dest_iface, data, len);
- break;
- }
- }
-
- return true;
-}
-
-bool gmrf_iface_send_bc(gmrf_t *gmrf, gmrf_iface_t *iface, const void *data, size_t len) {
- gmrf_iface_t *dest_iface;
- for (dest_iface = iface->net->interfaces; dest_iface; dest_iface = dest_iface->network_next) {
- if (dest_iface != iface)
- enqueue(gmrf->mmss, iface, dest_iface, data, len);
- }
-
- return true;
-}