aboutsummaryrefslogtreecommitdiffstats
path: root/libparc/parc/algol/parc_EventScheduler.h
blob: d84ac5e40bb83f72d1984289539cac3529ce55fb (plain)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */

/**
 * @file parc_EventScheduler.h
 * @ingroup events
 * @brief Event scheduler
 *
 * Provides a facade implementing many regularly available event functions.
 * This is an interface that software implementors may use to substitute
 * different kinds of underlying implementations of these event management functions.
 * Notable examples are libevent and libev.
 *
 */
#ifndef libparc_parc_EventScheduler_h
#define libparc_parc_EventScheduler_h

#include <stdlib.h>
#include <stdint.h>

/*
 * Currently implemented using libevent
 */

#include <parc/algol/parc_Memory.h>
#include <parc/logging/parc_Log.h>

/**
 * @typedef PARCEventScheduler
 * @brief A structure containing private event state
 */
struct PARCEventScheduler;
typedef struct PARCEventScheduler PARCEventScheduler;

typedef enum {
    PARCEventSchedulerDispatchType_Blocking = 0x00,
    PARCEventSchedulerDispatchType_LoopOnce = 0x01,
    PARCEventSchedulerDispatchType_NonBlocking = 0x02,
} PARCEventSchedulerDispatchType;

/**
 * Create a new parcEventScheduler instance.
 *
 * A new parcEventScheduler instance is returned.
 *
 * @returns A pointer to the a PARCEvent instance.
 *
 * Example:
 * @code
 * {
 *     PARCEvent *parcEventScheduler = parcEvent_Create();
 * }
 * @endcode
 *
 */
PARCEventScheduler *parcEventScheduler_Create(void);

/**
 * Start the event eventScheduler
 *
 * @param [in] parcEventScheduler - The parcEventScheduler instance to start.
 * @param type - The mode of dispatch for this `PARCEventScheduler` instance.
 * @returns 0 on success, -1 on failure
 *
 * Example:
 * @code
 * {
 *     result = parcEventScheduler_Start(parcEventScheduler, PARCEventScheduler_Blocking);
 * }
 * @endcode
 *
 */
int parcEventScheduler_Start(PARCEventScheduler *parcEventScheduler, PARCEventSchedulerDispatchType type);

/**
 * Dispatch the event scheduler to process any pending events, blocking until
 * some events have been triggered and then processed.
 *
 * @param [in] parcEventScheduler - The parcEventScheduler instance to run.
 * @returns 0 on success, -1 on failure
 *
 * Example:
 * @code
 * {
 *     result = parcEventScheduler_DispatchBlocking(parcEventScheduler, PARCEventScheduler_Blocking);
 * }
 * @endcode
 */
int parcEventScheduler_DispatchBlocking(PARCEventScheduler *parcEventScheduler);

/**
 * Dispatch the event scheduler to process any pending events.
 *
 * If there are no pending events then the function will immediately return.
 *
 * @param [in] parcEventScheduler - The parcEventScheduler instance to run.
 * @returns 0 on success, -1 on failure
 *
 * Example:
 * @code
 * {
 *     result = parcEventScheduler_DispatchNonBlocking(parcEventScheduler, PARCEventScheduler_Blocking);
 * }
 * @endcode
 *
 */
int parcEventScheduler_DispatchNonBlocking(PARCEventScheduler *parcEventScheduler);

/**
 * Stop the event parcEventScheduler
 *
 * @param [in] parcEventScheduler instance to stop scheduling.
 * @param [in] delay time to wait before stopping, 0 for stop now
 * @returns 0 on success, -1 on failure
 *
 * Example:
 * @code
 * {
 *     result = parcEventScheduler_Stop(parcEventScheduler, timeout);
 * }
 * @endcode
 *
 */
int parcEventScheduler_Stop(PARCEventScheduler *parcEventScheduler, struct timeval *delay);

/**
 * Immediately abort the event parcEventScheduler
 *
 * @param [in] parcEventScheduler instance to abort scheduling.
 * @returns 0 on success, -1 on failure
 *
 * Example:
 * @code
 * {
 *     result = parcEventScheduler_Abort(parcEventScheduler);
 * }
 * @endcode
 *
 */
int parcEventScheduler_Abort(PARCEventScheduler *parcEventScheduler);

/**
 * Destroy a parcEventScheduler instance.
 *
 * The address of the parcEventScheduler instance is passed in.
 *
 * @param [in] parcEventScheduler address of instance to destroy.
 *
 * Example:
 * @code
 * {
 *     parcEventScheduler_Destroy(&parcEventScheduler);
 * }
 * @endcode
 *
 */
void parcEventScheduler_Destroy(PARCEventScheduler **parcEventScheduler);

/**
 * Turn on debugging flags and messages
 *
 * Example:
 * @code
 * {
 *     parcEventScheduler_EnableDebug();
 * }
 * @endcode
 *
 */
void parcEventScheduler_EnableDebug(void);

/**
 * Turn off debugging flags and messages
 *
 * Example:
 * @code
 * {
 *     parcEventScheduler_DisableDebug();
 * }
 * @endcode
 *
 */
void parcEventScheduler_DisableDebug(void);

/**
 * Internal libevent data accessor function.
 *
 * THIS IS FOR INTERNAL USE ONLY. USE WITH CAUTION.
 *
 * Example:
 * @code
 * {
 *     parcEventScheduler_GetEvBase(parcEventScheduler);
 * }
 * @endcode
 *
 */
void *parcEventScheduler_GetEvBase(PARCEventScheduler *parcEventScheduler);

/**
 * Logger accessor function
 *
 * Example:
 * @code
 * {
 *     PARCLog *logger = parcEventScheduler_GetLogger(parcEventScheduler);
 * }
 * @endcode
 *
 */
PARCLog *parcEventScheduler_GetLogger(PARCEventScheduler *parcEventScheduler);
#endif // libparc_parc_EventScheduler_h