outgoing_transfer_registry.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
3  */
4 
5 #ifndef UAVCAN_TRANSPORT_OUTGOING_TRANSFER_REGISTRY_HPP_INCLUDED
6 #define UAVCAN_TRANSPORT_OUTGOING_TRANSFER_REGISTRY_HPP_INCLUDED
7 
8 #include <cassert>
9 #include <uavcan/std.hpp>
10 #include <uavcan/build_config.hpp>
11 #include <uavcan/util/map.hpp>
12 #include <uavcan/debug.hpp>
14 #include <uavcan/time.hpp>
15 
16 namespace uavcan
17 {
18 
20 {
24 
25 public:
27  : transfer_type_(0xFF)
28  { }
29 
30  OutgoingTransferRegistryKey(DataTypeID data_type_id, TransferType transfer_type, NodeID destination_node_id)
31  : data_type_id_(data_type_id)
32  , transfer_type_(transfer_type)
33  , destination_node_id_(destination_node_id)
34  {
35  UAVCAN_ASSERT((transfer_type == TransferTypeMessageBroadcast) == destination_node_id.isBroadcast());
36  /*
37  * Service response transfers must use the same Transfer ID as matching service request transfer,
38  * so this registry is not applicable for service response transfers at all.
39  */
41  }
42 
43  DataTypeID getDataTypeID() const { return data_type_id_; }
44  TransferType getTransferType() const { return TransferType(transfer_type_); }
45 
46  bool operator==(const OutgoingTransferRegistryKey& rhs) const
47  {
48  return
49  (data_type_id_ == rhs.data_type_id_) &&
50  (transfer_type_ == rhs.transfer_type_) &&
51  (destination_node_id_ == rhs.destination_node_id_);
52  }
53 
54 #if UAVCAN_TOSTRING
55  std::string toString() const;
56 #endif
57 };
58 
65 {
66  struct Value
67  {
70  };
71 
73  {
75 
76  public:
78  : ts_(ts)
79  { }
80 
81  bool operator()(const OutgoingTransferRegistryKey& key, const Value& value) const
82  {
83  (void)key;
84  UAVCAN_ASSERT(!value.deadline.isZero());
85  const bool expired = value.deadline <= ts_;
86  if (expired)
87  {
88  UAVCAN_TRACE("OutgoingTransferRegistry", "Expired %s tid=%i",
89  key.toString().c_str(), int(value.tid.get()));
90  }
91  return expired;
92  }
93  };
94 
96  {
99 
100  public:
102  : dtid_(dtid)
103  , tt_(tt)
104  { }
105 
106  bool operator()(const OutgoingTransferRegistryKey& key, const Value&) const
107  {
108  return dtid_ == key.getDataTypeID() && tt_ == key.getTransferType();
109  }
110  };
111 
113 
114 public:
116 
118  : map_(allocator)
119  { }
120 
121  TransferID* accessOrCreate(const OutgoingTransferRegistryKey& key, MonotonicTime new_deadline);
122 
123  bool exists(DataTypeID dtid, TransferType tt) const;
124 
125  void cleanup(MonotonicTime ts);
126 };
127 
128 }
129 
130 #endif // UAVCAN_TRANSPORT_OUTGOING_TRANSFER_REGISTRY_HPP_INCLUDED
std::uint8_t uint8_t
Definition: std.hpp:24
bool isZero() const
Definition: time.hpp:123
NodeID destination_node_id_
Not applicable for message broadcasting.
bool isBroadcast() const
Definition: transfer.hpp:135
static const MonotonicDuration MinEntryLifetime
static std::string toString(long x)
Definition: multiset.cpp:16
Map< OutgoingTransferRegistryKey, Value > map_
uint8_t get() const
Definition: transfer.hpp:99
TransferType
Definition: transfer.hpp:18
bool operator()(const OutgoingTransferRegistryKey &key, const Value &) const
OutgoingTransferRegistry(IPoolAllocator &allocator)
bool operator==(const OutgoingTransferRegistryKey &rhs) const
OutgoingTransferRegistryKey(DataTypeID data_type_id, TransferType transfer_type, NodeID destination_node_id)
ROSCPP_DECL bool exists(const std::string &service_name, bool print_failure_reason)
bool operator()(const OutgoingTransferRegistryKey &key, const Value &value) const
int
Definition: libstubs.cpp:120


uavcan_communicator
Author(s):
autogenerated on Wed Jan 11 2023 03:59:39