areaDetector  3-13
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 {
15  API_1_8_0
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
Definition: restApi.h:45
int deleteFile(const char *filename)
Definition: restApi.cpp:474
int wait(void)
Definition: restApi.cpp:368
int getFileSize(const char *filename, size_t *size)
Definition: restApi.cpp:391
int get(sys_t sys, std::string const &param, std::string &value, int timeout=DEFAULT_TIMEOUT)
Definition: restApi.cpp:734
int trigger(int timeout, double exposure=0.0)
Definition: restApi.cpp:328
eigerAPIVersion_t getAPIVersion(void)
Definition: restApi.cpp:386
int hvReset(int resetTime)
Definition: restApi.cpp:373
int disarm(void)
Definition: restApi.cpp:353
RestAPI(std::string const &hostname, int port=80, size_t numSockets=5)
Definition: restApi.cpp:237
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
static int buildMasterName(const char *pattern, int seqId, char *buf, size_t bufSize)
Definition: restApi.cpp:203
int initialize(void)
Definition: restApi.cpp:292
int waitFile(const char *filename, double timeout=DEFAULT_TIMEOUT)
Definition: restApi.cpp:424
int getMonitorImage(char **buf, size_t *bufSize, size_t timeout=500)
Definition: restApi.cpp:505
int cancel(void)
Definition: restApi.cpp:358
static int buildDataName(int n, const char *pattern, int seqId, char *buf, size_t bufSize)
Definition: restApi.cpp:219
int getFile(const char *filename, char **buf, size_t *bufSize)
Definition: restApi.cpp:469
int abort(void)
Definition: restApi.cpp:363
int arm(int *sequenceId)
Definition: restApi.cpp:297
int statusUpdate(void)
Definition: restApi.cpp:381
@ string
Definition: NDFileHDF5Layout.h:44
name
Definition: makeDbAndEdl.py:232
list value
Definition: makeDbAndEdl.py:234
sys_t
Definition: restApi.h:20
@ SSDetConfig
Definition: restApi.h:22
@ SSMonConfig
Definition: restApi.h:29
@ SSMonStatus
Definition: restApi.h:30
@ SSSysCommand
Definition: restApi.h:34
@ SSFWCommand
Definition: restApi.h:26
@ SSFWStatus
Definition: restApi.h:25
@ SSCommand
Definition: restApi.h:27
@ SSCount
Definition: restApi.h:36
@ SSData
Definition: restApi.h:28
@ SSStreamStatus
Definition: restApi.h:33
@ SSFWConfig
Definition: restApi.h:24
@ SSAPIVersion
Definition: restApi.h:21
@ SSDetStatus
Definition: restApi.h:23
@ SSMonImages
Definition: restApi.h:31
@ SSStreamConfig
Definition: restApi.h:32
#define DEFAULT_TIMEOUT
Definition: restApi.h:8
eigerAPIVersion_t
Definition: restApi.h:13
@ API_1_6_0
Definition: restApi.h:14
@ API_1_8_0
Definition: restApi.h:15
Definition: restApi.cpp:86
Definition: restApi.cpp:92
Definition: restApi.cpp:78
unsigned char * buf
Definition: udp_client_pixirad_single.cpp:70