6 changed files with 11 additions and 212 deletions
@ -1,9 +0,0 @@ |
|||||||
// HelloHandler_v1.cpp
|
|
||||||
#include "HelloHandler_v1.h" |
|
||||||
|
|
||||||
std::string HelloHandler_v1::GetResponse() |
|
||||||
{ |
|
||||||
return "Hello, 这是热更新后的版本!"; |
|
||||||
} |
|
||||||
|
|
||||||
REGISTERCLASS(HelloHandler_v1) |
|
@ -1,21 +0,0 @@ |
|||||||
// 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; |
|
||||||
}; |
|
@ -1,58 +1,12 @@ |
|||||||
#include "HelloWorldController.h" |
#include "HelloWorldController.h" |
||||||
#include "RuntimeObjectSystem/ObjectInterfacePerModule.h" |
|
||||||
#include "StdioLogSystem.h" |
|
||||||
#include "HelloHandler_v1.h" |
|
||||||
|
|
||||||
// 构造函数实现
|
using namespace drogon; |
||||||
HelloWorldController::HelloWorldController() |
|
||||||
: m_pRuntimeSystem(nullptr), |
|
||||||
m_pCompilerLogger(nullptr) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
// 析构函数实现
|
|
||||||
HelloWorldController::~HelloWorldController() |
|
||||||
{ |
|
||||||
delete m_pRuntimeSystem; |
|
||||||
delete m_pCompilerLogger; |
|
||||||
} |
|
||||||
|
|
||||||
void HelloWorldController::asyncHandleHttpRequest( |
void HelloWorldController::asyncHandleHttpRequest( |
||||||
const drogon::HttpRequestPtr &req, |
const HttpRequestPtr &req, |
||||||
std::function<void(const drogon::HttpResponsePtr &)> &&callback) |
std::function<void(const HttpResponsePtr &)> &&callback) |
||||||
{ |
{ |
||||||
// 初始化检查
|
auto resp = HttpResponse::newHttpResponse(); |
||||||
if (!m_pRuntimeSystem) |
resp->setBody("Hello, World!"); |
||||||
{ |
|
||||||
m_pRuntimeSystem = new RuntimeObjectSystem; |
|
||||||
m_pCompilerLogger = new StdioLogSystem(); |
|
||||||
|
|
||||||
if (!m_pRuntimeSystem->Initialise(m_pCompilerLogger, nullptr)) |
|
||||||
{ |
|
||||||
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 (IObject *pObj = m_pRuntimeSystem->GetObjectFactorySystem()->GetObject(m_ObjectId)) |
|
||||||
{ |
|
||||||
pObj->GetInterface(&pHandler); |
|
||||||
} |
|
||||||
|
|
||||||
// 生成响应
|
|
||||||
auto resp = drogon::HttpResponse::newHttpResponse(); |
|
||||||
resp->setBody(pHandler ? pHandler->GetResponse() : "Handler not available"); |
|
||||||
callback(resp); |
callback(resp); |
||||||
} |
} |
@ -1,31 +1,15 @@ |
|||||||
#pragma once |
#pragma once |
||||||
#include <drogon/HttpSimpleController.h> |
#include <drogon/HttpSimpleController.h> |
||||||
#include "RuntimeObjectSystem/RuntimeObjectSystem.h" |
|
||||||
#include "RuntimeObjectSystem/IObject.h" |
|
||||||
#include "RuntimeObjectSystem/IObjectFactorySystem.h" // 新增 |
|
||||||
|
|
||||||
// 前向声明
|
using namespace drogon; |
||||||
struct IRuntimeObjectSystem; |
|
||||||
struct IObject; |
|
||||||
struct IObjectFactorySystem; // 新增
|
|
||||||
struct ICompilerLogger; // 新增
|
|
||||||
|
|
||||||
class HelloWorldController : public drogon::HttpSimpleController<HelloWorldController> |
class HelloWorldController : public HttpSimpleController<HelloWorldController> |
||||||
{ |
{ |
||||||
public: |
public: |
||||||
HelloWorldController(); // 显式声明构造函数
|
|
||||||
~HelloWorldController(); // 显式声明析构函数
|
|
||||||
|
|
||||||
virtual void asyncHandleHttpRequest( |
|
||||||
const drogon::HttpRequestPtr &req, |
|
||||||
std::function<void(const drogon::HttpResponsePtr &)> &&callback) override; |
|
||||||
|
|
||||||
PATH_LIST_BEGIN |
PATH_LIST_BEGIN |
||||||
PATH_ADD("/hello", drogon::Get); |
PATH_ADD("/hello", Get); |
||||||
PATH_LIST_END |
PATH_LIST_END |
||||||
|
|
||||||
private: |
void asyncHandleHttpRequest(const HttpRequestPtr &req, |
||||||
IRuntimeObjectSystem *m_pRuntimeSystem = nullptr; |
std::function<void(const HttpResponsePtr &)> &&callback) override; |
||||||
ICompilerLogger *m_pCompilerLogger = nullptr; |
|
||||||
ObjectId m_ObjectId; |
|
||||||
}; |
}; |
@ -1,65 +0,0 @@ |
|||||||
//
|
|
||||||
// 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 |
|
||||||
} |
|
@ -1,44 +0,0 @@ |
|||||||
//
|
|
||||||
// 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
|
|
Loading…
Reference in new issue