Merge branch 'ref-counting-context'
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 25 Jun 2014 00:32:42 +0000 (10:32 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 25 Jun 2014 00:32:42 +0000 (10:32 +1000)
Conflicts:
src/udev-seat.c
test/log.c

1  2 
src/libinput-private.h
src/libinput.c
src/libinput.h
src/udev-seat.c
test/keyboard.c
test/litest.c
test/log.c
test/udev.c
tools/event-debug.c
tools/event-gui.c

@@@ -56,10 -56,8 +56,11 @@@ struct libinput 
  
        const struct libinput_interface *interface;
        const struct libinput_interface_backend *interface_backend;
 +
 +      libinput_log_handler log_handler;
 +      enum libinput_log_priority log_priority;
        void *user_data;
+       int refcount;
  };
  
  typedef void (*libinput_seat_destroy_func) (struct libinput_seat *seat);
diff --cc src/libinput.c
Simple merge
diff --cc src/libinput.h
Simple merge
diff --cc src/udev-seat.c
@@@ -351,58 -349,19 +351,59 @@@ libinput_udev_create_context(const stru
  
        if (libinput_init(&input->base, interface,
                          &interface_backend, user_data) != 0) {
++              libinput_unref(&input->base);
                free(input);
                return NULL;
        }
  
        input->udev = udev_ref(udev);
 +
 +      return &input->base;
 +}
 +
 +LIBINPUT_EXPORT int
 +libinput_udev_assign_seat(struct libinput *libinput,
 +                        const char *seat_id)
 +{
 +      struct udev_input *input = (struct udev_input*)libinput;
 +
 +      if (!seat_id)
 +              return -1;
 +      if (input->seat_id != NULL)
 +              return -1;
 +
 +      if (libinput->interface_backend != &interface_backend) {
 +              log_bug_client(libinput, "Mismatching backends.\n");
 +              return -1;
 +      }
 +
        input->seat_id = strdup(seat_id);
  
 -      if (udev_input_enable(&input->base) < 0) {
 -              udev_unref(udev);
 -              libinput_unref(&input->base);
 -              free(input);
 +      if (udev_input_enable(&input->base) < 0)
 +              return -1;
 +
 +      return 0;
 +}
 +
 +LIBINPUT_EXPORT struct libinput *
 +libinput_udev_create_for_seat(const struct libinput_interface *interface,
 +                            void *user_data,
 +                            struct udev *udev,
 +                            const char *seat_id)
 +{
 +      struct libinput *libinput;
 +
 +      if (!interface || !udev || !seat_id)
                return NULL;
-               libinput_destroy(libinput);
 +
 +      libinput = libinput_udev_create_context(interface, user_data, udev);
 +      if (!libinput)
 +              return NULL;
 +
 +      if (libinput_udev_assign_seat(libinput, seat_id) != 0) {
++              libinput_unref(libinput);
 +              libinput = NULL;
        }
  
 -      return &input->base;
 +      return libinput;
  }
diff --cc test/keyboard.c
Simple merge
diff --cc test/litest.c
Simple merge
diff --cc test/log.c
@@@ -65,14 -64,30 +65,14 @@@ simple_log_handler(struct libinput *lib
  START_TEST(log_default_priority)
  {
        enum libinput_log_priority pri;
 -
 -      pri = libinput_log_get_priority();
 -
 -      ck_assert_int_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR);
 -}
 -END_TEST
 -
 -START_TEST(log_handler_invoked)
 -{
        struct libinput *li;
 -      enum libinput_log_priority pri = libinput_log_get_priority();
 -
 -      libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
 -      libinput_log_set_handler(simple_log_handler, NULL);
 -      log_handler_userdata = NULL;
  
        li = libinput_path_create_context(&simple_interface, NULL);
 -      libinput_path_add_device(li, "/tmp");
 +      pri = libinput_log_get_priority(li);
  
 -      ck_assert_int_gt(log_handler_called, 0);
 -      log_handler_called = 0;
 +      ck_assert_int_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR);
  
-       libinput_destroy(li);
+       libinput_unref(li);
 -      libinput_log_set_priority(pri);
  }
  END_TEST
  
@@@ -91,9 -127,8 +91,9 @@@ START_TEST(log_handler_invoked
        ck_assert_int_gt(log_handler_called, 0);
        log_handler_called = 0;
  
-       libinput_destroy(li);
+       libinput_unref(li);
 -      libinput_log_set_priority(pri);
 +
 +      log_handler_context = NULL;
  }
  END_TEST
  
@@@ -109,8 -146,10 +109,8 @@@ START_TEST(log_handler_NULL
  
        ck_assert_int_eq(log_handler_called, 0);
        log_handler_called = 0;
 -      libinput_log_set_handler(simple_log_handler, NULL);
  
-       libinput_destroy(li);
+       libinput_unref(li);
 -      libinput_log_set_priority(pri);
  }
  END_TEST
  
@@@ -133,8 -173,8 +133,8 @@@ START_TEST(log_priority
  
        log_handler_called = 0;
  
-       libinput_destroy(li);
+       libinput_unref(li);
 -      libinput_log_set_priority(pri);
 +      log_handler_context = NULL;
  }
  END_TEST
  
diff --cc test/udev.c
@@@ -52,24 -52,26 +52,25 @@@ START_TEST(udev_create_NULL
  {
        struct libinput *li;
        const struct libinput_interface interface;
 -      struct udev *udev = (struct udev*)0xdeadbeef;
 -      const char *seat = (const char*)0xdeaddead;
 +      struct udev *udev;
  
 -      li = libinput_udev_create_for_seat(NULL, NULL, NULL, NULL);
 -      ck_assert(li == NULL);
 +      udev = udev_new();
  
 -      li = libinput_udev_create_for_seat(&interface, NULL, NULL, NULL);
 -      ck_assert(li == NULL);
 -      li = libinput_udev_create_for_seat(NULL, NULL, udev, NULL);
 -      ck_assert(li == NULL);
 -      li = libinput_udev_create_for_seat(NULL, NULL, NULL, seat);
 +      li = libinput_udev_create_context(NULL, NULL, NULL);
        ck_assert(li == NULL);
  
 -      li = libinput_udev_create_for_seat(&interface, NULL, udev, NULL);
 -      ck_assert(li == NULL);
 -      li = libinput_udev_create_for_seat(NULL, NULL, udev, seat);
 +      li = libinput_udev_create_context(&interface, NULL, NULL);
        ck_assert(li == NULL);
  
 -      li = libinput_udev_create_for_seat(&interface, NULL, NULL, seat);
 +      li = libinput_udev_create_context(NULL, NULL, udev);
        ck_assert(li == NULL);
-       libinput_destroy(li);
 +
 +      li = libinput_udev_create_context(&interface, NULL, udev);
 +      ck_assert(li != NULL);
 +      ck_assert_int_eq(libinput_udev_assign_seat(li, NULL), -1);
++
++      libinput_unref(li);
 +      udev_unref(udev);
  }
  END_TEST
  
@@@ -155,17 -146,6 +155,17 @@@ open_udev(struct libinput **li
                return 1;
        }
  
-               libinput_destroy(*li);
 +      if (verbose) {
 +              libinput_log_set_handler(*li, log_handler);
 +              libinput_log_set_priority(*li, LIBINPUT_LOG_PRIORITY_DEBUG);
 +      }
 +
 +      if (libinput_udev_assign_seat(*li, seat)) {
 +              fprintf(stderr, "Failed to set seat\n");
++              libinput_unref(*li);
 +              return 1;
 +      }
 +
        return 0;
  }
  
Simple merge