areaDetector  3-12-1
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 typedef enum {
17 
18 // Subsystems
19 typedef enum
20 {
35 
37 } sys_t;
38 
39 // Forward declarations
40 typedef struct request request_t;
41 typedef struct response response_t;
42 typedef struct socket socket_t;
43 
44 class RestAPI
45 {
46 private:
47  std::string mHostname;
48  int mPort;
49  struct sockaddr_in mAddress;
50  size_t mNumSockets;
51  socket_t *mSockets;
52  std::string mSysStr[SSCount];
53  eigerAPIVersion_t mAPIVersion;
54 
55  int connect (socket_t *s);
56  int setNonBlock (socket_t *s, bool nonBlock);
57 
58  int doRequest (const request_t *request, response_t *response, int timeout = DEFAULT_TIMEOUT);
59 
60  int getBlob (sys_t sys, const char *name, char **buf, size_t *bufSize, const char *accept);
61 
62 public:
63  static int buildMasterName (const char *pattern, int seqId, char *buf, size_t bufSize);
64  static int buildDataName (int n, const char *pattern, int seqId, char *buf, size_t bufSize);
65 
66  RestAPI (std::string const & hostname, int port=80, size_t numSockets=5);
67 
68  int get (sys_t sys, std::string const & param, std::string & value, int timeout = DEFAULT_TIMEOUT);
69  int put (sys_t sys, std::string const & param, std::string const & value = "", std::string * reply = NULL, int timeout = DEFAULT_TIMEOUT);
70 
71  int initialize (void);
72  int arm (int *sequenceId);
73  int trigger (int timeout, double exposure = 0.0);
74  int disarm (void);
75  int cancel (void);
76  int abort (void);
77  int wait (void);
78  int hvReset (int resetTime);
79  int statusUpdate (void);
81 
82  int getFileSize (const char *filename, size_t *size);
83  int waitFile (const char *filename, double timeout = DEFAULT_TIMEOUT);
84  int getFile (const char *filename, char **buf, size_t *bufSize);
85  int deleteFile (const char *filename);
86 
87  int getMonitorImage (char **buf, size_t *bufSize, size_t timeout = 500);
88 };
89 
90 #endif
static int buildMasterName(const char *pattern, int seqId, char *buf, size_t bufSize)
Definition: restApi.cpp:203
int deleteFile(const char *filename)
Definition: restApi.cpp:474
Definition: restApi.h:30
int cancel(void)
Definition: restApi.cpp:358
Definition: restApi.h:36
int put(sys_t sys, std::string const &param, std::string const &value="", std::string *reply=NULL, int timeout=DEFAULT_TIMEOUT)
Definition: restApi.cpp:686
Definition: restApi.h:34
Definition: restApi.h:44
Definition: restApi.h:22
eigerAPIVersion_t
Definition: restApi.h:13
static int buildDataName(int n, const char *pattern, int seqId, char *buf, size_t bufSize)
Definition: restApi.cpp:219
int waitFile(const char *filename, double timeout=DEFAULT_TIMEOUT)
Definition: restApi.cpp:424
int statusUpdate(void)
Definition: restApi.cpp:381
int hvReset(int resetTime)
Definition: restApi.cpp:373
name
Definition: makeDbAndEdl.py:232
int abort(void)
Definition: restApi.cpp:363
Definition: restApi.h:14
list value
Definition: makeDbAndEdl.py:234
Definition: restApi.cpp:77
Definition: restApi.h:32
Definition: restApi.h:31
int getFile(const char *filename, char **buf, size_t *bufSize)
Definition: restApi.cpp:469
Definition: restApi.h:25
Definition: restApi.h:27
int wait(void)
Definition: restApi.cpp:368
int initialize(void)
Definition: restApi.cpp:292
Definition: restApi.h:28
Definition: restApi.cpp:91
int disarm(void)
Definition: restApi.cpp:353
Definition: restApi.h:26
Definition: restApi.h:29
int get(sys_t sys, std::string const &param, std::string &value, int timeout=DEFAULT_TIMEOUT)
Definition: restApi.cpp:734
int getFileSize(const char *filename, size_t *size)
Definition: restApi.cpp:391
int getMonitorImage(char **buf, size_t *bufSize, size_t timeout=500)
Definition: restApi.cpp:505
#define DEFAULT_TIMEOUT
Definition: restApi.h:8
int arm(int *sequenceId)
Definition: restApi.cpp:297
RestAPI(std::string const &hostname, int port=80, size_t numSockets=5)
Definition: restApi.cpp:237
Definition: restApi.cpp:85
int trigger(int timeout, double exposure=0.0)
Definition: restApi.cpp:328
eigerAPIVersion_t getAPIVersion(void)
Definition: restApi.cpp:386
Definition: NDFileHDF5Layout.h:44
unsigned char * buf
Definition: udp_client_pixirad_single.cpp:70
Definition: restApi.h:15
Definition: restApi.h:21
Definition: restApi.h:24
sys_t
Definition: restApi.h:19
Definition: restApi.h:23
Definition: restApi.h:33