From 5b1149d52c74390d632bc8195cf418109ed90fe7 Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Tue, 22 Jun 2021 17:14:19 +0200
Subject: [PATCH] update grpc, styling, renamed caosdb_config to constants

---
 CMakeLists.txt                                |   6 +-
 cmake/FetchGRPC.cmake                         | 191 +++++++-----------
 include/CMakeLists.txt                        |   6 +-
 include/connection.h                          |  24 ++-
 .../{caosdb_config.h.in => constants.h.in}    |   0
 src/caosdbcli.cpp                             |   9 +-
 src/connection.cpp                            |  35 +++-
 test/test_connection.cpp                      |   3 +-
 8 files changed, 130 insertions(+), 144 deletions(-)
 rename include/{caosdb_config.h.in => constants.h.in} (100%)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index eeba1f5..84c7103 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -143,7 +143,7 @@ ${_PROTOBUF_LIBPROTOBUF})
 
 # These variables slightly modify the install location to allow for version
 # specific installations.
-option(INSTALL_DIR_NAME "libcaosdb-${libcaosdb_VERSION}")
+set(INSTALL_DIR_NAME "libcaosdb-${libcaosdb_VERSION}")
 set(libcaosdb_INCLUDE_DEST "include/${INSTALL_DIR_NAME}")
 set(libcaosdb_LIB_DEST "lib/${INSTALL_DIR_NAME}")
 
@@ -194,9 +194,7 @@ install(
     TARGETS
         caosdb
         caosdb_info_v1alpha1
-        #${_REFLECTION}
-        #${_GRPC_GRPCPP}
-        #${_PROTOBUF_LIBPROTOBUF}
+        ${_GRPC_DEPS}
     # name of the CMake "export group" containing the targets we want to install
     EXPORT caosdbTargets
     # Dynamic, static library and include destination locations after running
diff --git a/cmake/FetchGRPC.cmake b/cmake/FetchGRPC.cmake
index e9af5ff..7b4b368 100644
--- a/cmake/FetchGRPC.cmake
+++ b/cmake/FetchGRPC.cmake
@@ -35,7 +35,7 @@ set(gRPC_BUILD_GRPC_PHP_PLUGIN OFF)
 set(gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN OFF)
 set(gRPC_BUILD_GRPC_NODE_PLUGIN OFF)
 set(protobuf_BUILD_TESTS OFF)
-set(vGRPC_TAG_VERSION_OF_YOUR_CHOICE "v1.38.0")
+set(vGRPC_TAG_VERSION_OF_YOUR_CHOICE "v1.38.1")
 
 if(GRPC_AS_SUBMODULE)
   # One way to build a projects that uses gRPC is to just include the
@@ -87,7 +87,7 @@ elseif(GRPC_FETCHCONTENT)
     # v1.25.0, v1.26.0 etc..
     # For the purpose of testing, we override the tag used to the commit
     # that's currently under test.
-    GIT_TAG        vGRPC_TAG_VERSION_OF_YOUR_CHOICE
+    GIT_TAG         ${vGRPC_TAG_VERSION_OF_YOUR_CHOICE}
     GIT_SHALLOW     1)
   FetchContent_MakeAvailable(grpc)
 
@@ -97,137 +97,98 @@ elseif(GRPC_FETCHCONTENT)
   set(_REFLECTION grpc++_reflection)
   set(_PROTOBUF_PROTOC $<TARGET_FILE:protoc>)
   set(_GRPC_GRPCPP grpc++)
+  set(_GRPC_GRPC grpc)
   if(CMAKE_CROSSCOMPILING)
     find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
   else()
     set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:grpc_cpp_plugin>)
   endif()
 
