libosmocore  1.0.1.85-9f28
Osmocom core library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
43 };
44 
45 extern const struct value_string osmo_tdef_unit_names[];
47 static inline const char *osmo_tdef_unit_name(enum osmo_tdef_unit val)
48 { return get_value_string(osmo_tdef_unit_names, val); }
49 
64 struct osmo_tdef {
69  const int T;
72  const unsigned long default_val;
73  const enum osmo_tdef_unit unit;
76  const char *desc;
79  unsigned long val;
80 };
81 
93 #define osmo_tdef_for_each(t, tdefs) \
94  for (t = tdefs; t && (t->T || t->default_val || t->desc); t++)
95 
96 void osmo_tdefs_reset(struct osmo_tdef *tdefs);
97 unsigned long osmo_tdef_get(const struct osmo_tdef *tdefs, int T, enum osmo_tdef_unit as_unit,
98  unsigned long val_if_not_present);
99 struct osmo_tdef *osmo_tdef_get_entry(struct osmo_tdef *tdefs, int T);
100 
107  int T;
111 };
112 
113 const struct osmo_tdef_state_timeout *osmo_tdef_get_state_timeout(uint32_t state,
114  const struct osmo_tdef_state_timeout *timeouts_array);
115 
152 #define osmo_tdef_fsm_inst_state_chg(fi, state, timeouts_array, tdefs, default_timeout) \
153  _osmo_tdef_fsm_inst_state_chg(fi, state, timeouts_array, tdefs, default_timeout, \
154  __FILE__, __LINE__)
155 int _osmo_tdef_fsm_inst_state_chg(struct osmo_fsm_inst *fi, uint32_t state,
156  const struct osmo_tdef_state_timeout *timeouts_array,
157  const struct osmo_tdef *tdefs, unsigned long default_timeout,
158  const char *file, int line);
159 
165  const char *name;
166  const char *desc;
167  struct osmo_tdef *tdefs;
168 };
169 
174 #define osmo_tdef_groups_for_each(g, tdef_groups) \
175  for (g = tdef_groups; g && g->tdefs; g++)
176 
unsigned long val
Currently active timeout value, e.g.
Definition: tdef.h:79
static const char * osmo_tdef_unit_name(enum osmo_tdef_unit val)
Definition: tdef.h:47
const char * get_value_string(const struct value_string *vs, uint32_t val)
get human-readable string for given value
Definition: utils.c:55
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:237
most T are in seconds, keep 0 as default.
Definition: tdef.h:39
bool keep_timer
If true, call osmo_fsm_inst_state_chg_keep_timer().
Definition: tdef.h:110
minutes
Definition: tdef.h:41
A mapping between human-readable string and numeric value.
Definition: utils.h:37
enum osmo_tdef_unit unit
Definition: tdef.h:73
const unsigned long default_val
Timeout duration (according to unit), default value; type corresponds to osmo_fsm_inst_state_chg()'s ...
Definition: tdef.h:72
write Write running configuration to or terminal n Write configuration to the file(same as write file)\n") ALIAS(config_write_file
Manage timer definitions in named groups.
Definition: tdef.h:164
const char * desc
Definition: tdef.h:166
milliseconds
Definition: tdef.h:40
const char * desc
Human readable description.
Definition: tdef.h:76
struct osmo_tdef * tdefs
Definition: tdef.h:167
a single instanceof an osmocom finite state machine
Definition: fsm.h:86
osmo_tdef_unit
Definition: tdef.h:38
struct osmo_tdef * tdefs
Using osmo_tdef for osmo_fsm_inst: array entry for a mapping of state numbers to timeout definitions...
Definition: tdef.h:103
const char * name
Definition: tdef.h:165
unspecified unit, explained in osmo_tdef.desc.
Definition: tdef.h:42
void osmo_tdefs_reset(struct osmo_tdef *tdefs)
Set all osmo_tdef values to the default_val.
Definition: tdef.c:141
const int T
T1234 or X1234 number, corresponding to struct osmo_fsm_inst::T.
Definition: tdef.h:69
unsigned long osmo_tdef_get(const struct osmo_tdef *tdefs, int T, enum osmo_tdef_unit as_unit, unsigned 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:186
struct osmo_tdef * osmo_tdef_get_entry(struct osmo_tdef *tdefs, int T)
Find tdef entry matching T.
Definition: tdef.c:203
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, unsigned long default_timeout, const char *file, int line)
See invocation macro osmo_tdef_fsm_inst_state_chg() instead.
Definition: tdef.c:251
Define a GSM timer of the form Tnnn, with unit, default value and doc string.
Definition: tdef.h:64
int T
Timer number to match struct osmo_tdef.T, and to pass to osmo_fsm_inst_state_chg().
Definition: tdef.h:107
const struct value_string osmo_tdef_unit_names[]
Definition: tdef.c:279