1#ifdef WEB_FRAMEWORK_DLL
3#include "web_framework_c_api.h"
5#include "Import/WebFramework.h"
6#include "Import/Config.h"
9#define LOG_EXCEPTION() if (Log::isValid()) { Log::error("Exception: {}", "C_API", e.what()); }
10#define CREATE_EXCEPTION() *exception = new std::runtime_error(e.what())
11#define LOG_AND_CREATE_EXCEPTION() LOG_EXCEPTION(); CREATE_EXCEPTION()
13void deleteWebFrameworkString(String
string)
15 delete static_cast<std::string*
>(string);
18void deleteWebFrameworkConfig(Config config)
23void deleteWebFramework(WebFramework webFramework)
28void deleteWebFrameworkException(Exception exception)
30 delete static_cast<std::runtime_error*
>(exception);
33const char* getDataFromString(String
string)
35 return static_cast<std::string*
>(string)->data();
40WebFramework createWebFrameworkFromPath(
const char* configPath, Exception* exception)
46 catch (
const std::exception& e)
48 LOG_AND_CREATE_EXCEPTION();
54WebFramework createWebFrameworkFromString(
const char* serverConfiguration,
const char* applicationDirectory, Exception* exception)
60 catch (
const std::exception& e)
62 LOG_AND_CREATE_EXCEPTION();
68WebFramework createWebFrameworkFromConfig(Config config, Exception* exception)
74 catch (
const std::exception& e)
76 LOG_AND_CREATE_EXCEPTION();
82Config createConfigFromPath(
const char* configPath, Exception* exception)
88 catch (
const std::exception& e)
90 LOG_AND_CREATE_EXCEPTION();
96Config createConfigFromString(
const char* serverConfiguration,
const char* applicationDirectory, Exception* exception)
102 catch (
const std::exception& e)
104 LOG_AND_CREATE_EXCEPTION();
112void startWebFrameworkServerCXX(WebFramework server,
bool wait,
void* onStartServer, Exception* exception)
116 std::function<void()>* lambda =
static_cast<std::function<
void()
>*>(onStartServer);
120 catch (
const std::exception& e)
122 LOG_AND_CREATE_EXCEPTION();
126void startWebFrameworkServer(WebFramework server,
bool wait,
void (*onStartServer)(), Exception* exception)
132 catch (
const std::exception& e)
134 LOG_AND_CREATE_EXCEPTION();
138void stopWebFrameworkServer(WebFramework server,
bool wait, Exception* exception)
144 catch (
const std::exception& e)
146 LOG_AND_CREATE_EXCEPTION();
150bool isServerRunning(WebFramework server, Exception* exception)
156 catch (
const std::exception& e)
158 LOG_AND_CREATE_EXCEPTION();
164const char* getWebFrameworkVersion()
169void overrideConfigurationString(Config config,
const char* key,
const char* value,
bool recursive, Exception* exception)
175 catch (
const std::exception& e)
177 LOG_AND_CREATE_EXCEPTION();
181void overrideConfigurationInteger(Config config,
const char* key, int64_t value,
bool recursive, Exception* exception)
187 catch (
const std::exception& e)
189 LOG_AND_CREATE_EXCEPTION();
193void overrideConfigurationBoolean(Config config,
const char* key,
bool value,
bool recursive, Exception* exception)
197 static_cast<framework::utility::Config*
>(config)->overrideConfiguration(key,
static_cast<json::utility::jsonObject::variantType
>(value), recursive);
199 catch (
const std::exception& e)
201 LOG_AND_CREATE_EXCEPTION();
205void overrideConfigurationStringArray(Config config,
const char* key,
const char** value,
bool recursive, int64_t size, Exception* exception)
209 std::vector<json::utility::jsonObject> data;
213 for (int64_t i = 0; i < size; i++)
215 json::utility::appendArray(std::string(value[i]), data);
220 catch (
const std::exception& e)
222 LOG_AND_CREATE_EXCEPTION();
226void overrideConfigurationIntegerArray(Config config,
const char* key,
const int64_t* value,
bool recursive, int64_t size, Exception* exception)
230 std::vector<json::utility::jsonObject> data;
234 for (int64_t i = 0; i < size; i++)
236 json::utility::appendArray(value[i], data);
241 catch (
const std::exception& e)
243 LOG_AND_CREATE_EXCEPTION();
247String getConfigurationString(Config config,
const char* key,
bool recursive, Exception* exception)
253 catch (
const std::exception& e)
255 LOG_AND_CREATE_EXCEPTION();
261int64_t getConfigurationInteger(Config config,
const char* key,
bool recursive, Exception* exception)
267 catch (
const std::exception& e)
269 LOG_AND_CREATE_EXCEPTION();
275bool getConfigurationBoolean(Config config,
const char* key,
bool recursive, Exception* exception)
281 catch (
const std::exception& e)
283 LOG_AND_CREATE_EXCEPTION();
289void overrideBasePath(Config config,
const char* basePath, Exception* exception)
295 catch (
const std::exception& e)
297 LOG_AND_CREATE_EXCEPTION();
301void* getConfiguration(Config config, Exception* exception)
305 std::ostringstream result;
307 result << **static_cast<framework::utility::Config*>(config);
309 return new std::string(result.str());
311 catch (
const std::exception& e)
313 LOG_AND_CREATE_EXCEPTION();
319const char* getRawConfiguration(Config config, Exception* exception)
325 catch (
const std::exception& e)
327 LOG_AND_CREATE_EXCEPTION();
333void* getBasePath(Config config, Exception* exception)
339 catch (
const std::exception& e)
341 LOG_AND_CREATE_EXCEPTION();
349const char* getErrorMessage(Exception exception)
351 return static_cast<std::runtime_error*
>(exception)->what();
void start(bool wait=false, const std::function< void()> &onStartServer=[]() {})
Start server.
static std::string_view getWebFrameworkVersion()
Get current WebFramework version.
Config file representation.