File indexing completed on 2024-04-14 03:42:38

0001 /*
0002     SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006     Concrete device is a device that implement specific INDI Device Interface (e.g. Telescope).
0007 */
0008 
0009 #pragma once
0010 
0011 #include "indistd.h"
0012 #include "indipropertyswitch.h"
0013 
0014 #include <QTimer>
0015 
0016 namespace ISD
0017 {
0018 
0019 /**
0020  * @brief The ConcreteDevice class
0021  *
0022  * A convenience class to wrap common requests to parent generic device.
0023  */
0024 class ConcreteDevice : public GDInterface
0025 {
0026         Q_OBJECT
0027         Q_PROPERTY(QString name READ getDeviceName)
0028         Q_PROPERTY(bool connected READ isConnected)
0029 
0030     public:
0031         ConcreteDevice(GenericDevice *parent);
0032         virtual ~ConcreteDevice() override = default;
0033 
0034         const QString &getDeviceName() const
0035         {
0036             return m_Name;
0037         }
0038 
0039         bool isReady() const
0040         {
0041             return m_Parent->isReady();
0042         }
0043         bool isConnected() const
0044         {
0045             return m_Parent->isConnected();
0046         }
0047 
0048         void Connect()
0049         {
0050             m_Parent->Connect();
0051         }
0052 
0053         void Disconnect()
0054         {
0055             m_Parent->Disconnect();
0056         }
0057 
0058         uint32_t getDriverInterface()
0059         {
0060             return m_Parent->getDriverInterface();
0061         }
0062 
0063         GenericDevice *genericDevice() const
0064         {
0065             return m_Parent;
0066         }
0067 
0068         INDI::PropertyView<INumber> *getNumber(const QString &name) const;
0069         /** @return Return vector text property given its name */
0070         INDI::PropertyView<IText>   *getText(const QString &name) const;
0071         /** @return Return vector switch property given its name */
0072         INDI::PropertyView<ISwitch> *getSwitch(const QString &name) const;
0073         /** @return Return vector light property given its name */
0074         INDI::PropertyView<ILight>  *getLight(const QString &name) const;
0075         /** @return Return vector BLOB property given its name */
0076         INDI::PropertyView<IBLOB>   *getBLOB(const QString &name) const;
0077 
0078         /** @brief Send new property command to server */
0079         void sendNewProperty(INDI::Property prop);
0080 
0081         INDI::Property getProperty(const QString &name) const;
0082         Properties getProperties() const;
0083         const QSharedPointer<DriverInfo> &getDriverInfo() const;
0084         bool setConfig(INDIConfig tConfig);
0085         bool getMinMaxStep(const QString &propName, const QString &elementName, double *min, double *max,
0086                            double *step) const;
0087         IPState getState(const QString &propName) const;
0088         IPerm getPermission(const QString &propName) const;
0089         QString getMessage(int id) const;
0090 
0091         const QString &getDUBSObjectPath() const
0092         {
0093             return m_DBusObjectPath;
0094         }
0095 
0096         // No implmenetation by default
0097         virtual void registerProperty(INDI::Property) override {}
0098         virtual void removeProperty(INDI::Property) override {}
0099         virtual void updateProperty(INDI::Property prop) override;
0100 
0101         virtual void processSwitch(INDI::Property) override {}
0102         virtual void processText(INDI::Property) override {}
0103         virtual void processNumber(INDI::Property) override {}
0104         virtual void processLight(INDI::Property) override {}
0105         virtual bool processBLOB(INDI::Property) override
0106         {            
0107             return false;
0108         }
0109         virtual void processMessage(int) override {}
0110 
0111         /**
0112          * @brief Register all properties.
0113          */
0114         void registeProperties();
0115 
0116         /**
0117          * @brief processProperties Process all properties
0118          */
0119         void processProperties();
0120 
0121     signals:
0122         // Connection
0123         void Connected();
0124         void Disconnected();
0125 
0126         // Registeration
0127         void propertyDefined(INDI::Property prop);
0128         void propertyUpdated(INDI::Property prop);
0129         void propertyDeleted(INDI::Property prop);        
0130 
0131         void ready();
0132 
0133     protected:
0134         GenericDevice *m_Parent;
0135         QString m_Name;
0136         QScopedPointer<QTimer> m_ReadyTimer;
0137         QString m_DBusObjectPath;
0138         static uint8_t getID()
0139         {
0140             return m_ID++;
0141         }
0142         static uint8_t m_ID;
0143 };
0144 
0145 }