66 lines
2.0 KiB
C++
66 lines
2.0 KiB
C++
|
#include "XNInterfaceGenServer.h"
|
||
|
#include "GetInterfaceData.h"
|
||
|
#include "GenIDL.h"
|
||
|
#include "FastDDSGen.h"
|
||
|
#include "DDSInterfaceGen.h"
|
||
|
#include "CMakeListsGen.h"
|
||
|
|
||
|
int XNInterfaceGen(const char *tableName, const int tableNameSize, const char *configName,
|
||
|
const int configNameSize, const char *errorMsg, const int errorMsgSize)
|
||
|
{
|
||
|
std::string errorMsgStr;
|
||
|
// 1. 从数据库获取接口数据
|
||
|
AllInterfaceData interfaceData = GetInterfaceData::getInterfaceData(tableName, errorMsgStr);
|
||
|
if (!errorMsgStr.empty()) {
|
||
|
memcpy((void *)errorMsg, errorMsgStr.c_str(), errorMsgSize);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
// 2. 创建构型目录
|
||
|
bool ret = GenIDL::createConfigDirectory(configName);
|
||
|
if (!ret) {
|
||
|
memcpy((void *)errorMsg, "Create config directory failed", errorMsgSize);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
// 3. 生成IDL文件
|
||
|
ret = GenIDL::generateIDL(interfaceData);
|
||
|
if (!ret) {
|
||
|
memcpy((void *)errorMsg, "Generate IDL failed", errorMsgSize);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
// 4. 生成FastDDS代码
|
||
|
ret = FastDDSGen::generateFastDDSCode(GenIDL::getIDLFilePath());
|
||
|
if (!ret) {
|
||
|
memcpy((void *)errorMsg, "Generate FastDDS code failed", errorMsgSize);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
// 5. 生成DDS接口
|
||
|
DDSInterfaceGen ddsInterfaceGen(GenIDL::getIDLFilePath());
|
||
|
ret = ddsInterfaceGen.generateDDSInterface(interfaceData);
|
||
|
if (!ret) {
|
||
|
memcpy((void *)errorMsg, "Generate DDS interface failed", errorMsgSize);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
// 6. 生成CMakeLists.txt文件
|
||
|
ret = CMakeListsGen::generateCMakeLists(interfaceData, GenIDL::getIDLFilePath(), configName);
|
||
|
if (!ret) {
|
||
|
memcpy((void *)errorMsg, "Generate CMakeLists.txt failed", errorMsgSize);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
// 7. 执行CMake编译和安装
|
||
|
std::string idlDirPath = fs::path(GenIDL::getIDLFilePath()).parent_path().string();
|
||
|
std::string buildCmd =
|
||
|
"cd " + idlDirPath + " && mkdir -p build && cd build && cmake .. && make && make install";
|
||
|
int buildRet = system(buildCmd.c_str());
|
||
|
if (buildRet != 0) {
|
||
|
memcpy((void *)errorMsg, "CMake build or install failed", errorMsgSize);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|