Jelajahi Sumber

Z991239-351 #comment 将 module 移出到外层目录

gifur 5 tahun lalu
induk
melakukan
59e2e6f51a

+ 2 - 0
CMakeLists.txt

@@ -320,6 +320,7 @@ add_subdirectory(RVCComm)
 add_subdirectory(spbase)
 add_subdirectory(spshell)
 add_subdirectory(sphost)
+add_subdirectory(module)
 
 if(BUILD_TESTING)
 	add_subdirectory(test)
@@ -429,6 +430,7 @@ FOREACH(item ${PACK_COMPONENTS_ALL})
 message(STATUS "compoent: ${item}")
 ENDFOREACH()
 list(REMOVE_ITEM PACK_COMPONENTS_ALL  "headers" "tools" "symbols")
+#个人推断:该功能对 Release 版本才有效?
 set(CPACK_COMPONENTS_ALL ${PACK_COMPONENTS_ALL})
 
 include(CPack)

+ 1 - 1
CMakeSettings.json

@@ -18,7 +18,7 @@
       "configurationType": "Debug",
       "buildRoot": "${projectDir}\\out\\build\\${name}",
       "installRoot": "${projectDir}\\out\\install\\${name}",
-      "cmakeCommandArgs": "-D BUILD_TESTING=ON",
+      "cmakeCommandArgs": "-D BUILD_TESTING=OFF",
       "buildCommandArgs": "",
       "ctestCommandArgs": "-C Debug",
       "inheritEnvironments": [ "msvc_x86" ],

+ 29 - 10
libtoolkit/bus-win.c

@@ -11,6 +11,9 @@
 #include <winpr/pipe.h>
 #include <winpr/synch.h>
 #include <winpr/string.h>
+#include <winpr/wlog.h>
+
+#define TAG TOOLKIT_TAG("bus")
 
 #define BUS_RESULT_DATA		    1				// ==BUS_TYPE_PACKET, callback: callback.on_pkt,  no use
 #define BUS_RESULT_INFO	    	    2				// ==BUS_TYPE_INFO, callback: callback.on_inf
@@ -392,9 +395,9 @@ static int start_read_pkt(bus_endpt_t* endpt, iobuffer_t** p_pkt)
 
 static int read_left_pkt(bus_endpt_t* endpt, iobuffer_t** p_pkt)
 {
-	BOOL ret;
+	BOOL ret = 0;
 	int rc;
-	DWORD dwBytesTransferred;
+	DWORD dwBytesTransferred = 0;
 	iobuffer_t* pkt = NULL;
 
 	if (endpt->type == TYPE_PIPE) {
@@ -404,19 +407,25 @@ static int read_left_pkt(bus_endpt_t* endpt, iobuffer_t** p_pkt)
 		DWORD dwFlags = 0;
 		ret = WSAGetOverlappedResult(endpt->sock_handle, &endpt->rx_overlapped, &dwBytesTransferred, TRUE, &dwFlags);
 	}
+	else {
+		assert(0);
+	}
 
 	if (!ret || dwBytesTransferred == 0) {
-		DWORD dwError = GetLastError();
+		WLog_ERR(TAG, "(WSA)GetOverlappedResult failed: %d", GetLastError());
 		return -1;
 	}
 	if (dwBytesTransferred < 4) {
 		rc = recv_buf(endpt, (char*)&endpt->rx_pending_pkt_len + dwBytesTransferred, 4 - dwBytesTransferred);
-		if (rc < 0)
+		if (rc < 0) {
+			WLog_ERR(TAG, "recv buf failed.");
 			return rc;
+		}
 	}
 	pkt = iobuffer_create(-1, endpt->rx_pending_pkt_len);
 	rc = recv_buf(endpt, iobuffer_data(pkt, 0), endpt->rx_pending_pkt_len);
 	if (rc < 0) {
+		WLog_ERR(TAG, "recv buf failed and destroy buffer.");
 		iobuffer_destroy(pkt);
 		return rc;
 	}
@@ -661,20 +670,23 @@ static int bus_endpt_poll_internal(bus_endpt_t* endpt, int* result, int timeout)
 		}
 		else if (ret == WAIT_OBJECT_0 + 1) {
 			rc = read_left_pkt(endpt, &pkt);
-			if (rc < 0)
+			if (rc < 0) {
+				WLog_ERR(TAG, "read_left_pkt failed: %d", rc);
 				return rc;
-
+			}
+				
 			if (pkt) {
 				rc = append_rx_pkt(endpt, pkt);
 				if (rc < 0) {
 					iobuffer_destroy(pkt);
+					WLog_ERR(TAG, "append_rx_pkt failed: %d", rc);
 					return -1;
 				}
 			}
 		}
 	}
 	else {
-		OutputDebugStringA("pkt has readed\n");
+		WLog_ERR(TAG, "pkt has readed");
 	}
 
 	if (pkt) {
@@ -684,11 +696,12 @@ static int bus_endpt_poll_internal(bus_endpt_t* endpt, int* result, int timeout)
 		iobuffer_restore_read_state(pkt, read_state);
 		*result = to_result(type);
 		if (*result == BUS_RESULT_UNKNOWN) {
-			OutputDebugStringA("bug: unknown pkt type!\n");
+			WLog_ERR(TAG, "bug: unknown pkt type!");
 			return -1;
 		}
 	}
 	else {
+		WLog_ERR(TAG, "not pkt");
 		return -1;
 	}
 
