HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
localloop.h
Go to the documentation of this file.
1 // =============================================================================
16 // =============================================================================
17 
18 #ifndef HF_APP_LOCALLOOP_H
19 #define HF_APP_LOCALLOOP_H
20 
21 #include "hanfun.h"
22 
23 namespace
24 {
28  struct Link: public HF::Transport::AbstractLink
29  {
31 
34 
35  Link *other;
36 
37  Link(HF::Transport::AbstractLayer &_recv_tsp,
38  HF::UID::UID_T *uid = new HF::UID::NONE(),
39  HF::Transport::Layer *tsp = nullptr):
40  recv_tsp(_recv_tsp), _uid(uid), tsp(tsp), other(nullptr)
41  {}
42 
43  virtual ~Link()
44  {
45  delete _uid;
46  }
47 
48  void send(HF::Common::ByteArray &array)
49  {
50  recv_tsp.receive(other, array);
51  }
52 
53  const HF::UID::UID uid() const
54  {
55  return HF::UID::UID(_uid);
56  }
57 
58  HF::Transport::Layer const *transport() const
59  {
60  return tsp;
61  }
62  };
63 
70  class Localloop
71  {
72  protected:
73 
76 
78  std::vector<HF::Devices::Node::Transport *> devices_tsp;
79 
80  public: ~Localloop()
81  {
82  base_tsp.destroy();
83 
84  while (!devices_tsp.empty())
85  {
86  auto tsp = devices_tsp.back();
87  tsp->destroy();
88  devices_tsp.pop_back();
89  delete tsp;
90  }
91  }
92 
98  void set_base(HF::IDevice *base)
99  {
100  base_tsp.destroy();
101  base_tsp.add(base);
102  }
103 
104  void add_node(HF::IDevice *node, std::string uid)
105  {
107  dev_tsp->add(node);
108 
109  Link *dev_link = new Link(base_tsp, new HF::UID::URI("base"));
110  Link *base_link = new Link(*dev_tsp, new HF::UID::URI(uid));
111 
112  dev_link->other = base_link;
113  base_link->other = dev_link;
114 
115  dev_tsp->add(dev_link);
116  base_tsp.add(base_link);
117 
118  devices_tsp.push_back(dev_tsp);
119  }
120  };
121 
122 } // namespace
123 
124 #if HF_GROUP_SUPPORT
125 namespace HF
126 {
127  namespace Transport
128  {
129  namespace Group
130  {
131  HF::Common::Result create(Endpoint &ep, uint16_t group)
132  {
133  UNUSED(ep);
134  UNUSED(group);
136  }
137 
138  HF::Common::Result add(Endpoint &ep, uint16_t group, uint16_t device)
139  {
140  UNUSED(ep);
141  UNUSED(group);
142  UNUSED(device);
143 
145  }
146 
147  void remove(Endpoint &ep, uint16_t group, uint16_t device)
148  {
149  UNUSED(ep);
150  UNUSED(group);
151  UNUSED(device);
152  }
153 
154  void remove(Endpoint &ep, uint16_t group)
155  {
156  UNUSED(ep);
157  UNUSED(group);
158  }
159 
160  } // namespace Group
161 
162  } // namespace Transport
163 
164 } // namespace HF
165 
166 #endif /* HF_GROUP_SUPPORT */
167 
168 #endif /* HF_APP_LOCALLOOP_H */
void receive(HF::Transport::Link *link, HF::Common::ByteArray &payload)
Receive the data in payload, coming in in the given link and deliver the decoded packet to all regist...
This is the top level include file for the HAN-FUN library.
Common::Result create(Endpoint &ep, uint16_t group)
Create a new group of devices at the transport layer with the given address.
Parent class for transport layer implementations on a HAN-FUN Concentrator device.
Definition: devices.h:929
void add(HF::Transport::Endpoint *ep)
Register the given Endpoint to receive events.
Definition: devices.h:524
This class defines the API for the transport layer.
URI UID class.
Definition: uids.h:431
This class represents the interface common to all HAN-FUN devices.
Definition: device.h:99
Parent class for transport layer implementations on a HAN-FUN Node.
Definition: devices.h:506
Common::Result add(Endpoint &ep, uint16_t group, uint16_t device)
Add the given device to the given group for the given end-point ep.
Wrapper around UID_T pointer&#39;s.
Definition: uids.h:531
This class represents a byte array.
virtual void destroy()=0
Free the system resources associated with this transport layer.
void add(HF::Transport::Endpoint *ep)
Register the given Endpoint to receive events.
Definition: devices.h:945
Fail - Not Supported.
API for all UIDs.
Definition: uids.h:55
UID
Profiles UID&#39;s
Definition: profiles.h:60
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.
Parent class for all HF::Transport::Layer implementations.
This class represents an empty UID.
Definition: uids.h:144
void destroy()
Free the system resources associated with this transport layer.
Result
Commands result codes.
Top-level namespace for the HAN-FUN library.
Definition: attributes.h:22