Skip to content

Commit

Permalink
refactor: minify boost including
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Nov 12, 2023
1 parent a5e1ff7 commit 92d7fd6
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 7 deletions.
18 changes: 18 additions & 0 deletions source/MaaRestful/Handle/CallbackDispatcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "Handle/CallbackDispatcher.hpp"
#include "Utils/Format.hpp"

MAA_RESTFUL_NS_BEGIN

std::mutex CallbackDispatcher::mtx_;
std::map<std::string, std::function<void(json::value&&)>> CallbackDispatcher::callbacks_;

using namespace boost::beast::http;

bool CallbackDispatcher::handle(Context& ctx, UrlSegments segs)
{
std::ignore = ctx;
std::ignore = segs;
return false;
}

MAA_RESTFUL_NS_END
21 changes: 21 additions & 0 deletions source/MaaRestful/Handle/CallbackDispatcher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "Handle/Context.hpp"
#include "Helper/UrlSegments.hpp"

#include <functional>
#include <map>
#include <meojson/json.hpp>
#include <mutex>

MAA_RESTFUL_NS_BEGIN

struct CallbackDispatcher
{
bool handle(Context& ctx, UrlSegments segs);

static std::mutex mtx_;
static std::map<std::string, std::function<void(json::value&&)>> callbacks_;
};

MAA_RESTFUL_NS_END
3 changes: 3 additions & 0 deletions source/MaaRestful/Helper/Forward.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#define BOOST_WANT_UUID
#define BOOST_WANT_BEAST

#include "Conf/Conf.h"
#include "Utils/Boost.hpp"

Expand Down
11 changes: 11 additions & 0 deletions source/MaaRestful/Helper/Uuid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "Helper/Uuid.hpp"

MAA_RESTFUL_NS_BEGIN

auto uuid_generator = boost::uuids::random_generator();
std::string make_uuid()
{
return boost::uuids::to_string(uuid_generator());
}

MAA_RESTFUL_NS_END
9 changes: 9 additions & 0 deletions source/MaaRestful/Helper/Uuid.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "Helper/Forward.hpp"

MAA_RESTFUL_NS_BEGIN

std::string make_uuid();

MAA_RESTFUL_NS_END
6 changes: 3 additions & 3 deletions source/MaaRpc/implement/Utility.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#define BOOST_WANT_UUID

#include "Utility.h"
#include "MaaFramework/MaaAPI.h"
#include "Macro.h"
#include "Utils/Boost.hpp"
#include "Utils/Logger.h"

#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>

using namespace ::grpc;

auto uuid_generator = boost::uuids::random_generator();
Expand Down
12 changes: 8 additions & 4 deletions source/include/Utils/Boost.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ MAA_SUPPRESS_BOOST_WARNINGS_BEGIN
#include <boost/config.hpp>
#include <boost/dll.hpp>
#include <boost/process.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>

#ifdef _WIN32
#include <boost/process/windows.hpp>
#endif

#ifdef WITH_RESTFUL
#ifdef BOOST_WANT_UUID
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#endif

#ifdef BOOST_WANT_BEAST
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/version.hpp>
#include <boost/url.hpp>
#endif

MAA_SUPPRESS_BOOST_WARNINGS_END

0 comments on commit 92d7fd6

Please sign in to comment.