diff --git a/src/shared/uhid.c b/src/shared/uhid.c
index 1eddc61..4f149fd 100644
--- a/src/shared/uhid.c
+++ b/src/shared/uhid.c
struct queue *input;
uint8_t type;
bool created;
+ unsigned int start_id;
bool started;
struct uhid_replay *replay;
};
return 0;
notify = new0(struct uhid_notify, 1);
- notify->id = uhid->notify_id++;
+ notify->id = ++uhid->notify_id ? uhid->notify_id : ++uhid->notify_id;
notify->event = event;
notify->func = func;
notify->user_data = user_data;
if (uhid->created)
return 0;
+ /* Register callback for UHID_START if not registered yet */
+ if (!uhid->start_id) {
+ uhid->start_id = bt_uhid_register(uhid, UHID_START, uhid_start,
+ uhid);
+ if (!uhid->start_id)
+ return -ENOMEM;
+ }
+
memset(&ev, 0, sizeof(ev));
ev.type = UHID_CREATE2;
strncpy((char *) ev.u.create2.name, name,
if (err)
return err;
- bt_uhid_register(uhid, UHID_START, uhid_start, uhid);
-
uhid->created = true;
uhid->started = false;
uhid->type = type;
diff --git a/unit/test-uhid.c b/unit/test-uhid.c
index b0592d3..573da31 100644
--- a/unit/test-uhid.c
+++ b/unit/test-uhid.c
err = bt_uhid_create(context->uhid, "", NULL, NULL, 0, 0, 0, 0,
BT_UHID_NONE, NULL, 0);
- if (err < 0)
+ if (err < 0) {
+ tester_debug("create failed: %s\n", strerror(-err));
tester_test_failed();
+ }
if (g_str_equal(context->data->test_name, "/uhid/command/destroy")) {
err = bt_uhid_destroy(context->uhid, true);