@@ -1014,11 +1027,15 @@ TOOLKIT_API int bus_endpt_post_msg(bus_endpt_t* endpt, int msg, int nparam, int
 	assert(endpt);
 
 	e = MALLOC_T(msg_t);
+	if (e == NULL) {
+		return -1;
+	}
 	e->type = msg;
 	e->nparam = nparam;
 	if (nparam) {
 		e->params = (int*)malloc(sizeof(int) * nparam);
-		memcpy(e->params, params, sizeof(int) * nparam);
+		if(e->params != NULL)
+			memcpy(e->params, params, sizeof(int) * nparam);
 	}
 	else {
 		e->params = NULL;
@@ -1080,7 +1097,6 @@ TOOLKIT_API int bus_endpt_poll(bus_endpt_t* endpt, int timeout)
 	int rc;
 	int epid, type, state;
 	iobuffer_t* pkt = NULL;
-
 	rc = bus_endpt_poll_internal(endpt, &result, timeout);
 	if (rc > 0) {
 		if (result == BUS_RESULT_DATA) {
@@ -1134,6 +1150,9 @@ TOOLKIT_API int bus_endpt_poll(bus_endpt_t* endpt, int timeout)
 			rc = -1;
 		}
 	}
+	else if (rc < 0) {
+		WLog_DBG(TAG, "bus_endpt_poll_internal failed, rc = %d", rc);
+	}
 
 	return rc;
 }

+ 2 - 0
libtoolkit/bus_daemon-win.c

@@ -897,6 +897,8 @@ TOOLKIT_API int bus_daemon_create(int n_url, const char *urls[], int nthread, bu
 	}
 	WLog_DBG(TAG, "thread num: %d", nthread);
 	daemon = MALLOC_T(bus_daemon_t);
+	if (daemon == NULL)
+		return -1;
 	memset(daemon, 0, sizeof(bus_daemon_t));
 	daemon->nthread = nthread;
 	daemon->arr_acceptor = array_make(n_url, sizeof(daemon_accetpor_t*));

+ 15 - 3
libtoolkit/log_periodic.c

@@ -6,10 +6,16 @@
 #include "log.h"
 #include "spinlock.h"
 #include "fileutil.h"
+
+#if defined __linux__
+#include <unistd.h>
+#include <sys/syscall.h>
+#endif
+
 #include <winpr/string.h>
 
 #include <winpr/wlog.h>
-#define TAG TOOLKIT_TAG("log")
+#define TAG TOOLKIT_TAG("log_periodic")
 
 typedef struct periodiclogfactory_t periodiclogfactory_t;
 
@@ -266,8 +272,14 @@ static int periodicfilefactory_record_log(void *self,
 				st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, log_level2str(level));
 			plog->first_record = 0;
 		} else {
-			n = sprintf(tmp, LINE_BREAK_STR "[%02d:%02d:%02d.%03d][%05u][%s] ",
-				st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, GetCurrentThreadId(), log_level2str(level));
+			n = sprintf(tmp, LINE_BREAK_STR "[%02d:%02d:%02d.%03d][%5u][%s] ",
+				st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, 
+#if defined(__linux__)
+				(size_t)syscall(SYS_gettid)
+#else
+				GetCurrentThreadId()
+#endif
+				, log_level2str(level));
 		}
 		_fwrite_nolock(tmp, n, 1, plog->fp);
 		_fwrite_nolock(s, sn, 1, plog->fp);

+ 0 - 0
test/module/CMakeLists.txt → module/CMakeLists.txt


+ 0 - 0
test/module/mod_helloclient/CMakeLists.txt → module/mod_helloclient/CMakeLists.txt


+ 0 - 0
test/module/mod_helloclient/mod_helloclient.cpp → module/mod_helloclient/mod_helloclient.cpp


+ 0 - 0
test/module/mod_helloservice/CMakeLists.txt → module/mod_helloservice/CMakeLists.txt


+ 0 - 0
test/module/mod_helloservice/HelloService_client_g.h → module/mod_helloservice/HelloService_client_g.h


+ 0 - 0
test/module/mod_helloservice/HelloService_def_g.h → module/mod_helloservice/HelloService_def_g.h


+ 0 - 0
test/module/mod_helloservice/HelloService_msg_g.h → module/mod_helloservice/HelloService_msg_g.h


+ 0 - 0
test/module/mod_helloservice/HelloService_server_g.h → module/mod_helloservice/HelloService_server_g.h


+ 0 - 0
test/module/mod_helloservice/mod_helloservice.cpp → module/mod_helloservice/mod_helloservice.cpp


+ 0 - 0
test/module/mod_sample/CMakeLists.txt → module/mod_sample/CMakeLists.txt


+ 0 - 0
test/module/mod_sample/SampleEntity_client_g.h → module/mod_sample/SampleEntity_client_g.h


