virusb.h 3.7 KB
Newer Older
1
/*
2 3
 * virusb.h: helper APIs for managing host USB devices
 *
4 5 6 7 8 9 10 11 12 13 14 15 16
 * Copyright (C) 2009 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
17
 * License along with this library.  If not, see
O
Osier Yang 已提交
18
 * <http://www.gnu.org/licenses/>.
19 20
 */

21
#pragma once
22

23 24 25
#include "internal.h"
#include "virobject.h"
#include "virautoclean.h"
26

27
#define USB_DEVFS "/dev/bus/usb/"
28

29 30 31 32
typedef struct _virUSBDevice virUSBDevice;
typedef virUSBDevice *virUSBDevicePtr;
typedef struct _virUSBDeviceList virUSBDeviceList;
typedef virUSBDeviceList *virUSBDeviceListPtr;
33

34 35 36
virUSBDevicePtr virUSBDeviceNew(unsigned int bus,
                                unsigned int devno,
                                const char *vroot);
37

38 39
int virUSBDeviceFindByBus(unsigned int bus,
                          unsigned int devno,
40
                          const char *vroot,
41
                          bool mandatory,
42 43 44 45 46 47 48
                          virUSBDevicePtr *usb);

int virUSBDeviceFindByVendor(unsigned int vendor,
                             unsigned int product,
                             const char *vroot,
                             bool mandatory,
                             virUSBDeviceListPtr *devices);
49

50 51 52 53 54 55 56
int virUSBDeviceFind(unsigned int vendor,
                     unsigned int product,
                     unsigned int bus,
                     unsigned int devno,
                     const char *vroot,
                     bool mandatory,
                     virUSBDevicePtr *usb);
57

58
void virUSBDeviceFree(virUSBDevicePtr dev);
C
Chunyan Liu 已提交
59 60 61 62 63 64
int virUSBDeviceSetUsedBy(virUSBDevicePtr dev,
                          const char *drv_name,
                          const char *dom_name);
void virUSBDeviceGetUsedBy(virUSBDevicePtr dev,
                           const char **drv_name,
                           const char **dom_name);
65
const char *virUSBDeviceGetName(virUSBDevicePtr dev);
66
const char *virUSBDeviceGetPath(virUSBDevicePtr usb);
67

68 69
unsigned int virUSBDeviceGetBus(virUSBDevicePtr dev);
unsigned int virUSBDeviceGetDevno(virUSBDevicePtr dev);
70 71 72 73 74 75 76 77

/*
 * Callback that will be invoked once for each file
 * associated with / used for USB host device access.
 *
 * Should return 0 if successfully processed, or
 * -1 to indicate error and abort iteration
 */
78 79
typedef int (*virUSBDeviceFileActor)(virUSBDevicePtr dev,
                                     const char *path, void *opaque);
80

81 82 83
int virUSBDeviceFileIterate(virUSBDevicePtr dev,
                            virUSBDeviceFileActor actor,
                            void *opaque);
84

85 86
virUSBDeviceListPtr virUSBDeviceListNew(void);
int virUSBDeviceListAdd(virUSBDeviceListPtr list,
87
                        virUSBDevicePtr *dev);
88 89
virUSBDevicePtr virUSBDeviceListGet(virUSBDeviceListPtr list,
                                    int idx);
90
size_t virUSBDeviceListCount(virUSBDeviceListPtr list);
91 92 93 94 95 96
virUSBDevicePtr virUSBDeviceListSteal(virUSBDeviceListPtr list,
                                      virUSBDevicePtr dev);
void virUSBDeviceListDel(virUSBDeviceListPtr list,
                         virUSBDevicePtr dev);
virUSBDevicePtr virUSBDeviceListFind(virUSBDeviceListPtr list,
                                     virUSBDevicePtr dev);
97

98
VIR_DEFINE_AUTOPTR_FUNC(virUSBDevice, virUSBDeviceFree);