Open Lighting Architecture  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DmxSource.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program 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
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  * DmxSource.h
17  * Interface for the DmxSource class.
18  * A DmxSource contains a DmxSource as well as a priority & timestamp.
19  * Copyright (C) 2005-2010 Simon Newton
20  */
21 
22 #ifndef INCLUDE_OLAD_DMXSOURCE_H_
23 #define INCLUDE_OLAD_DMXSOURCE_H_
24 
25 #include <stdint.h>
26 #include <ola/Clock.h>
27 #include <ola/DmxBuffer.h>
29 
30 namespace ola {
31 
32 
33 /*
34  * The DmxSource class
35  */
36 class DmxSource {
37  public:
38  DmxSource():
39  m_buffer(),
40  m_timestamp(),
41  m_priority(ola::dmx::SOURCE_PRIORITY_MIN) {
42  }
43 
44  DmxSource(const DmxBuffer &buffer,
45  const TimeStamp &timestamp,
46  uint8_t priority):
47  m_buffer(buffer),
48  m_timestamp(timestamp),
49  m_priority(priority) {
50  }
51 
52  DmxSource(const DmxSource &other) {
53  m_buffer = other.m_buffer;
54  m_timestamp = other.m_timestamp;
55  m_priority = other.m_priority;
56  }
57 
58 
59  /*
60  * Assignment operator
61  */
62  DmxSource& operator=(const DmxSource& other) {
63  if (this != &other) {
64  m_buffer = other.m_buffer;
65  m_timestamp = other.m_timestamp;
66  m_priority = other.m_priority;
67  }
68  return *this;
69  }
70 
71  /*
72  * Equality check
73  */
74  bool operator==(const DmxSource &other) const {
75  return (m_buffer == other.m_buffer &&
76  m_timestamp == other.m_timestamp &&
77  m_priority == other.m_priority);
78  }
79 
80 
81  /*
82  * Update the DmxSource with new data
83  */
84  void UpdateData(const DmxBuffer &buffer, const TimeStamp &timestamp,
85  uint8_t priority) {
86  m_buffer = buffer;
87  m_timestamp = timestamp;
88  m_priority = priority;
89  }
90 
91 
92  /*
93  * Get the DmxBuffer in this source
94  */
95  const DmxBuffer &Data() const { return m_buffer; }
96 
97 
98  /*
99  * Get the timestamp
100  */
101  const TimeStamp &Timestamp() const { return m_timestamp; }
102 
103 
104  /*
105  * Check if this source has timed out
106  */
107  bool IsActive(const TimeStamp &now) const {
108  TimeStamp timeout = m_timestamp + TIMEOUT_INTERVAL;
109  return now < timeout;
110  }
111 
112 
113  /*
114  * Check if this source has ever got data
115  */
116  bool IsSet() const {
117  return m_timestamp.IsSet();
118  }
119 
120 
121  /*
122  * Get the priority for this source
123  */
124  uint8_t Priority() const { return m_priority; }
125 
126  private:
127  DmxBuffer m_buffer;
128  TimeStamp m_timestamp;
129  uint8_t m_priority;
130 
131  static const TimeInterval TIMEOUT_INTERVAL;
132 };
133 } // namespace ola
134 #endif // INCLUDE_OLAD_DMXSOURCE_H_