1 | /*******************************************************************************
|
---|
2 | Copyright(c) 2011 Jasem Mutlaq. All rights reserved.
|
---|
3 |
|
---|
4 | This library is free software; you can redistribute it and/or
|
---|
5 | modify it under the terms of the GNU Library General Public
|
---|
6 | License version 2 as published by the Free Software Foundation.
|
---|
7 |
|
---|
8 | This library is distributed in the hope that it will be useful,
|
---|
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
11 | Library General Public License for more details.
|
---|
12 |
|
---|
13 | You should have received a copy of the GNU Library General Public License
|
---|
14 | along with this library; see the file COPYING.LIB. If not, write to
|
---|
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
---|
16 | Boston, MA 02110-1301, USA.
|
---|
17 | *******************************************************************************/
|
---|
18 |
|
---|
19 | #ifndef INDIBASEDRIVER_H
|
---|
20 | #define INDIBASEDRIVER_H
|
---|
21 |
|
---|
22 | #include <vector>
|
---|
23 | #include <string>
|
---|
24 |
|
---|
25 | #include "indiapi.h"
|
---|
26 | #include "indidevapi.h"
|
---|
27 | #include "indibase.h"
|
---|
28 |
|
---|
29 | #define MAXRBUF 2048
|
---|
30 |
|
---|
31 | class PropertyContainer
|
---|
32 | {
|
---|
33 | public:
|
---|
34 | PropertyContainer();
|
---|
35 | ~PropertyContainer();
|
---|
36 |
|
---|
37 | /*! INDI property type */
|
---|
38 | typedef enum
|
---|
39 | {
|
---|
40 | INDI_NUMBER, /*!< INumberVectorProperty. */
|
---|
41 | INDI_SWITCH, /*!< ISwitchVectorProperty. */
|
---|
42 | INDI_TEXT, /*!< ITextVectorProperty. */
|
---|
43 | INDI_LIGHT, /*!< ILightVectorProperty. */
|
---|
44 | INDI_BLOB, /*!< IBLOBVectorProperty. */
|
---|
45 | INDI_UNKNOWN
|
---|
46 | } INDI_TYPE;
|
---|
47 |
|
---|
48 | void setProperty(void *);
|
---|
49 | void setType(INDI_TYPE t);
|
---|
50 | void setRegistered(bool r);
|
---|
51 | void setDynamic(bool d);
|
---|
52 |
|
---|
53 | void *getProperty() { return pPtr; }
|
---|
54 | INDI_TYPE getType() { return pType; }
|
---|
55 | bool getRegistered() { return pRegistered; }
|
---|
56 | bool getDynamic() { return pDynamic; }
|
---|
57 |
|
---|
58 | private:
|
---|
59 | void *pPtr;
|
---|
60 | INDI_TYPE pType;
|
---|
61 | bool pRegistered;
|
---|
62 | bool pDynamic;
|
---|
63 | };
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * \class INDI::BaseDriver
|
---|
67 | \brief Class to provide basic INDI driver functionality.
|
---|
68 |
|
---|
69 | INDI::BaseClient contains a vector list of INDI::BaseDrivers. Upon connection with INDI server, the client create a INDI::BaseDriver
|
---|
70 | \e instance for each driver owned by the INDI server. Properties of the driver can be build either by loading an external
|
---|
71 | skeleton file that contains a list of defXXX commands, or by dynamically building properties as they arrive from the server.
|
---|
72 |
|
---|
73 | \author Jasem Mutlaq
|
---|
74 | */
|
---|
75 | class INDI::BaseDriver
|
---|
76 | {
|
---|
77 | public:
|
---|
78 | BaseDriver();
|
---|
79 | ~BaseDriver();
|
---|
80 |
|
---|
81 | /*! INDI error codes. */
|
---|
82 | enum INDI_ERROR
|
---|
83 | {
|
---|
84 | INDI_DEVICE_NOT_FOUND=-1, /*!< INDI Device was not found. */
|
---|
85 | INDI_PROPERTY_INVALID=-2, /*!< Property has an invalid syntax or attribute. */
|
---|
86 | INDI_PROPERTY_DUPLICATED = -3, /*!< INDI Device was not found. */
|
---|
87 | INDI_DISPATCH_ERROR=-4 /*!< Dispatching command to driver failed. */
|
---|
88 | };
|
---|
89 |
|
---|
90 | /** \return Return vector number property given its name */
|
---|
91 | INumberVectorProperty * getNumber(const char *name);
|
---|
92 | /** \return Return vector text property given its name */
|
---|
93 | ITextVectorProperty * getText(const char *name);
|
---|
94 | /** \return Return vector switch property given its name */
|
---|
95 | ISwitchVectorProperty * getSwitch(const char *name);
|
---|
96 | /** \return Return vector light property given its name */
|
---|
97 | ILightVectorProperty * getLight(const char *name);
|
---|
98 | /** \return Return vector BLOB property given its name */
|
---|
99 | IBLOBVectorProperty * getBLOB(const char *name);
|
---|
100 |
|
---|
101 | void registerProperty(void *p, PropertyContainer::INDI_TYPE type);
|
---|
102 |
|
---|
103 | /** \brief Remove a property
|
---|
104 | \param name name of property to be removed
|
---|
105 | \return 0 if successul, -1 otherwise.
|
---|
106 | */
|
---|
107 | int removeProperty(const char *name);
|
---|
108 |
|
---|
109 | /** \brief Return a property and its type given its name.
|
---|
110 | \param name of property to be found.
|
---|
111 | \param type of property found.
|
---|
112 | \return If property is found, it is returned. To be used you must use static_cast with given the type of property
|
---|
113 | returned.
|
---|
114 |
|
---|
115 | \note This is a low-level function and should not be called directly unless necessary. Use getXXX instead where XXX
|
---|
116 | is the property type (Number, Text, Switch..etc).
|
---|
117 |
|
---|
118 | */
|
---|
119 | void * getProperty(const char *name, PropertyContainer::INDI_TYPE type = PropertyContainer::INDI_UNKNOWN);
|
---|
120 |
|
---|
121 | PropertyContainer * getContainer(const char *name, PropertyContainer::INDI_TYPE type = PropertyContainer::INDI_UNKNOWN);
|
---|
122 |
|
---|
123 | /** \brief Build driver properties from a skeleton file.
|
---|
124 | \param filename full path name of the file.
|
---|
125 |
|
---|
126 | A skeloton file defines the properties supported by this driver. It is a list of defXXX elements enclosed by @<INDIDriver>@
|
---|
127 | and @</INDIDriver>@ opening and closing tags. After the properties are created, they can be rerieved, manipulated, and defined
|
---|
128 | to other clients.
|
---|
129 |
|
---|
130 | \see An example skeleton file can be found under examples/tutorial_four_sk.xml
|
---|
131 |
|
---|
132 | */
|
---|
133 | void buildSkeleton(const char *filename);
|
---|
134 |
|
---|
135 | /** \return True if the device is connected (CONNECT=ON), False otherwise */
|
---|
136 | bool isConnected();
|
---|
137 |
|
---|
138 |
|
---|
139 | /** \brief Set the device name
|
---|
140 | \param dev new device name
|
---|
141 | */
|
---|
142 | void setDeviceName(const char *dev);
|
---|
143 |
|
---|
144 | /** \return Returns the device name */
|
---|
145 | const char *deviceName();
|
---|
146 |
|
---|
147 | /** \brief Add message to the driver's message queue.
|
---|
148 | \param msg Message to add.
|
---|
149 | */
|
---|
150 | void addMessage(const char *msg);
|
---|
151 |
|
---|
152 | /** \return Returns the contents of the driver's message queue. */
|
---|
153 | const char *message() { return messageQueue.c_str(); }
|
---|
154 |
|
---|
155 | /** \brief Set the driver's mediator to receive notification of news devices and updated property values. */
|
---|
156 | void setMediator(INDI::BaseMediator *med) { mediator = med; }
|
---|
157 |
|
---|
158 | /** \returns Get the meditator assigned to this driver */
|
---|
159 | INDI::BaseMediator * getMediator() { return mediator; }
|
---|
160 |
|
---|
161 |
|
---|
162 | protected:
|
---|
163 |
|
---|
164 | /** \brief Build a property given the supplied XML element (defXXX)
|
---|
165 | \param root XML element to parse and build.
|
---|
166 | \param errmsg buffer to store error message in parsing fails.
|
---|
167 | \return 0 if parsing is successful, -1 otherwise and errmsg is set */
|
---|
168 | int buildProp(XMLEle *root, char *errmsg);
|
---|
169 |
|
---|
170 | /** \brief handle SetXXX commands from client */
|
---|
171 | int setValue (XMLEle *root, char * errmsg);
|
---|
172 | /** \brief handle SetBLOB command from client */
|
---|
173 | int processBLOB(IBLOB *blobEL, XMLEle *ep, char * errmsg);
|
---|
174 | /** \brief Parse and store BLOB in the respective vector */
|
---|
175 | int setBLOB(IBLOBVectorProperty *pp, XMLEle * root, char * errmsg);
|
---|
176 |
|
---|
177 |
|
---|
178 | private:
|
---|
179 |
|
---|
180 | char deviceID[MAXINDINAME];
|
---|
181 |
|
---|
182 | std::vector<PropertyContainer *> pAll;
|
---|
183 |
|
---|
184 | LilXML *lp;
|
---|
185 |
|
---|
186 | std::string messageQueue;
|
---|
187 |
|
---|
188 | INDI::BaseMediator *mediator;
|
---|
189 |
|
---|
190 | friend class INDI::BaseClient;
|
---|
191 | friend class INDI::DefaultDriver;
|
---|
192 |
|
---|
193 | };
|
---|
194 |
|
---|
195 | #endif // INDIBASEDRIVER_H
|
---|