esp8266ndn
NDN Arduino library for ESP8266 and more
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
transport-tracer.hpp
Go to the documentation of this file.
1 #ifndef NDNPH_FACE_TRANSPORT_TRACER_HPP
2 #define NDNPH_FACE_TRANSPORT_TRACER_HPP
3 
4 #include "../core/log.hpp"
5 #include "transport.hpp"
6 
7 namespace ndnph {
8 namespace transport {
9 
11 class Tracer : public TransportWrap {
12 public:
13  explicit Tracer(Transport& inner, const char* category = "transport")
15  , category(category) {}
16 
17 private:
18  virtual void log(char direction, const uint8_t* pkt, size_t pktLen, uint64_t endpointId) {
19  (void)pkt;
20  (void)endpointId;
21  NDNPH_LOG_LINE("%s", "%c len=%zu", category, direction, pktLen);
22  }
23 
24  void handleRx(const uint8_t* pkt, size_t pktLen, uint64_t endpointId) override {
25  log('>', pkt, pktLen, endpointId);
26  invokeRxCallback(pkt, pktLen, endpointId);
27  }
28 
29  bool doSend(const uint8_t* pkt, size_t pktLen, uint64_t endpointId) override {
30  log('<', pkt, pktLen, endpointId);
31  return inner.send(pkt, pktLen, endpointId);
32  }
33 
34 protected:
35  const char* category;
36 };
37 
38 } // namespace transport
39 } // namespace ndnph
40 
41 #endif // NDNPH_FACE_TRANSPORT_TRACER_HPP
Print trace logs for each incoming and outgoing packet.
Definition: transport-tracer.hpp:11
virtual void log(char direction, const uint8_t *pkt, size_t pktLen, uint64_t endpointId)
Definition: transport-tracer.hpp:18
Tracer(Transport &inner, const char *category="transport")
Definition: transport-tracer.hpp:13
const char * category
Definition: transport-tracer.hpp:35
Wrap another transport.
Definition: transport.hpp:61
Transport & inner
Definition: transport.hpp:90
Base class of low-level transport.
Definition: transport.hpp:10
bool send(const uint8_t *pkt, size_t pktLen, uint64_t endpointId=0)
Synchronously transmit a packet.
Definition: transport.hpp:33
void invokeRxCallback(const uint8_t *pkt, size_t pktLen, uint64_t endpointId=0)
Invoke incoming packet callback for a received packet.
Definition: transport.hpp:39
#define NDNPH_LOG_LINE(category, fmt,...)
Log a message with "\n".
Definition: log.hpp:50
Definition: fs.hpp:33