[502] | 1 | #ifndef INDIBASEDRIVER_H
|
---|
| 2 | #define INDIBASEDRIVER_H
|
---|
| 3 |
|
---|
[504] | 4 | #include <boost/shared_ptr.hpp>
|
---|
[502] | 5 | #include <map>
|
---|
| 6 | #include <string>
|
---|
| 7 |
|
---|
| 8 | #include "indiapi.h"
|
---|
| 9 | #include "indidevapi.h"
|
---|
| 10 | #include "indibase.h"
|
---|
| 11 |
|
---|
| 12 | #define MAXRBUF 2048
|
---|
| 13 |
|
---|
| 14 | /**
|
---|
| 15 | * \class INDI::BaseDriver
|
---|
| 16 | \brief Class to provide basic INDI driver functionality.
|
---|
| 17 |
|
---|
| 18 | INDI::BaseClient contains a vector list of INDI::BaseDrivers. Upon connection with INDI server, the client create a INDI::BaseDriver
|
---|
| 19 | \e instance for each driver owned by the INDI server. Properties of the driver can be build either by loading an external
|
---|
| 20 | skeleton file that contains a list of defXXX commands, or by dynamically building properties as they arrive from the server.
|
---|
| 21 |
|
---|
| 22 | \author Jasem Mutlaq
|
---|
| 23 | */
|
---|
| 24 | class INDI::BaseDriver
|
---|
| 25 | {
|
---|
| 26 | public:
|
---|
| 27 | BaseDriver();
|
---|
[504] | 28 | ~BaseDriver();
|
---|
[502] | 29 |
|
---|
| 30 | /*! INDI error codes. */
|
---|
| 31 | enum INDI_ERROR
|
---|
| 32 | {
|
---|
| 33 | INDI_DEVICE_NOT_FOUND=-1, /*!< INDI Device was not found. */
|
---|
| 34 | INDI_PROPERTY_INVALID=-2, /*!< Property has an invalid syntax or attribute. */
|
---|
| 35 | INDI_PROPERTY_DUPLICATED = -3, /*!< INDI Device was not found. */
|
---|
| 36 | INDI_DISPATCH_ERROR=-4 /*!< Dispatching command to driver failed. */
|
---|
| 37 | };
|
---|
| 38 |
|
---|
| 39 | /*! INDI property type */
|
---|
[504] | 40 | typedef enum
|
---|
[502] | 41 | {
|
---|
| 42 | INDI_NUMBER, /*!< INumberVectorProperty. */
|
---|
| 43 | INDI_SWITCH, /*!< ISwitchVectorProperty. */
|
---|
| 44 | INDI_TEXT, /*!< ITextVectorProperty. */
|
---|
| 45 | INDI_LIGHT, /*!< ILightVectorProperty. */
|
---|
[504] | 46 | INDI_BLOB, /*!< IBLOBVectorProperty. */
|
---|
| 47 | INDI_UNKNOWN
|
---|
| 48 | } INDI_TYPE;
|
---|
[502] | 49 |
|
---|
| 50 | /** \return Return vector number property given its name */
|
---|
| 51 | INumberVectorProperty * getNumber(const char *name);
|
---|
| 52 | /** \return Return vector text property given its name */
|
---|
| 53 | ITextVectorProperty * getText(const char *name);
|
---|
| 54 | /** \return Return vector switch property given its name */
|
---|
| 55 | ISwitchVectorProperty * getSwitch(const char *name);
|
---|
| 56 | /** \return Return vector light property given its name */
|
---|
| 57 | ILightVectorProperty * getLight(const char *name);
|
---|
| 58 | /** \return Return vector BLOB property given its name */
|
---|
| 59 | IBLOBVectorProperty * getBLOB(const char *name);
|
---|
| 60 |
|
---|
[504] | 61 | void registerProperty(void *p, INDI_TYPE type);
|
---|
| 62 |
|
---|
[502] | 63 | /** \brief Remove a property
|
---|
| 64 | \param name name of property to be removed
|
---|
| 65 | \return 0 if successul, -1 otherwise.
|
---|
| 66 | */
|
---|
| 67 | int removeProperty(const char *name);
|
---|
| 68 |
|
---|
| 69 | /** \brief Return a property and its type given its name.
|
---|
| 70 | \param name of property to be found.
|
---|
| 71 | \param type of property found.
|
---|
| 72 | \return If property is found, it is returned. To be used you must use static_cast with given the type of property
|
---|
| 73 | returned.
|
---|
| 74 |
|
---|
| 75 | \note This is a low-level function and should not be called directly unless necessary. Use getXXX instead where XXX
|
---|
| 76 | is the property type (Number, Text, Switch..etc).
|
---|
| 77 |
|
---|
| 78 | */
|
---|
[504] | 79 | void * getProperty(const char *name, INDI_TYPE type = INDI_UNKNOWN);
|
---|
[502] | 80 |
|
---|
| 81 | /** \brief Build driver properties from a skeleton file.
|
---|
| 82 | \param filename full path name of the file.
|
---|
| 83 |
|
---|
| 84 | A skeloton file defines the properties supported by this driver. It is a list of defXXX elements enclosed by @<INDIDriver>@
|
---|
| 85 | and @</INDIDriver>@ opening and closing tags. After the properties are created, they can be rerieved, manipulated, and defined
|
---|
| 86 | to other clients.
|
---|
| 87 |
|
---|
| 88 | \see An example skeleton file can be found under examples/tutorial_four_sk.xml
|
---|
| 89 |
|
---|
| 90 | */
|
---|
| 91 | void buildSkeleton(const char *filename);
|
---|
| 92 |
|
---|
| 93 | /** \return True if the device is connected (CONNECT=ON), False otherwise */
|
---|
| 94 | bool isConnected();
|
---|
| 95 |
|
---|
[504] | 96 |
|
---|
[502] | 97 | /** \brief Set the device name
|
---|
| 98 | \param dev new device name
|
---|
| 99 | */
|
---|
| 100 | void setDeviceName(const char *dev);
|
---|
[504] | 101 |
|
---|
[502] | 102 | /** \return Returns the device name */
|
---|
| 103 | const char *deviceName();
|
---|
| 104 |
|
---|
| 105 | /** \brief Add message to the driver's message queue.
|
---|
| 106 | \param msg Message to add.
|
---|
| 107 | */
|
---|
| 108 | void addMessage(const char *msg);
|
---|
[504] | 109 |
|
---|
| 110 | /** \return Returns the contents of the driver's message queue. */
|
---|
[502] | 111 | const char *message() { return messageQueue.c_str(); }
|
---|
| 112 |
|
---|
| 113 | /** \brief Set the driver's mediator to receive notification of news devices and updated property values. */
|
---|
| 114 | void setMediator(INDI::BaseMediator *med) { mediator = med; }
|
---|
[504] | 115 |
|
---|
[502] | 116 | /** \returns Get the meditator assigned to this driver */
|
---|
| 117 | INDI::BaseMediator * getMediator() { return mediator; }
|
---|
| 118 |
|
---|
[504] | 119 |
|
---|
[502] | 120 | protected:
|
---|
| 121 |
|
---|
| 122 | /** \brief Build a property given the supplied XML element (defXXX)
|
---|
| 123 | \param root XML element to parse and build.
|
---|
| 124 | \param errmsg buffer to store error message in parsing fails.
|
---|
| 125 | \return 0 if parsing is successful, -1 otherwise and errmsg is set */
|
---|
| 126 | int buildProp(XMLEle *root, char *errmsg);
|
---|
| 127 |
|
---|
| 128 | /** \brief handle SetXXX commands from client */
|
---|
| 129 | int setValue (XMLEle *root, char * errmsg);
|
---|
| 130 | /** \brief handle SetBLOB command from client */
|
---|
| 131 | int processBLOB(IBLOB *blobEL, XMLEle *ep, char * errmsg);
|
---|
| 132 | /** \brief Parse and store BLOB in the respective vector */
|
---|
| 133 | int setBLOB(IBLOBVectorProperty *pp, XMLEle * root, char * errmsg);
|
---|
| 134 |
|
---|
| 135 | char deviceID[MAXINDINAME];
|
---|
| 136 |
|
---|
[504] | 137 | typedef boost::shared_ptr<INumberVectorProperty> numberPtr;
|
---|
| 138 | typedef boost::shared_ptr<ITextVectorProperty> textPtr;
|
---|
| 139 | typedef boost::shared_ptr<ISwitchVectorProperty> switchPtr;
|
---|
| 140 | typedef boost::shared_ptr<ILightVectorProperty> lightPtr;
|
---|
| 141 | typedef boost::shared_ptr<IBLOBVectorProperty> blobPtr;
|
---|
| 142 |
|
---|
[502] | 143 | private:
|
---|
| 144 |
|
---|
[504] | 145 | std::map< boost::shared_ptr<void>, INDI_TYPE> pAll;
|
---|
[502] | 146 |
|
---|
| 147 | LilXML *lp;
|
---|
| 148 |
|
---|
| 149 | std::string messageQueue;
|
---|
| 150 |
|
---|
| 151 | INDI::BaseMediator *mediator;
|
---|
| 152 |
|
---|
| 153 | friend class INDI::BaseClient;
|
---|
| 154 | friend class INDI::DefaultDriver;
|
---|
| 155 |
|
---|
| 156 | };
|
---|
| 157 |
|
---|
| 158 | #endif // INDIBASEDRIVER_H
|
---|