diff --git a/base/cvd/cuttlefish/host/commands/casimir_control_server/BUILD.bazel b/base/cvd/cuttlefish/host/commands/casimir_control_server/BUILD.bazel index 5e0c947ee14..3f56201dc30 100644 --- a/base/cvd/cuttlefish/host/commands/casimir_control_server/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/casimir_control_server/BUILD.bazel @@ -9,10 +9,7 @@ package( cf_cc_binary( name = "casimir_control_server", - srcs = [ - "main.cpp", - ], - clang_format_enabled = False, + srcs = ["main.cpp"], deps = [ ":libcasimir", ":libcasimir_control_server", diff --git a/base/cvd/cuttlefish/host/commands/casimir_control_server/main.cpp b/base/cvd/cuttlefish/host/commands/casimir_control_server/main.cpp index c11118d7433..3789dbce3f1 100644 --- a/base/cvd/cuttlefish/host/commands/casimir_control_server/main.cpp +++ b/base/cvd/cuttlefish/host/commands/casimir_control_server/main.cpp @@ -19,13 +19,13 @@ #include #include -#include -#include -#include -#include -#include #include "absl/log/log.h" #include "absl/strings/escaping.h" +#include "gflags/gflags.h" +#include "google/protobuf/empty.pb.h" +#include "grpcpp/ext/proto_server_reflection_plugin.h" +#include "grpcpp/grpcpp.h" +#include "grpcpp/health_check_service_interface.h" #include "cuttlefish/host/commands/casimir_control_server/casimir_control.grpc.pb.h" #include "cuttlefish/host/commands/casimir_control_server/casimir_controller.h" @@ -207,8 +207,8 @@ class CasimirControlServiceImpl final : public CasimirControlService::Service { std::vector bytes = CF_EXPECT(device_->SendApdu(id, std::move(apdu_bytes[i])), "Failed to send APDU bytes"); - std::string resp = absl::BytesToHexString( - std::string_view(reinterpret_cast(bytes.data()), bytes.size())); + std::string resp = absl::BytesToHexString(std::string_view( + reinterpret_cast(bytes.data()), bytes.size())); response->add_response_hex_strings(std::move(resp)); } diff --git a/base/cvd/cuttlefish/host/commands/cvdalloc/BUILD.bazel b/base/cvd/cuttlefish/host/commands/cvdalloc/BUILD.bazel index 6d809ae0308..fc83b638d08 100644 --- a/base/cvd/cuttlefish/host/commands/cvdalloc/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/cvdalloc/BUILD.bazel @@ -42,10 +42,7 @@ cf_cc_library( cf_cc_binary( name = "cvdalloc", - srcs = [ - "cvdalloc.cpp", - ], - clang_format_enabled = False, + srcs = ["cvdalloc.cpp"], deps = [ ":interface", ":privilege", diff --git a/base/cvd/cuttlefish/host/commands/cvdalloc/cvdalloc.cpp b/base/cvd/cuttlefish/host/commands/cvdalloc/cvdalloc.cpp index b53799ab176..f54ac6e59eb 100644 --- a/base/cvd/cuttlefish/host/commands/cvdalloc/cvdalloc.cpp +++ b/base/cvd/cuttlefish/host/commands/cvdalloc/cvdalloc.cpp @@ -13,21 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include #include -#include #include "absl/cleanup/cleanup.h" #include "absl/flags/flag.h" #include "absl/flags/parse.h" #include "absl/log/log.h" -#include "absl/strings/str_format.h" #include "allocd/alloc_utils.h" #include "cuttlefish/common/libs/fs/shared_fd.h" -#include "cuttlefish/common/libs/fs/shared_select.h" #include "cuttlefish/host/commands/cvdalloc/interface.h" #include "cuttlefish/host/commands/cvdalloc/privilege.h" #include "cuttlefish/host/commands/cvdalloc/sem.h" @@ -83,8 +79,8 @@ Result Teardown(int id, std::string_view ethernet_bridge_name, } // namespace -Result CvdallocMain(int argc, char *argv[]) { - std::vector args = absl::ParseCommandLine(argc, argv); +Result CvdallocMain(int argc, char* argv[]) { + std::vector args = absl::ParseCommandLine(argc, argv); if (absl::GetFlag(FLAGS_id) == 0 || absl::GetFlag(FLAGS_socket) == 0) { Usage(); @@ -103,9 +99,7 @@ Result CvdallocMain(int argc, char *argv[]) { return CF_ERRNO("close: " << StrError(errno)); } - absl::Cleanup shutdown = [sock]() { - sock->Shutdown(SHUT_RDWR); - }; + absl::Cleanup shutdown = [sock]() { sock->Shutdown(SHUT_RDWR); }; /* * Save our current uid, so we can restore it to drop privileges later. @@ -131,7 +125,8 @@ Result CvdallocMain(int argc, char *argv[]) { Teardown(id, kCvdallocEthernetBridgeName, kCvdallocWirelessBridgeName); }; - CF_EXPECT(Allocate(id, kCvdallocEthernetBridgeName, kCvdallocWirelessBridgeName)); + CF_EXPECT( + Allocate(id, kCvdallocEthernetBridgeName, kCvdallocWirelessBridgeName)); CF_EXPECT(cvdalloc::Post(sock)); LOG(INFO) << "cvdalloc: waiting to teardown"; @@ -145,7 +140,7 @@ Result CvdallocMain(int argc, char *argv[]) { } // namespace cuttlefish -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { auto res = cuttlefish::CvdallocMain(argc, argv); if (!res.ok()) { LOG(ERROR) << "cvdalloc failed: \n" << res.error(); diff --git a/base/cvd/cuttlefish/host/commands/defaults/BUILD.bazel b/base/cvd/cuttlefish/host/commands/defaults/BUILD.bazel index 0c305ffa71b..282f67c38c8 100644 --- a/base/cvd/cuttlefish/host/commands/defaults/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/defaults/BUILD.bazel @@ -6,10 +6,7 @@ package( cf_cc_binary( name = "cf_defaults", - srcs = [ - "defaults.cpp", - ], - clang_format_enabled = False, + srcs = ["defaults.cpp"], deps = [ "//cuttlefish/common/libs/key_equals_value", "//cuttlefish/host/libs/web/http_client:curl_http_client", diff --git a/base/cvd/cuttlefish/host/commands/defaults/defaults.cpp b/base/cvd/cuttlefish/host/commands/defaults/defaults.cpp index f56c4984fa8..4637ef4af19 100644 --- a/base/cvd/cuttlefish/host/commands/defaults/defaults.cpp +++ b/base/cvd/cuttlefish/host/commands/defaults/defaults.cpp @@ -27,7 +27,8 @@ #include "cuttlefish/host/libs/web/http_client/curl_http_client.h" #include "cuttlefish/host/libs/web/http_client/http_string.h" -ABSL_FLAG(std::string, filename, "/usr/lib/cuttlefish-common/etc/cf_defaults", "Output filename."); +ABSL_FLAG(std::string, filename, "/usr/lib/cuttlefish-common/etc/cf_defaults", + "Output filename."); ABSL_FLAG(std::optional, static_defaults_when, std::nullopt, "Specify a key-value pair as \"=\". " "The key should be a metadata path, e.g., 'project/project-id'. " @@ -48,7 +49,7 @@ Result MetadataValue(std::string_view key) { } Result> ParseKeyValueFlag( - const std::string &flag) { + const std::string& flag) { std::map> kvs = CF_EXPECT(ParseKeyEqualsValue(flag)); CF_EXPECT(kvs.size() == 1); @@ -62,7 +63,7 @@ Result> ParseKeyValueFlag( * For example, if the flag value is `project/project-id=testing`, * static defaults will only be used if running in the `testing` project. */ -Result UseStaticDefaults(const std::optional &flag) { +Result UseStaticDefaults(const std::optional& flag) { if (!flag.has_value()) { LOG(INFO) << "Will not use static defaults."; return false; @@ -73,7 +74,8 @@ Result UseStaticDefaults(const std::optional &flag) { Result> kv = CF_EXPECT(ParseKeyValueFlag(flag.value()), "Couldn't parse key-value pair to find in metadata, " - "got: " << flag.value()); + "got: " + << flag.value()); /* Does the key exist? If so, then get the value. */ std::string actual = @@ -81,12 +83,12 @@ Result UseStaticDefaults(const std::optional &flag) { "Couldn't get value at metadata path " << kv->first); std::string expected = kv->second; - /* Is the value expected? */ + /* Is the value expected? */ if (actual != expected) { // No error, but do not use static defaults. LOG(WARNING) << absl::StrFormat( - "Metadata value for %s unexpected, got: '%s', expected '%s'", - kv->first, actual, expected); + "Metadata value for %s unexpected, got: '%s', expected '%s'", kv->first, + actual, expected); } return actual == expected; } @@ -106,8 +108,8 @@ std::map StaticDefaults() { } // namespace -Result DefaultsMain(int argc, char *argv[]) { - std::vector args = absl::ParseCommandLine(argc, argv); +Result DefaultsMain(int argc, char* argv[]) { + std::vector args = absl::ParseCommandLine(argc, argv); std::string filename = absl::GetFlag(FLAGS_filename); LOG(INFO) << "Writing to " << filename; @@ -132,7 +134,7 @@ Result DefaultsMain(int argc, char *argv[]) { } // namespace cuttlefish -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { auto res = cuttlefish::DefaultsMain(argc, argv); if (!res.ok()) { LOG(ERROR) << "defaults failed: \n" << res.error(); diff --git a/base/cvd/cuttlefish/host/commands/display/BUILD.bazel b/base/cvd/cuttlefish/host/commands/display/BUILD.bazel index c4e6865ffdd..2e6121bd8f7 100644 --- a/base/cvd/cuttlefish/host/commands/display/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/display/BUILD.bazel @@ -6,10 +6,7 @@ package( cf_cc_binary( name = "cvd_internal_display", - srcs = [ - "main.cpp", - ], - clang_format_enabled = False, + srcs = ["main.cpp"], deps = [ "//cuttlefish/common/libs/fs", "//cuttlefish/common/libs/utils:files", @@ -21,7 +18,6 @@ cf_cc_binary( "//cuttlefish/host/libs/config:display", "//cuttlefish/host/libs/vm_manager", "//cuttlefish/result", - "//libbase", "@abseil-cpp//absl/base:no_destructor", ], ) diff --git a/base/cvd/cuttlefish/host/commands/display/main.cpp b/base/cvd/cuttlefish/host/commands/display/main.cpp index 43cc5bd2a40..b4e6ff98f83 100644 --- a/base/cvd/cuttlefish/host/commands/display/main.cpp +++ b/base/cvd/cuttlefish/host/commands/display/main.cpp @@ -21,12 +21,11 @@ #include #include "absl/base/no_destructor.h" -#include #include "cuttlefish/common/libs/utils/files.h" +#include "cuttlefish/common/libs/utils/tee_logging.h" #include "cuttlefish/flag_parser/flag.h" #include "cuttlefish/flag_parser/gflags_compat.h" -#include "cuttlefish/common/libs/utils/tee_logging.h" #include "cuttlefish/host/libs/command_util/runner/run_cvd.pb.h" #include "cuttlefish/host/libs/command_util/util.h" #include "cuttlefish/host/libs/config/cuttlefish_config.h" @@ -105,8 +104,7 @@ Result DoHelp(std::vector& args) { return 0; } - static const absl::NoDestructor< - std::unordered_map> + static const absl::NoDestructor> kSubCommandUsages({ {"add", kAddUsage}, {"list", kListUsage}, @@ -155,7 +153,7 @@ Result DoRemove(std::vector& args) { std::vector displays; const std::vector remove_displays_flags = { - Flag::StringFlag(kDisplayFlag) + Flag::StringFlag(kDisplayFlag) .Help("Display id of a display to remove.") .Setter([&](std::string_view arg) -> Result { displays.emplace_back(arg); diff --git a/base/cvd/cuttlefish/host/commands/gnss_grpc_proxy/BUILD.bazel b/base/cvd/cuttlefish/host/commands/gnss_grpc_proxy/BUILD.bazel index 2b4ec100e64..d32eaf90e18 100644 --- a/base/cvd/cuttlefish/host/commands/gnss_grpc_proxy/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/gnss_grpc_proxy/BUILD.bazel @@ -9,10 +9,7 @@ package( cf_cc_binary( name = "gnss_grpc_proxy", - srcs = [ - "gnss_grpc_proxy.cpp", - ], - clang_format_enabled = False, + srcs = ["gnss_grpc_proxy.cpp"], deps = [ ":libcvd_gnss_grpc_proxy", "//cuttlefish/common/libs/fs", diff --git a/base/cvd/cuttlefish/host/commands/gnss_grpc_proxy/gnss_grpc_proxy.cpp b/base/cvd/cuttlefish/host/commands/gnss_grpc_proxy/gnss_grpc_proxy.cpp index a26e5eae07c..caf172be276 100644 --- a/base/cvd/cuttlefish/host/commands/gnss_grpc_proxy/gnss_grpc_proxy.cpp +++ b/base/cvd/cuttlefish/host/commands/gnss_grpc_proxy/gnss_grpc_proxy.cpp @@ -15,9 +15,7 @@ */ #include -#include #include -#include #include #include #include @@ -25,17 +23,15 @@ #include #include -#include "absl/strings/str_split.h" -#include -#include -#include -#include -#include -#include -#include -#include #include "absl/log/log.h" #include "absl/strings/match.h" +#include "absl/strings/str_split.h" +#include "gflags/gflags.h" +#include "grpcpp/ext/proto_server_reflection_plugin.h" +#include "grpcpp/health_check_service_interface.h" +#include "grpcpp/server.h" +#include "grpcpp/server_builder.h" +#include "grpcpp/server_context.h" #include "cuttlefish/common/libs/fs/shared_buf.h" #include "cuttlefish/common/libs/fs/shared_fd.h" @@ -43,30 +39,24 @@ #include "cuttlefish/host/libs/config/logging.h" using gnss_grpc_proxy::GnssGrpcProxy; -using gnss_grpc_proxy::SendGpsReply; -using gnss_grpc_proxy::SendGpsRequest; using gnss_grpc_proxy::SendGpsCoordinatesReply; using gnss_grpc_proxy::SendGpsCoordinatesRequest; +using gnss_grpc_proxy::SendGpsReply; +using gnss_grpc_proxy::SendGpsRequest; using grpc::Server; using grpc::ServerBuilder; using grpc::ServerContext; using grpc::Status; -DEFINE_int32(gnss_in_fd, - -1, - "File descriptor for the gnss's input channel"); -DEFINE_int32(gnss_out_fd, - -1, - "File descriptor for the gnss's output channel"); +DEFINE_int32(gnss_in_fd, -1, "File descriptor for the gnss's input channel"); +DEFINE_int32(gnss_out_fd, -1, "File descriptor for the gnss's output channel"); DEFINE_int32(fixed_location_in_fd, -1, "File descriptor for the fixed location input channel"); DEFINE_int32(fixed_location_out_fd, -1, "File descriptor for the fixed location output channel"); -DEFINE_int32(gnss_grpc_port, - -1, - "Service port for gnss grpc"); +DEFINE_int32(gnss_grpc_port, -1, "Service port for gnss grpc"); DEFINE_string(gnss_grpc_socket, "", "Service socket path for gnss grpc"); DEFINE_string(gnss_file_path, "", @@ -94,30 +84,28 @@ std::string GenerateGpsLine(const std::string& dataPoint) { } // Logic and data behind the server's behavior. class GnssGrpcProxyServiceImpl final : public GnssGrpcProxy::Service { - public: - GnssGrpcProxyServiceImpl(cuttlefish::SharedFD gnss_in, - cuttlefish::SharedFD gnss_out, - cuttlefish::SharedFD fixed_location_in, - cuttlefish::SharedFD fixed_location_out) - : gnss_in_(gnss_in), - gnss_out_(gnss_out), - fixed_location_in_(fixed_location_in), - fixed_location_out_(fixed_location_out) { - //Set the default GPS delay to 1 second - fixed_locations_delay_=1000; - } - - - Status SendGps(ServerContext* context, const SendGpsRequest* request, - SendGpsReply* reply) override { - reply->set_reply("Received gps record"); - std::lock_guard lock(cached_fixed_location_mutex); - cached_fixed_location = request->gps(); - return Status::OK; - } - - - std::string ConvertCoordinate(gnss_grpc_proxy::GpsCoordinates coordinate){ + public: + GnssGrpcProxyServiceImpl(cuttlefish::SharedFD gnss_in, + cuttlefish::SharedFD gnss_out, + cuttlefish::SharedFD fixed_location_in, + cuttlefish::SharedFD fixed_location_out) + : gnss_in_(gnss_in), + gnss_out_(gnss_out), + fixed_location_in_(fixed_location_in), + fixed_location_out_(fixed_location_out) { + // Set the default GPS delay to 1 second + fixed_locations_delay_ = 1000; + } + + Status SendGps(ServerContext* context, const SendGpsRequest* request, + SendGpsReply* reply) override { + reply->set_reply("Received gps record"); + std::lock_guard lock(cached_fixed_location_mutex); + cached_fixed_location = request->gps(); + return Status::OK; + } + + std::string ConvertCoordinate(gnss_grpc_proxy::GpsCoordinates coordinate) { std::string latitude = std::to_string(coordinate.latitude()); std::string longitude = std::to_string(coordinate.longitude()); std::string elevation = std::to_string(coordinate.elevation()); @@ -125,273 +113,271 @@ class GnssGrpcProxyServiceImpl final : public GnssGrpcProxy::Service { return result; } - Status SendGpsVector(ServerContext* context, - const SendGpsCoordinatesRequest* request, - SendGpsCoordinatesReply* reply) override { - reply->set_status(SendGpsCoordinatesReply::OK);//update protobuf reply - { - std::lock_guard lock(fixed_locations_queue_mutex_); - // Reset local buffers - fixed_locations_queue_ = {}; - // Make a local copy of the input buffers - for (auto loc : request->coordinates()) { - fixed_locations_queue_.push(ConvertCoordinate(loc)); - } - fixed_locations_delay_ = request->delay(); - } - - return Status::OK; - } - - void sendToSerial() { - std::lock_guard lock(cached_fixed_location_mutex); - ssize_t bytes_written = cuttlefish::WriteAll( - fixed_location_in_, cached_fixed_location + END_OF_MSG_MARK); - if (bytes_written < 0) { - LOG(ERROR) << "Error writing to fd: " << gnss_in_->StrError(); + Status SendGpsVector(ServerContext* context, + const SendGpsCoordinatesRequest* request, + SendGpsCoordinatesReply* reply) override { + reply->set_status(SendGpsCoordinatesReply::OK); // update protobuf reply + { + std::lock_guard lock(fixed_locations_queue_mutex_); + // Reset local buffers + fixed_locations_queue_ = {}; + // Make a local copy of the input buffers + for (auto loc : request->coordinates()) { + fixed_locations_queue_.push(ConvertCoordinate(loc)); } + fixed_locations_delay_ = request->delay(); } - void sendGnssRawToSerial() { - std::lock_guard lock(cached_gnss_raw_mutex); - if (!isGnssRawMeasurement(cached_gnss_raw)) { - return; - } - if (previous_cached_gnss_raw == cached_gnss_raw) { - // Skip for same record - return; - } else { - // Update cached data - VLOG(0) << "Skip same record"; - previous_cached_gnss_raw = cached_gnss_raw; - } - ssize_t bytes_written = - cuttlefish::WriteAll(gnss_in_, cached_gnss_raw + END_OF_MSG_MARK); - VLOG(0) << "Send Gnss Raw to serial: bytes_written: " << bytes_written; - if (bytes_written < 0) { - LOG(ERROR) << "Error writing to fd: " << gnss_in_->StrError(); - } - } + return Status::OK; + } - void StartServer() { - // Create a new thread to handle writes to the gnss and to the any client - // connected to the socket. - fixed_location_write_thread_ = - std::thread([this]() { WriteFixedLocationFromQueue(); }); - measurement_read_thread_ = - std::thread([this]() { ReadMeasurementLoop(); }); - fixed_location_read_thread_ = - std::thread([this]() { ReadFixedLocLoop(); }); + void sendToSerial() { + std::lock_guard lock(cached_fixed_location_mutex); + ssize_t bytes_written = cuttlefish::WriteAll( + fixed_location_in_, cached_fixed_location + END_OF_MSG_MARK); + if (bytes_written < 0) { + LOG(ERROR) << "Error writing to fd: " << gnss_in_->StrError(); } + } - void StartReadFixedLocationFileThread() { - // Create a new thread to read fixed_location data. - fixed_location_file_read_thread_ = - std::thread([this]() { ReadFixedLocationFromLocalFile(); }); + void sendGnssRawToSerial() { + std::lock_guard lock(cached_gnss_raw_mutex); + if (!isGnssRawMeasurement(cached_gnss_raw)) { + return; } - - void StartReadGnssRawMeasurementFileThread() { - // Create a new thread to read raw measurement data. - measurement_file_read_thread_ = - std::thread([this]() { ReadGnssRawMeasurement(); }); + if (previous_cached_gnss_raw == cached_gnss_raw) { + // Skip for same record + return; + } else { + // Update cached data + VLOG(0) << "Skip same record"; + previous_cached_gnss_raw = cached_gnss_raw; } + ssize_t bytes_written = + cuttlefish::WriteAll(gnss_in_, cached_gnss_raw + END_OF_MSG_MARK); + VLOG(0) << "Send Gnss Raw to serial: bytes_written: " << bytes_written; + if (bytes_written < 0) { + LOG(ERROR) << "Error writing to fd: " << gnss_in_->StrError(); + } + } - void ReadFixedLocationFromLocalFile() { - std::ifstream file(FLAGS_fixed_location_file_path); - if (file.is_open()) { - std::string line; - while (std::getline(file, line)) { - /* Only support fix location format to make it simple. - * Records will only contains 'Fix' prefix. - * Sample line: - * Fix,GPS,37.7925002,-122.3979132,13.462797,0.000000,48.000000,0.000000,1593029872254,0.581968,0.000000 - * Sending at 1Hz, currently user should provide a fixed location - * file that has one location per second. need some extra work to - * make it more generic, i.e. align with the timestamp in the file. - */ - { - std::lock_guard lock(cached_fixed_location_mutex); - cached_fixed_location = line; - } - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + void StartServer() { + // Create a new thread to handle writes to the gnss and to the any client + // connected to the socket. + fixed_location_write_thread_ = + std::thread([this]() { WriteFixedLocationFromQueue(); }); + measurement_read_thread_ = std::thread([this]() { ReadMeasurementLoop(); }); + fixed_location_read_thread_ = std::thread([this]() { ReadFixedLocLoop(); }); + } + + void StartReadFixedLocationFileThread() { + // Create a new thread to read fixed_location data. + fixed_location_file_read_thread_ = + std::thread([this]() { ReadFixedLocationFromLocalFile(); }); + } + + void StartReadGnssRawMeasurementFileThread() { + // Create a new thread to read raw measurement data. + measurement_file_read_thread_ = + std::thread([this]() { ReadGnssRawMeasurement(); }); + } + + void ReadFixedLocationFromLocalFile() { + std::ifstream file(FLAGS_fixed_location_file_path); + if (file.is_open()) { + std::string line; + while (std::getline(file, line)) { + /* Only support fix location format to make it simple. + * Records will only contains 'Fix' prefix. + * Sample line: + * Fix,GPS,37.7925002,-122.3979132,13.462797,0.000000,48.000000,0.000000,1593029872254,0.581968,0.000000 + * Sending at 1Hz, currently user should provide a fixed location + * file that has one location per second. need some extra work to + * make it more generic, i.e. align with the timestamp in the file. + */ + { + std::lock_guard lock(cached_fixed_location_mutex); + cached_fixed_location = line; } - file.close(); - } else { - LOG(ERROR) << "Can not open fixed location file: " - << FLAGS_gnss_file_path; - return; + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } + file.close(); + } else { + LOG(ERROR) << "Can not open fixed location file: " + << FLAGS_gnss_file_path; + return; } + } - void ReadGnssRawMeasurement() { - std::ifstream file(FLAGS_gnss_file_path); + void ReadGnssRawMeasurement() { + std::ifstream file(FLAGS_gnss_file_path); - if (file.is_open()) { - std::string line; - std::string cached_line = ""; - std::string header = ""; + if (file.is_open()) { + std::string line; + std::string cached_line = ""; + std::string header = ""; - while (!cached_line.empty() || std::getline(file, line)) { - if (!cached_line.empty()) { - line = cached_line; - cached_line = ""; - } + while (!cached_line.empty() || std::getline(file, line)) { + if (!cached_line.empty()) { + line = cached_line; + cached_line = ""; + } - // Get data header. - if (header.empty() && absl::StartsWith(line, "# Raw")) { - header = line; - VLOG(0) << "Header: " << header; - continue; - } + // Get data header. + if (header.empty() && absl::StartsWith(line, "# Raw")) { + header = line; + VLOG(0) << "Header: " << header; + continue; + } - // Ignore not raw measurement data. - if (!absl::StartsWith(line, "Raw")) { - continue; - } + // Ignore not raw measurement data. + if (!absl::StartsWith(line, "Raw")) { + continue; + } - { - std::lock_guard lock(cached_gnss_raw_mutex); - cached_gnss_raw = header + "\n" + line; - - std::string new_line = ""; - while (std::getline(file, new_line)) { - // Group raw data by TimeNanos. - if (getTimeNanosFromLine(new_line) == - getTimeNanosFromLine(line)) { - cached_gnss_raw += "\n" + new_line; - } else { - cached_line = new_line; - break; - } + { + std::lock_guard lock(cached_gnss_raw_mutex); + cached_gnss_raw = header + "\n" + line; + + std::string new_line = ""; + while (std::getline(file, new_line)) { + // Group raw data by TimeNanos. + if (getTimeNanosFromLine(new_line) == getTimeNanosFromLine(line)) { + cached_gnss_raw += "\n" + new_line; + } else { + cached_line = new_line; + break; } } - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } - file.close(); - } else { - LOG(ERROR) << "Can not open GNSS Raw file: " << FLAGS_gnss_file_path; - return; + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } + file.close(); + } else { + LOG(ERROR) << "Can not open GNSS Raw file: " << FLAGS_gnss_file_path; + return; } + } - ~GnssGrpcProxyServiceImpl() { - if (fixed_location_file_read_thread_.joinable()) { - fixed_location_file_read_thread_.join(); - } - if (fixed_location_write_thread_.joinable()) { - fixed_location_write_thread_.join(); - } - if (measurement_file_read_thread_.joinable()) { - measurement_file_read_thread_.join(); + ~GnssGrpcProxyServiceImpl() { + if (fixed_location_file_read_thread_.joinable()) { + fixed_location_file_read_thread_.join(); + } + if (fixed_location_write_thread_.joinable()) { + fixed_location_write_thread_.join(); + } + if (measurement_file_read_thread_.joinable()) { + measurement_file_read_thread_.join(); + } + if (measurement_read_thread_.joinable()) { + measurement_read_thread_.join(); + } + if (fixed_location_read_thread_.joinable()) { + fixed_location_read_thread_.join(); + } + } + + private: + void SendCommand(std::string command, cuttlefish::SharedFD source_out, + int out_fd) { + std::vector buffer(GNSS_SERIAL_BUFFER_SIZE); + std::string cmd_str; + auto bytes_read = source_out->Read(buffer.data(), buffer.size()); + if (bytes_read > 0) { + std::string s(buffer.data(), bytes_read); + cmd_str += s; + // In case random string sent though /dev/gnss1, cmd_str will + // auto resize, to get rid of first page. + if (cmd_str.size() > GNSS_SERIAL_BUFFER_SIZE * 2) { + cmd_str = cmd_str.substr(cmd_str.size() - GNSS_SERIAL_BUFFER_SIZE); } - if (measurement_read_thread_.joinable()) { - measurement_read_thread_.join(); + if (cmd_str.find(command) != std::string::npos) { + if (command == CMD_GET_RAWMEASUREMENT) { + sendGnssRawToSerial(); + } else if (command == CMD_GET_LOCATION) { + sendToSerial(); + } + cmd_str = ""; } - if (fixed_location_read_thread_.joinable()) { - fixed_location_read_thread_.join(); + } else { + if (source_out->GetErrno() == EAGAIN || + source_out->GetErrno() == EWOULDBLOCK) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } else { + LOG(ERROR) << "Error reading fd " << out_fd << ": " + << " Error code: " << source_out->GetErrno() + << " Error sg:" << source_out->StrError(); } } + } + + [[noreturn]] void ReadMeasurementLoop() { + int flags = gnss_out_->Fcntl(F_GETFL, 0); + gnss_out_->Fcntl(F_SETFL, flags | O_NONBLOCK); - private: - void SendCommand(std::string command, cuttlefish::SharedFD source_out, - int out_fd) { - std::vector buffer(GNSS_SERIAL_BUFFER_SIZE); - std::string cmd_str; - auto bytes_read = source_out->Read(buffer.data(), buffer.size()); - if (bytes_read > 0) { - std::string s(buffer.data(), bytes_read); - cmd_str += s; - // In case random string sent though /dev/gnss1, cmd_str will - // auto resize, to get rid of first page. - if (cmd_str.size() > GNSS_SERIAL_BUFFER_SIZE * 2) { - cmd_str = cmd_str.substr(cmd_str.size() - GNSS_SERIAL_BUFFER_SIZE); - } - if (cmd_str.find(command) != std::string::npos) { - if (command == CMD_GET_RAWMEASUREMENT) { - sendGnssRawToSerial(); - } else if (command == CMD_GET_LOCATION) { - sendToSerial(); - } - cmd_str = ""; - } - } else { - if (source_out->GetErrno() == EAGAIN || - source_out->GetErrno() == EWOULDBLOCK) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } else { - LOG(ERROR) << "Error reading fd " << out_fd << ": " - << " Error code: " << source_out->GetErrno() - << " Error sg:" << source_out->StrError(); - } - } - } - - [[noreturn]] void ReadMeasurementLoop() { - int flags = gnss_out_->Fcntl(F_GETFL, 0); - gnss_out_->Fcntl(F_SETFL, flags | O_NONBLOCK); - - while (true) { - SendCommand(CMD_GET_RAWMEASUREMENT, gnss_out_, FLAGS_gnss_out_fd); - } - } - - [[noreturn]] void ReadFixedLocLoop() { - int flags2 = fixed_location_out_->Fcntl(F_GETFL, 0); - fixed_location_out_->Fcntl(F_SETFL, flags2 | O_NONBLOCK); - while (true) { - SendCommand(CMD_GET_LOCATION, fixed_location_out_, - FLAGS_fixed_location_out_fd); - } - } - - [[noreturn]] void WriteFixedLocationFromQueue() { - while (true) { - if (!fixed_locations_queue_.empty()) { - std::string dataPoint = fixed_locations_queue_.front(); - std::string line = GenerateGpsLine(dataPoint); - std::lock_guard lock(cached_fixed_location_mutex); - cached_fixed_location = line; - { - std::lock_guard lock(fixed_locations_queue_mutex_); - fixed_locations_queue_.pop(); - } - } - std::this_thread::sleep_for(std::chrono::milliseconds(fixed_locations_delay_)); - } - } - - std::string getTimeNanosFromLine(const std::string& line) { - // TimeNanos is in column #3. - std::vector vals = absl::StrSplit(line, ','); - return vals.size() >= 3 ? vals[2] : "-1"; + while (true) { + SendCommand(CMD_GET_RAWMEASUREMENT, gnss_out_, FLAGS_gnss_out_fd); } + } - bool isGnssRawMeasurement(const std::string& inputStr) { - // TODO: add more logic check to by pass invalid data. - return !inputStr.empty() && absl::StartsWith(inputStr, "# Raw"); + [[noreturn]] void ReadFixedLocLoop() { + int flags2 = fixed_location_out_->Fcntl(F_GETFL, 0); + fixed_location_out_->Fcntl(F_SETFL, flags2 | O_NONBLOCK); + while (true) { + SendCommand(CMD_GET_LOCATION, fixed_location_out_, + FLAGS_fixed_location_out_fd); } + } - cuttlefish::SharedFD gnss_in_; - cuttlefish::SharedFD gnss_out_; - cuttlefish::SharedFD fixed_location_in_; - cuttlefish::SharedFD fixed_location_out_; + [[noreturn]] void WriteFixedLocationFromQueue() { + while (true) { + if (!fixed_locations_queue_.empty()) { + std::string dataPoint = fixed_locations_queue_.front(); + std::string line = GenerateGpsLine(dataPoint); + std::lock_guard lock(cached_fixed_location_mutex); + cached_fixed_location = line; + { + std::lock_guard lock(fixed_locations_queue_mutex_); + fixed_locations_queue_.pop(); + } + } + std::this_thread::sleep_for( + std::chrono::milliseconds(fixed_locations_delay_)); + } + } - std::thread measurement_read_thread_; - std::thread fixed_location_read_thread_; - std::thread fixed_location_file_read_thread_; - std::thread fixed_location_write_thread_; - std::thread measurement_file_read_thread_; + std::string getTimeNanosFromLine(const std::string& line) { + // TimeNanos is in column #3. + std::vector vals = absl::StrSplit(line, ','); + return vals.size() >= 3 ? vals[2] : "-1"; + } + + bool isGnssRawMeasurement(const std::string& inputStr) { + // TODO: add more logic check to by pass invalid data. + return !inputStr.empty() && absl::StartsWith(inputStr, "# Raw"); + } + + cuttlefish::SharedFD gnss_in_; + cuttlefish::SharedFD gnss_out_; + cuttlefish::SharedFD fixed_location_in_; + cuttlefish::SharedFD fixed_location_out_; - std::string cached_fixed_location; - std::mutex cached_fixed_location_mutex; + std::thread measurement_read_thread_; + std::thread fixed_location_read_thread_; + std::thread fixed_location_file_read_thread_; + std::thread fixed_location_write_thread_; + std::thread measurement_file_read_thread_; - std::string cached_gnss_raw; - std::string previous_cached_gnss_raw; - std::mutex cached_gnss_raw_mutex; + std::string cached_fixed_location; + std::mutex cached_fixed_location_mutex; - std::queue fixed_locations_queue_; - std::mutex fixed_locations_queue_mutex_; - int fixed_locations_delay_; + std::string cached_gnss_raw; + std::string previous_cached_gnss_raw; + std::mutex cached_gnss_raw_mutex; + + std::queue fixed_locations_queue_; + std::mutex fixed_locations_queue_mutex_; + int fixed_locations_delay_; }; void RunServer() { @@ -441,8 +427,9 @@ void RunServer() { service.StartReadFixedLocationFileThread(); service.StartReadGnssRawMeasurementFileThread(); - // In the local mode, we are not start a grpc server, use a infinite loop instead - while(true) { + // In the local mode, we are not start a grpc server, use a infinite loop + // instead + while (true) { std::this_thread::sleep_for(std::chrono::milliseconds(2000)); } } else { @@ -473,10 +460,8 @@ void RunServer() { // responsible for shutting down the server for this call to ever return. server->Wait(); } - } - int main(int argc, char** argv) { cuttlefish::DefaultSubprocessLogging(argv); ::gflags::ParseCommandLineFlags(&argc, &argv, true); diff --git a/base/cvd/cuttlefish/host/commands/host_bugreport/BUILD.bazel b/base/cvd/cuttlefish/host/commands/host_bugreport/BUILD.bazel index e9bb9f4211c..f544a8764e5 100644 --- a/base/cvd/cuttlefish/host/commands/host_bugreport/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/host_bugreport/BUILD.bazel @@ -7,7 +7,6 @@ package( cf_cc_binary( name = "cvd_internal_host_bugreport", srcs = ["main.cc"], - clang_format_enabled = False, deps = [ "//cuttlefish/common/libs/fs", "//cuttlefish/common/libs/utils:environment", diff --git a/base/cvd/cuttlefish/host/commands/host_bugreport/main.cc b/base/cvd/cuttlefish/host/commands/host_bugreport/main.cc index dc62ee7d962..596bbae096f 100644 --- a/base/cvd/cuttlefish/host/commands/host_bugreport/main.cc +++ b/base/cvd/cuttlefish/host/commands/host_bugreport/main.cc @@ -16,13 +16,13 @@ #include -#include -#include -#include -#include #include "absl/log/check.h" #include "absl/log/log.h" #include "absl/strings/str_join.h" +#include "android-base/file.h" +#include "android-base/strings.h" +#include "fmt/format.h" +#include "gflags/gflags.h" #include "cuttlefish/common/libs/fs/shared_fd.h" #include "cuttlefish/common/libs/utils/environment.h" @@ -125,8 +125,9 @@ Result AddAdbBugreport(const CuttlefishConfig::InstanceSpecific& instance, // the fact that something was missing/inaccessible is still useful debugging // information. void TakeHostBugreport(const CuttlefishConfig* config, WritableZip& archive) { - LogError(AddFileAt(archive, config->AssemblyPath(kLogNameAssembleCvd), - absl::StrCat("cuttlefish_assembly", "/", kLogNameAssembleCvd))); + LogError( + AddFileAt(archive, config->AssemblyPath(kLogNameAssembleCvd), + absl::StrCat("cuttlefish_assembly", "/", kLogNameAssembleCvd))); LogError(AddFileAt(archive, config->AssemblyPath("cuttlefish_config.json"), "cuttlefish_assembly/cuttlefish_config.json")); diff --git a/base/cvd/cuttlefish/host/commands/log_tee/BUILD.bazel b/base/cvd/cuttlefish/host/commands/log_tee/BUILD.bazel index af1d6955ef6..e66b7945e12 100644 --- a/base/cvd/cuttlefish/host/commands/log_tee/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/log_tee/BUILD.bazel @@ -6,10 +6,7 @@ package( cf_cc_binary( name = "log_tee", - srcs = [ - "log_tee.cpp", - ], - clang_format_enabled = False, + srcs = ["log_tee.cpp"], deps = [ "//cuttlefish/common/libs/fs", "//cuttlefish/common/libs/utils:tee_logging", diff --git a/base/cvd/cuttlefish/host/commands/log_tee/log_tee.cpp b/base/cvd/cuttlefish/host/commands/log_tee/log_tee.cpp index b144ae54c5e..dd6185e1a90 100644 --- a/base/cvd/cuttlefish/host/commands/log_tee/log_tee.cpp +++ b/base/cvd/cuttlefish/host/commands/log_tee/log_tee.cpp @@ -20,11 +20,11 @@ #include -#include "absl/strings/ascii.h" -#include #include "absl/log/check.h" #include "absl/log/log.h" +#include "absl/strings/ascii.h" #include "absl/strings/match.h" +#include "gflags/gflags.h" #include "cuttlefish/common/libs/fs/shared_fd.h" #include "cuttlefish/common/libs/utils/tee_logging.h" @@ -69,13 +69,13 @@ int main(int argc, char** argv) { auto instance = config->ForDefaultInstance(); if (instance.run_as_daemon()) { - cuttlefish::LogToFiles({instance.launcher_log_path()}); + cuttlefish::LogToFiles({instance.launcher_log_path()}); } else { - cuttlefish::LogToStderrAndFiles({instance.launcher_log_path()}); + cuttlefish::LogToStderrAndFiles({instance.launcher_log_path()}); } auto log_fd = cuttlefish::SharedFD::Dup(FLAGS_log_fd_in); - CHECK(log_fd->IsOpen()) << "Failed to dup log_fd_in: " << log_fd->StrError(); + CHECK(log_fd->IsOpen()) << "Failed to dup log_fd_in: " << log_fd->StrError(); close(FLAGS_log_fd_in); if (!FLAGS_process_name.empty()) { diff --git a/base/cvd/cuttlefish/host/commands/logcat_receiver/BUILD.bazel b/base/cvd/cuttlefish/host/commands/logcat_receiver/BUILD.bazel index babf2b1403f..cd95ec56fb1 100644 --- a/base/cvd/cuttlefish/host/commands/logcat_receiver/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/logcat_receiver/BUILD.bazel @@ -6,10 +6,7 @@ package( cf_cc_binary( name = "logcat_receiver", - srcs = [ - "main.cpp", - ], - clang_format_enabled = False, + srcs = ["main.cpp"], deps = [ "//cuttlefish/common/libs/fs", "//cuttlefish/host/libs/config:config_instance_derived", diff --git a/base/cvd/cuttlefish/host/commands/logcat_receiver/main.cpp b/base/cvd/cuttlefish/host/commands/logcat_receiver/main.cpp index 4918d62d283..fd875c3e97f 100644 --- a/base/cvd/cuttlefish/host/commands/logcat_receiver/main.cpp +++ b/base/cvd/cuttlefish/host/commands/logcat_receiver/main.cpp @@ -16,9 +16,9 @@ #include -#include #include "absl/log/check.h" #include "absl/log/log.h" +#include "gflags/gflags.h" #include "cuttlefish/common/libs/fs/shared_buf.h" #include "cuttlefish/common/libs/fs/shared_fd.h" @@ -42,8 +42,7 @@ int main(int argc, char** argv) { auto instance = config->ForDefaultInstance(); // Disable default handling of SIGPIPE - struct sigaction new_action { - }, old_action{}; + struct sigaction new_action{}, old_action{}; new_action.sa_handler = SIG_IGN; sigaction(SIGPIPE, &new_action, &old_action); @@ -63,8 +62,8 @@ int main(int argc, char** argv) { } auto path = cuttlefish::LogcatPath(instance); - auto logcat_file = - cuttlefish::SharedFD::Open(path.c_str(), O_CREAT | O_APPEND | O_WRONLY, 0666); + auto logcat_file = cuttlefish::SharedFD::Open( + path.c_str(), O_CREAT | O_APPEND | O_WRONLY, 0666); // Server loop while (true) { diff --git a/base/cvd/cuttlefish/host/commands/modem_simulator/BUILD.bazel b/base/cvd/cuttlefish/host/commands/modem_simulator/BUILD.bazel index c8da18422fa..12f36ba8ac2 100644 --- a/base/cvd/cuttlefish/host/commands/modem_simulator/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/modem_simulator/BUILD.bazel @@ -10,7 +10,6 @@ cf_cc_library( name = "channel_monitor", srcs = ["channel_monitor.cpp"], hdrs = ["channel_monitor.h"], - clang_format_enabled = False, deps = [ "//cuttlefish/common/libs/fs", "//cuttlefish/host/commands/modem_simulator:client", @@ -36,7 +35,6 @@ cf_cc_library( name = "command_parser", srcs = ["command_parser.cpp"], hdrs = ["command_parser.h"], - clang_format_enabled = False, deps = [ "//libbase", "@abseil-cpp//absl/strings", @@ -53,7 +51,6 @@ cf_cc_library( name = "data_service", srcs = ["data_service.cpp"], hdrs = ["data_service.h"], - clang_format_enabled = False, deps = [ "//cuttlefish/host/commands/modem_simulator:device_config", "//cuttlefish/host/commands/modem_simulator:modem_service", @@ -163,10 +160,7 @@ cf_cc_library( cf_cc_binary( name = "modem_simulator", - srcs = [ - "main.cpp", - ], - clang_format_enabled = False, + srcs = ["main.cpp"], deps = [ "//cuttlefish/common/libs/fs", "//cuttlefish/common/libs/utils:tee_logging", diff --git a/base/cvd/cuttlefish/host/commands/modem_simulator/channel_monitor.cpp b/base/cvd/cuttlefish/host/commands/modem_simulator/channel_monitor.cpp index b8f64818680..959060e7581 100644 --- a/base/cvd/cuttlefish/host/commands/modem_simulator/channel_monitor.cpp +++ b/base/cvd/cuttlefish/host/commands/modem_simulator/channel_monitor.cpp @@ -18,8 +18,8 @@ #include -#include "absl/strings/str_replace.h" #include "absl/log/log.h" +#include "absl/strings/str_replace.h" #include "cuttlefish/common/libs/fs/shared_select.h" #include "cuttlefish/host/commands/modem_simulator/virtual_modem_simulator.h" @@ -68,13 +68,15 @@ ClientId ChannelMonitor::SetRemoteClient(SharedFD client, bool is_accepted) { void ChannelMonitor::AcceptIncomingConnection() { auto client_fd = SharedFD::Accept(*server_); if (!client_fd->IsOpen()) { - LOG(ERROR) << "Error accepting connection on socket: " << client_fd->StrError(); + LOG(ERROR) << "Error accepting connection on socket: " + << client_fd->StrError(); } else { auto client = std::make_unique(client_fd); VLOG(0) << "added one RIL client"; clients_.push_back(std::move(client)); if (clients_.size() == 1) { - // The first connected client default to be the unsolicited commands channel + // The first connected client default to be the unsolicited commands + // channel modem_.OnFirstClientConnected(); } } @@ -87,7 +89,7 @@ void ChannelMonitor::ReadCommand(Client& client) { if (errno == EAGAIN && client.type == Client::REMOTE && client.first_read_command_) { LOG(ERROR) << "After read 'REM' from remote client, and before select " - "no new data come."; + "no new data come."; return; } VLOG(0) << "Error reading from client fd: " @@ -130,7 +132,7 @@ void ChannelMonitor::ReadCommand(Client& client) { VLOG(1) << "AT> " << command; modem_.DispatchCommand(client, command); } - pos = r_pos + 1; // Skip '\r' + pos = r_pos + 1; // Skip '\r' } else if (pos < commands.length()) { // Incomplete command incomplete_command = commands.substr(pos); VLOG(1) << "incomplete command: " << incomplete_command; diff --git a/base/cvd/cuttlefish/host/commands/modem_simulator/command_parser.h b/base/cvd/cuttlefish/host/commands/modem_simulator/command_parser.h index 4eca215b119..1b5eb3e16c5 100644 --- a/base/cvd/cuttlefish/host/commands/modem_simulator/command_parser.h +++ b/base/cvd/cuttlefish/host/commands/modem_simulator/command_parser.h @@ -13,11 +13,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "absl/strings/strip.h" - #include #include +#include "absl/strings/strip.h" + namespace cuttlefish { class CommandParser { @@ -38,15 +38,17 @@ class CommandParser { std::string_view GetNextStr(); std::string_view GetNextStr(char flag); - std::string GetNextStrDeciToHex(); /* for AT+CRSM */ + std::string GetNextStrDeciToHex(); /* for AT+CRSM */ int GetNextInt(); int GetNextHexInt(); const std::string_view* operator->() const { return &command_; } const std::string_view& operator*() const { return command_; } - bool operator==(const std::string &rhs) const { return command_ == rhs; } - std::string_view::const_reference& operator[](int index) const { return command_[index]; } + bool operator==(const std::string& rhs) const { return command_ == rhs; } + std::string_view::const_reference& operator[](int index) const { + return command_[index]; + } private: std::string copy_command_; diff --git a/base/cvd/cuttlefish/host/commands/modem_simulator/data_service.cpp b/base/cvd/cuttlefish/host/commands/modem_simulator/data_service.cpp index 31db6357a30..117aba18dcc 100644 --- a/base/cvd/cuttlefish/host/commands/modem_simulator/data_service.cpp +++ b/base/cvd/cuttlefish/host/commands/modem_simulator/data_service.cpp @@ -15,7 +15,6 @@ #include "cuttlefish/host/commands/modem_simulator/data_service.h" - #include "cuttlefish/host/commands/modem_simulator/device_config.h" namespace cuttlefish { @@ -158,13 +157,10 @@ void DataService::HandlePDPContext(const Client& client, auto dnses = cuttlefish::modem::DeviceConfig::ril_dns(); auto gateways = cuttlefish::modem::DeviceConfig::ril_gateway(); - PDPContext pdp_context = {cid, - PDPContext::ACTIVE, + PDPContext pdp_context = {cid, PDPContext::ACTIVE, ip_type, // IPV4 or IPV6 or IPV4V6 - apn, - address, - dnses, - gateways}; + apn, address, + dnses, gateways}; // check cid auto iter = pdp_context_.begin(); @@ -191,8 +187,8 @@ void DataService::HandleQueryPDPContextList(const Client& client) { std::stringstream ss; for (auto it = pdp_context_.begin(); it != pdp_context_.end(); ++it) { std::stringstream ss; - ss << "+CGDCONT: " << it->cid << "," << it->conn_types << "," - << it->apn << "," << it->addresses << ",0,0"; + ss << "+CGDCONT: " << it->cid << "," << it->conn_types << "," << it->apn + << "," << it->addresses << ",0,0"; responses.push_back(ss.str()); } responses.push_back("OK"); @@ -247,13 +243,13 @@ void DataService::HandleEnterDataState(const Client& client, * The execution command returns the relevant information for an active non * secondary PDP context with the context identifier . * - * Command Possible response(s) - * +CGCONTRDP[=] [+CGCONTRDP: ,, - * [,[, - * [,[[...]]]]]] - * [+CGCONTRDP: ,, - * [,[, - * [,[[...]]]]]] + * Command Possible response(s) + * +CGCONTRDP[=] [+CGCONTRDP: ,, + * [,[, + * [,[[...]]]]]] + * [+CGCONTRDP: ,, + * [,[, + * [,[[...]]]]]] * * : see AT+CGACT * : integer type; identifies the bearer, i.e. the EPS bearer and @@ -263,7 +259,8 @@ void DataService::HandleEnterDataState(const Client& client, * : string type; shows the Gateway Address of the MT. The string is * given as dot-separated numeric (0-255) parameters. * : string type; shows the IP address of the primary DNS server. - * : string type; shows the IP address of the secondary DNS server. + * : string type; shows the IP address of the secondary DNS + * server. * * * see RIL_REQUEST_SETUP_DATA_CALL in RIL @@ -287,12 +284,8 @@ void DataService::HandleReadDynamicParam(const Client& client, responses.push_back(kCmeErrorInvalidIndex); // number } else { std::stringstream ss; - ss << "+CGCONTRDP: " - << iter->cid << ",5," - << iter->apn << "," - << iter->addresses << "," - << iter->gateways << "," - << iter->dnses; + ss << "+CGCONTRDP: " << iter->cid << ",5," << iter->apn << "," + << iter->addresses << "," << iter->gateways << "," << iter->dnses; responses.push_back(ss.str()); responses.push_back("OK"); } diff --git a/base/cvd/cuttlefish/host/commands/modem_simulator/data_service.h b/base/cvd/cuttlefish/host/commands/modem_simulator/data_service.h index b781067b70f..923e001b351 100644 --- a/base/cvd/cuttlefish/host/commands/modem_simulator/data_service.h +++ b/base/cvd/cuttlefish/host/commands/modem_simulator/data_service.h @@ -19,14 +19,15 @@ namespace cuttlefish { -class DataService : public ModemService, public std::enable_shared_from_this { +class DataService : public ModemService, + public std::enable_shared_from_this { public: DataService(int32_t service_id, ChannelMonitor* channel_monitor, ThreadLooper* thread_looper); ~DataService() = default; - DataService(const DataService &) = delete; - DataService &operator=(const DataService &) = delete; + DataService(const DataService&) = delete; + DataService& operator=(const DataService&) = delete; void HandleActivateDataCall(const Client& client, const std::string& command); void HandleQueryDataCallList(const Client& client); @@ -47,7 +48,7 @@ class DataService : public ModemService, public std::enable_shared_from_this #include -#include "absl/strings/str_split.h" -#include -#include #include "absl/log/check.h" #include "absl/log/log.h" +#include "absl/strings/str_split.h" +#include "fmt/format.h" +#include "gflags/gflags.h" #include "cuttlefish/common/libs/fs/shared_buf.h" #include "cuttlefish/common/libs/fs/shared_fd.h" @@ -34,7 +34,8 @@ // will listen to one server fd for incoming sms/phone call // there should be at least 1 valid fd DEFINE_string(server_fds, "", "A comma separated list of file descriptors"); -DEFINE_int32(sim_type, 1, "Sim type: 1 for normal, 2 for CtsCarrierApiTestCases"); +DEFINE_int32(sim_type, 1, + "Sim type: 1 for normal, 2 for CtsCarrierApiTestCases"); namespace cuttlefish { namespace { @@ -42,7 +43,7 @@ namespace { std::vector ServerFdsFromCmdline() { // Validate the parameter std::string fd_list = FLAGS_server_fds; - for (auto c: fd_list) { + for (auto c : fd_list) { if (c != ',' && (c < '0' || c > '9')) { LOG(ERROR) << "Invalid file descriptor list: " << fd_list; std::exit(1); @@ -51,7 +52,7 @@ std::vector ServerFdsFromCmdline() { std::vector fds = absl::StrSplit(fd_list, ','); std::vector shared_fds; - for (auto& fd_str: fds) { + for (auto& fd_str : fds) { auto fd = std::stoi(fd_str); auto shared_fd = SharedFD::Dup(fd); close(fd); @@ -77,8 +78,9 @@ int ModemSimulatorMain(int argc, char** argv) { } LOG(INFO) << "Start modem simulator, server_fds: " << FLAGS_server_fds - << ", Sim type: " << ((FLAGS_sim_type == 2) ? - "special for CtsCarrierApiTestCases" : "normal" ); + << ", Sim type: " + << ((FLAGS_sim_type == 2) ? "special for CtsCarrierApiTestCases" + : "normal"); auto server_fds = ServerFdsFromCmdline(); if (server_fds.empty()) { @@ -101,7 +103,8 @@ int ModemSimulatorMain(int argc, char** argv) { std::vector> modem_simulators; for (auto& fd : server_fds) { - CHECK(fd->IsOpen()) << "Error creating or inheriting modem simulator server: " + CHECK(fd->IsOpen()) + << "Error creating or inheriting modem simulator server: " << fd->StrError(); auto modem_simulator = std::make_unique(modem_id);