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

Commit 3a551be0 authored by Andre Eisenbach's avatar Andre Eisenbach
Browse files

resolve merge conflicts of d5895a3c to master.

Change-Id: Ic5d10e4a80d53f916ec61e75d01a0e08df6114cf
parents 2dcf8aba d5895a3c
Loading
Loading
Loading
Loading
+11 −16
Original line number Diff line number Diff line
@@ -1957,7 +1957,7 @@ static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG *pmeta_msg)
**
** Description      iterator callback function to match the event and handle
**                  timer cleanup
** Returns          true if matches with the event, flase otherwise
** Returns          true to continue iterating, false to stop
**
***************************************************************************/
bool iterate_supported_event_list_for_interim_rsp(void *data, void *cb_data)
@@ -1970,10 +1970,10 @@ bool iterate_supported_event_list_for_interim_rsp(void *data, void *cb_data)
    if (p_event->event_id == *p_event_id)
    {
        p_event->status = eINTERIM;
        return true;
    }
        return false;
    }
    return true;
}

/***************************************************************************
**
@@ -1984,26 +1984,23 @@ bool iterate_supported_event_list_for_interim_rsp(void *data, void *cb_data)
**                  transaction label and removes the event from list,
**                  this event will not be requested again during
**                  the lifetime of the connection.
** Returns          true if matches with the event, flase otherwise
** Returns          false to stop iterating, true to continue
**
***************************************************************************/
bool iterate_supported_event_list_for_timeout(void *data, void *cb_data)
{
    UINT8 label;
    UINT32 cb_value;
    btif_rc_supported_event_t *p_event = (btif_rc_supported_event_t *)data;

    cb_value = (UINT32)cb_data;

    label = cb_value & 0xFF;
    label = (*(UINT8*)cb_data) & 0xFF;

    if (p_event->label == label)
    {
        list_remove(btif_rc_cb.rc_supported_event_list, p_event);
        return true;
    }
        return false;
    }
    return true;
}

/***************************************************************************
**
@@ -2018,11 +2015,9 @@ bool iterate_supported_event_list_for_timeout(void *data, void *cb_data)
static void rc_notification_interim_timout (UINT8 label)
{
    list_node_t *node;
    UINT32 cb_data;

    cb_data = label;
    list_foreach_ext(btif_rc_cb.rc_supported_event_list,
                     iterate_supported_event_list_for_timeout, (void*)cb_data);
    list_foreach(btif_rc_cb.rc_supported_event_list,
                     iterate_supported_event_list_for_timeout, &label);
    /* Timeout happened for interim response for the registered event,
     * check if there are any pending for registration
     */
@@ -2471,9 +2466,9 @@ static void handle_notification_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_REG
                    p_rsp->event_id);
                return;
        }
        list_foreach_ext(btif_rc_cb.rc_supported_event_list,
        list_foreach(btif_rc_cb.rc_supported_event_list,
                iterate_supported_event_list_for_interim_rsp,
                (void*)&p_rsp->event_id);
                &p_rsp->event_id);

        node = list_begin(btif_rc_cb.rc_supported_event_list);
        while (node != NULL)
+11 −10
Original line number Diff line number Diff line
@@ -10,8 +10,12 @@ struct list_t;
typedef struct list_t list_t;

typedef void (*list_free_cb)(void *data);
typedef bool (*list_iter_cb)(void *data);
typedef bool (*list_iter_cb_ext)(void *data, void *cb_data);

// Iterator callback prototype used for |list_foreach|.
// |data| represents the list item currently being iterated, |context| is a
// user defined value passed into |list_foreach|.
// Callback must return true to continue iterating or false to stop iterating.
typedef bool (*list_iter_cb)(void *data, void *context);

// Returns a new, empty list. Returns NULL if not enough memory could be allocated
// for the list structure. The returned list must be freed with |list_free|. The
@@ -74,18 +78,15 @@ bool list_remove(list_t *list, void *data);
// same state it was in after |list_new|. |list| may not be NULL.
void list_clear(list_t *list);

// Iterates through the entire |list| and calls |callback| for each data element.
// Iterates through the |list| and calls |callback| for each data element. Iteration
// continues until |callback| returns false. The function returns the result of the
// last executed |callback| or true if the list is empty. |context| is passed to
// |callback| on each iteration.
// If the list is empty, |callback| will never be called. It is safe to mutate the
// list inside the callback. If an element is added before the node being visited,
// there will be no callback for the newly-inserted node. Neither |list| nor
// |callback| may be NULL.
void list_foreach(const list_t *list, list_iter_cb callback);

// Iterates through the entire |list| and calls |callback| for each data element but also passes
// an additional |cb_data|. The callback should hence accept two arguments.
//
// see list_foreach() for other details.
void list_foreach_ext(const list_t *list, list_iter_cb_ext callback, void *cb_data);
bool list_foreach(const list_t *list, list_iter_cb callback, void *context);