-  ## disable more unused stuff
-  set_target_properties(
-    zlibstatic
+  set(_GRPC_DEPS
+    grpc++
+    grpc
+    grpc++_reflection
     libprotobuf
-    libprotoc
-    grpc_plugin_support
-    grpc_cpp_plugin
-    upb
+    zlibstatic
     address_sorting
-    absl_log_severity
-    absl_raw_logging_internal
-    absl_bad_optional_access
-    absl_spinlock_wait
+    upb
+    absl_flat_hash_map
+    absl_inlined_vector
+    absl_bind_front
+    absl_statusor
+    gpr
+    ssl
+    crypto
+    absl_container_memory
+    absl_hash_function_defaults
+    absl_raw_hash_map
+    absl_algorithm_container
+    absl_memory
+    absl_algorithm
+    absl_core_headers
+    absl_inlined_vector_internal
     absl_throw_delegate
+    absl_base_internal
+    absl_compressed_tuple
+    absl_status
+    absl_raw_logging_internal
+    absl_type_traits
+    absl_strings
+    absl_utility
+    absl_variant
     absl_base
-    absl_malloc_internal
-    absl_debugging_internal
+    absl_str_format
+    absl_synchronization
+    absl_time
+    absl_optional
+    absl_cord
+    absl_hash
+    absl_raw_hash_set
+    absl_meta
+    absl_span
+    absl_atomic_hook
     absl_stacktrace
+    absl_symbolize
+    absl_log_severity
     absl_strings_internal
+    absl_bits
+    absl_endian
     absl_int128
-    absl_strings
-    absl_demangle_internal
-    absl_symbolize
+    absl_bad_variant_access
+    absl_dynamic_annotations
+    absl_spinlock_wait
     absl_str_format_internal
-    absl_cord
-    absl_status
+    absl_graphcycles_internal
+    absl_kernel_timeout_internal
+    absl_malloc_internal
     absl_civil_time
     absl_time_zone
-    absl_time
-    absl_graphcycles_internal
-    absl_synchronization
-    gpr
-    absl_exponential_biased
-    absl_hashtablez_sampler
-    absl_raw_hash_set
-    absl_wyhash
+    absl_bad_optional_access
+    absl_config
+    absl_fixed_array
+    absl_function_ref
     absl_city
-    absl_bad_variant_access
-    absl_hash
-    absl_statusor
-    c-ares
-    re2
-    ssl
-    crypto
-    gen_hpack_tables
-    gen_legal_metadata_characters
-    check_epollexclusive
-    grpcpp_channelz
-    gen_percent_encoding_tables
-    grpc++_error_details
-    grpc_unsecure
-    grpc++_alts
-    grpc++_unsecure
-    absl_strerror
-    absl_periodic_sampler
-    absl_scoped_set_env
-    absl_examine_stack
-    absl_failure_signal_handler
-    absl_leak_check
-    absl_leak_check_disable
-    absl_flags_program_name
-    absl_flags_config
-    absl_flags_commandlineflag_internal
-    absl_flags_commandlineflag
-    absl_flags_private_handle_accessor
-    absl_flags_reflection
-    absl_flags_marshalling
-    absl_flags_internal
-    absl_flags
-    absl_flags_usage_internal
-    absl_flags_usage
-    absl_flags_parse
-    absl_random_seed_gen_exception
-    absl_random_internal_seed_material
-    absl_random_internal_platform
-    absl_random_internal_randen_slow
-    absl_random_internal_randen_hwaes_impl
-    absl_random_internal_randen_hwaes
-    absl_random_internal_randen
-    absl_random_internal_pool_urbg
-    absl_random_distributions
-    absl_random_seed_sequences
-    absl_random_internal_distribution_test_util
-    absl_bad_any_cast_impl
-    acountry
-    adig
-    ahost
-    libprotobuf-lite
-    testing
-    search_test
-    regexp_test
-    possible_match_test
-    mimics_pcre_test
-    parse_test
-    required_prefix_test
-    filtered_re2_test
-    compile_test
-    re2_arg_test
-    charclass_test
-    exhaustive1_test
-    re2_test
-    simplify_test
-    string_generator_test
-    dfa_test
-    exhaustive3_test
-    exhaustive2_test
-    exhaustive_test
-    regexp_benchmark
-    random_test
-    set_test
-    bssl
-    zlib
-    example64
-    minigzip
-    example
-    minigzip64
-    grpc
-    grpc++
-    protoc
-    grpc++_reflection
-    PROPERTIES
-    CXX_CLANG_TIDY ""
-    CXX_INCLUDE_WHAT_YOU_USE ""
-    EXCLUDE_FROM_ALL 1
+    absl_wyhash
+    absl_container_common
+    absl_hash_policy_traits
+    absl_hashtable_debug_hooks
+    absl_have_sse
+    absl_layout
+    absl_hashtablez_sampler
+    absl_debugging_internal
+    absl_demangle_internal
+    absl_errno_saver
+    absl_numeric_representation
+    absl_exponential_biased
   )
+
+  ## disable more unused stuff
+  #set_target_properties(${_GRPC_DEPS}
+    #PROPERTIES
+    #CXX_CLANG_TIDY ""
+    #CXX_INCLUDE_WHAT_YOU_USE ""
+    #EXCLUDE_FROM_ALL 1
+  #)
 else()
   # This branch assumes that gRPC and all its dependencies are already installed
   # on this system, so they can be located by find_package().
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index 47e9f53..1b6533f 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -20,12 +20,12 @@
 
 # add all header files to this list
 set(libcaosdb_INCL
-    ${CMAKE_CURRENT_BINARY_DIR}/caosdb_config.h
+    ${CMAKE_CURRENT_BINARY_DIR}/constants.h
     ${CMAKE_CURRENT_SOURCE_DIR}/connection.h
     )
 
 # pass variable to parent scope
 set(libcaosdb_INCL ${libcaosdb_INCL} PARENT_SCOPE)
 
-# initialize build variables
-configure_file(caosdb_config.h.in caosdb_config.h)
+# initialize constants
+configure_file(constants.h.in constants.h)
diff --git a/include/connection.h b/include/connection.h
index 5317099..80a1de1 100644
--- a/include/connection.h
+++ b/include/connection.h
@@ -28,13 +28,15 @@
  * @date 2021-05-18
  * @brief Configuration and setup of the connection.
  */
-#include "caosdb/info/v1alpha1/main.grpc.pb.h"
 #include <string>
+#include <iosfwd>
+#include <memory>
 #include <grpc/grpc.h>
 #include <grpcpp/channel.h>
 #include <grpcpp/client_context.h>
 #include <grpcpp/create_channel.h>
 #include <grpcpp/security/credentials.h>
+#include "caosdb/info/v1alpha1/main.grpc.pb.h"
 
 namespace caosdb {
 using caosdb::info::v1alpha1::GeneralInfoService;
@@ -57,21 +59,25 @@ public:
   [[nodiscard]] auto virtual toString() const -> std::string = 0;
   [[nodiscard]] auto getHost() const -> std::string;
   [[nodiscard]] auto getPort() const -> int;
-  [[nodiscard]] auto virtual getChannelCredentials() const -> std::shared_ptr<ChannelCredentials> = 0;
+  [[nodiscard]] auto virtual getChannelCredentials() const
+    -> std::shared_ptr<ChannelCredentials> = 0;
 };
 
-class InsecureCaosDBConnectionConfig: public CaosDBConnectionConfig {
+class InsecureCaosDBConnectionConfig : public CaosDBConnectionConfig {
 private:
   std::shared_ptr<ChannelCredentials> credentials;
+
 public:
   InsecureCaosDBConnectionConfig(const std::string &host, int port);
   [[nodiscard]] auto toString() const -> std::string override;
-  [[nodiscard]] auto getChannelCredentials() const -> std::shared_ptr<ChannelCredentials> override;
+  [[nodiscard]] auto getChannelCredentials() const
+    -> std::shared_ptr<ChannelCredentials> override;
 };
 
-class SslCaosDBConnectionConfig: public CaosDBConnectionConfig {
+class SslCaosDBConnectionConfig : public CaosDBConnectionConfig {
   SslCaosDBConnectionConfig(const std::string &host, int port);
-  SslCaosDBConnectionConfig(const std::string &host, int port, std::string cacert);
+  SslCaosDBConnectionConfig(const std::string &host, int port,
+                            std::string cacert);
 };
 
 /**
@@ -82,10 +88,12 @@ class CaosDBConnection {
   std::unique_ptr<GeneralInfoService::Stub> stub_;
 
 public:
-  explicit CaosDBConnection(const std::shared_ptr<CaosDBConnectionConfig> &config);
+  explicit CaosDBConnection(
+    const std::shared_ptr<CaosDBConnectionConfig> &config);
   friend auto operator<<(std::ostream &out, const CaosDBConnection &connection)
     -> std::ostream &;
-  [[nodiscard]] auto getGeneralInfoService() const -> GeneralInfoService::Stub &;
+  [[nodiscard]] auto getGeneralInfoService() const
+    -> GeneralInfoService::Stub &;
   [[nodiscard]] auto getVersionInfo() const -> const VersionInfo &;
 };
 } // namespace caosdb
diff --git a/include/caosdb_config.h.in b/include/constants.h.in
similarity index 100%
rename from include/caosdb_config.h.in
rename to include/constants.h.in
diff --git a/src/caosdbcli.cpp b/src/caosdbcli.cpp
index 0b5e3f3..e5c95da 100644
--- a/src/caosdbcli.cpp
+++ b/src/caosdbcli.cpp
@@ -22,9 +22,10 @@
 
 // A simple caosdb client
 #include <iostream>
+#include <memory>
 #include <string>
 #include "caosdb/info/v1alpha1/main.pb.h"
-#include "caosdb_config.h"
+#include "constants.h"
 #include "connection.h"
 
 auto main() -> int {
@@ -40,14 +41,16 @@ auto main() -> int {
   const std::string &test = host;
   std::cout << test << std::endl;
 
-  std::shared_ptr<caosdb::InsecureCaosDBConnectionConfig> config = std::make_shared<caosdb::InsecureCaosDBConnectionConfig>(host, port);
+  std::shared_ptr<caosdb::InsecureCaosDBConnectionConfig> config =
+    std::make_shared<caosdb::InsecureCaosDBConnectionConfig>(host, port);
   caosdb::CaosDBConnection connection(config);
   std::cout << std::endl << connection << std::endl;
   const caosdb::info::v1alpha1::VersionInfo &v_info =
     connection.getVersionInfo();
   const std::string &build = v_info.build();
   std::cout << "BUILD(" << build[0] << ")" << std::endl;
-  std::cout << "VersionInfo(" << v_info.major() << "." << v_info.minor() << "." << v_info.patch() << ")" << std::endl;
+  std::cout << "VersionInfo(" << v_info.major() << "." << v_info.minor() << "."
+            << v_info.patch() << ")" << std::endl;
   std::cout << "PRE_RELEASE(" << v_info.pre_release() << ")" << std::endl;
   return 0;
 }
diff --git a/src/connection.cpp b/src/connection.cpp
index d52e15d..87ae072 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -21,10 +21,15 @@
  */
 
 #include "connection.h"
-#include "caosdb/info/v1alpha1/main.grpc.pb.h"
+#include <grpcpp/create_channel.h>
+#include <grpcpp/impl/codegen/client_context.h>
+#include <grpcpp/impl/codegen/status.h>
+#include <grpcpp/security/credentials.h>
 #include <iostream>
-#include <string>
 #include <stdexcept>
+#include <string>
+#include "caosdb/info/v1alpha1/main.grpc.pb.h"
+#include "caosdb/info/v1alpha1/main.pb.h"
 
 namespace caosdb {
 using caosdb::info::v1alpha1::GeneralInfoService;
@@ -39,7 +44,9 @@ CaosDBConnectionConfig::CaosDBConnectionConfig(const std::string &host,
   this->port = port;
 }
 
-auto CaosDBConnectionConfig::getHost() const -> std::string { return this->host; }
+auto CaosDBConnectionConfig::getHost() const -> std::string {
+  return this->host;
+}
 
 auto CaosDBConnectionConfig::getPort() const -> int { return this->port; }
 
@@ -49,22 +56,29 @@ auto operator<<(std::ostream &out, const CaosDBConnectionConfig &config)
   return out;
 }
 
-InsecureCaosDBConnectionConfig::InsecureCaosDBConnectionConfig(const std::string &host, int port) : CaosDBConnectionConfig(host, port) {
+InsecureCaosDBConnectionConfig::InsecureCaosDBConnectionConfig(
+  const std::string &host, int port)
+  : CaosDBConnectionConfig(host, port) {
   this->credentials = grpc::InsecureChannelCredentials();
 }
 
 auto InsecureCaosDBConnectionConfig::toString() const -> std::string {
-  return "InsecureCaosDBConnectionConfig(" + this->getHost() + "," + std::to_string(this->getPort()) + ")";
+  return "InsecureCaosDBConnectionConfig(" + this->getHost() + "," +
+         std::to_string(this->getPort()) + ")";
 }
 
-auto InsecureCaosDBConnectionConfig::getChannelCredentials() const -> std::shared_ptr<ChannelCredentials> {
+auto InsecureCaosDBConnectionConfig::getChannelCredentials() const
+  -> std::shared_ptr<ChannelCredentials> {
   return this->credentials;
 }
 
-CaosDBConnection::CaosDBConnection(const std::shared_ptr<CaosDBConnectionConfig> &config) {
+CaosDBConnection::CaosDBConnection(
+  const std::shared_ptr<CaosDBConnectionConfig> &config) {
   this->config = config;
-  const std::string &target = this->config->getHost() + ":" + std::to_string(this->config->getPort());
-  const std::shared_ptr<grpc::Channel> &channel = grpc::CreateChannel(target, this->config->getChannelCredentials());
+  const std::string &target =
+    this->config->getHost() + ":" + std::to_string(this->config->getPort());
+  const std::shared_ptr<grpc::Channel> &channel =
+    grpc::CreateChannel(target, this->config->getChannelCredentials());
   this->stub_ = GeneralInfoService::NewStub(channel);
 }
 
@@ -74,7 +88,8 @@ auto operator<<(std::ostream &out, const CaosDBConnection &connection)
   return out;
 }
 
-auto CaosDBConnection::getGeneralInfoService() const -> GeneralInfoService::Stub & {
+auto CaosDBConnection::getGeneralInfoService() const
+  -> GeneralInfoService::Stub & {
   return *stub_;
 }
 
diff --git a/test/test_connection.cpp b/test/test_connection.cpp
index 5ddfc94..b8d4d53 100644
--- a/test/test_connection.cpp
+++ b/test/test_connection.cpp
@@ -32,6 +32,7 @@ TEST(test_connection, localhost_8080) {
 
   ASSERT_EQ("localhost", config.getHost());
   ASSERT_EQ(8000, config.getPort());
-  std::shared_ptr<grpc::ChannelCredentials> icc = config.getChannelCredentials();
+  std::shared_ptr<grpc::ChannelCredentials> icc =
+    config.getChannelCredentials();
   ASSERT_TRUE(icc != nullptr);
 }
-- 
GitLab