Newer
Older
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "act_proc.h"
#include "../util/alg_ds/ds/lock_guard/lock_guard.h"
#include "../util/alg_ds/alg/find.h"
#include <assert.h>
#include <pthread.h>
void init_act_proc(act_proc_t* p)
{
assert(p != NULL);
assoc_reg_init(&p->reg, sizeof(act_proc_val_t ));
pthread_mutexattr_t *mtx_attr = NULL;
#ifdef DEBUG
*mtx_attr = PTHREAD_MUTEX_ERRORCHECK;
#endif
int rc = pthread_mutex_init(&p->mtx, mtx_attr );
assert(rc == 0);
}
void free_act_proc(act_proc_t* p)
{
assert(p != NULL);
assoc_reg_free(&p->reg);
int rc = pthread_mutex_destroy(&p->mtx);
assert(rc == 0);
}
void free_act_proc_val(void* value)
{
assert(value != NULL);
act_proc_val_t* v = (act_proc_val_t*) value;
free_global_e2_node_id(&v->e2_node);
}
static
bool valid_proc_type(act_proc_val_e type)
{
if(type == RIC_SUBSCRIPTION_PROCEDURE_ACTIVE
// || type == RIC_SUBSCRIPTION_DELETE_PROCEDURE_ACTIVE
// || type == RIC_INDICATION_PROCEDURE_ACTIVE
|| type == RIC_CONTROL_PROCEDURE_ACTIVE
)
return true;
return false;
}
uint32_t add_act_proc(act_proc_t* p, act_proc_val_e type, ric_gen_id_t id, global_e2_node_id_t const* e2_node, void(*sm_cb)(sm_ag_if_rd_t const *))
{
assert(p != NULL);
assert(valid_proc_type(type) == true );
lock_guard(&p->mtx);
act_proc_val_t val = { .type = type,
.id = id,
.sm_cb = sm_cb,
.e2_node = cp_global_e2_node_id(e2_node)
};
uint32_t const ric_req_id = assoc_reg_push_back(&p->reg, &val, sizeof(act_proc_val_t));
return ric_req_id;
}
void rm_act_proc(act_proc_t* p, uint16_t ric_req_id )
{
assert(p != NULL);
lock_guard(&p->mtx);
void* it = assoc_reg_front(&p->reg);
void* end = assoc_reg_end(&p->reg);
it = find_reg(&p->reg, it, end, ric_req_id );
assert(it != end && "ric_req_id key value not found in the registry" );
void* next = assoc_reg_next(&p->reg, it);
assoc_reg_erase(&p->reg, it, next, free_act_proc_val);
}
act_proc_ans_t find_act_proc(act_proc_t* act, uint16_t ric_req_id)
{
assert(act != NULL);
lock_guard(&act->mtx);
void* it = assoc_reg_front(&act->reg);
void* end = assoc_reg_end(&act->reg);
it = find_reg(&act->reg, it, end, ric_req_id );
if(it == end){
act_proc_ans_t ans = {.ok = false,
.error = "ric_req_id not found in the registry" };
return ans;
}
assert(it != end && "ric_req_id key value not found in the registry" );
act_proc_val_t* val = (act_proc_val_t*)assoc_reg_value(&act->reg ,it);
val->id.ric_req_id = ric_req_id;
act_proc_ans_t ans = {.ok = true,
.val = *val };
return ans;
}