Search

CN-117075856-B - Development system and method for asynchronous remote call based on Qt

CN117075856BCN 117075856 BCN117075856 BCN 117075856BCN-117075856-B

Abstract

The invention discloses a development framework and a method for asynchronous remote call based on Qt, the development framework for asynchronous remote call based on Qt comprises a base class and a public call function callFunc, wherein the base class realizes callSelfFunc functions, the function is searched and called through a reflection mechanism provided by Qt, the called module inherits the base class, the public call function callFunc finds out an object of the called module according to a module name, a QEventLoop object is generated, the development framework for asynchronous remote call based on Qt calls a callSelfFunc function of the called module through an invokeMethod provided by Qt, and the development framework for asynchronous remote call based on Qt calls a return value of the called module through messaging and synchronously returns to the calling module, so that the problem of logic splitting is solved, the complexity is reduced, and simultaneously, the called function which is not thread-safe can be called under a multithreaded environment, and some special application scenes are adapted.

Inventors

  • ZHENG ZE
  • LI CONGFEI
  • HAN BING
  • DENG HUA
  • ZHU JIWEI
  • LIU GUOWEI
  • QIAN WEI

Assignees

  • 国电南京自动化股份有限公司

Dates

Publication Date
20260512
Application Date
20230816

Claims (4)

  1. 1. A development system for asynchronous remote call based on Qt is characterized by comprising a base class and a public call function callFunc, The base class realizes callSelfFunc functions, the functions are searched and called through a reflection mechanism provided by Qt, and the called module inherits the base class; The common calling function callFunc finds the called module object according to the module name, generates QEventLoop object, and asynchronously calls the callSelfFunc function of the called module through the invokeMethod provided by Qt; the common calling function callFunc is a parallel calling function provided by the development framework for other modules, and supports parallel calling in a plurality of threads; the system also comprises a message development framework, a calling module and a called module; When the software is initialized, the message development framework generates a called module, the called module inherits the library file base class QObject, and the called object pointer of the calling module is stored into a called module set according to the module name; The called module inherits QObject and adds Q_OBJECT macro, and the function of the called module adds Q_ INVOKABLE or is declared under public slots; The messaging development framework includes: A messaging base class providing a base class including a messaging function sendData () and a messaging function recvData (); The configuration file provides two types of configuration information, wherein the first type of configuration information comprises a library name of a module and a generated module name, and the second type of configuration information comprises message dependence among the modules, and the message dependence is expressed as < send module name, message instruction and receive module name >; the message forwarding management engine reads configuration information from the configuration file, generates module objects according to the library name of one module and the module name required to be generated, and establishes message topology among the modules according to message dependence among the modules.
  2. 2. The development system of Qt-based asynchronous remote invocation of claim 1, wherein said QEventLoop objects are thread event loop objects provided by Qt.
  3. 3. The development system of Qt-based asynchronous remote invocation of claim 1, wherein said QEventLoop object inherits QObject class, temporarily stores data in the object via a setProperty function, and obtains temporarily stored data via the property function.
  4. 4. A method of developing a system for Qt based asynchronous remote invocation of any of claims 1-3, comprising the steps of: s1, a calling module calls a parallel calling function callFunc provided by a development framework in a thread 1, and the name of the calling module and the name of the calling function are transmitted; s2, searching a called module object according to the input module name in callFunc functions, if so, performing the next step, otherwise, directly returning; S3, searching whether the called module defines callSelfFunc functions or not, if so, carrying out the next step, otherwise, directly returning; S4, generating QEventLoop an object, asynchronously calling a callSelfFunc method of a called module through an invokeMethod provided by Qt, transferring a calling function name and a QEventLoop object, calling an exec function of the QEventLoop object, and entering an event cycle to enable callFunc to be blocked; S5, triggering the callSelfFunc method of the called module in the thread 2, searching a function entity according to the name of the called function, if so, performing the step S5, otherwise, performing the step S6; s6, calling a function of the called module in the thread 2 to obtain a return value; s7, filling the return value into QEventLoop objects, and asynchronously calling the quick function of QEventLoop objects through an invokeMethod provided by Qt; S8, returning the exec function of the QEventLoop object called in the step S4 due to the quick function called in the step S7, acquiring a return value from the QEventLoop object, and returning the callFunc function with the return value to the calling module.

Description

Development system and method for asynchronous remote call based on Qt Technical Field The invention relates to the technical field of software systems, in particular to a development framework and a development method for asynchronous remote call based on Qt. Background Modern large-scale software systems are quite complex, and are composed of various software sub-modules (modules) which are divided according to standards such as service flows, data flows and the like, certain coupling relations exist between service logics and data dependencies among different modules, and meanwhile, as the complexity of the software systems is continuously increased, different modules are often responsible for different development, test and operation and maintenance teams. Thus, the improvement of the coupling degree will present a great challenge for the maintenance and testing of the software. This is shown to be more prominent in large c++ software project engineering using the QT development framework, for example, if module a needs to call the interface of module B under the QT development framework, the strong dependency of module a on the code level of module B may be caused, where the strong dependency includes 3 aspects that module a needs to directly refer to the header file of module B, in the header file of module B, needs to explicitly declare the interface called by module a, and needs to have a corresponding implementation on the interface called by module B when compiling module a. The strong dependence can bring more design cost, communication cost and implementation cost in the actual development process, so that the problem of strong dependence in intermodulation between modules is solved, when the modules need to be called mutually, the code level of different modules is not directly dependent any more through developing a set of message transmitting and receiving development frames, and the unified message transmitting and managing engine module is responsible for interaction, thereby realizing decoupling of the code level of a software system, improving the readability, reusability and expandability of codes, reducing the communication and cooperation cost between developers of different modules, but in the use process of the message transmitting and receiving development frames, if the interaction needs to return values, the calling and the calling return need to be divided into 2 parts of logic to be completed, and the implementation complexity is increased. Disclosure of Invention This section is intended to outline some aspects of embodiments of the application and to briefly introduce some preferred embodiments. Some simplifications or omissions may be made in this section as well as in the description of the application and in the title of the application, which may not be used to limit the scope of the application. Therefore, the invention aims to provide a development framework and a development method for asynchronous remote call based on Qt, which solve the problem of logic splitting based on the development framework of messaging based on Qt, reduce the implementation complexity, and simultaneously can call a non-thread safe called function under a multithreading environment so as to adapt to some special application scenes. In order to solve the technical problems, according to one aspect of the present invention, the following technical solutions are provided: a development framework for Qt-based asynchronous remote invocation includes a base class and a common invocation function callFunc, The base class realizes callSelfFunc functions, the functions are searched and called through a reflection mechanism provided by Qt, and the called module inherits the base class; The common calling function callFunc finds the called module object according to the module name, generates QEventLoop object, and asynchronously calls the callSelfFunc function of the called module through the invokeMethod provided by Qt. As a preferred scheme of the method of the development framework of the asynchronous remote call based on the Qt, the common call function callFunc is a parallel call function provided by the development framework for other modules and supports parallel call in a plurality of threads. As a preferred scheme of the development framework method based on the Qt asynchronous remote call, the QEventLoop object is a thread event loop object provided by the Qt. As a preferred scheme of the method of the development framework based on the Qt asynchronous remote call, the invention further comprises a messaging development framework, a calling module and a called module; When the software is initialized, the message development framework generates a called module, the called module inherits the library file base class QObject, and the called object pointer of the calling module is stored into a called module set according to the module name; the called module inherits QObject and adds the Q_OBJECT