Open Lighting Architecture  Latest Git
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Message.h
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * Message.h
17  * Holds the data for a message.
18  * Copyright (C) 2011 Simon Newton
19  */
20 
21 #ifndef INCLUDE_OLA_MESSAGING_MESSAGE_H_
22 #define INCLUDE_OLA_MESSAGING_MESSAGE_H_
23 
24 #include <ola/messaging/Descriptor.h>
25 #include <ola/messaging/MessageVisitor.h>
27 #include <ola/network/MACAddress.h>
28 #include <ola/rdm/UID.h>
29 #include <string>
30 #include <vector>
31 
32 
33 namespace ola {
34 namespace messaging {
35 
36 
37 class MessageVisitor;
38 
39 class Message {
40  public:
41  explicit Message(
42  const std::vector<const class MessageFieldInterface*> &fields)
43  : m_fields(fields) {
44  }
45  ~Message();
46 
47  void Accept(MessageVisitor *visitor) const;
48 
49  unsigned int FieldCount() const { return m_fields.size(); }
50 
51  private:
52  std::vector<const class MessageFieldInterface*> m_fields;
53 };
54 
55 
56 
61  public:
62  virtual ~MessageFieldInterface() {}
63 
64  // Call back into a MessageVisitor
65  virtual void Accept(MessageVisitor *visitor) const = 0;
66 };
67 
68 
69 
74  public:
75  BoolMessageField(const BoolFieldDescriptor *descriptor,
76  bool value)
77  : m_descriptor(descriptor),
78  m_value(value) {
79  }
80 
81  const BoolFieldDescriptor *GetDescriptor() const {
82  return m_descriptor;
83  }
84  bool Value() const { return m_value; }
85 
86  void Accept(MessageVisitor *visitor) const {
87  visitor->Visit(this);
88  }
89 
90  private:
91  const BoolFieldDescriptor *m_descriptor;
92  bool m_value;
93 };
94 
95 
100  public:
101  IPV4MessageField(const IPV4FieldDescriptor *descriptor,
102  const ola::network::IPV4Address &value)
103  : m_descriptor(descriptor),
104  m_value(value) {
105  }
106 
107  IPV4MessageField(const IPV4FieldDescriptor *descriptor,
108  uint32_t value)
109  : m_descriptor(descriptor),
110  m_value(ola::network::IPV4Address(value)) {
111  }
112 
113  const IPV4FieldDescriptor *GetDescriptor() const {
114  return m_descriptor;
115  }
116  const ola::network::IPV4Address& Value() const { return m_value; }
117 
118  void Accept(MessageVisitor *visitor) const {
119  visitor->Visit(this);
120  }
121 
122  private:
123  const IPV4FieldDescriptor *m_descriptor;
125 };
126 
127 
132  public:
133  MACMessageField(const MACFieldDescriptor *descriptor,
134  const ola::network::MACAddress &value)
135  : m_descriptor(descriptor),
136  m_value(value) {
137  }
138 
139  const MACFieldDescriptor *GetDescriptor() const {
140  return m_descriptor;
141  }
142  const ola::network::MACAddress& Value() const { return m_value; }
143 
144  void Accept(MessageVisitor *visitor) const {
145  visitor->Visit(this);
146  }
147 
148  private:
149  const MACFieldDescriptor *m_descriptor;
150  ola::network::MACAddress m_value;
151 };
152 
153 
158  public:
159  UIDMessageField(const UIDFieldDescriptor *descriptor,
160  const ola::rdm::UID &uid)
161  : m_descriptor(descriptor),
162  m_uid(uid) {
163  }
164 
165  const UIDFieldDescriptor *GetDescriptor() const {
166  return m_descriptor;
167  }
168  const ola::rdm::UID& Value() const { return m_uid; }
169 
170  void Accept(MessageVisitor *visitor) const {
171  visitor->Visit(this);
172  }
173 
174  private:
175  const UIDFieldDescriptor *m_descriptor;
176  ola::rdm::UID m_uid;
177 };
178 
179 
184  public:
185  StringMessageField(const StringFieldDescriptor *descriptor,
186  const std::string &value)
187  : m_descriptor(descriptor),
188  m_value(value) {
189  }
190 
191  const StringFieldDescriptor *GetDescriptor() const { return m_descriptor; }
192  const std::string& Value() const { return m_value; }
193 
194  void Accept(MessageVisitor *visitor) const {
195  visitor->Visit(this);
196  }
197 
198  private:
199  const StringFieldDescriptor *m_descriptor;
200  const std::string m_value;
201 };
202 
203 
207 template <typename type>
209  public:
211  type value)
212  : m_descriptor(descriptor),
213  m_value(value) {
214  }
215 
216  const IntegerFieldDescriptor<type> *GetDescriptor() const {
217  return m_descriptor;
218  }
219  type Value() const { return m_value; }
220 
221  void Accept(MessageVisitor *visitor) const {
222  visitor->Visit(this);
223  }
224 
225  private:
226  const IntegerFieldDescriptor<type> *m_descriptor;
227  type m_value;
228 };
229 
230 
237 
238 
243  public:
245  const FieldDescriptorGroup *descriptor,
246  const std::vector<const class MessageFieldInterface*> &fields)
247  : m_descriptor(descriptor),
248  m_fields(fields) {}
250 
251  const FieldDescriptorGroup *GetDescriptor() const { return m_descriptor; }
252 
253  unsigned int FieldCount() const { return m_fields.size(); }
254  const class MessageFieldInterface *GetField(unsigned int index) const {
255  if (index < m_fields.size())
256  return m_fields[index];
257  return NULL;
258  }
259 
260  void Accept(MessageVisitor *visitor) const;
261 
262  private:
263  const FieldDescriptorGroup *m_descriptor;
264  std::vector<const class MessageFieldInterface*> m_fields;
265 };
266 } // namespace messaging
267 } // namespace ola
268 
269 #endif // INCLUDE_OLA_MESSAGING_MESSAGE_H_
Definition: MessageVisitor.h:43
Definition: Descriptor.h:84
Definition: Message.h:99
A RDM unique identifier (UID).
Definition: Message.h:73
Definition: Message.h:131
Definition: Descriptor.h:122
Definition: Descriptor.h:324
Represents a IPv4 Address.
Definition: IPV4Address.h:55
Represents a MAC Address.
Definition: MACAddress.h:50
Definition: Descriptor.h:141
Definition: Descriptor.h:103
Definition: Message.h:157
Represents an IPv4 Address.
Definition: Message.h:183
Definition: Descriptor.h:160
Definition: Message.h:39
Represents a RDM UID.
Definition: UID.h:57
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Represents a MAC Address.
Definition: Descriptor.h:190
Definition: Message.h:208
Definition: Message.h:242