-
Notifications
You must be signed in to change notification settings - Fork 1
/
pyWrapper.h
209 lines (142 loc) · 4.63 KB
/
pyWrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#ifndef __PYWRAPPER__
#define __PYWRAPPER__
#include "pybind11/embed.h"
#include "pybind11/stl.h"
#include <iostream>
#include <thread>
#include <chrono>
#include <sstream>
#include<map>
#include <vector>
#include "spdlog/spdlog.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "aiges/type.h"
#include "fswatch.h"
#include "aiges/wrapper.h"
#define gettid() syscall(SYS_gettid)
#define PYBIND11_DETAILED_ERROR_MESSAGES
typedef struct TestDataList {
char *key; // 数据标识
void *data; // 数据实体
unsigned int len; // 数据长度
struct TestDataList *next; // 链表指针
} *pTestDataList;
namespace py = pybind11;
using namespace std::chrono_literals;
// Session会话结create返回
class SessionCreateResponse {
public:
std::string handle;
int errCode;
};
class ResponseData {
public:
ResponseData(std::string r_key, unsigned int r_len, int r_status, int r_type) : key(r_key), len(r_len),
type(r_type), status(r_status) {
}
ResponseData() {
}
py::bytes get_data() {
return data;
}
void set_data(py::bytes data_) {
data = data_;
}
unsigned int get_len() {
return len;
}
void set_len(unsigned int _len) {
len = _len;
}
std::string key;
py::bytes data;
unsigned int len;
int type;
int status;
};
class Response {
public:
Response();
Response(int errCode);
std::unique_ptr <Response> responseErr(int err);
std::vector <ResponseData> list;
int errCode;
};
// 请求数据节点结构
class DataListNode {
public:
std::string key;
py::bytes data;
unsigned int len;
int status;
int type;
py::bytes get_data();
};
// 请求的数据结构 用以和pybind11 交互
class DataListCls {
public:
std::vector <DataListNode> list;
DataListNode *get(std::string key);
};
class PyWrapper {
public:
PyWrapper();
// PyWrapper(std::map <std::string, std::string> config);
~PyWrapper();
void StartMonitorWrapperClass(std::string wrapperFileAbs);
void ReloadWrapper(); // for dynamic reload wrapper
int wrapperInit(std::map <std::string, std::string> config);
std::string wrapperError(int x);
int wrapperOnceExec(const char *usrTag, std::map <std::string, std::string> params, DataListCls reqData,
pDataList *respData,
std::string sid, wrapperCallback cb, unsigned int psrId);
int wrapperOnceExecAsync(const char *usrTag, std::map <std::string, std::string> params, DataListCls reqData,
std::string sid, wrapperCallback cb, unsigned int psrId);
int wrapperFini();
std::string
wrapperCreate(const char *usrTag, std::map <std::string, std::string> params, wrapperCallback cb, int *errNum,
std::string sid, unsigned int psrId);
int wrapperSetMetricFunc(CtrlType type, wrapperMeterCustom mc);
int wrapperSetTraceFunc(CtrlType type, wrapperTraceLog mc);
int wrapperWrite(char *handle, DataListCls reqData);
int wrapperRead(char *handle, pDataList *respData);
int wrapperDestroy( char * handle);
int wrapperExecFree(const char *usrTag);
int wrapperTest();
int wrapperLoadRes(pDataList perData, std::string resId);
int wrapperUnloadRes(std::string resId);
void setCallBack(wrapperCallback cb);
wrapperMeterCustom metric_cb;
private:
py::module_ _wrapper;
std::string _wrapper_abs;
py::object _obj;
py::object _wrapperInit;
py::object _wrapperFini;
py::object _wrapperOnceExec;
py::object _wrapperOnceExecAsync;
py::object _wrapperError;
py::object _wrapperCreate;
py::object _wrapperDestroy;
py::object _wrapperWrite;
py::object _wrapperRead;
py::object _wrapperLoadRes;
py::object _wrapperUnloadRes;
py::object _wrapperTest;
wrapperCallback cb_;
};
void SetHandleSid(char *handle, std::string sid);
std::string GetHandleSid(char *handle);
void DelHandleSid(char *handle);
int callBack(Response *respData, char *usrTag);
int callbackMetric(const char *usrTag, const char *meterKey, int count);
int callbackTrace(const char *usrTag, const char *key, const char *value);
void SetSidCallBack(wrapperCallback cb, std::string sid);
wrapperCallback GetSidCB(std::string sid);
void DelSidCallback(std::string sid);
void SetSidUsrTag(std::string sid, const char *usrTag);
const char *GetSidUsrTag(std::string sid);
const std::string GetSidByUsrTag(const char *usrTag);
void DelSidUsrTag(std::string sid);
#endif