Fawkes API  Fawkes Development Version
SwitchInterface.h
1 
2 /***************************************************************************
3  * SwitchInterface.h - Fawkes BlackBoard Interface - SwitchInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2008 Tim Niemueller
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __INTERFACES_SWITCHINTERFACE_H_
25 #define __INTERFACES_SWITCHINTERFACE_H_
26 
27 #include <interface/interface.h>
28 #include <interface/message.h>
29 #include <interface/field_iterator.h>
30 
31 namespace fawkes {
32 
33 class SwitchInterface : public Interface
34 {
35  /// @cond INTERNALS
36  INTERFACE_MGMT_FRIENDS(SwitchInterface)
37  /// @endcond
38  public:
39  /* constants */
40 
41  private:
42 #pragma pack(push,4)
43  /** Internal data storage, do NOT modify! */
44  typedef struct {
45  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
46  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
47  bool enabled; /**<
48  True if the switch is currently enabled.
49  */
50  float value; /**<
51  If switches support multiple states these can be indicated with
52  this value. For example for a switch that notes the intensity it
53  could be a value in the valid range.
54  */
55  float history; /**<
56  This value records the number of seconds a switch has been
57  enabled continuously -- or not. The time is recorded in
58  seconds. A positive value indicates time the switch was turned
59  on, a negative value indicates the time (when converted to the
60  absolute value) the button has not been pressed. Zero means
61  "just initialized".
62  */
63  uint32_t short_activations; /**<
64  Number of consecutive short clicks (turned on). Can be used to recognize
65  patterns of clicks. This is an optional field.
66  */
67  uint32_t long_activations; /**<
68  Number of consecutive short clicks (turned on). Can be used to recognize
69  patterns of clicks. This is an optional field.
70  */
71  uint32_t activation_count; /**<
72  Number that is to be incremented whenever a short or long activation
73  happened. Can be used to decide if a change in status happened.
74  */
75  } SwitchInterface_data_t;
76 #pragma pack(pop)
77 
78  SwitchInterface_data_t *data;
79 
80  public:
81  /* messages */
82  class SetMessage : public Message
83  {
84  private:
85 #pragma pack(push,4)
86  /** Internal data storage, do NOT modify! */
87  typedef struct {
88  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
89  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
90  bool enabled; /**<
91  True if the switch is currently enabled.
92  */
93  float value; /**<
94  If switches support multiple states these can be indicated with
95  this value. For example for a switch that notes the intensity it
96  could be a value in the valid range.
97  */
98  } SetMessage_data_t;
99 #pragma pack(pop)
100 
101  SetMessage_data_t *data;
102 
103  public:
104  SetMessage(const bool ini_enabled, const float ini_value);
105  SetMessage();
106  ~SetMessage();
107 
108  SetMessage(const SetMessage *m);
109  /* Methods */
110  bool is_enabled() const;
111  void set_enabled(const bool new_enabled);
112  size_t maxlenof_enabled() const;
113  float value() const;
114  void set_value(const float new_value);
115  size_t maxlenof_value() const;
116  virtual Message * clone() const;
117  };
118 
120  {
121  private:
122 #pragma pack(push,4)
123  /** Internal data storage, do NOT modify! */
124  typedef struct {
125  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
126  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
127  } EnableSwitchMessage_data_t;
128 #pragma pack(pop)
129 
130  EnableSwitchMessage_data_t *data;
131 
132  public:
135 
137  /* Methods */
138  virtual Message * clone() const;
139  };
140 
142  {
143  private:
144 #pragma pack(push,4)
145  /** Internal data storage, do NOT modify! */
146  typedef struct {
147  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
148  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
149  } DisableSwitchMessage_data_t;
150 #pragma pack(pop)
151 
152  DisableSwitchMessage_data_t *data;
153 
154  public:
157 
159  /* Methods */
160  virtual Message * clone() const;
161  };
162 
164  {
165  private:
166 #pragma pack(push,4)
167  /** Internal data storage, do NOT modify! */
168  typedef struct {
169  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
170  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
171  float duration; /**< Duration in seconds for which
172  the switch should be enabled. */
173  float value; /**<
174  If switches support multiple states these can be indicated with
175  this value. For example for a switch that notes the intensity it
176  could be a value in the valid range.
177  */
178  } EnableDurationMessage_data_t;
179 #pragma pack(pop)
180 
181  EnableDurationMessage_data_t *data;
182 
183  public:
184  EnableDurationMessage(const float ini_duration, const float ini_value);
187 
189  /* Methods */
190  float duration() const;
191  void set_duration(const float new_duration);
192  size_t maxlenof_duration() const;
193  float value() const;
194  void set_value(const float new_value);
195  size_t maxlenof_value() const;
196  virtual Message * clone() const;
197  };
198 
199  virtual bool message_valid(const Message *message) const;
200  private:
201  SwitchInterface();
202  ~SwitchInterface();
203 
204  public:
205  /* Methods */
206  bool is_enabled() const;
207  void set_enabled(const bool new_enabled);
208  size_t maxlenof_enabled() const;
209  float value() const;
210  void set_value(const float new_value);
211  size_t maxlenof_value() const;
212  float history() const;
213  void set_history(const float new_history);
214  size_t maxlenof_history() const;
215  uint32_t short_activations() const;
216  void set_short_activations(const uint32_t new_short_activations);
217  size_t maxlenof_short_activations() const;
218  uint32_t long_activations() const;
219  void set_long_activations(const uint32_t new_long_activations);
220  size_t maxlenof_long_activations() const;
221  uint32_t activation_count() const;
222  void set_activation_count(const uint32_t new_activation_count);
223  size_t maxlenof_activation_count() const;
224  virtual Message * create_message(const char *type) const;
225 
226  virtual void copy_values(const Interface *other);
227  virtual const char * enum_tostring(const char *enumtype, int val) const;
228 
229 };
230 
231 } // end namespace fawkes
232 
233 #endif
size_t maxlenof_enabled() const
Get maximum length of enabled value.
size_t maxlenof_value() const
Get maximum length of value value.
virtual Message * clone() const
Clone this message.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:43
SetMessage Fawkes BlackBoard Interface Message.
void set_value(const float new_value)
Set value value.
const char * type() const
Get message type.
Definition: message.cpp:378
void set_enabled(const bool new_enabled)
Set enabled value.
Fawkes library namespace.
float value() const
Get value value.
uint32_t long_activations() const
Get long_activations value.
void set_history(const float new_history)
Set history value.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
void set_short_activations(const uint32_t new_short_activations)
Set short_activations value.
SwitchInterface Fawkes BlackBoard Interface.
float history() const
Get history value.
uint32_t short_activations() const
Get short_activations value.
void set_activation_count(const uint32_t new_activation_count)
Set activation_count value.
bool is_enabled() const
Get enabled value.
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
DisableSwitchMessage Fawkes BlackBoard Interface Message.
uint32_t activation_count() const
Get activation_count value.
void set_long_activations(const uint32_t new_long_activations)
Set long_activations value.
size_t maxlenof_activation_count() const
Get maximum length of activation_count value.
size_t maxlenof_long_activations() const
Get maximum length of long_activations value.
virtual void copy_values(const Interface *other)
Copy values from other interface.
EnableSwitchMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_history() const
Get maximum length of history value.
float value() const
Get value value.
size_t maxlenof_short_activations() const
Get maximum length of short_activations value.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
EnableDurationMessage Fawkes BlackBoard Interface Message.
virtual Message * create_message(const char *type) const
Create message based on type name.