Target component notification method and device, storage medium and electronic device
By constructing a two-dimensional array and using a two-way linked list header array to cache target component information, the problem of the terminal device notifying all target components at the same time when the target event occurs is solved, and the effect of the target components being notified in a preset order is achieved.
Patent Information
- Application Number
- CN202411853571.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-16
- Publication Date
- 2025-05-06
- Estimated Expiration
- 2044-12-16
AI Technical Summary
In the prior art, when a target event occurs, the terminal device simultaneously sends a notification to all target components that execute the above target event, resulting in confusion in execution of all target components.
By constructing a two-dimensional array to represent the relationship between the target event and the target component, the bidirectional linked list header array caches the information of the target component, and when the target event occurs, the notification order of the target component is determined from the linked list according to the preset execution order, and the target component is notified one by one.
Ensure that the target components are notified in a preset order, avoiding execution confusion caused by the terminal device sending notifications simultaneously.
Smart Images

Figure CN119938352A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of smart home technology, and more specifically, to a notification method, device, storage medium and electronic device for a target component. Background Art
[0002] In the related art, when a target event occurs, the existing event notification mechanism simultaneously sends the event information of the target event to all target components registered as listeners of the target event, and cannot ensure that the target components are notified in a preset execution order.
[0003] Therefore, in the related art, when a target event occurs, the terminal device simultaneously sends notifications to all target components that execute the target event, resulting in confusion in the execution of all the target components. No effective solution has yet been proposed. Summary of the invention
[0004] The embodiments of the present application provide a notification method, device, storage medium and electronic device for a target component, so as to at least solve the problem in the related art that when a target event occurs, the terminal device simultaneously sends notifications to all target components executing the above target event, resulting in confusion in the execution of all the above target components.
[0005] According to an embodiment of the present application, a method for notifying a target component is provided, comprising: constructing a two-dimensional array according to N target events and M target components that execute the N target events, wherein the rows of the two-dimensional array correspond one-to-one to the N target events, the elements on all columns of the two-dimensional array correspond to the M target components, all target components corresponding to the i-th row are components required to execute the target event corresponding to the i-th row, the column numbers of all target components are the execution order in which all target components are notified when executing the target event corresponding to the i-th row, M and N are both positive integers, i is a positive integer ranging from 1, ..., N; for the target event corresponding to the i-th row, the target events corresponding to the i-th row are initialized in sequence A doubly linked list header array, according to the execution order of all the target components and the target event corresponding to the i-th row, inserting the linked list nodes created for all the target components into the doubly linked list header array, wherein the doubly linked list header arrays are N, and each of the N doubly linked list header arrays caches a target event corresponding to each doubly linked list header array and component information of all the target components that execute the one target event; when the target event corresponding to the i-th row occurs, the execution order of all the target components corresponding to the target event corresponding to the i-th row is determined from the doubly linked list header array according to the event name of the target event corresponding to the i-th row, and all the target components are notified according to the execution order.
[0006] In an exemplary embodiment, according to the execution order of all the target components and the target event corresponding to the i-th row, the linked list nodes created for the all the target components are inserted into the bidirectional linked list header array, including: determining the bidirectional linked list header array corresponding to the target event corresponding to the i-th row from N bidirectional linked list header arrays according to the event name of the target event corresponding to the i-th row; creating the linked list nodes for the all the target components; and inserting the linked list nodes into the bidirectional linked list header array corresponding to the target event corresponding to the i-th row according to the execution order.
[0007] In an exemplary embodiment, notifying all the target components according to the execution order includes: traversing the doubly linked list header array to determine whether all the target components in the doubly linked list header array are in an active state; when it is determined that all the target components are in an active state, obtaining callback functions of all the target components, and calling the callback functions corresponding to all the target components in sequence according to the execution order to notify all the target components.
[0008] In an exemplary embodiment, notifying all the target components according to the execution order includes: setting a response time for all the target components; in the case where no asynchronous response is received from all the target components, determining the first target component that feeds back an asynchronous response within the response time, and determining the component with the largest column number in the first target components as the second target component; determining the third target component according to the second target component and the execution order, and notifying the third target component again to instruct the third target component to execute the target event corresponding to the i-th row, wherein the column number of the third target component is greater than that of the second target component, and the third target component and the second target component are adjacent, and the asynchronous response is used to inform the terminal device that the first target component has completed the execution of the target event corresponding to the i-th row in sequence.
[0009] In an exemplary embodiment, after notifying the third target component again, the method further includes: if an asynchronous response fed back by the third target component is still not received within the response time, stopping notifying the third target component, and notifying the fourth target component according to the execution order, wherein the column number of the fourth target component is greater than the column number of the third target component, and the fourth target component and the third target component are adjacent.
[0010] In an exemplary embodiment, in the process of notifying all target components according to the execution order, the method also includes: obtaining the event type and event parameters of the target event corresponding to the i-th row; passing the event type and the event parameters to all target components through callback functions corresponding to all target components; upon receiving an asynchronous response fed back by all target components that completes the execution of the target event corresponding to the i-th row according to the event type and the event parameters, marking the target event corresponding to the i-th row as completed, wherein the asynchronous response is used to inform the terminal device that the target event corresponding to the i-th row has been executed.
[0011] In an exemplary embodiment, in the process of notifying all the target components according to the execution order, the method further includes: in a case where there is a fifth target component among all the target components that is executing other events, determining whether the other events have been executed, wherein the other events refer to events in the to-be-executed events of the fifth target component other than the target event corresponding to the i-th row; and instructing the fifth target component to start executing the target event corresponding to the i-th row when it is determined that the other events have been executed.
[0012] According to another embodiment of the embodiment of the present application, a notification device for a target component is also provided, including: a construction module, used to construct a two-dimensional array according to N target events and M target components that execute the N target events, wherein the rows of the two-dimensional array correspond one-to-one to the N target events, respectively, the elements on all columns of the two-dimensional array correspond to the M target components, respectively, all target components corresponding to the i-th row are components required to execute the target event corresponding to the i-th row, the column numbers of all target components are the execution order in which all target components are notified when executing the target event corresponding to the i-th row, M and N are both positive integers, and i is a positive integer ranging from 1, ..., N; an initialization module, used to initialize the target event corresponding to the i-th row for the target event corresponding to the i-th row; Initialize a doubly linked list header array in sequence, and insert the linked list nodes created for all the target components into the doubly linked list header array according to the execution order of all the target components and the target event corresponding to the i-th row, wherein there are N doubly linked list header arrays, and each of the N doubly linked list header arrays caches a target event corresponding to each doubly linked list header array and component information of all the target components that execute the one target event; a notification module is used to determine, when the target event corresponding to the i-th row occurs, the execution order of all the target components corresponding to the target event corresponding to the i-th row from the doubly linked list header array according to the event name of the target event corresponding to the i-th row, and notify all the target components according to the execution order.
[0013] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the notification method of the target component when running.
[0014] According to another aspect of an embodiment of the present application, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the notification method of the target component through the computer program.
[0015] According to another embodiment of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0016] In an embodiment of the present application, a two-dimensional array is constructed according to N target events and M target components that execute the N target events, wherein the rows of the two-dimensional array correspond to the N target events one by one, and the elements on all columns of the two-dimensional array correspond to the M target components, respectively, and the column number is used to indicate the execution order of the target component executing the target event corresponding to the i-th row. In addition, a bidirectional linked list header array is initialized for the target event corresponding to the i-th row in sequence, which is used to cache the target event corresponding to the i-th row and the component information of all target components that execute the target event corresponding to the i-th row. When the target event corresponding to the i-th row occurs, the execution order of all the above target components is determined from the bidirectional linked list header array according to the event name of the target event corresponding to the i-th row, thereby ensuring that all the above target components are notified in the order preset in the two-dimensional array. The above technical solution solves the problem that when the target event occurs, the terminal device sends notifications to all the target components that execute the above target event at the same time, resulting in confusion in the execution of all the above target components. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0018] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0019] Figure 1 It is a hardware environment diagram of a notification method of a target component in an embodiment of the present application;
[0020] Figure 2 is a flowchart of a notification method of a target component according to an embodiment of the present application;
[0021] Figure 3 is a logic flow chart of a notification method of a target component according to an embodiment of the present application;
[0022] Figure 4 is a sequential maintenance diagram of a notification method of a target component according to an embodiment of the present application;
[0023] Figure 5 is a memory management diagram of a notification method of a target component according to an embodiment of the present application;
[0024] Figure 6 is a registration flow chart of a notification method for a target component according to an embodiment of the present application;
[0025] Figure 7 is a notification flow chart of a notification method of a target component according to an embodiment of the present application;
[0026] Figure 8 It is a structural block diagram of a notification device for a target component according to an embodiment of the present application. DETAILED DESCRIPTION
[0027] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work 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 and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] According to one aspect of an embodiment of the present application, a method for notifying a target component is provided. The method for notifying a target component is widely used in smart home (SmartHome), smart home, smart home device ecology, smart home (IntelligenceHouse) ecology and other whole-house intelligent digital control application scenarios. Optionally, in this embodiment, the method for notifying a target component can be applied to Figure 1 In the hardware environment composed of the terminal device 102 and the server 104 shown in FIG. Figure 1 As shown, the server 104 is connected to the terminal device 102 via a network, and can be used to provide services (such as application services, etc.) for the terminal or a client installed on the terminal. A database can be set on the server or independently of the server to provide data storage services for the server 104. Cloud computing and / or edge computing services can be configured on the server or independently of the server to provide data computing services for the server 104.
[0030] The network may include but is not limited to at least one of the following: wired network, wireless network. The wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal device 102 may be but is not limited to a PC, a mobile phone, a tablet computer, a smart air conditioner, a smart range hood, a smart refrigerator, a smart oven, a smart stove, a smart washing machine, a smart water heater, a smart washing device, a smart dishwasher, a smart projection device, a smart TV, a smart clothes drying rack, a smart curtain, a smart audio and video, a smart socket, a smart speaker, a smart speaker, a smart fresh air device, a smart kitchen and bathroom device, a smart bathroom device, a smart sweeping robot, a smart window cleaning robot, a smart mopping robot, a smart air purification device, a smart steamer, a smart microwave oven, a smart kitchen treasure, a smart purifier, a smart water dispenser, a smart door lock, etc.
[0031] In this embodiment, a notification method for a target component is provided, which is applied to the above terminal device. Figure 2 : is a flowchart of a notification method for a target component according to an embodiment of the present application, and the process includes the following steps:
[0032] Step S202, constructing a two-dimensional array according to N target events and M target components that execute the N target events, wherein the rows of the two-dimensional array correspond to the N target events one by one, the elements on all columns of the two-dimensional array correspond to the M target components, all target components corresponding to the i-th row are components required to execute the target event corresponding to the i-th row, the column numbers of all target components are the execution order in which all target components are notified when executing the target event corresponding to the i-th row, M and N are both positive integers, and i is a positive integer ranging from 1, ..., N;
[0033] Step S204: for the target event corresponding to the i-th row, initialize the doubly linked list header array for the target event corresponding to the i-th row in sequence, and insert the linked list nodes created for all the target components into the doubly linked list header array according to the execution order of all the target components and the target event corresponding to the i-th row, wherein the doubly linked list header array is N, and each of the N doubly linked list header arrays caches a target event corresponding to each doubly linked list header array and component information of all the target components that execute the one target event;
[0034] Step S206, when the target event corresponding to the i-th row occurs, determine the execution order of all target components corresponding to the target event corresponding to the i-th row from the bidirectional linked list header array according to the event name of the target event corresponding to the i-th row, and notify all target components according to the execution order.
[0035] Through the above steps, a two-dimensional array is constructed according to N target events and M target components that execute the N target events, wherein the rows of the two-dimensional array correspond to the N target events one by one, and the elements on all columns of the two-dimensional array correspond to the M target components respectively. All target components corresponding to the i-th row are components required to execute the target event corresponding to the i-th row, and the column numbers of all target components are the execution order in which all target components are notified when executing the target event corresponding to the i-th row. M and N are both positive integers, and i is a positive integer ranging from 1, ..., N; for the target event corresponding to the i-th row, a bidirectional linked list header array is initialized in sequence for the target event corresponding to the i-th row, and the target events corresponding to the i-th row are initialized in sequence according to the There are the execution order of the target components and the target events corresponding to the i-th row, and the linked list nodes created for all the target components are inserted into the bidirectional linked list header array, wherein the bidirectional linked list header array is N, and each of the N bidirectional linked list header arrays caches a target event corresponding to each bidirectional linked list header array and the component information of all the target components that execute the one target event; when the target event corresponding to the i-th row occurs, the execution order of all the target components corresponding to the target event corresponding to the i-th row is determined from the bidirectional linked list header array according to the event name of the target event corresponding to the i-th row, and all the target components are notified according to the execution order. The above technical solution solves the problem that when the target event occurs, the terminal device simultaneously sends notifications to all the target components that execute the above target event, resulting in confusion in the execution of all the above target components.
[0036] It should be clear that the notification order of the target components in this embodiment is the execution order of the target components executing the corresponding target events.
[0037] In an exemplary embodiment, according to the execution order of all the target components and the target event corresponding to the i-th row, the linked list nodes created for the all the target components are inserted into the bidirectional linked list header array, including: determining the bidirectional linked list header array corresponding to the target event corresponding to the i-th row from N bidirectional linked list header arrays according to the event name of the target event corresponding to the i-th row; creating the linked list nodes for the all the target components; and inserting the linked list nodes into the bidirectional linked list header array corresponding to the target event corresponding to the i-th row according to the execution order.
[0038] It should be clear that the linked list node corresponding to each target component contains its own component information, forward pointer and backward pointer. Insert the linked list node into the bidirectional linked list header array of the corresponding target event, ensuring that the linked list nodes with smaller column numbers are at the front and the linked list nodes with larger column numbers are at the back, so as to maintain the order of event processing. After all components are inserted, the bidirectional linked list header array of the target event is constructed, where the linked list header points to the first target component that needs to be notified.
[0039] Optionally, assuming that there are N doubly linked list header arrays, according to the event name of the target event, for example: event A, the corresponding doubly linked list header array is determined from the N doubly linked list header arrays, assuming that the corresponding doubly linked list header array is event A, component 1, component 2, component 3, component 4, component 5. Create linked list nodes for the above components 1-component 5, and obtain component node 1, component node 2, component node 3, component node 4, component node 5. Insert all the above linked list nodes into the doubly linked list header array whose linked list head is event A in the execution order, i.e., 1-5.
[0040] In an exemplary embodiment, notifying all the target components according to the execution order includes: traversing the doubly linked list header array to determine whether all the target components in the doubly linked list header array are in an active state; when it is determined that all the target components are in an active state, obtaining callback functions of all the target components, and calling the callback functions corresponding to all the target components in sequence according to the execution order to notify all the target components.
[0041] Traversing the doubly linked list header array means accessing each element in the doubly linked list header array in turn. Each element has a forward pointer pointing to the previous linked list node and a backward pointer pointing to the next linked list node. During the traversal process, it is necessary to check whether the target component represented by each linked list header is in an active state, that is, whether the target component is working normally. When all target components are in an active state, according to the execution order, assuming it is component 1, component 2, component 3, component 4, component 5, the callback function of component 1 is called in turn to notify component 1 to execute the target event; the callback function of component 2 is called to notify component 2 to execute the target event, and so on.
[0042] In an exemplary embodiment, notifying all the target components according to the execution order includes: setting a response time for all the target components; in the case where no asynchronous response is received from all the target components, determining the first target component that feeds back an asynchronous response within the response time, and determining the component with the largest column number in the first target components as the second target component; determining the third target component according to the second target component and the execution order, and notifying the third target component again to instruct the third target component to execute the target event corresponding to the i-th row, wherein the column number of the third target component is greater than that of the second target component, and the third target component and the second target component are adjacent, and the asynchronous response is used to inform the terminal device that the first target component has completed the execution of the target event corresponding to the i-th row in sequence.
[0043] Optionally, a response time is set for all target components, such as 5 seconds. When the target event corresponding to the i-th row occurs, all target components are notified, and all target components are required to feedback within the response time whether they have received the notification and executed the target event corresponding to the i-th row. After the response time is over, only component A and component B feedback asynchronous responses, and these two components are the first target components. Among these two components, the column number of component A is 1, and the column number of component B is 2, so component B is determined as the second target component. The third target component is determined based on the second target component (i.e., component B) and the execution order. Assume that the column number of component C is 3, therefore, component C is the third target component. Notify component C again and instruct it to execute the target event corresponding to the i-th row. After receiving the notification and executing the target event corresponding to the i-th row, component C will send an asynchronous response to inform the terminal device that it has completed the execution of the target event corresponding to the i-th row in sequence.
[0044] In an exemplary embodiment, after notifying the third target component again, the method further includes: if an asynchronous response fed back by the third target component is still not received within the response time, stopping notifying the third target component, and notifying the fourth target component according to the execution order, wherein the column number of the fourth target component is greater than the column number of the third target component, and the fourth target component and the third target component are adjacent.
[0045] Optionally, assume that the third target component is component C, where the column number of component C is 3. If no asynchronous response is received from component C within the response time, a notification is sent to component C again to instruct component C to execute the target event corresponding to the i-th row within the second response time. However, if no asynchronous response is received from component C within the second response time, component D adjacent to component C and having a column number of 4 is determined as the fourth target component, and a notification is sent to component D to instruct component D to execute the target event corresponding to the i-th row within the response time.
[0046] In an exemplary embodiment, in the process of notifying all target components according to the execution order, the method also includes: obtaining the event type and event parameters of the target event corresponding to the i-th row; passing the event type and the event parameters to all target components through callback functions corresponding to all target components; upon receiving an asynchronous response fed back by all target components that completes the execution of the target event corresponding to the i-th row according to the event type and the event parameters, marking the target event corresponding to the i-th row as completed, wherein the asynchronous response is used to inform the terminal device that the target event corresponding to the i-th row has been executed.
[0047] Optionally, assuming that the target event corresponding to the i-th row is "8 pm, dim the living room lights, adjust the air conditioner to 26 degrees, and play soft music", the target components that execute the above target event are the lighting component, the air conditioning component and the music player, and the execution order is the lighting component, the air conditioning component and the music player. According to the target event of the i-th row, the event type is determined to be "automatically adjust the environment at 8 pm", and the event parameters are extracted, namely "dim the lights", "adjust the air conditioner to 26 degrees" and "play soft music". These event parameters are passed to all target components through the callback function corresponding to each target component, where the terminal device will pass the callback function according to the execution order. For example: first pass "dim the lights" to the lighting component; secondly, pass "adjust to 26 degrees" to the air conditioning component; and finally pass "play soft music" to the music player. After receiving the "dim the lights" instruction, the lighting component performs the corresponding operation to dim the lights. After receiving the "adjust to 26 degrees" instruction, the air conditioning component performs the corresponding operation to adjust the temperature to 26 degrees. After receiving the instruction "play soft music", the music player performs the corresponding operation and starts playing soft music. After each target component is executed, it sends an asynchronous response to the terminal device to inform that the operation is completed. After the terminal device receives the asynchronous responses of all target components, it marks the target event corresponding to the i-th row as completed.
[0048] In an exemplary embodiment, in the process of notifying all the target components according to the execution order, the method further includes: in a case where there is a fifth target component among all the target components that is executing other events, determining whether the other events have been executed, wherein the other events refer to events in the to-be-executed events of the fifth target component other than the target event corresponding to the i-th row; and instructing the fifth target component to start executing the target event corresponding to the i-th row when it is determined that the other events have been executed.
[0049] Optionally, assume that in the configuration process, the fifth target component is the security check component of the device, which is responsible for verifying the security of the network environment in the configuration process of the device. In the configuration process of the device, the security check component is notified to execute after other components (such as the Wi-Fi management component) in the execution order. However, if the security check component is performing other events (such as regular security scans) at the beginning of the device configuration process, the security of the network environment will be verified only after the security check component completes the regular security scan.
[0050] In order to better understand the implementation process of the notification method of the above-mentioned target component, the implementation method flow of the notification of the above-mentioned target component is described below in combination with an optional embodiment, but it is not used to limit the technical solution of the embodiment of the present application.
[0051] Figure 3 is a logic flow chart of a notification method of a target component according to an embodiment of the present application; Figure 3 As shown, including:
[0052] In the process of reconfiguring the bound device, the device calls the SMCFG component (i.e., the device component) through the configuration API interface. The SMCFG component passes the configuration event to the diagnostic component. The diagnostic component reports the offline reason of the device to the cloud server and stores the offline reason. When the diagnostic component processes the configuration event, it responds to the SMCFG component. The SMCFG component passes the configuration event to the connection management component. The connection management component responds to the SMCFG component after disconnecting the cloud connection of the device. The SMCFG component passes the configuration event to the WiFi management component. The WiFi management component disconnects the original connection of the device and enters the configuration mode and responds to the SMCFG component. The SMCFG component passes the configuration event to the SoftAP network configuration component. The SoftAP network configuration component starts the SoftAP and sends an instruction to the WiFi management component to start the AP hotspot. The WiFi management component responds to the SoftAP network configuration component after starting the AP hotspot. The SoftAP network configuration component responds to the SMCFG component. The SMCFG component passes the configuration event to the device.
[0053] In order to better understand the implementation process of the notification method of the above target component, it is also necessary to clarify how the execution order of event notification is determined. Figure 4 is a sequential maintenance diagram of a notification method of a target component according to an embodiment of the present application; Figure 4 As shown, including:
[0054] A two-dimensional array named l_a_evt_sequence_table is defined in the event notification sequence maintenance table to manage the timing of event notifications in the configuration device. The above two-dimensional array is defined as volatile type, which means that even in a multi-threaded or multi-tasking environment, the reading and writing of elements in the two-dimensional array will be forced to be synchronized to prevent data competition.
[0055] The size of the two-dimensional array is determined by the two macros E_SMARTCFG_EVENT_MAX and E_SMARTCFG_COMPONENT_MAX, which represent the maximum number of events in the device and the maximum number of components that execute events, respectively. Each row of the two-dimensional array corresponds to an event, and each column represents the components that need to be notified in the order of column numbers when the event occurs.
[0056] The two-dimensional array is initialized as follows:
[0057] The first line: initialized to {0,0}, which usually means that for invalid or basic events, the component does not need to pay attention, so no component notification is performed.
[0058] The second line: defines that when the device enters the configuration mode, the column number of the two-dimensional array corresponds to the order of the components to be notified. The components will receive the notification of entering the configuration mode in sequence according to the value of their column number, starting from the smallest column number. If you need to adjust the notification order of any component in the configuration mode, just change the column number of the component in the two-dimensional array. In this embodiment, the components that need to be notified in sequence are: device discovery and status monitoring component E_SMARTCFG_COMPONENT_DEVDISCOVERY_STP, device cloud service component E_SMARTCFG_COMPONENT_DEVCLOUD, device discovery component E_SMARTCFG_COMPONENT_DEVDISCOVERY, and multi-protocol collaboration component E_SMARTCFG_COMPONENT_MPC.
[0059] The third line: When the device receives wifi configuration information, the order of components that need to be notified is: Bluetooth component E_SMARTCFG_COMPONENT_BLE, smart link component E_SMARTCFG_COMPONENT_SMLINK, and software access point component E_SMARTCFG_COMPONENT_SOFTAP.
[0060] Fourth line: When the configuration stop event is triggered, the components that need to be notified in order are: E_SMARTCFG_COMPONENT_DEVCLOUD, E_SMARTCFG_COMPONENT_DEVDISCOVERY, E_SMARTCFG_COMPONENT_MPC.
[0061] Through this table, the smartcfg component of the device can automatically notify related components in a predetermined order according to different events, thereby ensuring the timing and coordination of event processing between components.
[0062] After clarifying the execution order of event notifications, it is also necessary to determine the memory management method for event sequence notifications. Figure 5 is a memory management diagram of the notification method of the target component according to an embodiment of the present application; Figure 5 As shown, including:
[0063] In order to ensure that the message events are notified to each component in the preset order during the configuration of the smart device, the device will initialize a bidirectional linked list header array, each header corresponds to an event, which is used to create a component notification linked list for executing the above event. The function of this bidirectional linked list header array is to cache all component information that executes the event, which is equivalent to creating a queue of components to be notified for each event.
[0064] When a component receives an asynchronous notification of a target event, the smartcfg component obtains the notification order of the target component corresponding to the target time from the event notification order maintenance table according to the event name of the target event, and determines the position of the component in the bidirectional linked list header array. This event notification order maintenance table is pre-set, where the column number is the order of one or more target components that execute the target event in the target event processing. By comparing, the smartcfg component can insert the target components into the corresponding bidirectional linked list header array in the correct order.
[0065] Once an event occurs, the smartcfg component will start from the header of the doubly linked list header array, and call the asynchronous callback function of the target component in the order of the target components in the doubly linked list header array, and notify the target component of the event information and related parameters. This design makes it unnecessary to judge the order of event notifications again in subsequent business processing. The target component only needs to focus on its own processing logic without worrying about the timing of notifications, which greatly improves the efficiency of business processing.
[0066] In the memory management diagram of event sequence notification, the component n in the doubly linked list header array node indicates that the doubly linked list header array can support any number of components, that is, the length of the doubly linked list header array is dynamic and can change with the increase or decrease of components, providing good scalability. At the same time, event n: linked list header means that events can be elastically expanded, and each event has its own independent component notification doubly linked list header array. This design ensures the flexibility and adaptability of the event notification mechanism.
[0067] Through the above mechanism, whether it is the start of device configuration, configuration information processing or the end of configuration, the smartcfg component can automatically notify the relevant components in the preset order, realize the orderly processing of events between components, and improve the efficiency and reliability of the device configuration process. At the same time, the dynamic management of the bidirectional linked list header array and the flexible expansion of events also enable the device to better adapt to possible future component additions or adjustments, enhancing the adaptability and maintainability of the device.
[0068] Figure 6 is a registration flow chart of a notification method for a target component according to an embodiment of the present application; Figure 6 As shown, the following steps are included:
[0069] Step S602: When the target component executing the target event needs to receive notification of the target event, the target component calls the registration interface provided by the smartcfg component and sends a registration request to the smartcfg component.
[0070] Step S604: after receiving the registration request, the smartcfg component determines the corresponding bidirectional linked list header array according to the event name of the target event. The bidirectional linked list header array is used to maintain the component information of all target components.
[0071] Step S606: Determine in the bidirectional linked list header array whether the component information of the target component has been registered. If the component information of the target component has been registered in the bidirectional linked list header array, it is considered that the target component has been registered in the notification list of the target event and there is no need to register again. Success or registered information is directly returned.
[0072] Step S608: If the component information of the target component is not registered in the bidirectional linked list header array, the smartcfg component determines the corresponding bidirectional linked list header array according to the event name of the target event.
[0073] Step S610: the smartcfg component applies for a section of memory for the target component in the bidirectional linked list header array. The section of memory is used to cache the registration information of the target component, including the ID and callback function of the target component.
[0074] Step S612: According to the event name and the ID of the target component, the index number corresponding to the target component in the notification sequence is retrieved from the event notification sequence maintenance table. This index number determines the insertion position of the target component in the bidirectional linked list header array.
[0075] Step S618: The smartcfg component traverses the doubly linked list header array, determines the insertion position of the target component according to the index number of the acquired notification sequence, and then inserts the registration information of the target component into the correct position. In this way, the order of the target components in the doubly linked list header array is consistent with the order in the event notification sequence maintenance table, ensuring the correct timing of the target event notification.
[0076] Step S620: After the target component is inserted, the return interface is called to notify the device that the registration process of the target component has been completed.
[0077] In order to better understand the implementation process of the notification method of the above-mentioned target component, the specific notification process of the notification method of the above-mentioned target component is described below in combination with an optional embodiment, but it is not used to limit the technical solution of the embodiment of the present application.
[0078] Figure 7 is a notification flow chart of a notification method of a target component according to an embodiment of the present application; Figure 7 As shown, including:
[0079] When the target event occurs, the smartcfg component calls the event notification interface to obtain the linked list head of the corresponding doubly linked list header array according to the event name of the target event, and determines whether the linked list head is empty. If the linked list head is empty, it means that there is no target event. If the linked list head is not empty, obtain the subscription information of the target event, that is, the component information of the target component that subscribes to the target event. Determine whether the subscription information is empty. If it is determined that the subscription information is empty, traverse the component information of all target components that subscribe to the above target event, change the status of the above target component to unnotified, and execute the above target event. After executing the target event, respond to the smartcfg component. After receiving the response, the smartcfg component will update the status of the doubly linked list header array, mark the component of the node has processed the event, and then continue to notify the next component in the doubly linked list header array until all subscribed components receive the notification and complete the processing.
[0080] When it is determined that the subscription information is not empty, determine whether the target component has received the notification of executing the target event. When it is determined that the target component has received the notification of executing the target event, obtain the subscription information of the target event again, that is, the component information of the target component that subscribes to the target event. When it is determined that the target component has not received the notification of executing the target event, change the notification flag to notified, which means that the target component has been notified to execute the above target event. When the target component receives the notification, the target component will temporarily save this information and create asynchronous response callback parameters and timers, wherein the asynchronous response callback parameters include the target event, the asynchronous callback function of the target component, and other component information. After the processing of its own business logic is completed, respond to the smartcfg component through the asynchronous callback function to confirm that the target event has been completed. If the response of the target component does not arrive within the expected time, a timeout callback will be triggered, which is equivalent to giving the target component a deadline to complete the target event. At the same time, the smartcfg component detects whether there are any target components that have not been notified. When it is determined that all target components have responded, it means that the target components have completed the target event in the order of notification. The smartcfg component will jump to the next target event, which means that subsequent operations can be performed.
[0081] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of each embodiment of the present application.
[0082] Figure 8 is a structural block diagram of a notification device for a target component according to an embodiment of the present application; Figure 8 As shown, including:
[0083] A construction module 80 is used to construct a two-dimensional array according to N target events and M target components that execute the N target events, wherein the rows of the two-dimensional array correspond to the N target events one by one, the elements on all columns of the two-dimensional array correspond to the M target components, all target components corresponding to the i-th row are components required to execute the target event corresponding to the i-th row, the column numbers of all target components are the execution order in which all target components are notified when executing the target event corresponding to the i-th row, M and N are both positive integers, and i is a positive integer ranging from 1, ..., N;
[0084] An initialization module 82 is used to initialize the doubly linked list header array for the target event corresponding to the i-th row in sequence, and insert the linked list nodes created for all the target components into the doubly linked list header array according to the execution order of all the target components and the target event corresponding to the i-th row, wherein the doubly linked list header array is N, and each of the N doubly linked list header arrays caches a target event corresponding to each doubly linked list header array and component information of all the target components that execute the one target event;
[0085] The notification module 84 is used to determine the execution order of all target components corresponding to the target event corresponding to the i-th row from the bidirectional linked list header array according to the event name of the target event corresponding to the i-th row when the target event corresponding to the i-th row occurs, and notify all target components according to the execution order.
[0086] Through the above-mentioned device, a two-dimensional array is constructed according to N target events and M target components that execute the N target events, wherein the rows of the two-dimensional array correspond to the N target events one by one, and the elements on all columns of the two-dimensional array correspond to the M target components respectively. All target components corresponding to the i-th row are components required to execute the target event corresponding to the i-th row, and the column numbers of all target components are the execution order in which all target components are notified when executing the target event corresponding to the i-th row, M and N are both positive integers, and i is a positive integer ranging from 1, ..., N; for the target event corresponding to the i-th row, a bidirectional linked list header array is initialized in sequence for the target event corresponding to the i-th row, and according to the There are the execution order of the target components and the target events corresponding to the i-th row, and the linked list nodes created for all the target components are inserted into the bidirectional linked list header array, wherein the bidirectional linked list header array is N, and each of the N bidirectional linked list header arrays caches a target event corresponding to each bidirectional linked list header array and the component information of all the target components that execute the one target event; when the target event corresponding to the i-th row occurs, the execution order of all the target components corresponding to the target event corresponding to the i-th row is determined from the bidirectional linked list header array according to the event name of the target event corresponding to the i-th row, and all the target components are notified according to the execution order. The above technical solution solves the problem that when the target event occurs, the terminal device simultaneously sends notifications to all the target components that execute the above target event, resulting in confusion in the execution of all the above target components.
[0087] In an exemplary embodiment, the initialization module 82 is also used to determine the bidirectional linked list header array corresponding to the target event corresponding to the i-th row from the N bidirectional linked list header arrays according to the event name of the target event corresponding to the i-th row; create the linked list nodes for all the target components; and insert the linked list nodes into the bidirectional linked list header array corresponding to the target event corresponding to the i-th row according to the execution order.
[0088] In an exemplary embodiment, the notification module 84 is also used to traverse the bidirectional linked list header array to determine whether all the target components in the bidirectional linked list header array are in an active state; when it is determined that all the target components are in an active state, the callback functions of all the target components are obtained, and the callback functions corresponding to all the target components are called in sequence according to the execution order to notify all the target components.
[0089] In an exemplary embodiment, the notification module 84 is also used to set a response time for all the target components; in the case where no asynchronous response is received from all the target components, determine the first target component that feeds back an asynchronous response within the response time, and determine the component with the largest column number in the first target components as the second target component; determine the third target component according to the second target component and the execution order, and notify the third target component again to instruct the third target component to execute the target event corresponding to the i-th row, wherein the column number of the third target component is greater than that of the second target component, and the third target component and the second target component are adjacent, and the asynchronous response is used to inform the terminal device that the first target component has completed the execution of the target event corresponding to the i-th row in sequence.
[0090] In an exemplary embodiment, the notification module 84 is also used to stop notifying the third target component if an asynchronous response fed back by the third target component is not received within the response time, and to notify the fourth target component according to the execution order, wherein the column number of the fourth target component is greater than the column number of the third target component, and the fourth target component and the third target component are adjacent.
[0091] In an exemplary embodiment, the notification module 84 is also used to obtain the event type and event parameters of the target event corresponding to the i-th row; pass the event type and the event parameters to all target components through the callback functions corresponding to all target components; and upon receiving the asynchronous response fed back by all target components that complete the execution of the target event corresponding to the i-th row according to the event type and the event parameters, mark the target event corresponding to the i-th row as completed, wherein the asynchronous response is used to inform the terminal device that the target event corresponding to the i-th row has been executed.
[0092] In an exemplary embodiment, the notification module 84 is also used to determine whether the execution of other events is completed when there is a fifth target component among all the target components that is executing other events, wherein the other events refer to events in the to-be-executed events of the fifth target component except the target event corresponding to the i-th row; when it is determined that the other events have been executed, instruct the fifth target component to start executing the target event corresponding to the i-th row.
[0093] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0094] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0095] An embodiment of the present application further provides a storage medium, which includes a stored program, wherein the program executes any of the above methods when it is run.
[0096] Optionally, in this embodiment, the storage medium may be configured to store program codes for executing the following steps:
[0097] S1, construct a two-dimensional array according to N target events and M target components that execute the N target events, wherein the rows of the two-dimensional array correspond to the N target events one by one, the elements on all columns of the two-dimensional array correspond to the M target components, all target components corresponding to the i-th row are components required to execute the target event corresponding to the i-th row, the column numbers of all target components are the execution order in which all target components are notified when executing the target event corresponding to the i-th row, M and N are both positive integers, and i is a positive integer ranging from 1, ..., N;
[0098] S2, for the target event corresponding to the i-th row, initialize the doubly linked list header array for the target event corresponding to the i-th row in sequence, and insert the linked list nodes created for all the target components into the doubly linked list header array according to the execution order of all the target components and the target event corresponding to the i-th row, wherein the doubly linked list header array is N, and each of the N doubly linked list header arrays caches a target event corresponding to each doubly linked list header array and component information of all the target components that execute the one target event;
[0099] S3, when the target event corresponding to the i-th row occurs, determine the execution order of all target components corresponding to the target event corresponding to the i-th row from the bidirectional linked list header array according to the event name of the target event corresponding to the i-th row, and notify all target components according to the execution order.
[0100] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0101] 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.
[0102] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0103] S1, construct a two-dimensional array according to N target events and M target components that execute the N target events, wherein the rows of the two-dimensional array correspond to the N target events one by one, the elements on all columns of the two-dimensional array correspond to the M target components, all target components corresponding to the i-th row are components required to execute the target event corresponding to the i-th row, the column numbers of all target components are the execution order in which all target components are notified when executing the target event corresponding to the i-th row, M and N are both positive integers, and i is a positive integer ranging from 1, ..., N;
[0104] S2, for the target event corresponding to the i-th row, initialize the doubly linked list header array for the target event corresponding to the i-th row in sequence, and insert the linked list nodes created for all the target components into the doubly linked list header array according to the execution order of all the target components and the target event corresponding to the i-th row, wherein the doubly linked list header array is N, and each of the N doubly linked list header arrays caches a target event corresponding to each doubly linked list header array and component information of all the target components that execute the one target event;
[0105] S3, when the target event corresponding to the i-th row occurs, determine the execution order of all target components corresponding to the target event corresponding to the i-th row from the bidirectional linked list header array according to the event name of the target event corresponding to the i-th row, and notify all target components according to the execution order.
[0106] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.
[0107] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0108] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any one of the above method embodiments are implemented.
[0109] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0110] The embodiments of the present application also provide a computer program, which includes computer instructions stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps of any one of the above method embodiments.
[0111] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0112] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A notification method for a target component, characterized in that: include: A two-dimensional array is constructed according to N target events and M target components that execute the N target events, wherein the rows of the two-dimensional array correspond to the N target events one by one, the elements on all columns of the two-dimensional array correspond to the M target components, all target components corresponding to the i-th row are components required to execute the target event corresponding to the i-th row, the column numbers of all target components are the execution order in which all target components are notified when executing the target event corresponding to the i-th row, M and N are both positive integers, and i is a positive integer ranging from 1, ..., N; For the target event corresponding to the i-th row, initialize the doubly linked list header array for the target event corresponding to the i-th row in sequence, and insert the linked list nodes created for all the target components into the doubly linked list header array according to the execution order of all the target components and the target event corresponding to the i-th row, wherein the doubly linked list header array is N, and each of the N doubly linked list header arrays caches a target event corresponding to each doubly linked list header array and component information of all the target components that execute the one target event; When the target event corresponding to the i-th row occurs, the execution order of all the target components corresponding to the target event corresponding to the i-th row is determined from the bidirectional linked list header array according to the event name of the target event corresponding to the i-th row, and all the target components are notified according to the execution order.
2. The target component notification method according to claim 1, characterized in that: Inserting the linked list nodes created for all the target components into the bidirectional linked list header array according to the execution order of all the target components and the target event corresponding to the i-th row, including: Determine the bidirectional linked list header array corresponding to the target event corresponding to the i-th row from the N bidirectional linked list header arrays according to the event name of the target event corresponding to the i-th row; Creating the linked list nodes for all the target components; Insert the linked list nodes into the bidirectional linked list header array corresponding to the target event corresponding to the i-th row according to the execution order.
3. The target component notification method according to claim 1, characterized in that: Notifying all target components according to the execution order includes: Traversing the bidirectional linked list header array to determine whether all the target components in the bidirectional linked list header array are in an active state; When it is determined that all the target components are in an active state, the callback functions of all the target components are obtained, and the callback functions corresponding to all the target components are called in sequence according to the execution order to notify all the target components.
4. The target component notification method according to claim 1, characterized in that: Notifying all target components according to the execution order includes: Setting a response time for all target components; In the case where no asynchronous responses fed back by all the target components are received, determining a first target component that feeds back an asynchronous response within the response time, and determining the component with the largest column number among the first target components as the second target component; Determine a third target component based on the second target component and the execution order, and notify the third target component again to instruct the third target component to execute the target event corresponding to the i-th row, wherein the column number of the third target component is greater than that of the second target component, and the third target component and the second target component are adjacent, and the asynchronous response is used to inform the terminal device that the first target component has completed the execution of the target event corresponding to the i-th row in sequence.
5. The target component notification method according to claim 4, characterized in that: After notifying the third target component again, the method further includes: If no asynchronous response is received from the third target component within the response time, stop notifying the third target component and notify the fourth target component according to the execution order, wherein the column number of the fourth target component is greater than the column number of the third target component, and the fourth target component and the third target component are adjacent.
6. The target component notification method according to claim 1, characterized in that: In the process of notifying all target components according to the execution order, the method further includes: Obtain the event type and event parameters of the target event corresponding to the i-th row; Passing the event type and the event parameters to all target components through callback functions corresponding to all target components; Upon receiving the asynchronous response fed back by all target components that complete the target event corresponding to the i-th row according to the event type and the event parameters, the target event corresponding to the i-th row is marked as completed, wherein the asynchronous response is used to inform the terminal device that the target event corresponding to the i-th row has been executed.
7. The target component notification method according to claim 1, characterized in that: In the process of notifying all target components according to the execution order, the method further includes: In the case that a fifth target component among all the target components is executing other events, determining whether the other events are executed, wherein the other events refer to events to be executed by the fifth target component except the target event corresponding to the i-th row; When it is determined that the other events have been executed, the fifth target component is instructed to start executing the target event corresponding to the i-th row.
8. A notification device for a target component, characterized in that: include: A construction module, used to construct a two-dimensional array according to N target events and M target components that execute the N target events, wherein the rows of the two-dimensional array correspond to the N target events one by one, the elements on all columns of the two-dimensional array correspond to the M target components, all target components corresponding to the i-th row are components required to execute the target event corresponding to the i-th row, the column numbers of all target components are the execution order in which all target components are notified when executing the target event corresponding to the i-th row, M and N are both positive integers, and i is a positive integer ranging from 1, ..., N; An initialization module, for initializing a doubly linked list header array for the target event corresponding to the i-th row in sequence, and inserting the linked list nodes created for all the target components into the doubly linked list header array according to the execution order of all the target components and the target event corresponding to the i-th row, wherein the doubly linked list header array is N, and each of the N doubly linked list header arrays caches a target event corresponding to each doubly linked list header array and component information of all the target components that execute the one target event; A notification module is used to determine the execution order of all target components corresponding to the target event corresponding to the i-th row from the bidirectional linked list header array according to the event name of the target event corresponding to the i-th row when the target event corresponding to the i-th row occurs, and notify all target components according to the execution order.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method described in any one of claims 1 to 7 when executed.
10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 7 through the computer program.
Citation Information
Patent Citations
Method for real time bookbinding and processing navigating point for unmanned aerial vehicle
CN101251385A
Database writing method, device and equipment based on multi-writing component and storage medium
CN115203262A
Notification message sending method and device, equipment and storage medium
CN116149881A
State management strategy determination method and device, storage medium and electronic device
CN118487884A
Computer program profiler
US6519766B1