add wt.
This commit is contained in:
parent
da673dfee6
commit
5d35522a19
1
.vscode/c_cpp_properties.json
vendored
1
.vscode/c_cpp_properties.json
vendored
@ -6,6 +6,7 @@
|
||||
"${workspaceFolder}/**",
|
||||
"${workspaceFolder}/build/_deps/kylin-src/Universal",
|
||||
"/opt/Libraries/boost_1_86_0/include",
|
||||
"/opt/Libraries/wt-4.11.0/include",
|
||||
"/opt/Libraries/ZLMediaKit/include"
|
||||
],
|
||||
"defines": [],
|
||||
|
@ -11,6 +11,10 @@ set(MBEDTLS_ROOT ${Libraries_ROOT}/mbedtls-3.6.2)
|
||||
set(MBEDTLS_INCLUDE_DIR ${MBEDTLS_ROOT}/include)
|
||||
set(MBEDTLS_LIBRARY_DIRS ${MBEDTLS_ROOT}/lib)
|
||||
|
||||
set(WT_ROOT ${Libraries_ROOT}/wt-4.11.0)
|
||||
set(WT_INCLUDE_DIR ${WT_ROOT}/include)
|
||||
set(WT_LIBRARY_DIRS ${WT_ROOT}/lib)
|
||||
|
||||
set(OPENSSL_LIBRARIES ssl crypto)
|
||||
|
||||
include(FetchContent)
|
||||
@ -21,6 +25,7 @@ FetchContent_MakeAvailable(Kylin)
|
||||
|
||||
add_subdirectory(MediaServer)
|
||||
add_subdirectory(ToolKit)
|
||||
add_subdirectory(WebApplication)
|
||||
add_subdirectory(Server)
|
||||
add_subdirectory(ThirdParty)
|
||||
add_subdirectory(UnitTest)
|
@ -23,6 +23,7 @@ target_link_libraries(Server
|
||||
PRIVATE HttpProxy
|
||||
PRIVATE Database
|
||||
PRIVATE MediaServer
|
||||
PRIVATE WebApplication
|
||||
PRIVATE ${Boost_LIBRARIES}
|
||||
)
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "UdpServer.h"
|
||||
#include "WeChatContext/CorporationContext.h"
|
||||
#include "WeChatContext/WeChatContext.h"
|
||||
#include "WebApplication.h"
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/property_tree/ini_parser.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
@ -98,8 +99,8 @@ int main(int argc, char const *argv[]) {
|
||||
});
|
||||
|
||||
auto udpServer = std::make_shared<UdpServer>(application->ioContext());
|
||||
|
||||
auto mediaServer = std::make_shared<MediaServer>(554, false);
|
||||
auto webApp = std::make_unique<WebApplication>();
|
||||
|
||||
using namespace boost::asio::ip;
|
||||
auto proxyAddress = make_address(application->getServer());
|
||||
|
20
WebApplication/CMakeLists.txt
Normal file
20
WebApplication/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
||||
add_library(WebApplication
|
||||
WebApplication.h WebApplication.cpp
|
||||
Hello.h Hello.cpp
|
||||
)
|
||||
|
||||
target_include_directories(WebApplication
|
||||
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PRIVATE ${WT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
target_link_directories(WebApplication
|
||||
PUBLIC ${WT_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(WebApplication
|
||||
PUBLIC wt
|
||||
PUBLIC wttest
|
||||
PUBLIC wthttp
|
||||
PUBLIC Universal
|
||||
)
|
52
WebApplication/Hello.cpp
Normal file
52
WebApplication/Hello.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include "Hello.h"
|
||||
#include "BoostLog.h"
|
||||
#include <Wt/WContainerWidget.h>
|
||||
#include <Wt/WEnvironment.h>
|
||||
#include <Wt/WLineEdit.h>
|
||||
#include <Wt/WPushButton.h>
|
||||
#include <Wt/WText.h>
|
||||
|
||||
Hello::Hello(const Wt::WEnvironment &env, bool embedded) : Wt::WApplication(env) {
|
||||
setTitle("Hello world");
|
||||
Wt::WContainerWidget *top = nullptr;
|
||||
if (!embedded) {
|
||||
top = root();
|
||||
} else {
|
||||
std::unique_ptr<Wt::WContainerWidget> topPtr = std::make_unique<Wt::WContainerWidget>();
|
||||
top = topPtr.get();
|
||||
const std::string *div = env.getParameter("div");
|
||||
if (div) {
|
||||
setJavaScriptClass(*div);
|
||||
bindWidget(std::move(topPtr), *div);
|
||||
} else {
|
||||
LOG(error) << "Missing: parameter: 'div'";
|
||||
}
|
||||
LOG(info) << "url: " << url();
|
||||
LOG(info) << "relative resources url: " << relativeResourcesUrl();
|
||||
LOG(info) << "resources url: " << resourcesUrl();
|
||||
url();
|
||||
}
|
||||
|
||||
if (!embedded) {
|
||||
root()->addWidget(std::make_unique<Wt::WText>("<p><emph>Note: you can also run this application "
|
||||
"from within <a href=\"hello.html\">a web page</a>.</emph></p>"));
|
||||
}
|
||||
|
||||
top->addWidget(std::make_unique<Wt::WText>("Your name, please ? "));
|
||||
m_nameEdit = top->addWidget(std::make_unique<Wt::WLineEdit>());
|
||||
m_nameEdit->setFocus();
|
||||
|
||||
auto b = top->addWidget(std::make_unique<Wt::WPushButton>("点击我!"));
|
||||
b->setMargin(5, Wt::Side::Left);
|
||||
|
||||
top->addWidget(std::make_unique<Wt::WBreak>());
|
||||
|
||||
m_greeting = top->addWidget(std::make_unique<Wt::WText>());
|
||||
|
||||
b->clicked().connect(this, &Hello::greet);
|
||||
m_nameEdit->enterPressed().connect(this, &Hello::greet);
|
||||
}
|
||||
|
||||
void Hello::greet() {
|
||||
m_greeting->setText("Hello there, " + m_nameEdit->text());
|
||||
}
|
18
WebApplication/Hello.h
Normal file
18
WebApplication/Hello.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef __HELLO_H__
|
||||
#define __HELLO_H__
|
||||
|
||||
#include <Wt/WApplication.h>
|
||||
|
||||
class Hello : public Wt::WApplication {
|
||||
public:
|
||||
Hello(const Wt::WEnvironment &env, bool embedded);
|
||||
|
||||
protected:
|
||||
void greet();
|
||||
|
||||
private:
|
||||
Wt::WLineEdit *m_nameEdit = nullptr;
|
||||
Wt::WText *m_greeting = nullptr;
|
||||
};
|
||||
|
||||
#endif // __HELLO_H__
|
44
WebApplication/WebApplication.cpp
Normal file
44
WebApplication/WebApplication.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include "WebApplication.h"
|
||||
#include "BoostLog.h"
|
||||
#include "Hello.h"
|
||||
#include <Wt/WServer.h>
|
||||
|
||||
static std::unique_ptr<Wt::WApplication> createApplication(const Wt::WEnvironment &env) {
|
||||
return std::make_unique<Hello>(env, false);
|
||||
}
|
||||
|
||||
static std::unique_ptr<Wt::WApplication> createWidgetSet(const Wt::WEnvironment &env) {
|
||||
return std::make_unique<Hello>(env, true);
|
||||
}
|
||||
|
||||
WebApplication::WebApplication() {
|
||||
try {
|
||||
std::vector<std::string> args;
|
||||
args.push_back("--docroot=./build");
|
||||
args.push_back("--http-listen=127.0.0.1:8855");
|
||||
// --docroot=. --no-compression --http-listen 127.0.0.1:8855
|
||||
m_server = std::make_unique<Wt::WServer>("./build", args);
|
||||
m_server->addEntryPoint(Wt::EntryPointType::Application, createApplication);
|
||||
m_server->addEntryPoint(Wt::EntryPointType::WidgetSet, createWidgetSet, "/gui/hello.js");
|
||||
m_thread = std::thread(&WebApplication::run, this);
|
||||
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
LOG(error) << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
WebApplication::~WebApplication() {
|
||||
if (m_thread.joinable()) {
|
||||
m_thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
void WebApplication::run() {
|
||||
try {
|
||||
|
||||
m_server->run();
|
||||
} catch (const std::exception &e) {
|
||||
LOG(error) << e.what();
|
||||
}
|
||||
}
|
24
WebApplication/WebApplication.h
Normal file
24
WebApplication/WebApplication.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef __WEBAPPLICATION_H__
|
||||
#define __WEBAPPLICATION_H__
|
||||
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
namespace Wt {
|
||||
class WServer;
|
||||
};
|
||||
|
||||
class WebApplication {
|
||||
public:
|
||||
WebApplication();
|
||||
~WebApplication();
|
||||
|
||||
protected:
|
||||
void run();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Wt::WServer> m_server;
|
||||
std::thread m_thread;
|
||||
};
|
||||
|
||||
#endif // __WEBAPPLICATION_H__
|
@ -21,6 +21,9 @@ function cmake_scan() {
|
||||
}
|
||||
|
||||
function build() {
|
||||
# pkill -9 HttpServer
|
||||
# cp -r /opt/Libraries/wt-4.11.0/share/Wt/* ./build
|
||||
|
||||
if [ ! -f "${build_path}/CMakeCache.txt" ]; then
|
||||
cmake_scan
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user