source: BAORadio/libindi/v1.0.1/libs/indibase/basedriver.h @ 503

Last change on this file since 503 was 502, checked in by frichard, 14 years ago

-BAOControl : petite interface permettant de contrôler les antennes via le pilote indi_BAO
-Le pilote indi_BAO utilise désormais indilib v 0.7

File size: 5.6 KB
Line 
1#ifndef INDIBASEDRIVER_H
2#define INDIBASEDRIVER_H
3
4#include <vector>
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 */
24class INDI::BaseDriver
25{
26public:
27    BaseDriver();
28    virtual ~BaseDriver();
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 */
40    enum INDI_TYPE
41    {
42        INDI_NUMBER, /*!< INumberVectorProperty. */
43        INDI_SWITCH, /*!< ISwitchVectorProperty. */
44        INDI_TEXT,   /*!< ITextVectorProperty. */
45        INDI_LIGHT,  /*!< ILightVectorProperty. */
46        INDI_BLOB    /*!< IBLOBVectorProperty. */
47    };
48
49    /** \return Return vector number property given its name */
50    INumberVectorProperty * getNumber(const char *name);
51    /** \return Return vector text property given its name */
52    ITextVectorProperty * getText(const char *name);
53    /** \return Return vector switch property given its name */
54    ISwitchVectorProperty * getSwitch(const char *name);
55    /** \return Return vector light property given its name */
56    ILightVectorProperty * getLight(const char *name);
57    /** \return Return vector BLOB property given its name */
58    IBLOBVectorProperty * getBLOB(const char *name);
59
60    /** \brief Remove a property
61        \param name name of property to be removed
62        \return 0 if successul, -1 otherwise.
63    */
64    int removeProperty(const char *name);
65
66    /** \brief Return a property and its type given its name.
67        \param name of property to be found.
68        \param type of property found.
69        \return If property is found, it is returned. To be used you must use static_cast with given the type of property
70        returned.
71
72        \note This is a low-level function and should not be called directly unless necessary. Use getXXX instead where XXX
73        is the property type (Number, Text, Switch..etc).
74
75    */
76    void * getProperty(const char *name, INDI_TYPE & type);
77
78    /** \brief Build driver properties from a skeleton file.
79        \param filename full path name of the file.
80
81    A skeloton file defines the properties supported by this driver. It is a list of defXXX elements enclosed by @<INDIDriver>@
82 and @</INDIDriver>@ opening and closing tags. After the properties are created, they can be rerieved, manipulated, and defined
83 to other clients.
84
85 \see An example skeleton file can be found under examples/tutorial_four_sk.xml
86
87    */
88    void buildSkeleton(const char *filename);
89
90    /** \return True if the device is connected (CONNECT=ON), False otherwise */
91    bool isConnected();
92    /** \brief Connect or Disconnect a device.
93      \param status If true, the driver will attempt to connect to the device (CONNECT=ON). If false, it will attempt
94to disconnect the device.
95    */
96    virtual void setConnected(bool status);
97
98    /** \brief Set the device name
99      \param dev new device name
100      */
101    void setDeviceName(const char *dev);
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);
109    //** \returns Returns the contents of the driver's message queue. *;
110    const char *message() { return messageQueue.c_str(); }
111
112    /** \brief Set the driver's mediator to receive notification of news devices and updated property values. */
113    void setMediator(INDI::BaseMediator *med) { mediator = med; }
114    /** \returns Get the meditator assigned to this driver */
115    INDI::BaseMediator * getMediator() { return mediator; }
116
117protected:
118
119    /** \brief Build a property given the supplied XML element (defXXX)
120      \param root XML element to parse and build.
121      \param errmsg buffer to store error message in parsing fails.
122
123      \return 0 if parsing is successful, -1 otherwise and errmsg is set */
124    int buildProp(XMLEle *root, char *errmsg);
125
126    /** \brief handle SetXXX commands from client */
127    int setValue (XMLEle *root, char * errmsg);
128    /** \brief handle SetBLOB command from client */
129    int processBLOB(IBLOB *blobEL, XMLEle *ep, char * errmsg);
130    /** \brief Parse and store BLOB in the respective vector */
131    int setBLOB(IBLOBVectorProperty *pp, XMLEle * root, char * errmsg);
132
133    char deviceID[MAXINDINAME];
134
135private:
136
137    typedef struct
138    {
139        INDI_TYPE type;
140        void *p;
141    } pOrder;
142
143    std::vector<INumberVectorProperty *> pNumbers;
144    std::vector<ITextVectorProperty *> pTexts;
145    std::vector<ISwitchVectorProperty *> pSwitches;
146    std::vector<ILightVectorProperty *> pLights;
147    std::vector<IBLOBVectorProperty *> pBlobs;
148
149    LilXML *lp;
150
151    std::vector<pOrder> pAll;
152
153    std::string messageQueue;
154
155    INDI::BaseMediator *mediator;
156
157    friend class INDI::BaseClient;
158    friend class INDI::DefaultDriver;
159
160};
161
162#endif // INDIBASEDRIVER_H
Note: See TracBrowser for help on using the repository browser.