SatCat5
net_dispatch.h
Go to the documentation of this file.
1 // Copyright 2023-2024 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
8 
9 #pragma once
10 
11 #include <satcat5/list.h>
12 #include <satcat5/types.h>
13 
14 namespace satcat5 {
15  namespace net {
36  class Dispatch {
37  public:
52  const satcat5::net::Type& type, unsigned len) = 0;
53 
55  inline void add(satcat5::net::Protocol* proto)
56  {m_list.add(proto);}
57 
59  inline void remove(satcat5::net::Protocol* proto)
60  {m_list.remove(proto);}
61 
63  bool bound(const satcat5::net::Type& type) const;
64 
65  protected:
68  Dispatch() {}
69  ~Dispatch() {}
71 
75  bool deliver(
76  const satcat5::net::Type& type,
77  satcat5::io::Readable* src, unsigned len);
78 
81  };
82  }
83 }
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
Definition: net_dispatch.h:36
void add(satcat5::net::Protocol *proto)
Register a Protocol object.
Definition: net_dispatch.h:55
Dispatch()
Constructor and destructor access restricted to children.
Definition: net_dispatch.h:68
virtual satcat5::io::Writeable * open_reply(const satcat5::net::Type &type, unsigned len)=0
Open a reply to the sender of the most recent message by writing frame header(s) and returning a stre...
satcat5::util::List< satcat5::net::Protocol > m_list
Linked list of Protocol objects.
Definition: net_dispatch.h:80
~Dispatch()
Constructor and destructor access restricted to children.
Definition: net_dispatch.h:69
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
void remove(satcat5::net::Protocol *proto)
Unregister a Protocol object.
Definition: net_dispatch.h:59
bool bound(const satcat5::net::Type &type) const
Check if a given net::Type has a matching Protocol.
Definition: net_dispatch.cc:14
A net::Protocol is the counterpart to net::Dispatch that handles a particular data stream,...
Definition: net_protocol.h:28
void add(T *item)
Add new item to front or back, whichever is simpler.
Definition: list.h:221
void remove(T *item)
Remove the designated item from the list.
Definition: list.h:277
Templated functions for manipulating singly-linked lists.
Multipurpose filter for matching fields in network packets.
Definition: net_type.h:38
Basic type aliases and prototypes used throughout SatCat5.