diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..078c4d6 --- /dev/null +++ b/.clang-format @@ -0,0 +1,76 @@ +# Generated from CLion C/C++ Code Style settings +BinPackParameters: false +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: None +AlignOperands: Align +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: true +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakTemplateDeclarations: Yes +# 函数和返回类型分两行,方便阅读 +AlwaysBreakAfterReturnType: TopLevelDefinitions +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +ConstructorInitializerAllOnOneLineOrOnePerLine: true +BreakInheritanceList: BeforeColon +ColumnLimit: 120 +CompactNamespaces: false +ContinuationIndentWidth: 4 +EmptyLineBeforeAccessModifier: LogicalBlock +SeparateDefinitionBlocks: Always +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: false +PointerAlignment: Right +ReflowComments: false +SortIncludes: Never +AlignArrayOfStructures: Right +# AlignConsecutiveStyle: AcrossEmptyLines +AlignConsecutiveMacros: AcrossEmptyLines +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 0 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 24fd172..cb499f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,9 @@ add_library(${PROJECT_NAME} STATIC "" src/network/socket_factory.cpp src/network/socket_address.cpp src/network/socket_server.cpp - src/synchronization/event.cpp) + src/synchronization/event.cpp + src/logging/log.cpp +) target_compile_definitions(${PROJECT_NAME} PRIVATE ULIB_LIBRARY_IMPL) target_include_directories(${PROJECT_NAME} PUBLIC src) target_sources(${PROJECT_NAME} diff --git a/drone/build.yaml b/drone/build.yaml deleted file mode 100644 index 5d97426..0000000 --- a/drone/build.yaml +++ /dev/null @@ -1,61 +0,0 @@ -kind: pipeline -type: docker -name: default -steps: - {{ $prepare_commands := .input.prepare_commands }} - {{ $before_commands := .input.before_commands }} - {{ $build_commands:= .input.build_commands }} - {{ $after_commands := .input.after_commands }} - {{ $default_build_types := .input.default_build_types }} - - {{ range .input.builds }} - {{ $cmake_configure_args := .cmake_configure_args }} - {{ $image_name := .image_name }} - {{ if .cmake_configure_args }} - {{ $cmake_configure_args := .cmake_configure_args }} - {{ end }} - - {{ $image_name := .image_name }} - - name: build {{ .image_name }} - image: dockcross/{{ .image_name }} - commands: - {{ range $prepare_commands }} - - {{ . }} - {{ end }} - - {{ $build_types := $default_build_types }} - {{ if .build_types }} - {{ $build_types := .build_types }} - {{ end }} - - {{ range $build_types }} - - export BUILD_TYPE={{.}} - - export BUILD_DIR=build-{{$image_name}}-{{.}} - - echo $BUILD_TYPE - - echo $BUILD_DIR - - {{ range $before_commands }} - - {{ . }} - {{ end }} - - {{ range $build_commands }} - - {{ . }} - {{ end }} - - {{ range $after_commands }} - - {{ . }} - {{ end }} - - {{ end }} - - - {{ end }} - - - name: list all build dir - image: alpine - commands: - - ls -l build-* - depends_on: - {{ range .input.builds }} - - build {{ .image_name }} - {{ end }} diff --git a/src/common/compiler_defs.h b/src/common/compiler_defs.h new file mode 100644 index 0000000..953b8c0 --- /dev/null +++ b/src/common/compiler_defs.h @@ -0,0 +1,51 @@ +// +// Created by tqcq on 2023/11/22. +// + +#ifndef ULIB_SRC_COMMON_PLATFORM_H_ +#define ULIB_SRC_COMMON_PLATFORM_H_ + +#define ULIB_PLATFORM_WINDOWS 1 +#define ULIB_PLATFORM_UNIX 2 +#define ULIB_PLATFORM_APPLE 3 +#define ULIB_PLATFORM_INTEL 4 + +#if defined(_WIN64) +# define ULIB_PLATFORM ULIB_PLATFORM_WINDOWS +#elif defined(__WIN32__) || defined(WIN32) || defined(_WIN32) +# define ULIB_PLATFORM ULIB_PLATFORM_WINDOWS +#elif defined(__APPLE_CC__) +# define ULIB_PLATFORM ULIB_PLATFORM_APPLE +#elif defined(__INTEL_COMPILER) +# define ULIB_PLATFORM ULIB_PLATFORM_INTEL +#else +# define ULIB_PLATFORM ULIB_PLATFORM_UNIX +#endif + +#define ULIB_COMPILER_GNU 1 +#define ULIB_COMPILER_CLANG 2 + +#ifdef __GUNC__ +# define ULIB_COMPILER ULIB_COMPILER_GNU +#elif __clang__ +# define ULIB_COMPILER ULIB_COMPILER_CLANG +#else +# error "FATAL ERROR: Unknown compiler." +#endif + +namespace tqcq { + +class CompilerDefs { + public: + static bool IsWindows() { return ULIB_PLATFORM == ULIB_PLATFORM_WINDOWS; } + static bool IsUnix() { return ULIB_PLATFORM == ULIB_PLATFORM_UNIX; } + static bool IsApple() { return ULIB_PLATFORM == ULIB_PLATFORM_APPLE; } + static bool IsIntel() { return ULIB_PLATFORM == ULIB_PLATFORM_INTEL; } + + static bool IsGNU() { return ULIB_COMPILER == ULIB_COMPILER_GNU; } + static bool IsClang() { return ULIB_COMPILER == ULIB_COMPILER_CLANG; } +}; + +} // namespace tqcq + +#endif //ULIB_SRC_COMMON_PLATFORM_H_ diff --git a/src/common/define.h b/src/common/define.h new file mode 100644 index 0000000..7389924 --- /dev/null +++ b/src/common/define.h @@ -0,0 +1,23 @@ +// +// Created by tqcq on 2023/11/22. +// + +#ifndef ULIB_SRC_COMMON_DEFINE_H_ +#define ULIB_SRC_COMMON_DEFINE_H_ + +#include "compiler_defs.h" + +#include +#include +#include + +#define int64 int64_t +#define int32 int32_t +#define int16 int16_t +#define int8 int8_t +#define uint64 uint64_t +#define uint32 uint32_t +#define uint16 uint16_t +#define uint8 uint8_t + +#endif//ULIB_SRC_COMMON_DEFINE_H_ diff --git a/src/logging/log.cpp b/src/logging/log.cpp new file mode 100644 index 0000000..9b53c74 --- /dev/null +++ b/src/logging/log.cpp @@ -0,0 +1,8 @@ +// +// Created by tqcq on 2023/11/22. +// + +#include "log.h" + +namespace tqcq { +} // namespace tqcq diff --git a/src/logging/log.h b/src/logging/log.h new file mode 100644 index 0000000..e9fde97 --- /dev/null +++ b/src/logging/log.h @@ -0,0 +1,40 @@ +// +// Created by tqcq on 2023/11/22. +// + +#ifndef ULIB_SRC_LOGGING_LOG_H_ +#define ULIB_SRC_LOGGING_LOG_H_ + +#include +#include "log_common.h" + +namespace tqcq { + +class Log { +private: + Log(); + ~Log(); + +public: + Log(const Log &) = delete; + Log(Log &&) = delete; + Log &operator=(const Log &) = delete; + Log &operator=(Log &&) = delete; + +public: + static Log *instance(); + + void Close(); + bool ShouldLog(const std::string &type, int level); + bool SetLogLevel(const std::string &type, int level); + + template + void OutMessage(const std::string &filter, LogLevel const level, const char *fmt, Args... args) + { + OutMessageImpl(filter, level, fmt, args...); + } +}; + +}// namespace tqcq + +#endif//ULIB_SRC_LOGGING_LOG_H_ diff --git a/src/logging/log_common.h b/src/logging/log_common.h new file mode 100644 index 0000000..3ecdbd6 --- /dev/null +++ b/src/logging/log_common.h @@ -0,0 +1,29 @@ +// +// Created by tqcq on 2023/11/22. +// + +#ifndef ULIB_SRC_LOGGING_LOG_COMMON_H_ +#define ULIB_SRC_LOGGING_LOG_COMMON_H_ + +#include "common/define.h" + +namespace tqcq { + +enum LogLevel : uint8 { + LOG_LEVEL_DISABLED = 0, + LOG_LEVEL_TRACE = 1, + LOG_LEVEL_DEBUG = 2, + LOG_LEVEL_INFO = 3, + LOG_LEVEL_WARN = 4, + LOG_LEVEL_ERROR = 5, + LOG_LEVEL_FATAL = 6, + + NUM_ENABLED_LOG_LEVELS = LOG_LEVEL_FATAL, + LOG_LEVEL_INVALID = 0xFF +}; + +class LogCommon {}; + +}// namespace tqcq + +#endif//ULIB_SRC_LOGGING_LOG_COMMON_H_