The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
control.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /**
19  * $Id: c82782bbbfad0f10cf1b9db838006f90bb8cc4c3 $
20  *
21  * @file io/control.h
22  * @brief control-plane signaling
23  *
24  * @copyright 2016 Alan DeKok (aland@freeradius.org)
25  */
26 RCSIDH(control_h, "$Id: c82782bbbfad0f10cf1b9db838006f90bb8cc4c3 $")
27 
28 #include <freeradius-devel/io/atomic_queue.h>
29 #include <freeradius-devel/io/ring_buffer.h>
30 #include <freeradius-devel/util/time.h>
31 #include <freeradius-devel/util/event.h>
32 
33 #include <sys/types.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /**
40  * A one-way control plane signal.
41  *
42  * Multiple-producer, single consumer.
43  */
44 typedef struct fr_control_s fr_control_t;
45 typedef void (*fr_control_callback_t)(void *ctx, void const *data, size_t data_size, fr_time_t now);
46 
47 /*
48  * A suggestion for max # of messages, and max message size.
49  */
50 #define FR_CONTROL_MAX_MESSAGES (1024)
51 #define FR_CONTROL_MAX_SIZE (64)
52 
53 /*
54  * A list of pre-allocated IDs, so that the callers don't have to manage their own.
55  */
56 #define FR_CONTROL_ID_CHANNEL (1)
57 #define FR_CONTROL_ID_LISTEN (2)
58 #define FR_CONTROL_ID_WORKER (3)
59 #define FR_CONTROL_ID_DIRECTORY (4)
60 #define FR_CONTROL_ID_INJECT (5)
61 #define FR_CONTROL_ID_LISTEN_DEAD (6)
62 
64 
66 
67 int fr_control_message_send(fr_control_t *c, fr_ring_buffer_t *rb, uint32_t id, void *data, size_t data_size) CC_HINT(nonnull);
68 
69 int fr_control_message_push(fr_control_t *c, fr_ring_buffer_t *rb, uint32_t id, void *data, size_t data_size) CC_HINT(nonnull);
70 ssize_t fr_control_message_pop(fr_atomic_queue_t *aq, uint32_t *p_id, void *data, size_t data_size) CC_HINT(nonnull);
71 
72 int fr_control_callback_add(fr_control_t *c, uint32_t id, void *ctx, fr_control_callback_t callback) CC_HINT(nonnull(1,4));
74 
76 
77 #ifdef __cplusplus
78 }
79 #endif
Structure to hold the atomic queue.
Definition: atomic_queue.c:54
#define RCSIDH(h, id)
Definition: build.h:482
int fr_control_gc(fr_control_t *c, fr_ring_buffer_t *rb)
ssize_t fr_control_message_pop(fr_atomic_queue_t *aq, uint32_t *p_id, void *data, size_t data_size)
Pop control-plane message.
Definition: control.c:377
fr_control_t * fr_control_create(TALLOC_CTX *ctx, fr_event_list_t *el, fr_atomic_queue_t *aq))
Create a control-plane signaling path.
Definition: control.c:149
int fr_control_message_send(fr_control_t *c, fr_ring_buffer_t *rb, uint32_t id, void *data, size_t data_size)
Send a control-plane message.
Definition: control.c:343
int fr_control_message_push(fr_control_t *c, fr_ring_buffer_t *rb, uint32_t id, void *data, size_t data_size)
Push a control-plane message.
Definition: control.c:298
int fr_control_callback_add(fr_control_t *c, uint32_t id, void *ctx, fr_control_callback_t callback))
Register a callback for an ID.
Definition: control.c:417
int fr_control_same_thread(fr_control_t *c)
Definition: control.c:472
int fr_control_callback_delete(fr_control_t *c, uint32_t id)
Delete a callback for an ID.
Definition: control.c:454
void(* fr_control_callback_t)(void *ctx, void const *data, size_t data_size, fr_time_t now)
Definition: control.h:45
static fr_ring_buffer_t * rb
Definition: control_test.c:51
static fr_atomic_queue_t * aq
Definition: control_test.c:47
The control structure.
Definition: control.c:79
Stores all information relating to an event list.
Definition: event.c:411
unsigned int uint32_t
Definition: merged_model.c:33
long int ssize_t
Definition: merged_model.c:24
"server local" time.
Definition: time.h:69
static fr_event_list_t * el
static fr_slen_t data
Definition: value.h:1265
int nonnull(2, 5))