Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09d3f800 authored by Myles Watson's avatar Myles Watson
Browse files

vendor_lib: Apply clang-format with the new config

cd vendor_libs/test_vendor_lib/
clang-format ../linux/bt_vendor_linux.c -style=file -i
clang-format include/* test/* src/* -style=file -i

Update the style guide since clang-format help uses the
-style=file option.

Test: mm -j32
Change-Id: I166adfb2bb9a87fefa1242c91e5f180011caa2ad
parent 3435cab3
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -265,11 +265,11 @@ result in faster compilation.
Code formatting is done automatically using clang-format.

The style file is located at the root of the source tree in .clang-format.  The
--style=file option instructs clang-format to look for this file.  You may find
-style=file option instructs clang-format to look for this file.  You may find
clang-format --help useful for more advanced usage. The [Online clang-format
Documentation](http://clang.llvm.org/docs/ClangFormat.html) can also be helpful.

`clang-format --style=file -i path_to_files/filename_or_*`
`clang-format -style=file -i path_to_files/filename_or_*`

### My Patch Doesn't Apply Anymore!
Choose one of the options below.  The fewer patches that have been applied to
@@ -316,7 +316,7 @@ and remove their changes

##### Reformat the code

`clang-format --style=file -i path_to_files/filename_or_*`
`clang-format -style=file -i path_to_files/filename_or_*`

##### Commit the code that your patch touched

@@ -352,7 +352,7 @@ and remove their changes

##### Reformat the code

`clang-format --style=file -i path_to_files/filename_or_*`
`clang-format -style=file -i path_to_files/filename_or_*`

##### Commit your temporary formatting patch

@@ -372,7 +372,7 @@ and remove their changes

##### Reformat the code

`clang-format --style=file -i path_to_files/filename_or_*`
`clang-format -style=file -i path_to_files/filename_or_*`

##### Commit your second temporary formatting patch

@@ -406,7 +406,7 @@ and remove their changes

##### Remember to edit the commit message!

`clang-format --style=file -i path_to_files/filename_or_*`
`clang-format -style=file -i path_to_files/filename_or_*`

##### Check to see that everything looks right

+91 −112
Original line number Diff line number Diff line
@@ -20,21 +20,21 @@
#define LOG_TAG "bt_vendor"

#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <fcntl.h>
#include <poll.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <poll.h>

#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/socket.h>

#include "hci/include/bt_vendor_lib.h"
#include "osi/include/osi.h"
#include "osi/include/compat.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
#include "osi/include/properties.h"
#include "osi/include/compat.h"

#define BTPROTO_HCI 1
#define HCI_CHANNEL_USER 1
@@ -87,8 +87,7 @@ static int rfkill_en;
static int bt_hwcfg_en;

static int bt_vendor_init(const bt_vendor_callbacks_t* p_cb,
                          unsigned char *local_bdaddr)
{
                          unsigned char* local_bdaddr) {
  char prop_value[PROPERTY_VALUE_MAX];

  LOG_INFO(LOG_TAG, "%s", __func__);
@@ -100,8 +99,7 @@ static int bt_vendor_init(const bt_vendor_callbacks_t *p_cb,

  bt_vendor_callbacks = p_cb;

  memcpy(bt_vendor_local_bdaddr, local_bdaddr,
         sizeof(bt_vendor_local_bdaddr));
  memcpy(bt_vendor_local_bdaddr, local_bdaddr, sizeof(bt_vendor_local_bdaddr));

  osi_property_get("bluetooth.interface", prop_value, "0");

@@ -110,29 +108,24 @@ static int bt_vendor_init(const bt_vendor_callbacks_t *p_cb,
    hci_interface = strtol(prop_value, NULL, 10);
  else
    hci_interface = strtol(prop_value + 3, NULL, 10);
  if (errno)
    hci_interface = 0;
  if (errno) hci_interface = 0;

  LOG_INFO(LOG_TAG, "Using interface hci%d", hci_interface);

  osi_property_get("bluetooth.rfkill", prop_value, "0");

  rfkill_en = atoi(prop_value);
  if (rfkill_en)
    LOG_INFO(LOG_TAG, "RFKILL enabled");
  if (rfkill_en) LOG_INFO(LOG_TAG, "RFKILL enabled");

  bt_hwcfg_en = osi_property_get("bluetooth.hwcfg",
                             prop_value, NULL) > 0 ? 1 : 0;
  if (bt_hwcfg_en)
    LOG_INFO(LOG_TAG, "HWCFG enabled");
  bt_hwcfg_en =
      osi_property_get("bluetooth.hwcfg", prop_value, NULL) > 0 ? 1 : 0;
  if (bt_hwcfg_en) LOG_INFO(LOG_TAG, "HWCFG enabled");

  return 0;
}

static int bt_vendor_hw_cfg(int stop)
{
  if (!bt_hwcfg_en)
    return 0;
static int bt_vendor_hw_cfg(int stop) {
  if (!bt_hwcfg_en) return 0;

  if (stop) {
    if (osi_property_set("bluetooth.hwcfg", "stop") < 0) {
@@ -148,8 +141,7 @@ static int bt_vendor_hw_cfg(int stop)
  return 0;
}

static int bt_vendor_wait_hcidev(void)
{
static int bt_vendor_wait_hcidev(void) {
  struct sockaddr_hci addr;
  struct pollfd fds[1];
  struct mgmt_pkt ev;
@@ -221,12 +213,10 @@ static int bt_vendor_wait_hcidev(void)

        cc = (struct mgmt_event_read_index*)ev.data;

        if (cc->cc_opcode != MGMT_OP_INDEX_LIST || cc->status != 0)
          continue;
        if (cc->cc_opcode != MGMT_OP_INDEX_LIST || cc->status != 0) continue;

        for (i = 0; i < cc->num_intf; i++) {
          if (cc->index[i] == hci_interface)
            goto end;
          if (cc->index[i] == hci_interface) goto end;
        }
      }
    }
@@ -237,8 +227,7 @@ end:
  return ret;
}

static int bt_vendor_open(void *param)
{
static int bt_vendor_open(void* param) {
  int(*fd_array)[] = (int(*)[])param;
  int fd;

@@ -262,8 +251,7 @@ static int bt_vendor_open(void *param)
  return 1;
}

static int bt_vendor_close(void *param)
{
static int bt_vendor_close(void* param) {
  (void)(param);

  LOG_INFO(LOG_TAG, "%s", __func__);
@@ -276,8 +264,7 @@ static int bt_vendor_close(void *param)
  return 0;
}

static int bt_vendor_rfkill(int block)
{
static int bt_vendor_rfkill(int block) {
  struct rfkill_event event;
  int fd;

@@ -308,8 +295,7 @@ static int bt_vendor_rfkill(int block)
}

/* TODO: fw config should thread the device waiting and return immedialty */
static void bt_vendor_fw_cfg(void)
{
static void bt_vendor_fw_cfg(void) {
  struct sockaddr_hci addr;
  int fd = bt_vendor_fd;

@@ -346,25 +332,21 @@ failure:
  bt_vendor_callbacks->fwcfg_cb(BT_VND_OP_RESULT_FAIL);
}

static int bt_vendor_op(bt_vendor_opcode_t opcode, void *param)
{
static int bt_vendor_op(bt_vendor_opcode_t opcode, void* param) {
  int retval = 0;

  LOG_INFO(LOG_TAG, "%s op %d", __func__, opcode);

  switch (opcode) {
    case BT_VND_OP_POWER_CTRL:
    if (!rfkill_en || !param)
      break;
      if (!rfkill_en || !param) break;

      if (*((int*)param) == BT_VND_PWR_ON) {
        retval = bt_vendor_rfkill(0);
      if (!retval)
        retval = bt_vendor_hw_cfg(0);
        if (!retval) retval = bt_vendor_hw_cfg(0);
      } else {
        retval = bt_vendor_hw_cfg(1);
      if (!retval)
        retval = bt_vendor_rfkill(1);
        if (!retval) retval = bt_vendor_rfkill(1);
      }

      break;
@@ -417,16 +399,13 @@ static int bt_vendor_op(bt_vendor_opcode_t opcode, void *param)
  return retval;
}

static void bt_vendor_cleanup(void)
{
static void bt_vendor_cleanup(void) {
  LOG_INFO(LOG_TAG, "%s", __func__);

  bt_vendor_callbacks = NULL;
}

EXPORT_SYMBOL const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE = {
  sizeof(bt_vendor_interface_t),
  bt_vendor_init,
  bt_vendor_op,
    sizeof(bt_vendor_interface_t), bt_vendor_init, bt_vendor_op,
    bt_vendor_cleanup,
};
+3 −4
Original line number Diff line number Diff line
@@ -181,8 +181,8 @@ class DualModeController {

  void RegisterPeriodicTaskScheduler(
      std::function<AsyncTaskId(std::chrono::milliseconds,
                                std::chrono::milliseconds,
                                const TaskCallback&)> periodicEvtScheduler);
                                std::chrono::milliseconds, const TaskCallback&)>
          periodicEvtScheduler);

  void RegisterTaskCancel(std::function<void(AsyncTaskId)> cancel);

@@ -491,8 +491,7 @@ class DualModeController {
  std::function<AsyncTaskId(std::chrono::milliseconds, const TaskCallback&)>
      schedule_task_;
  std::function<AsyncTaskId(std::chrono::milliseconds,
                            std::chrono::milliseconds,
                            const TaskCallback&)>
                            std::chrono::milliseconds, const TaskCallback&)>
      schedule_periodic_task_;

  std::function<void(AsyncTaskId)> cancel_task_;
+7 −16
Original line number Diff line number Diff line
@@ -76,15 +76,12 @@ class EventPacket : public Packet {
  // Bluetooth Core Specification Version 4.2, Volume 2, Part E, Section 7.4.4
  static std::unique_ptr<EventPacket>
  CreateCommandCompleteReadLocalExtendedFeatures(
      uint8_t status,
      uint8_t page_number,
      uint8_t maximum_page_number,
      uint8_t status, uint8_t page_number, uint8_t maximum_page_number,
      uint64_t extended_lmp_features);

  // Bluetooth Core Specification Version 4.2, Volume 2, Part E, Section 7.4.5
  static std::unique_ptr<EventPacket> CreateCommandCompleteReadBufferSize(
      uint8_t status,
      uint16_t hc_acl_data_packet_length,
      uint8_t status, uint16_t hc_acl_data_packet_length,
      uint8_t hc_synchronous_data_packet_length,
      uint16_t hc_total_num_acl_data_packets,
      uint16_t hc_total_synchronous_data_packets);
@@ -96,8 +93,7 @@ class EventPacket : public Packet {
  // Bluetooth Core Specification Version 4.2, Volume 2, Part E, Section 7.4.8
  static std::unique_ptr<EventPacket>
  CreateCommandCompleteReadLocalSupportedCodecs(
      uint8_t status,
      const std::vector<uint8_t>& supported_codecs,
      uint8_t status, const std::vector<uint8_t>& supported_codecs,
      const std::vector<uint32_t>& vendor_specific_codecs);

  // Bluetooth Core Specification Version 4.2, Volume 2, Part E, Section 7.7.2
@@ -110,27 +106,22 @@ class EventPacket : public Packet {
  static std::unique_ptr<EventPacket> CreateInquiryResultEvent(
      const BtAddress& bt_address,
      const PageScanRepetitionMode page_scan_repetition_mode,
      uint32_t class_of_device,
      uint16_t clock_offset);
      uint32_t class_of_device, uint16_t clock_offset);

  void AddInquiryResult(const BtAddress& bt_address,
                        const PageScanRepetitionMode page_scan_repetition_mode,
                        uint32_t class_of_device,
                        uint16_t clock_offset);
                        uint32_t class_of_device, uint16_t clock_offset);

  // Bluetooth Core Specification Version 4.2, Volume 2, Part E, Section 7.7.38
  static std::unique_ptr<EventPacket> CreateExtendedInquiryResultEvent(
      const BtAddress& bt_address,
      const PageScanRepetitionMode page_scan_repetition_mode,
      uint32_t class_of_device,
      uint16_t clock_offset,
      uint8_t rssi,
      uint32_t class_of_device, uint16_t clock_offset, uint8_t rssi,
      const std::vector<uint8_t>& extended_inquiry_response);

  // Bluetooth Core Specification Version 4.2, Volume 2, Part E, Section 7.8.2
  static std::unique_ptr<EventPacket> CreateCommandCompleteLeReadBufferSize(
      uint8_t status,
      uint16_t hc_le_data_packet_length,
      uint8_t status, uint16_t hc_le_data_packet_length,
      uint8_t hc_total_num_le_data_packets);

  // Bluetooth Core Specification Version 4.2, Volume 2, Part E, Section 7.8.3
+2 −4
Original line number Diff line number Diff line
@@ -55,13 +55,11 @@ class PacketStream {
  // Attempts to receive |num_octets_to_receive| into |destination| from |fd|,
  // returning false if an error occurs.
  bool ReceiveAll(std::vector<uint8_t>& destination,
                  size_t num_octets_to_receive,
                  int fd) const;
                  size_t num_octets_to_receive, int fd) const;

  // Attempts to send |num_octets_to_send| from |source| to |fd|, returning
  // false if an error occurs.
  bool SendAll(const std::vector<uint8_t>& source,
               size_t num_octets_to_send,
  bool SendAll(const std::vector<uint8_t>& source, size_t num_octets_to_send,
               int fd) const;
};

Loading