summaryrefslogtreecommitdiff
path: root/test/uat-users.c
blob: 0f00d45d9fe48e3598bbfbb03b30548a1b62b4a9 (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
/*
 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <glib.h>
#include <gio/gio.h>

#include <user-awareness.h>

#include "uat-menu.h"
#include "uat-common.h"

extern ua_monitor_h g_ua_mon_h; /**< Monitor handle */
extern ua_device_h g_device_h; /**< Device handle */
ua_user_h g_user_h = NULL; /**< User handle */
extern ua_service_h g_service_h; /**< Service handle */

char g_user_account_str[MENU_DATA_SIZE + 1] = { "default@default.com" };
char g_user_name_str[MENU_DATA_SIZE + 1] = { "default" };

extern char g_device_type[MENU_DATA_SIZE + 1]; /**< Sensor type of the selected device */
extern char g_device_type_str[MENU_DATA_SIZE + 1]; /**< Readable sensor type string */
extern char g_device_id_str[MENU_DATA_SIZE + 1]; /**< Mobile ID of the selected device */
extern char g_mac_addr_str[MENU_DATA_SIZE + 1]; /**< MAC of the selected device */

extern char g_service_str[MENU_DATA_SIZE + 1]; /**< Service name */

GSList *user_list = NULL; /**< User List */
int idx_user = 0; /**< Found device sequence number */

extern char g_selected_device_idx[MENU_DATA_SIZE + 1]; /**< Selected device id */
extern GSList *g_device_list; /**< Device List */
extern int g_device_count; /**< Seletected service name */

char g_selected_user_idx[MENU_DATA_SIZE + 1] = {0,}; /** Selected user id */

static void update_user_info(void)
{
	int ret = UA_ERROR_NONE;
	char *account = NULL;
	char *name = NULL;

	if (0 == idx_user) {
		if (g_user_h) {
			ua_user_destroy(g_user_h);
			g_user_h = NULL;
		}
		ua_user_get_default_user(&g_user_h);
	}

	ret  = ua_user_get_account(g_user_h, &account);
	if (UA_ERROR_NONE == ret) {
		memset(g_user_account_str, 0, MENU_DATA_SIZE + 1);
		memcpy(g_user_account_str, account, MENU_DATA_SIZE);
		g_free(account);
	}
	ret  = ua_user_get_name(g_user_h, &name);
	if (UA_ERROR_NONE == ret) {
		memset(g_user_name_str, 0, MENU_DATA_SIZE + 1);
		memcpy(g_user_name_str, name, MENU_DATA_SIZE);
		g_free(name);
	}
}

static void  ___free_users(gpointer data)
{
	ua_user_h handle = data;
	ua_user_destroy(handle);
	handle = NULL;
}

void uat_clear_user_list(void)
{
	g_slist_free_full(user_list, ___free_users);
	user_list = NULL;
	idx_user = 0;
}

static bool __foreach_registered_user_cb(
	ua_user_h user_handle, void *user_data)
{
	int ret = UA_ERROR_NONE;
	ua_user_h handle = NULL;
	char *account = NULL;
	char *name = NULL;
	unsigned long long timestamp = 0;

	if (!user_handle) {
		msgr("user_handle is NULL");
		return true;
	}

	ret = ua_user_clone(&handle, user_handle);
	if (UA_ERROR_NONE != ret) {
		msgr("ua_user_clone() result: [0x%X] [%s]",
			ret, uat_get_error_str(ret));
	}

	user_list = g_slist_append(user_list, handle);
	idx_user++;

	ret = ua_user_get_account(handle, &account);
	if (UA_ERROR_NONE == ret) {
		msglr("[%d]", idx_user);
		msglr("User account info %s", account);
		g_free(account);
	}

	ret = ua_user_get_name(handle, &name);
	if (UA_ERROR_NONE == ret) {
		msglr("User Name : %s", name);
		g_free(name);
	}

	ret = ua_user_get_last_presence(handle, &timestamp);
	if (UA_ERROR_NONE == ret)
		msglr("last present at %llu", timestamp);

	return true;
}

static void __device_added_cb(int result,
		ua_device_h handle, void *user_data)
{
	int ret;
	ua_mac_type_e mac_type = UA_MAC_TYPE_INVALID;
	ua_os_type_e ostype = UA_OS_TYPE_NOT_DEFINE;
	char *device_id = NULL;
	char *mac = NULL;
	char *ipv4 = NULL;

	if (UA_ERROR_NONE != result) {
		msgr("__device_added_cb() result: [0x%X] [%s]",
			result, uat_get_error_str(result));
		return;
	}

	if (NULL == handle) {
		msgr("Device handle is NULL");
		return;
	}

	msgb("__device_added_cb() result: [0x%X] [%s]",
			result, uat_get_error_str(result));

	ret = ua_device_get_mac_type(handle, &mac_type);
	if (UA_ERROR_NONE == ret)
		msgb("Device MAC Type : %s", uat_get_mac_type_str(mac_type));

	ret = ua_device_get_os_info(handle, &ostype);
	if (UA_ERROR_NONE == ret)
		msgb("Device OS Type : %s",
				ostype == 1 ? "Tizen" :
				ostype == 2 ? "Android" :
				ostype == 3 ? "iOS" : "N/A");

	ret = ua_device_get_device_id(handle, &device_id);
	if (UA_ERROR_NONE == ret) {
		msgb("Device ID : %s", device_id);
		g_free(device_id);
	}

	ret = ua_device_get_mac_address(handle, &mac);
	if (UA_ERROR_NONE == ret) {
		msgb("Device MAC : %s", mac);
		g_free(mac);
	}

	ret = ua_device_get_wifi_ipv4_address(handle, &ipv4);
	if (UA_ERROR_NONE == ret) {
		msgb("Device IPv4 Addr : %s", ipv4);
		g_free(ipv4);
	}

}

static bool _user_foreach_added_device_cb(ua_device_h device_handle,
	void *user_data)
{
	int ret, ret_temp;
	ua_device_h handle = NULL;

	ua_mac_type_e mac_type = UA_MAC_TYPE_INVALID;
	ua_os_type_e ostype = UA_OS_TYPE_NOT_DEFINE;

	char *device_id = NULL;
	char *mac = NULL;
	char *wifi_bssid = NULL;
	char *ipv4 = NULL;
	bool required = false;
	unsigned long long timestamp = 0;
	bool discriminant = false;
	char service_id = 0;
	char device_icon = 0;
	char purpose = 0;
	char *duid = NULL;

	if (!device_handle) {
		msgr("device_handle is NULL");
		return true;
	}

	ret = ua_device_clone(&handle, device_handle);
	if (UA_ERROR_NONE != ret) {
		msgr(" - ua_device_clone() ret: [0x%X] [%s]",
			ret, uat_get_error_str(ret));
		return true;
	}

	msgc("\n[%d]", ++g_device_count);

	ret_temp = ua_device_get_mac_type(handle, &mac_type);
	if (UA_ERROR_NONE == ret_temp)
		msgc("Device MAC Type : %s", uat_get_mac_type_str(mac_type));

	ret_temp = ua_device_get_os_info(handle, &ostype);
	if (UA_ERROR_NONE == ret_temp) {
		msgc("Device OS Type : %s",
			ostype == 1 ? "Tizen" :
			ostype == 2 ? "Android" :
			ostype == 3 ? "iOS" : "N/A");
	}

	ret_temp = ua_device_get_device_id(handle, &device_id);
	if (UA_ERROR_NONE == ret_temp) {
		msgc("Device ID : %s", device_id);
		g_free(device_id);
	}

	ret_temp = ua_device_get_mac_address(handle, &mac);
	if (UA_ERROR_NONE == ret_temp) {
		msgc("Device MAC : %s", mac);
		g_free(mac);
	}

	ret_temp = ua_device_get_wifi_bssid(handle, &wifi_bssid);
	if (UA_ERROR_NONE == ret_temp) {
		msgc("Device BSSID : %s", wifi_bssid);
		g_free(wifi_bssid);
	}

	ret_temp = ua_device_get_wifi_ipv4_address(handle, &ipv4);
	if (UA_ERROR_NONE == ret_temp) {
		msgc("Device IPv4 Addr : %s", ipv4);
		g_free(ipv4);
	}

	ret_temp = ua_device_get_discriminant(handle, &discriminant);
	if (UA_ERROR_NONE == ret_temp)
		msgc("Discriminant : %s", discriminant ? "Enabled" : "Disabled");

	ret_temp = ua_device_get_pairing_required(handle, &required);
	if (UA_ERROR_NONE == ret_temp)
		msgc("Pairing Required : %s", required ? "YES" : "NO");

	ret_temp = ua_device_get_last_presence(handle, &timestamp);
	if (UA_ERROR_NONE == ret_temp)
		msgc("Last present at : %llu", timestamp);

	ret_temp = ua_device_get_payload_service_id(handle, &service_id);
	if (UA_ERROR_NONE == ret_temp)
		msgc("payload service_id : %d[hex: 0x%X]", service_id, service_id);

	ret_temp = ua_device_get_payload_device_icon(handle, &device_icon);
	if (UA_ERROR_NONE == ret_temp)
		msgc("payload device_icon : %d[hex: 0x%X]", device_icon, device_icon);

	ret_temp = ua_device_get_payload_purpose(handle, &purpose);
	if (UA_ERROR_NONE == ret_temp)
		msgc("payload purpose : %d[hex: 0x%X]", purpose, purpose);

	ret_temp = ua_device_get_payload_duid(handle, &duid);
	if (UA_ERROR_NONE == ret_temp) {
		uat_print_duid(duid);
		g_free(duid);
	}

	g_device_list = g_slist_append(g_device_list, handle);

	return true;
}

int uat_select_user(MManager *mm, struct menu_data *menu)
{
	GSList *iter = user_list;

	int id = 0;
	int selected_id = 0;

	if (strlen(g_selected_user_idx))
		selected_id = (unsigned char)strtol(g_selected_user_idx, NULL, 10);

	if (selected_id <= 0) {
		msg("Please select user first");
		return RET_SUCCESS;
	}

	while (NULL != iter) {
		GSList *next = iter->next;
		ua_user_h *handle = iter->data;
		if (handle && ++id == selected_id) {
			g_user_h = handle; /* Make selected user as a current one */
			update_user_info(); /* Update user info. */
			msg("Select user done");
			return RET_SUCCESS;
		}
		iter = next;
	}

	return RET_SUCCESS;
}

static int run_ua_user_create(MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;

	msg("ua_user_create");

	if (g_user_h) {
		ua_user_destroy((g_user_h));
		g_user_h = NULL;
	}

	ret = ua_user_create(&g_user_h);

	msg(" - ua_user_create() ret: [0x%X] [%s]",
			ret, uat_get_error_str(ret));

	return RET_SUCCESS;
}

static int run_ua_user_destroy(MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;

	msg("ua_user_destroy");

	if (g_user_h) {
		ret = ua_user_destroy((g_user_h));
		g_user_h = NULL;
	}

	msg(" - ua_user_destroy() ret: [0x%X] [%s]",
			ret, uat_get_error_str(ret));

	return RET_SUCCESS;
}

static int run_ua_user_set_account(MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;

	msg("ua_user_set_account");

	check_if(NULL == g_user_h);

	ret = ua_user_set_account(g_user_h, g_user_account_str);

	msg(" - ua_user_set_account() ret: [0x%X] [%s]",
			ret, uat_get_error_str(ret));

	return RET_SUCCESS;
}

static int run_ua_user_set_name(MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;

	msg("ua_user_set_name");

	check_if(NULL == g_user_h);

	ret = ua_user_set_name(g_user_h, g_user_name_str);

	msg(" - ua_user_set_name() ret: [0x%X] [%s]",
			ret, uat_get_error_str(ret));

	return RET_SUCCESS;
}

static int run_ua_user_add(MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;

	msg("ua_user_add");

	check_if(NULL == g_user_h);

	ret = ua_user_add(g_user_h);

	msg(" - ua_user_add() ret: [0x%X] [%s]",
			ret, uat_get_error_str(ret));

	return RET_SUCCESS;
}

static int run_ua_user_remove(MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;

	msg("ua_user_remove");

	check_if(NULL == g_user_h);

	ret = ua_user_remove(g_user_h);

	msg(" - ua_user_remove() ret: [0x%X] [%s]",
			ret, uat_get_error_str(ret));

	return RET_SUCCESS;
}

static int run_ua_user_update(MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;

	msg("ua_user_update");

	check_if(NULL == g_user_h);

	ret = ua_user_update(g_user_h);

	msg(" - ua_user_update() ret: [0x%X] [%s]",
			ret, uat_get_error_str(ret));

	return RET_SUCCESS;
}

static int run_ua_user_get_default_user(MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;

	msg("ua_user_get_default_user");

	if (g_user_h) {
		ua_user_destroy(g_user_h);
		g_user_h = NULL;
	}

	ret = ua_user_get_default_user(&g_user_h);
	if (UA_ERROR_NONE == ret)
		update_user_info();

	msg(" - ua_get_default_user() ret: [0x%X] [%s]",
		ret, uat_get_error_str(ret));

	return RET_SUCCESS;
}

static int run_ua_user_get_by_account(MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;
	ua_user_h user_handle;

	msg("ua_user_get_by_account");

	ret = ua_user_get_by_account(g_user_account_str, &user_handle);

	msg(" - ua_user_get_by_account() ret: [0x%X] [%s]",
			ret, uat_get_error_str(ret));

	if (UA_ERROR_NONE == ret) {
		msgb("User Handle [%p]", user_handle);
		ua_user_destroy(g_user_h);
		g_user_h = user_handle;
		update_user_info();
	}
	return RET_SUCCESS;
}

static int run_ua_user_foreach(
	MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;
	msg("ua_user_foreach_added");

	uat_clear_user_list();

	ret = ua_user_foreach_added(__foreach_registered_user_cb, NULL);

	msg(" - ua_user_foreach_added() ret: [0x%X] [%s]",
				ret, uat_get_error_str(ret));

	return RET_SUCCESS;
}

static int run_ua_user_add_device(
	MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;

	msg("ua_user_add_device");

	check_if(NULL == g_device_h);

	ret = ua_user_add_device(g_user_h, g_device_h, __device_added_cb, NULL);

	msg(" - ua_user_add_device() ret: [0x%X] [%s]",
			ret, uat_get_error_str(ret));

	return RET_SUCCESS;
}

static int run_ua_user_remove_device(
	MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;

	msg("ua_user_remove_device");

	check_if(NULL == g_user_h);
	check_if(NULL == g_device_h);

	ret = ua_user_remove_device(g_user_h, g_device_h);

	msg(" - ua_user_remove_device() ret: [0x%X] [%s]",
			ret, uat_get_error_str(ret));

	return RET_SUCCESS;
}

static int run_ua_user_remove_device_by_device_id(
	MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;
	uat_mac_type_e idx = UAT_MAC_TYPE_MAX;

	msg("ua_user_remove_device_by_device_id");

	if (strlen(g_device_type))
		idx  = (unsigned char)strtol(g_device_type, NULL, 10);

	msgb("idx [%d] mac_type[%d]", idx, uat_convert_idx_to_device_type(idx));

	ret = ua_user_remove_device_by_device_id(g_device_id_str,
			uat_convert_idx_to_device_type(idx));

	msg(" - ua_user_remove_device_by_device_id() ret: [0x%X] [%s]",
			ret, uat_get_error_str(ret));

	return RET_SUCCESS;
}

static int run_ua_user_remove_device_by_mac_address(
	MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;
	uat_mac_type_e idx = UAT_MAC_TYPE_MAX;

	msg("ua_user_remove_device_by_mac_address");

	if (strlen(g_device_type))
		idx = (unsigned char)strtol(g_device_type, NULL, 10);

	msgb("idx [%d] mac_type[%d]", idx, uat_convert_idx_to_device_type(idx));

	ret = ua_user_remove_device_by_mac_address(g_mac_addr_str);

	msg(" - ua_user_remove_device_by_mac_address() ret: [0x%X] [%s]",
			ret, uat_get_error_str(ret));

	return RET_SUCCESS;
}

static int run_ua_user_foreach_added_devices(MManager *mm, struct menu_data *menu)
{
	int ret = UA_ERROR_NONE;
	ua_user_h user_handle;

	msg("ua_user_foreach_added_devices");

	ret = ua_user_get_by_account(g_user_account_str, &user_handle);
	if (UA_ERROR_NONE == ret) {
		msgb("User Handle [%p]", user_handle);
		ua_user_destroy(g_user_h);
		g_user_h = user_handle;
		update_user_info();
	} else {
		msg(" - ua_user_get_by_account() ret: [0x%X] [%s]",
				ret, uat_get_error_str(ret));
	}

	uat_clear_device_list();

	ret = ua_user_foreach_added_devices(g_user_h,
					_user_foreach_added_device_cb, NULL);

	msg(" - ua_user_foreach_added_devices() ret: [0x%X] [%s]",
			ret, uat_get_error_str(ret));

	return RET_SUCCESS;
}

static int run_select_device(MManager *mm, struct menu_data *menu)
{
	GSList *iter = g_device_list;

	int id = 0;
	int selected_id = 0;

	if (strlen(g_selected_device_idx))
		selected_id = (unsigned char)strtol(g_selected_device_idx, NULL, 10);

	if (selected_id <= 0) {
		msg("Please select device first");
		return RET_SUCCESS;
	}

	while (NULL != iter) {
		GSList *next = iter->next;
		ua_device_h *handle = iter->data;
		if (handle && ++id == selected_id) {
			g_device_h = handle; /* Make selected device as a current one */
			uat_update_device_info(); /* Update device info. */
			msg("[%d] device selected", selected_id);
			return RET_SUCCESS;
		}
		iter = next;
	}

	return RET_SUCCESS;
}

static struct menu_data menu_ua_user_account[] = {
	{ "1", "account",
		NULL, NULL, g_user_account_str },
	{ "2", "run", NULL,
		run_ua_user_set_account, NULL },
	{ NULL, NULL, },
};

static struct menu_data menu_ua_user_name[] = {
	{ "1", "name",
		NULL, NULL, g_user_name_str },
	{ "2", "run", NULL,
		run_ua_user_set_name, NULL },
	{ NULL, NULL, },
};

static struct menu_data menu_ua_user_get_handle_by_account[] = {
	{ "1", "account",
		NULL, NULL, g_user_account_str},
	{ "2", "run", NULL,
		run_ua_user_get_by_account, NULL },
	{ NULL, NULL, },
};

struct menu_data menu_sel_added_user[] = {
	{ "1", "User list", NULL,
		run_ua_user_foreach, g_selected_user_idx},
	{ "2", "Apply", NULL, uat_select_user, NULL },
	{ NULL, NULL, },
};

static struct menu_data menu_ua_rm_dev_by_device_id[] = {
	{ "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)",
		NULL, NULL, g_device_type },
	{ "2", "device_id",
		NULL, NULL, g_device_id_str },
	{ "3", "run", NULL,
		run_ua_user_remove_device_by_device_id, NULL },
	{ NULL, NULL, },
};

static struct menu_data menu_ua_rm_dev_by_addr[] = {
	{ "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)",
		NULL, NULL, g_device_type },
	{ "2", "MAC",
		NULL, NULL, g_mac_addr_str },
	{ "3", "run", NULL,
		run_ua_user_remove_device_by_mac_address, NULL },
	{ NULL, NULL, },
};

struct menu_data menu_ua_user_added_devlist[] = {
	{ "1", "Device list", NULL,
		run_ua_user_foreach_added_devices, g_selected_device_idx},
	{ "2", "Apply", NULL, run_select_device, NULL },
	{ NULL, NULL, },
};

struct menu_data menu_ua_users[] = {
	{ "1", "ua_user_create",
		NULL, run_ua_user_create, NULL },
	{ "2", "ua_user_destroy",
		NULL, run_ua_user_destroy, NULL },
	{ "3", "ua_user_set_account",
		menu_ua_user_account, NULL, g_user_account_str },
	{ "4", "ua_user_set_name",
		menu_ua_user_name, NULL, g_user_name_str },
	{ "5", "ua_user_add",
		NULL, run_ua_user_add, NULL },
	{ "6", "ua_user_remove",
		NULL, run_ua_user_remove, NULL},
	{ "7", "ua_user_update",
		NULL, run_ua_user_update, NULL},
	{ "8", "ua_user_get_default_user",
		NULL, run_ua_user_get_default_user, NULL },
	{ "9", "ua_user_get_handle_by_account",
		menu_ua_user_get_handle_by_account, NULL, NULL },
	{ "10", ANSI_COLOR_LIGHTMAGENTA "ua_user_foreach_added" ANSI_COLOR_NORMAL,
		menu_sel_added_user, NULL, NULL },
	{ "11", ANSI_COLOR_LIGHTGREEN "ua_user_add_device" ANSI_COLOR_NORMAL,
		NULL, run_ua_user_add_device, NULL },
	{ "12", ANSI_COLOR_LIGHTRED "ua_user_remove_device" ANSI_COLOR_NORMAL,
		NULL, run_ua_user_remove_device, NULL },
	{ "13", "ua_user_remove_device_by_device_id",
		menu_ua_rm_dev_by_device_id, NULL, NULL },
	{ "14", "ua_user_remove_device_by_mac_address",
		menu_ua_rm_dev_by_addr, NULL, NULL },
	{ "15", ANSI_COLOR_LIGHTMAGENTA "ua_user_foreach_added_devices" ANSI_COLOR_NORMAL,
		menu_ua_user_added_devlist, NULL, NULL },
	{ NULL, NULL, },
};

struct menu_data menu_sel_user[] = {
	{ "1", "User list", NULL, run_ua_user_foreach, g_selected_user_idx},
	{ "2", "Apply", NULL, uat_select_user , NULL },
	{ NULL, NULL, },
};