Open Lighting Architecture
 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>
28 
29 namespace ola {
30 
31 
32 /*
33  * The DmxSource class
34  */
35 class DmxSource {
36  public:
37  DmxSource():
38  m_buffer(),
39  m_timestamp(),
40  m_priority(PRIORITY_MIN) {
41  }
42 
43  DmxSource(const DmxBuffer &buffer,
44  const TimeStamp &timestamp,
45  uint8_t priority):
46  m_buffer(buffer),
47  m_timestamp(timestamp),
48  m_priority(priority) {
49  }
50 
51  DmxSource(const DmxSource &other) {
52  m_buffer = other.m_buffer;
53  m_timestamp = other.m_timestamp;
54  m_priority = other.m_priority;
55  }
56 
57 
58  /*
59  * Assignment operator
60  */
61  DmxSource& operator=(const DmxSource& other) {
62  if (this != &other) {
63  m_buffer = other.m_buffer;
64  m_timestamp = other.m_timestamp;
65  m_priority = other.m_priority;
66  }
67  return *this;
68  }
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  static const uint8_t PRIORITY_MIN;
127  static const uint8_t PRIORITY_MAX;
128  static const uint8_t PRIORITY_DEFAULT;
129 
130  private:
131  DmxBuffer m_buffer;
132  TimeStamp m_timestamp;
133  uint8_t m_priority;
134 
135  static const TimeInterval TIMEOUT_INTERVAL;
136 };
137 } // namespace ola
138 #endif // INCLUDE_OLAD_DMXSOURCE_H_