esp8266ndn
NDN Arduino library for ESP8266 and more
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bridge-transport.hpp
Go to the documentation of this file.
1#ifndef NDNPH_FACE_BRIDGE_TRANSPORT_HPP
2#define NDNPH_FACE_BRIDGE_TRANSPORT_HPP
3
5
6namespace ndnph {
7
10 : public virtual Transport
12public:
14
19 bool begin(BridgeTransport& peer) {
20 if (m_peer != nullptr || peer.m_peer != nullptr) {
21 return false;
22 }
23 m_peer = &peer;
24 peer.m_peer = this;
25 return true;
26 }
27
29 bool end() {
30 if (m_peer == nullptr || m_peer->m_peer != this) {
31 return false;
32 }
33 m_peer->m_peer = nullptr;
34 m_peer = nullptr;
35 return true;
36 }
37
38private:
39 bool doIsUp() const final {
40 return m_peer != nullptr;
41 }
42
43 void doLoop() final {
44 this->loopRxQueue();
45 }
46
47 bool doSend(const uint8_t* pkt, size_t pktLen, uint64_t endpointId) final {
48 if (m_peer == nullptr) {
49 return false;
50 }
51 if (auto r = m_peer->receiving()) {
52 if (r.bufLen() < pktLen) {
53 return false;
54 }
55 std::copy_n(pkt, pktLen, r.buf());
56 r(pktLen, endpointId);
57 return true;
58 }
59 return false;
60 }
61
62private:
63 BridgeTransport* m_peer = nullptr;
64};
65
66} // namespace ndnph
67
68#endif // NDNPH_FACE_BRIDGE_TRANSPORT_HPP
Virtual transport that connects to a peer.
Definition bridge-transport.hpp:11
bool begin(BridgeTransport &peer)
Connect to peer transport.
Definition bridge-transport.hpp:19
bool doIsUp() const final
Definition bridge-transport.hpp:39
bool end()
Disconnect from peer transport.
Definition bridge-transport.hpp:29
void doLoop() final
Definition bridge-transport.hpp:43
bool doSend(const uint8_t *pkt, size_t pktLen, uint64_t endpointId) final
Definition bridge-transport.hpp:47
Mixin of RX queue in Transport, allocating buffers from DynamicRegion.
Definition transport-rxqueue.hpp:134
DynamicRxQueueMixin(size_t bufLen=DEFAULT_BUFLEN)
Constructor.
Definition transport-rxqueue.hpp:143
RxContext receiving()
Receive packets in a loop.
Definition transport-rxqueue.hpp:103
void loopRxQueue()
Process periodical events.
Definition transport-rxqueue.hpp:113
Base class of low-level transport.
Definition transport.hpp:10
Definition fs.hpp:33