2016-09-14 07:16:04 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Wireless daemon for Linux
|
|
|
|
*
|
2017-11-14 18:25:32 +01:00
|
|
|
* Copyright (C) 2016-2017 Intel Corporation. All rights reserved.
|
2016-09-14 07:16:04 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef void (*watchlist_item_destroy_func_t)(void *data);
|
|
|
|
|
|
|
|
struct watchlist_item {
|
|
|
|
unsigned int id;
|
|
|
|
void *notify;
|
|
|
|
void *notify_data;
|
|
|
|
watchlist_item_destroy_func_t destroy;
|
|
|
|
};
|
|
|
|
|
2017-09-01 00:57:16 +02:00
|
|
|
struct watchlist_ops {
|
|
|
|
void (*item_free)(struct watchlist_item *item);
|
|
|
|
};
|
|
|
|
|
2016-09-14 07:16:04 +02:00
|
|
|
struct watchlist {
|
|
|
|
int next_id;
|
|
|
|
struct l_queue *items;
|
2016-09-22 22:28:29 +02:00
|
|
|
bool in_notify : 1;
|
|
|
|
bool stale_items : 1;
|
2017-09-01 00:57:16 +02:00
|
|
|
const struct watchlist_ops *ops;
|
2016-09-14 07:16:04 +02:00
|
|
|
};
|
|
|
|
|
2017-09-01 00:57:16 +02:00
|
|
|
struct watchlist *watchlist_new(const struct watchlist_ops *ops);
|
|
|
|
void watchlist_init(struct watchlist *watchlist,
|
|
|
|
const struct watchlist_ops *ops);
|
2016-09-14 07:16:04 +02:00
|
|
|
unsigned int watchlist_add(struct watchlist *watchlist, void *notify,
|
|
|
|
void *notify_data,
|
|
|
|
watchlist_item_destroy_func_t destroy);
|
2017-09-01 00:57:16 +02:00
|
|
|
unsigned int watchlist_link(struct watchlist *watchlist,
|
|
|
|
struct watchlist_item *item,
|
|
|
|
void *notify, void *notify_data,
|
|
|
|
watchlist_item_destroy_func_t destroy);
|
2016-09-14 07:16:04 +02:00
|
|
|
bool watchlist_remove(struct watchlist *watchlist, unsigned int id);
|
|
|
|
void watchlist_destroy(struct watchlist *watchlist);
|
|
|
|
void watchlist_free(struct watchlist *watchlist);
|
|
|
|
|
2016-09-22 22:28:29 +02:00
|
|
|
void __watchlist_prune_stale(struct watchlist *watchlist);
|
|
|
|
|
2016-09-14 07:16:04 +02:00
|
|
|
#define WATCHLIST_NOTIFY(watchlist, type, args...) \
|
|
|
|
do { \
|
|
|
|
const struct l_queue_entry *entry = \
|
|
|
|
l_queue_get_entries((watchlist)->items);\
|
|
|
|
\
|
2016-09-22 22:28:29 +02:00
|
|
|
(watchlist)->in_notify = true; \
|
2016-09-14 07:16:04 +02:00
|
|
|
for (; entry; entry = entry->next) { \
|
|
|
|
struct watchlist_item *item = entry->data; \
|
|
|
|
type t = item->notify; \
|
|
|
|
t(args, item->notify_data); \
|
|
|
|
} \
|
2016-09-22 22:28:29 +02:00
|
|
|
(watchlist)->in_notify = false; \
|
|
|
|
if ((watchlist)->stale_items) \
|
|
|
|
__watchlist_prune_stale(watchlist); \
|
2016-09-14 07:16:04 +02:00
|
|
|
} while (false) \
|
|
|
|
|
2017-09-01 00:58:36 +02:00
|
|
|
#define WATCHLIST_NOTIFY_MATCHES(watchlist, match, match_data, type, args...) \
|
|
|
|
do { \
|
|
|
|
const struct l_queue_entry *entry = \
|
|
|
|
l_queue_get_entries((watchlist)->items);\
|
|
|
|
\
|
|
|
|
(watchlist)->in_notify = true; \
|
|
|
|
for (; entry; entry = entry->next) { \
|
|
|
|
struct watchlist_item *item = entry->data; \
|
|
|
|
type t = item->notify; \
|
|
|
|
\
|
2017-09-07 23:04:43 +02:00
|
|
|
if (!match(item, match_data)) \
|
2017-09-01 00:58:36 +02:00
|
|
|
continue; \
|
|
|
|
\
|
|
|
|
t(args, item->notify_data); \
|
|
|
|
} \
|
|
|
|
(watchlist)->in_notify = false; \
|
|
|
|
if ((watchlist)->stale_items) \
|
|
|
|
__watchlist_prune_stale(watchlist); \
|
|
|
|
} while (false)
|
2017-11-14 18:25:32 +01:00
|
|
|
|
|
|
|
#define WATCHLIST_NOTIFY_NO_ARGS(watchlist, type) \
|
|
|
|
do { \
|
|
|
|
const struct l_queue_entry *entry = \
|
|
|
|
l_queue_get_entries((watchlist)->items);\
|
|
|
|
\
|
|
|
|
(watchlist)->in_notify = true; \
|
|
|
|
for (; entry; entry = entry->next) { \
|
|
|
|
struct watchlist_item *item = entry->data; \
|
|
|
|
type t = item->notify; \
|
|
|
|
t(item->notify_data); \
|
|
|
|
} \
|
|
|
|
(watchlist)->in_notify = false; \
|
|
|
|
if ((watchlist)->stale_items) \
|
|
|
|
__watchlist_prune_stale(watchlist); \
|
|
|
|
} while (false)
|