github.com/distbuild/reclient@v0.0.0-20240401075343-3de72e395564/internal/pkg/gomaipservice/gomaip.h (about) 1 // Copyright 2023 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef CMD_SCANDEPS_GOMAIPSERVICE_GOMAIP_H_ 16 #define CMD_SCANDEPS_GOMAIPSERVICE_GOMAIP_H_ 17 18 #include <grpcpp/grpcpp.h> 19 20 #include <atomic> 21 #include <condition_variable> 22 #include <ctime> 23 #include <thread> 24 25 #include "api/scandeps/cppscandeps.grpc.pb.h" 26 #include "include_processor.h" 27 28 class GomaIPServiceImpl final : public scandeps::CPPDepsScanner::Service { 29 public: 30 GomaIPServiceImpl(std::function<void()> shutdown_server, 31 const char* process_name, std::string cache_dir, 32 std::string log_dir, int cache_file_max_mb, 33 bool use_deps_cache, uint32_t experimental_deadlock, 34 uint32_t experimental_segfault); 35 ~GomaIPServiceImpl(); 36 grpc::Status ProcessInputs(grpc::ServerContext*, 37 const scandeps::CPPProcessInputsRequest*, 38 scandeps::CPPProcessInputsResponse*) override; 39 grpc::Status Status(grpc::ServerContext*, const google::protobuf::Empty*, 40 scandeps::StatusResponse*) override; 41 grpc::Status Shutdown(grpc::ServerContext*, const google::protobuf::Empty*, 42 scandeps::StatusResponse*) override; 43 grpc::Status Capabilities(grpc::ServerContext*, 44 const google::protobuf::Empty*, 45 scandeps::CapabilitiesResponse*) override; 46 47 private: 48 std::thread init_thread_; 49 std::mutex init_mutex_; 50 std::condition_variable init_cv_; 51 std::time_t started_; 52 std::atomic<std::size_t> current_actions_; 53 std::atomic<std::size_t> completed_actions_; 54 std::function<void()> shutdown_server_; 55 std::unique_ptr<include_processor::IncludeProcessor> deps_scanner_cache_; 56 const char* process_name_; 57 std::string cache_dir_; 58 std::string log_dir_; 59 int cache_file_max_mb_; 60 bool use_deps_cache_; 61 #ifdef _WIN32 62 bool wsa_initialized_; 63 #endif 64 65 // Configurations used for experiments 66 std::mutex exp_mutex_; 67 uint32_t experimental_deadlock_; 68 uint32_t experimental_segfault_; 69 70 void PopulateStatusResponse(scandeps::StatusResponse*); 71 }; 72 73 #endif // CMD_SCANDEPS_GOMAIPSERVICE_GOMAIP_H_