syslog-ng source
poll-events.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2013 Balabit
3  * Copyright (c) 1998-2013 Balázs Scheidler
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 #ifndef POLL_EVENTS_H_INCLUDED
25 #define POLL_EVENTS_H_INCLUDED
26 
27 #include "syslog-ng.h"
28 
29 typedef enum
30 {
38 
39 typedef struct _PollEvents PollEvents;
40 typedef void (*PollCallback)(gpointer user_data);
41 typedef gboolean (*PollChecker)(PollEvents *self, gpointer user_data);
42 
43 /* TODO: Poll is just a legacy word here, rename to sg. more appropriate (e.g. FollowEvents) */
45 {
48  gpointer callback_data;
49  gpointer checker_data;
50 
51  void (*start_watches)(PollEvents *self);
52  void (*stop_watches)(PollEvents *self);
54  void (*update_watches)(PollEvents *self, GIOCondition cond);
55  void (*suspend_watches)(PollEvents *self);
56  gint (*get_fd)(PollEvents *self);
57  void (*free_fn)(PollEvents *self);
58 };
59 
60 static inline gint
61 poll_events_get_fd(PollEvents *self)
62 {
63  if (self->get_fd)
64  return self->get_fd(self);
65  return -1;
66 }
67 
68 static inline gboolean
69 poll_events_system_polled(PollEvents *self)
70 {
71  return self->type == FM_SYSTEM_POLL;
72 }
73 
74 static inline gboolean
75 poll_events_system_notified(PollEvents *self)
76 {
77  return self->type == FM_INOTIFY;
78 }
79 
80 static inline void
81 poll_events_start_watches(PollEvents *self)
82 {
83  if (self->start_watches)
84  self->start_watches(self);
85 }
86 
87 static inline void
88 poll_events_stop_watches(PollEvents *self)
89 {
90  if (self->stop_watches)
91  self->stop_watches(self);
92 }
93 
94 static inline gboolean
95 poll_events_check_watches(PollEvents *self)
96 {
97  if (self->check_watches)
98  return self->check_watches(self, self->checker_data);
99  return TRUE;
100 }
101 
102 static inline void
103 poll_events_update_watches(PollEvents *self, GIOCondition cond)
104 {
105  self->update_watches(self, cond);
106 }
107 
108 static inline void
109 poll_events_suspend_watches(PollEvents *self)
110 {
111  if (self->suspend_watches)
112  return self->suspend_watches(self);
113  poll_events_stop_watches(self);
114 }
115 
116 void poll_events_invoke_callback(PollEvents *self);
117 void poll_events_set_callback(PollEvents *self, PollCallback callback, gpointer user_data);
118 void poll_events_set_checker(PollEvents *self, PollChecker check_watches, gpointer user_data);
119 void poll_events_init(PollEvents *self);
120 void poll_events_free(PollEvents *self);
121 
122 #endif
void poll_events_free(PollEvents *self)
Definition: poll-events.c:52
void poll_events_set_checker(PollEvents *self, PollChecker check_watches, gpointer user_data)
Definition: poll-events.c:40
void(* PollCallback)(gpointer user_data)
Definition: poll-events.h:40
void poll_events_set_callback(PollEvents *self, PollCallback callback, gpointer user_data)
Definition: poll-events.c:33
void poll_events_init(PollEvents *self)
Definition: poll-events.c:47
FollowMethod
Definition: poll-events.h:30
@ FM_UNKNOWN
Definition: poll-events.h:36
@ FM_INOTIFY
Definition: poll-events.h:34
@ FM_SYSTEM_POLL
Definition: poll-events.h:33
@ FM_AUTO
Definition: poll-events.h:35
@ FM_POLL
Definition: poll-events.h:32
@ FM_LEGACY
Definition: poll-events.h:31
void poll_events_invoke_callback(PollEvents *self)
Definition: poll-events.c:27
gboolean(* PollChecker)(PollEvents *self, gpointer user_data)
Definition: poll-events.h:41
#define self
Definition: rcptid.c:38
Definition: poll-events.h:45
void(* stop_watches)(PollEvents *self)
Definition: poll-events.h:52
FollowMethod type
Definition: poll-events.h:46
void(* suspend_watches)(PollEvents *self)
Definition: poll-events.h:55
void(* update_watches)(PollEvents *self, GIOCondition cond)
Definition: poll-events.h:54
gint(* get_fd)(PollEvents *self)
Definition: poll-events.h:56
void(* free_fn)(PollEvents *self)
Definition: poll-events.h:57
PollChecker check_watches
Definition: poll-events.h:53
PollCallback callback
Definition: poll-events.h:47
void(* start_watches)(PollEvents *self)
Definition: poll-events.h:51
gpointer callback_data
Definition: poll-events.h:48
gpointer checker_data
Definition: poll-events.h:49