From f875913bff6b9b1a94ad5f8425d9336d74a59a53 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Mon, 2 Feb 2015 01:33:03 +0300 Subject: [PATCH] Updated statistics library. - Win compilation fixes. - Removed onWiFi event from Android as it can create unnecessary battery load. --- .../ios/SampleClient.xcodeproj/.gitignore | 2 + .../SampleClient.xcodeproj/project.pbxproj | 10 +- .../contents.xcworkspacedata | 7 - .../xcshareddata/SampleClient.xccheckout | 41 --- .../UserInterfaceState.xcuserstate | Bin 10395 -> 0 bytes .../xcschemes/SampleClient.xcscheme | 110 -------- .../xcschemes/xcschememanagement.plist | 27 -- .../examples/ios/SampleClient/Info.plist | 2 +- 3party/Alohalytics/src/Bricks/exception.h | 58 +++- 3party/Alohalytics/src/Bricks/file/file.h | 58 +++- .../Alohalytics/src/Bricks/rtti/dispatcher.h | 100 +++++++ .../Alohalytics/src/Bricks/rtti/exceptions.h | 38 +++ 3party/Alohalytics/src/Bricks/rtti/test.cc | 262 ++++++++++++++++++ .../exponential_retry_strategy.h | 9 + 3party/Alohalytics/src/FileStorageQueue/fsq.h | 4 +- .../ConnectivityChangedReceiver.java | 2 - .../java/org/alohalytics/Statistics.java | 4 +- 3party/Alohalytics/src/event_base.h | 3 + .../Alohalytics/src/posix/http_client_curl.cc | 9 + 3party/Alohalytics/src/server/demo.cc | 84 ++++++ 20 files changed, 617 insertions(+), 213 deletions(-) create mode 100644 3party/Alohalytics/examples/ios/SampleClient.xcodeproj/.gitignore delete mode 100644 3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.xcworkspace/xcshareddata/SampleClient.xccheckout delete mode 100644 3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.xcworkspace/xcuserdata/alexz.xcuserdatad/UserInterfaceState.xcuserstate delete mode 100644 3party/Alohalytics/examples/ios/SampleClient.xcodeproj/xcuserdata/alexz.xcuserdatad/xcschemes/SampleClient.xcscheme delete mode 100644 3party/Alohalytics/examples/ios/SampleClient.xcodeproj/xcuserdata/alexz.xcuserdatad/xcschemes/xcschememanagement.plist create mode 100644 3party/Alohalytics/src/Bricks/rtti/dispatcher.h create mode 100644 3party/Alohalytics/src/Bricks/rtti/exceptions.h create mode 100644 3party/Alohalytics/src/Bricks/rtti/test.cc create mode 100644 3party/Alohalytics/src/server/demo.cc diff --git a/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/.gitignore b/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/.gitignore new file mode 100644 index 0000000000..7f42cddede --- /dev/null +++ b/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/.gitignore @@ -0,0 +1,2 @@ +project.xcworkspace +xcuserdata diff --git a/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.pbxproj b/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.pbxproj index 2a2092dddb..9272982ad3 100644 --- a/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.pbxproj +++ b/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.pbxproj @@ -267,7 +267,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; @@ -297,7 +297,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.1; + IPHONEOS_DEPLOYMENT_TARGET = 5.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -309,7 +309,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; @@ -333,7 +333,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.1; + IPHONEOS_DEPLOYMENT_TARGET = 5.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -414,6 +414,7 @@ 6BDEF0761A3CF2D100054FAC /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 6BDEF0771A3CF2D100054FAC /* Build configuration list for PBXNativeTarget "SampleClientTests" */ = { isa = XCConfigurationList; @@ -422,6 +423,7 @@ 6BDEF0791A3CF2D100054FAC /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index c1faf5c24c..0000000000 --- a/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.xcworkspace/xcshareddata/SampleClient.xccheckout b/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.xcworkspace/xcshareddata/SampleClient.xccheckout deleted file mode 100644 index ce4126e4ba..0000000000 --- a/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.xcworkspace/xcshareddata/SampleClient.xccheckout +++ /dev/null @@ -1,41 +0,0 @@ - - - - - IDESourceControlProjectFavoriteDictionaryKey - - IDESourceControlProjectIdentifier - DC49AAAD-79F8-48DF-87B1-7B0856F93DB4 - IDESourceControlProjectName - SampleClient - IDESourceControlProjectOriginsDictionary - - B29F426D1BF5D0F0A418F392D1F363C5DC680EA5 - github.com:KnowSheet/AlohaStatsClient.git - - IDESourceControlProjectPath - examples/ios/SampleClient.xcodeproj - IDESourceControlProjectRelativeInstallPathDictionary - - B29F426D1BF5D0F0A418F392D1F363C5DC680EA5 - ../../../.. - - IDESourceControlProjectURL - github.com:KnowSheet/AlohaStatsClient.git - IDESourceControlProjectVersion - 111 - IDESourceControlProjectWCCIdentifier - B29F426D1BF5D0F0A418F392D1F363C5DC680EA5 - IDESourceControlProjectWCConfigurations - - - IDESourceControlRepositoryExtensionIdentifierKey - public.vcs.git - IDESourceControlWCCIdentifierKey - B29F426D1BF5D0F0A418F392D1F363C5DC680EA5 - IDESourceControlWCCName - AlohaStatsClient - - - - diff --git a/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.xcworkspace/xcuserdata/alexz.xcuserdatad/UserInterfaceState.xcuserstate b/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/project.xcworkspace/xcuserdata/alexz.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index 20dddb4e2163d270386719069bef51b5a9c47420..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10395 zcmdT~cU+TK_rD_{fvhJ_CYeyI#VVkJfZ8F`je{YGiV+?mHYAt?1Qk74Yj>+{)mp6z zQb&Eet<~CLr`=2Ko_4o(@4g+s`{W^kSl{>8-{;eRe&r(xcbt3fx#xV(_nzAYEk183 zJbd^ugb_g$$&ef+(9Lv9^`JH(81e@E)q?^H776v?P|YAuu)fL5nkxo{11&tlYqsB} z$2?LXB{Co*GNB>pY%~-NLm4O&Wuf6{1R9SfpowS_nvABPsi+K1L(|a=G!r!;FIt2y zKt9xr{3w80&|=hqE<#tMwP*v{f^I}x(M@O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E8}Ky)!b~Zkz2(1xB$193vm~7 zYq|B@Ms5?gncL0X!rjK*!R_Y`aQAZeaZhn?aUXGCalh%Yp6ccLB)wX%)pL5AK21MN zKUQC;pQfLwuh7rZ*XV2Y0sV4)r+$SV^jGTF>aWqS*KgEs(%+)ruRo-}U;m)~A^mgu zqx$3eSM+b{-`2mYKcPRV|A8mGf=}dCJje6AkvH?{{0RO$zJM>{OZf@>B)*)l=4bPB z_<8&Vdx|bL*Bdt)HyJk@w-|3X z9yC5~eA@V|@ps^n&TQ=@rv!rngP+nogKLF#TjkW{sIQ8_j03-Rv~G&8g-rbH2I6Jjp!8 zTxKpeSDI&;Ys@}#tN9u82j(x#Uz@)*e{aDSqs45oT5J}F#brscoM9Pc8EhGC8EZM$ za=xX&QfwJ-nPiz_DYHzsG+I_$wp#XD9=05_d}U3vrdTtqBds~sTA8b#zpKTvz&#>p(C)+FRv+OnYTD#BQW^cDIwJ*1? zuzzO%&Vd|qhr*HQ&^kB=?=U*-jx!v2j$+4DN3$dBxXy92;~vKW$3e#-#}keh9Y-C< z9j`cEbDVH|;P}Y#iQ_ZJNvFkG>TGpxb?$ZE>b%`~m-BAtJ$JO9k=xTCxxR$v(T`OH( zuFG5-U0YmRUE5tZxpuksxc0j4bRBd(=X%5Srt2-&JFb(iuUy}_zIXlT`q?daYu%ii zcN^Vix7(fSPII5>KFdACJ<>haUF@FWu5eemYut0(^V~jnhkK2ClY5JMo4dz-lY6&& zulrW_9qxVZBkrf%&$yp+zu-RVe%bw+`%U-T?swgvxqnE}rr1(Oq?D%Ari4F yk@9KE*D1fI($s`hWolBYA=R2{OLe5WQirFGN*x=yNg+a{Pr6O|jQ&nN_kRFZa{?~_ diff --git a/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/xcuserdata/alexz.xcuserdatad/xcschemes/SampleClient.xcscheme b/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/xcuserdata/alexz.xcuserdatad/xcschemes/SampleClient.xcscheme deleted file mode 100644 index ef89e60aa5..0000000000 --- a/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/xcuserdata/alexz.xcuserdatad/xcschemes/SampleClient.xcscheme +++ /dev/null @@ -1,110 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/xcuserdata/alexz.xcuserdatad/xcschemes/xcschememanagement.plist b/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/xcuserdata/alexz.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index 7208349db4..0000000000 --- a/3party/Alohalytics/examples/ios/SampleClient.xcodeproj/xcuserdata/alexz.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,27 +0,0 @@ - - - - - SchemeUserState - - SampleClient.xcscheme - - orderHint - 0 - - - SuppressBuildableAutocreation - - 6BDEF0501A3CF2D100054FAC - - primary - - - 6BDEF0691A3CF2D100054FAC - - primary - - - - - diff --git a/3party/Alohalytics/examples/ios/SampleClient/Info.plist b/3party/Alohalytics/examples/ios/SampleClient/Info.plist index 7aa21dbd9a..ee8791cef9 100644 --- a/3party/Alohalytics/examples/ios/SampleClient/Info.plist +++ b/3party/Alohalytics/examples/ios/SampleClient/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - org.alohaclient.$(PRODUCT_NAME:rfc1034identifier) + org.alohalytics.$(PRODUCT_NAME:rfc1034identifier) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/3party/Alohalytics/src/Bricks/exception.h b/3party/Alohalytics/src/Bricks/exception.h index 0a98f31265..f43cfea8aa 100644 --- a/3party/Alohalytics/src/Bricks/exception.h +++ b/3party/Alohalytics/src/Bricks/exception.h @@ -1,12 +1,66 @@ +/******************************************************************************* +The MIT License (MIT) + +Copyright (c) 2014 Dmitry "Dima" Korolev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*******************************************************************************/ + #ifndef BRICKS_EXCEPTIONS_H #define BRICKS_EXCEPTIONS_H #include +#include + +#include "strings/printf.h" namespace bricks { -// TODO(dkorolev): Add string descriptions. -struct Exception : std::exception {}; +class Exception : public std::exception { + public: + Exception(const std::string& what = "") : what_(what) {} + virtual ~Exception() = default; + + void SetWhat(const std::string& what) { what_ = what; } + + // LCOV_EXCL_START + virtual const char* what() const noexcept override { return what_.c_str(); } + // LCOV_EXCL_STOP + + virtual const std::string& What() const noexcept { return what_; } + + void SetCaller(const std::string& caller) { what_ = caller + '\t' + what_; } + + void SetOrigin(const char* file, int line) { what_ = strings::Printf("%s:%d\t", file, line) + what_; } + + private: + std::string what_; +}; + +// Extra parenthesis around `e((E))` are essential to not make it a function declaration. +#define BRICKS_THROW(E) \ + { \ + auto e((E)); \ + e.SetCaller(#E); \ + e.SetOrigin(__FILE__, __LINE__); \ + throw e; \ + } } // namespace bricks diff --git a/3party/Alohalytics/src/Bricks/file/file.h b/3party/Alohalytics/src/Bricks/file/file.h index 884ec768cb..90ae821407 100644 --- a/3party/Alohalytics/src/Bricks/file/file.h +++ b/3party/Alohalytics/src/Bricks/file/file.h @@ -33,8 +33,27 @@ SOFTWARE. #include #include +#ifdef _MSC_VER +#include +#include +struct ScopedCloseFindFileHandle { + HANDLE handle_; + ScopedCloseFindFileHandle(HANDLE handle) : handle_(handle) {} + ~ScopedCloseFindFileHandle() { + ::FindClose(handle_); + } +}; +#else #include #include +struct ScopedCloseDir { + DIR * dir_; + ScopedCloseDir(DIR * dir) : dir_(dir) {} + ~ScopedCloseDir() { + ::closedir(dir_); + } +}; +#endif #include "exceptions.h" #include "../../logger.h" @@ -47,8 +66,8 @@ inline std::string ReadFileAsString(std::string const& file_name) { fi.exceptions(std::ifstream::failbit | std::ifstream::badbit); fi.open(file_name, std::ifstream::binary); fi.seekg(0, std::ios::end); - const size_t size = fi.tellg(); - std::string buffer(size, '\0'); + const std::streampos size = fi.tellg(); + std::string buffer(static_cast(size), '\0'); fi.seekg(0); if (fi.read(&buffer[0], size).good()) { return buffer; @@ -100,17 +119,6 @@ class ScopedRemoveFile final { std::string file_name_; }; -class ScopedCloseDir final { - DIR* dir_; - - public: - explicit ScopedCloseDir(DIR* dir) : dir_(dir) { - } - ~ScopedCloseDir() { - ::closedir(dir_); - } -}; - // Platform-indepenent, injection-friendly filesystem wrapper. struct FileSystem { typedef std::ofstream OutputFile; @@ -148,9 +156,24 @@ struct FileSystem { static inline void ScanDirUntil(const std::string& directory, std::function lambda) { - DIR* dir = ::opendir(directory.c_str()); - const ScopedCloseDir dir_closer(dir); +#ifdef _MSC_VER + WIN32_FIND_DATAA find_data; + HANDLE handle = ::FindFirstFileA(directory.c_str(), &find_data); + if (handle == INVALID_HANDLE_VALUE) { + return; + } + const ScopedCloseFindFileHandle closer(handle); + do { + if (!(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + if (!lambda(find_data.cFileName)) { + return; + } + } + } while (::FindNextFileA(handle, &find_data) != 0); +#else + DIR * dir = ::opendir(directory.c_str()); if (dir) { + const ScopedCloseDir closer(dir); while (struct dirent* entry = ::readdir(dir)) { if (*entry->d_name && ::strcmp(entry->d_name, ".") && ::strcmp(entry->d_name, "..")) { if (!lambda(entry->d_name)) { @@ -159,6 +182,7 @@ struct FileSystem { } } } +#endif } static inline void ScanDir(const std::string& directory, std::function lambda) { @@ -179,8 +203,12 @@ struct FileSystem { } static inline void CreateDirectory(const std::string& directory) { +#ifdef _MSC_VER + ::_mkdir(directory.c_str()); +#else // Hard-code default permissions to avoid cross-platform compatibility issues. ::mkdir(directory.c_str(), 0755); +#endif } }; diff --git a/3party/Alohalytics/src/Bricks/rtti/dispatcher.h b/3party/Alohalytics/src/Bricks/rtti/dispatcher.h new file mode 100644 index 0000000000..112e7c6ace --- /dev/null +++ b/3party/Alohalytics/src/Bricks/rtti/dispatcher.h @@ -0,0 +1,100 @@ +/******************************************************************************* +The MIT License (MIT) + +Copyright (c) 2014 Dmitry "Dima" Korolev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*******************************************************************************/ + +// RTTI-based call dispatching to the handler of the appropriate type. + +#ifndef BRICKS_RTTI_DISPATCHER_H +#define BRICKS_RTTI_DISPATCHER_H + +#include "exceptions.h" + +#include + +namespace bricks { +namespace rtti { + +template +struct RuntimeDispatcher { + typedef BASE T_BASE; + typedef DERIVED T_DERIVED; + template + static void DispatchCall(const TYPE &x, PROCESSOR &c) { + if (const DERIVED *d = dynamic_cast(&x)) { + c(*d); + } else { + RuntimeDispatcher::DispatchCall(x, c); + } + } + template + static void DispatchCall(TYPE &x, PROCESSOR &c) { + if (DERIVED *d = dynamic_cast(&x)) { + c(*d); + } else { + RuntimeDispatcher::DispatchCall(x, c); + } + } +}; + +template +struct RuntimeDispatcher { + typedef BASE T_BASE; + typedef DERIVED T_DERIVED; + template + static void DispatchCall(const TYPE &x, PROCESSOR &c) { + if (const DERIVED *d = dynamic_cast(&x)) { + c(*d); + } else { + const BASE *b = dynamic_cast(&x); + if (b) { + c(*b); + } else { + BRICKS_THROW(UnrecognizedPolymorphicType()); + } + } + } + template + static void DispatchCall(TYPE &x, PROCESSOR &c) { + if (DERIVED *d = dynamic_cast(&x)) { + c(*d); + } else { + BASE *b = dynamic_cast(&x); + if (b) { + c(*b); + } else { + BRICKS_THROW(UnrecognizedPolymorphicType()); + } + } + } +}; + +template +struct RuntimeTupleDispatcher {}; + +template +struct RuntimeTupleDispatcher> : RuntimeDispatcher {}; + +} // namespace rtti +} // namespace bricks + +#endif // BRICKS_RTTI_DISPATCHER_H diff --git a/3party/Alohalytics/src/Bricks/rtti/exceptions.h b/3party/Alohalytics/src/Bricks/rtti/exceptions.h new file mode 100644 index 0000000000..f9856d7b5b --- /dev/null +++ b/3party/Alohalytics/src/Bricks/rtti/exceptions.h @@ -0,0 +1,38 @@ +/******************************************************************************* +The MIT License (MIT) + +Copyright (c) 2014 Dmitry "Dima" Korolev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*******************************************************************************/ + +#ifndef BRICKS_RTTI_EXCEPTIONS_H +#define BRICKS_RTTI_EXCEPTIONS_H + +#include "../exception.h" + +namespace bricks { +namespace rtti { + +struct UnrecognizedPolymorphicType : Exception {}; + +} // namespace rtti +} // namespace bricks + +#endif // BRICKS_RTTI_EXCEPTIONS_H diff --git a/3party/Alohalytics/src/Bricks/rtti/test.cc b/3party/Alohalytics/src/Bricks/rtti/test.cc new file mode 100644 index 0000000000..4b2ff85cbc --- /dev/null +++ b/3party/Alohalytics/src/Bricks/rtti/test.cc @@ -0,0 +1,262 @@ +/******************************************************************************* +The MIT License (MIT) + +Copyright (c) 2014 Dmitry "Dima" Korolev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*******************************************************************************/ + +#include "dispatcher.h" + +#include +#include + +#include "../3party/gtest/gtest-main.h" + +using std::string; +using std::tuple; + +template +struct TypeList; + +struct Base { + // Empty constructor required by clang++. + Base() {} + // Need to define at least one virtual method. + virtual ~Base() = default; +}; +struct Foo : Base { + Foo() {} +}; +struct Bar : Base { + Bar() {} +}; +struct Baz : Base { + Baz() {} +}; + +struct OtherBase { + // Empty constructor required by clang++. + OtherBase() {} + // Need to define at least one virtual method. + virtual ~OtherBase() = default; +}; + +typedef TypeList FooBarBazTypeList; + +struct Processor { + string s; + void operator()(const Base&) { s = "const Base&"; } + void operator()(const Foo&) { s = "const Foo&"; } + void operator()(const Bar&) { s = "const Bar&"; } + void operator()(const Baz&) { s = "const Baz&"; } + void operator()(Base&) { s = "Base&"; } + void operator()(Foo&) { s = "Foo&"; } + void operator()(Bar&) { s = "Bar&"; } + void operator()(Baz&) { s = "Baz&"; } +}; + +TEST(RuntimeDispatcher, StaticCalls) { + Processor p; + EXPECT_EQ("", p.s); + p(Base()); + EXPECT_EQ("const Base&", p.s); + p(Foo()); + EXPECT_EQ("const Foo&", p.s); + p(Bar()); + EXPECT_EQ("const Bar&", p.s); + p(Baz()); + EXPECT_EQ("const Baz&", p.s); +} + +TEST(RuntimeDispatcher, ImmutableStaticCalls) { + const Base base; + const Foo foo; + const Bar bar; + const Baz baz; + Processor p; + EXPECT_EQ("", p.s); + p(base); + EXPECT_EQ("const Base&", p.s); + p(foo); + EXPECT_EQ("const Foo&", p.s); + p(bar); + EXPECT_EQ("const Bar&", p.s); + p(baz); + EXPECT_EQ("const Baz&", p.s); +} + +TEST(RuntimeDispatcher, MutableStaticCalls) { + Base base; + Foo foo; + Bar bar; + Baz baz; + Processor p; + EXPECT_EQ("", p.s); + p(base); + EXPECT_EQ("Base&", p.s); + p(foo); + EXPECT_EQ("Foo&", p.s); + p(bar); + EXPECT_EQ("Bar&", p.s); + p(baz); + EXPECT_EQ("Baz&", p.s); +} + +TEST(RuntimeDispatcher, ImmutableWithoutDispatching) { + const Base base; + const Foo foo; + const Bar bar; + const Baz baz; + const Base& rbase = base; + const Base& rfoo = foo; + const Base& rbar = bar; + const Base& rbaz = baz; + Processor p; + EXPECT_EQ("", p.s); + p(rbase); + EXPECT_EQ("const Base&", p.s); + p(rfoo); + EXPECT_EQ("const Base&", p.s); + p(rbar); + EXPECT_EQ("const Base&", p.s); + p(rbaz); + EXPECT_EQ("const Base&", p.s); +} + +TEST(RuntimeDispatcher, MutableWithoutDispatching) { + Base base; + Foo foo; + Bar bar; + Baz baz; + Base& rbase = base; + Base& rfoo = foo; + Base& rbar = bar; + Base& rbaz = baz; + Processor p; + EXPECT_EQ("", p.s); + p(rbase); + EXPECT_EQ("Base&", p.s); + p(rfoo); + EXPECT_EQ("Base&", p.s); + p(rbar); + EXPECT_EQ("Base&", p.s); + p(rbaz); + EXPECT_EQ("Base&", p.s); +} + +TEST(RuntimeDispatcher, ImmutableWithDispatching) { + const Base base; + const Foo foo; + const Bar bar; + const Baz baz; + const OtherBase other; + const Base& rbase = base; + const Base& rfoo = foo; + const Base& rbar = bar; + const Base& rbaz = baz; + const OtherBase& rother = other; + Processor p; + EXPECT_EQ("", p.s); + bricks::rtti::RuntimeDispatcher::DispatchCall(rbase, p); + EXPECT_EQ("const Base&", p.s); + bricks::rtti::RuntimeDispatcher::DispatchCall(rfoo, p); + EXPECT_EQ("const Foo&", p.s); + bricks::rtti::RuntimeDispatcher::DispatchCall(rbar, p); + EXPECT_EQ("const Bar&", p.s); + bricks::rtti::RuntimeDispatcher::DispatchCall(rbaz, p); + EXPECT_EQ("const Baz&", p.s); + ASSERT_THROW((bricks::rtti::RuntimeDispatcher::DispatchCall(rother, p)), + bricks::rtti::UnrecognizedPolymorphicType); +} + +TEST(RuntimeDispatcher, MutableWithDispatching) { + Base base; + Foo foo; + Bar bar; + Baz baz; + OtherBase other; + Base& rbase = base; + Base& rfoo = foo; + Base& rbar = bar; + Base& rbaz = baz; + OtherBase& rother = other; + Processor p; + EXPECT_EQ("", p.s); + bricks::rtti::RuntimeDispatcher::DispatchCall(rbase, p); + EXPECT_EQ("Base&", p.s); + bricks::rtti::RuntimeDispatcher::DispatchCall(rfoo, p); + EXPECT_EQ("Foo&", p.s); + bricks::rtti::RuntimeDispatcher::DispatchCall(rbar, p); + EXPECT_EQ("Bar&", p.s); + bricks::rtti::RuntimeDispatcher::DispatchCall(rbaz, p); + EXPECT_EQ("Baz&", p.s); + ASSERT_THROW((bricks::rtti::RuntimeDispatcher::DispatchCall(rother, p)), + bricks::rtti::UnrecognizedPolymorphicType); +} + +TEST(RuntimeDispatcher, ImmutableWithTupleTypeListDispatching) { + const Base base; + const Foo foo; + const Bar bar; + const Baz baz; + const OtherBase other; + const Base& rbase = base; + const Base& rfoo = foo; + const Base& rbar = bar; + const Base& rbaz = baz; + const OtherBase& rother = other; + Processor p; + EXPECT_EQ("", p.s); + bricks::rtti::RuntimeTupleDispatcher>::DispatchCall(rbase, p); + EXPECT_EQ("const Base&", p.s); + bricks::rtti::RuntimeTupleDispatcher>::DispatchCall(rfoo, p); + EXPECT_EQ("const Foo&", p.s); + bricks::rtti::RuntimeTupleDispatcher>::DispatchCall(rbar, p); + EXPECT_EQ("const Bar&", p.s); + bricks::rtti::RuntimeTupleDispatcher>::DispatchCall(rbaz, p); + EXPECT_EQ("const Baz&", p.s); + ASSERT_THROW((bricks::rtti::RuntimeDispatcher::DispatchCall(rother, p)), + bricks::rtti::UnrecognizedPolymorphicType); +} + +TEST(RuntimeDispatcher, MutableWithTupleTypeListDispatching) { + Base base; + Foo foo; + Bar bar; + Baz baz; + OtherBase other; + Base& rbase = base; + Base& rfoo = foo; + Base& rbar = bar; + Base& rbaz = baz; + OtherBase& rother = other; + Processor p; + EXPECT_EQ("", p.s); + bricks::rtti::RuntimeTupleDispatcher>::DispatchCall(rbase, p); + EXPECT_EQ("Base&", p.s); + bricks::rtti::RuntimeTupleDispatcher>::DispatchCall(rfoo, p); + EXPECT_EQ("Foo&", p.s); + bricks::rtti::RuntimeTupleDispatcher>::DispatchCall(rbar, p); + EXPECT_EQ("Bar&", p.s); + bricks::rtti::RuntimeTupleDispatcher>::DispatchCall(rbaz, p); + EXPECT_EQ("Baz&", p.s); + ASSERT_THROW((bricks::rtti::RuntimeDispatcher::DispatchCall(rother, p)), + bricks::rtti::UnrecognizedPolymorphicType); +} diff --git a/3party/Alohalytics/src/FileStorageQueue/exponential_retry_strategy.h b/3party/Alohalytics/src/FileStorageQueue/exponential_retry_strategy.h index a7ca820580..3dc0a1accd 100644 --- a/3party/Alohalytics/src/FileStorageQueue/exponential_retry_strategy.h +++ b/3party/Alohalytics/src/FileStorageQueue/exponential_retry_strategy.h @@ -10,6 +10,15 @@ #include "exception.h" #include "../Bricks/time/chrono.h" +#ifdef _MSC_VER +#ifdef max +#undef max +#endif +#ifdef min +#undef min +#endif +#endif // _MSC_VER + namespace fsq { namespace strategy { diff --git a/3party/Alohalytics/src/FileStorageQueue/fsq.h b/3party/Alohalytics/src/FileStorageQueue/fsq.h index 393a742acb..7e9d3a0e37 100644 --- a/3party/Alohalytics/src/FileStorageQueue/fsq.h +++ b/3party/Alohalytics/src/FileStorageQueue/fsq.h @@ -317,7 +317,7 @@ class FSQ final : public CONFIG::T_FILE_NAMING_STRATEGY, // Step 1/4: Get the list of finalized files. typedef std::vector> FileInfoVector; const FileInfoVector& finalized_files_on_disk = ScanDir([this](const std::string& s, T_TIMESTAMP* t) { - return T_FILE_NAMING_STRATEGY::finalized.ParseFileName(s, t); + return this->finalized.ParseFileName(s, t); }); status_.finalized.queue.assign(finalized_files_on_disk.begin(), finalized_files_on_disk.end()); status_.finalized.total_size = 0; @@ -327,7 +327,7 @@ class FSQ final : public CONFIG::T_FILE_NAMING_STRATEGY, // Step 2/4: Get the list of current files. const FileInfoVector& current_files_on_disk = ScanDir([this]( - const std::string& s, T_TIMESTAMP* t) { return T_FILE_NAMING_STRATEGY::current.ParseFileName(s, t); }); + const std::string& s, T_TIMESTAMP* t) { return this->current.ParseFileName(s, t); }); if (!current_files_on_disk.empty()) { const bool resume = T_FILE_RESUME_STRATEGY::ShouldResume(); const size_t number_of_files_to_finalize = current_files_on_disk.size() - (resume ? 1u : 0u); diff --git a/3party/Alohalytics/src/android/java/org/alohalytics/ConnectivityChangedReceiver.java b/3party/Alohalytics/src/android/java/org/alohalytics/ConnectivityChangedReceiver.java index 5254538ffe..7549fa02e5 100644 --- a/3party/Alohalytics/src/android/java/org/alohalytics/ConnectivityChangedReceiver.java +++ b/3party/Alohalytics/src/android/java/org/alohalytics/ConnectivityChangedReceiver.java @@ -52,8 +52,6 @@ public class ConnectivityChangedReceiver extends BroadcastReceiver { } public void onWiFiConnected() { - // TODO(AlexZ): Make it optional. - org.alohalytics.Statistics.logEvent("$onWiFi"); org.alohalytics.Statistics.forceUpload(); } } diff --git a/3party/Alohalytics/src/android/java/org/alohalytics/Statistics.java b/3party/Alohalytics/src/android/java/org/alohalytics/Statistics.java index 2c804ccd6c..db64baceb0 100644 --- a/3party/Alohalytics/src/android/java/org/alohalytics/Statistics.java +++ b/3party/Alohalytics/src/android/java/org/alohalytics/Statistics.java @@ -123,8 +123,8 @@ public class Statistics { private static final String PREF_APP_UPDATE_TIME = "APP_UPDATE_TIME"; // Returns id and true if id was generated or false if id was read from preferences. - // Please note, that only the very first call to getInstallationId can tell the truth. - public synchronized static Pair getInstallationId(final Context context) { + // Please note, that only the very first call to getInstallationId in the app lifetime returns true. + private synchronized static Pair getInstallationId(final Context context) { if (uniqueID == null) { final SharedPreferences sharedPrefs = context.getSharedPreferences( PREF_FILE, Context.MODE_PRIVATE); diff --git a/3party/Alohalytics/src/event_base.h b/3party/Alohalytics/src/event_base.h index 614268f2ce..45dfc429a6 100644 --- a/3party/Alohalytics/src/event_base.h +++ b/3party/Alohalytics/src/event_base.h @@ -33,6 +33,9 @@ #include "cereal/include/cereal.hpp" #include "cereal/include/types/base_class.hpp" #include "cereal/include/types/polymorphic.hpp" +#include "cereal/include/archives/binary.hpp" +#include "cereal/include/types/string.hpp" +#include "cereal/include/types/map.hpp" // For easier processing on a server side, every statistics event should derive from this base class. struct AlohalyticsBaseEvent { diff --git a/3party/Alohalytics/src/posix/http_client_curl.cc b/3party/Alohalytics/src/posix/http_client_curl.cc index b4c17bda82..b6b3b08440 100644 --- a/3party/Alohalytics/src/posix/http_client_curl.cc +++ b/3party/Alohalytics/src/posix/http_client_curl.cc @@ -28,6 +28,11 @@ #include #include // std::cerr +#ifdef _MSC_VER +#define popen _popen +#define pclose _pclose +#endif + // Used as a test stub for basic HTTP client implementation. namespace alohalytics { @@ -54,7 +59,11 @@ bool HTTPClientPlatformWrapper::RunHTTPRequest() { if (!post_body_.empty()) { // POST body through tmp file to avoid breaking command line. char tmp_file[L_tmpnam]; +#ifdef _MSC_VER + ::tmpnam_s(tmp_file, L_tmpnam); +#else ::tmpnam(tmp_file); +#endif std::ofstream(tmp_file) << post_body_; post_file_ = tmp_file; } diff --git a/3party/Alohalytics/src/server/demo.cc b/3party/Alohalytics/src/server/demo.cc new file mode 100644 index 0000000000..cb0e1d05fb --- /dev/null +++ b/3party/Alohalytics/src/server/demo.cc @@ -0,0 +1,84 @@ +/******************************************************************************* + The MIT License (MIT) + + Copyright (c) 2014 Alexander Zolotarev from Minsk, Belarus + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + *******************************************************************************/ + +// Small demo which prints raw (ungzipped) cereal stream from stdin. + +// This define is needed to preserve client's timestamps in events. +#define ALOHALYTICS_SERVER +#include "../event_base.h" + +#include "../Bricks/rtti/dispatcher.h" + +#include +#include +#include + +struct Processor { + void PrintTime(const AlohalyticsBaseEvent & event) { + const time_t timestamp = static_cast(event.timestamp / 1000); + std::cout << std::put_time(std::localtime(×tamp), "%e-%b-%Y %H:%M:%S"); + } + void operator()(const AlohalyticsBaseEvent & event) { + PrintTime(event); + std::cout << "Unhandled event of type " << typeid(event).name() << std::endl; + } + void operator()(const AlohalyticsIdEvent & event) { + PrintTime(event); + std::cout << " ID: " << event.id << std::endl; + } + void operator()(const AlohalyticsKeyEvent & event) { + PrintTime(event); + std::cout << ' ' << event.key << std::endl; + } + void operator()(const AlohalyticsKeyValueEvent & event) { + PrintTime(event); + std::cout << ' ' << event.key << " = " << event.value << std::endl; + } + void operator()(const AlohalyticsKeyPairsEvent & event) { + PrintTime(event); + std::cout << ' ' << event.key << " [ "; + for (const auto & pair : event.pairs) { + std::cout << pair.first << '=' << pair.second << ' '; + } + std::cout << ']' << std::endl; + } +}; + +int main(int, char **) { + cereal::BinaryInputArchive ar(std::cin); + Processor processor; + try { + while (std::cin.good()) { + std::unique_ptr ptr; + ar(ptr); + bricks::rtti::RuntimeDispatcher::DispatchCall(*ptr, processor); + } + } catch (const cereal::Exception & ex) { + } + return 0; +}