mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-04 21:07:57 +08:00
75 lines
1.8 KiB
C++
75 lines
1.8 KiB
C++
/*
|
|
* Copyright(C) 2021 hikyuu.org
|
|
*
|
|
* Create on: 2021-02-28
|
|
* Author: fasiondog
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <unordered_set>
|
|
#include <hikyuu/utilities/thread/MQStealThreadPool.h>
|
|
#include <hikyuu/utilities/thread/ThreadPool.h>
|
|
#include <hikyuu/utilities/thread/FuncWrapper.h>
|
|
#include "HttpHandle.h"
|
|
|
|
namespace hku {
|
|
|
|
class HttpServer {
|
|
CLASS_LOGGER(HttpServer)
|
|
|
|
public:
|
|
HttpServer(const char *host, uint16_t port);
|
|
virtual ~HttpServer();
|
|
|
|
void start();
|
|
|
|
template <typename Handle>
|
|
void GET(const char *path) {
|
|
regHandle("GET", path, [](nng_aio *aio) { ms_tg.submit(Handle(aio)); });
|
|
}
|
|
|
|
template <typename Handle>
|
|
void POST(const char *path) {
|
|
regHandle("POST", path, [](nng_aio *aio) { ms_tg.submit(Handle(aio)); });
|
|
}
|
|
|
|
template <typename Handle>
|
|
void PUT(const char *path) {
|
|
regHandle("PUT", path, [](nng_aio *aio) { ms_tg.submit(Handle(aio)); });
|
|
}
|
|
|
|
template <typename Handle>
|
|
void DEL(const char *path) {
|
|
regHandle("DELETE", path, [](nng_aio *aio) { ms_tg.submit(Handle(aio)); });
|
|
}
|
|
|
|
template <typename Handle>
|
|
void PATCH(const char *path) {
|
|
regHandle("PATCH", path, [](nng_aio *aio) { ms_tg.submit(Handle(aio)); });
|
|
}
|
|
|
|
template <typename Handle>
|
|
void regHandle(const char *method, const char *path) {
|
|
regHandle(method, path, [](nng_aio *aio) { ms_tg.submit(Handle(aio)); });
|
|
}
|
|
|
|
private:
|
|
void regHandle(const char *method, const char *path, void (*rest_handle)(nng_aio *));
|
|
|
|
private:
|
|
std::string m_root_url;
|
|
std::string m_host;
|
|
uint16_t m_port;
|
|
|
|
private:
|
|
static void http_exit();
|
|
static void signal_handler(int signal);
|
|
|
|
private:
|
|
static nng_http_server *ms_server;
|
|
static MQStealThreadPool ms_tg;
|
|
};
|
|
|
|
} // namespace hku
|