ekg2  GIT master
sources.h
Idź do dokumentacji tego pliku.
1 /*
2  * GSource-related APIs and functions
3  *
4  * (C) Copyright 2011 EKG2 team
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License Version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifndef __EKG_SOURCES_H
21 #define __EKG_SOURCES_H
22 
23 #include <glib.h>
24 
25 /* Common API */
26 typedef struct ekg_source *ekg_source_t;
27 
28 void ekg_source_remove(ekg_source_t s);
29 gboolean ekg_source_remove_by_handler(gpointer handler, const gchar *name);
30 gboolean ekg_source_remove_by_data(gpointer priv_data, const gchar *name);
31 gboolean ekg_source_remove_by_plugin(plugin_t *plugin, const gchar *name);
32 
33 /* Child watches */
34 typedef ekg_source_t ekg_child_t;
35 
36 ekg_child_t ekg_child_add(plugin_t *plugin, const gchar *name_format, GPid pid, GChildWatchFunc handler, gpointer data, GDestroyNotify destr, ...) G_GNUC_PRINTF(2, 7) G_GNUC_MALLOC;
37 
38 /* Timers */
39 typedef ekg_source_t ekg_timer_t;
40 
41 ekg_timer_t ekg_timer_add(plugin_t *plugin, const gchar *name_format, guint64 interval, GSourceFunc handler, gpointer data, GDestroyNotify destr, ...) G_GNUC_PRINTF(2, 7) G_GNUC_MALLOC;
42 
43 /* Macro-handlers are deprecated
44  * please use explicit prototypes with new timer API */
45 #define TIMER(x) gint x(gint type, gpointer data)
46 #define TIMER_SESSION(x) gint x(gint type, session_t *s)
47 
48 /* old timer API */
49 ekg_timer_t timer_add(plugin_t *plugin, const gchar *name, guint period, gboolean persist, gint (*function)(gint, gpointer), gpointer data);
50 ekg_timer_t timer_add_ms(plugin_t *plugin, const gchar *name, guint period, gboolean persist, gint (*function)(gint, gpointer), gpointer data);
51 ekg_timer_t timer_add_session(session_t *session, const gchar *name, guint period, gboolean persist, gint (*function)(gint, session_t *));
52 
53 ekg_timer_t timer_find_session(session_t *session, const gchar *name);
54 gint timer_remove(plugin_t *plugin, const gchar *name);
55 gint timer_remove_session(session_t *session, const gchar *name);
56 
57 /* Watches */
58 
59 extern list_t watches;
60 
61 typedef enum {
67 } watch_type_t;
68 
69 #define WATCHER(x) int x(int type, int fd, watch_type_t watch, void *data)
70 #define WATCHER_LINE(x) int x(int type, int fd, const char *watch, void *data)
71 #define WATCHER_SESSION(x) int x(int type, int fd, watch_type_t watch, session_t *s)
72 #define WATCHER_SESSION_LINE(x) int x(int type, int fd, const char *watch, session_t *s)
73 
75 /* typedef WATCHER_LINE(watcher_handler_line_func_t); */
77 
78 typedef struct watch {
79  int fd; /* obserwowany deskryptor */
80  watch_type_t type; /* co sprawdzamy */
81  plugin_t *plugin; /* wtyczka obsługujÂąca deskryptor */
82  void *handler; /* funkcja wywoływana jeÂśli sÂą dane itp. */
83  void *data; /* dane przekazywane powyĹźszym funkcjom. */
84  string_t buf; /* bufor na linię */
85  time_t timeout; /* timeout */
86  time_t started; /* kiedy zaczęto obserwować */
87 
88  int transfer_limit; /* XXX, requested by GiM to limit data transmitted to ircd server... currently only to send all data
89  done by serveral calls of watch_write() in one packet... by setting it to -1 and than changing it back to 0
90  if we really want to send packet in that function we ought to do by calling watch_handle_write()
91  [PLEASE NOTE, THAT YOU CANNOT DO watch_write().. cause it will check if there is somethink in write buffor...
92  and if it is, it won't call watch_handle_write()]
93  or it will be
94  executed in next ekg_loop() loop.
95  */
96  int is_session; /* if set, this watch belongs to session specified in data */
97 
98  guint id;
99  GIOChannel *f;
100 } watch_t;
101 
102 #ifndef EKG2_WIN32_NOFUNCTION
103 
104 #ifdef __GNU__
105 int watch_write(watch_t *w, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
106 #else
107 int watch_write(watch_t *w, const char *format, ...);
108 #endif
109 int watch_write_data(watch_t *w, const char *buf, int len);
110 
112 void watch_free(watch_t *w);
113 
114 typedef void *watch_handler_func_t;
115 
116 int watch_timeout_set(watch_t *w, time_t timeout);
117 
118 watch_t *watch_add(plugin_t *plugin, int fd, watch_type_t type, watcher_handler_func_t *handler, void *data);
119 #define watch_add_line(p, fd, type, handler, data) watch_add(p, fd, type, (watcher_handler_func_t *) (handler), data)
121 #define watch_add_session_line(s, fd, type, handler) watch_add_session(s, fd, type, (watcher_session_handler_func_t *) (handler))
122 
123 int watch_remove(plugin_t *plugin, int fd, watch_type_t type);
124 
125 #endif
126 
127 #endif
ekg_child_t G_GNUC_MALLOC
Definition: sources.h:36
Definition: sources.h:65
int is_session
Definition: sources.h:96
GString * string_t
Definition: dynstuff.h:147
struct watch watch_t
string_t buf
Definition: sources.h:84
int watch_write(watch_t *w, const char *format,...)
Definition: sources.c:1374
Definition: sessions.h:127
void * data
Definition: sources.h:83
int fd
Definition: sources.h:79
ekg_timer_t timer_add_session(session_t *session, const gchar *name, guint period, gboolean persist, gint(*function)(gint, session_t *))
Definition: sources.c:369
gboolean ekg_source_remove_by_data(gpointer priv_data, const gchar *name)
Definition: sources.c:194
GIOChannel * f
Definition: sources.h:99
Definition: ekg_hash_benchmark.c:47
GPid pid
Definition: sources.c:57
guint64 interval
Definition: sources.c:63
Definition: sources.h:62
watch_type_t type
Definition: sources.h:80
plugin_t * plugin
Definition: sources.h:81
ekg_timer_t timer_add_ms(plugin_t *plugin, const gchar *name, guint period, gboolean persist, gint(*function)(gint, gpointer), gpointer data)
Definition: sources.c:336
ekg_timer_t timer_find_session(session_t *session, const gchar *name)
Definition: sources.c:463
Definition: sources.c:39
void watch_free(watch_t *w)
Definition: sources.c:1482
time_t timeout
Definition: sources.h:85
int watcher_session_handler_func_t(int type, int fd, watch_type_t watch, session_t *s)
Definition: sources.h:76
Definition: sources.h:64
Definition: plugins.h:76
Definition: rivchat.h:42
#define WATCHER_SESSION(x)
Definition: sources.h:71
gint timer_remove(plugin_t *plugin, const gchar *name)
Definition: sources.c:450
watch_t * watch_find(plugin_t *plugin, int fd, watch_type_t type)
Definition: sources.c:1187
struct ekg_source * ekg_source_t
Definition: sources.h:26
int watch_timeout_set(watch_t *w, time_t timeout)
Definition: plugins.c:787
#define WATCHER(x)
Definition: sources.h:69
ekg_timer_t ekg_timer_add(plugin_t *plugin, const gchar *name_format, guint64 interval, GSourceFunc handler, gpointer data, GDestroyNotify destr,...) G_GNUC_PRINTF(2
watch_t * watch_add(plugin_t *plugin, int fd, watch_type_t type, watcher_handler_func_t *handler, void *data)
Definition: sources.c:1509
GDestroyNotify destr
Definition: sources.c:53
gboolean ekg_source_remove_by_plugin(plugin_t *plugin, const gchar *name)
Definition: sources.c:227
gboolean ekg_source_remove_by_handler(gpointer handler, const gchar *name)
Definition: sources.c:156
watch_type_t
Definition: sources.h:61
void ekg_source_remove(ekg_source_t s)
Definition: sources.c:113
gpointer priv_data
Definition: sources.c:52
gint timer_remove_session(session_t *session, const gchar *name)
Definition: sources.c:482
gboolean persist
Definition: sources.c:67
list_t watches
Definition: plugins.c:52
int watch_remove(plugin_t *plugin, int fd, watch_type_t type)
Definition: sources.c:1572
ekg_source_t ekg_child_t
Definition: sources.h:34
Definition: sources.h:66
void * watch_handler_func_t
Definition: sources.h:114
int watch_write_data(watch_t *w, const char *buf, int len)
Definition: sources.c:1351
watch_t * watch_add_session(session_t *session, int fd, watch_type_t type, watcher_session_handler_func_t *handler)
Definition: sources.c:1560
const char * name
Definition: remote.c:88
void * handler
Definition: sources.h:82
Definition: ekg_hash_benchmark.c:14
Definition: sources.h:78
Definition: sources.h:63
ekg_child_t ekg_child_add(plugin_t *plugin, const gchar *name_format, GPid pid, GChildWatchFunc handler, gpointer data, GDestroyNotify destr,...) G_GNUC_PRINTF(2
int watcher_handler_func_t(int type, int fd, watch_type_t watch, void *data)
Definition: sources.h:74
ekg_timer_t timer_add(plugin_t *plugin, const gchar *name, guint period, gboolean persist, gint(*function)(gint, gpointer), gpointer data)
Definition: sources.c:365
#define s
abort_handler handler
Definition: abort.c:24
guint id
Definition: sources.h:98
int transfer_limit
Definition: sources.h:88
time_t started
Definition: sources.h:86