Instrument Neutral Distributed Interface INDI  2.0.2
watchdeviceproperty.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2022 Pawel Soja <kernel32.pl@gmail.com>
3  Copyright (C) 2011 Jasem Mutlaq. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 #pragma once
20 
21 #include "basedevice.h"
22 #include "parentdevice.h"
23 #include "indililxml.h"
24 
25 #include <functional>
26 #include <map>
27 #include <set>
28 #include <vector>
29 
30 namespace INDI
31 {
32 // Internal use only - Common implementatnion for client and driver side
34 {
35  public:
36  struct DeviceInfo
37  {
39  std::function<void (BaseDevice)> newDeviceCallback; // call if device available
40  std::set<std::string> properties; // watch only specific properties only
41 
43  {
46  }
47  };
48 
49  public:
50  std::vector<BaseDevice> getDevices() const;
51  BaseDevice getDeviceByName(const char *name);
52  DeviceInfo &ensureDeviceByName(const char *name, const std::function<ParentDevice()> &constructor);
53 
54  public:
55  bool isEmpty() const;
56 
63  bool isDeviceWatched(const char *deviceName) const;
64 
65  public:
66  void unwatchDevices();
67 
68  void watchDevice(const std::string &deviceName);
69  void watchDevice(const std::string &deviceName, const std::function<void (BaseDevice)> &callback);
70 
71  void watchProperty(const std::string &deviceName, const std::string &propertyName);
72 
73  void clear();
74  void clearDevices();
75  bool deleteDevice(const BaseDevice &device);
76 
77  public:
78  int processXml(const INDI::LilXmlElement &root, char *errmsg, const std::function<ParentDevice()> &constructor = [] { return ParentDevice(ParentDevice::Valid); } );
79 
80  public:
81  std::map<std::string, DeviceInfo>::iterator begin()
82  {
83  return data.begin();
84  }
85 
86  std::map<std::string, DeviceInfo>::iterator end()
87  {
88  return data.end();
89  }
90 
91  protected:
92  std::set<std::string> watchedDevice;
93  std::map<std::string, DeviceInfo> data;
94 };
95 
96 }
hid_device * device
Class to provide basic INDI device functionality.
Definition: basedevice.h:52
The class is used to create device instances. Class copying is not allowed. When an object is destroy...
Definition: parentdevice.h:18
void watchProperty(const std::string &deviceName, const std::string &propertyName)
std::map< std::string, DeviceInfo >::iterator end()
bool isDeviceWatched(const char *deviceName) const
checks if the device is being watched by something
std::vector< BaseDevice > getDevices() const
DeviceInfo & ensureDeviceByName(const char *name, const std::function< ParentDevice()> &constructor)
std::map< std::string, DeviceInfo >::iterator begin()
std::map< std::string, DeviceInfo > data
BaseDevice getDeviceByName(const char *name)
std::set< std::string > watchedDevice
void watchDevice(const std::string &deviceName)
int processXml(const INDI::LilXmlElement &root, char *errmsg, const std::function< ParentDevice()> &constructor=[] { return ParentDevice(ParentDevice::Valid);})
bool deleteDevice(const BaseDevice &device)
Namespace to encapsulate INDI client, drivers, and mediator classes.
std::function< void(BaseDevice)> newDeviceCallback