Instrument Neutral Distributed Interface INDI  0.9.9
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 
36 
37 
55 {
56 public:
57  enum { INDI_DEVICE_NOT_FOUND=-1, INDI_PROPERTY_INVALID=-2, INDI_PROPERTY_DUPLICATED = -3, INDI_DISPATCH_ERROR=-4 };
58  //typedef boost::shared_ptr<INDI::BaseDevice> devicePtr;
59 
60  BaseClient();
61  virtual ~BaseClient();
62 
67  void setServer(const char * hostname, unsigned int port);
68 
76  void watchDevice(const char * deviceName);
77 
78 
84  bool connectServer();
85 
91  bool disconnectServer();
92 
96  void connectDevice(const char *deviceName);
97 
101  void disconnectDevice(const char *deviceName);
102 
106  INDI::BaseDevice * getDevice(const char * deviceName);
107 
110  const vector<INDI::BaseDevice *> & getDevices() const { return cDevices; }
111 
129  void setBLOBMode(BLOBHandling blobH, const char *dev, const char *prop = NULL);
130 
131  // Update
132  static void * listenHelper(void *context);
133 
134  const char * getHost() { return cServer.c_str();}
135  int getPort() { return cPort; }
136 
138  void sendNewText (ITextVectorProperty *pp);
140  void sendNewText (const char * deviceName, const char * propertyName, const char* elementName, const char *text);
142  void sendNewNumber (INumberVectorProperty *pp);
144  void sendNewNumber (const char * deviceName, const char *propertyName, const char* elementName, double value);
146  void sendNewSwitch (ISwitchVectorProperty *pp);
148  void sendNewSwitch (const char * deviceName, const char *propertyName, const char *elementName);
149 
151  void startBlob( const char *devName, const char *propName, const char *timestamp);
153  void sendOneBlob( const char *blobName, unsigned int blobSize, const char *blobFormat, void * blobBuffer);
155  void finishBlob();
156 
157 protected:
158 
160  int dispatchCommand(XMLEle *root, char* errmsg);
161 
163  int removeDevice( const char * devName, char * errmsg );
164 
166  int delPropertyCmd (XMLEle *root, char * errmsg);
167 
169  INDI::BaseDevice * findDev( const char * devName, char * errmsg);
171  INDI::BaseDevice * addDevice (XMLEle *dep, char * errmsg);
173  INDI::BaseDevice * findDev (XMLEle *root, int create, char * errmsg);
174 
176  int messageCmd (XMLEle *root, char * errmsg);
177 
178 
179 private:
180 
186  void setDriverConnection(bool status, const char *deviceName);
187 
188  // Listen to INDI server and process incoming messages
189  void listenINDI();
190 
191  // Thread for listenINDI()
192  pthread_t listen_thread;
193 
194  vector<INDI::BaseDevice *> cDevices;
195  vector<string> cDeviceNames;
196 
197  string cServer;
198  unsigned int cPort;
199  bool sConnected;
200 
201  // Parse & FILE buffers for IO
202  int sockfd;
203  LilXML *lillp; /* XML parser context */
204  FILE *svrwfp; /* FILE * to talk to server */
205 
206  int m_receiveFd;
207  int m_sendFd;
208 
209 };
210 
211 #endif // INDIBASECLIENT_H
Class to provide basic INDI device functionality.
Definition: basedevice.h:45
Switch vector property descriptor.
Definition: indiapi.h:290
const char * timestamp()
Create an ISO 8601 formatted time stamp. The format is YYYY-MM-DDTHH:MM:SS.
Definition: indicom.c:236
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...
Number vector property descriptor.
Definition: indiapi.h:251
Interface to the reference INDI C API device implementation on the Device Driver side.
const vector< INDI::BaseDevice * > & getDevices() const
Definition: baseclient.h:110
Text vector property descriptor.
Definition: indiapi.h:195
Class to provide basic client functionality.
Definition: baseclient.h:54
Meditates event notification as generated by driver and passed to clients.
Definition: indibase.h:70