diff --git a/include/globals.hpp b/include/globals.hpp index c4a134b7..ed20eded 100644 --- a/include/globals.hpp +++ b/include/globals.hpp @@ -24,8 +24,4 @@ struct global_ctx_t{ field_models_t value_models; }; -namespace singleton{ -extern vs_test_debug_t debug; -} - } \ No newline at end of file diff --git a/include/loader.hpp b/include/loader.hpp index 982728bd..a9252433 100644 --- a/include/loader.hpp +++ b/include/loader.hpp @@ -1,20 +1,48 @@ -#pragma once +/** + * @file loader.hpp + * @author karurochari + * @brief Utility function and classes to handle everything related to application loading. + * + * @copyright Copyright (c) 2024 + * + */ -/* - Glue logic exposed to the final application to avoid exposing too many libraries. -*/ +#pragma once #include "globals.hpp" -class ui_tree_xml; namespace vs{ -struct app_loader{ - ui_tree_xml* root; + +class ui_tree; + +struct loader_t{ + private: + ui_tree* root; + + public: + /** + * @brief Load a new application + * + * @param globals The current global context object. + * @param profile Filename of the profile to use for loading. If `nullptr` default will be used. + * @param path The virtual path to the app root file. + */ + loader_t(global_ctx_t& globals, const char* profile, const char* path); + ~loader_t(); + + /** + * @brief After building in the constructor, run the application once ready. + * + * @return int 0 if everything went ok, else error codes. + */ + int run(); - app_loader(global_ctx_t& globals, const char* profile, const char* path); - ~app_loader(); - int run(); - int test(); + /** + * @brief RUn the application in test mode. + * + * @return int if everything went ok, else error codes. + */ + int test(); }; } \ No newline at end of file diff --git a/include/settings.hpp b/include/settings.hpp new file mode 100644 index 00000000..e6ce888f --- /dev/null +++ b/include/settings.hpp @@ -0,0 +1,18 @@ +/** + * @file settings.hpp + * @author karurochari + * @brief Structures to store the instance settings + * + * @copyright Copyright (c) 2024 + * + */ + +#pragma once + +namespace vs{ + +struct settings_t{ + +}; + +} \ No newline at end of file diff --git a/include/singletons.hpp b/include/singletons.hpp new file mode 100644 index 00000000..577f5d7f --- /dev/null +++ b/include/singletons.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace vs{ + +namespace singleton{ + +#ifdef VS_USE_NETWORKING_CURL +struct curl_t{ + curl_t(); + ~curl_t(); +} extern curl; +#endif + +struct debug_t{ + FILE* fd = nullptr; + debug_t(); + ~debug_t(); + + void operator()(const char* field, const char* value); +} extern debug; +} + +} \ No newline at end of file diff --git a/include/utils/env.hpp b/include/utils/env.hpp index eb192e9d..c8a16b66 100644 --- a/include/utils/env.hpp +++ b/include/utils/env.hpp @@ -26,14 +26,6 @@ struct js_rt_t{ void* operator()(); }; -struct vs_test_debug_t{ - FILE* fd = nullptr; - vs_test_debug_t(); - ~vs_test_debug_t(); - - void operator()(const char* field, const char* value); -}; - /** * @brief In case it is not configured already, it prepares the SQLITE file and all the pre-compiled queries needed. * diff --git a/meson.build b/meson.build index 10e24083..3b0d907a 100644 --- a/meson.build +++ b/meson.build @@ -286,8 +286,8 @@ vs_fltk = shared_library( './src/utils/policies.internal.cpp', './src/utils/tcc-wrap.cpp', + './src/singletons.cpp', './src/fetcher.cpp', - './src/loader.cpp', src_components, diff --git a/src/app/main.cpp b/src/app/main.cpp index e262e5d8..67e05a85 100755 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -57,7 +57,7 @@ int run(const char* path, const char *entry, const char* profile, const char* te globals.env.computed_policies.testing=true; } - app_loader loader(globals,profile,entry); + loader_t loader(globals,profile,entry); //TODO implement test if(tests!=nullptr){ diff --git a/src/cbindings/vs.cpp b/src/cbindings/vs.cpp index 2094028d..6a3ec3d2 100644 --- a/src/cbindings/vs.cpp +++ b/src/cbindings/vs.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include void vs_hello_world(){ std::cout<<"Hello world!\n"; diff --git a/src/globals.cpp b/src/globals.cpp index 067c4aab..f1be4c8e 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -1,11 +1,2 @@ -#include #include -#include -namespace vs{ -namespace singleton{ - -vs_test_debug_t debug; - -} -} diff --git a/src/loader.cpp b/src/loader.cpp index 057b2cf9..be723410 100644 --- a/src/loader.cpp +++ b/src/loader.cpp @@ -1,22 +1,13 @@ #include -#ifdef VS_USE_NETWORKING_CURL -#include -#endif - - #include #include #include -//TODO:Remove namespace vs { -app_loader::app_loader(global_ctx_t& globals, const char *profile, const char *path) { - -#ifdef VS_USE_NETWORKING_CURL - curl_global_init(CURL_GLOBAL_ALL); -#endif +loader_t::loader_t(global_ctx_t& globals, const char *profile, const char *path) { + pugi::xml_document doc; static constexpr const char *embedded_profile = R"()"; @@ -48,12 +39,12 @@ app_loader::app_loader(global_ctx_t& globals, const char *profile, const char *p } } -int app_loader::test() { +int loader_t::test() { return root->runtime_testsuite(); // TODO } -int app_loader::run() { +int loader_t::run() { root->globals->mem_storage.cleanup(); root->cleanup(); if (!root->globals->env.computed_policies.headless) { @@ -67,10 +58,7 @@ int app_loader::run() { } } -app_loader::~app_loader() { -#ifdef VS_USE_NETWORKING_CURL - curl_global_cleanup(); -#endif +loader_t::~loader_t() { if (root != nullptr) delete root; } diff --git a/src/pipelines/tcc-c.cpp b/src/pipelines/tcc-c.cpp index 49a1b753..96447296 100644 --- a/src/pipelines/tcc-c.cpp +++ b/src/pipelines/tcc-c.cpp @@ -6,7 +6,7 @@ #include "utils/paths.hpp" #include -#include +#include #include #include diff --git a/src/singletons.cpp b/src/singletons.cpp new file mode 100644 index 00000000..ffa0801a --- /dev/null +++ b/src/singletons.cpp @@ -0,0 +1,32 @@ +#include +#include + +#ifdef VS_USE_NETWORKING_CURL +#include +#endif + +namespace vs{ +namespace singleton{ + +debug_t::debug_t(){auto file=getenv("VS_DEBUG_FILE");if(file!=nullptr)fd=fopen(file,"w+");} +debug_t::~debug_t(){if(fd!=nullptr)fclose(fd);} + +void debug_t::operator()(const char* field, const char* value){ + if(fd==nullptr)return; + else{ + auto now = std::chrono::system_clock::now(); + fprintf(fd,"%s\t%s\t%ld\n",field,value,std::chrono::duration_cast(now.time_since_epoch()).count()); + } +} + + +#ifdef VS_USE_NETWORKING_CURL +curl_t::curl_t(){curl_global_init(CURL_GLOBAL_ALL);} +curl_t::~curl_t(){curl_global_cleanup();} + +curl_t curl; +debug_t debug; +#endif + +} +} \ No newline at end of file diff --git a/src/ui-tree.xml.cpp b/src/ui-tree.xml.cpp index d02e8aaf..18256fba 100755 --- a/src/ui-tree.xml.cpp +++ b/src/ui-tree.xml.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include diff --git a/src/utils/env.cpp b/src/utils/env.cpp index a5aa1d2c..8291e22b 100644 --- a/src/utils/env.cpp +++ b/src/utils/env.cpp @@ -100,19 +100,6 @@ js_rt_t::~js_rt_t(){ void* js_rt_t::operator()(){return rt;} -vs_test_debug_t::vs_test_debug_t(){auto file=getenv("VS_DEBUG_FILE");if(file!=nullptr)fd=fopen(file,"w+");} -vs_test_debug_t::~vs_test_debug_t(){if(fd!=nullptr)fclose(fd);} - -void vs_test_debug_t::operator()(const char* field, const char* value){ - if(fd==nullptr)return; - else{ - auto now = std::chrono::system_clock::now(); - fprintf(fd,"%s\t%s\t%ld\n",field,value,std::chrono::duration_cast(now.time_since_epoch()).count()); - } -} - - - void prepare_db(){ try