diff options
author | khristich <khristich@yandex-team.ru> | 2022-02-10 16:50:11 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:11 +0300 |
commit | 4488b6dd6356a10e57c74303b91211469ab2ec34 (patch) | |
tree | c186b22d3dc57247df20942ecfb176abe093d306 /util/stream | |
parent | eeb44fff3b21a0abc3a28ecf80df8ea214338f2a (diff) | |
download | ydb-4488b6dd6356a10e57c74303b91211469ab2ec34.tar.gz |
Restoring authorship annotation for <khristich@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/stream')
-rw-r--r-- | util/stream/output.cpp | 172 | ||||
-rw-r--r-- | util/stream/output.h | 4 |
2 files changed, 88 insertions, 88 deletions
diff --git a/util/stream/output.cpp b/util/stream/output.cpp index db81b81b70..98b61c2e95 100644 --- a/util/stream/output.cpp +++ b/util/stream/output.cpp @@ -8,13 +8,13 @@ #include <util/charset/utf8.h> #include <util/charset/wide.h> -#if defined(_android_) +#if defined(_android_) #include <util/system/dynlib.h> #include <util/system/guard.h> #include <util/system/mutex.h> #include <android/log.h> -#endif - +#endif + #include <cerrno> #include <string> #include <string_view> @@ -243,102 +243,102 @@ void Out<TNullPtr>(IOutputStream& o, TTypeTraits<TNullPtr>::TFuncParam) { o << TStringBuf("nullptr"); } -#if defined(_android_) +#if defined(_android_) namespace { - class TAndroidStdIOStreams { - public: - TAndroidStdIOStreams() - : LogLibrary("liblog.so") - , LogFuncPtr((TLogFuncPtr)LogLibrary.Sym("__android_log_write")) - , Out(LogFuncPtr) - , Err(LogFuncPtr) + class TAndroidStdIOStreams { + public: + TAndroidStdIOStreams() + : LogLibrary("liblog.so") + , LogFuncPtr((TLogFuncPtr)LogLibrary.Sym("__android_log_write")) + , Out(LogFuncPtr) + , Err(LogFuncPtr) { } - - public: + + public: using TLogFuncPtr = void (*)(int, const char*, const char*); - + class TAndroidStdOutput: public IOutputStream { - public: + public: inline TAndroidStdOutput(TLogFuncPtr logFuncPtr) noexcept : Buffer() , LogFuncPtr(logFuncPtr) { } - + virtual ~TAndroidStdOutput() { } - - private: - virtual void DoWrite(const void* buf, size_t len) override { + + private: + virtual void DoWrite(const void* buf, size_t len) override { with_lock (BufferMutex) { Buffer.Write(buf, len); } - } - - virtual void DoFlush() override { + } + + virtual void DoFlush() override { with_lock (BufferMutex) { LogFuncPtr(ANDROID_LOG_DEBUG, GetTag(), Buffer.Data()); Buffer.Clear(); } - } - - virtual const char* GetTag() const = 0; - - private: + } + + virtual const char* GetTag() const = 0; + + private: TMutex BufferMutex; - TStringStream Buffer; - TLogFuncPtr LogFuncPtr; - }; - + TStringStream Buffer; + TLogFuncPtr LogFuncPtr; + }; + class TStdErr: public TAndroidStdOutput { - public: - TStdErr(TLogFuncPtr logFuncPtr) - : TAndroidStdOutput(logFuncPtr) + public: + TStdErr(TLogFuncPtr logFuncPtr) + : TAndroidStdOutput(logFuncPtr) { } - + virtual ~TStdErr() { } - - private: - virtual const char* GetTag() const override { - return "stderr"; - } - }; - + + private: + virtual const char* GetTag() const override { + return "stderr"; + } + }; + class TStdOut: public TAndroidStdOutput { - public: - TStdOut(TLogFuncPtr logFuncPtr) - : TAndroidStdOutput(logFuncPtr) + public: + TStdOut(TLogFuncPtr logFuncPtr) + : TAndroidStdOutput(logFuncPtr) { } - + virtual ~TStdOut() { } - - private: - virtual const char* GetTag() const override { - return "stdout"; - } - }; - - static bool Enabled; - TDynamicLibrary LogLibrary; // field order is important, see constructor - TLogFuncPtr LogFuncPtr; - TStdOut Out; - TStdErr Err; - - static inline TAndroidStdIOStreams& Instance() { - return *SingletonWithPriority<TAndroidStdIOStreams, 4>(); - } - }; - - bool TAndroidStdIOStreams::Enabled = false; -} -#endif // _android_ - -namespace { + + private: + virtual const char* GetTag() const override { + return "stdout"; + } + }; + + static bool Enabled; + TDynamicLibrary LogLibrary; // field order is important, see constructor + TLogFuncPtr LogFuncPtr; + TStdOut Out; + TStdErr Err; + + static inline TAndroidStdIOStreams& Instance() { + return *SingletonWithPriority<TAndroidStdIOStreams, 4>(); + } + }; + + bool TAndroidStdIOStreams::Enabled = false; +} +#endif // _android_ + +namespace { class TStdOutput: public IOutputStream { public: inline TStdOutput(FILE* f) noexcept @@ -402,27 +402,27 @@ namespace { } IOutputStream& NPrivate::StdErrStream() noexcept { -#if defined(_android_) - if (TAndroidStdIOStreams::Enabled) { - return TAndroidStdIOStreams::Instance().Err; - } -#endif +#if defined(_android_) + if (TAndroidStdIOStreams::Enabled) { + return TAndroidStdIOStreams::Instance().Err; + } +#endif return TStdIOStreams::Instance().Err; } IOutputStream& NPrivate::StdOutStream() noexcept { -#if defined(_android_) - if (TAndroidStdIOStreams::Enabled) { - return TAndroidStdIOStreams::Instance().Out; - } -#endif +#if defined(_android_) + if (TAndroidStdIOStreams::Enabled) { + return TAndroidStdIOStreams::Instance().Out; + } +#endif return TStdIOStreams::Instance().Out; } - -void RedirectStdioToAndroidLog(bool redirect) { -#if defined(_android_) - TAndroidStdIOStreams::Enabled = redirect; -#else + +void RedirectStdioToAndroidLog(bool redirect) { +#if defined(_android_) + TAndroidStdIOStreams::Enabled = redirect; +#else Y_UNUSED(redirect); -#endif -} +#endif +} diff --git a/util/stream/output.h b/util/stream/output.h index 00eef50b95..61ca03dfbe 100644 --- a/util/stream/output.h +++ b/util/stream/output.h @@ -299,6 +299,6 @@ static inline void Flush(IOutputStream& o) { #include "debug.h" -void RedirectStdioToAndroidLog(bool redirect); - +void RedirectStdioToAndroidLog(bool redirect); + /** @} */ |