Sent from my iPad > On Jun 18, 2015, at 18:29, Christophe Fergeau <cfergeau@xxxxxxxxxx> wrote: > > Hey, > >> On Thu, Jun 18, 2015 at 03:46:16PM +0300, Kirill Moizik wrote: >> From: Kirill Moizik <kirillm@xxxxxxxxxx> >> >> Introduce UsbDk API definitions and binding code. >> >> Signed-off-by: Kirill Moizik <kirillm@xxxxxxxxxx> >> --- >> src/Makefile.am | 2 + >> src/usbdk_api.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> src/usbdk_api.h | 34 +++++++++++ >> 3 files changed, 209 insertions(+) >> create mode 100644 src/usbdk_api.c >> create mode 100644 src/usbdk_api.h >> >> diff --git a/src/Makefile.am b/src/Makefile.am >> index 25e2255..655357a 100644 >> --- a/src/Makefile.am >> +++ b/src/Makefile.am >> @@ -367,6 +367,8 @@ WIN_USB_FILES= \ >> win-usb-clerk.h \ >> win-usb-driver-install.h \ >> win-usb-driver-install.c \ >> + usbdk_api.h \ >> + usbdk_api.c \ >> $(NULL) >> >> if OS_WIN32 >> diff --git a/src/usbdk_api.c b/src/usbdk_api.c >> new file mode 100644 >> index 0000000..23a0534 >> --- /dev/null >> +++ b/src/usbdk_api.c > [...] >> +uint64_t usbdk_usbredir_field_to_usbdk(int value){ > > This should be static > >> + if (value >= 0) >> + return (int)value; > > and the (int) cast is unneeded. This looks good otherwise, I can do the > changes locally before pushing. Great! Please do. Thanks a lot for your help, Christophe! Dmitry. > > Christophe > >> + else if (value == -1) >> + return USB_DK_HIDE_RULE_MATCH_ALL; >> + >> + /* value is < -1 */ >> + g_return_val_if_reached(USB_DK_HIDE_RULE_MATCH_ALL); >> +} >> + >> +void usbdk_api_set_hide_rules(usbdk_api_wrapper *usbdk_api, HANDLE hider_handle, gchar *redirect_on_connect) >> +{ >> + struct usbredirfilter_rule *rules; >> + int r, count; >> + >> + r = usbredirfilter_string_to_rules(redirect_on_connect, ",", "|", &rules, &count); >> + if (r) { >> + g_warning("auto-connect rules parsing failed with error %d", r); >> + return; >> + } >> + >> + for (int i = 0; i < count; i++) { >> + USB_DK_HIDE_RULE rule; >> + rule.Hide = usbdk_usbredir_field_to_usbdk(rules[i].allow); >> + rule.Class = usbdk_usbredir_field_to_usbdk(rules[i].device_class); >> + rule.VID = usbdk_usbredir_field_to_usbdk(rules[i].vendor_id); >> + rule.PID = usbdk_usbredir_field_to_usbdk(rules[i].product_id); >> + rule.BCD = usbdk_usbredir_field_to_usbdk(rules[i].device_version_bcd); >> + if (usbdk_add_hide_rule(usbdk_api, hider_handle, &rule)) { >> + SPICE_DEBUG("UsbDk set hide rule API failed"); >> + } >> + } >> + >> + free(rules); >> +} >> + >> +HANDLE usbdk_create_hider_handle(usbdk_api_wrapper *usbdk_api){ >> + return usbdk_api->CreateHandle(); >> +} >> + >> +BOOL usbdk_add_hide_rule(usbdk_api_wrapper *usbdk_api, HANDLE hider_handle, PUSB_DK_HIDE_RULE rule) { >> + return usbdk_api->AddRule(hider_handle, rule); >> +} >> + >> +BOOL usbdk_clear_hide_rules(usbdk_api_wrapper *usbdk_api, HANDLE hider_handle) { >> + return usbdk_api->ClearRules(hider_handle); >> +} >> + >> +void usbdk_close_hider_handle(usbdk_api_wrapper *usbdk_api, HANDLE hider_handle) { >> + return usbdk_api->CloseHiderHandle(hider_handle); >> +} >> diff --git a/src/usbdk_api.h b/src/usbdk_api.h >> new file mode 100644 >> index 0000000..bc6098d >> --- /dev/null >> +++ b/src/usbdk_api.h >> @@ -0,0 +1,34 @@ >> +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ >> +/* >> + Copyright (C) 2014-2015 Red Hat, Inc. >> + >> + This library is free software; you can redistribute it and/or >> + modify it under the terms of the GNU Lesser General Public >> + License as published by the Free Software Foundation; either >> + version 2.1 of the License, or (at your option) any later version. >> + >> + This library is distributed in the hope that it will be useful, >> + but WITHOUT ANY WARRANTY; without even the implied warranty of >> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >> + Lesser General Public License for more details. >> + >> + You should have received a copy of the GNU Lesser General Public >> + License along with this library; if not, see <http://www.gnu.org/licenses/>. >> + >> + Authors: >> + Dmitry Fleytman <dmitry@xxxxxxxxxx> >> + Kirill Moizik <kirill@xxxxxxxxxx> >> +*/ >> +#ifndef USBDK_HEADER >> +#define USBDK_HEADER >> + >> +typedef struct tag_usbdk_api_wrapper usbdk_api_wrapper; >> + >> +BOOL usbdk_is_driver_installed(void); >> +HANDLE usbdk_create_hider_handle(usbdk_api_wrapper *usbdk_api); >> +BOOL usbdk_clear_hide_rules(usbdk_api_wrapper *usbdk_api, HANDLE hider_handle); >> +void usbdk_close_hider_handle(usbdk_api_wrapper *usbdk_api, HANDLE hider_handle); >> +int usbdk_api_load(usbdk_api_wrapper **usbdk_api); >> +void usbdk_api_unload(usbdk_api_wrapper *usbdk_api); >> +void usbdk_api_set_hide_rules(usbdk_api_wrapper *usbdk_api, HANDLE hider_handle, gchar *redirect_on_connect); >> +#endif >> -- >> 2.1.0 >> >> _______________________________________________ >> Spice-devel mailing list >> Spice-devel@xxxxxxxxxxxxxxxxxxxxx >> http://lists.freedesktop.org/mailman/listinfo/spice-devel _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel