diff options
| author | Stefan Boberg <[email protected]> | 2021-09-17 09:54:50 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-17 09:54:50 +0200 |
| commit | 6da25650aa4bf87dcd5e3d612c615e0b8240015f (patch) | |
| tree | e23e686b6296e860a010b6e3fa580eea8481c185 | |
| parent | Moved zenserverprocess into zenutil/zenserverprocess.h (diff) | |
| download | zen-6da25650aa4bf87dcd5e3d612c615e0b8240015f.tar.xz zen-6da25650aa4bf87dcd5e3d612c615e0b8240015f.zip | |
Added namespace scopes to more includes for better consistency
| -rw-r--r-- | zen/cmds/copy.cpp | 4 | ||||
| -rw-r--r-- | zen/cmds/copy.h | 4 | ||||
| -rw-r--r-- | zen/cmds/dedup.cpp | 4 | ||||
| -rw-r--r-- | zen/cmds/dedup.h | 4 | ||||
| -rw-r--r-- | zen/cmds/deploy.cpp | 4 | ||||
| -rw-r--r-- | zen/cmds/deploy.h | 4 | ||||
| -rw-r--r-- | zen/cmds/hash.cpp | 4 | ||||
| -rw-r--r-- | zen/cmds/hash.h | 4 | ||||
| -rw-r--r-- | zen/cmds/run.cpp | 4 | ||||
| -rw-r--r-- | zen/cmds/run.h | 5 | ||||
| -rw-r--r-- | zen/cmds/scrub.cpp | 4 | ||||
| -rw-r--r-- | zen/cmds/scrub.h | 5 | ||||
| -rw-r--r-- | zen/cmds/status.cpp | 5 | ||||
| -rw-r--r-- | zen/cmds/status.h | 4 | ||||
| -rw-r--r-- | zen/cmds/top.cpp | 4 | ||||
| -rw-r--r-- | zen/cmds/top.h | 4 | ||||
| -rw-r--r-- | zen/cmds/up.cpp | 4 | ||||
| -rw-r--r-- | zen/cmds/up.h | 4 | ||||
| -rw-r--r-- | zen/zen.cpp | 50 | ||||
| -rw-r--r-- | zencore-test/zencore-test.cpp | 2 | ||||
| -rw-r--r-- | zencore/include/zencore/zencore.h | 4 | ||||
| -rw-r--r-- | zencore/zencore.cpp | 8 | ||||
| -rw-r--r-- | zenserver-test/zenserver-test.cpp | 9 | ||||
| -rw-r--r-- | zenserver/zenserver.cpp | 6 | ||||
| -rw-r--r-- | zenutil/include/zenutil/zenserverprocess.h | 4 | ||||
| -rw-r--r-- | zenutil/zenserverprocess.cpp | 60 |
26 files changed, 147 insertions, 71 deletions
diff --git a/zen/cmds/copy.cpp b/zen/cmds/copy.cpp index 4ce09c982..6b3965f99 100644 --- a/zen/cmds/copy.cpp +++ b/zen/cmds/copy.cpp @@ -7,6 +7,8 @@ #include <zencore/string.h> #include <zencore/timer.h> +namespace zen { + CopyCommand::CopyCommand() { m_Options.add_options()("h,help", "Print help"); @@ -94,3 +96,5 @@ CopyCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) return 0; } + +} diff --git a/zen/cmds/copy.h b/zen/cmds/copy.h index 22b240d11..c2a7fd23b 100644 --- a/zen/cmds/copy.h +++ b/zen/cmds/copy.h @@ -4,6 +4,8 @@ #include "../zen.h" +namespace zen { + /** Copy files, possibly using block cloning */ class CopyCommand : public ZenCmdBase @@ -22,3 +24,5 @@ private: std::string m_CopyTarget; bool m_NoClone = false; }; + +} diff --git a/zen/cmds/dedup.cpp b/zen/cmds/dedup.cpp index 90a4fea76..f95a87518 100644 --- a/zen/cmds/dedup.cpp +++ b/zen/cmds/dedup.cpp @@ -12,6 +12,8 @@ #include <ppl.h> +namespace zen { + DedupCommand::DedupCommand() { m_Options.add_options()("h,help", "Print help"); @@ -290,3 +292,5 @@ DedupCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) return 0; } + +} diff --git a/zen/cmds/dedup.h b/zen/cmds/dedup.h index 0f0aecc8e..c955d4bbd 100644 --- a/zen/cmds/dedup.h +++ b/zen/cmds/dedup.h @@ -6,6 +6,8 @@ #include <ppl.h> +namespace zen { + /** Deduplicate files in a tree using block cloning */ class DedupCommand : public ZenCmdBase @@ -24,3 +26,5 @@ private: std::string m_DedupTarget; size_t m_SizeThreshold = 1024 * 1024; }; + +} diff --git a/zen/cmds/deploy.cpp b/zen/cmds/deploy.cpp index b8879fefb..faaf0030c 100644 --- a/zen/cmds/deploy.cpp +++ b/zen/cmds/deploy.cpp @@ -5,6 +5,8 @@ #include <zencore/logging.h> #include <zencore/string.h> +namespace zen { + DeployCommand::DeployCommand() { m_Options.add_options()("h,help", "Print help"); @@ -80,3 +82,5 @@ DeployCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) return 0; } + +} diff --git a/zen/cmds/deploy.h b/zen/cmds/deploy.h index 1109aaf17..565e11bf3 100644 --- a/zen/cmds/deploy.h +++ b/zen/cmds/deploy.h @@ -4,6 +4,8 @@ #include "../zen.h" +namespace zen { + /** Deploy files from Zen build store */ class DeployCommand : public ZenCmdBase @@ -23,3 +25,5 @@ private: bool m_NoClone = false; bool m_IsClean = false; }; + +} diff --git a/zen/cmds/hash.cpp b/zen/cmds/hash.cpp index b6276dbc1..e9484c453 100644 --- a/zen/cmds/hash.cpp +++ b/zen/cmds/hash.cpp @@ -9,6 +9,8 @@ #include <ppl.h> +namespace zen { + HashCommand::HashCommand() { m_Options.add_options()("d,dir", "Directory to scan", cxxopts::value<std::string>(m_ScanDirectory))( @@ -123,3 +125,5 @@ HashCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) // TODO: implement snapshot enumeration and display return 0; } + +} diff --git a/zen/cmds/hash.h b/zen/cmds/hash.h index b994b497d..8ed8e9fa3 100644 --- a/zen/cmds/hash.h +++ b/zen/cmds/hash.h @@ -7,6 +7,8 @@ #include <ppl.h> +namespace zen { + /** Generate hash list file */ class HashCommand : public ZenCmdBase @@ -23,3 +25,5 @@ private: std::string m_ScanDirectory; std::string m_OutputFile; }; + +} diff --git a/zen/cmds/run.cpp b/zen/cmds/run.cpp index d0ecaaf2b..711a3a341 100644 --- a/zen/cmds/run.cpp +++ b/zen/cmds/run.cpp @@ -35,6 +35,8 @@ ////////////////////////////////////////////////////////////////////////// +namespace zen { + using namespace std::literals; RunCommand::RunCommand() @@ -181,3 +183,5 @@ RunCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) return 0; } + +} diff --git a/zen/cmds/run.h b/zen/cmds/run.h index 8fa1f6ae9..f4eb4ef76 100644 --- a/zen/cmds/run.h +++ b/zen/cmds/run.h @@ -2,10 +2,9 @@ #pragma once -#include "../internalfile.h" #include "../zen.h" -#include <ppl.h> +namespace zen { /** Execute a command (using Zen) */ @@ -23,3 +22,5 @@ private: std::string m_TargetHost; std::string m_ExeTree; }; + +} diff --git a/zen/cmds/scrub.cpp b/zen/cmds/scrub.cpp index fd6047078..73d2b45ee 100644 --- a/zen/cmds/scrub.cpp +++ b/zen/cmds/scrub.cpp @@ -5,6 +5,8 @@ using namespace std::literals; +namespace zen { + ScrubCommand::ScrubCommand() { } @@ -36,3 +38,5 @@ GcCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) return 0; } + +} diff --git a/zen/cmds/scrub.h b/zen/cmds/scrub.h index 348f579c5..a3f25c259 100644 --- a/zen/cmds/scrub.h +++ b/zen/cmds/scrub.h @@ -2,10 +2,9 @@ #pragma once -#include "../internalfile.h" #include "../zen.h" -#include <ppl.h> +namespace zen { /** Scrub storage */ @@ -36,3 +35,5 @@ public: private: cxxopts::Options m_Options{"gc", "Garbage collect zen storage"}; }; + +} diff --git a/zen/cmds/status.cpp b/zen/cmds/status.cpp index 6741ab9e9..1050b5b96 100644 --- a/zen/cmds/status.cpp +++ b/zen/cmds/status.cpp @@ -3,7 +3,8 @@ #include "status.h" #include <zencore/logging.h> -#include <memory> + +namespace zen { StatusCommand::StatusCommand() { @@ -18,3 +19,5 @@ StatusCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) return 0; } + +} diff --git a/zen/cmds/status.h b/zen/cmds/status.h index bb439f340..f2c68b96a 100644 --- a/zen/cmds/status.h +++ b/zen/cmds/status.h @@ -4,6 +4,8 @@ #include "../zen.h" +namespace zen { + class StatusCommand : public ZenCmdBase { public: @@ -16,3 +18,5 @@ public: private: cxxopts::Options m_Options{"status", "Show zen status"}; }; + +} diff --git a/zen/cmds/top.cpp b/zen/cmds/top.cpp index 8c74e5145..3ff7edcda 100644 --- a/zen/cmds/top.cpp +++ b/zen/cmds/top.cpp @@ -11,6 +11,8 @@ ////////////////////////////////////////////////////////////////////////// +namespace zen { + TopCommand::TopCommand() { } @@ -76,3 +78,5 @@ PsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) return 0; } + +} diff --git a/zen/cmds/top.h b/zen/cmds/top.h index 32ba6c57b..a842089ff 100644 --- a/zen/cmds/top.h +++ b/zen/cmds/top.h @@ -4,6 +4,8 @@ #include "../zen.h" +namespace zen { + class TopCommand : public ZenCmdBase { public: @@ -29,3 +31,5 @@ public: private: cxxopts::Options m_Options{"ps", "Enumerate running Zen server instances"}; }; + +} diff --git a/zen/cmds/up.cpp b/zen/cmds/up.cpp index 99fbfe3ae..048133fc9 100644 --- a/zen/cmds/up.cpp +++ b/zen/cmds/up.cpp @@ -8,6 +8,8 @@ #include <memory> +namespace zen { + UpCommand::UpCommand() { } @@ -98,3 +100,5 @@ DownCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) return 0; } + +} diff --git a/zen/cmds/up.h b/zen/cmds/up.h index a3c6eaa06..fda62693a 100644 --- a/zen/cmds/up.h +++ b/zen/cmds/up.h @@ -4,6 +4,8 @@ #include "../zen.h" +namespace zen { + class UpCommand : public ZenCmdBase { public: @@ -29,3 +31,5 @@ public: private: cxxopts::Options m_Options{"down", "Bring down zen service"}; }; + +} diff --git a/zen/zen.cpp b/zen/zen.cpp index d8bfa13e5..6390c832f 100644 --- a/zen/zen.cpp +++ b/zen/zen.cpp @@ -42,6 +42,7 @@ ////////////////////////////////////////////////////////////////////////// + class TemplateCommand : public ZenCmdBase { public: @@ -94,29 +95,12 @@ private: int main(int argc, char** argv) { + using namespace zen; + mi_version(); zen::logging::InitializeLogging(); -#if TEST_UWS - /* Overly simple hello world app, using multiple threads */ - std::vector<std::thread*> threads(4); - - std::transform(threads.begin(), threads.end(), threads.begin(), [](std::thread* /*t*/) { - return new std::thread([]() { - uWS::App() - .get("/*", - [&](uWS::HttpResponse<false>* res, uWS::HttpRequest*) { - zen::Sleep(1); - res->end("hello, world!"); - }) - .listen(1337, [&](auto* listen_socket) { ZEN_UNUSED(listen_socket); }) - .run(); - }); - }); - - std::for_each(threads.begin(), threads.end(), [](std::thread* t) { t->join(); }); -#endif ////////////////////////////////////////////////////////////////////////// auto _ = zen::MakeGuard([] { spdlog::shutdown(); }); @@ -141,19 +125,21 @@ main(int argc, char** argv) ZenCmdBase* Cmd; const char* CmdSummary; } Commands[] = { - {"chunk", &ChunkCmd, "Perform chunking"}, - {"copy", &CopyCmd, "Copy file(s)"}, - {"deploy", &DeployCmd, "Deploy data"}, - {"dedup", &DedupCmd, "Dedup files"}, - {"drop", &DropCmd, "Drop cache bucket(s)"}, - {"hash", &HashCmd, "Compute file hashes"}, - {"runtests", &RunTestsCmd, "Run zen tests"}, - {"run", &RunCmd, "Remote execution"}, - {"status", &StatusCmd, "Show zen status"}, - {"ps", &PsCmd, "Enumerate running zen server instances"}, - {"top", &TopCmd, "Monitor zen server activity"}, - {"up", &UpCmd, "Bring zen server up"}, - {"down", &DownCmd, "Bring zen server down"}, + // clang-format off + {"chunk", &ChunkCmd, "Perform chunking"}, + {"copy", &CopyCmd, "Copy file(s)"}, + {"deploy", &DeployCmd, "Deploy data"}, + {"dedup", &DedupCmd, "Dedup files"}, + {"drop", &DropCmd, "Drop cache bucket(s)"}, + {"hash", &HashCmd, "Compute file hashes"}, + {"runtests", &RunTestsCmd, "Run zen tests"}, + {"run", &RunCmd, "Remote execution"}, + {"status", &StatusCmd, "Show zen status"}, + {"ps", &PsCmd, "Enumerate running zen server instances"}, + {"top", &TopCmd, "Monitor zen server activity"}, + {"up", &UpCmd, "Bring zen server up"}, + {"down", &DownCmd, "Bring zen server down"}, + // clang-format on }; // Build set containing available commands diff --git a/zencore-test/zencore-test.cpp b/zencore-test/zencore-test.cpp index 559349076..7242a30ec 100644 --- a/zencore-test/zencore-test.cpp +++ b/zencore-test/zencore-test.cpp @@ -11,7 +11,7 @@ void forceLinkTests() { - zencore_forcelinktests(); + zen::zencore_forcelinktests(); } int diff --git a/zencore/include/zencore/zencore.h b/zencore/include/zencore/zencore.h index 54df7e85e..da17e61e3 100644 --- a/zencore/include/zencore/zencore.h +++ b/zencore/include/zencore/zencore.h @@ -150,12 +150,16 @@ char (&ZenArrayCountHelper(const T (&)[N]))[N + 1]; #define ZEN_NOT_IMPLEMENTED(...) ZEN_ASSERT(false, __VA_ARGS__) #define ZENCORE_API // Placeholder to allow DLL configs in the future +namespace zen { + ZENCORE_API bool IsPointerToStack(const void* ptr); // Query if pointer is within the stack of the currently executing thread ZENCORE_API bool IsApplicationExitRequested(); ZENCORE_API void RequestApplicationExit(int ExitCode); ZENCORE_API void zencore_forcelinktests(); +} + ////////////////////////////////////////////////////////////////////////// #if ZEN_COMPILER_MSC diff --git a/zencore/zencore.cpp b/zencore/zencore.cpp index f179880e4..5899f014d 100644 --- a/zencore/zencore.cpp +++ b/zencore/zencore.cpp @@ -28,6 +28,8 @@ #include <zencore/timer.h> #include <zencore/uid.h> +namespace zen { + bool IsPointerToStack(const void* ptr) { @@ -53,11 +55,11 @@ IsPointerToStack(const void* ptr) #endif } -zen::AssertException::AssertException(const char* Msg) : m_Msg(Msg) +AssertException::AssertException(const char* Msg) : m_Msg(Msg) { } -zen::AssertException::~AssertException() +AssertException::~AssertException() { } @@ -101,3 +103,5 @@ zencore_forcelinktests() zen::usonbuilder_forcelink(); zen::usonpackage_forcelink(); } + +} // namespace zen diff --git a/zenserver-test/zenserver-test.cpp b/zenserver-test/zenserver-test.cpp index 6b4d39f89..48bbacd80 100644 --- a/zenserver-test/zenserver-test.cpp +++ b/zenserver-test/zenserver-test.cpp @@ -657,20 +657,20 @@ main() } #else -ZenServerEnvironment TestEnv; +zen::ZenServerEnvironment TestEnv; int main(int argc, char** argv) { mi_version(); - zencore_forcelinktests(); + zen::zencore_forcelinktests(); zen::zenhttp_forcelinktests(); zen::logging::InitializeLogging(); spdlog::set_level(spdlog::level::debug); - spdlog::set_formatter(std::make_unique<logging::full_formatter>("test", std::chrono::system_clock::now())); + spdlog::set_formatter(std::make_unique<::logging::full_formatter>("test", std::chrono::system_clock::now())); std::filesystem::path ProgramBaseDir = std::filesystem::path(argv[0]).parent_path(); std::filesystem::path TestBaseDir = ProgramBaseDir.parent_path().parent_path() / ".test"; @@ -681,6 +681,8 @@ main(int argc, char** argv) return doctest::Context(argc, argv).run(); } +namespace zen::tests { + # if 1 TEST_CASE("asio.http") { @@ -1771,4 +1773,5 @@ TEST_CASE("lifetime.owner.2") } # endif +} #endif diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index 3681d2f8c..eb0324161 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -82,6 +82,8 @@ #define ZEN_APP_NAME "Zen store" +namespace zen { + class ZenServer { ZenServerState::ZenServerEntry* m_ServerEntry = nullptr; @@ -420,9 +422,13 @@ private: bool m_DebugOptionForcedCrash = false; }; +} + int main(int argc, char* argv[]) { + using namespace zen; + mi_version(); ZenServerOptions GlobalOptions; diff --git a/zenutil/include/zenutil/zenserverprocess.h b/zenutil/include/zenutil/zenserverprocess.h index d1897d5e2..f0924f048 100644 --- a/zenutil/include/zenutil/zenserverprocess.h +++ b/zenutil/include/zenutil/zenserverprocess.h @@ -13,6 +13,8 @@ #include <filesystem> #include <optional> +namespace zen { + class ZenServerEnvironment { public: @@ -128,3 +130,5 @@ private: int m_MaxEntryCount = 131072 / sizeof(ZenServerEntry); ZenServerEntry* m_OurEntry = nullptr; }; + +} diff --git a/zenutil/zenserverprocess.cpp b/zenutil/zenserverprocess.cpp index 622423cac..c504ce7da 100644 --- a/zenutil/zenserverprocess.cpp +++ b/zenutil/zenserverprocess.cpp @@ -17,44 +17,46 @@ ////////////////////////////////////////////////////////////////////////// +namespace zen { + namespace zenutil { -class SecurityAttributes -{ -public: - inline SECURITY_ATTRIBUTES* Attributes() { return &m_Attributes; } + class SecurityAttributes + { + public: + inline SECURITY_ATTRIBUTES* Attributes() { return &m_Attributes; } -protected: - SECURITY_ATTRIBUTES m_Attributes{}; - SECURITY_DESCRIPTOR m_Sd{}; -}; + protected: + SECURITY_ATTRIBUTES m_Attributes{}; + SECURITY_DESCRIPTOR m_Sd{}; + }; -// Security attributes which allows any user access + // Security attributes which allows any user access -class AnyUserSecurityAttributes : public SecurityAttributes -{ -public: - AnyUserSecurityAttributes() + class AnyUserSecurityAttributes : public SecurityAttributes { - m_Attributes.nLength = sizeof m_Attributes; - m_Attributes.bInheritHandle = false; // Disable inheritance - - const BOOL success = InitializeSecurityDescriptor(&m_Sd, SECURITY_DESCRIPTOR_REVISION); - - if (success) + public: + AnyUserSecurityAttributes() { - const BOOL bSetOk = SetSecurityDescriptorDacl(&m_Sd, TRUE, (PACL)NULL, FALSE); + m_Attributes.nLength = sizeof m_Attributes; + m_Attributes.bInheritHandle = false; // Disable inheritance - if (bSetOk) - { - m_Attributes.lpSecurityDescriptor = &m_Sd; - } - else + const BOOL success = InitializeSecurityDescriptor(&m_Sd, SECURITY_DESCRIPTOR_REVISION); + + if (success) { - zen::ThrowLastError("SetSecurityDescriptorDacl failed", std::source_location::current()); + const BOOL bSetOk = SetSecurityDescriptorDacl(&m_Sd, TRUE, (PACL)NULL, FALSE); + + if (bSetOk) + { + m_Attributes.lpSecurityDescriptor = &m_Sd; + } + else + { + zen::ThrowLastError("SetSecurityDescriptorDacl failed", std::source_location::current()); + } } } - } -}; + }; } // namespace zenutil @@ -628,3 +630,5 @@ ZenServerInstance::GetBaseUri() const return "http://localhost:{}"_format(m_BasePort); } + +} // namespace zen |