1 /*
2  * Copyright (c) 2018 Balabit
3  * Copyright (c) 2018 László Várady <laszlo.varady@balabit.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  * As an additional exemption you are allowed to compile & link against the
20  * OpenSSL libraries as published by the OpenSSL project. See the file
21  * COPYING for details.
22  *
23  */
24 
25 #ifndef LOGTHRSOURCEDRV_H
26 #define LOGTHRSOURCEDRV_H
27 
28 #include "syslog-ng.h"
29 #include "driver.h"
30 #include "logsource.h"
31 #include "cfg.h"
32 #include "logpipe.h"
33 #include "logmsg/logmsg.h"
34 
35 typedef struct _LogThreadedSourceDriver LogThreadedSourceDriver;
36 typedef struct _LogThreadedSourceWorker LogThreadedSourceWorker;
37 
38 typedef void (*LogThreadedSourceWorkerRunFunc)(LogThreadedSourceDriver *);
39 typedef void (*LogThreadedSourceWorkerRequestExitFunc)(LogThreadedSourceDriver *);
40 typedef void (*LogThreadedSourceWorkerWakeupFunc)(LogThreadedSourceDriver *);
41 
42 typedef struct _LogThreadedSourceWorkerOptions
43 {
44   LogSourceOptions super;
45   MsgFormatOptions parse_options;
46   AckTrackerFactory *ack_tracker_factory;
47 } LogThreadedSourceWorkerOptions;
48 
49 struct _LogThreadedSourceDriver
50 {
51   LogSrcDriver super;
52   LogThreadedSourceWorkerOptions worker_options;
53   LogThreadedSourceWorker *worker;
54 
55   const gchar *(*format_stats_instance)(LogThreadedSourceDriver *self);
56 };
57 
58 void log_threaded_source_worker_options_defaults(LogThreadedSourceWorkerOptions *options);
59 void log_threaded_source_worker_options_init(LogThreadedSourceWorkerOptions *options, GlobalConfig *cfg,
60                                              const gchar *group_name);
61 void log_threaded_source_worker_options_destroy(LogThreadedSourceWorkerOptions *options);
62 
63 void log_threaded_source_driver_init_instance(LogThreadedSourceDriver *self, GlobalConfig *cfg);
64 gboolean log_threaded_source_driver_init_method(LogPipe *s);
65 gboolean log_threaded_source_driver_deinit_method(LogPipe *s);
66 void log_threaded_source_driver_free_method(LogPipe *s);
67 
68 void log_threaded_source_driver_set_worker_run_func(LogThreadedSourceDriver *self, LogThreadedSourceWorkerRunFunc run);
69 void log_threaded_source_driver_set_worker_request_exit_func(LogThreadedSourceDriver *self,
70     LogThreadedSourceWorkerRequestExitFunc request_exit);
71 
72 static inline LogSourceOptions *
log_threaded_source_driver_get_source_options(LogDriver * s)73 log_threaded_source_driver_get_source_options(LogDriver *s)
74 {
75   LogThreadedSourceDriver *self = (LogThreadedSourceDriver *) s;
76 
77   return &self->worker_options.super;
78 }
79 
80 static inline MsgFormatOptions *
log_threaded_source_driver_get_parse_options(LogDriver * s)81 log_threaded_source_driver_get_parse_options(LogDriver *s)
82 {
83   LogThreadedSourceDriver *self = (LogThreadedSourceDriver *) s;
84 
85   return &self->worker_options.parse_options;
86 }
87 
88 /* blocking API */
89 void log_threaded_source_blocking_post(LogThreadedSourceDriver *self, LogMessage *msg);
90 
91 /* non-blocking API, use it wisely (thread boundaries) */
92 void log_threaded_source_set_wakeup_func(LogThreadedSourceDriver *self, LogThreadedSourceWorkerWakeupFunc wakeup);
93 void log_threaded_source_post(LogThreadedSourceDriver *self, LogMessage *msg);
94 gboolean log_threaded_source_free_to_send(LogThreadedSourceDriver *self);
95 
96 #endif
97