Browse Source

RCC引入编译通过

master
hejl 2 months ago
parent
commit
305a6be616
  1. 50
      uft_dev_server/CMakeLists.txt
  2. 4
      uft_dev_server/cmd.txt
  3. 3
      uft_dev_server/src/controllers/ApiController.cpp
  4. 9
      uft_dev_server/src/controllers/HelloHandler_v1.cpp
  5. 21
      uft_dev_server/src/controllers/HelloHandler_v1.h
  6. 64
      uft_dev_server/src/controllers/HelloWorldController.cpp
  7. 28
      uft_dev_server/src/controllers/HelloWorldController.h
  8. 65
      uft_dev_server/src/controllers/StdioLogSystem.cpp
  9. 44
      uft_dev_server/src/controllers/StdioLogSystem.h
  10. 31
      uft_dev_server/src/main.cpp

50
uft_dev_server/CMakeLists.txt

@ -1,53 +1,63 @@ @@ -1,53 +1,63 @@
cmake_minimum_required(VERSION 3.12)
project(UftDevServer)
# vcpkg
set(CMAKE_TOOLCHAIN_FILE "D:/aigc/vcpkg/scripts/buildsystems/vcpkg.cmake")
#
if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
# vcpkg
set(CMAKE_TOOLCHAIN_FILE "D:/aigc/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")
# C++
# C++
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#
set(SOURCE_DIR src)
# RCC++
set(RCCPP_SOURCE_DIR ${SOURCE_DIR})
set(RCCPP_INCLUDE_DIRS ${SOURCE_DIR} ${SOURCE_DIR}/controllers ${SOURCE_DIR}/filters)
set(RCCPP_SOURCE_DIR third_party/RuntimeCompiledCPlusPlus/Aurora)
# D:\aigc\Libs\RCCPP\lib
set(RCCPP_LIB_DIR "D:/aigc/Libs/RCCPP/lib")
# Drogon, RapidJSON
#
find_package(Drogon CONFIG REQUIRED)
find_package(RapidJSON CONFIG REQUIRED)
# Drogon, RapidJSON
set(RCCPP_DIR "D:/aigc/manta/uft_dev_server/third_party/RuntimeCompiledCPlusPlus/Aurora")
find_package(RuntimeCompiledCPlusPlus REQUIRED)
set(SOURCES
src/main.cpp
src/controllers/*.cpp
src/filters/*.cpp
)
# 使GLOB
file(GLOB_RECURSE SOURCES_EXPANDED ${SOURCES})
#
add_executable(${PROJECT_NAME}
${SOURCE_DIR}/main.cpp
${SOURCE_DIR}/controllers/HelloWorldController.cpp
${SOURCE_DIR}/controllers/ApiController.cpp
${SOURCE_DIR}/filters/ApiFilter.cpp
${SOURCES_EXPANDED}
)
# RCCPP
#
target_link_libraries(${PROJECT_NAME} PRIVATE
Drogon::Drogon
${CMAKE_DL_LIBS}
RuntimeCompiledCPlusPlus::RuntimeCompiledCPlusPlus
${CMAKE_DL_LIBS} #
"${RCCPP_LIB_DIR}/RuntimeCompiler.lib"
"${RCCPP_LIB_DIR}/RuntimeObjectSystem.lib"
)
#
#
target_include_directories(${PROJECT_NAME} PRIVATE
${RCCPP_INCLUDE_DIRS}
${RCCPP_SOURCE_DIR}
${SOURCE_DIR}
${SOURCE_DIR}/controllers
${SOURCE_DIR}/filters
)
#
set(CONFIG_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/config/config.json")
set(CONFIG_DEST "${CMAKE_CURRENT_BINARY_DIR}/Debug/config.json")

4
uft_dev_server/cmd.txt

@ -1,10 +1,12 @@ @@ -1,10 +1,12 @@
#增加RCC++依赖包(专为自行编译RCCPP提供,直接使用已有RCCPP目录则无需执行--注意命令执行位置)
mkdir third_party
git clone https://github.com/RuntimeCompiledCPlusPlus/RuntimeCompiledCPlusPlus.git
cd RuntimeCompiledCPlusPlus/Aurora
rm -Path build -Recurse -Force
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX="D:/aigc/Libs/RCCPP" -DINSTALL_CMAKE_CONFIG=ON -DBUILD_SHARED_LIBS=ON -G "Visual Studio 17 2022" -A x64 -DCMAKE_POLICY_VERSION_MINIMUM="4.0.2"
cmake --build . --config Release --target install
cmake --build . --config Debug --target install
#工程编译

3
uft_dev_server/src/controllers/ApiController.cpp

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
#include <drogon/HttpController.h>
#pragma once
#include <drogon/HttpController.h>
#include <drogon/HttpResponse.h>
#include <json/json.h>

9
uft_dev_server/src/controllers/HelloHandler_v1.cpp

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
// HelloHandler_v1.cpp
#include "HelloHandler_v1.h"
std::string HelloHandler_v1::GetResponse()
{
return "Hello, 这是热更新后的版本!";
}
REGISTERCLASS(HelloHandler_v1)

21
uft_dev_server/src/controllers/HelloHandler_v1.h

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
// HelloHandler_v1.cpp
#include "HelloWorldController.h"
#include "RuntimeObjectSystem/ObjectInterfacePerModule.h"
#include "StdioLogSystem.h"
// 接口定义
enum CustomInterfaceIDs
{
IID_HELLO_HANDLER = IID_ENDInterfaceID + 1
};
struct IHelloHandler : public IObject
{
virtual std::string GetResponse() = 0;
};
class HelloHandler_v1 : public TInterface<IID_HELLO_HANDLER, IHelloHandler>
{
public:
std::string GetResponse() override;
};

64
uft_dev_server/src/controllers/HelloWorldController.cpp

@ -1,54 +1,58 @@ @@ -1,54 +1,58 @@
#include <drogon/drogon.h>
#include <iostream>
#include "HelloWorldController.h"
#include "RuntimeObjectSystem/IObject.h"
#include "HelloWorldController.h"
#include "RuntimeObjectSystem/ObjectInterfacePerModule.h"
#include "StdioLogSystem.h"
#include "HelloHandler_v1.h"
// 定义可热更新的接口
class IHelloHandler : public IObject
// 构造函数实现
HelloWorldController::HelloWorldController()
: m_pRuntimeSystem(nullptr),
m_pCompilerLogger(nullptr)
{
public:
virtual std::string GetResponse() = 0;
};
}
// 默认实现(可被热更新)
class HelloHandler_v1 : public TInterface<IID_DEFAULT, IHelloHandler>
// 析构函数实现
HelloWorldController::~HelloWorldController()
{
public:
std::string GetResponse() override
{
return "Hello from Version 1!";
}
};
REGISTERCLASS(HelloHandler_v1);
delete m_pRuntimeSystem;
delete m_pCompilerLogger;
}
void HelloWorldController::asyncHandleHttpRequest(
const HttpRequestPtr &req,
std::function<void(const HttpResponsePtr &)> &&callback)
const drogon::HttpRequestPtr &req,
std::function<void(const drogon::HttpResponsePtr &)> &&callback)
{
// 初始化 RCCPP 系统(仅首次)
// 初始化检查
if (!m_pRuntimeSystem)
{
m_pRuntimeSystem = new RuntimeObjectSystem;
m_pRuntimeSystem->Initialise(new StdioLogSystem(), nullptr);
m_pCompilerLogger = new StdioLogSystem();
// 创建初始对象
auto pCtor = m_pRuntimeSystem->GetObjectFactorySystem()->GetConstructor("HelloHandler_v1");
if (pCtor)
if (!m_pRuntimeSystem->Initialise(m_pCompilerLogger, nullptr))
{
m_ObjectId = pCtor->Construct()->GetObjectId();
auto resp = drogon::HttpResponse::newHttpResponse();
resp->setBody("RCCPP Initialization failed");
callback(resp);
return;
}
}
// 获取当前实现(可能是热更新后的版本)
// 获取构造器
IObjectConstructor *pCtor = m_pRuntimeSystem->GetObjectFactorySystem()->GetConstructor("HelloHandler_v1");
if (pCtor)
{
IObject *pObj = pCtor->Construct();
m_ObjectId = pObj->GetObjectId();
}
// 获取处理器
IHelloHandler *pHandler = nullptr;
if (auto pObj = m_pRuntimeSystem->GetObjectFactorySystem()->GetObject(m_ObjectId))
if (IObject *pObj = m_pRuntimeSystem->GetObjectFactorySystem()->GetObject(m_ObjectId))
{
pObj->GetInterface(&pHandler);
}
// 生成响应
auto resp = HttpResponse::newHttpResponse();
resp->setBody(pHandler ? pHandler->GetResponse() : "Error: Handler not loaded");
auto resp = drogon::HttpResponse::newHttpResponse();
resp->setBody(pHandler ? pHandler->GetResponse() : "Handler not available");
callback(resp);
}

28
uft_dev_server/src/controllers/HelloWorldController.h

@ -1,19 +1,31 @@ @@ -1,19 +1,31 @@
#pragma once
#include <drogon/HttpSimpleController.h>
#include "RuntimeObjectSystem/RuntimeObjectSystem.h" // 全局作用域
#include "RuntimeObjectSystem/RuntimeObjectSystem.h"
#include "RuntimeObjectSystem/IObject.h"
#include "RuntimeObjectSystem/IObjectFactorySystem.h" // 新增
class HelloWorldController : public HttpSimpleController<HelloWorldController>
// 前向声明
struct IRuntimeObjectSystem;
struct IObject;
struct IObjectFactorySystem; // 新增
struct ICompilerLogger; // 新增
class HelloWorldController : public drogon::HttpSimpleController<HelloWorldController>
{
public:
HelloWorldController(); // 显式声明构造函数
~HelloWorldController(); // 显式声明析构函数
virtual void asyncHandleHttpRequest(
const drogon::HttpRequestPtr &req,
std::function<void(const drogon::HttpResponsePtr &)> &&callback) override;
PATH_LIST_BEGIN
PATH_ADD("/hello", Get);
PATH_ADD("/hello", drogon::Get);
PATH_LIST_END
void asyncHandleHttpRequest(const HttpRequestPtr &req,
std::function<void(const HttpResponsePtr &)> &&callback) override;
private:
// RCCPP 相关成员(非继承)
IRuntimeObjectSystem *m_pRuntimeSystem;
IRuntimeObjectSystem *m_pRuntimeSystem = nullptr;
ICompilerLogger *m_pCompilerLogger = nullptr;
ObjectId m_ObjectId;
};

65
uft_dev_server/src/controllers/StdioLogSystem.cpp

@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
//
// Copyright (c) 2010-2011 Matthew Jack and Doug Binks
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
#include "StdioLogSystem.h"
// Currently we create the file on first real output, and only close it on shutdown
#include <stdarg.h>
#include <assert.h>
#include <iostream>
#ifdef _WIN32
#include "RuntimeCompiler/FileSystemUtils.h"
#include "Windows.h"
#pragma warning(disable : 4996 4800)
#endif
void StdioLogSystem::LogError(const char *format, ...)
{
va_list args;
va_start(args, format);
LogInternal(format, args);
}
void StdioLogSystem::LogWarning(const char *format, ...)
{
va_list args;
va_start(args, format);
LogInternal(format, args);
}
void StdioLogSystem::LogInfo(const char *format, ...)
{
va_list args;
va_start(args, format);
LogInternal(format, args);
}
void StdioLogSystem::LogInternal(const char *format, va_list args)
{
int result = vsnprintf(m_buff, LOGSYSTEM_MAX_BUFFER - 1, format, args);
// Make sure there's a limit to the amount of rubbish we can output
m_buff[LOGSYSTEM_MAX_BUFFER - 1] = '\0';
std::cout << m_buff;
#ifdef _WIN32
std::string temp = m_buff;
// convert from utf-8 to Wide char
std::wstring tempW = FileSystemUtils::_Win32Utf8ToUtf16(temp);
OutputDebugStringW(tempW.c_str());
#endif
}

44
uft_dev_server/src/controllers/StdioLogSystem.h

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
//
// Copyright (c) 2010-2011 Matthew Jack and Doug Binks
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
#pragma once
#ifndef STDIOLOGSYSTEM_INCLUDED
#define STDIOLOGSYSTEM_INCLUDED
#include "RuntimeCompiler/ICompilerLogger.h"
#include <string>
#include <stdio.h>
// StdioLogSystem for compiler
const size_t LOGSYSTEM_MAX_BUFFER = 4096;
class StdioLogSystem : public ICompilerLogger
{
public:
virtual void LogError(const char *format, ...);
virtual void LogWarning(const char *format, ...);
virtual void LogInfo(const char *format, ...);
protected:
void LogInternal(const char *format, va_list args);
char m_buff[LOGSYSTEM_MAX_BUFFER];
};
#endif // STDIOLOGSYSTEM_INCLUDED

31
uft_dev_server/src/main.cpp

@ -1,45 +1,20 @@ @@ -1,45 +1,20 @@
#include <drogon/drogon.h>
#include <rccpp/RuntimeObjectSystem.h>
#include <rccpp/RuntimeCompiler.h>
#include <rccpp/FileChangeNotifier.h>
#include <drogon/drogon.h>
#include <iostream>
using namespace drogon;
class MyAppSystem : public RCCPP::ISystem
{
public:
virtual bool Initialise() { return true; }
virtual void Shutdown() {}
virtual void Update(float deltaTime) {}
};
int main()
{
try
{
// 初始化RCC++
RCCPP::RuntimeObjectSystem runtimeObjectSystem;
runtimeObjectSystem.Initialise(new MyAppSystem, ".");
// 设置日志级别
drogon::app().setLogLevel(trantor::Logger::kTrace);
drogon::app().registerBeginningAdvice([]() {
LOG_INFO << "Drogon application starting...";
});
drogon::app().registerBeginningAdvice([]()
{ LOG_INFO << "Drogon application starting..."; });
// 加载配置
drogon::app().loadConfigFile("./config.json");
// 启动文件监视器
auto& fileChangeNotifier = runtimeObjectSystem.GetFileChangeNotifier();
fileChangeNotifier.AddWatch(".", true);
// 主循环中检查文件变化
drogon::app().registerBeginningAdvice([&]() {
runtimeObjectSystem.GetRuntimeCompiler()->Update(0.1f);
});
// 启动服务
drogon::app().run();
}

Loading…
Cancel
Save