From dcefae14f0c23f984511cc10aefa4500bffa9aa6 Mon Sep 17 00:00:00 2001 From: jinyuan Date: Fri, 15 May 2026 09:59:53 +0800 Subject: [PATCH] =?UTF-8?q?Workflow,WFCrystal,WFEngine,WFWidget=20?= =?UTF-8?q?=E9=80=82=E9=85=8Dlinux?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SysUtility/utils/include/TurtleType.h | 2 +- .../SysUtility/utils/include/Utils.h | 2 +- .../WFCrystal/SysUtility/utils/src/Utils.cpp | 5 +- .../SysUtility/utils/src/uTurtleAPI.cpp | 163 ++++++++++++++++++ Workflow/WFCrystal/WFCrystal.pro | 6 +- Workflow/WFEngine/Module/include/Buffer.h | 10 +- Workflow/WFEngine/Module/include/Module.h | 10 +- .../WFEngine/Module/src/ModuleManager.cpp | 8 +- .../ObjectModelBase/src/PaiHtmlProperties.cpp | 2 +- Workflow/WFEngine/WFEngine.pro | 4 +- Workflow/WFWidget/src/WFWidget.pro | 4 +- Workflow/include/pthread.h | 40 +++-- Workflow/include/sched.h | 40 ++++- 13 files changed, 252 insertions(+), 44 deletions(-) create mode 100644 Workflow/WFCrystal/SysUtility/utils/src/uTurtleAPI.cpp diff --git a/Workflow/WFCrystal/SysUtility/utils/include/TurtleType.h b/Workflow/WFCrystal/SysUtility/utils/include/TurtleType.h index 9e80936..4549813 100644 --- a/Workflow/WFCrystal/SysUtility/utils/include/TurtleType.h +++ b/Workflow/WFCrystal/SysUtility/utils/include/TurtleType.h @@ -20,7 +20,7 @@ #define APIPRIVATE #define PASCAL typedef void * LPVOID; -typedef unsigned int HANDLE; +//typedef unsigned int HANDLE; typedef void * (WINAPI *LPTHREAD_START_ROUTINE)( LPVOID lpThreadParameter ); diff --git a/Workflow/WFCrystal/SysUtility/utils/include/Utils.h b/Workflow/WFCrystal/SysUtility/utils/include/Utils.h index fe8f10f..7c4d0da 100644 --- a/Workflow/WFCrystal/SysUtility/utils/include/Utils.h +++ b/Workflow/WFCrystal/SysUtility/utils/include/Utils.h @@ -110,7 +110,7 @@ public: */ static long long StrToLL(const std::string& s) { - return GetTurtleAPI()->StringToLong(s); + return GetTurtleAPI()->StringToLong(s); } /** diff --git a/Workflow/WFCrystal/SysUtility/utils/src/Utils.cpp b/Workflow/WFCrystal/SysUtility/utils/src/Utils.cpp index 6937882..1f5a993 100644 --- a/Workflow/WFCrystal/SysUtility/utils/src/Utils.cpp +++ b/Workflow/WFCrystal/SysUtility/utils/src/Utils.cpp @@ -971,6 +971,8 @@ std::string CUtils::Trim(std::string str) std::string CUtils::GetPaiHome() { + std::string str; + #ifdef WIN32 wchar_t process_name[MAX_PATH] = {}; wchar_t process_name1[MAX_PATH] = {}; @@ -1002,9 +1004,10 @@ std::string CUtils::GetPaiHome() CHAR *pBuffer = new CHAR[nLen + 1]; WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), (int)(wstr.size()), pBuffer, nLen, NULL, NULL); pBuffer[nLen] = '\0'; - std::string str; + str.append(pBuffer); delete[] pBuffer; +#endif return str; } diff --git a/Workflow/WFCrystal/SysUtility/utils/src/uTurtleAPI.cpp b/Workflow/WFCrystal/SysUtility/utils/src/uTurtleAPI.cpp new file mode 100644 index 0000000..9f18001 --- /dev/null +++ b/Workflow/WFCrystal/SysUtility/utils/src/uTurtleAPI.cpp @@ -0,0 +1,163 @@ +#include "uTurtleAPI.h" +#include +#include +#include +#include +#include +#include +#include +#include +using namespace pai::turtle; + + +uTurtleAPI::uTurtleAPI() { + +} + +//uTurtleAPI::~uTurtleAPI() { +// +//} + +void uTurtleAPI::Sleep(unsigned long long time) { + usleep(1000 * time); +} + +void uTurtleAPI::SysCall(const std::string& oper, const std::string& name, + const std::string& param, const std::string& path, int cmd) { + system(oper.c_str()); +} + +unsigned int uTurtleAPI::CreateThread(LPTHREAD_START_ROUTINE pFunction, + void * param) { + pthread_t handle; + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + int ret = pthread_create(&handle, &attr, + (LPTHREAD_START_ROUTINE) pFunction, (void *) param); + pthread_attr_destroy(&attr); + return ret; +} + +bool uTurtleAPI::DeletePath(std::string &path) { + if(remove(path.c_str()) == 0) + return true; + else + return false; +} + +bool uTurtleAPI::CheckPath(std::string& path) { + //TODO + return true; +} + +bool uTurtleAPI::MkDir(std::string &path) { + char const *b = path.c_str(); + int status = mkdir(b, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + if (0 == status) + return true; + else + return false; +} + +bool uTurtleAPI::ScanDir(const std::string &path,std::vector &filelist) { + struct dirent **namelist; + char const *b = path.c_str(); + std::string listFsPath = ""; + int n = scandir(b, &namelist, 0, alphasort); + if(n < 0) + return false; + else { + for(int i=0;id_name; + filelist.push_back(listFsPath); + free(namelist[i]); + } + free(namelist); + return true; + } +} + +bool uTurtleAPI::Readline(FILE *file,std::string &str) { + char *line = NULL; + size_t len = 0; + ssize_t items_read = getline(&line, &len, file); + str = line; + free(line); + return true; +} + +unsigned long long uTurtleAPI::GetSystemTime() { + struct timeval tv; + gettimeofday(&tv, NULL); + unsigned long long t = tv.tv_sec; + t *=1000*1000; + t +=tv.tv_usec; + return t; +} + +int uTurtleAPI::GetTimeOfDay(struct timeval *tv, void *tz) { + int re = gettimeofday(tv, NULL); + return re; +} + +bool uTurtleAPI::GetNSTime(long long &time) { + + timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + time = static_cast(ts.tv_sec) * 1000000000LL + static_cast(ts.tv_nsec); + return true; +} + +long long uTurtleAPI::StringToLong(const std::string &str) { + return std::atoll(str.c_str()); +} + +int uTurtleAPI::SetEnv(std::string &strEnvName,std::string &strEnvValue) { + return setenv(strEnvName.c_str(), strEnvValue.c_str(), 1); +} + +void uTurtleAPI::SetValue(pthread_t& pt, int value){ + pt = value; +} + +bool uTurtleAPI::IsValid(pthread_t& pt){ + return pt>0 ? true : false; +} + +int uTurtleAPI::GetOpt(int argc, char **argv, char *opstring) { + return ::getopt(argc, argv, opstring); +} + +void * uTurtleAPI::OpenLibrary(const std::string &strlibrary) +{ + return dlopen(strlibrary.c_str(), RTLD_LAZY); +} + +long uTurtleAPI::CloseLibrary(void *library) +{ + return dlclose(library); +} +std::string uTurtleAPI::ErrorLibrary() +{ + return dlerror(); +} + +int uTurtleAPI::GetPid() { + return static_cast(getpid()); +} + +int uTurtleAPI::isNAN(double x) +{ + return qIsNaN(x); +} + +int uTurtleAPI::isINF(double x) +{ + return qIsInf(x); +} +std::string uTurtleAPI::GetLibraryFileExt() +{ + return ".so"; +} diff --git a/Workflow/WFCrystal/WFCrystal.pro b/Workflow/WFCrystal/WFCrystal.pro index 3cc872d..5cc6b79 100644 --- a/Workflow/WFCrystal/WFCrystal.pro +++ b/Workflow/WFCrystal/WFCrystal.pro @@ -71,10 +71,12 @@ SOURCES += \ ./SysUtility/utils/src/Utils.cpp \ ./SysUtility/utils/src/PAIConst.cpp \ ./SysUtility/utils/src/Turtle.cpp \ - ./SysUtility/utils/src/wTurtleAPI.cpp \ + ./SysUtility/utils/src/uTurtleAPI.cpp \ ./SysUtility/configuration/src/Configure.cpp -INCLUDEPATH += ../include +win32 { + INCLUDEPATH += ../include +} INCLUDEPATH += ./Crystal/include INCLUDEPATH += ./Plugin/include INCLUDEPATH += ./SysUtility/utils/include diff --git a/Workflow/WFEngine/Module/include/Buffer.h b/Workflow/WFEngine/Module/include/Buffer.h index 57adde1..0e354ef 100644 --- a/Workflow/WFEngine/Module/include/Buffer.h +++ b/Workflow/WFEngine/Module/include/Buffer.h @@ -213,11 +213,11 @@ public: * @param[in] key 元数据关键字 * @return 获取到的元数据信息 */ - template - T GetMetaData(const std::string& key) - { - return this->m_context.Get(key); - }; +// template +// T GetMetaData(const std::string& key) +// { +// return this->m_context.Get(key); +// }; /** * @brief 是否有对应的元数据信息 * @param[in] key 元信息的key diff --git a/Workflow/WFEngine/Module/include/Module.h b/Workflow/WFEngine/Module/include/Module.h index 307e34d..6b73dc2 100644 --- a/Workflow/WFEngine/Module/include/Module.h +++ b/Workflow/WFEngine/Module/include/Module.h @@ -295,11 +295,11 @@ public: * @param[in] port 输入口 * @return 指定输入口传递过来的文件头 */ - template - T GetFileHeader(const int& port) - { - return this->GetInputMetaData(port,WORKLFOWCONTEXT_KEY_DATASETINFO); - }; +// template +// T GetFileHeader(const int& port) +// { +// return this->GetInputMetaData(port,WORKLFOWCONTEXT_KEY_DATASETINFO); +// }; /** * @brief 设置元数据信息到下游模块 * @param[in] key 元数据关键字 diff --git a/Workflow/WFEngine/Module/src/ModuleManager.cpp b/Workflow/WFEngine/Module/src/ModuleManager.cpp index e2a01ea..f7d954f 100644 --- a/Workflow/WFEngine/Module/src/ModuleManager.cpp +++ b/Workflow/WFEngine/Module/src/ModuleManager.cpp @@ -189,14 +189,14 @@ void CModuleManager::Initialize(string jsonPath) bool CModuleManager::LoadModuleByClassName(const std::string moduleClassName) { - char * paiHome = (char*)PAI_HOME.c_str(); //getenv(PAI_HOME.c_str())获取环境变量PAI_HOME +// char * paiHome = (char*)PAI_HOME.c_str(); //getenv(PAI_HOME.c_str())获取环境变量PAI_HOME std::string metaDataPartFileName; // if the class name start with 'C', remove it. if ('C' == moduleClassName.at(0)) metaDataPartFileName = moduleClassName.substr(1,moduleClassName.size()); else metaDataPartFileName = moduleClassName; - string metaDataFilePath = paiHome; + string metaDataFilePath;// = paiHome; metaDataFilePath.append(DERECTORY_SPLIT).append(MODULE_PATH).append(DERECTORY_SPLIT).append(metaDataPartFileName).append(JSON_METADATA_FILE_SUFFIX); if(FindModule(metaDataPartFileName)) @@ -337,8 +337,8 @@ string CModuleManager::GetLibDeployPath() const void CModuleManager::ReLoadAllModules() { - char * pVal = (char*)PAI_HOME.c_str(); //getenv(PAI_HOME.c_str())获取环境变量PAI_HOME - string str = pVal; +// char * pVal = (char*)PAI_HOME.c_str(); //getenv(PAI_HOME.c_str())获取环境变量PAI_HOME + string str;// = pVal; string path = DERECTORY_SPLIT; path.append(MODULE_PATH); str += path; diff --git a/Workflow/WFEngine/ObjectModel/ObjectModelBase/src/PaiHtmlProperties.cpp b/Workflow/WFEngine/ObjectModel/ObjectModelBase/src/PaiHtmlProperties.cpp index 4db43c0..784929e 100644 --- a/Workflow/WFEngine/ObjectModel/ObjectModelBase/src/PaiHtmlProperties.cpp +++ b/Workflow/WFEngine/ObjectModel/ObjectModelBase/src/PaiHtmlProperties.cpp @@ -176,7 +176,7 @@ QString PaiHtmlProperties::GetHtml(const std::vector< std::vector< PropertyItem case pai::ios::property::DATE: { valuve = QDateTime::fromMSecsSinceEpoch( - pai::utils::CUtils::StrToLL(item.GetPropertyValue()) / 1000).toString(LONG_TIME_FORMAT); + pai::utils::CUtils::StrToLL(item.GetPropertyValue()) / 1000).toString(); break; } case pai::ios::property::STRING: diff --git a/Workflow/WFEngine/WFEngine.pro b/Workflow/WFEngine/WFEngine.pro index d3a564d..0ab55c2 100644 --- a/Workflow/WFEngine/WFEngine.pro +++ b/Workflow/WFEngine/WFEngine.pro @@ -87,7 +87,9 @@ SOURCES += \ -INCLUDEPATH += ../include +win32 { + INCLUDEPATH += ../include +} INCLUDEPATH += ./Module/include INCLUDEPATH += ./WorkflowEngine/include INCLUDEPATH += ./Component/WorkflowWidget/include diff --git a/Workflow/WFWidget/src/WFWidget.pro b/Workflow/WFWidget/src/WFWidget.pro index bbbd114..4551f8a 100644 --- a/Workflow/WFWidget/src/WFWidget.pro +++ b/Workflow/WFWidget/src/WFWidget.pro @@ -103,7 +103,9 @@ SOURCES += \ PaiWorkspace.cpp INCLUDEPATH += ../include -INCLUDEPATH += ../../include +win32 { + INCLUDEPATH += ../../include +} INCLUDEPATH += ../../WFCrystal/Crystal/include INCLUDEPATH += ../../WFCrystal/SysUtility/configuration/include INCLUDEPATH += ../../WFCrystal/SysUtility/utils/include diff --git a/Workflow/include/pthread.h b/Workflow/include/pthread.h index 5bccb67..67631b4 100644 --- a/Workflow/include/pthread.h +++ b/Workflow/include/pthread.h @@ -537,9 +537,9 @@ extern "C" #define SEM_VALUE_MAX INT_MAX -#if defined(__GNUC__) && !defined(__declspec) -# error Please upgrade your GNU compiler to one that supports __declspec. -#endif +//#if defined(__GNUC__) && !defined(__declspec) +//# error Please upgrade your GNU compiler to one that supports __declspec. +//#endif /* * When building the library, you should define PTW32_BUILD so that @@ -547,14 +547,29 @@ extern "C" * do NOT define PTW32_BUILD, and then the variables/functions will * be imported correctly. */ -#if !defined(PTW32_STATIC_LIB) -# if defined(PTW32_BUILD) -# define PTW32_DLLPORT __declspec (dllexport) -# else -# define PTW32_DLLPORT __declspec (dllimport) -# endif -#else -# define PTW32_DLLPORT +// 在文件开头,其他宏定义之前添加 +#ifndef PTW32_CDECL + #if defined(_WIN32) || defined(_WIN64) + #define PTW32_CDECL __cdecl + #else + #define PTW32_CDECL + #endif +#endif + +#ifndef PTW32_DLLPORT + #if defined(_WIN32) || defined(_WIN64) + #if defined(PTW32_BUILD) + #define PTW32_DLLPORT __declspec(dllexport) + #else + #define PTW32_DLLPORT __declspec(dllimport) + #endif + #else + #if defined(PTW32_BUILD) + #define PTW32_DLLPORT __attribute__((visibility("default"))) + #else + #define PTW32_DLLPORT + #endif + #endif #endif /* @@ -567,7 +582,6 @@ extern "C" * the DLL and application, then you can probably define this as a null string. * Remember that pthread.h (this file) is used for both the DLL and application builds. */ -#define PTW32_CDECL __cdecl #if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX # include @@ -1176,7 +1190,7 @@ PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t * */ PTW32_DLLPORT int PTW32_CDECL pthread_delay_np (struct timespec * interval); PTW32_DLLPORT int PTW32_CDECL pthread_num_processors_np(void); -PTW32_DLLPORT unsigned __int64 PTW32_CDECL pthread_getunique_np(pthread_t thread); +PTW32_DLLPORT unsigned long long PTW32_CDECL pthread_getunique_np(pthread_t thread); /* * Useful if an application wants to statically link diff --git a/Workflow/include/sched.h b/Workflow/include/sched.h index f36a97a..f73dab4 100644 --- a/Workflow/include/sched.h +++ b/Workflow/include/sched.h @@ -66,8 +66,15 @@ #endif -#if defined(__GNUC__) && !defined(__declspec) -# error Please upgrade your GNU compiler to one that supports __declspec. +//#if defined(__GNUC__) && !defined(__declspec) +//# error Please upgrade your GNU compiler to one that supports __declspec. +//#endif + +// 在文件开头,或其他宏定义之前添加 +#ifdef __linux__ + #define __cdecl + #define __stdcall + #define __fastcall #endif /* @@ -76,14 +83,29 @@ * do NOT define PTW32_BUILD, and then the variables/functions will * be imported correctly. */ -#if !defined(PTW32_STATIC_LIB) -# if defined(PTW32_BUILD) -# define PTW32_DLLPORT __declspec (dllexport) -# else -# define PTW32_DLLPORT __declspec (dllimport) -# endif + +// 定义跨平台的导出/导入宏 +#if defined(_WIN32) || defined(_WIN64) + #if !defined(PTW32_STATIC_LIB) + #if defined(PTW32_BUILD) + #define PTW32_DLLPORT __declspec(dllexport) + #else + #define PTW32_DLLPORT __declspec(dllimport) + #endif + #else + #define PTW32_DLLPORT + #endif #else -# define PTW32_DLLPORT + // Linux/Unix/Mac 使用 GCC 可见性属性 + #if !defined(PTW32_STATIC_LIB) + #if defined(PTW32_BUILD) + #define PTW32_DLLPORT __attribute__((visibility("default"))) + #else + #define PTW32_DLLPORT + #endif + #else + #define PTW32_DLLPORT + #endif #endif /*