open62541 1.3.12
Open source implementation of OPC UA
Loading...
Searching...
No Matches
ua_timer.h
Go to the documentation of this file.
1/** This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 *
5 * Copyright 2017, 2018, 2021 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
6 * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
7 */
8
9#ifndef UA_TIMER_H_
10#define UA_TIMER_H_
11
12#include "ua_util_internal.h"
13#include "aa_tree.h"
14
16
17/** The timer is protected by its own mutex. The mutex is released before calling
18 * into the callbacks. So the timer can be modified from the callbacks it is
19 * executing. Also, the timer mutex can never lead to locking. Because the timer
20 * mutex will be left without acquiring another mutex.
21 *
22 * Obviously, the timer must not be deleted from within one of its
23 * callbacks. */
24
25/** Callback where the application is either a client or a server */
26typedef void (*UA_ApplicationCallback)(void *application, void *data);
27
28typedef struct UA_TimerEntry {
30 UA_TimerPolicy timerPolicy; /* Timer policy to handle cycle misses */
31 UA_DateTime nextTime; /* The next time when the callback
32 * is to be executed */
33 UA_UInt64 interval; /* Interval in 100ns resolution. If
34 the interval is zero, the
35 callback is not repeated and
36 removed after execution. */
39 void *data;
40
42 UA_UInt64 id; /* Id of the entry */
44
45typedef struct {
46 struct aa_head root; /* The root of the time-sorted tree */
47 struct aa_head idRoot; /* The root of the id-sorted tree */
48 UA_UInt64 idCounter; /* Generate unique identifiers. Identifiers are
49 * always above zero. */
50#if UA_MULTITHREADING >= 100
51 UA_Lock timerMutex;
52#endif
53} UA_Timer;
54
55void
57
60 void *application, void *data, UA_DateTime date,
61 UA_UInt64 *callbackId);
62
63/** Add a pre-allocated and pre-filled UA_TimerEntry. This cannot fail. It is
64 * used, for example, for delayed memory reclamation where the data structure
65 * begins with a UA_TimerEntry. */
66void
68
71 void *application, void *data, UA_Double interval_ms,
72 UA_DateTime *baseTime, UA_TimerPolicy timerPolicy,
73 UA_UInt64 *callbackId);
74
77 UA_Double interval_ms, UA_DateTime *baseTime,
78 UA_TimerPolicy timerPolicy);
79
80void
82
83/** Process (dispatch) the repeated callbacks that have timed out. Returns the
84 * timestamp of the next scheduled repeated callback. Not thread-safe.
85 * Application is a pointer to the client / server environment for the callback.
86 * Dispatched is set to true when at least one callback was run / dispatched. */
87typedef void
88(*UA_TimerExecutionCallback)(void *executionApplication, UA_ApplicationCallback cb,
89 void *callbackApplication, void *data);
90
93 UA_TimerExecutionCallback executionCallback,
94 void *executionApplication);
95
96void
98
100
101#endif /* UA_TIMER_H_ */
#define _UA_BEGIN_DECLS
#undef UA_DEBUG_DUMP_PKGS
Definition config.h:89
#define _UA_END_DECLS
Definition config.h:96
struct aa_entry idTreeEntry
Definition ua_timer.h:41
UA_ApplicationCallback callback
Definition ua_timer.h:37
void * data
Definition ua_timer.h:39
struct aa_entry treeEntry
Definition ua_timer.h:29
UA_UInt64 id
Definition ua_timer.h:42
void * application
Definition ua_timer.h:38
UA_DateTime nextTime
Definition ua_timer.h:31
UA_TimerPolicy timerPolicy
Definition ua_timer.h:30
UA_UInt64 interval
Definition ua_timer.h:33
UA_UInt64 idCounter
Definition ua_timer.h:48
Definition aa_tree.h:21
int64_t UA_DateTime
Definition types.h:144
uint32_t UA_StatusCode
Definition types.h:77
double UA_Double
Definition types.h:74
uint64_t UA_UInt64
Definition types.h:66
_UA_BEGIN_DECLS typedef void(* UA_ApplicationCallback)(void *application, void *data)
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition ua_timer.h:26
UA_DateTime UA_Timer_process(UA_Timer *t, UA_DateTime nowMonotonic, UA_TimerExecutionCallback executionCallback, void *executionApplication)
UA_StatusCode UA_Timer_addTimedCallback(UA_Timer *t, UA_ApplicationCallback callback, void *application, void *data, UA_DateTime date, UA_UInt64 *callbackId)
UA_StatusCode UA_Timer_addRepeatedCallback(UA_Timer *t, UA_ApplicationCallback callback, void *application, void *data, UA_Double interval_ms, UA_DateTime *baseTime, UA_TimerPolicy timerPolicy, UA_UInt64 *callbackId)
void UA_Timer_clear(UA_Timer *t)
void(* UA_TimerExecutionCallback)(void *executionApplication, UA_ApplicationCallback cb, void *callbackApplication, void *data)
Process (dispatch) the repeated callbacks that have timed out.
Definition ua_timer.h:88
void UA_Timer_init(UA_Timer *t)
struct UA_TimerEntry UA_TimerEntry
void UA_Timer_removeCallback(UA_Timer *t, UA_UInt64 callbackId)
UA_StatusCode UA_Timer_changeRepeatedCallback(UA_Timer *t, UA_UInt64 callbackId, UA_Double interval_ms, UA_DateTime *baseTime, UA_TimerPolicy timerPolicy)
void UA_Timer_addTimerEntry(UA_Timer *t, UA_TimerEntry *te, UA_UInt64 *callbackId)
Add a pre-allocated and pre-filled UA_TimerEntry.
UA_TimerPolicy
Timer policy to handle cycle misses.
Definition util.h:31