WO2020168928A1 - 事件处理方法、装置和设备 - Google Patents
事件处理方法、装置和设备 Download PDFInfo
- Publication number
- WO2020168928A1 WO2020168928A1 PCT/CN2020/074583 CN2020074583W WO2020168928A1 WO 2020168928 A1 WO2020168928 A1 WO 2020168928A1 CN 2020074583 W CN2020074583 W CN 2020074583W WO 2020168928 A1 WO2020168928 A1 WO 2020168928A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- registration information
- storage space
- event
- event registration
- behavior
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/12—Protocols specially adapted for proprietary or special-purpose networking environments, e.g. medical networks, sensor networks, networks in vehicles or remote metering networks
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F15/00—Digital computers in general; Data processing equipment in general
- G06F15/16—Combinations of two or more digital computers each having at least an arithmetic unit, a program unit and a register, e.g. for a simultaneous processing of several programs
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Definitions
- the present invention relates to the technical field of the Internet of Things, in particular to an event processing method, device and equipment.
- the operating systems used in different devices are not uniform. Although these operating systems provide basic kernel functions, such as memory management, thread scheduling and other basic functions, these operating systems lack a general event handling mechanism. Most of the applications of the Internet of Things are event-driven. These applications require a general event processing mechanism, and at the same time, the overhead of resources (such as storage resources and computing resources) must meet the requirements of resource-constrained devices.
- the embodiments of the present invention provide an event processing method, device, and equipment, and provide a general event processing mechanism to reduce the consumption of resources in the equipment.
- an embodiment of the present invention provides an event processing method applied to an embedded device, and the method includes:
- a second storage space is allocated, wherein both the first storage space and the second storage space can accommodate the first number of event registrations Information, the first number is less than the maximum number of events that can be registered for an object;
- the first event registration information is stored in the second storage space.
- an embodiment of the present invention provides an event processing apparatus, which is applied to an embedded device, and includes:
- a receiving module for receiving first event registration information corresponding to the first object
- An allocation module configured to allocate a second storage space if the allocated first storage space is not enough to accommodate the first event registration information, wherein the first storage space and the second storage space can both accommodate the first storage space A quantity of event registration information, where the first quantity is less than the maximum number of events that can be registered for an object;
- the storage module is configured to store the first event registration information in the second storage space.
- an embodiment of the present invention provides an embedded device that includes a processor and a memory, wherein executable code is stored in the memory, and when the executable code is executed by the processor , Enabling the processor to execute the event processing method in the first aspect.
- an embodiment of the present invention provides a non-transitory machine-readable storage medium that stores executable code on the non-transitory machine-readable storage medium.
- the executable code is processed by an embedded device
- the processor executes, the processor is caused to execute the event processing method in the first aspect.
- an embodiment of the present invention provides an event processing method, which includes:
- a second storage space is allocated, wherein both the first storage space and the second storage space can accommodate the first number of event registrations Information, the first number is less than the maximum number of events that can be registered for an object;
- the first event registration information is stored in the second storage space.
- the event processing method provided by the fifth aspect can be applied to any electronic device, such as various IoT devices.
- the event registration information corresponding to the first object (Referred to as the first event registration information) is sent to the operating system.
- the first event registration information will at least include event behavior, callback function and other information.
- the operating system queries whether the first storage space currently allocated for storing the event registration information is sufficient to accommodate the first event registration information. If the first storage space is not enough to accommodate the first event registration information, a new storage space is allocated, and the newly allocated storage space is called the second storage space, so that the first event registration information is stored in the second storage space .
- each time storage space needs to be allocated, storage space that can accommodate a first number of event registration information is allocated, and the first number is greater than 1 but less than the maximum number of events that can be registered for an object. It can also be understood that every time storage space is allocated, it is assumed that there may be a first number (for example, 8) of objects in the future that also need to register the event behavior in the current first event registration information, so as to register according to the first number of events
- the storage space is allocated for the capacity required by the information. In this way, the on-demand batch allocation of storage space is realized, which can reduce the waste of storage space and the waste of computing resources caused by frequent storage space allocation.
- FIG. 1 is a flowchart of an event processing method provided by an embodiment of the present invention
- FIG. 2 is a flowchart of another event processing method provided by an embodiment of the present invention.
- FIG. 3 is a flowchart of yet another event processing method provided by an embodiment of the present invention.
- FIG. 4 is a schematic structural diagram of an event processing apparatus provided by an embodiment of the present invention.
- FIG. 5 is a schematic structural diagram of an electronic device corresponding to the event processing apparatus provided in the embodiment shown in FIG. 4.
- the words “if” and “if” as used herein can be interpreted as “when” or “when” or “in response to determination” or “in response to detection”.
- the phrase “if determined” or “if detected (statement or event)” can be interpreted as “when determined” or “in response to determination” or “when detected (statement or event) )” or “in response to detection (statement or event)”.
- Fig. 1 is a flowchart of an event processing method provided by an embodiment of the present invention. As shown in Fig. 1, the method includes the following steps:
- the event processing method can be applied to an embedded device.
- the embedded device can be, for example, a sensor, a smart home device, and other IoT devices.
- the event processing method can be controlled by the operating system in the embedded device. To execute.
- the event processing method can also be applied to other electronic devices, such as notebook computers, mobile phones, and so on.
- the first object may be a certain functional module in a certain application.
- the application program is an application program that provides network processing of devices, and two functional modules are provided under the application program: a local area network communication module and a cloud communication module.
- the local area network communication module provides the function of connecting the device to the local area network to network the device;
- the cloud communication module provides the function of connecting the device to the remote interconnection or public network to identify the network.
- the application can perform an event registration for the local area network communication module and an event registration for the cloud communication module.
- the application program When registering events for the local area network communication module, the application program generates event registration information and sends the event registration information to the operating system of the device.
- the event registration information corresponding to the local area network communication module may include: the event behavior of "obtain the IP address of the device", and the callback function of the local area network communication module in response to this event behavior.
- the event registration information may also include the priority corresponding to the local area network communication module, that is, the priority relative to other functional modules that register the event behavior of "getting the device's IP address”.
- the application program when performing event registration for the cloud communication module, the application program generates corresponding event registration information, and sends the event registration information to the operating system of the device.
- the event registration information corresponding to the cloud communication module may include: the event behavior of "obtain the IP address of the device", and the callback function of the cloud communication module in response to this event behavior.
- the event registration information may also include the priority corresponding to the cloud communication module.
- the first object may be a local area network communication module or a cloud communication module.
- the event registration information corresponding to the local area network communication module is called first event registration information;
- the event registration information corresponding to the cloud communication module is called The first event registration information.
- the allocated first storage space is not enough to accommodate the first event registration information, allocate a second storage space, where both the first storage space and the second storage space can hold the first amount of event registration information, and The number is less than the maximum number of events that can be registered for an object.
- the operating system After the operating system receives the first event registration information, it needs to store the first event registration information. Because the resources of embedded devices such as sensors and smart home devices are limited, in order to take into account resource consumption, the embodiment of the present invention adopts a strategy of allocating storage space in batches on demand. Among them, the storage space is used to store event registration information.
- the operating system can allocate storage space sufficient to accommodate multiple event registration information at one time, that is, the operating system uses storage space that can accommodate multiple event registration information as an allocation unit. To allocate storage space.
- a plurality of event registration information is represented by a first number.
- the first number will be set to be greater than 1 but less than the maximum number of events that can be registered for an object.
- the number of events that can be registered for an object in the application that is, the number of event registration information that can be possessed, may be limited, and this limitation is called the maximum number of events.
- the operating system allocates a storage space that can accommodate the first number of event registration information at a time. Then, what is the capacity of this storage space? It can be estimated based on the capacity required to count each event registration information.
- the operating system needs to allocate storage space capable of storing 30 event registration information at a time, so that although overall, the operating system performs storage There are fewer space allocation actions, but there is a problem of wasting storage space. Because if there is not so much event registration information actually generated, the allocated storage space will be seriously idle.
- the first number is taken between 1 and the maximum number of events.
- the first number can be a certain value set empirically, such as 8.
- the first number can also be determined according to the size of the remaining storage space, and/or according to the number of event registration information corresponding to multiple objects.
- determining the first number according to the size of the remaining storage space means that if the remaining storage space without storing event registration information in all storage spaces is large, it means that the storage resources of the device are not tight at this time, and the first The number is set to a larger value, such as 8; relatively, if the remaining storage space is small, it indicates that the storage resources of the device are tight at this time, and the first number can be appropriately set to a smaller value, such as 4.
- the above-mentioned total storage space refers to the storage space used for storing all event registration information in the device.
- determining the first number according to the number of event registration information corresponding to the multiple objects means that the number of event registration information corresponding to the multiple objects in the application can be counted, and for example, the average value can be taken as the first number.
- the operating system allocates enough storage space for the first number of event registration information at a time. It can also be understood that every time storage space is allocated, assuming that there may be the first number of objects in the future, the current event registration information needs to be registered.
- the storage space is allocated according to the capacity required by the first number of event registration information.
- the two objects of the local area network communication module and the cloud communication module in the previous example are registered with the event behavior corresponding to "obtain the IP address of the device".
- the first number can also be determined according to how many objects in the application program can register for the same event behavior. For any event behavior, how many objects in the application need to register for this event behavior can be calculated by the application designer. For example, for event behavior A, there will be 3 objects that need to be registered, and for event behavior B, there will be 8 objects that need to be registered, so the first number can be set to 8.
- the operating system when the operating system is triggered to allocate storage space is determined according to the following method:
- the operating system receives an event registration information
- the event registration information is the first event sent by the application Registration information
- the event registration information is not the first event registration information sent by the application, you can determine whether a new storage space needs to be triggered based on whether the first amount of event registration information has been stored in the previously allocated storage space
- the allocation process Specifically, if the first amount of event registration information has been stored in the previously allocated storage space, a new storage space allocation process will be triggered. Again, a new storage space allocation process will not be triggered.
- the second storage space is allocated. It can be known from the foregoing that both the first storage space and the second storage space can hold the first amount of event registration information.
- the first event registration information is the first event registration information sent by the application, then the first storage space does not yet exist, and it is not enough to accommodate the first event registration information. If the first event registration information is not the first event registration information, then if the first amount of event registration information is already stored in the first storage space allocated before, then the first storage space will not be enough to accommodate the first event registration information To allocate the second storage space. Conversely, if the number of event registration information stored in the first storage space is less than the first number, then the first event registration information can be stored in the first storage space, and there is no need to allocate the second storage space.
- the operating system allocates storage space for storing event registration information in batches on demand, which can reduce the waste of storage space and the waste of computing resources caused by frequent storage space allocation.
- FIG. 2 is a flowchart of another event processing method provided by an embodiment of the present invention. As shown in FIG. 2, it may include the following steps:
- first event registration information corresponding to a first object, where the first event registration information includes an event behavior and a priority of the first object.
- the allocated first storage space is not enough to accommodate the first event registration information, and the second event registration information including the event behavior is stored in the first storage space, allocate a second number that is an integer multiple of the first amount. In the storage space, the second event registration information corresponds to the second object.
- the first object and the second object According to the event behavior and the priorities of the first object and the second object, insert the first event registration information into an adjacent position of the second event registration information according to a set priority ordering strategy.
- a centralized storage strategy is adopted when storing event registration information.
- the so-called centralized storage refers to the centralized storage of multiple event registration information registered with the same event behavior.
- each event registration information stored in the first storage space contains the first event. Event behavior in registration information. If the event behavior is included, based on the first amount, the second storage space that can accommodate event registration information of an integer multiple of the first amount is allocated. It can be understood that the integer multiple of the first amount means greater than 1 times, such as 2 times the first amount. Assuming that the first number is 8, then a storage space that can accommodate 16 event registration information needs to be allocated as the second storage space at this time.
- the event registration information (including the second event registration information) stored in the first storage space can be copied to the second storage space, and the first storage space is released.
- releasing the first storage space refers to deleting each event registration information stored in the first storage space.
- the first event registration information having the same event behavior as the second event registration information can be inserted into the adjacent position of the second event registration information.
- the first event registration information may include the priority of the corresponding first object
- the second event registration information may also include the priority of the corresponding second object.
- the function of this priority is embodied in that when the aforementioned event behavior is triggered by the user, the operating system can determine the object that needs to respond according to the priority, that is, determine the object with a high priority to respond to the occurrence of the event behavior.
- the operating system can insert the first event registration information into the second event registration information according to the set priority ranking strategy during the process of inserting the first event registration information into the adjacent position of the second event registration information.
- Adjacent position For example, if the priority of the first object is higher than that of the second object, and the priority ranking strategy is from high to low, the first event registration information can be inserted into the left adjacent position of the second event registration information.
- FIG. 3 is a flowchart of another event processing method provided by an embodiment of the present invention. As shown in FIG. 3, it may include the following steps:
- first event registration information corresponding to a first object, where the first event registration information includes an event behavior and a priority of the first object.
- the first storage space is sufficient to accommodate the first event registration information, and the first storage space stores third event registration information including the event behavior, and the third event registration information corresponds to the third object, perform For the event behavior and the priority of the first object and the third object, the first event registration information is inserted into the adjacent position of the third event storage information according to the set priority ordering strategy.
- the priority of the first object may not be included in the first event registration information.
- the operating system only needs to associate the first event registration information and the third event registration information corresponding to the same event behavior.
- the adjacent storage can be.
- the event triggering process can be implemented as the following steps:
- each event registration information registered with the same event behavior when each event registration information registered with the same event behavior is stored centrally, when the operating system senses that the event behavior is triggered, it can search for registration in each storage space. The event registration information for the event behavior. If an event registration information that registered the event behavior is found in a certain storage space, then other event registration information that registered the event behavior is also found. At this time, the operating system can determine the target object that responds to the event behavior according to the priority of the object corresponding to each event registration information. It is understandable that when the above-mentioned event registration information is centrally stored according to the priority of the corresponding object, the operating system can easily locate the target object based on the priority ranking strategy.
- the operating system notifies the target object to respond to the event behavior.
- the operating system may directly provide the callback function in the event registration information corresponding to the target object to the target object, and the target object executes the callback function to respond to the event behavior.
- the operating system notifies the target object to respond to the above-mentioned event behavior, which can also be implemented as: the operating system sends the callback function corresponding to the target object to a certain queue, so that the queue notifies the target object to read from the queue Take the callback function to respond to the above event behavior.
- the isolation between the operating system and the upper-level application is actually achieved. Even if the response process of the target object at the application level is abnormal, it will not affect the normal operation of the operating system.
- the event deregistration process can be implemented as the following steps:
- the free storage space in the first storage space and the second storage space can accommodate the second amount of event registration information, the free storage space is reclaimed, where the second amount is more than the first amount.
- the first event registration information is stored in the second storage space, and assuming that the total allocated storage space currently consists of the first storage space and the second storage space, then in the first event When the registration information is cancelled, the operating system needs to delete the first event registration information stored in the second storage space.
- the operating system can further determine the currently allocated storage space, that is, the free status of the first storage space and the second storage space. If the free status meets the set threshold condition, it can check The free storage space is reclaimed.
- the free storage space in the first storage space and the second storage space can accommodate the second amount of event registration information
- the free storage space is reclaimed, where the second amount is more than the first amount. For example, assuming that the first number is 8 and the second number is 12, this means that theoretically, the first storage space and the second storage space can hold a total of 16 event registration information. If it is found that the total number of event registration information stored in the first storage space and the second storage space has dropped from a large number to 4, it means that 12 event registration information has been idle in the first storage space and the second storage space. Storage space, this free storage space needs to be reclaimed at this time.
- the operating system can reclaim all these free storage spaces.
- the operating system can also only reclaim part of the free storage in these free storage spaces. space.
- the operating system may reclaim an integer multiple of the first quantity from the free storage space, where the second quantity is greater than the integer multiple of the first quantity. Since the storage space is allocated in units of the first amount, the free storage space may also be reclaimed based on an integer multiple of the first amount when reclaiming the free storage space, and the integer multiple may be 1 or more times.
- the operating system can also partially reclaim the free storage space according to a certain ratio, for example, the set ratio is 70%, then in combination with the foregoing example, if the free storage space has reached 12 events The capacity of the registration information, then the operating system can reclaim the storage space corresponding to the result of rounding down 12*70%, and the result of rounding down 12*70% is 8, which means that the recovery can accommodate 8 event registration information storage.
- a certain ratio for example, the set ratio is 70%
- FIG. 4 is a schematic structural diagram of an event processing apparatus provided by an embodiment of the present invention.
- the event processing apparatus is located in a certain device, and specifically may be located in the operating system of the device.
- the device may be an embedded device. As shown in FIG. 4, the device includes: a receiving module 11, a distribution module 12, and a storage module 13.
- the receiving module 11 is configured to receive the first event registration information corresponding to the first object.
- the allocating module 12 is configured to allocate a second storage space if the allocated first storage space is not enough to accommodate the first event registration information, wherein both the first storage space and the second storage space can accommodate A first number of event registration information, where the first number is greater than 1 but less than the maximum number of events that can be registered for an object.
- the storage module 13 is configured to store the first event registration information in the second storage space.
- the device further includes: a determining module, configured to determine the first number according to the size of the remaining storage space and/or according to the number of event registration information corresponding to the multiple objects.
- a determining module configured to determine the first number according to the size of the remaining storage space and/or according to the number of event registration information corresponding to the multiple objects.
- the first event registration information includes an event behavior
- the allocation module 12 may be specifically configured to: if the second event registration information including the event behavior is stored in the first storage space, allocate A second storage space that can accommodate an integer multiple of the first number of event registration information, and the second event registration information corresponds to a second object.
- the storage module 13 may be specifically used to: copy each event registration information stored in the first storage space to the second storage space, and release the first storage space; according to the event Behavior, inserting the first event registration information into an adjacent position of the second event registration information.
- the storage module 13 may be specifically used to: according to the first object and the According to the priority of the second object, the first event registration information is inserted into the adjacent position of the second event registration information according to a set priority ordering strategy.
- the first event registration information includes event behavior
- the storage module 13 may also be configured to: if the first storage space is sufficient to accommodate the first event registration information, and the first storage space If third event registration information including the event behavior is stored in the event behavior, the first event registration information is inserted into the adjacent position of the third event registration information according to the event behavior, and the third event registration The information corresponds to the third object.
- the storage module 13 may be specifically used to: according to the first object and the According to the priority of the third object, the first event registration information is inserted into the adjacent position of the third event registration information according to a set priority ordering strategy.
- the device may further include: an event trigger processing module, configured to query each event registration information containing the event behavior in response to the trigger of the event behavior; corresponding to each event registration information respectively The priority of the object determines the target object that responds to the event behavior; notifies the target object to respond to the event behavior.
- an event trigger processing module configured to query each event registration information containing the event behavior in response to the trigger of the event behavior; corresponding to each event registration information respectively The priority of the object determines the target object that responds to the event behavior; notifies the target object to respond to the event behavior.
- the event trigger processing module may be specifically configured to: send the callback function corresponding to the target object to the queue to The queue is made to notify the target object to read the callback function from the queue to respond to the event behavior.
- the device may further include: an event cancellation processing module, configured to delete the first event registration information from the second storage space in response to the cancellation of the first event registration information; if the When the free storage space in the first storage space and the second storage space reaches the second amount of event registration information, the free storage space is reclaimed, where the second amount is more than the first amount.
- an event cancellation processing module configured to delete the first event registration information from the second storage space in response to the cancellation of the first event registration information
- the event deregistration processing module may be specifically configured to: reclaim an integer multiple of the first quantity from the free storage space, and the first The second number is greater than the integer multiple of the first number.
- the device shown in FIG. 4 can execute the methods in the foregoing embodiments.
- parts that are not described in detail in this embodiment reference may be made to the relevant descriptions of the foregoing embodiments, which will not be repeated here.
- the structure of the event processing device shown in FIG. 4 can be implemented as embedded devices such as sensors and smart home devices.
- the embedded device may include: a processor 21 and a memory 22. Wherein, executable code is stored on the memory 22, and when the executable code is executed by the processor 21, the processor 21 is caused to perform at least the following steps:
- a second storage space is allocated, wherein both the first storage space and the second storage space can accommodate the first number of event registrations Information, the first number is less than the maximum number of events that can be registered for an object;
- the first event registration information is stored in the second storage space.
- the structure of the embedded device may also include a communication interface 23 for communicating with other devices or a communication network.
- the embodiment of the present invention provides a non-transitory machine-readable storage medium, the non-transitory machine-readable storage medium stores executable code, when the executable code is executed by the processor of the embedded device At this time, the processor is caused to execute the steps in the foregoing embodiments.
- the structure of the foregoing event processing apparatus can also be implemented as non-embedded devices such as a notebook computer, a mobile phone, and the like.
- the device embodiments described above are merely illustrative.
- the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in One place, or it can be distributed to multiple network units. Some or all of the modules may be selected according to actual needs to achieve the objectives of the solutions of the embodiments. Those of ordinary skill in the art can understand and implement it without creative work.
Landscapes
- Engineering & Computer Science (AREA)
- Computer Hardware Design (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Health & Medical Sciences (AREA)
- General Health & Medical Sciences (AREA)
- Medical Informatics (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Stored Programmes (AREA)
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
一种事件处理方法、装置和设备,该方法可以应用于嵌入式设备中,该方法包括:操作系统接收对应于第一对象的第一事件注册信息(101);若已分配的第一存储空间不足以容纳第一事件注册信息,则分配第二存储空间,其中,第一存储空间和第二存储空间均可容纳第一数量的事件注册信息,第一数量小于一个对象可允许注册的最大事件数量(102);将第一事件注册信息存储到第二存储空间中(103)。每当需要分配一次存储空间时,均分配可容纳第一数量的事件注册信息的存储空间,如此,实现了存储空间的按需批量分配,可以降低存储空间的浪费以及频繁分配存储空间导致的计算资源浪费。
Description
本申请要求2019年02月22日递交的申请号为201910139280.7、发明名称为“事件处理方法、装置和设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本发明涉及物联网技术领域,尤其涉及一种事件处理方法、装置和设备。
随着物联网的发展,越来越多的设备(可以称为物联网设备)开始接入到互联网,而这些设备大部分都是存储和计算资源非常受限的设备。
对于这些资源非常受限的设备,不同的设备中所采用的操作系统并不统一。虽然这些操作系统提供了基本的内核功能,比如存储管理、线程调度等基本功能,但是这些操作系统缺乏一种通用的事件处理机制。而物联网的应用程序大部分又是基于事件驱动的,这些应用程序需要一种通用的事件处理机制,同时对资源(比如存储资源、计算资源)的开销又要满足资源受限设备的要求。
发明内容
本发明实施例提供一种事件处理方法、装置和设备,提供了一种通用的事件处理机制,以降低对设备中资源的消耗。
第一方面,本发明实施例提供一种事件处理方法,应用于嵌入式设备,该方法包括:
接收对应于第一对象的第一事件注册信息;
若已分配的第一存储空间不足以容纳所述第一事件注册信息,则分配第二存储空间,其中,所述第一存储空间和所述第二存储空间均可容纳第一数量的事件注册信息,所述第一数量小于一个对象可允许注册的最大事件数量;
将所述第一事件注册信息存储到所述第二存储空间中。
第二方面,本发明实施例提供一种事件处理装置,应用于嵌入式设备,包括:
接收模块,用于接收对应于第一对象的第一事件注册信息;
分配模块,用于若已分配的第一存储空间不足以容纳所述第一事件注册信息,则分配第二存储空间,其中,所述第一存储空间和所述第二存储空间均可容纳第一数量的事 件注册信息,所述第一数量小于一个对象可允许注册的最大事件数量;
存储模块,用于将所述第一事件注册信息存储到所述第二存储空间中。
第三方面,本发明实施例提供一种嵌入式设备,该嵌入式设备包括处理器和存储器,其中,所述存储器上存储有可执行代码,当所述可执行代码被所述处理器执行时,使所述处理器执行第一方面中的事件处理方法。
第四方面,本发明实施例提供了一种非暂时性机器可读存储介质,所述非暂时性机器可读存储介质上存储有可执行代码,当所述可执行代码被嵌入式设备的处理器执行时,使所述处理器执行第一方面中的事件处理方法。
第五方面,本发明实施例提供一种事件处理方法,该方法包括:
接收对应于第一对象的第一事件注册信息;
若已分配的第一存储空间不足以容纳所述第一事件注册信息,则分配第二存储空间,其中,所述第一存储空间和所述第二存储空间均可容纳第一数量的事件注册信息,所述第一数量小于一个对象可允许注册的最大事件数量;
将所述第一事件注册信息存储到所述第二存储空间中。
实际应用中,第五方面提供的事件处理方法可以适用于任何电子设备,比如各种物联网设备。
在本发明实施例中,当某应用程序针对其中的某个对象(称为第一对象,比如为某个功能模块)向操作系统进行事件注册时,将该第一对象对应的事件注册信息(称为第一事件注册信息)发送至操作系统。其中,第一事件注册信息中至少会包含有事件行为、回调函数等信息。操作系统接收到第一事件注册信息后,查询目前已经为存储事件注册信息而分配的第一存储空间是否足以容纳第一事件注册信息。如果第一存储空间不足以容纳第一事件注册信息,则进行新的存储空间的分配,将新分配的存储空间称为第二存储空间,从而将第一事件注册信息存储到第二存储空间中。其中,每当需要分配一次存储空间时,均分配可容纳第一数量的事件注册信息的存储空间,第一数量大于1而小于一个对象可允许注册的最大事件数量。亦可以理解为,每次分配存储空间时,假设后续可能会有第一数量(比如为8个)的对象也需要注册当前第一事件注册信息中的事件行为,从而按照第一数量个事件注册信息所需要的容量分配存储空间,如此,实现了存储空间的按需批量分配,可以降低存储空间的浪费以及频繁分配存储空间导致的计算资源浪费。
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作一简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1为本发明实施例提供的一种事件处理方法的流程图;
图2为本发明实施例提供的另一种事件处理方法的流程图;
图3为本发明实施例提供的又一种事件处理方法的流程图;
图4为本发明实施例提供的一种事件处理装置的结构示意图;
图5为与图4所示实施例提供的事件处理装置对应的电子设备的结构示意图。
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
在本发明实施例中使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本发明。在本发明实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义,“多种”一般包含至少两种。
取决于语境,如在此所使用的词语“如果”、“若”可以被解释成为“在……时”或“当……时”或“响应于确定”或“响应于检测”。类似地,取决于语境,短语“如果确定”或“如果检测(陈述的条件或事件)”可以被解释成为“当确定时”或“响应于确定”或“当检测(陈述的条件或事件)时”或“响应于检测(陈述的条件或事件)”。
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的商品或者系统不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种商品或者系统所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的商品或 者系统中还存在另外的相同要素。
另外,下述各方法实施例中的步骤时序仅为一种举例,而非严格限定。
图1为本发明实施例提供的一种事件处理方法的流程图,如图1所示,该方法包括如下步骤:
101、接收对应于第一对象的第一事件注册信息。
可选地,该事件处理方法可以应用于嵌入式设备中,该嵌入式设备例如可以是传感器、智能家居设备等物联网设备,具体地,该事件处理方法可以由该嵌入式设备中的操作系统来执行。
可选地,该事件处理方法也可以应用于其他电子设备中,比如笔记本电脑、手机等。
其中,第一对象可以是某应用程序中的某个功能模块。
比如,该应用程序是一种提供对设备进行联网处理的应用程序,在该应用程序下提供了两个功能模块:本地局域网通信模块和云端通信模块。其中,本地局域网通信模块提供了通过将设备接入本地局域网而使设备联网的功能;云端通信模块提供了将设备接入远端互联外或者说公网而使识别联网的功能。
而不管是本地局域网通信模块还是云端通信模块,为实现将设备连接入网的目的,比如均需要注册“获取设备的IP地址”这个事件行为。
因此,应用程序可以针对本地局域网通信模块进行一次事件注册,针对云端通信模块也进行一次事件注册。
针对本地局域网通信模块进行事件注册时,应用程序生成事件注册信息,并将事件注册信息发送至设备的操作系统。其中,与本地局域网通信模块对应的事件注册信息中可以包括:“获取设备的IP地址”这个事件行为、本地局域网通信模块响应这个事件行为的回调函数。可选地,该事件注册信息中还可以包括本地局域网通信模块对应的优先级,即相对于注册“获取设备的IP地址”这个事件行为的其他功能模块的优先级。
同样地,针对云端通信模块进行事件注册时,应用程序生成与之对应的事件注册信息,并将事件注册信息发送至设备的操作系统。此时,与云端通信模块对应的事件注册信息中可以包括:“获取设备的IP地址”这个事件行为、云端通信模块响应这个事件行为的回调函数。可选地,该事件注册信息中还可以包括云端通信模块对应的优先级。
基于上述举例,第一对象可以是本地局域网通信模块或云端通信模块。当第一对象 为本地局域网通信模块时,与本地局域网通信模块对应的事件注册信息称为第一事件注册信息;当第一对象为云端通信模块时,与云端通信模块对应的事件注册信息称为第一事件注册信息。
102、若已分配的第一存储空间不足以容纳第一事件注册信息,则分配第二存储空间,其中,第一存储空间和第二存储空间均可容纳第一数量的事件注册信息,第一数量小于一个对象可允许注册的最大事件数量。
103、将第一事件注册信息存储到第二存储空间中。
操作系统在接收到第一事件注册信息后,需要存储该第一事件注册信息。由于诸如传感器、智能家居设备等嵌入式设备的资源受限,为了兼顾资源消耗情况,本发明实施例中采用了按需批量分配存储空间的策略。其中,存储空间用于存储事件注册信息。
具体来说,在需要进行存储空间分配时,操作系统可以一次分配足以容纳多个事件注册信息的存储空间,也就是说,操作系统以可以容纳多个事件注册信息的存储空间作为一个分配单位,进行存储空间的分配。
其中,多个事件注册信息中的多个,以第一数量来表示,实际上,会设置该第一数量大于1而小于一个对象可允许注册的最大事件数量。其中,应用程序中的一个对象可以注册的事件数量即可以具有的事件注册信息数量可能是有限定的,将该数量限定称为最大事件数量。
操作系统一次分配可以容纳第一数量的事件注册信息的存储空间,那么这个存储空间的容量是多少呢,可以根据统计每个事件注册信息所需的容量来估计。
之所以第一数量取自1和最大事件数量之间,而不取1和最大事件数量,是因为如果第一数量取为1,那么意味着每当有一个事件注册信息生成时,操作系统就需要执行一次存储空间分配动作,且此次分配的存储空间仅用于存储当前生成的一个事件注册信息。如此,当应用程序存在较多的事件注册信息时,操作系统将需要执行多次存储空间分配动作,对计算资源消耗过大。而如果第一数量取为最大事件数量(假设最大事件数量为30),那么意味着操作系统一次需要分配能够存储30个事件注册信息的存储空间,这样虽然从整体来看,操作系统执行的存储空间分配动作数量较少,但是却存在着存储空间浪费的问题。因为如果实际上并没有那么多的事件注册信息产生,那么已经分配的存储空间将存在严重空闲的现象。
基于上述原因,第一数量取自1和最大事件数量之间。可选地,第一数量可以是经 验设定的某个数值,比如为8。可选地,还可以根据剩余存储空间的大小,和/或,根据多个对象分别对应的事件注册信息数量确定第一数量。
其中,根据剩余存储空间大小确定第一数量,是指:如果全部存储空间中未存储事件注册信息的剩余存储空间较大,则说明此时设备的存储资源不紧张,此时可以适当将第一数量设置为较大数值,比如为8;相对地,如果剩余存储空间较小,则说明此时设备的存储资源紧张,此时可以适当将第一数量设置为较小数值,比如为4。其中,上述全部存储空间是指设备中用于存储全部事件注册信息的存储空间。
其中,根据多个对象分别对应的事件注册信息数量确定第一数量,是指:可以统计应用程序中多个对象各自对应的事件注册信息数量,进而比如可以取平均值作为第一数量。
另外,操作系统一次分配足以容纳第一数量的事件注册信息的存储空间,亦可以理解为,每次分配存储空间时,假设后续可能会有第一数量个对象也需要注册当前产生的事件注册信息中的事件行为,从而按照第一数量个事件注册信息所需要的容量分配存储空间。正如前文举例的本地局域网通信模块和云端通信模块这两个对象均注册有对应于“获取设备的IP地址”这个事件行为。基于此,第一数量也可以是根据应用程序中最多会有多少个对象会注册同一事件行为而确定。而针对任一事件行为,应用程序中有多少对象需要注册这个事件行为,应用程序的设计者是可以计算出的。比如,针对事件行为A,会有3个对象需要注册,针对事件行为B,会有8个对象需要注册,则第一数量可以设置为8。
以上对操作系统的按需批量分配存储空间的策略进行了介绍。在实际应用中,何时触发操作系统进行一次存储空间的分配,是根据如下方式确定的:当操作系统接收到某个事件注册信息时,如果该事件注册信息是应用程序发送的第一个事件注册信息,那么触发操作系统进行一次存储空间的分配,即分配足以容纳第一数量的事件注册信息的存储空间。而如果该事件注册信息不是应用程序发送的第一个事件注册信息,那么可以根据之前已经分配的那个存储空间中是否已经存储了第一数量的事件注册信息来确定是否需要触发一次新的存储空间分配过程。具体地,如果之前已经分配的那个存储空间中已经存储了第一数量的事件注册信息,则触发一次新的存储空间分配过程,反正,不会触发一次新的存储空间分配过程。
综上,以操作系统接收到上述第一事件注册信息来说,若已分配的第一存储空间不 足以容纳第一事件注册信息,则分配第二存储空间。由前文所述可知,第一存储空间和第二存储空间均可容纳第一数量的事件注册信息。
其中,如果第一事件注册信息是应用程序发送的第一个事件注册信息,那么第一存储空间还不存在,则不足以容纳第一事件注册信息。而如果第一事件注册信息并非第一个事件注册信息,那么若之前分配的第一存储空间内已经存储有第一数量的事件注册信息,那么第一存储空间将不足以容纳第一事件注册信息,进行第二存储空间的分配。相反地,若第一存储空间中存储的事件注册信息的数量小于第一数量,则可以将第一事件注册信息存入到第一存储空间内即可,无需进行第二存储空间的分配。
综上,操作系统通过按需批量分配用于存储事件注册信息的存储空间,可以降低存储空间的浪费以及频繁分配存储空间导致的计算资源浪费。
图2为本发明实施例提供的另一种事件处理方法的流程图,如图2所示,可以包括如下步骤:
201、接收对应于第一对象的第一事件注册信息,第一事件注册信息中包括事件行为和第一对象的优先级。
202、若已分配的第一存储空间不足以容纳第一事件注册信息,且第一存储空间中存储有包含所述事件行为的第二事件注册信息,则分配整数倍于第一数量的第二存储空间,第二事件注册信息对应于第二对象。
203、将第一存储空间中存储的各事件注册信息复制到第二存储空间中,并释放第一存储空间。
204、根据所述事件行为以及第一对象和第二对象的优先级,按照设定的优先级排序策略,将第一事件注册信息插入到第二事件注册信息的相邻位置。
由前文所述可知,应用程序中可能会有不同的对象注册有相同的事件行为,而如果对应于同一事件行为的多个对象所各自对应的事件注册信息被较为分散地存储,那么在该事件行为被用户触发时,操作系统可能需要遍历所有的存储空间以便找到注册有该事件行为的对象。
为了降低操作系统的计算量,本实施例中,在对事件注册信息进行存储时,采用了集中存储的策略,所谓集中存储是指将注册有同一事件行为的多个事件注册信息集中存储。
具体来说,当如前述其他实施例中的说明,确定第一存储空间不足以容纳第一事件注册信息时,进一步确定第一存储空间中存储的各事件注册信息中是否包含有该第一事件注册信息中的事件行为。如果包含有该事件行为,则以第一数量为基础,分配可容纳整数倍于第一数量的事件注册信息的第二存储空间,可以理解的是,该整数倍于第一数量,是指大于1倍,比如2倍于第一数量。假设第一数量为8,那么此时需要分配可以容纳16个事件注册信息的存储空间作为第二存储空间。
在分配好第二存储空间后,可以将第一存储空间中存储的各事件注册信息(其中包括第二事件注册信息)复制到第二存储空间中,并释放第一存储空间。其中,释放第一存储空间是指将第一存储空间中存储的各事件注册信息删除。进而,可以基于上述事件行为,将与第二事件注册信息具有相同事件行为的第一事件注册信息插入到第二事件注册信息的相邻位置。
另外,在一可选实施例中,第一事件注册信息中可以包括其对应的第一对象的优先级,第二事件注册信息中也可以包括其对应的第二对象的优先级。该优先级的作用体现为:当上述事件行为被用户触发时,操作系统可以根据该优先级确定需要进行响应的对象,即确定具有高优先级的对象来响应该事件行为的发生。
基于此,操作系统在将第一事件注册信息插入到第二事件注册信息的相邻位置的过程中,可以按照设定的优先级排序策略,将第一事件注册信息插入到第二事件注册信息的相邻位置。比如,假设第一对象的优先级高于第二对象,优先级排序策略是由高到低排列,则可以将第一事件注册信息插入到第二事件注册信息的左侧相邻位置。
图3为本发明实施例提供的又一种事件处理方法的流程图,如图3所示,可以包括如下步骤:
301、接收对应于第一对象的第一事件注册信息,第一事件注册信息中包括事件行为和第一对象的优先级。
302、若第一存储空间足以容纳第一事件注册信息,且第一存储空间中存储有包含所述事件行为的第三事件注册信息,第三事件注册信息对应于第三对象,则根据所述事件行为以及第一对象和第三对象的优先级,按照设定的优先级排序策略,将第一事件注册信息插入到第三事件存储信息的相邻位置。
当然,可以理解的是,第一事件注册信息中也可以不包括第一对象的优先级,此时,操作系统仅需要将对应于同一事件行为的第一事件注册信息和第三事件注册信息相 邻存储即可。
通过以上各实施例对事件注册信息的存储过程进行了说明,但是,在实际应用中,事件除了涉及注册过程外,还会涉及到事件触发过程以及事件注销过程。下面对这两种过程分别进行说明。
在一可选实施例中,事件触发过程可以实现为如下步骤:
响应于事件行为的触发,查询包含有该事件行为的各事件注册信息;
根据各事件注册信息分别对应的对象的优先级,确定响应该事件行为的目标对象;
通知目标对象对该事件行为进行响应处理。
如前述图2或图3所示实施例中的介绍,当注册了同一事件行为的各事件注册信息被集中存储时,操作系统感应到该事件行为被触发时,可以在各存储空间中查找注册了该事件行为的各事件注册信息。如果在某存储空间中找到了一个注册了该事件行为的事件注册信息,那么其他的注册了该事件行为的事件注册信息也便找到了。此时,操作系统可以根据各事件注册信息分别对应的对象的优先级,确定响应该事件行为的目标对象。可以理解的是,当上述各事件注册信息是按照各自对应的对象的优先级进行集中存储的时,操作系统可以基于优先级排序策略方便地定位到目标对象。
操作系统通知目标对象对该事件行为进行响应处理,可以是操作系统直接将该目标对象对应的事件注册信息中的回调函数提供给目标对象,目标对象执行该回调函数以对该事件行为进行响应。
另外,可选地,操作系统通知目标对象对上述事件行为进行响应处理,还可以实现为:操作系统将目标对象对应的回调函数发送至某队列中,以使该队列通知目标对象从队列中读取该回调函数以对上述事件行为进行响应处理。通过这种方式,其实是实现了操作系统与上层的应用程序之间的隔离,即使应用程序层面的目标对象的响应过程出现异常,也不至于影响操作系统的正常运行。
在一可选实施例中,以前述第一事件注册信息为例,事件注销过程可以实现为如下步骤:
响应于第一事件注册信息的注销,从第二存储空间中删除第一事件注册信息;
若第一存储空间和第二存储空间中的空闲存储空间达到能够容纳第二数量的事件注册信息,则回收空闲存储空间,其中,第二数量多于第一数量。
由此可知,在事件注销的过程中,可能会涉及到存储空间的回收处理。
假设基于前文的存储过程的描述,第一事件注册信息被存入到第二存储空间中,并且假设目前总共已经分配的存储空间由第一存储空间和第二存储空间构成,那么在第一事件注册信息被注销时,操作系统需要删除存储在第二存储空间中的该第一事件注册信息。
在删除了第一事件注册信息后,操作系统还可以进一步确定当前已分配的存储空间即第一存储空间和第二存储空间中的空闲情况,如果空闲情况符合设定的阈值条件,则可以对其中的空闲存储空间进行回收。
具体地,若第一存储空间和第二存储空间中的空闲存储空间达到能够容纳第二数量的事件注册信息,则回收空闲存储空间,其中,第二数量多于第一数量。举例来说,假设第一数量为8,第二数量为12,这就意味着理论上第一存储空间和第二存储空间一共可以容纳16个事件注册信息。如果发现第一存储空间和第二存储空间中一共存储的事件注册信息的数量已经由较多数量下降到4,说明第一存储空间和第二存储空间中已经出现了12个事件注册信息的空闲存储空间,此时需要回收这些空闲存储空间。
可选地,操作系统可以全部回收这些空闲存储空间。
但是,为了避免在某事件注册信息刚被注销后随后又被重新注册的情况下,需要重新分配一次存储空间而导致的计算量开销,操作系统也可以仅回收这些空闲存储空间中的部分空闲存储空间。
具体地,操作系统可以从这些空闲存储空间中回收整数倍于第一数量的部分,其中,第二数量大于第一数量的该整数倍。由于存储空间的分配是以第一数量为单位的,因此,回收空闲存储空间时也可以以第一数量的整数倍为基准来回收,该整数倍可以是1倍或多倍。
当然,可选地,操作系统也可以根据按照一定的比例对这些空闲存储空间进行部分回收,比如设定的比例为70%,那么结合前述的举例,如果空闲存储空间已经达到可以容纳12个事件注册信息的容量,那么操作系统可以回收其中向下取整12*70%的结果所对应的存储空间,向下取整12*70%的结果为8,即回收可以容纳8个事件注册信息的存储空间。
以下将详细描述本发明的一个或多个实施例的事件处理装置。本领域技术人员可以理解,这些事件处理装置均可使用市售的硬件组件通过本方案所教导的步骤进行配置来 构成。
图4为本发明实施例提供的一种事件处理装置的结构示意图,该事件处理装置位于某设备中,具体可以位于该设备中的操作系统中。另外,该设备可以是嵌入式设备。如图4所示,该装置包括:接收模块11、分配模块12、存储模块13。
接收模块11,用于接收对应于第一对象的第一事件注册信息。
分配模块12,用于若已分配的第一存储空间不足以容纳所述第一事件注册信息,则分配第二存储空间,其中,所述第一存储空间和所述第二存储空间均可容纳第一数量的事件注册信息,所述第一数量大于1而小于一个对象可允许注册的最大事件数量。
存储模块13,用于将所述第一事件注册信息存储到所述第二存储空间中。
可选地,所述装置还包括:确定模块,用于根据剩余存储空间的大小,和/或,根据多个对象分别对应的事件注册信息数量,确定所述第一数量。
可选地,所述第一事件注册信息中包括事件行为,所述分配模块12具体可以用于:若所述第一存储空间中存储有包含所述事件行为的第二事件注册信息,则分配可容纳整数倍于所述第一数量的事件注册信息的第二存储空间,所述第二事件注册信息对应于第二对象。相应地,所述存储模块13具体可以用于:将所述第一存储空间中存储的各事件注册信息复制到所述第二存储空间中,并释放所述第一存储空间;根据所述事件行为,将所述第一事件注册信息插入到所述第二事件注册信息的相邻位置。
其中,可选地,在将所述第一事件注册信息插入到所述第二事件注册信息的相邻位置的过程中,所述存储模块13具体可以用于:根据所述第一对象和所述第二对象的优先级,按照设定的优先级排序策略,将所述第一事件注册信息插入到所述第二事件注册信息的相邻位置。
可选地,所述第一事件注册信息中包括事件行为,所述存储模块13还可以用于:若所述第一存储空间足以容纳所述第一事件注册信息,且所述第一存储空间中存储有包含所述事件行为的第三事件注册信息,则根据所述事件行为,将所述第一事件注册信息插入到所述第三事件注册信息的相邻位置,所述第三事件注册信息对应于第三对象。
其中,可选地,在将所述第一事件注册信息插入到所述第三事件注册信息的相邻位置的过程中,所述存储模块13具体可以用于:根据所述第一对象和所述第三对象的优先级,按照设定的优先级排序策略,将所述第一事件注册信息插入到所述第三事件注册信息的相邻位置。
可选地,所述装置还可以包括:事件触发处理模块,用于响应于所述事件行为的触发,查询包含有所述事件行为的各事件注册信息;根据所述各事件注册信息分别对应的对象的优先级,确定响应所述事件行为的目标对象;通知所述目标对象对所述事件行为进行响应处理。
其中,可选地,在通知所述目标对象对所述事件行为进行响应处理的过程中,所述事件触发处理模块具体可以用于:将所述目标对象对应的回调函数发送至队列中,以使所述队列通知所述目标对象从所述队列中读取所述回调函数以对所述事件行为进行响应处理。
可选地,所述装置还可以包括:事件注销处理模块,用于响应于所述第一事件注册信息的注销,从所述第二存储空间中删除所述第一事件注册信息;若所述第一存储空间和所述第二存储空间中的空闲存储空间达到能够容纳第二数量的事件注册信息,则回收所述空闲存储空间,其中,第二数量多于所述第一数量。
其中,可选地,在回收所述空闲存储空间的过程中,所述事件注销处理模块具体可以用于:从所述空闲存储空间中回收整数倍于所述第一数量的部分,所述第二数量大于所述第一数量的所述整数倍。
图4所示装置可以执行前述各实施例中的方法,本实施例未详细描述的部分,可参考前述实施例的相关说明,在此不再赘述。
在一个可能的设计中,上述图4所示的事件处理装置的结构可实现为诸如传感器、智能家居设备等嵌入式设备。如图5所示,该嵌入式设备可以包括:处理器21、存储器22。其中,所述存储器22上存储有可执行代码,当所述可执行代码被所述处理器21执行时,至少使所述处理器21完成如下步骤:
接收对应于第一对象的第一事件注册信息;
若已分配的第一存储空间不足以容纳所述第一事件注册信息,则分配第二存储空间,其中,所述第一存储空间和所述第二存储空间均可容纳第一数量的事件注册信息,所述第一数量小于一个对象可允许注册的最大事件数量;
将所述第一事件注册信息存储到所述第二存储空间中。
其中,该嵌入式设备的结构中还可以包括通信接口23,用于与其他设备或通信网络通信。
另外,本发明实施例提供了一种非暂时性机器可读存储介质,所述非暂时性机器可 读存储介质上存储有可执行代码,当所述可执行代码被嵌入式设备的处理器执行时,使所述处理器执行前述各实施例中的各步骤。
可选地,上述事件处理装置的结构还可实现为诸如笔记本电脑、手机等等非嵌入式设备。
以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助加必需的通用硬件平台的方式来实现,当然也可以通过硬件和软件结合的方式来实现。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以计算机产品的形式体现出来,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。
Claims (13)
- 一种事件处理方法,其特征在于,应用于嵌入式设备,所述方法包括:接收对应于第一对象的第一事件注册信息;若已分配的第一存储空间不足以容纳所述第一事件注册信息,则分配第二存储空间,其中,所述第一存储空间和所述第二存储空间均可容纳第一数量的事件注册信息,所述第一数量小于一个对象可允许注册的最大事件数量;将所述第一事件注册信息存储到所述第二存储空间中。
- 根据权利要求1所述的方法,其特征在于,所述方法还包括:根据剩余存储空间的大小,和/或,根据多个对象分别对应的事件注册信息数量,确定所述第一数量。
- 根据权利要求1所述的方法,其特征在于,所述第一事件注册信息中包括事件行为;所述分配第二存储空间,包括:若所述第一存储空间中存储有包含所述事件行为的第二事件注册信息,则分配可容纳整数倍于所述第一数量的事件注册信息的第二存储空间,所述第二事件注册信息对应于第二对象;所述将所述第一事件注册信息存储到所述第二存储空间中,包括:将所述第一存储空间中存储的各事件注册信息复制到所述第二存储空间中,并释放所述第一存储空间;根据所述事件行为,将所述第一事件注册信息插入到所述第二事件注册信息的相邻位置。
- 根据权利要求3所述的方法,其特征在于,所述将所述第一事件注册信息插入到所述第二事件注册信息的相邻位置,包括:根据所述第一对象和所述第二对象的优先级,按照设定的优先级排序策略,将所述第一事件注册信息插入到所述第二事件注册信息的相邻位置。
- 根据权利要求1所述的方法,其特征在于,所述第一事件注册信息中包括事件行为;所述方法还包括:若所述第一存储空间足以容纳所述第一事件注册信息,且所述第一存储空间中存储有包含所述事件行为的第三事件注册信息,则根据所述事件行为,将所述第一事件注册 信息插入到所述第三事件注册信息的相邻位置,所述第三事件注册信息对应于第三对象。
- 根据权利要求5所述的方法,其特征在于,所述将所述第一事件注册信息插入到所述第三事件注册信息的相邻位置,包括:根据所述第一对象和所述第三对象的优先级,按照设定的优先级排序策略,将所述第一事件注册信息插入到所述第三事件注册信息的相邻位置。
- 根据权利要求4或6所述的方法,其特征在于,所述方法还包括:响应于所述事件行为的触发,查询包含有所述事件行为的各事件注册信息;根据所述各事件注册信息分别对应的对象的优先级,确定响应所述事件行为的目标对象;通知所述目标对象对所述事件行为进行响应处理。
- 根据权利要求7所述的方法,其特征在于,所述通知所述目标对象对所述事件行为进行响应处理,包括:将所述目标对象对应的回调函数发送至队列中,以使所述队列通知所述目标对象从所述队列中读取所述回调函数以对所述事件行为进行响应处理。
- 根据权利要求1所述的方法,其特征在于,所述方法还包括:响应于所述第一事件注册信息的注销,从所述第二存储空间中删除所述第一事件注册信息;若所述第一存储空间和所述第二存储空间中的空闲存储空间达到能够容纳第二数量的事件注册信息,则回收所述空闲存储空间,其中,第二数量多于所述第一数量。
- 根据权利要求9所述的方法,其特征在于,所述回收所述空闲存储空间,包括:从所述空闲存储空间中回收整数倍于所述第一数量的部分,所述第二数量大于所述第一数量的所述整数倍。
- 一种事件处理装置,其特征在于,应用于嵌入式设备,包括:接收模块,用于接收对应于第一对象的第一事件注册信息;分配模块,用于若已分配的第一存储空间不足以容纳所述第一事件注册信息,则分配第二存储空间,其中,所述第一存储空间和所述第二存储空间均可容纳第一数量的事件注册信息,所述第一数量小于一个对象可允许注册的最大事件数量;存储模块,用于将所述第一事件注册信息存储到所述第二存储空间中。
- 一种嵌入式设备,其特征在于,包括:存储器、处理器;其中,所述存储器上 存储有可执行代码,当所述可执行代码被所述处理器执行时,使所述处理器执行如权利要求1至10中任一项所述的事件处理方法。
- 一种事件处理方法,其特征在于,包括:接收对应于第一对象的第一事件注册信息;若已分配的第一存储空间不足以容纳所述第一事件注册信息,则分配第二存储空间,其中,所述第一存储空间和所述第二存储空间均可容纳第一数量的事件注册信息,所述第一数量小于一个对象可允许注册的最大事件数量;将所述第一事件注册信息存储到所述第二存储空间中。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910139280.7 | 2019-02-22 | ||
| CN201910139280.7A CN111611193B (zh) | 2019-02-22 | 2019-02-22 | 事件处理方法、装置和设备 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2020168928A1 true WO2020168928A1 (zh) | 2020-08-27 |
Family
ID=72144754
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2020/074583 Ceased WO2020168928A1 (zh) | 2019-02-22 | 2020-02-10 | 事件处理方法、装置和设备 |
Country Status (3)
| Country | Link |
|---|---|
| CN (1) | CN111611193B (zh) |
| TW (1) | TW202044071A (zh) |
| WO (1) | WO2020168928A1 (zh) |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103064639A (zh) * | 2012-12-28 | 2013-04-24 | 华为技术有限公司 | 数据存储方法及装置 |
| WO2015053766A1 (en) * | 2013-10-09 | 2015-04-16 | Intel Corporation | Technology for managing cloud storage |
| CN107092562A (zh) * | 2017-04-10 | 2017-08-25 | 中云信安(深圳)科技有限公司 | 一种嵌入式设备安全存储管理系统及方法 |
| CN107426321A (zh) * | 2017-07-31 | 2017-12-01 | 郑州云海信息技术有限公司 | 一种分布式存储系统配额分配方法及装置 |
| CN109117090A (zh) * | 2018-07-27 | 2019-01-01 | 郑州云海信息技术有限公司 | 一种存储池的存储空间配额方法、装置、设备及存储介质 |
Family Cites Families (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US5594889A (en) * | 1992-01-03 | 1997-01-14 | Digital Equipment Corporation | Memory resource allocation look ahead system and method |
| US8271996B1 (en) * | 2008-09-29 | 2012-09-18 | Emc Corporation | Event queues |
| JP2012212227A (ja) * | 2011-03-30 | 2012-11-01 | Nec Corp | イベント処理システム、該システムに用いられるイベント処理方法及びイベント処理プログラム |
| CN104346264A (zh) * | 2013-07-26 | 2015-02-11 | 鸿富锦精密工业(深圳)有限公司 | 系统事件日志处理系统及方法 |
| US9807161B2 (en) * | 2013-09-16 | 2017-10-31 | Axis Ab | Distributed events in an access control system |
| CN108170577B (zh) * | 2013-10-31 | 2021-11-26 | 乾元云硕科技(深圳)有限公司 | 服务器 |
| CN105426236A (zh) * | 2015-11-11 | 2016-03-23 | 上海斐讯数据通信技术有限公司 | 高并发状态机的实现方法、实现装置及系统 |
-
2019
- 2019-02-22 CN CN201910139280.7A patent/CN111611193B/zh active Active
- 2019-11-25 TW TW108142730A patent/TW202044071A/zh unknown
-
2020
- 2020-02-10 WO PCT/CN2020/074583 patent/WO2020168928A1/zh not_active Ceased
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103064639A (zh) * | 2012-12-28 | 2013-04-24 | 华为技术有限公司 | 数据存储方法及装置 |
| WO2015053766A1 (en) * | 2013-10-09 | 2015-04-16 | Intel Corporation | Technology for managing cloud storage |
| CN107092562A (zh) * | 2017-04-10 | 2017-08-25 | 中云信安(深圳)科技有限公司 | 一种嵌入式设备安全存储管理系统及方法 |
| CN107426321A (zh) * | 2017-07-31 | 2017-12-01 | 郑州云海信息技术有限公司 | 一种分布式存储系统配额分配方法及装置 |
| CN109117090A (zh) * | 2018-07-27 | 2019-01-01 | 郑州云海信息技术有限公司 | 一种存储池的存储空间配额方法、装置、设备及存储介质 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN111611193B (zh) | 2023-06-20 |
| CN111611193A (zh) | 2020-09-01 |
| TW202044071A (zh) | 2020-12-01 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| EP2919116B1 (en) | Global memory sharing method and device and communication system | |
| CN110018899B (zh) | 回收内存的方法及装置 | |
| CN104539708B (zh) | 一种云平台资源的缩容方法、装置与系统 | |
| US11675622B2 (en) | Leader election with lifetime term | |
| CN109191287B (zh) | 一种区块链智能合约的分片方法、装置及电子设备 | |
| CN113886069B (zh) | 一种资源分配方法、装置、电子设备及存储介质 | |
| US10409498B2 (en) | Method and apparatus for managing memory | |
| CN110162395B (zh) | 一种内存分配的方法及装置 | |
| CN111078405B (zh) | 内存分配方法、装置、存储介质及电子设备 | |
| US9384050B2 (en) | Scheduling method and scheduling system for multi-core processor system | |
| CN110750498B (zh) | 对象访问方法、装置及存储介质 | |
| CN113886082A (zh) | 请求处理方法、装置、计算设备及介质 | |
| WO2022028165A1 (zh) | 缓存管理方法、终端以及存储介质 | |
| WO2017070869A1 (zh) | 一种内存配置方法、装置及系统 | |
| CN113806050B (zh) | 一种计算资源的处理方法、装置、电子设备及存储介质 | |
| CN111611193B (zh) | 事件处理方法、装置和设备 | |
| WO2025202758A1 (zh) | 内存回收方法、装置、电子设备、存储介质及程序产品 | |
| CN111782560A (zh) | 内存回收方法、装置、终端设备以及存储介质 | |
| CN109976885B (zh) | 基于多任务操作系统的事件处理方法、装置及存储介质 | |
| CN110187957B (zh) | 一种下载任务的排队方法、装置及电子设备 | |
| CN108121598A (zh) | 套接字缓存资源管理方法及装置 | |
| CN104714924B (zh) | 一种资源控制方法和装置 | |
| CN117785486B (zh) | 环境资源调配方法、装置、设备和介质 | |
| CN118626272B (zh) | 内存的分配方法、装置、设备、介质和产品 | |
| CN118245185A (zh) | 一种任务管理方法、装置、电子设备及存储介质 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 20760117 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 20760117 Country of ref document: EP Kind code of ref document: A1 |