SatCat5
net_dispatch.cc
1 // Copyright 2023-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 
6 #include <satcat5/net_dispatch.h>
7 #include <satcat5/net_protocol.h>
8 #include <satcat5/net_type.h>
9 
12 using satcat5::net::Type;
13 
14 bool Dispatch::bound(const Type& type) const
15 {
16  Protocol* item = m_list.head();
17  while (item) {
18  if (item->m_filter.match(type))
19  return true; // Found a match!
20  item = m_list.next(item);
21  }
22  return false; // No match found.
23 }
24 
25 bool Dispatch::deliver(const Type& type,
26  satcat5::io::Readable* src, unsigned len)
27 {
28  Protocol* item = m_list.head();
29  while (item) {
30  if (item->m_filter.match(type)) {
31  satcat5::io::LimitedRead tmp(src, len);
32  item->frame_rcvd(tmp);
33  return true; // Delivery successful!
34  }
35  item = m_list.next(item);
36  }
37  return false; // No match found.
38 }
Limited read of next N bytes.
Definition: io_readable.h:255
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
Definition: net_dispatch.h:36
satcat5::util::List< satcat5::net::Protocol > m_list
Linked list of Protocol objects.
Definition: net_dispatch.h:80
bool deliver(const satcat5::net::Type &type, satcat5::io::Readable *src, unsigned len)
Deliver current message by calling Protocol::frame_rcvd(...).
Definition: net_dispatch.cc:25
A net::Protocol is the counterpart to net::Dispatch that handles a particular data stream,...
Definition: net_protocol.h:28
virtual void frame_rcvd(satcat5::io::LimitedRead &src)=0
Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.
satcat5::net::Type m_filter
Incoming packet filter.
Definition: net_protocol.h:52
T * next(const T *item) const
Fetch pointer to the next item.
Definition: list.h:261
Generic network Dispatch API.
Generic network Protocol API.
Generic numeric "Type" for use with net::Protocol.
Multipurpose filter for matching fields in network packets.
Definition: net_type.h:38
bool match(const Type &other) const
Check if this Type matches other.
Definition: net_type.h:82