+ 0 - 0
test/module/mod_sample/SampleEntity_def_g.h → module/mod_sample/SampleEntity_def_g.h


+ 0 - 0
test/module/mod_sample/SampleEntity_msg_g.h → module/mod_sample/SampleEntity_msg_g.h


+ 0 - 0
test/module/mod_sample/SampleEntity_server_g.h → module/mod_sample/SampleEntity_server_g.h


+ 1 - 1
test/module/mod_sample/SampleFSM.cpp → module/mod_sample/SampleFSM.cpp

@@ -19,7 +19,7 @@ CSampleFSM::~CSampleFSM(void)
 ErrorCodeEnum CSampleFSM::OnInit()
 {
 	LOG_FUNCTION();
-
+	//MessageBox(NULL, NULL, NULL, 0);
 	ErrorCodeEnum ec = Error_Unexpect;
 
 	// TODO: user should implement the function!

+ 0 - 0
test/module/mod_sample/SampleFSM.h → module/mod_sample/SampleFSM.h


+ 0 - 0
test/module/mod_sample/mod_SampleEntity.cpp → module/mod_sample/mod_SampleEntity.cpp


+ 0 - 0
test/module/mod_sample/mod_SampleEntity.h → module/mod_sample/mod_SampleEntity.h


+ 0 - 2
spbase/sp_mod.c

@@ -157,8 +157,6 @@ static void mod_entity_process_cmd(threadpool_t *threadpool, void *arg)
 	iobuffer_read(pkt, IOBUF_T_I4, &svc_id, NULL);
 	iobuffer_read(pkt, IOBUF_T_I4, &pkt_type, NULL);
 	iobuffer_read(pkt, IOBUF_T_I4, &pkt_id, NULL);
-	sp_dbg_debug("receive stub address: intptr 0x%016X", (intptr_t)stub);
-	sp_dbg_debug("receive stub address: int 0x%016X", (int)stub);
 	cmd_type = SP_GET_TYPE(pkt_type);
 	sp_dbg_debug("enter mod entity process cmd: %d", cmd_type);
 

+ 2 - 1
sphost/sphost.c

@@ -44,9 +44,10 @@ static void SetEnvPath(const char *mod_name)
 	char *buf;
 	const char *var = "PATH";
 	
-
 	dwSize = GetEnvironmentVariableA(var, NULL, 0);
 	buf = (char*)malloc(dwSize+MAX_PATH*3);
+	if (buf == NULL)
+		return;
 	dwSize = GetEnvironmentVariableA(var, buf, dwSize);
 
 	dwSize = GetCurrentDirectoryA(MAX_PATH, path);

+ 1 - 0
spshell/app.cpp

@@ -269,6 +269,7 @@ int app_init()
 		sp_dbg_error("start bus daemon failed!");
 		return rc;
 	}
+	sp_dbg_info("start bus daemon ok!");
 #endif
 
 	rc = sp_iom_create(env->url, SP_SHELL_MOD_ID, &g_app.iom);

+ 8 - 1
spshell/spshell.cpp

@@ -742,9 +742,11 @@ int main(int argc, char **argv)
 	_CrtSetDebugFillThreshold(0);
 #endif //_WIN32
 
-#ifndef _WIN32
 	SetEnvironmentVariableA("WLOG_APPENDER", "FILE");
+#ifndef _WIN32
 	SetEnvironmentVariableA("WLOG_FILEAPPENDER_OUTPUT_FILE_PATH", "/opt/wlog");
+#else
+	SetEnvironmentVariableA("WLOG_FILEAPPENDER_OUTPUT_FILE_PATH", "C:\\wlog");
 #endif //NOT _WIN32
 
 	sp_dbg_init("SpShell");
@@ -770,7 +772,12 @@ int main(int argc, char **argv)
 
 	if (!IsProcessRunAsAdmin())
 	{
+#ifdef _WIN32
+		MessageBox(NULL, "Need run with Administrator privilege!", "Error", MB_OK);
+#else
 		sp_dbg_fatal("current process need run with administrator or root privilege !!!");
+#endif //_WIN32
+		
 		Sleep(10000);
 		return -201;
 	} else {

+ 1 - 1
test/CMakeLists.txt

@@ -1 +1 @@
-add_subdirectory(module)
+# add_subdirectory(module)

+ 1 - 1
third_party/CMakeLists.txt

@@ -3,4 +3,4 @@ if(BUILD_TESTING)
 	add_subdirectory(gtest)
 endif()
 add_subdirectory(openssl-1.1.1d)
-add_subdirectory(libuv-1.35.0)
+# add_subdirectory(libuv-1.35.0)

+ 1 - 1
winpr/libwinpr/utils/ini.c

@@ -560,7 +560,7 @@ static int IniFile_Load(wIniFile* ini)
 			value = beg;
 
 			if (!IniFile_AddKey(ini, section, name, value, NULL)) {
-				fprintf(stderr, "IniFile_AddKey \"%s\" with %s=%s failed.\n", section, name, value);
+				fprintf(stderr, "IniFile_AddKey \"%s\" with %s=%s failed.\n", section->name, name, value);
 				return -1;
 			}
 		}