Patch logic execution method and device, storage medium and electronic device
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- QINGDAO HAIER TECH
- Filing Date
- 2025-12-29
- Publication Date
- 2026-05-05
AI Technical Summary
[0006]本申请实施例提供了一种补丁逻辑的执行方法和装置、存储介质及电子装置,以至少解决相关技术中在需要在设备管理类中添加回调方法时,无法在不影响原有业务逻辑的情况下添加补丁逻辑的问题
[0018]在本申请实施例中,在确定目标设备接收控制命令的情况下,基于预设匹配规则确定包括多个拦截器实例的拦截器数组中是否存在与目标设备匹配的封装有用于执行目标设备的补丁逻辑的脚本的目标拦截器实例;在确定拦截器数组中存在目标拦截器实例的情况下,确定目标设备执行控制命令的执行结果;调用目标拦截器实例,并指示目标拦截器实例基于执行结果为目标设备添加补丁逻辑,以使目标设备执行补丁逻辑。也就是说,本申请在目标设备接收到控制命令的情况下,基于确定拦截器数组中是否存在与目标设备匹配的目标拦截器数组;在确定存在目标拦截器数组的情况下,即可通过目标拦截器数组为目标设备添加补丁逻辑,进而可以在不影响目标设备执行控制命令的原有逻辑的情况下,指示目标拦截器实例根据目标设备执行控制命令的执行结果添加和执行补丁逻辑。通过本申请,可以解决相关技术中在需要在设备管理类中添加回调方法时,无法在不影响原有业务逻辑的情况下添加补丁逻辑的问题,进而可以在不影响原有业务逻辑的情况下,为目标设备添加补丁逻辑。
Smart Images

