Skip to content

Commit 921d9fd

Browse files
committed
fix
1 parent 4b6501b commit 921d9fd

File tree

3 files changed

+33
-47
lines changed

3 files changed

+33
-47
lines changed

pyWrapper.cpp

+20-29
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ PyWrapper::PyWrapper() {
132132
_wrapperTest = _obj.attr("wrapperTestFunc");
133133

134134
py::gil_scoped_release release;
135-
//StartMonitorWrapperClass(_wrapper_abs);
135+
// StartMonitorWrapperClass(_wrapper_abs);
136136

137137
}
138138

@@ -252,7 +252,7 @@ int PyWrapper::wrapperFini() {
252252

253253
int PyWrapper::wrapperOnceExec(const char *usrTag, std::map <std::string, std::string> params, DataListCls reqData,
254254
pDataList *respData, std::string sid, wrapperCallback cb, unsigned int psrId) {
255-
SetSidUsrTag(sid, usrTag);
255+
// SetSidUsrTag(sid, usrTag);
256256
try {
257257
if (cb != nullptr) {
258258
SetSidCallBack(cb, sid);
@@ -353,7 +353,6 @@ int PyWrapper::wrapperOnceExecAsync(const char *usrTag, std::map <std::string, s
353353
py::gil_scoped_acquire acquire;
354354

355355
int ret = 0;
356-
SetSidUsrTag(sid, usrTag);
357356
params["sid"] = sid;
358357
// 执行python exec 推理
359358
py::object r = _wrapperOnceExecAsync(params, reqData, sid, psrId);
@@ -413,12 +412,11 @@ PyWrapper::wrapperCreate(const char *usrTag, std::map <std::string, std::string>
413412
int *errNum, std::string sid, unsigned int psrId) {
414413
SessionCreateResponse *resp;
415414
SetSidCallBack(cb, sid);
416-
SetSidUsrTag(sid, usrTag);
417415

418416
try {
419417
py::gil_scoped_acquire acquire;
420418
// 此段根据python的返回 ,回写 respData
421-
py::object r = _wrapperCreate(params, sid, psrId);
419+
py::object r = _wrapperCreate(params, sid, psrId, usrTag);
422420
resp = r.cast<SessionCreateResponse *>();
423421
*errNum = resp->errCode;
424422
if (*errNum != 0) {
@@ -439,11 +437,11 @@ PyWrapper::wrapperCreate(const char *usrTag, std::map <std::string, std::string>
439437
}
440438

441439
// 上行数据
442-
int PyWrapper::wrapperWrite(char *handle, DataListCls reqData, std::string sid) {
440+
int PyWrapper::wrapperWrite(char *handle, DataListCls reqData) {
443441
try {
444442
int ret = 0;
445443
// 执行python exec 推理
446-
py::object r = _wrapperWrite(handle, reqData, sid);
444+
py::object r = _wrapperWrite(handle, reqData);
447445
ret = r.cast<int>();
448446
return ret;
449447
}
@@ -458,12 +456,12 @@ int PyWrapper::wrapperWrite(char *handle, DataListCls reqData, std::string sid)
458456
}
459457

460458
// 下行数据
461-
int PyWrapper::wrapperRead(char *handle, pDataList *respData, std::string sid) {
459+
int PyWrapper::wrapperRead(char *handle, pDataList *respData) {
462460
try {
463461
Response *resp;
464462
// 执行python exec 推理
465-
py::object r = _wrapperRead(handle, sid);
466-
spdlog::debug("start cast python resp to c++ object, thread_id: {}, sid: {}", gettid(), sid);
463+
py::object r = _wrapperRead(handle);
464+
spdlog::debug("start cast python resp to c++ object, thread_id: {}, handle: {}", gettid(), handle);
467465
resp = r.cast<Response *>();
468466
pDataList headPtr;
469467
pDataList curPtr;
@@ -492,7 +490,7 @@ int PyWrapper::wrapperRead(char *handle, pDataList *respData, std::string sid) {
492490
pr = malloc(itemData.len);
493491
if (pr == nullptr) {
494492
int ret = -1;
495-
spdlog::get("stderr_console")->error("can't malloc memory for data, sid:{}", sid);
493+
spdlog::get("stderr_console")->error("can't malloc memory for data, handle:{}", handle);
496494
return ret;
497495
}
498496
memcpy(pr, (const void *) itemData.data.ptr(), itemData.len);
@@ -507,9 +505,9 @@ int PyWrapper::wrapperRead(char *handle, pDataList *respData, std::string sid) {
507505
curPtr->next = tmpData;
508506
curPtr = tmpData;
509507
}
510-
spdlog::debug("get result,key:{},data:{},len:{},type:{},status:{},sid:{}",
508+
spdlog::debug("get result,key:{},data:{},len:{},type:{},status:{},handle:{}",
511509
tmpData->key, (char *) tmpData->data, tmpData->len, tmpData->type,
512-
tmpData->status, sid);
510+
tmpData->status, handle);
513511
}
514512
*respData = headPtr;
515513
}
@@ -524,20 +522,15 @@ int PyWrapper::wrapperRead(char *handle, pDataList *respData, std::string sid) {
524522
return 0;
525523
}
526524

527-
int PyWrapper::wrapperDestroy(std::string sid, char * handle) {
528-
DelSidCallback(sid);
529-
DelSidUsrTag(sid);
525+
int PyWrapper::wrapperDestroy(char * handle) {
530526
py::object r = _wrapperDestroy(handle);
531527
// 此段根据python的返回 ,回写 respData
532-
spdlog::info("Destroy .. thread_id: {}, sid: {}", gettid(), sid);
528+
spdlog::info("Destroy .. thread_id: {}, handle: {}", gettid(), handle);
533529
int ret = r.cast<int>();
534530
return ret;
535531
}
536532

537533
int PyWrapper::wrapperExecFree(const char *usrTag) {
538-
std::string sid = GetSidByUsrTag(usrTag);
539-
if (sid != "")
540-
DelSidUsrTag(sid);
541534
return 0;
542535
}
543536

@@ -626,15 +619,13 @@ int callbackTrace(const char *usrTag, const char *key, const char *value) {
626619
return g_trace_cb(usrTag, key, value);
627620
}
628621

629-
int callBack(Response *resp, std::string sid) {
622+
int callBack(Response *resp, char *usrTag) {
630623
wrapperCallback cb_;
631-
cb_ = GetSidCB(sid);
624+
cb_ = g_resp_cb;
632625
if (cb_ == NULL) {
633626
printf("null cb....\n");
634627
return -1;
635628
}
636-
const char *usrTag = GetSidUsrTag(sid);
637-
638629
pDataList headPtr;
639630
pDataList curPtr;
640631
int ret ;
@@ -664,7 +655,7 @@ int callBack(Response *resp, std::string sid) {
664655
pr = malloc(itemData.len);
665656
if (pr == nullptr) {
666657
int ret = -1;
667-
spdlog::get("stderr_console")->error("can't malloc memory for data, sid:{}", sid);
658+
spdlog::get("stderr_console")->error("can't malloc memory for data, usrTag:{}", usrTag);
668659
return ret;
669660
}
670661
ptr = PyBytes_AsString(itemData.data.ptr());
@@ -682,13 +673,13 @@ int callBack(Response *resp, std::string sid) {
682673
curPtr->next = tmpData;
683674
curPtr = tmpData;
684675
}
685-
spdlog::debug("callback result,key:{},data:{},len:{},type:{},status:{},sid:{}",
676+
spdlog::debug("callback result,key:{},data:{},len:{},type:{},status:{},usrTag:{}",
686677
tmpData->key, (char *) tmpData->data, tmpData->len, tmpData->type,
687-
tmpData->status, sid);
678+
tmpData->status, usrTag);
688679
}
689680

690-
cb_(usrTag, headPtr, 0);
691-
spdlog::debug("call c's callback ok");
681+
int cb_ret = cb_(usrTag, headPtr, 0);
682+
spdlog::debug("call c's callback,usrTag:{} ret {}",usrTag, cb_ret);
692683
return 0;
693684

694685
}

pyWrapper.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ class PyWrapper {
138138

139139
int wrapperSetTraceFunc(CtrlType type, wrapperTraceLog mc);
140140

141-
int wrapperWrite(char *handle, DataListCls reqData, std::string sid);
141+
int wrapperWrite(char *handle, DataListCls reqData);
142142

143-
int wrapperRead(char *handle, pDataList *respData, std::string sid);
143+
int wrapperRead(char *handle, pDataList *respData);
144144

145-
int wrapperDestroy(std::string sid, char * handle);
145+
int wrapperDestroy( char * handle);
146146

147147
int wrapperExecFree(const char *usrTag);
148148

@@ -186,7 +186,7 @@ std::string GetHandleSid(char *handle);
186186
void DelHandleSid(char *handle);
187187

188188

189-
int callBack(Response *respData, std::string);
189+
int callBack(Response *respData, char *usrTag);
190190

191191
int callbackMetric(const char *usrTag, const char *meterKey, int count);
192192

wrapper.cpp

+9-14
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ WrapperAPI wrapperCreate(const char *usrTag, pParamList params, wrapperCallback
224224
spdlog::debug("wrapper create Error, errNum:{}, sid:{}", *errNum, sid);
225225
return NULL;
226226
}
227-
SetHandleSid(handlePtr, sid);
227+
// SetHandleSid(handlePtr, sid);
228228
return static_cast<const void *>(handlePtr);
229229

230230
}
@@ -236,8 +236,8 @@ int WrapperAPI wrapperWrite(const void *handle, pDataList reqData) {
236236
for (pDataList tmpDataPtr = reqData; tmpDataPtr != NULL; tmpDataPtr = tmpDataPtr->next) {
237237
dataNum++;
238238
}
239-
std::string sid = GetHandleSid((char *) handle);
240-
spdlog::debug("call wrapper wrapperWrite: building req data, data num:{},sid:{}", dataNum, sid);
239+
// std::string sid = GetHandleSid((char *) handle);
240+
spdlog::debug("call wrapper wrapperWrite: building req data, data num:{},hanlde:{}", dataNum, handle);
241241
py::gil_scoped_acquire acquire;
242242

243243
DataListCls req;
@@ -254,13 +254,13 @@ int WrapperAPI wrapperWrite(const void *handle, pDataList reqData) {
254254
char t = static_cast<int>(p->type);
255255
item.type = p->type;
256256
item.status = p->status;
257-
spdlog::debug("reqDatatype :{},sid:{}", p->type, sid);
257+
spdlog::debug("reqDatatype :{},wrapper handle:{}", p->type, handle);
258258
req.list.push_back(item);
259259
p = p->next;
260260
}
261261
}
262262
// 构造响应数据
263-
ret = pyWrapper->wrapperWrite((char *) handle, req, sid);
263+
ret = pyWrapper->wrapperWrite((char *) handle, req);
264264
if (ret != 0) {
265265
spdlog::get("stderr_console")->error("wrapper write error!");
266266
}
@@ -271,10 +271,9 @@ int WrapperAPI wrapperWrite(const void *handle, pDataList reqData) {
271271
int WrapperAPI wrapperRead(const void *handle, pDataList *respData) {
272272
py::gil_scoped_acquire acquire;
273273
int ret = 0;
274-
std::string sid = GetHandleSid((char *) handle);
275274
// 构造响应数据
276-
printf("start read...sid %s\n", sid.c_str());
277-
ret = pyWrapper->wrapperRead((char *) handle, respData, sid);
275+
printf("start read...sid %s\n", handle);
276+
ret = pyWrapper->wrapperRead((char *) handle, respData);
278277
if (ret != 0) {
279278
spdlog::get("stderr_console")->error("wrapper read error!");
280279
}
@@ -286,8 +285,7 @@ int WrapperAPI wrapperRead(const void *handle, pDataList *respData) {
286285
int WrapperAPI wrapperDestroy(const void *handle) {
287286
int ret = 0;
288287
py::gil_scoped_acquire acquire;
289-
std::string sid = GetHandleSid((char *) handle);
290-
ret = pyWrapper->wrapperDestroy(sid, (char *) handle);
288+
ret = pyWrapper->wrapperDestroy( (char *) handle);
291289
if (ret != 0) {
292290
spdlog::get("stderr_console")->error("wrapper destroy error!");
293291
}
@@ -417,10 +415,7 @@ int WrapperAPI wrapperExecFree(const char *usrTag, pDataList *respData) {
417415
ptr = tmp;
418416
}
419417
}
420-
std::string sid = GetSidByUsrTag(usrTag);
421-
if (sid != "") {
422-
DelSidUsrTag(sid);
423-
}
418+
424419
// 构造响应数据
425420
int ret = pyWrapper->wrapperExecFree(usrTag);
426421
if (ret != 0) {

0 commit comments

Comments
 (0)