Instrument Neutral Distributed Interface INDI  1.4.1
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 <pthread.h>
27 
28 #include "indiapi.h"
29 #include "indidevapi.h"
30 #include "indibase.h"
31 
32 #define MAXRBUF 2048
33 
34 using namespace std;
35 
56 {
57 
58 public:
59  BaseClient();
60  virtual ~BaseClient();
61 
66  void setServer(const char * hostname, unsigned int port);
67 
75  void watchDevice(const char * deviceName);
76 
77 
83  bool connectServer();
84 
90  bool disconnectServer();
91 
95  void connectDevice(const char *deviceName);
96 
100  void disconnectDevice(const char *deviceName);
101 
105  INDI::BaseDevice * getDevice(const char * deviceName);
106 
109  const vector<INDI::BaseDevice *> & getDevices() const { return cDevices; }
110 
127  void setBLOBMode(BLOBHandling blobH, const char *dev, const char *prop = NULL);
128 
135  BLOBHandling getBLOBMode(const char *dev, const char *prop = NULL);
136 
137  // Update
138  static void * listenHelper(void *context);
139 
140  const char * getHost() { return cServer.c_str();}
141  int getPort() { return cPort; }
142 
144  void sendNewText (ITextVectorProperty *pp);
146  void sendNewText (const char * deviceName, const char * propertyName, const char* elementName, const char *text);
148  void sendNewNumber (INumberVectorProperty *pp);
150  void sendNewNumber (const char * deviceName, const char *propertyName, const char* elementName, double value);
152  void sendNewSwitch (ISwitchVectorProperty *pp);
154  void sendNewSwitch (const char * deviceName, const char *propertyName, const char *elementName);
155 
157  void startBlob( const char *devName, const char *propName, const char *timestamp);
159  void sendOneBlob( const char *blobName, unsigned int blobSize, const char *blobFormat, void * blobBuffer);
161  void finishBlob();
162 
168  void setVerbose(bool enable) { verbose = enable; }
169 
174  bool isVerbose() const { return verbose; }
175 
181  void setConnectionTimeout(uint32_t seconds, uint32_t microseconds) { timeout_sec = seconds; timeout_us = microseconds;}
182 
183 protected:
184 
186  int dispatchCommand(XMLEle *root, char* errmsg);
187 
189  int deleteDevice( const char * devName, char * errmsg );
190 
192  int delPropertyCmd (XMLEle *root, char * errmsg);
193 
195  INDI::BaseDevice * findDev( const char * devName, char * errmsg);
197  INDI::BaseDevice * addDevice (XMLEle *dep, char * errmsg);
199  INDI::BaseDevice * findDev (XMLEle *root, int create, char * errmsg);
200 
202  int messageCmd (XMLEle *root, char * errmsg);
203 
204 private:
205 
206  typedef struct
207  {
208  string device;
209  string property;
210  BLOBHandling blobMode;
211  } BLOBMode;
212 
213  BLOBMode *findBLOBMode(string device, string property);
214 
220  void setDriverConnection(bool status, const char *deviceName);
221 
225  void clear();
226 
227  pthread_t listen_thread;
228 
229  FILE *svrwfp; /* FILE * to talk to server */
230  int sockfd;
231 
232  int m_receiveFd;
233  int m_sendFd;
234 
235  // Listen to INDI server and process incoming messages
236  void listenINDI();
237 
238  vector<INDI::BaseDevice *> cDevices;
239  vector<string> cDeviceNames;
240  vector<BLOBMode*> blobModes;
241 
242  string cServer;
243  unsigned int cPort;
244  bool sConnected;
245  bool verbose;
246 
247  // Parse & FILE buffers for IO
248 
249  LilXML *lillp; /* XML parser context */
250  uint32_t timeout_sec, timeout_us;
251 
252 
253 };
254 
255 #endif // INDIBASECLIENT_H
void setVerbose(bool enable)
setVerbose Set verbose mode
Definition: baseclient.h:168
bool isVerbose() const
isVerbose Is client in verbose mode?
Definition: baseclient.h:174
Class to provide basic INDI device functionality.
Definition: basedevice.h:44
Switch vector property descriptor.
Definition: indiapi.h:304
const char * timestamp()
Create an ISO 8601 formatted time stamp. The format is YYYY-MM-DDTHH:MM:SS.
Definition: indicom.c:256
BLOBHandling
How drivers handle BLOBs incoming from snooping drivers.
Definition: indidevapi.h:294
Constants and Data structure definitions for the interface to the reference INDI C API implementation...
void setConnectionTimeout(uint32_t seconds, uint32_t microseconds)
setConnectionTimeout Set connection timeout. By default it is 3 seconds.
Definition: baseclient.h:181
Number vector property descriptor.
Definition: indiapi.h:265
Interface to the reference INDI C API device implementation on the Device Driver side.
const vector< INDI::BaseDevice * > & getDevices() const
Definition: baseclient.h:109
Text vector property descriptor.
Definition: indiapi.h:209
Class to provide basic client functionality.
Definition: baseclient.h:55
Meditates event notification as generated by driver and passed to clients.
Definition: indibase.h:74