Skip to content

Commit

Permalink
refactor: move sources
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Mar 15, 2024
1 parent 8c16775 commit 35fb21e
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 16 deletions.
7 changes: 4 additions & 3 deletions source/MaaHttp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ add_subdirectory(LHG)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

lhggenerate(${CMAKE_CURRENT_SOURCE_DIR}/interface.json ${CMAKE_CURRENT_SOURCE_DIR}/config.json
${CMAKE_CURRENT_SOURCE_DIR}/info.hpp)
lhggenerate(LHGInfo ${CMAKE_CURRENT_SOURCE_DIR}/interface.json ${CMAKE_CURRENT_SOURCE_DIR}/config.json
${CMAKE_CURRENT_SOURCE_DIR}/source/info.hpp)

set(maa_http_src main.cpp extra.cpp extra.h include.h info.hpp)
file(GLOB_RECURSE maa_http_src source/*.cpp source/*.h source/*.hpp)

add_executable(MaaHttp ${maa_http_src})
target_include_directories(MaaHttp PRIVATE ./../include)
target_link_libraries(MaaHttp LHGHeaderonly LHGSupport Boost::system MaaFramework MaaToolkit)
add_dependencies(MaaHttp LHGInfo)

if(WIN32)
target_compile_definitions(MaaHttp PRIVATE _WIN32_WINNT=0x0A00)
Expand Down
2 changes: 1 addition & 1 deletion source/MaaHttp/LHG
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions source/MaaHttp/source/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <cstdlib>
#include <iostream>

#include "server.h"

int main(int argc, char* argv[])
{
unsigned port = 13126;
for (int i = 1; i + 1 < argc; i++) {
if (!strcmp(argv[i], "-p")) {
port = atoi(argv[i + 1]);
if (port == 0 || port > 65535) {
std::cerr << "invalid port " << argv[i] << std::endl;
port = 13126;
}
}
}

lhg::server::Dispatcher* dispatcher;
lhg::server::Server* server;
setup_server(port, server, dispatcher);

server->run();

std::cerr << "server started at 127.0.0.1:" << port << std::endl;
std::cerr << "press enter to stop" << std::endl;

std::cin.get();

server->stop();

return 0;
}
19 changes: 7 additions & 12 deletions source/MaaHttp/main.cpp → source/MaaHttp/source/server.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
#include <iostream>

#include "info.hpp"
#include "utils/phony.hpp"

#include "server.h"
#include "spec/spec.hpp"

int main()
void setup_server(
unsigned short port,
lhg::server::Server*& server,
lhg::server::Dispatcher*& dispatcher)
{
auto* dispatcher = new lhg::server::Dispatcher();
auto* server = new lhg::server::Server(dispatcher, 13126);
dispatcher = new lhg::server::Dispatcher();
server = new lhg::server::Server(dispatcher, 13126);

lhg::server::apply_function<lhg::maa::__function_list>(dispatcher);
lhg::server::apply_callback<lhg::maa::__callback_list>(dispatcher);
lhg::server::apply_handle<lhg::maa::__handle_list>(dispatcher);

dispatcher->setup_help("/help", "maa http", "1.0.0");

server->sync_run();

return 0;
}
8 changes: 8 additions & 0 deletions source/MaaHttp/source/server.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include "utils/phony.hpp"

extern void setup_server(
unsigned short port,
lhg::server::Server*& server,
lhg::server::Dispatcher*& dispatcher);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 35fb21e

Please sign in to comment.