Instrument Neutral Distributed Interface INDI  0.9.6
baseclient.h
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 INDIBASECLIENT_H
20 #define INDIBASECLIENT_H
21 
22 #include <vector>
23 #include <map>
24 #include <string>
25 
26 #include "indiapi.h"
27 #include "indidevapi.h"
28 #include "indibase.h"
29 
30 #define MAXRBUF 2048
31 
32 using namespace std;
33 
34 
35 
53 {
54 public:
55  enum { INDI_DEVICE_NOT_FOUND=-1, INDI_PROPERTY_INVALID=-2, INDI_PROPERTY_DUPLICATED = -3, INDI_DISPATCH_ERROR=-4 };
56  //typedef boost::shared_ptr<INDI::BaseDevice> devicePtr;
57 
58  BaseClient();
59  virtual ~BaseClient();
60 
65  void setServer(const char * hostname, unsigned int port);
66 
74  void watchDevice(const char * deviceName);
75 
76 
82  bool connectServer();
83 
89  bool disconnectServer();
90 
94  void connectDevice(const char *deviceName);
95 
99  void disconnectDevice(const char *deviceName);
100 
104  INDI::BaseDevice * getDevice(const char * deviceName);
105 
108  const vector<INDI::BaseDevice *> & getDevices() const { return cDevices; }
109 
127  void setBLOBMode(BLOBHandling blobH, const char *dev, const char *prop = NULL);
128 
129  // Update
130  static void * listenHelper(void *context);
131 
132  const char * getHost() { return cServer.c_str();}
133  int getPort() { return cPort; }
134 
136  void sendNewText (ITextVectorProperty *pp);
138  void sendNewText (const char * deviceName, const char * propertyName, const char* elementName, const char *text);
140  void sendNewNumber (INumberVectorProperty *pp);
142  void sendNewNumber (const char * deviceName, const char *propertyName, const char* elementName, double value);
144  void sendNewSwitch (ISwitchVectorProperty *pp);
146  void sendNewSwitch (const char * deviceName, const char *propertyName, const char *elementName);
147 
149  void startBlob( const char *devName, const char *propName, const char *timestamp);
151  void sendOneBlob( const char *blobName, unsigned int blobSize, const char *blobFormat, void * blobBuffer);
153  void finishBlob();
154 
155 protected:
156 
158  int dispatchCommand(XMLEle *root, char* errmsg);
159 
161  int removeDevice( const char * devName, char * errmsg );
162 
164  int delPropertyCmd (XMLEle *root, char * errmsg);
165 
167  INDI::BaseDevice * findDev( const char * devName, char * errmsg);
169  INDI::BaseDevice * addDevice (XMLEle *dep, char * errmsg);
171  INDI::BaseDevice * findDev (XMLEle *root, int create, char * errmsg);
172 
174  int messageCmd (XMLEle *root, char * errmsg);
175 
176 
177 private:
178 
184  void setDriverConnection(bool status, const char *deviceName);
185 
186  // Listen to INDI server and process incoming messages
187  void listenINDI();
188 
189  // Thread for listenINDI()
190  pthread_t listen_thread;
191 
192  vector<INDI::BaseDevice *> cDevices;
193  vector<string> cDeviceNames;
194 
195  string cServer;
196  unsigned int cPort;
197  bool sConnected;
198 
199  // Parse & FILE buffers for IO
200  int sockfd;
201  LilXML *lillp; /* XML parser context */
202  FILE *svrwfp; /* FILE * to talk to server */
203 
204  int m_receiveFd;
205  int m_sendFd;
206 
207 };
208 
209 #endif // INDIBASECLIENT_H