Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/grpc' into grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
whybeyoung committed Apr 23, 2024
2 parents f909f6e + b5cddae commit f7e0d78
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ endif

wrapper:
echo $(PYLIB)
${CC} -Wall -pedantic -Wextra -fPIC -shared -std=c++1y -fvisibility=default -Wno-attributes $(PYINC) -g -O0 -I. -I./include/spdlog/include/ -I./include/ -o libwrapper.so pyWrapper.cpp fswatch.cpp wrapper.cpp -L. -L /opt/conda/envs/loader/lib $(PYLIB) -rdynamic
${CC} -Wall -pedantic -Wextra -fPIC -shared -std=c++1y -fvisibility=default -Wno-unused-variable -Wno-deprecated-declarations -Wno-unused-parameter -Wno-attributes $(PYINC) -g -O0 -I. -I./include/spdlog/include/ -I./include/ -o libwrapper.so pyWrapper.cpp fswatch.cpp wrapper.cpp -L. -L /opt/conda/envs/loader/lib $(PYLIB) -rdynamic
mkdir -p wrapper_lib
cp libwrapper.so ./wrapper_lib

Expand Down
4 changes: 2 additions & 2 deletions fswatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ int main() {
EventHandle e = test;
funs.insert({"IN_MOVE_SELF", test});
ino.InitWatchFile(s, NULL);
printf("pid,%d\n", _pid);
printf("pid,%lu\n", _pid);
int ret = ino.StartWatchThread(funs, _pid);
printf("aftpid,%d\n", _pid);
printf("aftpid,%lu\n", _pid);
ret = pthread_join(_pid, NULL);
printf("%d\n", ret);
return 0;
Expand Down
32 changes: 22 additions & 10 deletions pyWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ py::bytes DataListNode::get_data() {
}

DataListNode *DataListCls::get(std::string key) {
for (int idx = 0; idx < list.size(); idx++) {
for (size_t idx = 0; idx < list.size(); idx++) {
DataListNode *node = &list[idx];
if (strcmp(node->key.c_str(), key.c_str()) == 0) {
return node;
Expand Down Expand Up @@ -203,7 +203,7 @@ void PyWrapper::StartMonitorWrapperClass(std::string wrapperFileAbs) {
FSInotify *ino = new FSInotify();
pthread_t _pid;
std::vector <std::string> s;
printf("starting monitoring %s, pid is: %d\n", wrapperFileAbs.c_str(), _pid);
printf("starting monitoring %s, pid is: %lu\n", wrapperFileAbs.c_str(), _pid);
s.push_back(wrapperFileAbs);
std::map <std::string, EventHandle> funs;

Expand All @@ -212,7 +212,7 @@ void PyWrapper::StartMonitorWrapperClass(std::string wrapperFileAbs) {
ino->InitWatchFile(s, this);
int ret = ino->StartWatchThread(funs, _pid);
if (ret != 0) {
printf("Error starting monitoring %s, pid is: %d\n", wrapperFileAbs.c_str(), _pid);
printf("Error starting monitoring %s, pid is: %lu\n", wrapperFileAbs.c_str(), _pid);
}
}

Expand Down Expand Up @@ -299,7 +299,7 @@ int PyWrapper::wrapperOnceExec(const char *usrTag, std::map <std::string, std::s
return ret;
}
ptr = PyBytes_AsString(itemData.data.ptr());
Py_ssize_t size = PyBytes_GET_SIZE(itemData.data.ptr());
// Py_ssize_t size = PyBytes_GET_SIZE(itemData.data.ptr());
// printf("GetSIze, %d", size);
// printf("item data len: %d", itemData.len);
memcpy(pr, ptr, itemData.len);
Expand Down Expand Up @@ -550,7 +550,7 @@ int PyWrapper::wrapperLoadRes(pDataList p, std::string patch_id) {
item.data = py::bytes((char *) (p->data), len);

item.len = p->len;
char t = static_cast<int>(p->type);
// char t = static_cast<int>(p->type);
item.type = p->type;
item.status = p->status;
spdlog::debug("reqDatatype :{},patch_id:{}", p->type, patch_id);
Expand Down Expand Up @@ -592,7 +592,7 @@ int PyWrapper::wrapperTest() {
std::cout << e.what() << std::endl;
return -1;
}
for (int i = 0; i < l->list.size(); ++i) {
for (size_t i = 0; i < l->list.size(); ++i) {
ResponseData d = l->list[i];
// std::cout << "Response len" << d.len << std::endl;
// std::cout << "response actual data Size " << d.data.length() << std::endl;
Expand All @@ -614,7 +614,7 @@ int callbackMetric(const char *usrTag, const char *meterKey, int count) {
}

int callbackTrace(const char *usrTag, const char *key, const char *value) {
printf("callback Trace: %s, %s, %d\n", usrTag, key, value);
printf("callback Trace: %s, %s, %s\n", usrTag, key, value);
return g_trace_cb(usrTag, key, value);
}

Expand All @@ -625,8 +625,8 @@ int callBack(Response *resp, char *usrTag) {
printf("null cb....\n");
return -1;
}
pDataList headPtr;
pDataList curPtr;
pDataList headPtr = nullptr;
pDataList curPtr = nullptr;
int ret ;
// 先判断python有没有抛出错误. response中的 errorCode
if (resp->errCode != 0) {
Expand Down Expand Up @@ -678,7 +678,19 @@ int callBack(Response *resp, char *usrTag) {
}

int cb_ret = cb_(usrTag, headPtr, 0);
spdlog::debug("call c's callback,usrTag:{} ret {}",usrTag, cb_ret);
while (headPtr != nullptr) {
pDataList ptr = headPtr;
headPtr = headPtr->next;
if (ptr->key) {
free(ptr->key);
}
if (ptr->data) {
free(ptr->data);
}
delete ptr;
}

spdlog::debug("call c's callback, usrTag:{} ret {}",usrTag, cb_ret);
return 0;

}
Expand Down
2 changes: 1 addition & 1 deletion pyWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class ResponseData {
std::string key;
py::bytes data;
unsigned int len;
int status;
int type;
int status;
};

class Response {
Expand Down
10 changes: 5 additions & 5 deletions wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ void initlog(std::string logDir, std::string logpath) {

// Creating a directory
if (mkdir(logDir.c_str(), 0777) == -1) {
printf("log目录创建失败或已存在 %s\n", logpath);
printf("log目录创建失败或已存在 %s\n", logpath.c_str());
} else {
printf("log目录已创建, %s \n", logpath);
printf("log目录已创建, %s \n", logpath.c_str());
}
auto file_logger = spdlog::rotating_logger_mt("mspper", logpath.c_str(), 1048576 * 10, 50);
// Console logger
Expand Down Expand Up @@ -116,7 +116,7 @@ int WrapperAPI wrapperInit(pConfig cfg) {
pyWrapper = new PyWrapper();

setLog(loglvl);
printf("WrapperInit: 当前线程ID: %d \n", gettid());
printf("WrapperInit: 当前线程ID: %ld \n", gettid());
if (global_metric_cb != NULL) {
printf("Metric Custom func set! \n");
pyWrapper->wrapperSetMetricFunc(CTMeterCustom, global_metric_cb);
Expand All @@ -131,7 +131,7 @@ int WrapperAPI wrapperInit(pConfig cfg) {
}

int WrapperAPI wrapperFini() {
printf("WrapperFini: 当前线程ID: %d \n", gettid());
printf("WrapperFini: 当前线程ID: %ld \n", gettid());
pyWrapper->wrapperFini();
return 0;
}
Expand Down Expand Up @@ -272,7 +272,7 @@ int WrapperAPI wrapperRead(const void *handle, pDataList *respData) {
py::gil_scoped_acquire acquire;
int ret = 0;
// 构造响应数据
printf("start read...sid %s\n", handle);
printf("start read...sid %p\n", handle);
ret = pyWrapper->wrapperRead((char *) handle, respData);
if (ret != 0) {
spdlog::get("stderr_console")->error("wrapper read error!");
Expand Down

0 comments on commit f7e0d78

Please sign in to comment.