diff options
author | Seungjae Yoo <seungjaeyoo@google.com> | 2023-04-18 09:48:02 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-04-18 09:48:02 +0000 |
commit | dba789749b10bc2a7925245cd93ad2371283b5f5 (patch) | |
tree | 19d3c7e3bbcf8c0b02c176897339dc527735c832 | |
parent | ff489ad593805def05b444e65ada8f13baa61496 (diff) | |
parent | 6e7e4424f554808917147253e3dbda1e6a7aca77 (diff) | |
download | wmediumd-dba789749b10bc2a7925245cd93ad2371283b5f5.tar.gz |
Apply clang-format and bpfmt am: 6e7e4424f5
Original change: https://android-review.googlesource.com/c/platform/external/wmediumd/+/2542491
Change-Id: I45ecdec50f05c72a1565e4cacb9d6092d4a1333f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | .clang-format | 21 | ||||
-rw-r--r-- | Android.bp | 6 | ||||
-rw-r--r-- | PREUPLOAD.cfg | 6 | ||||
-rw-r--r-- | main.cc | 54 | ||||
-rw-r--r-- | util/wmediumd_gen_config.c | 21 | ||||
-rw-r--r-- | wmediumd/.clang-format | 22 | ||||
-rw-r--r-- | wmediumd_server/wmediumd.proto | 2 | ||||
-rw-r--r-- | wmediumd_server/wmediumd_server.cc | 80 |
8 files changed, 135 insertions, 77 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..c8e6173 --- /dev/null +++ b/.clang-format @@ -0,0 +1,21 @@ +# +# Copyright (C) 2023 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# See https://clang.llvm.org/docs/ClangFormatStyleOptions.html for the +# various options that can be configured and for the definitions of each +# of the below options. + +BasedOnStyle: Google @@ -25,7 +25,7 @@ cc_binary_host { "libconfig", ], visibility: [ - "//device/google/cuttlefish/build", + "//device/google/cuttlefish/build", ], } @@ -126,7 +126,7 @@ cc_binary_host { ], cpp_std: "c++17", visibility: [ - "//device/google/cuttlefish/build", + "//device/google/cuttlefish/build", ], } @@ -139,7 +139,7 @@ cc_binary_host { "wmediumd/inc", ], visibility: [ - "//device/google/cuttlefish/build", + "//device/google/cuttlefish/build", ], stl: "none", static_executable: true, diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg new file mode 100644 index 0000000..0b46545 --- /dev/null +++ b/PREUPLOAD.cfg @@ -0,0 +1,6 @@ +[Builtin Hooks] +bpfmt = true +clang_format = true + +[Builtin Hooks Options] +clang_format = --commit ${PREUPLOAD_COMMIT} --style file --extensions c,h,cc,cpp
\ No newline at end of file @@ -16,47 +16,47 @@ * */ -#include <string> -#include <thread> -#include <vector> - #include <android-base/logging.h> #include <android-base/strings.h> #include <sys/eventfd.h> #include <sys/msg.h> - #include <wmediumd/wmediumd.h> #include <wmediumd_server/wmediumd_server.h> +#include <string> +#include <thread> +#include <vector> + constexpr char kGrpcUdsPathOption[] = "--grpc_uds_path="; int main(int argc, char* argv[]) { - std::vector<char*> wmediumd_args; - std::string grpc_uds_path; - for (int i = 0; i < argc; i++) { - if (android::base::StartsWith(argv[i], kGrpcUdsPathOption)) { - std::string current_arg(argv[i]); - grpc_uds_path = current_arg.substr(strlen(kGrpcUdsPathOption)); - } else { - wmediumd_args.push_back(argv[i]); - } + std::vector<char*> wmediumd_args; + std::string grpc_uds_path; + for (int i = 0; i < argc; i++) { + if (android::base::StartsWith(argv[i], kGrpcUdsPathOption)) { + std::string current_arg(argv[i]); + grpc_uds_path = current_arg.substr(strlen(kGrpcUdsPathOption)); + } else { + wmediumd_args.push_back(argv[i]); } + } - int fd = eventfd(0, 0); - int msq_id = msgget(IPC_PRIVATE, IPC_CREAT | 0666); + int fd = eventfd(0, 0); + int msq_id = msgget(IPC_PRIVATE, IPC_CREAT | 0666); - std::thread wmediumd_server_thread; - if (!grpc_uds_path.empty()) { - wmediumd_server_thread = std::thread(RunWmediumdServer, grpc_uds_path, fd, msq_id); - } + std::thread wmediumd_server_thread; + if (!grpc_uds_path.empty()) { + wmediumd_server_thread = + std::thread(RunWmediumdServer, grpc_uds_path, fd, msq_id); + } - wmediumd_main(wmediumd_args.size(), wmediumd_args.data(), fd, msq_id); + wmediumd_main(wmediumd_args.size(), wmediumd_args.data(), fd, msq_id); - if (!grpc_uds_path.empty()) { - wmediumd_server_thread.join(); - } + if (!grpc_uds_path.empty()) { + wmediumd_server_thread.join(); + } - msgctl(msq_id, IPC_RMID, 0); - close(fd); - return 0; + msgctl(msq_id, IPC_RMID, 0); + close(fd); + return 0; }
\ No newline at end of file diff --git a/util/wmediumd_gen_config.c b/util/wmediumd_gen_config.c index f7aa25d..8984e7e 100644 --- a/util/wmediumd_gen_config.c +++ b/util/wmediumd_gen_config.c @@ -66,18 +66,24 @@ int add_cuttlefish_mac_addresses(config_setting_t *ids, int mac_prefix, return 0; } -int add_cuttlefish_path_loss_model(config_setting_t *model, int instance_count) { - config_setting_t *type = config_setting_add(model, "type", CONFIG_TYPE_STRING); +int add_cuttlefish_path_loss_model(config_setting_t *model, + int instance_count) { + config_setting_t *type = + config_setting_add(model, "type", CONFIG_TYPE_STRING); config_setting_set_string(type, "path_loss"); - config_setting_t *model_name = config_setting_add(model, "model_name", CONFIG_TYPE_STRING); + config_setting_t *model_name = + config_setting_add(model, "model_name", CONFIG_TYPE_STRING); config_setting_set_string(model_name, "free_space"); - config_setting_t *positions = config_setting_add(model, "positions", CONFIG_TYPE_LIST); - config_setting_t *tx_powers = config_setting_add(model, "tx_powers", CONFIG_TYPE_ARRAY); + config_setting_t *positions = + config_setting_add(model, "positions", CONFIG_TYPE_LIST); + config_setting_t *tx_powers = + config_setting_add(model, "tx_powers", CONFIG_TYPE_ARRAY); for (int idx = 0; idx < instance_count; ++idx) { - config_setting_t *position = config_setting_add(positions, NULL, CONFIG_TYPE_LIST); + config_setting_t *position = + config_setting_add(positions, NULL, CONFIG_TYPE_LIST); config_setting_set_float_elem(position, APPEND_LAST, 0.0); config_setting_set_float_elem(position, APPEND_LAST, 0.0); @@ -282,7 +288,8 @@ int main(int argc, char **argv) { print_help(-1); } - config_setting_t *model = config_setting_add(root, "model", CONFIG_TYPE_GROUP); + config_setting_t *model = + config_setting_add(root, "model", CONFIG_TYPE_GROUP); add_cuttlefish_path_loss_model(model, config_setting_length(ids)); config_setting_set_int(count, config_setting_length(ids)); diff --git a/wmediumd/.clang-format b/wmediumd/.clang-format new file mode 100644 index 0000000..c7bf22d --- /dev/null +++ b/wmediumd/.clang-format @@ -0,0 +1,22 @@ +# +# Copyright (C) 2023 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# See https://clang.llvm.org/docs/ClangFormatStyleOptions.html for the +# various options that can be configured and for the definitions of each +# of the below options. + +# Upstream follows other formatting rule. Do not apply clang-format in this dir. +BasedOnStyle: None diff --git a/wmediumd_server/wmediumd.proto b/wmediumd_server/wmediumd.proto index 6939f7f..592e708 100644 --- a/wmediumd_server/wmediumd.proto +++ b/wmediumd_server/wmediumd.proto @@ -20,7 +20,7 @@ import "google/protobuf/empty.proto"; service WmediumdService { // TODO(273384914): Define a response type. - rpc SetPosition (SetPositionRequest) returns (google.protobuf.Empty) {} + rpc SetPosition(SetPositionRequest) returns (google.protobuf.Empty) {} } message SetPositionRequest { diff --git a/wmediumd_server/wmediumd_server.cc b/wmediumd_server/wmediumd_server.cc index 09b3283..229d505 100644 --- a/wmediumd_server/wmediumd_server.cc +++ b/wmediumd_server/wmediumd_server.cc @@ -16,23 +16,23 @@ * */ -#include <algorithm> -#include <array> -#include <iostream> -#include <memory> -#include <string> -#include <unistd.h> - #include <android-base/strings.h> #include <gflags/gflags.h> #include <grpcpp/ext/proto_server_reflection_plugin.h> #include <grpcpp/grpcpp.h> #include <grpcpp/health_check_service_interface.h> #include <sys/msg.h> +#include <unistd.h> + +#include <algorithm> +#include <array> +#include <iostream> +#include <memory> +#include <string> +#include "wmediumd.grpc.pb.h" #include "wmediumd/api.h" #include "wmediumd/grpc.h" -#include "wmediumd.grpc.pb.h" using google::protobuf::Empty; using grpc::Server; @@ -89,38 +89,40 @@ static std::array<uint8_t, 6> ParseMacAddress(const std::string& mac_address) { } class WmediumdServiceImpl final : public WmediumdService::Service { - public: - WmediumdServiceImpl(int event_fd, int msq_id) : event_fd_(event_fd), msq_id_(msq_id) {} - - Status SetPosition(ServerContext* context, const SetPositionRequest* request, - Empty* reply) override { - // Validate parameters - if (!IsValidMacAddr(request->mac_address())) { - return Status(StatusCode::INVALID_ARGUMENT, "Got invalid mac address"); - } - auto mac = ParseMacAddress(request->mac_address()); - - // Construct request data - struct wmediumd_set_position data; - memcpy(data.mac, &mac, sizeof(mac)); - data.x = request->x_pos(); - data.y = request->y_pos(); - - // Fill data in the message queue - struct wmediumd_grpc_message msg; - msg.type = GRPC_REQUEST; - memcpy(msg.data, &data, sizeof(data)); - msgsnd(msq_id_, &msg, sizeof(data), 0); - - // Throw an event to wmediumd - uint64_t value = REQUEST_SET_POSITION; - write(event_fd_, &value, sizeof(uint64_t)); - - return Status::OK; + public: + WmediumdServiceImpl(int event_fd, int msq_id) + : event_fd_(event_fd), msq_id_(msq_id) {} + + Status SetPosition(ServerContext* context, const SetPositionRequest* request, + Empty* reply) override { + // Validate parameters + if (!IsValidMacAddr(request->mac_address())) { + return Status(StatusCode::INVALID_ARGUMENT, "Got invalid mac address"); } - private: - int event_fd_; - int msq_id_; + auto mac = ParseMacAddress(request->mac_address()); + + // Construct request data + struct wmediumd_set_position data; + memcpy(data.mac, &mac, sizeof(mac)); + data.x = request->x_pos(); + data.y = request->y_pos(); + + // Fill data in the message queue + struct wmediumd_grpc_message msg; + msg.type = GRPC_REQUEST; + memcpy(msg.data, &data, sizeof(data)); + msgsnd(msq_id_, &msg, sizeof(data), 0); + + // Throw an event to wmediumd + uint64_t value = REQUEST_SET_POSITION; + write(event_fd_, &value, sizeof(uint64_t)); + + return Status::OK; + } + + private: + int event_fd_; + int msq_id_; }; void RunWmediumdServer(std::string grpc_uds_path, int event_fd, int msq_id) { |