1 /*****
2 *
3 * Copyright (C) 2001-2015 CS-SI. All Rights Reserved.
4 * Author: Yoann Vandoorselaere <yoann.v@prelude-ids.com>
5 *
6 * This file is part of the Prelude library.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 *****/
23 
24 #ifndef _LIBPRELUDE_PRELUDE_CONNECTION_POOL_H
25 #define _LIBPRELUDE_PRELUDE_CONNECTION_POOL_H
26 
27 #include "prelude-list.h"
28 #include "prelude-connection.h"
29 
30 #ifdef __cplusplus
31  extern "C" {
32 #endif
33 
34 typedef enum {
35         PRELUDE_CONNECTION_POOL_FLAGS_RECONNECT        = 0x01,
36         PRELUDE_CONNECTION_POOL_FLAGS_FAILOVER         = 0x02
37 } prelude_connection_pool_flags_t;
38 
39 
40 typedef enum {
41         PRELUDE_CONNECTION_POOL_EVENT_INPUT            = 0x01,
42         PRELUDE_CONNECTION_POOL_EVENT_DEAD             = 0x02,
43         PRELUDE_CONNECTION_POOL_EVENT_ALIVE            = 0x04
44 } prelude_connection_pool_event_t;
45 
46 typedef struct prelude_connection_pool prelude_connection_pool_t;
47 
48 
49 void prelude_connection_pool_broadcast(prelude_connection_pool_t *pool, prelude_msg_t *msg);
50 
51 void prelude_connection_pool_broadcast_async(prelude_connection_pool_t *pool, prelude_msg_t *msg);
52 
53 int prelude_connection_pool_init(prelude_connection_pool_t *pool);
54 
55 int prelude_connection_pool_new(prelude_connection_pool_t **ret,
56                                 prelude_client_profile_t *cp,
57                                 prelude_connection_permission_t permission);
58 
59 prelude_list_t *prelude_connection_pool_get_connection_list(prelude_connection_pool_t *pool);
60 
61 int prelude_connection_pool_add_connection(prelude_connection_pool_t *pool, prelude_connection_t *cnx);
62 
63 int prelude_connection_pool_del_connection(prelude_connection_pool_t *pool, prelude_connection_t *cnx);
64 
65 int prelude_connection_pool_set_connection_dead(prelude_connection_pool_t *pool, prelude_connection_t *cnx);
66 int prelude_connection_pool_set_connection_alive(prelude_connection_pool_t *pool, prelude_connection_t *cnx);
67 
68 int prelude_connection_pool_set_connection_string(prelude_connection_pool_t *pool, const char *cfgstr);
69 
70 const char *prelude_connection_pool_get_connection_string(prelude_connection_pool_t *pool);
71 
72 void prelude_connection_pool_destroy(prelude_connection_pool_t *pool);
73 
74 prelude_connection_pool_t *prelude_connection_pool_ref(prelude_connection_pool_t *pool);
75 
76 prelude_connection_pool_flags_t prelude_connection_pool_get_flags(prelude_connection_pool_t *pool);
77 
78 void prelude_connection_pool_set_flags(prelude_connection_pool_t *pool, prelude_connection_pool_flags_t flags);
79 
80 void prelude_connection_pool_set_required_permission(prelude_connection_pool_t *pool, prelude_connection_permission_t req_perm);
81 
82 void prelude_connection_pool_set_data(prelude_connection_pool_t *pool, void *data);
83 
84 void *prelude_connection_pool_get_data(prelude_connection_pool_t *pool);
85 
86 int prelude_connection_pool_recv(prelude_connection_pool_t *pool, int timeout, prelude_connection_t **outcon, prelude_msg_t **outmsg);
87 
88 int prelude_connection_pool_check_event(prelude_connection_pool_t *pool, int timeout,
89                                         int (*event_cb)(prelude_connection_pool_t *pool,
90                                                         prelude_connection_pool_event_t event,
91                                                         prelude_connection_t *cnx, void *extra), void *extra);
92 
93 void prelude_connection_pool_set_global_event_handler(prelude_connection_pool_t *pool,
94                                                       prelude_connection_pool_event_t wanted_events,
95                                                       int (*callback)(prelude_connection_pool_t *pool,
96                                                                       prelude_connection_pool_event_t events));
97 
98 void prelude_connection_pool_set_event_handler(prelude_connection_pool_t *pool,
99                                                prelude_connection_pool_event_t wanted_events,
100                                                int (*callback)(prelude_connection_pool_t *pool,
101                                                                prelude_connection_pool_event_t events,
102                                                                prelude_connection_t *cnx));
103 
104 #ifdef __cplusplus
105  }
106 #endif
107 
108 #endif /* _LIBPRELUDE_PRELUDE_CONNECTION_POOL_H */
109