libosmocore 1.13.1.1-afb4 Osmocom core library

tdef.h
Go to the documentation of this file.
1
4/*
5 * (C) 2018-2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
6 *
7 * All Rights Reserved
8 *
9 * SPDX-License-Identifier: GPL-2.0+
10 *
11 * Author: Neels Hofmeyr <neels@hofmeyr.de>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU Affero General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Affero General Public License for more details.
22 *
23 * You should have received a copy of the GNU Affero General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 */
26#pragma once
27
28#include <stdint.h>
29#include <osmocom/core/utils.h>
30
31 struct osmo_fsm_inst;
32
38 enum osmo_tdef_unit {
39 OSMO_TDEF_S = 0,
40 OSMO_TDEF_MS,
41 OSMO_TDEF_M,
42 OSMO_TDEF_CUSTOM,
43 OSMO_TDEF_US,
44};
45
46 extern const struct value_string osmo_tdef_unit_names[];
48 static inline const char *osmo_tdef_unit_name(enum osmo_tdef_unit val)
49{ return get_value_string(osmo_tdef_unit_names, val); }
50
65 struct osmo_tdef {
70 const int T;
73 const unsigned long default_val;
74 const enum osmo_tdef_unit unit;
77 const char *desc;
80 unsigned long val;
82 unsigned long min_val;
84 unsigned long max_val;
85};
86
98#define osmo_tdef_for_each(t, tdefs) \
99 for (t = tdefs; t && (t->T || t->default_val || t->desc); t++)
100
101 void osmo_tdefs_reset(struct osmo_tdef *tdefs);
102 unsigned long osmo_tdef_get(const struct osmo_tdef *tdefs, int T, enum osmo_tdef_unit as_unit,
103 long val_if_not_present);
104 struct osmo_tdef *osmo_tdef_get_entry(struct osmo_tdef *tdefs, int T);
105 int osmo_tdef_set(struct osmo_tdef *tdefs, int T, unsigned long val, enum osmo_tdef_unit val_unit);
106 bool osmo_tdef_val_in_range(struct osmo_tdef *tdef, unsigned long new_val);
107 int osmo_tdef_range_str_buf(char *buf, size_t buf_len, struct osmo_tdef *t);
108
111 struct osmo_tdef_state_timeout {
115 int T;
118 bool keep_timer;
119};
120
121 const struct osmo_tdef_state_timeout *osmo_tdef_get_state_timeout(uint32_t state,
122 const struct osmo_tdef_state_timeout *timeouts_array);
123
163#define osmo_tdef_fsm_inst_state_chg(fi, state, timeouts_array, tdefs, default_timeout) \
164 _osmo_tdef_fsm_inst_state_chg(fi, state, timeouts_array, tdefs, default_timeout, \
165 __FILE__, __LINE__)
166 int _osmo_tdef_fsm_inst_state_chg(struct osmo_fsm_inst *fi, uint32_t state,
167 const struct osmo_tdef_state_timeout *timeouts_array,
168 const struct osmo_tdef *tdefs, signed long default_timeout,
169 const char *file, int line);
170
175 struct osmo_tdef_group {
176 const char *name;
177 const char *desc;
178 struct osmo_tdef *tdefs;
179};
180
185#define osmo_tdef_groups_for_each(g, tdef_groups) \
186 for (g = tdef_groups; g && g->tdefs; g++)
187
tdefs
struct osmo_tdef * tdefs
osmo_tdef_unit_name
static const char * osmo_tdef_unit_name(enum osmo_tdef_unit val)
Definition: tdef.h:48
_osmo_tdef_fsm_inst_state_chg
int _osmo_tdef_fsm_inst_state_chg(struct osmo_fsm_inst *fi, uint32_t state, const struct osmo_tdef_state_timeout *timeouts_array, const struct osmo_tdef *tdefs, signed long default_timeout, const char *file, int line)
osmo_tdefs_reset
void osmo_tdefs_reset(struct osmo_tdef *tdefs)
Set all osmo_tdef values to the default_val.
Definition: tdef.c:155
osmo_tdef_get_entry
struct osmo_tdef * osmo_tdef_get_entry(struct osmo_tdef *tdefs, int T)
Find tdef entry matching T.
Definition: tdef.c:226
osmo_tdef_get
unsigned long osmo_tdef_get(const struct osmo_tdef *tdefs, int T, enum osmo_tdef_unit as_unit, long val_if_not_present)
Return the value of a T timer from a list of osmo_tdef, in the given unit.
Definition: tdef.c:209
osmo_tdef_unit_names
const struct value_string osmo_tdef_unit_names[]
Definition: tdef.c:374
osmo_tdef_val_in_range
bool osmo_tdef_val_in_range(struct osmo_tdef *tdef, unsigned long new_val)
Check if value new_val is in range of valid possible values for timer entry tdef.
Definition: tdef.c:264
osmo_tdef_get_state_timeout
const struct osmo_tdef_state_timeout * osmo_tdef_get_state_timeout(uint32_t state, const struct osmo_tdef_state_timeout *timeouts_array)
Using osmo_tdef for osmo_fsm_inst: find a given state's osmo_tdef_state_timeout entry.
Definition: tdef.c:321
osmo_tdef_range_str_buf
int osmo_tdef_range_str_buf(char *buf, size_t buf_len, struct osmo_tdef *t)
Write string representation of osmo_tdef range into buf.
Definition: tdef.c:277
osmo_tdef_unit
osmo_tdef_unit
Definition: tdef.h:38
osmo_tdef_set
int osmo_tdef_set(struct osmo_tdef *tdefs, int T, unsigned long val, enum osmo_tdef_unit val_unit)
Set value in entry matching T, converting val from val_unit to unit of T.
Definition: tdef.c:244
OSMO_TDEF_CUSTOM
@ OSMO_TDEF_CUSTOM
unspecified unit, explained in osmo_tdef.desc.
Definition: tdef.h:42
OSMO_TDEF_US
@ OSMO_TDEF_US
microseconds
Definition: tdef.h:43
OSMO_TDEF_M
@ OSMO_TDEF_M
minutes
Definition: tdef.h:41
OSMO_TDEF_S
@ OSMO_TDEF_S
most T are in seconds, keep 0 as default.
Definition: tdef.h:39
OSMO_TDEF_MS
@ OSMO_TDEF_MS
milliseconds
Definition: tdef.h:40
file
write Write running configuration to or terminal n Write configuration to the file(same as write file)\n") ALIAS(config_write_file
get_value_string
const char * get_value_string(const struct value_string *vs, uint32_t val)
get human-readable string for given value
Definition: utils.c:63
osmo_fsm_inst
a single instanceof an osmocom finite state machine
Definition: fsm.h:87
osmo_tdef_group
Manage timer definitions in named groups.
Definition: tdef.h:175
osmo_tdef_group::name
const char * name
Definition: tdef.h:176
osmo_tdef_group::tdefs
struct osmo_tdef * tdefs
Definition: tdef.h:178
osmo_tdef_group::desc
const char * desc
Definition: tdef.h:177
osmo_tdef_state_timeout
Using osmo_tdef for osmo_fsm_inst: array entry for a mapping of state numbers to timeout definitions.
Definition: tdef.h:111
osmo_tdef_state_timeout::keep_timer
bool keep_timer
If true, call osmo_fsm_inst_state_chg_keep_timer().
Definition: tdef.h:118
osmo_tdef_state_timeout::T
int T
Timer number to match struct osmo_tdef.T, and to pass to osmo_fsm_inst_state_chg().
Definition: tdef.h:115
osmo_tdef
Define a GSM timer of the form Tnnn, with unit, default value and doc string.
Definition: tdef.h:65
osmo_tdef::unit
enum osmo_tdef_unit unit
Definition: tdef.h:74
osmo_tdef::max_val
unsigned long max_val
Maximum timer value (in this tdef unit), checked if set (not zero).
Definition: tdef.h:84
osmo_tdef::desc
const char * desc
Human readable description.
Definition: tdef.h:77
osmo_tdef::T
const int T
T1234 or X1234 number, corresponding to struct osmo_fsm_inst::T.
Definition: tdef.h:70
osmo_tdef::default_val
const unsigned long default_val
Timeout duration (according to unit), default value; type corresponds to osmo_fsm_inst_state_chg()'s ...
Definition: tdef.h:73
osmo_tdef::min_val
unsigned long min_val
Minimum timer value (in this tdef unit), checked if set (not zero).
Definition: tdef.h:82
osmo_tdef::val
unsigned long val
Currently active timeout value, e.g.
Definition: tdef.h:80
value_string
A mapping between human-readable string and numeric value.
Definition: utils.h:51
utils.h