-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnotif.c
More file actions
62 lines (49 loc) · 1.48 KB
/
notif.c
File metadata and controls
62 lines (49 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* =====================================================================================
*
* Filename: notif.c
*
* Description: This file implements Generaic Notif Chain structures definitions
*
* Version: 1.0
* Created: 10/17/2020 01:56:00 AM
* Revision: none
* Compiler: gcc
*
* Author: ABHISHEK SAGAR (), sachinites@gmail.com
* Organization: Juniper Networks
*
* =====================================================================================
*/
#include <stdlib.h>
#include <memory.h>
#include <assert.h>
#include "notif.h"
void
nfc_register_notif_chain(notif_chain_t *nfc,
notif_chain_elem_t *nfce){
notif_chain_elem_t *new_nfce = calloc(1, sizeof(notif_chain_elem_t));
memcpy(new_nfce, nfce, sizeof(notif_chain_elem_t));
init_glthread(&new_nfce->glue);
glthread_add_next(&nfc->notif_chain_head, &new_nfce->glue);
}
void
nfc_invoke_notif_chain(notif_chain_t *nfc,
void *arg, size_t arg_size,
char *key, size_t key_size){
glthread_t *curr;
notif_chain_elem_t *nfce;
assert(key_size <= MAX_NOTIF_KEY_SIZE);
ITERATE_GLTHREAD_BEGIN(&nfc->notif_chain_head, curr){
nfce = glthread_glue_to_notif_chain_elem(curr);
if(!(key && key_size &&
nfce->is_key_set && (key_size == nfce->key_size))){
nfce->app_cb(arg, arg_size);
}
else {
if(memcmp(key, nfce->key, key_size) == 0) {
nfce->app_cb(arg, arg_size);
}
}
}ITERATE_GLTHREAD_END(&nfc->notif_chain_head, curr);
}