areaDetector  3-5-0
EPICS areaDetector framework
restApi.h
Go to the documentation of this file.
1 #ifndef REST_API_H
2 #define REST_API_H
3 
4 #include <string>
5 #include <epicsMutex.h>
6 #include <osiSock.h>
7 
8 #define DEFAULT_TIMEOUT 20 // seconds
9 
10 #define MAX_CHANGED_PARAMS 32
11 #define MAX_PARAM_NAME 64
12 
13 // Subsystems
14 typedef enum
15 {
30 
32 } sys_t;
33 
34 // Forward declarations
35 typedef struct request request_t;
36 typedef struct response response_t;
37 typedef struct socket socket_t;
38 
39 class RestAPI
40 {
41 private:
42  std::string mHostname;
43  int mPort;
44  struct sockaddr_in mAddress;
45  size_t mNumSockets;
46  socket_t *mSockets;
47 
48  int connect (socket_t *s);
49  int setNonBlock (socket_t *s, bool nonBlock);
50 
51  int doRequest (const request_t *request, response_t *response, int timeout = DEFAULT_TIMEOUT);
52 
53  int getBlob (sys_t sys, const char *name, char **buf, size_t *bufSize, const char *accept);
54 
55 public:
56  static const char *sysStr [SSCount];
57 
58  static int buildMasterName (const char *pattern, int seqId, char *buf, size_t bufSize);
59  static int buildDataName (int n, const char *pattern, int seqId, char *buf, size_t bufSize);
60 
61  RestAPI (std::string const & hostname, int port = 80, size_t numSockets=5);
62 
63  int get (sys_t sys, std::string const & param, std::string & value, int timeout = DEFAULT_TIMEOUT);
64  int put (sys_t sys, std::string const & param, std::string const & value = "", std::string * reply = NULL, int timeout = DEFAULT_TIMEOUT);
65 
66  int initialize (void);
67  int arm (int *sequenceId);
68  int trigger (int timeout, double exposure = 0.0);
69  int disarm (void);
70  int cancel (void);
71  int abort (void);
72  int wait (void);
73  int statusUpdate (void);
74 
75  int getFileSize (const char *filename, size_t *size);
76  int waitFile (const char *filename, double timeout = DEFAULT_TIMEOUT);
77  int getFile (const char *filename, char **buf, size_t *bufSize);
78  int deleteFile (const char *filename);
79 
80  int getMonitorImage (char **buf, size_t *bufSize, size_t timeout = 500);
81 };
82 
83 #endif
static int buildMasterName(const char *pattern, int seqId, char *buf, size_t bufSize)
Definition: restApi.cpp:222
int deleteFile(const char *filename)
Definition: restApi.cpp:445
Definition: restApi.h:25
int cancel(void)
Definition: restApi.cpp:342
Definition: restApi.h:31
int put(sys_t sys, std::string const &param, std::string const &value="", std::string *reply=NULL, int timeout=DEFAULT_TIMEOUT)
Definition: restApi.cpp:657
Definition: restApi.h:29
Definition: restApi.h:39
Definition: restApi.h:17
static int buildDataName(int n, const char *pattern, int seqId, char *buf, size_t bufSize)
Definition: restApi.cpp:238
int waitFile(const char *filename, double timeout=DEFAULT_TIMEOUT)
Definition: restApi.cpp:395
int statusUpdate(void)
Definition: restApi.cpp:357
name
Definition: makeDbAndEdl.py:232
int abort(void)
Definition: restApi.cpp:347
list value
Definition: makeDbAndEdl.py:234
Definition: restApi.cpp:78
Definition: restApi.h:27
Definition: restApi.h:26
int getFile(const char *filename, char **buf, size_t *bufSize)
Definition: restApi.cpp:440
Definition: restApi.h:20
static const char * sysStr[SSCount]
Definition: restApi.h:56
Definition: restApi.h:22
int wait(void)
Definition: restApi.cpp:352
int initialize(void)
Definition: restApi.cpp:276
Definition: restApi.h:23
Definition: restApi.cpp:92
int disarm(void)
Definition: restApi.cpp:337
Definition: restApi.h:21
Definition: restApi.h:24
int get(sys_t sys, std::string const &param, std::string &value, int timeout=DEFAULT_TIMEOUT)
Definition: restApi.cpp:705
int getFileSize(const char *filename, size_t *size)
Definition: restApi.cpp:362
int getMonitorImage(char **buf, size_t *bufSize, size_t timeout=500)
Definition: restApi.cpp:476
#define DEFAULT_TIMEOUT
Definition: restApi.h:8
int arm(int *sequenceId)
Definition: restApi.cpp:281
RestAPI(std::string const &hostname, int port=80, size_t numSockets=5)
Definition: restApi.cpp:256
Definition: restApi.cpp:86
int trigger(int timeout, double exposure=0.0)
Definition: restApi.cpp:312
Definition: NDFileHDF5Layout.h:42
unsigned char * buf
Definition: udp_client_pixirad_single.cpp:70
Definition: restApi.h:16
Definition: restApi.h:19
sys_t
Definition: restApi.h:14
Definition: restApi.h:18
Definition: restApi.h:28