Data processing method of USB device, electronic device and readable medium
By detecting the data transmission status of the target client through the proxy, and switching the USB device when the switchable state is available, the problem of cumbersome device switching between clients is solved, and convenient and efficient device switching and data transmission are achieved.
Patent Information
- Application Number
- CN202511590942.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-31
- Publication Date
- 2026-03-03
AI Technical Summary
In existing technologies, it is difficult for a client to efficiently switch to a USB device that another client is using, resulting in cumbersome operation and affecting data transmission on the target client.
The agent detects the data transmission status of the target client, establishes a transmission connection with the first client in a switchable state, and forwards the USB data of the target USB device to achieve device switching.
This reduces the impact of device switching on the target client, ensures the switching effect, and improves operational convenience and data transmission efficiency.
Smart Images

Figure CN121597618A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a data processing method for a USB device, an electronic device, and a readable medium. Background Technology
[0002] Universal Serial Bus (USB) devices are widely used external devices that can connect to electronic devices and provide USB data to clients. For example, a USB camera can provide image data, and a USB keyboard can provide keyboard data.
[0003] In practical use, there may be situations where one client needs to use data from a USB device being used by another client. Therefore, how to achieve device switching becomes a technical problem that urgently needs to be solved. Summary of the Invention
[0004] This invention provides a data processing method for a USB device, an electronic device, and a readable medium, which can enable device switching.
[0005] To address the aforementioned problems, this invention discloses a data processing method for a USB device, applied to a proxy terminal in a first physical machine. The method includes: Upon receiving a device usage request from the first client, it checks whether a target client currently exists among the proxied clients; the target client is a client that uses a target USB device, and the target USB device is the USB device requested by the device usage request. In the presence of the target client, the data transmission status of the transmission connection with the target client is detected; When the data transmission state is used to characterize a switchable state, a transmission connection is established with the first client, and the USB data of the target USB device is forwarded to the first client.
[0006] Optionally, the method further includes: If the recovery conditions of the target client are met, the connection information corresponding to the target client is retrieved from the pre-recorded connection information table; wherein, the connection information table is used to record the connection information of the client that is saved when a transmission connection is established with the client; Based on the connection information corresponding to the target client, the transmission connection with the target client is restored, and the USB data of the target USB device is forwarded to the target client.
[0007] Optionally, the proxy is connected to the USB server, and the USB server is connected to the USB device; The forwarding of USB data from the target USB device to the first client includes: The USB server forwards the device usage request sent by the first client. Receive the USB data of the target USB device returned by the USB server in response to the device usage request; Based on the transmission connection with the first client, the USB data of the target USB device is forwarded to the first client.
[0008] Optionally, detecting the data transmission status of the transmission connection with the target client includes: Detect whether data transmission exists in the transmission connection with the target client; If data transmission exists in the transmission connection, the data transmission status is determined to characterize the switchable state; If no data transmission occurs in the transmission connection, the data transmission status is determined to represent an unswitchable state.
[0009] Optionally, the method further includes: If the data transmission status is determined to represent an unswitchable state, a handover confirmation message is sent to the first client. Upon receiving the confirmation response from the first client, a transmission connection is established with the first client, and the USB data of the target USB device is forwarded to the first client; the switching confirmation information is generated in response to the switching confirmation information and based on the user operation.
[0010] Optionally, detecting whether the target client currently exists among the proxied clients includes: The client that establishes a transmission connection with the proxy is designated as the proxied client, and a first device identifier is determined based on the device identifier of the USB device currently used by each of the proxied clients; Based on the device usage request sent by the first client, the device identifier of the target USB device is determined and used as the target identifier; The proxy client whose corresponding device identifier matches the target identifier is designated as the target client.
[0011] Optionally, the device usage request is generated based on the device information of the target USB device; the method further includes: In response to the device information request sent by the first client, the device information request is sent to the USB server; the device information request is used to obtain the device information of the target USB device; The device information returned by the USB server in response to the device information request is received and forwarded to the first client.
[0012] Optionally, both the first physical machine and the virtual machine deployed on the first physical machine display device options for USB devices connected to the USB server; The first client and the target client belong to the first physical machine or the virtual machine, respectively.
[0013] On the other hand, embodiments of the present invention disclose an electronic device, including: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, wherein the executable instruction causes the processor to execute the aforementioned method.
[0014] This invention also discloses a machine-readable medium storing instructions that, when executed by one or more processors, cause the processors to perform the methods described above.
[0015] This invention also discloses a computer program product, including a computer program that, when executed by a processor, implements the steps of the above-described method.
[0016] The embodiments of the present invention have the following advantages: The data processing method for a USB device provided in the embodiments of the present invention, upon receiving a device usage request sent by a first client, detects whether a target client currently exists among the proxied clients; the target client is a client using a target USB device, and the target USB device is the USB device requested in the device usage request. If a target client exists, the data transmission status of the transmission connection with the target client is detected. If the data transmission status indicates a switchable state, a transmission connection is established with the first client, and the USB data of the target USB device is forwarded to the first client. In this way, the currently used USB device can be switched to another client, and the switching only occurs when the data transmission status of the target client currently using the target USB device indicates a switchable state, which can reduce the impact of the switching operation on the target client to a certain extent, thereby ensuring the switching effect. Attached Figure Description
[0017] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 This is a flowchart of the steps of a data processing method for a USB device provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0019] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0020] First, the application scenarios involved in the embodiments of the present invention will be described. The execution subject of the data processing method provided in the embodiments of the present invention can be a physical machine, on which a virtual machine is deployed; correspondingly, the physical machine can also be called a host machine. Specifically, a proxy is also deployed on the physical machine, and the execution subject of the data processing method can specifically be this proxy. The proxy can essentially be a software application, and can also be called a USB proxy layer.
[0021] USB devices can connect to a USB server. For example, a USB server is deployed on a physical machine. USB devices connected to this physical machine establish a connection with the USB server. The physical machine to which the USB device is connected (hereinafter referred to as the second physical machine) can be the same physical machine as the execution entity of the data processing method (hereinafter referred to as the first physical machine), or the second physical machine and the first physical machine can be different physical machines. For example, the second physical machine can be a remote device. The USB server can support the USB / IP protocol and share the connected USB device with the first physical machine via an IP network based on the USB / IP protocol. The USB / IP protocol is an open-source technology that allows remote sharing of USB devices via an IP network. Exemplarily, the first physical machine can establish a connection with the second physical machine. Specifically, a proxy in the first physical machine can establish a connection with the USB server in the second physical machine, for example, by establishing a TCP / IP connection. Correspondingly, the USB server can also be called a usbip service, a tool provided by the Linux kernel for remotely accessing USB devices.
[0022] The data processing method for USB devices provided in the embodiments of the present invention will be described in detail below.
[0023] Figure 1 This is a flowchart illustrating the steps of a data processing method for a USB device provided in an embodiment of the present invention, applied to a proxy end in a first physical machine, such as... Figure 1 As shown, the data processing method of this USB device may include the following steps: Step 101: Upon receiving a device usage request from the first client, detect whether a target client currently exists among the proxied clients; the target client is a client using a target USB device, and the target USB device is the USB device requested by the device usage request.
[0024] Step 102: If the target client exists, detect the data transmission status of the transmission connection with the target client.
[0025] Step 103: When the data transmission state is used to characterize the switchable state, establish a transmission connection with the first client and forward the USB data of the target USB device to the first client.
[0026] In this embodiment of the invention, the proxy end is connected to the USB server, and the USB server is connected to the USB device. The client can interact with the USB server through the proxy end. Here, the client refers to software that needs to use the USB device; essentially, it is an application, also known as a USB client. In this embodiment, the first physical machine (i.e., the client in the host machine) and the clients in the virtual machine constitute a client set. This client set includes a first client and a target client; specifically, the client set includes the first client and the proxied client. The proxied client refers to the client that has established a transmission connection with the proxy end. In this embodiment, the connection method between the client in the virtual machine and the proxy end is the same as the connection method between the client in the host machine and the proxy end.
[0027] Furthermore, the first client can be any client in the client set, and the client can send a device usage request to the proxy when a USB data acquisition operation is triggered. For example, when the user clicks the image acquisition button on the first client interface, the first client can select the desired USB device from the currently identified USB devices. For instance, a USB camera can be selected as the desired USB device. A device usage request for the USB camera is then sent to the proxy. Accordingly, the USB device indicated by the device usage request is the USB camera. In this embodiment of the invention, the communication address of the USB server recorded in the configuration information of each client can be modified in advance to the communication address of the proxy, so that all requests sent by each client to the USB server are actually sent to the proxy. The communication address can be the IP address of the proxy.
[0028] Accordingly, the proxy can use a client with the target USB device that has already established a transmission connection as the target client. Here, the transmission connection is the connection used to transmit USB data to the client; exemplarily, this transmission connection can be a socket connection. The proxy can generate a socket file descriptor for the first client and identify the socket connection using the first client's IP address and port number. For example, the IP address and port number can be stored in correspondence with the socket file descriptor of the socket connection. When transmitting USB data to the first client, a data transfer function can be called to send USB data to the IP address and port number using the socket file descriptor, thereby achieving the transmission of USB data to the first client.
[0029] Furthermore, since the target USB device is currently occupied by the target client, the agent can first detect the data transmission status of the transmission connection with the target client. If the data transmission status indicates a switchable state, it means that the target USB device can now be switched to the first client. Switching the target USB device to the first client means forwarding the USB data of the target USB device to the first client. Accordingly, if the data transmission status indicates a switchable state, a transmission connection can be established with the first client, and the USB data of the target USB device can be forwarded to the first client.
[0030] In summary, the USB device data processing method provided in this embodiment of the invention, upon receiving a device usage request sent by a first client, detects whether a target client currently exists among the proxied clients; the target client is the client using the target USB device, and the target USB device is the USB device requested in the device usage request. If a target client exists, the data transmission status of the transmission connection with the target client is detected. If the data transmission status indicates a switchable state, a transmission connection is established with the first client, and the USB data of the target USB device is forwarded to the first client. This achieves the switching of the currently used USB device to other clients, and the switching only occurs when the data transmission status of the target client currently using the target USB device indicates a switchable state. This reduces the impact of the switching operation on the target client to a certain extent, thereby ensuring the switching effect.
[0031] Optionally, both the first physical machine and the virtual machine deployed on the first physical machine display a device option for a USB device connected to the USB server; the first client and the target client belong to the first physical machine or the virtual machine, respectively.
[0032] Assuming the host machine is a computer running one or more virtual machines, in existing technology, for any connected USB device, the user is prompted to insert it into the virtual machine. If the user confirms insertion into a virtual machine, the host machine will no longer display the device option for that USB device until the virtual machine ejects the USB device. The user needs to manually find the USB device name via command line and manually configure the virtual machine management software to insert the USB device into the virtual machine for the virtual machine to recognize it. Furthermore, after configuring the USB device to be inserted into the virtual machine, the connection to the host machine needs to be manually changed for the USB device to appear on the host machine for use by clients on the host machine. The entire process is quite cumbersome.
[0033] In this embodiment of the invention, without manual user operation, the agent can send a device list retrieval request to the USB server. The agent receives a device list returned by the USB server in response to the request. This device list records all currently connected USB devices. The first physical machine can display device options representing each USB device in the USB device list. Each device option represents a USB device in the list; for example, the device option may include the name of the USB device. Specifically, the first physical machine can directly display device options on both the host machine interface and the virtual machine interface, ensuring that both the first physical machine and the virtual machine deployed on it display device options for the USB devices connected to the USB server. This makes the operation more convenient and efficient. Thus, both the host machine and the virtual machine can display device options for USB devices, allowing both to simultaneously identify the USB devices connected to the USB server, and enabling users to easily identify the currently existing USB devices. The host machine and the virtual machine can identify the USB devices represented by their respective displayed device options; the USB devices represented by the displayed device options are the currently identified USB devices. This allows both USB clients on the host machine and USB clients in the virtual machine to access USB devices connected to the USB server, improving ease of use.
[0034] It should be noted that when the second physical machine connected to the USB device is different from the first physical machine, the client in this embodiment of the invention is essentially a remote client. In one application scenario, the first client can belong to the first physical machine, and the target client can belong to a virtual machine. Alternatively, the target client can belong to the first physical machine, and the first client can belong to a virtual machine. In this embodiment of the invention, both the virtual machine and the host machine can recognize the USB device connected to the USB server. Therefore, the client in the virtual machine and the client in the host machine may sometimes request to use the same USB device, meaning that the USB device requested by the first client is used by the target client. In this embodiment of the invention, by switching when the data transmission status of the target client indicates a switchable state, the first client uses the target USB device, achieving the effect of time-sharing multiplexing.
[0035] Of course, in other application scenarios, the first client and the target client may both belong to the host machine or both belong to the virtual machine. For example, the two clients may both belong to the same virtual machine in the host machine, or they may belong to different virtual machines in the host machine. This embodiment of the invention does not limit this.
[0036] Optionally, in this embodiment of the invention, the step of forwarding the USB data of the target USB device to the first client may specifically include: Step 1031: Forward the device usage request sent by the first client to the USB server.
[0037] Step 1032: Receive the USB data of the target USB device returned by the USB server in response to the device usage request.
[0038] Step 1033: Based on the transmission connection with the first client, forward the USB data of the target USB device to the first client.
[0039] In this embodiment of the invention, the proxy can, after establishing a transmission connection with the first client, forward the USB data of the target USB device to the first client upon receiving a data acquisition request from the first client, based on the transmission connection with the first client. Alternatively, it can directly send USB data to the first client after establishing a transmission connection with the first client.
[0040] The proxy acts as an intermediary between the USB server and the client. It forwards received device usage requests to the USB server. Upon receiving the request, the USB server processes it. For example, the USB server can extract the device identifier carried in the request and obtain the USB data generated by the USB device indicated by that identifier. This USB data is then returned to the proxy as the response data to the device usage request. For instance, assuming the first client is software using a USB camera, the device usage request could be an image acquisition request, and the carried device identifier could be the USB camera's device identifier. Accordingly, the USB server can obtain the image data captured by the connected USB camera and return it to the proxy as the response data. It should be noted that without a proxy, the USB server and client communicate directly. With a proxy, communication between the USB server and client is relayed through the proxy, which forwards data between them. The proxy does not process the forwarded USB data.
[0041] Accordingly, the proxy can receive the response data and, based on the transmission connection with the first client, forward the USB data of the target USB device carried in the response data to the first client. For example, the proxy can use the socket file descriptor of the transmission connection with the first client to call a send function to send the USB data of the target USB device to the first client. In this way, by sending the USB data of the target USB device to the first client, a single-client interaction process is achieved. In this embodiment of the invention, the forwarded USB data is data generated by the target USB device; different types of USB devices generate different USB data.
[0042] For example, when the target USB device is a USB key (U-shield), the first client can be U-shield software, and the USB data from the target USB device can be U-shield information. When the target USB device is a USB keyboard, the first client can be typing practice software, and the USB data from the target USB device can be keyboard information. When the target USB device is a USB camera, the first client can be camera monitoring software, and the USB data from the target USB device can be image data captured by the USB camera. After receiving the USB data from the target USB device, the first client can display the image data captured by the USB camera. It should be noted that the proxy may receive multiple device usage requests. Accordingly, after receiving a device usage request, the proxy can record each device usage request and its corresponding client. The client corresponding to the device usage request refers to the client that sent the device usage request. Accordingly, after receiving the response data from the server, the proxy forwards the USB data in the response data to the client corresponding to the device usage request responded to by the response data. The device usage request responded to by the response data has the same request identifier as the device usage request itself, so that the proxy can easily identify the response data of each device usage request.
[0043] In this embodiment of the invention, by forwarding the device usage request sent by the first client to the USB server, the USB data of the target USB device returned by the USB server in response to the device usage request can be received. Thus, subsequently, only the USB data of the target USB device needs to be forwarded to the first client based on the transmission connection with the first client, thereby providing the first client with the required USB data of the target USB device. This results in high data provision efficiency and high response efficiency to the device usage request sent by the first client.
[0044] It is understood that in this embodiment of the invention, the proxy terminal performs multi-client switching decisions while forwarding data. While the first client is using the target USB device, if another client sends a device usage request requesting the use of the target USB device, then the first client becomes the current target client. Accordingly, if the data transmission status of the transmission connection with the first client indicates a switchable state, a transmission connection can be established with that other client, and the USB data of the target USB device can be forwarded to that other client.
[0045] Optionally, the data processing method provided in this embodiment of the invention may further include the following steps: Step S21: If the recovery conditions of the target client are met, search for the connection information corresponding to the target client from the pre-recorded connection information table; wherein, the connection information table is used to record the connection information of the client that is saved when a transmission connection is established with the client.
[0046] Step S22: Based on the connection information corresponding to the target client, restore the transmission connection with the target client and forward the USB data of the target USB device to the target client.
[0047] In this embodiment of the invention, if the recovery conditions of the target client are currently met, it indicates that the target USB device can be switched to the target client for use. Accordingly, the proxy can restore the transmission connection with the target client and forward the USB data of the target USB device to the target client, thereby switching the target USB device to the target client for use. Specifically, the recovery conditions can be preset as needed. For example, it can be determined that the recovery conditions of the target client are currently met when a device use request for the target USB device is received from the target client, and the data transmission status of the transmission connection with the first client indicates a switchable state. Alternatively, the recovery conditions of the target client can be determined to be met after forwarding the USB data of the target USB device to the first client. This embodiment of the invention does not limit this.
[0048] Each time the proxy establishes a transport connection with a client, it records the client's connection information. This connection information may include the socket file descriptor of the transport connection with the client, the client's IP address, and port number. For example, upon receiving a device usage request, the proxy records the client identifier, IP address, and port number carried in the request. When establishing a transport connection with the client, the proxy stores the client identifier, IP address, and port number, along with the corresponding socket file descriptor of the transport connection, in a connection information table. Accordingly, if the recovery conditions of the target client are met, the proxy can retrieve the corresponding IP address, port number, and socket file descriptor of the transport connection from the connection information table based on the target client's client identifier to obtain the connection information. The IP address and port number can be considered the client's transport address. The proxy can then use the target client's socket file descriptor to call a send function, reassigning the call parameter variable of the send function to the target client's socket file descriptor to achieve recovery. At the same time, the USB data returned by the USB server is sent to the IP address and port number of the target client through this sending function, so as to forward the USB data to the target USB device to the target client.
[0049] In this embodiment of the invention, when the recovery conditions of the target client are met, the connection information corresponding to the target client is retrieved from a pre-recorded connection information table. This connection information table records the client's connection information saved when a transmission connection is established with the client. Based on the connection information corresponding to the target client, the transmission connection with the target client is restored, and the USB data from the target USB device is forwarded to the target client. In this way, by restoring the connection, the target client that previously used the target USB device can regain access to the target USB device's USB data, thus reducing the impact of the switching operation on the target client's usage to some extent.
[0050] Optionally, in this embodiment of the invention, the step of detecting the data transmission status of the transmission connection with the target client may specifically include: Step 1021: Detect whether data transmission exists in the transmission connection with the target client.
[0051] Step 1022: If data transmission exists in the transmission connection, then determine the data transmission status to characterize the switchable status.
[0052] Step 1023: If the transmission connection does not have data transmission, then the data transmission status is determined to represent the non-switchable state.
[0053] In one implementation, this embodiment of the invention can call a preset detection function to read data on the transmission connection with the target client. If the data length returned by the detection function is greater than 0, it can be determined that data transmission exists on the transmission connection with the target client. Conversely, if the data length returned by the detection function is not greater than 0, it can be determined that no data transmission exists on the transmission connection with the target client. For example, the preset detection function can be a recv function or a read function, and this embodiment of the invention does not limit this.
[0054] Furthermore, if no data is being transmitted through the transmission connection with the target client, it can be determined that the transmission connection with the target client is in a suspended state. Accordingly, it can be determined that if a handover is performed at this time, it will not cause transmission interruption on the target client. Therefore, the data transmission state can be used to characterize the switchable state. Conversely, if data is being transmitted through the transmission connection with the target client, it can be determined that if a handover is performed at this time, it will cause transmission interruption on the target client. Therefore, the data transmission state can be used to characterize the non-switchable state.
[0055] In this embodiment of the invention, the presence of data transmission over the transmission connection with the target client is detected. If data transmission exists, the data transmission status is determined to characterize a switchable state. If no data transmission exists, the data transmission status is determined to characterize a non-switchable state. Thus, by detecting whether data transmission exists over the transmission connection with the target client, it is possible to determine whether the target client is currently in a switchable state, which can, to some extent, ensure overall processing efficiency.
[0056] The embodiments of the present invention may further include: Step S31: If the data transmission status is determined to represent an unswitchable state, send a handover confirmation message to the first client.
[0057] Step S32: Upon receiving the confirmation response information returned by the first client, establish a transmission connection with the first client and forward the USB data of the target USB device to the first client; the switching confirmation information is generated in response to the switching confirmation information and based on the user operation.
[0058] The switch confirmation information indicates that data transmission is currently occurring on the target client's connection. The switch confirmation information can be a first string in a preset format; for example, it can be "Force switch," but this embodiment of the invention does not limit this. Accordingly, when the first client receives the first string, it can confirm receipt of the switch confirmation information. A prompt window can be displayed on the interface. If a user selects the confirmation button in the prompt window, it is determined that the user has chosen to forcibly disconnect the target client from the target USB device. A confirmation response can be generated for the switch confirmation information. The prompt window can include a preset prompt message, a confirmation button, and a cancel button. For example, the preset prompt message can be "The target USB device is being used by the target client; force disconnect?" The user can click the confirmation button if a forced disconnect is needed, and click the cancel button if a forced disconnect is not required.
[0059] Furthermore, the confirmation response information can be a second string in a preset format. For example, the switch confirmation information can be "YES," and this embodiment of the invention does not limit this. Accordingly, when the agent receives the second string, it can confirm that it has received the confirmation response information. Accordingly, it can pause the transmission of data to the target client and establish a transmission connection with the first client, sending the USB data of the target USB device to the first client. It is understood that if the user's selection operation of the cancel button in the prompt window is detected, it is determined that the user has chosen not to forcibly disconnect the connection of the target client, and accordingly, a cancellation response information can be generated for the switch confirmation information. The cancellation response information can be a third string in a preset format. For example, the switch confirmation information can be "NO," and this embodiment of the invention does not limit this. Accordingly, when the agent receives the third string, it can confirm that it has received the cancellation response information. Accordingly, it can directly determine that the current device usage request is invalid and exit the current processing flow.
[0060] In this embodiment of the invention, when the data transmission state is determined to represent an unswitchable state, a switching confirmation message is sent to the first client; upon receiving a confirmation response message from the first client based on user operation, a transmission connection is established with the first client, and the USB data of the target USB device is forwarded to the first client. This allows the user to easily decide whether to preempt the target USB device used by the target client, resulting in high user convenience.
[0061] Alternatively, in another embodiment of the invention, the method may further include: when it is determined that the data transmission state is used to characterize an unswitchable state, returning waiting information to the first client. This avoids the problem of switching causing transmission interruption to the target client, affecting its normal use. Specifically, after receiving the returned waiting information, the first client can display a waiting prompt to the user. For example, the waiting prompt can be text information, such as: "Please try again later."
[0062] Optionally, in this embodiment of the invention, after the step of determining the data transmission state to characterize the switchable state if data transmission exists in the transmission connection, the method may further include: sending an exit notification message to the target client to instruct the target client to output an exit prompt message to the user; the exit prompt message is used to characterize that the target client has exited the service; and sending a first prompt message to the USB server, the first prompt message being used to instruct the USB server to perform a reset process on the target USB device.
[0063] The exit notification message indicates that the transfer of USB data from the target USB device to the target client is currently suspended, and the target client has exited the service. Accordingly, the target client can display this exit notification message on its interface, allowing the user to be promptly informed that the transfer of USB data from the target USB device to the target client is currently suspended. This way, when the user needs to use the target USB device's USB data through the target client, the target client can be triggered to re-initiate a device usage request.
[0064] Furthermore, the proxy can also send a first prompt message to the USB server. This first prompt message can instruct the USB server to perform a reset operation, and it carries the device identifier of the target USB device. The specific format of the first prompt message can adopt a format pre-agreed upon by the proxy and the USB server; this embodiment of the invention does not impose any restrictions on this. Accordingly, in response to the first prompt message, the USB server will perform a reset operation on the device represented by the carried device identifier (i.e., the target USB device). In this way, by performing the reset operation, it can ensure that the latest data collected by the target USB device is sent to the first client, ensuring the timeliness of the transmitted data.
[0065] It should be noted that the proxy can also send a second prompt message to the first client to indicate continued execution. The specific format of the second prompt message can adopt a format pre-agreed upon by the proxy and the client, and this embodiment of the invention does not impose any restrictions on this. Upon receiving the second prompt message, the first client can read the data transmitted on the transmission connection with the proxy and perform subsequent operations, such as displaying data.
[0066] Optionally, in this embodiment of the invention, the step of detecting whether the target client currently exists among the proxied clients may specifically include: Step 1011: The client that has established a transmission connection with the agent is designated as the agent client, and a first device identifier is determined based on the device identifier of the USB device currently used by each agent client.
[0067] Step 1012: Based on the device usage request sent by the first client, determine the device identifier of the target USB device as the target identifier.
[0068] Step 1013: Select the proxy client whose corresponding device identifier matches the target identifier as the target client.
[0069] In this embodiment of the invention, when establishing a transmission connection with the client, the proxy can also record the device identifier of the USB device and the client identifier carried in the device usage request sent by the client. This device identifier is then used as the device identifier of the USB device currently used by the client. For example, the device identifier of the USB device currently used by the client, the client identifier, and the socket file descriptor of the client's transmission connection can be stored accordingly. Correspondingly, the device identifiers corresponding to the socket file descriptors of each transmission connection that is not in a suspended state can be obtained, and these identifiers can be used as the first device identifier.
[0070] Furthermore, the device identifier carried in the device usage request sent by the first client can be extracted as the target identifier. Then, the target identifier is compared with each device identifier in the first device identifier. The client represented by the client identifier corresponding to the device identifier that is the same as the target identifier is determined as the target client.
[0071] In this embodiment of the invention, the client that has established a transmission connection with the proxy is designated as the proxy client, and a first device identifier is determined based on the device identifier of the USB device currently used by each proxy client. Based on the device usage request sent by the first client, the device identifier of the target USB device is determined and used as the target identifier. The proxy client whose device identifier matches the target identifier is designated as the target client. In this way, the target client can be identified through device representation comparison, which is relatively easy to implement and can ensure overall processing efficiency to a certain extent.
[0072] Optionally, in embodiments of the present invention, a transmission connection can be directly established with the first client in the absence of the target client, and the USB data of the target USB device can be forwarded to the first client.
[0073] Optionally, in this embodiment of the invention, the device usage request sent by the first client is generated based on the device information of the target USB device. This embodiment of the invention may further include: Step S51: In response to the device information request sent by the first client, send the device information request to the USB server; the device information request is used to obtain the device information of the target USB device.
[0074] Step S51: Receive the device information returned by the USB server in response to the device information request, and forward it to the first client.
[0075] In this embodiment of the invention, when a USB device is connected to a physical machine, the device connection will be detected. Accordingly, the USB server can obtain the device descriptor of the USB device. The first client can send a device information request to the proxy to obtain device information of the target USB device. The device information can be a device descriptor, and the device information request can be an enumeration device request. For example, the first client can send this enumeration device request when it needs to access the target USB device. The proxy can forward the enumeration device request to the USB server, and in response, the USB server returns the device descriptor of the target USB device. The proxy then returns the device descriptor to the first client.
[0076] Accordingly, the first client can identify the device function represented by the device descriptor based on the target USB device's device descriptor. If the represented device function meets the pre-set usage requirements of the first client, it can generate a device usage request that conforms to the communication parameters defined in the device descriptor. For example, a device usage request with a length conforming to the data packet length defined in the device descriptor can be generated.
[0077] In this embodiment of the invention, in response to a device information request sent by a first client, a device information request is sent to a USB server; the device information request is used to obtain device information of the target USB device. The USB server receives the device information returned in response to the device information request and forwards it to the first client. This allows the client to conveniently obtain device information through a proxy, ensuring efficient information acquisition.
[0078] Reference Figure 2 This is a schematic diagram of the structure of the electronic device provided in an embodiment of the present invention. For example... Figure 2 As shown, the electronic device includes: a processor, a memory, a communication interface, and a communication bus.
[0079] The processor, the memory, and the communication interface communicate with each other via the communication bus; the memory stores at least one executable instruction, which causes the processor to execute the data processing method of the USB device described in the preceding embodiment. The executable instructions can form a program.
[0080] This invention provides a machine-readable medium storing instructions that, when executed by one or more processors, enable the processors to perform the data processing method of the USB device described in the preceding embodiments. The machine-readable medium may be one or more processors.
[0081] This invention also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the data processing method for the USB device described in the foregoing embodiments.
[0082] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0083] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, embodiments of the present invention can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of the present invention can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0084] It should be noted that all actions involving the acquisition of signals, information, or data in this application are carried out in compliance with the relevant data protection laws and policies of the country where the application is located, and with the authorization granted by the owner of the relevant device.
[0085] Embodiments of the present invention are described with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0086] These computer program instructions may also be stored in a computer-readable storage medium capable of directing a computer or other programmable data processing terminal device to operate in a predictive manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0087] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0088] Although preferred embodiments of the present invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present invention.
[0089] Finally, it should be noted that in this paper, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0090] Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0091] The foregoing has provided a detailed description of a data processing method for a USB device, an electronic device, and a readable medium provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A data processing method for a USB device, characterized in that, The method, applied to the agent in the first physical machine, includes: Upon receiving a device usage request from the first client, it checks whether a target client currently exists among the proxied clients; the target client is a client that uses a target USB device, and the target USB device is the USB device requested by the device usage request. In the presence of the target client, the data transmission status of the transmission connection with the target client is detected; When the data transmission state is used to characterize a switchable state, a transmission connection is established with the first client, and the USB data of the target USB device is forwarded to the first client.
2. The method according to claim 1, characterized in that, The method further includes: If the recovery conditions of the target client are met, the connection information corresponding to the target client is retrieved from the pre-recorded connection information table; wherein, the connection information table is used to record the connection information of the client that is saved when a transmission connection is established with the client; Based on the connection information corresponding to the target client, the transmission connection with the target client is restored, and the USB data of the target USB device is forwarded to the target client.
3. The method according to claim 1, characterized in that, The proxy terminal is connected to the USB server, and the USB server is connected to the USB device; The forwarding of USB data from the target USB device to the first client includes: The USB server forwards the device usage request sent by the first client. Receive the USB data of the target USB device returned by the USB server in response to the device usage request; Based on the transmission connection with the first client, the USB data of the target USB device is forwarded to the first client.
4. The method according to claim 1, characterized in that, The detection of the data transmission status of the transmission connection between the target client and the target client includes: Detect whether data transmission exists in the transmission connection with the target client; If data transmission exists in the transmission connection, the data transmission status is determined to characterize the switchable state; If no data transmission occurs in the transmission connection, the data transmission status is determined to represent an unswitchable state.
5. The method according to claim 1, characterized in that, The method further includes: If the data transmission status is determined to represent an unswitchable state, a handover confirmation message is sent to the first client. Upon receiving the confirmation response from the first client, a transmission connection is established with the first client, and the USB data of the target USB device is forwarded to the first client; the switching confirmation information is generated in response to the switching confirmation information and based on the user operation.
6. The method according to claim 1, characterized in that, The detection of whether the target client currently exists among the proxied clients includes: The client that establishes a transmission connection with the proxy is designated as the proxied client, and a first device identifier is determined based on the device identifier of the USB device currently used by each of the proxied clients; Based on the device usage request sent by the first client, the device identifier of the target USB device is determined and used as the target identifier; The proxy client whose corresponding device identifier matches the target identifier is designated as the target client.
7. The method according to claim 1, characterized in that, The device usage request is generated based on the device information of the target USB device; the method further includes: In response to the device information request sent by the first client, the device information request is sent to the USB server; the device information request is used to obtain the device information of the target USB device; The device information returned by the USB server in response to the device information request is received and forwarded to the first client.
8. The method according to claim 1, characterized in that, Both the first physical machine and the virtual machine deployed on the first physical machine display device options for USB devices connected to the USB server; The first client and the target client belong to the first physical machine or the virtual machine, respectively.
9. An electronic device, characterized in that, include: The processor, memory, communication interface, and communication bus are provided, wherein the processor, memory, and communication interface communicate with each other via the communication bus. The memory is used to store executable instructions that cause the processor to perform the method as described in any one of claims 1 to 8.
10. A machine-readable medium, characterized in that, It stores instructions that, when executed by one or more processors, cause the processors to perform the method as described in any one of claims 1 to 8.
11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 8.