File: obex-glib.c

package info (click to toggle)
gpe-bluetooth 0.56-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 792 kB
  • ctags: 419
  • sloc: ansic: 3,348; sh: 1,090; xml: 105; makefile: 72
file content (71 lines) | stat: -rw-r--r-- 1,432 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Copyright (C) 2004 Philip Blundell <philb@gnu.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */

#include <glib.h>
#include <openobex/obex.h>

#include "obex-glib.h"

struct obex_channel
{
  GIOChannel *chan;
  int fd;
  int source;
};

static GList *channels;

static gboolean
io_callback (GIOChannel *source, GIOCondition cond, gpointer data)
{
  obex_t *obex = (obex_t *)data;

  OBEX_HandleInput (obex, 0);

  return TRUE;
}

void
obex_disconnect_input (obex_t *obex)
{
  int fd;
  GList *i;

  fd = OBEX_GetFD (obex);

  for (i = channels; i; i = i->next)
    {
      struct obex_channel *chan = i->data;

      chan = i->data;

      if (chan->fd == fd)
	{
	  channels = g_list_remove (channels, chan);
	  g_source_remove (chan->source);
	  g_io_channel_unref (chan->chan);
	  g_free (chan);
	  return;
	}
    }

  g_critical ("Couldn't find channel in list.\n");
}

void
obex_connect_input (obex_t *obex)
{
  struct obex_channel *chan;

  chan = g_new (struct obex_channel, 1);
  chan->fd = OBEX_GetFD (obex);
  chan->chan = g_io_channel_unix_new (chan->fd);
  chan->source = g_io_add_watch (chan->chan, G_IO_IN | G_IO_ERR | G_IO_HUP, io_callback, obex);
  channels = g_list_prepend (channels, chan);  
}