// Returns an iterator to the first element in |list|. |list| may not be NULL.
// The returned iterator is valid as long as it does not equal the value returned
+4 −14
Original line number Diff line number Diff line
@@ -168,27 +168,17 @@ void list_clear(list_t *list) {
  list->length = 0;
}

void list_foreach(const list_t *list, list_iter_cb callback) {
bool list_foreach(const list_t *list, list_iter_cb callback, void *context) {
  assert(list != NULL);
  assert(callback != NULL);

  for (list_node_t *node = list->head; node; ) {
    list_node_t *next = node->next;
    callback(node->data);
    node = next;
  }
}

void list_foreach_ext(const list_t *list, list_iter_cb_ext callback, void *cb_data) {
  list_node_t *node;

  assert(list != NULL);
  assert(callback != NULL);
  for (node = list->head; node; ) {
    list_node_t *next = node->next;
    callback(node->data, cb_data);
    if (!callback(node->data, context))
      return false;
    node = next;
  }
  return true;
}

list_node_t *list_begin(const list_t *list) {
+47 −38
Original line number Diff line number Diff line
@@ -147,55 +147,64 @@ TEST_F(ListTest, test_list_next) {
  list_free(list);
}

bool iterate_increment_items(void *data) {
  int *data_cast = (int *)data;
  *data_cast += 1;
static bool list_callback_sum(void *data, void *context) {
  assert(data);
  assert(context);
  int *sum = (int *)context;
  int *value = (int *)data;
  *sum += *value;
  return true;
}

TEST_F(ListTest, test_list_foreach) {
static bool list_callback_find_int(void *data, void *context) {
  assert(data);
  assert(context);
  return (*(int *)data != *(int *)context);
}

TEST_F(ListTest, test_list_foreach_full) {
  list_t *list = list_new(NULL);
  int item1 = 1;
  int item2 = 2;
  list_append(list, &item1);
  list_append(list, &item2);

  // Increment the items using foreach.
  list_foreach(list, iterate_increment_items);
  // Fill in test data
  int x[] = { 1, 2, 3, 4, 5 };
  for (size_t i = 0; i < ARRAY_SIZE(x); ++i)
    list_append(list, &x[i]);
  EXPECT_EQ(list_length(list), 5);

  // Check the values to be incremented.
  // Since we inserted values *1* and *2* in that order we should get *2* and
  // *3* in that order.
  const void *node1 = list_node(list_begin(list));
  EXPECT_EQ(*((int*)(node1)), 2);  /* item1 + 1 = 2 */
  const void *node2 = list_node(list_next(list_begin(list)));
  EXPECT_EQ(*((int*)(node2)), 3);  /* item2 + 1 = 3 */
  list_free(list);
}
  // Test complete iteration
  int sum = 0;
  bool rc = list_foreach(list, list_callback_sum, &sum);
  EXPECT_EQ(sum, 15);
  EXPECT_TRUE(rc);

bool iterate_increment_items_with_data(void *data, void *cb_data) {
  int *data_cast = (int *)data;
  int *cb_data_cast = (int *)cb_data;
  // Multiply them.
  *data_cast = (*data_cast) * (*cb_data_cast);
  return true;
  list_free(list);
}

TEST_F(ListTest, test_list_foreach_ext) {
TEST_F(ListTest, test_list_foreach_partial) {
  list_t *list = list_new(NULL);
  int item1 = 10;
  int item2 = 20;
  list_append(list, &item1);
  list_append(list, &item2);

  // Increment the items using foreach.
  int m_factor = 2;
  list_foreach_ext(list, iterate_increment_items_with_data, &m_factor);
  // Fill in test data
  int x[] = { 1, 2, 3, 4, 5 };
  for (size_t i = 0; i < ARRAY_SIZE(x); ++i)
    list_append(list, &x[i]);
  EXPECT_EQ(list_length(list), 5);

  // Test partial iteration
  int find = 4;
  bool rc = list_foreach(list, list_callback_find_int, &find);
  EXPECT_FALSE(rc);

  find = 1;
  rc = list_foreach(list, list_callback_find_int, &find);
  EXPECT_FALSE(rc);

  find = 5;
  rc = list_foreach(list, list_callback_find_int, &find);
  EXPECT_FALSE(rc);

  find = 0;
  rc = list_foreach(list, list_callback_find_int, &find);
  EXPECT_TRUE(rc);

  // Check that values get multiplied correctly.
  const void *node1 = list_node(list_begin(list));
  EXPECT_EQ(*((int*)(node1)), 20);  /* item1 * m_factor = 20 */
  const void *node2 = list_node(list_next(list_begin(list)));
  EXPECT_EQ(*((int*)(node2)), 40);  /* item2 * m_factor = 40 */
  list_free(list);
}