ekg2  GIT master
 All Struktury Danych Pliki Funkcje Zmienne Definicje typów Wyliczenia Wartości wyliczeń Definicje Grupay Strony
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 
111 watch_t *watch_find(plugin_t *plugin, int fd, watch_type_t type);
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