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

Commit f91839c6 authored by Sharvil Nanavati's avatar Sharvil Nanavati
Browse files

Make unit tests pass again after OS callout change.

Change-Id: Icc7846faef581855c5fe3d12244d4a754badd9b7
parent 98a0b19c
Loading
Loading
Loading
Loading
+49 −1
Original line number Diff line number Diff line
@@ -16,11 +16,25 @@
 *
 ******************************************************************************/

#include <signal.h>
#include <time.h>

#include "base.h"
#include "support/hal.h"

static bool set_wake_alarm(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data);
static int acquire_wake_lock(const char *lock_name);
static int release_wake_lock(const char *lock_name);

static const bluetooth_device_t *bt_device;

static bt_os_callouts_t callouts = {
  sizeof(bt_os_callouts_t),
  set_wake_alarm,
  acquire_wake_lock,
  release_wake_lock,
};

bool hal_open(bt_callbacks_t *callbacks) {
  hw_module_t *module;
  if (hw_get_module(BT_STACK_MODULE_ID, (hw_module_t const **)&module)) {
@@ -40,7 +54,9 @@ bool hal_open(bt_callbacks_t *callbacks) {
    return false;
  }

  return bt_interface->init(callbacks) == BT_STATUS_SUCCESS;
  bool success = (bt_interface->init(callbacks) == BT_STATUS_SUCCESS);
  success = success && (bt_interface->set_os_callouts(&callouts) == BT_STATUS_SUCCESS);
  return success;
}

void hal_close() {
@@ -54,3 +70,35 @@ void hal_close() {
    bt_device = NULL;
  }
}

static bool set_wake_alarm(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data) {
  static timer_t timer;
  static bool timer_created;

  if (!timer_created) {
    struct sigevent sigevent;
    memset(&sigevent, 0, sizeof(sigevent));
    sigevent.sigev_notify = SIGEV_THREAD;
    sigevent.sigev_notify_function = (void (*)(union sigval))cb;
    sigevent.sigev_value.sival_ptr = data;
    timer_create(CLOCK_MONOTONIC, &sigevent, &timer);
    timer_created = true;
  }

  struct itimerspec new_value;
  new_value.it_value.tv_sec = delay_millis / 1000;
  new_value.it_value.tv_nsec = (delay_millis % 1000) * 1000 * 1000;
  new_value.it_interval.tv_sec = 0;
  new_value.it_interval.tv_nsec = 0;
  timer_settime(timer, 0, &new_value, NULL);

  return true;
}

static int acquire_wake_lock(const char *lock_name) {
  return BT_STATUS_SUCCESS;
}

static int release_wake_lock(const char *lock_name) {
  return BT_STATUS_SUCCESS;
}