blob: 92eb6f47e6e22578fd09cbd73909417790028004 [file] [log] [blame]
Harald Weltecbd18962019-03-03 19:02:38 +01001#pragma once
2#include <stdint.h>
3#include <stdbool.h>
4#include <pthread.h>
5#include <osmocom/core/linuxlist.h>
6
7struct bank_slot {
8 uint16_t bank_id;
9 uint16_t slot_nr;
10};
11
12static inline bool bank_slot_equals(const struct bank_slot *a, const struct bank_slot *b)
13{
14 if (a->bank_id == b->bank_id && a->slot_nr == b->slot_nr)
15 return true;
16 else
17 return false;
18}
19
20struct client_slot {
21 uint16_t client_id;
22 uint16_t slot_nr;
23};
24
25static inline bool client_slot_equals(const struct client_slot *a, const struct client_slot *b)
26{
27 if (a->client_id == b->client_id && a->slot_nr == b->slot_nr)
28 return true;
29 else
30 return false;
31}
32
33/* slot mappings are created / removed by the server */
34struct slot_mapping {
35 /* global lits of bankd slot mappings */
36 struct llist_head list;
37 /* slot on bank side */
38 struct bank_slot bank;
39 /* slot on client side */
40 struct client_slot client;
41};
42
43/* collection of slot mappings */
44struct slotmaps {
45 struct llist_head mappings;
46 pthread_rwlock_t rwlock;
47};
48
49/* thread-safe lookup of map by client:slot */
50struct slot_mapping *slotmap_by_client(struct slotmaps *maps, const struct client_slot *client);
51
52/* thread-safe lookup of map by bank:slot */
53struct slot_mapping *slotmap_by_bank(struct slotmaps *maps, const struct bank_slot *bank);
54
55/* thread-safe creating of a new bank<->client map */
56int slotmap_add(struct slotmaps *maps, const struct bank_slot *bank, const struct client_slot *client);
57
58/* thread-safe removal of a bank<->client map */
59void slotmap_del(struct slotmaps *maps, struct slot_mapping *map);
60
61/* initialize the entire map collection */
62struct slotmaps *slotmap_init(void *ctx);