Instrument Neutral Distributed Interface INDI  2.0.2
indipropertyswitch.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2021 by Pawel Soja <kernel32.pl@gmail.com>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #pragma once
20 
21 #include "indipropertybasic.h"
22 #include <map>
23 
24 namespace INDI
25 {
26 
27 class PropertySwitchPrivate;
28 class PropertySwitch: public INDI::PropertyBasic<ISwitch>
29 {
30  DECLARE_PRIVATE(PropertySwitch)
31  public:
32  struct NewValues: public std::map<std::string, ISState>
33  {
34  bool contains(const std::string &key, const ISState &state) const
35  {
36  auto it = this->find(key);
37  return it != this->cend() && it->second == state;
38  }
39  };
40 
41  public:
42  PropertySwitch(size_t count);
45 
46  public:
47  void onNewValues(const std::function<void(const NewValues &)> &callback);
48 
49  public:
50  bool update(const ISState states[], const char * const names[], int n);
51  bool hasUpdateCallback() const;
52 
53  void fill(
54  const char *device, const char *name, const char *label, const char *group,
55  IPerm permission, ISRule rule, double timeout, IPState state
56  );
57 
58  public:
59  void reset();
60  int findOnSwitchIndex() const;
62 
63  public:
64  void setRule(ISRule rule);
65 
66  public:
67  ISRule getRule() const;
68  const char * getRuleAsString() const;
69 };
70 
71 }
hid_device * device
void onNewValues(const std::function< void(const NewValues &)> &callback)
bool update(const ISState states[], const char *const names[], int n)
const char * getRuleAsString() const
void setRule(ISRule rule)
INDI::WidgetViewSwitch * findOnSwitch() const
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, ISRule rule, double timeout, IPState state)
Provides generic container for INDI properties.
Definition: indiproperty.h:48
friend class PropertySwitch
Definition: indiproperty.h:208
ISState
Switch state.
Definition: indiapi.h:150
IPerm
Permission hint, with respect to client.
Definition: indiapi.h:183
IPState
Property state.
Definition: indiapi.h:160
ISRule
Switch vector rule hint.
Definition: indiapi.h:172
Namespace to encapsulate INDI client, drivers, and mediator classes.
bool contains(const std::string &key, const ISState &state) const