stream: add a concurrency option to services, limiting parallel callbacks
[strongswan.git] / src / libstrongswan / networking / streams / stream_manager.h
1 /*
2 * Copyright (C) 2013 Martin Willi
3 * Copyright (C) 2013 revosec AG
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup stream_manager stream_manager
18 * @{ @ingroup streams
19 */
20
21 #ifndef STREAM_MANAGER_H_
22 #define STREAM_MANAGER_H_
23
24 typedef struct stream_manager_t stream_manager_t;
25
26 #include <library.h>
27 #include <networking/streams/stream_service.h>
28
29 /**
30 * Manages client-server connections and services using stream_t backends.
31 */
32 struct stream_manager_t {
33
34 /**
35 * Create a client-server connection to a service.
36 *
37 * @param uri URI of service to connect to
38 * @return stream instance, NULL on error
39 */
40 stream_t* (*connect)(stream_manager_t *this, char *uri);
41
42 /**
43 * Start a new service under an URI, accept()ing client connections.
44 *
45 * @param uri URI of service to provide
46 * @param backlog size of the backlog queue, as passed to listen()
47 * @param cb callback function invoked for each client connection
48 * @param data user data to pass to callback
49 * @param prio job priority to invoke callback with
50 * @param cncrncy maximum number of parallel callback invocations
51 * @return TRUE if service started, FALSE on failure
52 */
53 bool (*start_service)(stream_manager_t *this, char *uri, int backlog,
54 stream_service_cb_t cb, void *data,
55 job_priority_t prio, u_int cncrncy);
56
57 /**
58 * Stop a service previously create with start_service().
59 *
60 * @param uri URI of service to stop
61 */
62 void (*stop_service)(stream_manager_t *this, char *uri);
63
64 /**
65 * Register a stream backend to the manager.
66 *
67 * @param prefix prefix of URIs to use the backend for
68 * @param create constructor function for the stream
69 */
70 void (*add_stream)(stream_manager_t *this, char *prefix,
71 stream_constructor_t create);
72
73 /**
74 * Unregister stream backends from the manager.
75 *
76 * @param create constructor function passed to add_stream()
77 */
78 void (*remove_stream)(stream_manager_t *this, stream_constructor_t create);
79
80 /**
81 * Register a stream service backend to the manager.
82 *
83 * @param prefix prefix of URIs to use the backend for
84 * @param create constructor function for the stream service
85 */
86 void (*add_service)(stream_manager_t *this, char *prefix,
87 stream_service_constructor_t create);
88
89 /**
90 * Unregister stream service backends from the manager.
91 *
92 * @param create constructor function passed to add_service()
93 */
94 void (*remove_service)(stream_manager_t *this,
95 stream_service_constructor_t create);
96
97 /**
98 * Destroy a stream_manager_t.
99 */
100 void (*destroy)(stream_manager_t *this);
101 };
102
103 /**
104 * Create a stream_manager instance.
105 */
106 stream_manager_t *stream_manager_create();
107
108 #endif /** STREAM_MANAGER_H_ @}*/