source: lib/events_glib.c @ 93d4d8f

Last change on this file since 93d4d8f was c479242, checked in by dequis <dx@…>, at 2020-04-05T13:53:06Z

events_glib: fix some g_main_loop deprecation warnings

  • Property mode set to 100644
File size: 4.0 KB
RevLine 
[5ebff60]1/********************************************************************\
[ecf8fa8]2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2006 Wilmer van der Gaast and others                *
5  \********************************************************************/
6
7/*
8 * Event handling (using GLib)
9 */
10
11/*
12  This program is free software; you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) any later version.
16
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  GNU General Public License for more details.
21
22  You should have received a copy of the GNU General Public License with
23  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
[6f10697]24  if not, write to the Free Software Foundation, Inc., 51 Franklin St.,
25  Fifth Floor, Boston, MA  02110-1301  USA
[ecf8fa8]26*/
27
28#define BITLBEE_CORE
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <sys/types.h>
33#include <sys/socket.h>
34#include <netdb.h>
35#include <netinet/in.h>
36#include <arpa/inet.h>
37#include <unistd.h>
38#include <fcntl.h>
39#include <errno.h>
40#include "proxy.h"
41
42typedef struct _GaimIOClosure {
[ba9edaa]43        b_event_handler function;
[ecf8fa8]44        gpointer data;
[c5c18c1]45        guint flags;
[ecf8fa8]46} GaimIOClosure;
47
[851a8c2]48static GMainLoop *loop = NULL;
[ba9edaa]49
50void b_main_init()
51{
[5ebff60]52        if (loop == NULL) {
[c479242]53                loop = g_main_loop_new(NULL, FALSE);
[5ebff60]54        }
[ba9edaa]55}
56
57void b_main_run()
58{
[c479242]59        g_main_loop_run(loop);
[ba9edaa]60}
61
62void b_main_quit()
63{
[c479242]64        g_main_loop_quit(loop);
[ba9edaa]65}
66
[b15cbc4]67void b_main_iteration()
68{
[c479242]69        g_main_context_iteration(NULL, FALSE);
[b15cbc4]70        event_debug("b_main_iteration()\n");
71}
72
[ecf8fa8]73static gboolean gaim_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data)
74{
75        GaimIOClosure *closure = data;
[ba9edaa]76        b_input_condition gaim_cond = 0;
[fc2ee0f]77        gboolean st;
[5ebff60]78
79        if (condition & G_IO_NVAL) {
[9ff0c25]80                return FALSE;
[5ebff60]81        }
[ecf8fa8]82
[5ebff60]83        if (condition & GAIM_READ_COND) {
[e046390]84                gaim_cond |= B_EV_IO_READ;
[5ebff60]85        }
86        if (condition & GAIM_WRITE_COND) {
[e046390]87                gaim_cond |= B_EV_IO_WRITE;
[5ebff60]88        }
89
[cc8cf75]90        event_debug("gaim_io_invoke( %d, %d, %p )\n", g_io_channel_unix_get_fd(source), condition, data);
[ecf8fa8]91
[fc2ee0f]92        st = closure->function(closure->data, g_io_channel_unix_get_fd(source), gaim_cond);
[5ebff60]93
94        if (!st) {
95                event_debug("Returned FALSE, cancelling.\n");
96        }
97
98        if (closure->flags & B_EV_FLAG_FORCE_ONCE) {
[c5c18c1]99                return FALSE;
[5ebff60]100        } else if (closure->flags & B_EV_FLAG_FORCE_REPEAT) {
[c5c18c1]101                return TRUE;
[5ebff60]102        } else {
[c5c18c1]103                return st;
[5ebff60]104        }
[ecf8fa8]105}
106
107static void gaim_io_destroy(gpointer data)
108{
[cc8cf75]109        event_debug("gaim_io_destroy( 0%p )\n", data);
[ecf8fa8]110        g_free(data);
111}
112
[ba9edaa]113gint b_input_add(gint source, b_input_condition condition, b_event_handler function, gpointer data)
[ecf8fa8]114{
115        GaimIOClosure *closure = g_new0(GaimIOClosure, 1);
116        GIOChannel *channel;
117        GIOCondition cond = 0;
[f394500]118        int st;
[5ebff60]119
[ecf8fa8]120        closure->function = function;
121        closure->data = data;
[c5c18c1]122        closure->flags = condition;
[5ebff60]123
124        if (condition & B_EV_IO_READ) {
[ecf8fa8]125                cond |= GAIM_READ_COND;
[5ebff60]126        }
127        if (condition & B_EV_IO_WRITE) {
[ecf8fa8]128                cond |= GAIM_WRITE_COND;
[5ebff60]129        }
130
[ecf8fa8]131        channel = g_io_channel_unix_new(source);
[f394500]132        st = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond,
133                                 gaim_io_invoke, closure, gaim_io_destroy);
[5ebff60]134
[cc8cf75]135        event_debug("b_input_add( %d, %d, %p, %p ) = %d (%p)\n", source, condition, function, data, st, closure);
[5ebff60]136
[ecf8fa8]137        g_io_channel_unref(channel);
[f394500]138        return st;
[ecf8fa8]139}
140
[ba9edaa]141gint b_timeout_add(gint timeout, b_event_handler func, gpointer data)
142{
[04026d4]143        /* GSourceFunc and the BitlBee event handler function aren't
144           really the same, but they're "compatible". ;-) It will do
145           for now, BitlBee only looks at the "data" argument. */
146        gint st = g_timeout_add(timeout, (GSourceFunc) func, data);
[5ebff60]147
[cc8cf75]148        event_debug("b_timeout_add( %d, %p, %p ) = %d\n", timeout, func, data, st);
[5ebff60]149
[fc2ee0f]150        return st;
[ba9edaa]151}
152
153void b_event_remove(gint tag)
[ecf8fa8]154{
[5ebff60]155        event_debug("b_event_remove( %d )\n", tag);
156
157        if (tag > 0) {
[ecf8fa8]158                g_source_remove(tag);
[5ebff60]159        }
[ecf8fa8]160}
[25b5a4a]161
[5ebff60]162void closesocket(int fd)
[25b5a4a]163{
[5ebff60]164        close(fd);
[25b5a4a]165}
Note: See TracBrowser for help on using the repository browser.