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

Commit 30adc76d authored by Jack He's avatar Jack He
Browse files

Fix broken linux build

* Generic linux does not have property_get_int32. Instead,
  osi_property_get_int32() is created to handle OS_GENERIC cases
* Some linux header have sigevent.sigev_notify_attributes typed as
  (pthread_attr_t *) whereas others typed it as (void *), as any pointer
  can be implicitly casted to (void *), the current casting to (void *)
  is unncessary and will break build on systems using (pthread_attr_t *)

Test: make, unit test, no user visible effect
Change-Id: I24b33da453dc9d40656168a3bcd900d9c99219ce
(cherry picked from commit d025bc48)
parent f12f892a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -92,8 +92,8 @@ static future_t* start_up(void) {
    delete_btsnoop_files();
  } else {
    open_next_snoop_file();
    packets_per_file =
        property_get_int32(BTSNOOP_MAX_PACKETS_PROPERTY, DEFAULT_BTSNOOP_SIZE);
    packets_per_file = osi_property_get_int32(BTSNOOP_MAX_PACKETS_PROPERTY,
                                              DEFAULT_BTSNOOP_SIZE);
    btsnoop_net_open();
  }

+8 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#pragma once

#include <cstdint>
#if defined(OS_GENERIC)
#define PROPERTY_VALUE_MAX 92
#else
@@ -35,3 +36,10 @@ int osi_property_get(const char* key, char* value, const char* default_value);
// Write value of property associated with key |key| to |value|.
// Returns 0 on success, < 0 on failure
int osi_property_set(const char* key, const char* value);

// Adapter function for property_get_int32 in
// libcutils/include/cutils/properties.h
//
// returns the value of |key| truncated and coerced into an
// int32_t. If the property is not set, then the |default_value| is used.
int32_t osi_property_get_int32(const char* key, int32_t default_value);
+1 −1
Original line number Diff line number Diff line
@@ -633,7 +633,7 @@ static bool timer_create_internal(const clockid_t clock_id, timer_t* timer) {
  memset(&sigevent, 0, sizeof(sigevent));
  sigevent.sigev_notify = SIGEV_THREAD;
  sigevent.sigev_notify_function = (void (*)(union sigval))timer_callback;
  sigevent.sigev_notify_attributes = (void*)(&thread_attr);
  sigevent.sigev_notify_attributes = &thread_attr;
  if (timer_create(clock_id, &sigevent, timer) == -1) {
    LOG_ERROR(LOG_TAG, "%s unable to create timer with clock %d: %s", __func__,
              clock_id, strerror(errno));
+8 −0
Original line number Diff line number Diff line
@@ -44,3 +44,11 @@ int osi_property_set(const char* key, const char* value) {
  return property_set(key, value);
#endif  // defined(OS_GENERIC)
}

int32_t osi_property_get_int32(const char* key, int32_t default_value) {
#if defined(OS_GENERIC)
  return default_value;
#else
  return property_get_int32(key, default_value);
#endif  // defined(OS_GENERIC)
}
+15 −0
Original line number Diff line number Diff line
@@ -39,3 +39,18 @@ TEST_F(PropertiesTest, test_successfull_set_and_get_value) {
  osi_property_get("very.useful.set.test", received, NULL);
  ASSERT_STREQ(received, "nothing_interesting");
}

TEST_F(PropertiesTest, test_default_value_int32) {
  int32_t value = 42;
  int32_t rvalue = osi_property_get_int32("very.useful.test", value);
  ASSERT_EQ(rvalue, value);
}

TEST_F(PropertiesTest, test_successfull_set_and_get_value_int32) {
  char value[PROPERTY_VALUE_MAX] = "42";
  int ret = osi_property_set("very.useful.set.test", value);
  ASSERT_EQ(0, ret);

  int32_t received = osi_property_get_int32("very.useful.set.test", 84);
  ASSERT_EQ(received, 42);
}