Figure CN121979552A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of smart home technology, and more specifically, to a method and apparatus for executing patch logic, a storage medium, and an electronic device. Background Technology
[0002] In smart home and other fields, the device management code in home appliance applications contains a device management class that includes a device list and multiple device objects. As functionality iterates, the functions of these device objects become increasingly complex. Applications (APPs) need to manage various devices, and the device management class (e.g., UpDeviceManager) is responsible for maintaining the device list and device objects (e.g., UpDevice objects). Users can trigger device operations in multiple scenarios (such as smart home tab cards, device details pages, etc.), and the devices need to execute corresponding commands and provide feedback. To implement specific functions (e.g., real-time interaction), callback processing needs to be added after the device executes a command, but this must be done without interfering with the original device management logic.
[0003] When adding callback methods to the device management class, the following technical problems exist: it is not easy to add patch logic into complex logic, and it may affect the original logic; it is also difficult to isolate business that is not related to device management.
[0004] Therefore, in related technologies, when a callback method needs to be added to the device management class, it is impossible to add patch logic without affecting the original business logic.
[0005] There is no effective solution yet for the problem in related technologies where it is impossible to add patch logic without affecting the original business logic when adding callback methods in the device management class. Summary of the Invention
[0006] This application provides a method and apparatus for executing patch logic, a storage medium, and an electronic device to at least solve the problem in related technologies where, when a callback method needs to be added to a device management class, patch logic cannot be added without affecting the original business logic.
[0007] According to one embodiment of this application, a method for executing patch logic is provided, comprising: when it is determined that a target device has received a control command, determining whether there is a target interceptor instance matching the target device in an interceptor array based on a preset matching rule, wherein the interceptor array includes: a plurality of interceptor instances, and the target interceptor instance encapsulates a script for executing patch logic for the target device; when it is determined that the target interceptor instance exists in the interceptor array, determining the execution result of the target device executing the control command; invoking the target interceptor instance and instructing the target interceptor instance to add the patch logic to the target device based on the execution result, so that the target device executes the patch logic.
[0008] In an exemplary embodiment, before determining whether a target interceptor instance matching the target device exists in the interceptor array based on a preset matching rule, the method includes: traversing a preset device list based on a preset time period to determine whether a first device exists in the preset device list, wherein the preset device list includes: the target device, and the first device is a device newly added to the preset device list in the last time period before the current time; if it is determined that the first device exists in the preset device list, invoking a preset interceptor protocol, and generating a first interceptor instance corresponding to the first device based on the preset interceptor protocol and the first device; and adding the first interceptor instance to the interceptor array.
[0009] In an exemplary embodiment, generating a first interceptor instance corresponding to the first device based on the preset interceptor protocol and the first device includes: creating an interceptor object corresponding to the first device based on a first method declaration in the preset interceptor protocol, wherein the first method declaration is used to declare a method for creating the interceptor object that matches the first device and the preset interceptor protocol; modifying the interceptor object based on a second method declaration and a third method declaration of the preset interceptor protocol to generate the first interceptor instance, wherein the second method declaration is used to declare a method for matching the first device with the interceptor object, and the third method declaration is used to declare at least one of the following: a first callback method of the first device before executing the first control command, a second callback method of the first device after successfully executing the first control command, and a third callback method of the first device after failing to execute the first control command.
[0010] In an exemplary embodiment, before determining whether a target interceptor instance matching the target device exists in the interceptor array based on a preset matching rule, the method includes: traversing a preset device list based on a preset time period, and comparing a first traversal result obtained by traversing the preset device list at the current time with a second traversal result obtained by the last traversal of the preset device list before the current time, wherein the preset device list includes the target device; if it is determined that the second traversal result indicates that a second device exists in the preset device list, and the first traversal result indicates that the second device does not exist in the preset device list, determining whether a second interceptor instance matching the second device exists in the interceptor array; if it is determined that the second interceptor instance exists in the interceptor array, deleting the second interceptor instance.
[0011] In an exemplary embodiment, invoking the target interceptor instance and instructing the target interceptor instance to add the patch logic to the target device based on the execution result, so that the target device executes the patch logic, includes: in the case that the execution result is an execution failure, invoking the target interceptor instance and instructing the target interceptor instance to generate failure information corresponding to the execution result; and displaying the failure information on the display screen corresponding to the target device.
[0012] In one exemplary embodiment, invoking the target interceptor instance and instructing the target interceptor instance to add the patch logic to the target device based on the execution result, so that the target device executes the patch logic, includes: if the execution result is successful, invoking the target interceptor instance and instructing the target interceptor instance to execute a post-processing task corresponding to the target device, wherein the post-processing task includes at least one of the following: a real-time interaction task between the target object and the target device, a task to update the device status of the target device, and a task to display the execution progress of the target device in executing the control command.
[0013] In an exemplary embodiment, determining whether there is a target interceptor instance in the interceptor array that matches the target device based on a preset matching rule includes: determining the target device type corresponding to the target device when the preset matching rule is used to indicate the correspondence between device types and interceptor instances; and determining whether there is a target interceptor instance in the interceptor array corresponding to a device of the target device type.
[0014] According to another embodiment of the present application, a patch logic execution device is also provided, comprising: a first determining module, configured to determine, based on a preset matching rule, whether there exists a target interceptor instance matching the target device in an interceptor array when it is determined that the target device has received a control command, wherein the interceptor array includes: a plurality of interceptor instances, and the target interceptor instance encapsulates a script for executing patch logic for the target device; a second determining module, configured to determine, when it is determined that the target interceptor instance exists in the interceptor array, the execution result of the target device executing the control command; and a calling module, configured to call the target interceptor instance and instruct the target interceptor instance to add the patch logic to the target device based on the execution result, so that the target device executes the patch logic.
[0015] According to another aspect of the embodiments of this application, a computer-readable storage medium is also provided, wherein a computer program is stored in the computer program, and the computer program is configured to execute the above-described patching logic execution method when running.
[0016] According to another aspect of the embodiments of this application, an electronic device is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the above-described patching logic execution method through the computer program.
[0017] According to another aspect of the embodiments of this application, a computer program product is also provided, including a computer program, wherein the computer program is executed by a processor to perform the above-described patching logic execution method.
[0018] In this embodiment, when it is determined that the target device receives a control command, a target interceptor instance matching the target device and containing a script for executing patching logic for the target device is determined based on a preset matching rule. If a target interceptor instance exists in the interceptor array, the execution result of the control command executed by the target device is determined. The target interceptor instance is then invoked and instructed to add patching logic to the target device based on the execution result, so that the target device executes the patching logic. In other words, when the target device receives a control command, this application determines whether a target interceptor array matching the target device exists in the interceptor array. If a target interceptor array exists, patching logic can be added to the target device through the target interceptor array. This allows the target interceptor instance to add and execute patching logic based on the execution result of the control command without affecting the original logic of the target device executing the control command. This application solves the problem in related technologies where, when adding callback methods to a device management class, patching logic cannot be added without affecting the original business logic, thus enabling the addition of patching logic to the target device without impacting the original business logic. Attached Figure Description
[0019] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0020] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 This is a schematic diagram of the hardware environment for a patch logic execution method according to an embodiment of this application;
[0022] Figure 2 This is a flowchart of the patch logic execution method according to an embodiment of this application;
[0023] Figure 3 This is a schematic diagram of the interception and callback processing method for device command execution according to an optional embodiment of this application;
[0024] Figure 4 This is a timing diagram for adding interceptors according to an optional embodiment of this application;
[0025] Figure 5 This is a timing diagram of interceptor usage according to an optional embodiment of this application;
[0026] Figure 6 This is a structural block diagram of a patch logic execution device according to an embodiment of this application. Detailed Implementation
[0027] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0028] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0029] According to one aspect of the embodiments of this application, a method for executing patch logic is provided. This method for executing patch logic is widely applicable to whole-house intelligent digital control application scenarios such as smart homes, smart home ecosystems, and intelligence house ecosystems. Optionally, Figure 1 This is a schematic diagram of a hardware environment for executing a patch logic according to an embodiment of this application. In this embodiment, the above-mentioned patch logic execution method can be applied to a computer device, and the computer device can be applied to, for example, Figure 1 The hardware environment shown consists of home appliance 102 and server 104. Figure 1 As shown, server 104 is connected to home appliance 102 via a network and can be used to provide services (such as application services) to nodes or clients installed on nodes. A database can be set up on the server or independently to provide data storage services for server 104. Cloud computing and / or edge computing services can be configured on the server or independently to provide data processing services for server 104.
[0030] The aforementioned networks may include, but are not limited to, at least one of the following: wired network, wireless network. The aforementioned wired network may include, but is not limited to, at least one of the following: wide area network (WAN), metropolitan area network (MAN), local area network (LAN). The aforementioned wireless network may include, but is not limited to, at least one of the following: Wi-Fi (Wireless Fidelity), Bluetooth. Home appliances 102 may not be limited to smart air conditioners, smart range hoods, smart refrigerators, smart ovens, smart stoves, smart washing machines, smart water heaters, smart washing equipment, smart dishwashers, smart projectors, smart TVs, smart clothes racks, smart curtains, smart audio-visual equipment, smart sockets, smart speakers, smart speakers, smart fresh air systems, smart kitchen and bathroom equipment, smart bathroom fixtures, smart robot vacuum cleaners, smart window cleaning robots, smart mopping robots, smart air purifiers, smart steam ovens, smart microwave ovens, smart water heaters, smart air purifiers, smart water dispensers, smart door locks, etc.
[0031] This embodiment provides a method for executing patch logic, applied to the aforementioned computer device. Figure 2 This is a flowchart of a patch logic execution method according to an embodiment of this application, which includes the following steps:
[0032] Step S202: If it is determined that the target device has received a control command, determine whether there is a target interceptor instance in the interceptor array that matches the target device based on a preset matching rule. The interceptor array includes multiple interceptor instances, and the target interceptor instance encapsulates a script for executing the patching logic of the target device.
[0033] Among them, the preset matching rules can be based on the device type of the target device to match the target interceptor instance, or based on the current running state of the target device to match the target interceptor instance, or based on the action type of the action to be executed by the target device according to the control command, etc.
[0034] Step S204: If it is determined that the target interceptor instance exists in the interceptor array, determine the execution result of the control command executed by the target device;
[0035] Step S206: Invoke the target interceptor instance and instruct the target interceptor instance to add the patch logic to the target device based on the execution result, so that the target device executes the patch logic.
[0036] The patch logic mentioned above can be business logic for starting real-time activities (e.g., displaying the remaining laundry time in real time), business logic for displaying failure information, etc.
[0037] Through the above steps, when it is determined that the target device receives a control command, the system determines, based on preset matching rules, whether there exists a target interceptor instance in the interceptor array (containing multiple interceptor instances) that matches the target device and encapsulates a script for executing patching logic for the target device. If a target interceptor instance is found in the interceptor array, the system determines the execution result of the control command executed by the target device. The system then calls the target interceptor instance and instructs it to add patching logic to the target device based on the execution result, so that the target device executes the patching logic. In other words, when the target device receives a control command, this application determines whether a target interceptor array matching the target device exists in the interceptor array. If a target interceptor array exists, patching logic can be added to the target device through the target interceptor array. This allows the target interceptor instance to add and execute patching logic based on the execution result of the control command executed by the target device without affecting the original logic of the target device executing the control command. This application solves the problem in related technologies where, when adding callback methods to a device management class, patching logic cannot be added without affecting the original business logic, thus enabling the addition of patching logic to the target device without impacting the original business logic.
[0038] Optionally, before determining whether a target interceptor instance matching the target device exists in the interceptor array based on preset matching rules in step S202 above, the method includes: traversing a preset device list based on a preset time period to determine whether a first device exists in the preset device list, wherein the preset device list includes: the target device, and the first device is a device newly added to the preset device list in the last time period before the current time; if it is determined that the first device exists in the preset device list, invoking a preset interceptor protocol, and generating a first interceptor instance corresponding to the first device based on the preset interceptor protocol and the first device; adding the first interceptor instance to the interceptor array.
[0039] The process of generating a first interceptor instance corresponding to the first device based on the preset interceptor protocol and the first device includes: creating an interceptor object corresponding to the first device based on a first method declaration in the preset interceptor protocol, wherein the first method declaration is used to declare a method for creating the interceptor object that matches the first device and the preset interceptor protocol; modifying the interceptor object based on a second method declaration and a third method declaration of the preset interceptor protocol to generate the first interceptor instance, wherein the second method declaration is used to declare a method for matching the first device with the interceptor object, and the third method declaration is used to declare at least one of the following: a first callback method of the first device before executing the first control command, a second callback method of the first device after successfully executing the first control command, and a third callback method of the first device after failing to execute the first control command.
[0040] Understandably, before determining whether a target interceptor instance exists in the interceptor array, specific command interceptors can be dynamically registered for devices newly added to the preset device list. Specifically:
[0041] 1) Traverse the device list: According to the preset time period, such as the early morning of each day or the hour of each hour, traverse the preset device list to identify any new devices added to the list after the most recent traversal, i.e., the first device.
[0042] Another way to determine whether a new device exists in the preset device list is to receive a prompt message sent by the device manager, wherein the prompt message is used to indicate that a new device exists in the preset device list.
[0043] 2) Generate an interceptor instance: Once the first device is identified, the preset interceptor protocol is invoked, and a first interceptor instance matching the first device is generated according to the creation method defined in the protocol. For example, for a newly added washing machine (the first device), a WashProgramStartInterceptor instance is generated.
[0044] 3) Configure callback methods: When generating an interceptor instance, the first interceptor instance is configured according to the second and third method declarations defined in the preset interceptor protocol, setting its callback logic. The second method declaration ensures that the interceptor (i.e., the first interceptor instance) is associated with a specific device (i.e., the first device), while the third method declaration defines the response behavior before, after success, and after failure of command execution, such as the `beforeCommandExecution`, `onCommandSuccess`, and `onCommandFailure` methods.
[0045] 4) Register the interceptor: Add the configured first interceptor instance to the interceptor array of the device object (i.e., the first device).
[0046] For example: Suppose the system iterates through the preset device list at 00:00 and finds a newly added washing machine (the first device). Based on the preset UpDeviceCommandInterceptor protocol and the corresponding WashProgramStartInterceptor class, the system will: create a WashProgramStartInterceptor instance, ensuring it matches the washing machine device; configure the instance's callback methods, such as calling beforeCommandExecution before the washing machine starts the washing program, onCommandSuccess after successful program startup, and onCommandFailure if startup fails; and add the configured WashProgramStartInterceptor instance to the washing machine device object's interceptor array.
[0047] The above technical solution allows for regular checks of device list changes, automatic registration and configuration of specific command interceptors for new devices, without manual intervention. Furthermore, it avoids direct modification to the core logic of device management classes (such as UpDeviceManager), instead extending functionality by adding interceptors, thus maintaining clean and modular code.
[0048] Optionally, before determining whether a target interceptor instance matching the target device exists in the interceptor array based on preset matching rules in step S202 above, the method includes: traversing a preset device list based on a preset time period, and comparing a first traversal result obtained by traversing the preset device list at the current time with a second traversal result obtained by the last traversal of the preset device list before the current time, wherein the preset device list includes the target device; if it is determined that the second traversal result indicates that a second device exists in the preset device list, and the first traversal result indicates that the second device does not exist in the preset device list, determining whether a second interceptor instance matching the second device exists in the interceptor array; if it is determined that a second interceptor instance exists in the interceptor array, deleting the second interceptor instance.
[0049] Understandably, if the preset device list changes, the configuration changes in the interceptor array can be dynamically adjusted based on these changes. Specifically:
[0050] 1) Periodically iterate through the device list: Based on a preset time period, such as every morning, every hour on the hour, or every time the app starts, iterate through the preset device list once. By comparing the results of two iterations, i.e., the current iteration (first iteration result) and the previous iteration (second iteration result), changes in the device list can be identified.
[0051] 2) Identify removed devices: Compare the results of the first and second traversals to identify whether any devices have been removed from the list. For example, if a washing machine (the second device) existed in the previous traversal but no longer exists in the current traversal, then mark the washing machine as a removed device.
[0052] 3) Check and delete interceptor instances: For identified removed devices, check if there is still an interceptor instance matching that device in the interceptor array of the device management class. If so, such as a WashProgramStartInterceptor instance associated with a specific washing machine, these instances will be deleted to maintain consistency between the interceptor array and the device list.
[0053] Optionally, step S206 above, which involves invoking the target interceptor instance and instructing the target interceptor instance to add the patch logic to the target device based on the execution result, so that the target device executes the patch logic, includes:
[0054] (1) If the execution result is an execution failure, the target interceptor instance is invoked and the target interceptor instance is instructed to generate the failure information corresponding to the execution result; the failure information is displayed on the display screen corresponding to the target device.
[0055] In other words, when a device's control command fails to execute, the target interceptor instance associated with the device can be invoked, instructing it to generate detailed failure information based on the specific reason for the failure. This failure information is then displayed on the target device's user interface, typically on the device details page or status panel, so that the target device understands the specific reason for the failure.
[0056] (2) If the execution result is successful, the target interceptor instance is invoked and the target interceptor instance is instructed to execute the post-processing task corresponding to the target device. The post-processing task includes at least one of the following: a real-time interaction task between the target object and the target device, a task to update the device status of the target device, and a task to display the execution progress of the target device in executing the control command.
[0057] In other words, if the device's control commands are executed successfully, the target interceptor instance is invoked to perform a series of post-processing tasks based on the target interceptor instance. These tasks must cover at least one of the following three categories:
[0058] Real-time interaction between the target device and other system components (such as cloud platforms or mobile applications), such as the activation of real-time activities or data synchronization.
[0059] Update the target device's status information to ensure that the information displayed on the user application is up-to-date, such as the device's power status, operating mode, or error codes.
[0060] Display the process of the target device executing control commands, such as showing the remaining time of a washing machine's washing program or the heating progress of an oven.
[0061] Optionally, step S202 above, which determines whether there is a target interceptor instance in the interceptor array that matches the target device based on a preset matching rule, includes: determining the target device type corresponding to the target device when the preset matching rule is used to indicate the correspondence between device type and interceptor instance; and determining whether there is a target interceptor instance in the interceptor array corresponding to a device of the target device type.
[0062] Understandably, preset matching rules can be used to confirm the association between device types and specific interceptor instances. Based on the type of each device, it is determined whether a matching interceptor instance exists in the interceptor array. That is, the preset matching rules can contain a mapping table between device types and interceptor instances; for example, a washing machine corresponds to a WashProgramStartInterceptor instance, and an air conditioner corresponds to an ACPowerStateInterceptor instance, etc.
[0063] To better understand the execution process of the above patch logic, the flow of the above patch logic execution method will be described below in conjunction with optional embodiments, but this is not intended to limit the technical solution of the embodiments of this application.
[0064] In related technologies, the extension of device management logic mainly takes the following forms: 1) Hard-coded mode: In the core code of the device management class, the differentiated logic of specific devices is directly embedded through conditional statements (if-else) or selection statements (switch-case). When new functions need to be added, the core code must be modified directly; 2) Inheritance extension mode: Differentiated functions are implemented by subclassing device objects (e.g., creating a washing machine-specific UpDevice subclass). Each special device corresponds to a subclass; 3) Notification center mode: A global event broadcast mechanism is used to send a notification after the device executes a command. The business side listens for the notification to perform subsequent operations. However, the above methods have the following problems: In the hard-coded mode, directly modifying the core code leads to high code coupling, which can easily cause chain errors during function iteration and greatly increase maintenance costs; In the inheritance extension mode, each special device corresponds to a subclass. As the number of device types increases, the number of classes will explode, the code structure will be bloated, and reusability will be poor; The notification center mode uses global event broadcasting, which will cause unnecessary performance loss, and the event handling logic is scattered, making it difficult to track and debug.
[0065] Furthermore, when adding callback methods to the device management class, the following technical problems exist: it is not easy to add patch logic into complex logic, and it may affect the original logic; it is difficult to isolate business that is not related to device management; special handling of specific devices (e.g., washing machines) in general logic will lead to messy code and high maintenance difficulty; code that is not related to the business of the device management class (e.g., code that sends the command to start real-time activities) is embedded in it, which destroys the logic of the code.
[0066] Based on the above problems, this application provides an optional embodiment that defines a method for adding callback listeners to existing device management logic. The aim is to leverage an interceptor mechanism to easily add patch logic without modifying the original core code, isolating business logic unrelated to device management, reducing maintenance costs, and improving code scalability and stability. Specifically:
[0067] Figure 3 This is a schematic diagram of the interception and callback processing method for device command execution according to an optional embodiment of this application, such as... Figure 3 As shown:
[0068] The optional embodiments of this application involve methods for intercepting and handling the execution of protocol and device commands, including:
[0069] Assume the device management class is named UpDeviceManager (Device Manager);
[0070] Add an array of interceptors to it: commandInterceptors, where the elements of the array are objects that implement the UpDeviceCommandInterceptor protocol.
[0071] Add a method to it: +addCommandIntercepter(UpDeviceCommandIntercepterintercepter) (add command interceptor method), which is used to add objects that implement the UpDeviceCommandIntercepter protocol;
[0072] Each device object is named: UpDevice(device object, i.e., the target device);
[0073] Add an interceptor array to it: -commandInterceptors: NSArray (an array of command interceptors inside the device object), where the elements of the array are objects that implement the UpDeviceCommandInterceptor protocol;
[0074] Add a method to it: +addCommandInterceptor(...) (the method to add a command interceptor to the device object, i.e., the first method declaration), to add objects that match this device and implement the UpDeviceCommandInterceptor protocol.
[0075] Device objects also have other methods of their own, such as:
[0076] +executeCommand(UpDeviceCommand command) (Execute device command method);
[0077] Create a protocol class: UpDeviceCommandInterceptor (Device Command Interceptor Protocol);
[0078] Includes a method to determine if a device meets the criteria: +isMatch(UpDevice device): BOOL (method to determine if a device matches, i.e., the second method declaration) (must be implemented);
[0079] It contains several callback methods (i.e., third-party method declarations), for example:
[0080] +beforeCommandExecution(UpDevice device, UpDeviceCommand command) (Callback method before command execution) (Optional method);
[0081] +onCommandSuccess(UpDevice device, UpDeviceCommand command) (Callback method after command success) (Optional method);
[0082] +onCommandFaliure(UpDevice device, UpDeviceCommand command) (Callback method after command failure) (Optional method);
[0083] For example, you can create an implementation class of the protocol class UpDeviceCommandInterceptor, such as WashProgramStartInterceptor (the washing machine program startup interceptor class).
[0084] Includes a method to determine if a device meets the criteria: +isMatch(UpDevice device): BOOL (Required);
[0085] Includes a callback method, such as: +onCommandSuccess(UpDevice device, UpDeviceCommand command) (optional method).
[0086] Figure 4 This is a timing diagram for adding an interceptor according to an optional embodiment of this application, such as... Figure 4 As shown:
[0087] Taking the washing machine program startup interceptor class as an example, the device program's main entry point initializes the interceptor and sends a method to obtain the device manager to the device injection module; the device injection module returns a device manager instance to the application's main entry point; then the application's main entry point sends an add interceptor command to the device manager, so that the device manager adds the interceptor to the interceptor collection, and the device manager can iterate through the interceptors in the interceptor array and add matching interceptors for the device object.
[0088] When the device list (i.e. the default device list) of a device object changes, you can iterate through the device list of the device object, create a new device object, and then add a matching interceptor to the new device object.
[0089] Furthermore, interceptors can be iterated through. The device manager sends a device matching judgment method to the washing machine program startup interceptor class to determine whether the device object is a washing machine device (e.g., category 4 / 5 / 31 is the washing machine device class). The interceptor can return a yes or no answer to the device manager. If it is determined to be a washing machine device, the washing machine program startup interceptor class is determined to match the device object. At this time, the device manager can add a command interceptor to the device object, and then the device object adds the command interceptor to the interceptor collection.
[0090] Once the device list is ready or changes, the above process steps need to be repeated to add matching interceptors to the devices.
[0091] Figure 5 This is a timing diagram of the interceptor usage according to an optional embodiment of this application, such as... Figure 5 As shown:
[0092] 1) Taking the real-time activity triggered after the washing machine starts the program as an example: Create a WashProgramStartIntercepter class, implement the isMatch method, and determine whether the device is a washing machine (e.g., the major category is 4 / 5 / 31).
[0093] 2) Implement the onCommandSuccess method, in which the real-time activity module is notified to start the real-time activity.
[0094] 3) When the app starts, the WashProgramStartInterceptor is added through UpDeviceManager. This interceptor will be added to all matching washing machine device objects.
[0095] 4) When the washing machine issues a start command and executes it successfully, UpDevice will call the onCommandSuccess method of WashProgramStartInterceptor, thereby triggering the start of the real-time activity.
[0096] In other words, the device card / details page sends device commands (e.g., start the program) to the device plugin, the device plugin calls the execute command method to execute the device command, and then the device object executes the command logic.
[0097] There are two scenarios. If the command executes successfully, the interceptors are iterated through, and the command success callback method is called. The interceptor triggers the callback, passing device and command information, allowing the business logic to execute, such as initiating an activity (e.g., displaying remaining laundry time). If the command fails, the interceptors are iterated through, and the command success callback method is called. The interceptor triggers the callback, passing device and command information, allowing the business logic to execute, such as displaying an error message. Furthermore, the device object returns the command execution result to the device plugin so that the device card / details page displays the processing result.
[0098] In summary, the optional embodiments of this application can construct an interceptor protocol, define device matching rules and callback methods, and decouple business logic from device management logic. The device management class (UpDeviceManager) and device objects (UpDevice) manage interceptors through an interceptor array, supporting dynamic loading and matching. The interceptor implementation class customizes matching rules and callback logic according to business needs, achieving non-intrusive functional expansion. The mechanism of triggering callbacks based on command execution results ensures that the business side executes relevant logic only after the operation on a specific device is completed. In other words, the optional embodiments of this application, through the interceptor mechanism, can add new functions without modifying the core code of the device management class, reducing code coupling and maintenance costs during feature iteration. Dynamic matching of interceptors and devices ensures that business logic only applies to the target device, avoiding interference with other devices and improving code scalability. Simultaneously, business-irrelevant code is isolated through interceptors, ensuring the purity of the device management class and facilitating code debugging and functional reuse.
[0099] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of this application.
[0100] Figure 6 This is a structural block diagram of a patch logic execution device according to an embodiment of this application; as shown below. Figure 6 As shown, it includes:
[0101] The first determining module 62 is used to determine, based on a preset matching rule, whether there is a target interceptor instance in the interceptor array that matches the target device when the target device receives a control command. The interceptor array includes multiple interceptor instances, and the target interceptor instance encapsulates a script for executing the patching logic of the target device.
[0102] The second determining module 64 is used to determine the execution result of the target device executing the control command when it is determined that the target interceptor instance exists in the interceptor array;
[0103] Module 66 is invoked to invoke the target interceptor instance and instruct the target interceptor instance to add the patch logic to the target device based on the execution result, so that the target device executes the patch logic.
[0104] Using the aforementioned apparatus, when it is determined that the target device has received a control command, the system determines, based on preset matching rules, whether there exists a target interceptor instance in an interceptor array containing a script encapsulated with patching logic for executing the target device that matches the target device. If a target interceptor instance is found in the interceptor array, the system determines the execution result of the control command executed by the target device. The system then invokes the target interceptor instance and instructs it to add patching logic to the target device based on the execution result, thereby enabling the target device to execute the patching logic. In other words, this application, when the target device receives a control command, determines whether a target interceptor array matching the target device exists in the interceptor array. If such an array exists, patching logic can be added to the target device through the target interceptor array. This allows the target interceptor instance to add and execute patching logic based on the execution result of the control command executed by the target device without affecting the original logic of the target device executing the control command. This application solves the problem in related technologies where, when adding callback methods to a device management class, patching logic cannot be added without affecting the original business logic. Therefore, it allows patching logic to be added to the target device without affecting the original business logic.
[0105] In an exemplary embodiment, the first determining module 62 is further configured to traverse a preset device list based on a preset time period to determine whether a first device exists in the preset device list, wherein the preset device list includes: the target device, and the first device is a device newly added to the preset device list in the last time period before the current time; if it is determined that the first device exists in the preset device list, a preset interceptor protocol is invoked, and a first interceptor instance corresponding to the first device is generated based on the preset interceptor protocol and the first device; and the first interceptor instance is added to the interceptor array.
[0106] In an exemplary embodiment, the first determining module 62 is further configured to create an interceptor object corresponding to the first device based on a first method declaration in the preset interceptor protocol, wherein the first method declaration is configured to declare a method for creating the interceptor object that matches the first device and the preset interceptor protocol; and to modify the interceptor object based on a second method declaration and a third method declaration of the preset interceptor protocol to generate the first interceptor instance, wherein the second method declaration is configured to declare a method for matching the first device with the interceptor object, and the third method declaration is configured to declare at least one of the following: a first callback method of the first device before executing the first control command, a second callback method of the first device after successfully executing the first control command, and a third callback method of the first device after failing to execute the first control command.
[0107] In an exemplary embodiment, the first determining module 62 is further configured to traverse a preset device list based on a preset time period, and compare a first traversal result obtained by traversing the preset device list at the current time with a second traversal result obtained by the last traversal of the preset device list before the current time, wherein the preset device list includes the target device; if it is determined that the second traversal result indicates that a second device exists in the preset device list, and the first traversal result indicates that the second device does not exist in the preset device list, determine whether there is a second interceptor instance in the interceptor array that matches the second device; if it is determined that there is a second interceptor instance in the interceptor array, delete the second interceptor instance.
[0108] In an exemplary embodiment, the calling module 66 is further configured to, in the event that the execution result is an execution failure, call the target interceptor instance and instruct the target interceptor instance to generate failure information corresponding to the execution result; and display the failure information on the display screen corresponding to the target device.
[0109] In an exemplary embodiment, the calling module 66 is further configured to, if the execution result is successful, call the target interceptor instance and instruct the target interceptor instance to execute the post-processing task corresponding to the target device, wherein the post-processing task includes at least one of the following: a real-time interaction task between the target object and the target device, a task to update the device status of the target device, and a task to display the execution progress of the target device in executing the control command.
[0110] In an exemplary embodiment, the first determining module 62 is further configured to determine the target device type corresponding to the target device when the preset matching rule is used to indicate the correspondence between device type and interceptor instance; and to determine whether there is a target interceptor instance corresponding to the target device type in the interceptor array.
[0111] Embodiments of this application also provide a storage medium including a stored program, wherein the program executes any of the methods described above when it is run.
[0112] Optionally, in this embodiment, the storage medium may be configured to store program code for performing the following steps:
[0113] S1, when it is determined that the target device has received a control command, determine whether there is a target interceptor instance in the interceptor array that matches the target device based on a preset matching rule, wherein the interceptor array includes: multiple interceptor instances, and the target interceptor instance encapsulates a script for executing the patch logic of the target device;
[0114] S2, if it is determined that the target interceptor instance exists in the interceptor array, determine the execution result of the control command executed by the target device;
[0115] S3, invoke the target interceptor instance and instruct the target interceptor instance to add the patch logic to the target device based on the execution result, so that the target device executes the patch logic.
[0116] Embodiments of this application also provide an electronic device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above method embodiments.
[0117] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.
[0118] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:
[0119] S1, when it is determined that the target device has received a control command, determine whether there is a target interceptor instance in the interceptor array that matches the target device based on a preset matching rule, wherein the interceptor array includes: multiple interceptor instances, and the target interceptor instance encapsulates a script for executing the patch logic of the target device;
[0120] S2, if it is determined that the target interceptor instance exists in the interceptor array, determine the execution result of the control command executed by the target device;
[0121] S3, invoke the target interceptor instance and instruct the target interceptor instance to add the patch logic to the target device based on the execution result, so that the target device executes the patch logic.
[0122] Embodiments of this application also provide a computer program product, including a computer program that is executed by a processor through the steps of any of the above method embodiments.
[0123] Optionally, in this embodiment, the above-mentioned computer program product can be executed by a processor using the following steps:
[0124] S1, when it is determined that the target device has received a control command, determine whether there is a target interceptor instance in the interceptor array that matches the target device based on a preset matching rule, wherein the interceptor array includes: multiple interceptor instances, and the target interceptor instance encapsulates a script for executing the patch logic of the target device;
[0125] S2, if it is determined that the target interceptor instance exists in the interceptor array, determine the execution result of the control command executed by the target device;
[0126] S3, invoke the target interceptor instance and instruct the target interceptor instance to add the patch logic to the target device based on the execution result, so that the target device executes the patch logic.
[0127] Optionally, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0128] Optionally, specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementations, and will not be repeated here.
[0129] Obviously, those skilled in the art should understand that the modules or steps of this application described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. Optionally, they can be implemented using computer-executable program code, thereby storing them in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those presented here, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, this application is not limited to any particular combination of hardware and software.
[0130] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A method for executing patch logic, characterized in that, include: If it is determined that the target device has received a control command, the system determines whether there is a target interceptor instance in the interceptor array that matches the target device based on a preset matching rule. The interceptor array includes multiple interceptor instances, and the target interceptor instance encapsulates a script for executing the patching logic of the target device. If it is determined that the target interceptor instance exists in the interceptor array, the execution result of the control command executed by the target device is determined; The target interceptor instance is invoked, and the target interceptor instance is instructed to add the patch logic to the target device based on the execution result, so that the target device executes the patch logic.
2. The method for executing patch logic according to claim 1, characterized in that, Before determining whether a target interceptor instance matching the target device exists in the interceptor array based on preset matching rules, the method includes: A preset device list is traversed based on a preset time period to determine whether a first device exists in the preset device list. The preset device list includes the target device, and the first device is a device that was newly added to the preset device list in the last time period before the current time. If the first device is found in the preset device list, the preset interceptor protocol is invoked, and a first interceptor instance corresponding to the first device is generated based on the preset interceptor protocol and the first device. Add the first interceptor instance to the interceptor array.
3. The method for executing patch logic according to claim 2, characterized in that, Based on the preset interceptor protocol and the first device, a first interceptor instance corresponding to the first device is generated, including: An interceptor object corresponding to the first device is created based on a first method declaration in the preset interceptor protocol, wherein the first method declaration is used to declare a method for creating the interceptor object that matches the first device and the preset interceptor protocol; The interceptor object is modified based on the second method declaration and the third method declaration of the preset interceptor protocol to generate the first interceptor instance. The second method declaration is used to declare a method for matching the first device with the interceptor object, and the third method declaration is used to declare at least one of the following: a first callback method of the first device before executing the first control command, a second callback method of the first device after successfully executing the first control command, and a third callback method of the first device after failing to execute the first control command.
4. The method for executing patch logic according to claim 1, characterized in that, Before determining whether a target interceptor instance matching the target device exists in the interceptor array based on preset matching rules, the method includes: A preset device list is traversed based on a preset time period, and the first traversal result obtained by traversing the preset device list at the current time is compared with the second traversal result obtained by the last traversal of the preset device list before the current time. The preset device list includes the target device. If it is determined that the second traversal result indicates that the second device exists in the preset device list, and the first traversal result indicates that the second device does not exist in the preset device list, then it is determined whether there is a second interceptor instance in the interceptor array that matches the second device. If it is determined that the second interceptor instance exists in the interceptor array, the second interceptor instance is deleted.
5. The method for executing patch logic according to claim 1, characterized in that, Invoking the target interceptor instance and instructing the target interceptor instance to add the patch logic to the target device based on the execution result, so that the target device executes the patch logic, includes: If the execution result is an execution failure, the target interceptor instance is invoked, and the target interceptor instance is instructed to generate failure information corresponding to the execution result; The failure information is displayed on the screen corresponding to the target device.
6. The method for executing patch logic according to claim 1, characterized in that, Invoking the target interceptor instance and instructing the target interceptor instance to add the patch logic to the target device based on the execution result, so that the target device executes the patch logic, includes: If the execution result is successful, the target interceptor instance is invoked and instructed to execute the post-processing task corresponding to the target device. The post-processing task includes at least one of the following: a real-time interaction task between the target object and the target device, a task to update the device status of the target device, and a task to display the execution progress of the target device in executing the control command.
7. The method for executing patch logic according to claim 1, characterized in that, Determining whether a target interceptor instance matching the target device exists in the interceptor array based on preset matching rules includes: When the preset matching rule is used to indicate the correspondence between device types and interceptor instances, the target device type corresponding to the target device is determined; Determine whether there exists a target interceptor instance corresponding to a device of the target device type in the interceptor array.
8. An execution device for patch logic, characterized in that, include: The first determining module is used to determine, based on a preset matching rule, whether there is a target interceptor instance in the interceptor array that matches the target device when the target device receives a control command. The interceptor array includes multiple interceptor instances, and the target interceptor instance encapsulates a script for executing the patching logic of the target device. The second determining module is used to determine the execution result of the control command executed by the target device when it is determined that the target interceptor instance exists in the interceptor array; The module is used to invoke the target interceptor instance and instruct the target interceptor instance to add the patch logic to the target device based on the execution result, so that the target device executes the patch logic.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein the program, when executed, performs the method described in any one of claims 1 to 7.
10. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to execute the method described in any one of claims 1 to 7 through the computer program.