~ubuntu-branches/ubuntu/wily/bluez/wily

« back to all changes in this revision

Viewing changes to input/fakehid.c

ImportĀ upstreamĀ versionĀ 4.81

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *
3
3
 *  BlueZ - Bluetooth protocol stack for Linux
4
4
 *
5
 
 *  Copyright (C) 2004-2009  Marcel Holtmann <marcel@holtmann.org>
 
5
 *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
6
6
 *
7
7
 *
8
8
 *  This program is free software; you can redistribute it and/or modify
33
33
#include <sys/types.h>
34
34
 
35
35
#include <bluetooth/bluetooth.h>
36
 
#include <bluetooth/l2cap.h>
37
36
#include <bluetooth/hidp.h>
 
37
#include <bluetooth/sdp.h>
38
38
 
39
39
#include <glib.h>
40
40
#include <dbus/dbus.h>
41
41
 
42
 
#include "logging.h"
 
42
#include "../src/adapter.h"
 
43
#include "../src/device.h"
 
44
 
 
45
#include "log.h"
43
46
#include "device.h"
44
47
#include "fakehid.h"
45
48
#include "uinput.h"
268
271
}
269
272
 
270
273
static int ps3remote_setup_uinput(struct fake_input *fake,
271
 
                                  struct fake_hid *fake_hid)
 
274
                                                struct fake_hid *fake_hid)
272
275
{
273
276
        struct uinput_dev dev;
274
277
        int i;
344
347
                .disconnect     = fake_hid_common_disconnect,
345
348
                .event          = ps3remote_event,
346
349
                .setup_uinput   = ps3remote_setup_uinput,
 
350
                .devices        = NULL,
347
351
        },
348
352
 
349
353
        { },
366
370
        return NULL;
367
371
}
368
372
 
369
 
int fake_hid_connadd(struct fake_input *fake, GIOChannel *intr_io,
 
373
struct fake_input *fake_hid_connadd(struct fake_input *fake,
 
374
                                                GIOChannel *intr_io,
370
375
                                                struct fake_hid *fake_hid)
371
376
{
372
 
        if (fake_hid->setup_uinput(fake, fake_hid)) {
373
 
                error("Error setting up uinput");
374
 
                return ENOMEM;
 
377
        GList *l;
 
378
        struct fake_input *old = NULL;
 
379
 
 
380
        /* Look for an already setup device */
 
381
        for (l = fake_hid->devices; l != NULL; l = l->next) {
 
382
                old = l->data;
 
383
                if (old->idev == fake->idev) {
 
384
                        g_free(fake);
 
385
                        fake = old;
 
386
                        fake_hid->connect(fake, NULL);
 
387
                        break;
 
388
                }
 
389
                old = NULL;
 
390
        }
 
391
 
 
392
        /* New device? Add it to the list of known devices,
 
393
         * and create the uinput necessary */
 
394
        if (old == NULL) {
 
395
                if (fake_hid->setup_uinput(fake, fake_hid)) {
 
396
                        error("Error setting up uinput");
 
397
                        g_free(fake);
 
398
                        return NULL;
 
399
                }
 
400
                fake_hid->devices = g_list_append(fake_hid->devices, fake);
375
401
        }
376
402
 
377
403
        fake->io = g_io_channel_ref(intr_io);
379
405
        g_io_add_watch(fake->io, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
380
406
                                        (GIOFunc) fake_hid->event, fake);
381
407
 
382
 
        return 0;
 
408
        return fake;
383
409
}