1 /*
2     SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 
6     Handle INDI Standard properties.
7 */
8 
9 #pragma once
10 
11 #include "indi/indistd.h"
12 
13 #include <indiproperty.h>
14 
15 #include <QObject>
16 
17 class ClientManager;
18 class FITSViewer;
19 class DeviceInfo;
20 
21 /**
22  * @class INDIListener
23  * INDIListener is responsible for creating ISD::GDInterface generic devices as new devices arrive from
24  * ClientManager. It can support multiple ClientManagers and will first create a generic INDI device.
25  * Upon arrival of INDI properties, INDIListener can create specialized devices (e.g. Telescope) if it
26  * detects key Standard INDI property that signifies a particular device family. The generic device
27  * functionality is extended via the Decorator design pattern.
28  *
29  * INDIListener also delegates INDI properties as they are received from ClientManager to the appropriate
30  * device to be processed.
31  *
32  * @author Jasem Mutlaq
33  */
34 class INDIListener : public QObject
35 {
36         Q_OBJECT
37 
38     public:
39         static INDIListener *Instance();
40 
41         void addClient(ClientManager *cm);
42         void removeClient(ClientManager *cm);
43 
44         ISD::GDInterface *getDevice(const QString &name);
getDevices()45         QList<ISD::GDInterface *> getDevices()
46         {
47             return devices;
48         }
49 
size()50         int size()
51         {
52             return devices.size();
53         }
54 
55         bool isStandardProperty(const QString &name);
56 
57     public slots:
58 
59         void registerProperty(INDI::Property prop);
60         void removeProperty(const QString &device, const QString &name);
61         void processDevice(DeviceInfo *dv);
62         void processSwitch(ISwitchVectorProperty *svp);
63         void processText(ITextVectorProperty *tvp);
64         void processNumber(INumberVectorProperty *nvp);
65         void processLight(ILightVectorProperty *lvp);
66         void processBLOB(IBLOB *bp);
67         void processMessage(INDI::BaseDevice *dp, int messageID);
68         void processUniversalMessage(const QString &message);
69         //void removeDevice(DeviceInfo *dv);
70         void removeDevice(const QString &deviceName);
71 
72     private:
73         explicit INDIListener(QObject *parent);
74         ~INDIListener();
75 
76         static INDIListener *_INDIListener;
77 
78         QList<ClientManager *> clients;
79         QList<ISD::GDInterface *> devices;
80         QList<ISD::ST4 *> st4Devices;
81 
82     signals:
83         void newDevice(ISD::GDInterface *);
84         void newTelescope(ISD::GDInterface *);
85         void newCCD(ISD::GDInterface *);
86         void newFilter(ISD::GDInterface *);
87         void newFocuser(ISD::GDInterface *);
88         void newDome(ISD::GDInterface *);
89         void newWeather(ISD::GDInterface *);
90         void newDustCap(ISD::GDInterface *);
91         void newLightBox(ISD::GDInterface *);
92         void newST4(ISD::ST4 *);
93         void deviceRemoved(ISD::GDInterface *);
94 };
95