Application program extension method and device and electronic equipment
By using message queue mode to detect and route messages in applications, binary compatibility, stability and language limitation issues in traditional plug-in extension methods are solved, and independent development and efficient expansion of the main program and extension are achieved.
Patent Information
- Application Number
- CN202311134219.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-04
- Publication Date
- 2025-03-04
AI Technical Summary
Traditional plug-in-based application extension methods have binary compatibility issues, stability issues and language type limitation issues, resulting in development complexity and inefficiency.
Decoupling and independent development between the extension program and the main program is achieved by detecting whether the first program sends a message to the target channel and when it sends the message, the message is routed to the second program subscribed to the channel.
Reduces coupling between the extension and the main program, avoids binary compatibility and stability issues, and allows the development of extensions using any mainstream development language.
Smart Images

Figure CN119557001A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of computer technology, and in particular to an application expansion method, device, and electronic device. Background Art
[0002] Traditional application extensions often take the form of plug-ins. During the development of the main program, the plug-in interface needs to be defined first. The plug-in developer needs to implement these interfaces and register his plug-in with the application after the application is started. During the running of the application, once a specific event occurs, the application will check the plug-in registered to this interface and call the plug-in interface. This application extension method has a clear program architecture. The main program does not need to care about the specific implementation of the plug-in. The plug-in developer only needs to develop and register the plug-in according to the interface specification to achieve the extension of the main program. Summary of the invention
[0003] This disclosure section is provided to introduce concepts in a brief form, which will be described in detail in the detailed description section below. This disclosure section is not intended to identify key features or essential features of the claimed technical solution, nor is it intended to limit the scope of the claimed technical solution.
[0004] In a first aspect, an embodiment of the present disclosure provides an application expansion method, comprising: detecting whether a first program sends a message to a target channel; if so, sending the message to a second program subscribed to the target channel, so that the second program performs a preset operation based on the message, wherein at least one of the first program and the second program is an extended program.
[0005] In a second aspect, an embodiment of the present disclosure provides an application expansion device, comprising: a detection unit, for detecting whether a first program sends a message to a target channel; a sending unit, for sending the message to a second program subscribed to the target channel if the first program sends a message to the target channel, so that the second program can perform a preset operation based on the message, wherein at least one of the first program and the second program is an extension program.
[0006] In a third aspect, an embodiment of the present disclosure provides an electronic device, comprising: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the application expansion method as described in the first aspect.
[0007] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the application expansion method as described in the first aspect.
[0008] The application extension method, device and electronic device provided by the disclosed embodiment detect whether the first program sends a message to the target channel; if so, the message is sent to the second program subscribed to the target channel, so that the second program performs a preset operation based on the message, wherein at least one of the first program and the second program is an extension program. This method realizes the message routing function between the subscriber (i.e., the second program) and the publisher (i.e., the first program) by using the message queue mode.
[0009] Traditional plug-in-based application extension methods usually have the following problems:
[0010] First, there is the binary compatibility issue. Due to different versions of the compilation toolchain or different levels of compilation optimization, binary incompatibility issues are easy to occur between the main program and the plug-in. Such problems are often hidden and will only cause crashes when calling specific interfaces. It is also more difficult to locate the crash than general application crashes.
[0011] Secondly, there is the stability issue. The essence of a plug-in is usually a dynamic link library, which shares the same address space as the process. Therefore, once an exception occurs inside the plug-in, the main program will crash and exit. For a mature application, there are often dozens or even hundreds of plug-in programs. The developers of these plug-ins have different levels, and it is inevitable that there are defects in different programs. Each time the program is started, several or even dozens of plug-ins are usually loaded at the same time. The stability of the main program will decrease as the number of plug-ins increases.
[0012] The third issue is the language type limitation. The essence of a plug-in is usually a dynamic link library. The most suitable language for writing plug-ins is a programming language such as C / C++ that can generate native code. If it is a language with an intermediate layer such as Java or C#, or a scripting language such as Python, it is not suitable as a plug-in development language. Although dynamic link library development can be achieved with the help of tools provided by the language itself, the development efficiency is low. Therefore, the limitation of language type also causes limitations in the application of the plug-in mechanism.
[0013] Compared with the traditional plug-in-based application expansion method, this solution can minimize the coupling between the extension program and the main program, making the development and construction of the main program and the extension program independent of each other. There is no need to worry about binary compatibility issues, and the instability of the extension program will not affect the main program. The development of the extension program can use any mainstream development language. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.
[0015] Figure 1 is a flowchart of an embodiment of an application extension method according to the present disclosure;
[0016] Figure 2 is a flowchart of another embodiment of the application expansion method according to the present disclosure;
[0017] Figure 3 is a schematic diagram of an application scenario of the application extension method according to the present disclosure;
[0018] Figure 4 is a flowchart of another embodiment of the application expansion method according to the present disclosure;
[0019] Figure 5 is a schematic diagram of another application scenario of the application expansion method according to the present disclosure;
[0020] Figure 6 is a flowchart of another embodiment of the application expansion method according to the present disclosure;
[0021] Figure 7 is a flowchart of an embodiment of program startup in the application extension method according to the present disclosure;
[0022] Figure 8 is a schematic diagram of a structure of an extension program directory in the application extension method according to the present disclosure;
[0023] Fig. 9 is a schematic diagram comparing a traditional application extension method in the application extension method of the present invention with the application extension method of the present invention;
[0024] Fig.10 is a structural diagram of an embodiment of an application expansion device according to the present disclosure;
[0025] Fig.11 is an exemplary system architecture diagram in which various embodiments of the present disclosure may be applied;
[0026] Fig.12 It is a schematic diagram of the structure of a computer system suitable for implementing the electronic device of the embodiment of the present disclosure. DETAILED DESCRIPTION
[0027] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0028] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0029] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0030] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0031] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0032] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0033] Please refer to Figure 1 , shows a process 100 of an embodiment of an application extension method according to the present disclosure. The application extension method comprises the following steps:
[0034] Step 101, detecting whether the first program sends a message to a target channel.
[0035] In this embodiment, the execution subject of the application program extension method can detect whether the first program sends a message to the target channel. If it is detected that the first program sends a message to the target channel, the execution subject can execute step 102.
[0036] Here, the first program and the second program can use RabbitMQ for information exchange. RabbitMQ is an open source message broker software (also known as message-oriented middleware) that implements the Advanced Message Queuing Protocol (AMQP) and is used to realize data sharing between completely different applications.
[0037] The message queue mode can also be called the publish-subscribe mode or the observer mode, which consists of publishers (pub), subscribers (sub) and channels (channel). The publisher sends messages and the subscriber receives messages, thus serving as a message routing function between subscribers and publishers.
[0038] Here, the first program is usually the publisher, and the second program is usually the subscriber. The first program and the second program pre-agree on a channel (ie, the target channel). After the first program sends a message to the target channel, the second program that subscribes to the target channel can receive the message.
[0039] Step 102: If the first program sends a message to the target channel, the message is sent to the second program subscribed to the target channel, so that the second program performs a preset operation based on the message.
[0040] In this embodiment, if it is detected in step 101 that the first program sends a message to the target channel, the execution subject may send the message to the second program subscribed to the target channel.
[0041] Here, at least one of the first program and the second program is an extended program. The first program and the second program can be divided into the following three situations: the first program is a main program and the second program is an extended program; the first program is an extended program and the second program is a main program; and both the first program and the second program are extended programs.
[0042] The main program can also be called the main function. The main program is an entry point for the program. Without the main program, the software will not know where to start execution. Extension programs can be used to add certain functions to the main program. For example, if a graphics editing tool does not have a cropping function, an extension program can be added to the main program of the graphics editing tool to crop the graphics through the extension program and return the cropped graphics to the main program for subsequent processing.
[0043] Here, after receiving the message, the second program may perform a preset operation based on the message. The operation performed by the second program depends on the function it provides. For example, if the second program is an extension program, and the extension program is used for log storage, the second program may store the received message.
[0044] The method provided by the above embodiment of the present disclosure detects whether the first program sends a message to the target channel; if so, the message is sent to the second program subscribed to the target channel, so that the second program performs a preset operation based on the message, wherein at least one of the first program and the second program is an extended program. This method realizes the message routing function between the subscriber (i.e., the second program) and the publisher (i.e., the first program) by using the message queue mode.
[0045] Compared with the traditional plug-in-based application expansion method, this solution can minimize the coupling between the extension program and the main program, making the development and construction of the main program and the extension program independent of each other. There is no need to worry about binary compatibility issues, and the instability of the extension program will not affect the main program. The development of the extension program can use any mainstream development language.
[0046] In some optional implementations, the first program and the second program may communicate using a remote dictionary server (Remote Dictionary Server, Redis) database. Redis is a high-performance key-value database that supports multiple message queue models. Redis has the advantages of being lightweight and high-performance, and has both database and message queue functions. Therefore, using Redis also solves the problem of data storage, without the need to install a separate database service, thereby improving the overall operating efficiency of the system.
[0047] Since Redis is used as a medium, there are almost no restrictions on the development language and operating system used for developing extension programs, as long as the language can provide a Redis link library and support the subscription and publishing of Redis channels. Almost all mainstream languages currently used provide support for access to Redis. The deployment method of extension programs is also very loose. As long as it can communicate with the main program over the network, the extension program can exist on any computer, as long as the computer supports the TCP / IP protocol (Transmission Control Protocol / Internet Protocol). It should be noted that if the main program and the extension program are located on different PCs, the computer where the extension program is located needs to install an agent to be responsible for starting the extension program instead of the main program.
[0048] Continue to refer Figure 2 , which shows a process 200 of another embodiment of an application extension method. In the process 200 of the application extension method, the first program is a main program, and the second program is an extension program. The process includes the following steps:
[0049] Step 201, detecting whether a preset event of the main program is triggered.
[0050] In this embodiment, the execution subject of the application extension method can detect whether the preset event of the main program is triggered. The above-mentioned execution subject can monitor the preset events in the main program and detect whether these preset events are triggered. If the preset event of the main program is triggered, the above-mentioned execution subject can execute step 202.
[0051] Step 202: If a preset event of the main program is triggered, the event information of the triggered event is sent to the target channel.
[0052] In this embodiment, if it is detected in step 201 that a preset event of the main program is triggered, the execution subject may send event information of the triggered event to the target channel.
[0053] Here, the main program is usually the publisher, and the extended program is usually the subscriber. The above target channel is usually the channel corresponding to the above event, that is, the main program and the extended program agree that if the above event occurs, communication will be carried out through the target channel.
[0054] Here, the above-mentioned execution entity can encapsulate the triggered event into a JSON (JavaScript Object Notation, JS object notation) string. JSON is a lightweight data exchange format. The JSON string is a plain text format independent of the programming language. The syntax is concise and clear. It can represent both basic data formats and complex hierarchical objects, which is in line with the data exchange scenario of this solution.
[0055] Step 203: Send event information to an extension program that subscribes to the target channel, so that the extension program can perform a preset operation based on the event information.
[0056] In this embodiment, the execution subject may send the event information to an extension program subscribed to the target channel, so that the extension program may perform a preset operation based on the event information.
[0057] As an example, the main program can define a mouse click channel. The above event is a mouse click event. If it is detected that the user clicks on the interface, the coordinate information of the mouse click can be sent to the mouse click channel, and the extension program that subscribes to the mouse click channel can process the coordinate information. If there are currently three extension programs subscribed to the mouse click channel, the first extension program can store the coordinate information of the mouse click in the log system, the second extension program can draw a geometric figure at the click position, and the third extension program can pop up a custom menu at the click position.
[0058] Here, the above-mentioned preset events may include but are not limited to: hardware events: motor running and stopping, light barrier triggering and closing, ray beam output, etc.; software events: image noise data, scanning preheating data, image generation and saving, marking data generation and saving, etc.; user interaction events: user buttons, mouse, touch screen, etc. are triggered.
[0059] The data of these events can be subscribed by the extension program and processed accordingly. At the same time, the main program also opens a series of service interfaces to facilitate the extension program to directly operate the scanning components, which is conducive to completing some highly customized tasks to adapt to industry customers and lay a solid foundation for enterprises to quickly respond to customer needs. In addition, due to the clear boundaries between the main program and the extension program, the development threshold is low and debugging is easy, which effectively shortens the development cycle of customized projects and improves the competitiveness of enterprise products.
[0060] from Figure 2 It can be seen that Figure 1 Compared with the corresponding embodiment, the process 200 of the application extension method in this embodiment embodies the steps of sending event information from the main program to the extension program. Therefore, the scheme described in this embodiment uses the main program as the publisher and the extension program as the subscriber, realizing the routing function for event information between the two.
[0061] Continue to see Figure 3 , Figure 3 FIG. 1 is a schematic diagram of an application scenario of the application extension method according to this embodiment. Figure 3 In the application scenario, the main program encapsulates the time information of its own event into a JSON string and publishes it through the target channel. Extensions 1, 2, and 3 that have subscribed to the target channel can receive the event information of the event.
[0062] Further references Figure 4 , which shows a process 400 of another embodiment of the application extension method. In the process 400 of the application extension method, the first program is an extension program, and the second program is a main program. The process includes the following steps:
[0063] Step 401, detecting whether a preset service subscribed by the extension program is requested.
[0064] In this embodiment, the execution subject of the application extension method can detect whether the preset service subscribed by the extension program is requested. The above-mentioned execution subject can monitor the preset services subscribed by the extension program and detect whether these preset services are requested. If the preset service subscribed by the extension program is requested, the above-mentioned execution subject can execute step 402.
[0065] Step 402: If the preset service subscribed by the extension program is requested, the service request parameter of the requested service is sent to the target channel.
[0066] In this embodiment, if it is detected in step 401 that the preset service subscribed by the extension program is requested, the execution subject may send the service request parameter of the requested service to the target channel.
[0067] Here, the extension program is usually the publisher, and the main program is usually the subscriber. The above target channel is usually the channel corresponding to the above service, that is, the main program and the extension program agree that if the above service is requested, communication will be carried out through the target channel.
[0068] Here, the execution subject may encapsulate the service request parameters of the requested service into a JSON string.
[0069] Step 403: Send service request parameters to the main program subscribing to the target channel, so that the main program can perform preset operations based on the service request parameters.
[0070] In this embodiment, the execution subject can send the service request parameters to the main program subscribed to the target channel, so that the main program can perform preset operations based on the service request parameters, that is, the main program will process according to the service agreement. If the main program needs to return the processing result, it can inform the extension program again by publishing an event.
[0071] As an example, if the current main program is a control program for a VR (Virtual Reality) head-mounted device, after the control program is started, it will publish a service for playing 3D videos to the extension program. After that, all extension programs that have subscribed to the service can use the channel corresponding to the service to interact with the control program. When an extension program wants to play a 3D video, it can send 3D video playback request parameters (including the path and format of the video) to the channel. After the main program of the VR head-mounted device receives the 3D video playback request parameters, it will start the corresponding video playback.
[0072] from Figure 4 It can be seen that Figure 1 Compared with the corresponding embodiment, the process 400 of the application extension method in this embodiment reflects the steps of the extension program calling the service of the main program. Therefore, the solution described in this embodiment uses the extension program as the publisher and the main program as the subscriber, and realizes the routing function between the two for service request parameters.
[0073] See also Figure 5 , Figure 5 FIG. 1 is a schematic diagram of another application scenario of the application expansion method according to this embodiment. Figure 5In the application scenario, the extension program encapsulates the service request parameters into a JSON string and sends it to the main program through the target channel. The main program receives the service request parameters and provides corresponding services.
[0074] Continue to refer Figure 6 , which shows a process 600 of another embodiment of an application extension method. The first program and the second program in the process 600 of the application extension method are both extension programs, and the process includes the following steps:
[0075] Step 601: Detect whether the extension program sends a broadcast to a target channel.
[0076] In this embodiment, the execution subject of the application extension method can detect whether the extension program sends a broadcast to the target channel. The above-mentioned target channel is usually a channel pre-agreed between the above-mentioned extension program and other extension programs. The extension program that sends the broadcast is the publisher, and the extension program that receives the broadcast is the subscriber. The above-mentioned broadcast can be used by other extension programs to discover the extension program that sends the broadcast.
[0077] If it is detected that the extension program sends a broadcast to the target channel, the execution subject may execute step 602 .
[0078] Step 602: If the extension program sends a broadcast to the target channel, then the broadcast is sent to the extension program subscribed to the target channel, so that the extension program subscribed to the target channel performs a preset operation based on the broadcast.
[0079] In this embodiment, if it is detected in step 601 that the extension program sends a broadcast to the target channel, the execution subject may send the broadcast to the extension program subscribed to the target channel. After receiving the broadcast, the extension program subscribed to the target channel may discover the extension program sending the broadcast. Afterwards, the extension program sending the broadcast and the extension program receiving the broadcast may establish further communication according to the agreed protocol.
[0080] from Figure 6 It can be seen that Figure 1 Compared with the corresponding embodiment, the process 600 of the application extension method in this embodiment embodies the steps of communication between extension programs. Therefore, the scheme described in this embodiment can realize the communication between extension programs without the participation of the main program. The traditional plug-in-based program extension method needs to use the main program as a bridge to complete the communication between plug-ins, including the subsequent data exchange after the detection of the plug-in availability. This method of the present solution is simpler than the traditional plug-in-based program extension.
[0081] In some optional implementations, the above-mentioned interface message generally includes an event list field and / or a service list field, the above-mentioned event list field is generally used to represent at least one event, each event includes a channel name field corresponding to the event, and the above-mentioned service list field is generally used to represent at least one service, each service includes a channel name field corresponding to the service.
[0082] Further references Figure 7 , which shows a process 700 of an embodiment of program startup in an application extension method. The process 700 of program startup includes the following steps:
[0083] Step 701: In response to detecting that the main program is started, subscribing to a feedback channel for the main program.
[0084] In this embodiment, the execution subject of the application extension method can detect whether the main program is started. If the execution subject detects that the main program is started, the execution subject can subscribe to a feedback channel for the main program. The feedback channel is usually used to receive the startup result of the extension program.
[0085] Step 702: traverse the extension program directory to start the extension program, and send the start result of the extension program to the feedback channel.
[0086] In this embodiment, the execution subject can traverse the extension program directory to start the extension program. The extension program directory usually includes multiple extension programs. After the extension program is started, the extension program usually sends the start result of the extension program to the feedback channel.
[0087] Here, the above startup result usually includes an extension program identifier (ID) and a startup success identifier. The main program compares the IDs to know which extension program is started and whether the extension program is successfully started. For example, if the startup success identifier is "1", it means that the extension program is successfully started; if the startup success identifier is "0", it means that the extension program fails to start.
[0088] The method provided by the above embodiment of the present disclosure detects the startup of the main program, subscribes the main program to a feedback channel for receiving the startup result of the extended program; then, the extended program is started, and the startup result of the extended program is sent to the feedback channel. In this way, the routing function of the startup result of the extended program between the extended program and the main program is realized by using the message queue mode during the program startup process.
[0089] In some optional implementations, the extension program directory may include at least one extension program subdirectory, each extension program subdirectory may include an extension program and an extension program configuration file, the extension program configuration file generally includes a startup flag and an extension program flag, the startup flag is generally used to inform the main program whether the extension program needs to be started. As an example, if the startup flag is "1", it means that the main program needs to start the extension program; if the startup flag is "0", it means that the main program does not need to start the extension program.
[0090] like Figure 8 As shown, Figure 8 A schematic diagram of the structure of the extension program directory in the application extension method is shown. Figure 8 In the example, the extension directory includes subdirectory 1, subdirectory 2, and subdirectory 3. Each subdirectory contains extensions and configuration files. Taking subdirectory 1 as an example, the configuration file of subdirectory 1 includes a startup flag, an extension ID, and an extension custom configuration. The extension ID is unique for each extension and is used by the extension to identify itself to the main program. Each extension can also put its own unique configuration into the extension custom configuration, which is not required here.
[0091] In some optional implementations, the startup result may include a startup success flag and detailed information. If the startup success flag indicates a startup failure, the detailed information generally includes a failure reason. As an example, the failure reason may be an interface version mismatch.
[0092] In some optional implementations, after sending the startup result of the above-mentioned extension program to the above-mentioned feedback channel, the above-mentioned execution subject can detect whether the above-mentioned extension program has been started. Here, detecting whether the above-mentioned extension program has been started usually refers to detecting whether the target extension program has been started. The above-mentioned target extension program usually includes extension programs with higher priority and extension programs that must be started. If it is detected that the above-mentioned extension program has been started, the above-mentioned main program can publish an interface message for the above-mentioned extension program to subscribe to the channel indicated by the above-mentioned interface message. The above-mentioned interface message usually includes information about the channel corresponding to the service and / or event, so that the extension program can subscribe to the channel corresponding to the required service or event. In this way, a channel is provided for the subsequent interaction between the main program and the extension program.
[0093] It should be noted that the above interface message may also include an application name and a version number. The version number is used to indicate the version of the current main program and is used for compatibility determination of the extended program.
[0094] The traditional plug-in-based application expansion method also has the problem of a cumbersome plug-in interface identification process. After the main program loads the plug-in, it is necessary to search for the address of the interface function one by one according to the pre-agreed plug-in interface. If it does not exist, the function pointer needs to be set to null and ignored in subsequent interface calls. This identification process often requires filling in lengthy codes, especially for plug-ins with many interface functions, the loading process is more cumbersome.
[0095] Compared with the traditional plug-in-based application expansion method, in this solution, the main program does not need to actively identify whether the plug-in interface meets the requirements. Instead, this identification process is handed over to the extension program, which determines whether it can be loaded normally, thereby simplifying the development of the main program.
[0096] In some optional implementations, the above-mentioned interface message generally includes an event list field and / or a service list field, the above-mentioned event list field is generally used to represent at least one event, each event includes a channel name field corresponding to the event, and the above-mentioned service list field is generally used to represent at least one service, each service includes a channel name field corresponding to the service.
[0097] It should be noted that each event may also include an event details field, which is a paragraph of explanatory text, usually used to explain what parameters the event contains, the type of parameters and their meanings. Each service may also include a service details field, which is a paragraph of explanatory text, usually used to explain what parameters need to be passed when requesting the service, the type of parameters and their meanings.
[0098] like Fig. 9 As shown, Fig. 9 A schematic diagram showing a comparison between a conventional application extension method and the application extension method disclosed in the present invention. Fig. 9 In the figure, the arrow on the left is the traditional application extension method, and the arrow on the right is the Redis-based application extension method of this solution. In the traditional main program plug-in extension method, the main program needs to define the plug-in interface in the form of abstract class and virtual function, while in this solution, the interface is defined as a Redis channel. Compared with the plug-in extension method, the channel is equivalent to the virtual function inside the abstract class, and the events published in the channel are equivalent to the parameters of the pure virtual function.
[0099] In addition, the benefit of using JSON plain text for data exchange is that it facilitates the development and debugging of extensions, and there is no binary compatibility problem. In the plug-in mode, if the type, quantity and order of the plug-in interface parameters defined by the main program are inconsistent with the plug-in actually loaded, an exception will occur during the call process, which will cause the entire program to crash. In the process of exchanging JSON data format, even if the data format sent by the main program through the channel is inconsistent with the expectations of the extension program, no exception will occur during the data parsing process, which ensures the stability of the main program and the extension program. It should be noted that the extension program can even determine the current version of the main program by detecting the JSON data format, so as to achieve compatibility with various versions of the main program.
[0100] Further references Fig.10 As an implementation of the methods shown in the above figures, the present application provides an embodiment of an application expansion device, and the device embodiment is Figure 1 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0101] like Fig.10 As shown, the application extension device 1000 of this embodiment includes: a detection unit 1001 and a sending unit 1002. The detection unit 1001 is used to detect whether the first program sends a message to the target channel; the sending unit 1002 is used to send the message to the second program subscribed to the target channel if the first program sends the message to the target channel, so that the second program performs a preset operation based on the message, wherein at least one of the first program and the second program is an extension program.
[0102] In this embodiment, the specific processing of the detection unit 1001 and the sending unit 1002 of the application expansion device 1000 can refer to Figure 1 This corresponds to step 101 and step 102 in the embodiment.
[0103] In some optional implementations, the first program is the main program, and the second program is an extended program; and the detection unit 1001 can be further used to detect whether the first program sends a message to the target channel in the following manner: detect whether a preset event of the main program is triggered; if so, send the event information of the triggered event to the target channel, wherein the target channel is the channel corresponding to the event.
[0104] In some optional implementations, the first program is an extension program, and the second program is a main program; and the detection unit 1001 can be further used to detect whether the first program sends a message to the target channel in the following manner: detect whether the preset service subscribed by the extension program is requested; if so, send the service request parameters of the requested service to the target channel, wherein the target channel is the channel corresponding to the service.
[0105] In some optional implementations, the first program and the second program are both extended programs; and the detection unit 1001 can be further used to detect whether the first program sends a message to the target channel in the following manner: detect whether the extended program sends a broadcast to the target channel, wherein the target channel is a channel pre-agreed between the extended program and other extended programs, and the broadcast is used by other extended programs to discover the extended program that sends the broadcast.
[0106] In some optional implementations, the application extension device 1000 may further include a subscription unit (not shown in the figure) and a startup unit (not shown in the figure). The subscription unit is used to subscribe to a feedback channel for the main program in response to detecting the startup of the main program, wherein the feedback channel is used to receive the startup result of the extension program; the startup unit is used to traverse the extension program directory to start the extension program and send the startup result of the extension program to the feedback channel.
[0107] In some optional implementations, the extension program directory includes at least one extension program subdirectory, each extension program subdirectory includes an extension program and an extension program configuration file, the extension program configuration file includes a startup identifier and an extension program identifier, and the startup identifier is used to inform the main program whether the extension program needs to be started.
[0108] In some optional implementations, the startup result includes a startup success flag and detailed information. If the startup success flag indicates a startup failure, the detailed information includes a failure reason.
[0109] In some optional implementations, the application extension device 1000 may further include a publishing unit (not shown in the figure). The publishing unit is used to respond to the main program publishing an interface message in response to detecting that the extension program has been started, so that the extension program can subscribe to the channel indicated by the interface message.
[0110] In some optional implementations, the above-mentioned interface message includes an event list field and / or a service list field, the above-mentioned event list field is used to represent at least one event, each event includes a channel name field corresponding to the event, and the above-mentioned service list field is used to represent at least one service, each service includes a channel name field corresponding to the service.
[0111] In some optional implementations, the first program and the second program communicate using a remote dictionary service database.
[0112] Fig.11 An exemplary system architecture 1100 is shown to which an embodiment of the application extension method of the present disclosure can be applied.
[0113] like Fig.11 As shown, the system architecture 1100 may include terminal devices 11011, 11012, 11013, a network 1102, and a server 1103. The network 1102 is used to provide a medium for communication links between the terminal devices 11011, 11012, 11013 and the server 1103. The network 1102 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0114] The user can use the terminal devices 11011, 11012, 11013 to interact with the server 1103 through the network 1102 to send or receive messages, etc. For example, the terminal devices 11011, 11012, 11013 can send the execution result of the second program to the server 1103. Various communication client applications can be installed on the terminal devices 11011, 11012, 11013, such as video players, image scanning applications, instant messaging software, etc.
[0115] Terminal devices 11011, 11012, and 11013 can detect whether the first program sends a message to the target channel; if so, the message is sent to the second program subscribed to the target channel so that the second program can perform preset operations based on the message, wherein at least one of the first program and the second program is an extended program.
[0116] Terminal devices 11011, 11012, and 11013 can be hardware or software. When terminal devices 11011, 11012, and 11013 are hardware, they can be various electronic devices with display screens and supporting information interaction, including but not limited to XR (Extended Reality) devices, smart phones, tablet computers, laptop computers, etc. When terminal devices 11011, 11012, and 11013 are software, they can be installed in the electronic devices listed above. It can be implemented as multiple software or software modules (for example, multiple software or software modules used to provide distributed services), or it can be implemented as a single software or software module. No specific limitation is made here.
[0117] The server 1103 may be a server providing various services. The server 1103 may detect whether the first program sends a message to the target channel; if so, the server 1103 may send the message to the second program subscribed to the target channel, so that the second program may perform a preset operation based on the message, wherein at least one of the first program and the second program is an extended program.
[0118] It should be noted that the server 1103 can be hardware or software. When the server 1103 is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or it can be implemented as a single server. When the server 1103 is software, it can be implemented as multiple software or software modules (for example, for providing distributed services), or it can be implemented as a single software or software module. No specific limitation is made here.
[0119] It should also be noted that the application expansion method provided in the embodiment of the present disclosure can be executed by terminal devices 11011, 11012, 11013, in which case the application expansion device is usually set in the terminal devices 11011, 11012, 11013, or it can be executed by server 1103, in which case the application expansion device is usually set in server 1103.
[0120] It should be understood that Fig.11 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0121] Reference below Fig.12 , which shows an electronic device (eg, Fig.11 The terminal device in the embodiments of the present disclosure may include but is not limited to mobile terminals such as XR devices, mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig.12 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0122] like Fig.12As shown, the electronic device 1200 may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 1201, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1202 or a program loaded from a storage device 1208 to a random access memory (RAM) 1203. In the RAM 1203, various programs and data required for the operation of the electronic device 1200 are also stored. The processing device 1201, the ROM 1202, and the RAM 1203 are connected to each other via a bus 1204. An input / output (I / O) interface 1205 is also connected to the bus 1204.
[0123] Typically, the following devices may be connected to the I / O interface 1205: an input device 1206 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 1207 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1208 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1209. The communication device 1209 may allow the electronic device 1200 to communicate with other devices wirelessly or by wire to exchange data. Although Fig.12 The electronic device 1200 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead. Fig.12 Each block shown in the figure may represent one device, or may represent multiple devices as required.
[0124] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 1209, or installed from the storage device 1208, or installed from the ROM 1202. When the computer program is executed by the processing device 1201, the above functions defined in the method of the embodiment of the present disclosure are executed. It should be noted that the computer-readable medium described in the embodiment of the present disclosure can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection with one or more conductors, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In an embodiment of the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, an apparatus, or a device. In an embodiment of the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in combination with an instruction execution system, an apparatus, or a device. The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to: wire, optical cable, RF (radio frequency), etc., or any suitable combination of the foregoing.
[0125] The computer-readable medium may be included in the electronic device; or it may exist independently without being installed in the electronic device. The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: detects whether the first program sends a message to the target channel; if so, sends a message to the second program subscribed to the target channel, so that the second program performs a preset operation based on the message, wherein at least one of the first program and the second program is an extended program.
[0126] Computer program code for performing the operations of embodiments of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on a user's computer, partially on a user's computer, as a separate software package, partially on a user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0127] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0128] According to one or more embodiments of the present disclosure, a method for extending an application is provided, the method comprising: detecting whether a first program sends a message to a target channel; if so, sending the message to a second program subscribed to the target channel, so that the second program performs a preset operation based on the message, wherein at least one of the first program and the second program is an extended program.
[0129] According to one or more embodiments of the present disclosure, the first program is a main program, the second program is an extended program; and detecting whether the first program sends a message to a target channel comprises: detecting whether a preset event of the main program is triggered; if so, sending event information of the triggered event to the target channel, wherein the target channel is a channel corresponding to the event.
[0130] According to one or more embodiments of the present disclosure, the first program is an extension program, the second program is a main program; and detecting whether the first program sends a message to a target channel comprises: detecting whether a preset service subscribed to by the extension program is requested; if so, sending a service request parameter of the requested service to the target channel, wherein the target channel is a channel corresponding to the service.
[0131] According to one or more embodiments of the present disclosure, the first program and the second program are both extended programs; and detecting whether the first program sends a message to a target channel includes: detecting whether the extended program sends a broadcast to the target channel, wherein the target channel is a channel pre-agreed between the extended program and other extended programs, and the broadcast is used by other extended programs to discover the extended program that sends the broadcast.
[0132] According to one or more embodiments of the present disclosure, before detecting whether the first program sends a message to the target channel, the method further includes: in response to detecting that the main program is started, subscribing to a feedback channel for the main program, wherein the feedback channel is used to receive the startup result of the extended program; traversing the extended program directory to start the extended program, and sending the startup result of the extended program to the feedback channel.
[0133] According to one or more embodiments of the present disclosure, the above-mentioned extension program directory includes at least one extension program sub-directory, each extension program sub-directory includes an extension program and an extension program configuration file, the above-mentioned extension program configuration file includes a startup identifier and an extension program identifier, and the above-mentioned startup identifier is used to inform the above-mentioned main program whether the extension program needs to be started.
[0134] According to one or more embodiments of the present disclosure, the startup result includes a startup success flag and detailed information. If the startup success flag indicates a startup failure, the detailed information includes a failure reason.
[0135] According to one or more embodiments of the present disclosure, after sending the startup result of the above-mentioned extension program to the above-mentioned feedback channel, the method also includes: in response to detecting that the startup of the above-mentioned extension program is completed, the above-mentioned main program publishes an interface message for the above-mentioned extension program to subscribe to the channel indicated by the above-mentioned interface message.
[0136] According to one or more embodiments of the present disclosure, the above-mentioned interface message includes an event list field and / or a service list field, the above-mentioned event list field is used to represent at least one event, each event includes a channel name field corresponding to the event, and the above-mentioned service list field is used to represent at least one service, each service includes a channel name field corresponding to the service.
[0137] According to one or more embodiments of the present disclosure, the first program and the second program communicate using a remote dictionary service database.
[0138] According to one or more embodiments of the present disclosure, there is provided an application expansion device, which includes: a detection unit, for detecting whether a first program sends a message to a target channel; a sending unit, for sending the message to a second program subscribed to the target channel if the first program sends the message to the target channel, so that the second program can perform a preset operation based on the message, wherein at least one of the first program and the second program is an extension program.
[0139] According to one or more embodiments of the present disclosure, the first program is a main program, the second program is an extended program, and the detection unit is further used to detect whether the first program sends a message to the target channel in the following manner: detect whether a preset event of the main program is triggered; if so, send the event information of the triggered event to the target channel, wherein the target channel is the channel corresponding to the event.
[0140] According to one or more embodiments of the present disclosure, the first program is an extension program, the second program is a main program, and the detection unit is further used to detect whether the first program sends a message to the target channel in the following manner: detect whether the preset service subscribed by the extension program is requested; if so, send the service request parameters of the requested service to the target channel, wherein the target channel is the channel corresponding to the service.
[0141] According to one or more embodiments of the present disclosure, the first program and the second program are both extended programs; and the detection unit is further used to detect whether the first program sends a message to a target channel by detecting whether the extended program sends a broadcast to the target channel, wherein the target channel is a channel pre-agreed between the extended program and other extended programs, and the broadcast is used by other extended programs to discover the extended program that sends the broadcast.
[0142] According to one or more embodiments of the present disclosure, the application extension device further includes a subscription unit and a startup unit. The subscription unit is used to, in response to detecting that the main program is started, subscribe to a feedback channel for the main program, wherein the feedback channel is used to receive the startup result of the extension program; the startup unit is used to traverse the extension program directory to start the extension program, and send the startup result of the extension program to the feedback channel.
[0143] According to one or more embodiments of the present disclosure, the above-mentioned extension program directory includes at least one extension program sub-directory, each extension program sub-directory includes an extension program and an extension program configuration file, the above-mentioned extension program configuration file includes a startup identifier and an extension program identifier, and the above-mentioned startup identifier is used to inform the above-mentioned main program whether the extension program needs to be started.
[0144] According to one or more embodiments of the present disclosure, the startup result includes a startup success flag and detailed information. If the startup success flag indicates a startup failure, the detailed information includes a failure reason.
[0145] According to one or more embodiments of the present disclosure, the application extension device further includes a publishing unit. The publishing unit is used for, in response to detecting that the extension program has been started, the main program publishes an interface message for the extension program to subscribe to the channel indicated by the interface message.
[0146] According to one or more embodiments of the present disclosure, the above-mentioned interface message includes an event list field and / or a service list field, the above-mentioned event list field is used to represent at least one event, each event includes a channel name field corresponding to the event, and the above-mentioned service list field is used to represent at least one service, each service includes a channel name field corresponding to the service.
[0147] According to one or more embodiments of the present disclosure, the first program and the second program communicate using a remote dictionary service database.
[0148] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware. The units described may also be set in a processor, for example, it may be described as: a processor includes a detection unit and a sending unit. The names of these units do not constitute a limitation on the units themselves in some cases, for example, the detection unit may also be described as "a unit for detecting whether the first program sends a message to the target channel".
[0149] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the embodiments of the present disclosure is not limited to the technical solutions formed by a specific combination of the above-mentioned technical features, but should also cover other technical solutions formed by any combination of the above-mentioned technical features or their equivalent features without departing from the above-mentioned inventive concept. For example, the above-mentioned features are replaced with the technical features with similar functions disclosed in the embodiments of the present disclosure (but not limited to) to form a technical solution.
Claims
1. An application expansion method, characterized in that: include: Detecting whether the first program sends a message to the target channel; If so, the message is sent to a second program subscribed to the target channel, so that the second program performs a preset operation based on the message, wherein at least one of the first program and the second program is an extended program.
2. The method according to claim 1, characterized in that The first program is a main program, and the second program is an extended program; as well as The detecting whether the first program sends a message to the target channel includes: Detect whether the preset event of the main program is triggered; If so, the event information of the triggered event is sent to the target channel, wherein the target channel is the channel corresponding to the event.
3. The method according to claim 1, characterized in that The first program is an extended program, and the second program is a main program; and The detecting whether the first program sends a message to the target channel includes: Check if the preset service subscribed by the extension is requested; If yes, the service request parameters of the requested service are sent to the target channel, wherein the target channel is the channel corresponding to the service.
4. The method according to claim 1, characterized in that The first program and the second program are both extended programs; and The detecting whether the first program sends a message to the target channel includes: It is detected whether the extension program sends a broadcast to a target channel, wherein the target channel is a channel pre-agreed between the extension program and other extension programs, and the broadcast is used by other extension programs to discover the extension program that sends the broadcast.
5. The method according to claim 1, characterized in that Before detecting whether the first program sends a message to the target channel, the method further includes: In response to detecting that the main program is started, subscribing to a feedback channel for the main program, wherein the feedback channel is used to receive a startup result of the extended program; Traverse the extension program directory to start the extension program, and send the start result of the extension program to the feedback channel.
6. The method according to claim 5, characterized in that The extension program directory includes at least one extension program subdirectory, each extension program subdirectory includes an extension program and an extension program configuration file, the extension program configuration file includes a startup identifier and an extension program identifier, and the startup identifier is used to inform the main program whether the extension program needs to be started.
7. The method according to claim 5, characterized in that The startup result includes a startup success mark and detailed information. If the startup success mark indicates that the startup fails, the detailed information includes the reason for the failure.
8. The method according to claim 5, characterized in that After sending the startup result of the extension program to the feedback channel, the method further includes: In response to detecting that the extended program has been started, the main program publishes an interface message for the extended program to subscribe to a channel indicated by the interface message.
9. The method according to claim 8, characterized in that The interface message includes an event list field and / or a service list field, the event list field is used to represent at least one event, each event includes a channel name field corresponding to the event, and the service list field is used to represent at least one service, each service includes a channel name field corresponding to the service.
10. The method according to any one of claims 1 to 9, characterized in that: The first program and the second program communicate using a remote dictionary service database.
11. An application expansion device, characterized in that: include: A detection unit, used for detecting whether the first program sends a message to the target channel; A sending unit is used to send a message to a second program subscribed to the target channel if the first program sends the message to the target channel, so that the second program performs a preset operation based on the message, wherein at least one of the first program and the second program is an extended program.
12. An electronic device, characterized in that: include: one or more processors; a storage device having one or more programs stored thereon, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 10.
13. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 10 is implemented.