Disclosure of Invention
In order to make up the defects of the prior art, the invention provides a communication method and a communication system of a cross-platform API and an SPI based on PISA.
In order to solve the technical problems, the invention adopts the following technical scheme:
in a first aspect, a method for communicating a cross-platform API and an SPI based on PISA is provided, which is applied to a communication system of the cross-platform API and the SPI based on PISA, the communication system of the cross-platform API and the SPI based on PISA includes an application layer, a local manager, and a remote device, the local manager has an API layer, the remote device has a cross-platform SPI service layer and an SPI layer, and the method for communicating includes:
when the application layer needs to call a target SPI through an API, the API sends an API call request to a local end manager;
the local end manager generates a callback message object name, registers the callback message object name to a local message center, adds the callback message object name with the network address of the API and sends the callback message object name to the cross-platform SPI service layer;
the local end manager sends an API call request to a cross-platform SPI service layer;
the cross-platform SPI service layer executes target SPI call according to the API call request, and generates a completion message;
and the cross-platform SPI service layer sends the completion message to the terminal machine where the API is located through the local terminal manager according to the network address in the callback message object name.
Further, the method further comprises:
the local end manager establishes a network communication mode between a cross-platform SPI service layer and an API layer;
the network communication mode supports various operating systems;
the home terminal manager has a message service function based on a network communication mode, and the message service function supports object name registration and message sending.
Further, the home terminal manager generates a callback message object name, registers the callback message object name to a local message center, and sends the callback message object name plus a network address of an API to a cross-platform SPI service layer, including:
the local end manager reads preset configuration information and determines SPI service call of the remote equipment according to the preset configuration information;
the home terminal manager selects a registration message callback function according to SPI service call of the remote terminal equipment, and generates a callback message object name;
the local terminal manager registers the callback message object name to a local message center, so as to realize message subscription of the terminal machine where the API is located;
and the home terminal manager adds the name of the callback message object and the network address of the API and then sends the callback message object name to the cross-platform SPI service layer.
Further, registering the callback message object name to the local message center includes:
the local end manager adds a process character behind the callback message object name to obtain the internal message object name, and registers the internal message object name to the local message center.
Further, the home terminal manager sends the callback message object name plus the network address of the API to the cross-platform SPI service layer, including:
the home terminal manager adds the name of the callback message object and the network address of the API and then sends the callback message object name to the cross-platform SPI service layer;
registering the callback message object name and the network address of the API into the SPI layer by the cross-platform SPI service layer to generate a registration process event message;
the cross-platform SPI service layer judges whether the registration is successful according to the event message in the registration process; if the registration fails, no step is executed;
if the registration is successful, the cross-platform SPI service layer processes the event message in the registration process according to a preset message conversion rule to obtain a JSON character string, and the JSON character string is sent to a local end manager;
the local terminal manager converts the JSON character string into a parameter structure body with a preset structure, and sends the parameter structure body to the terminal machine where the API is located according to the network address of the API.
In a second aspect, a communications system of a cross-platform API and an SPI based on PISA is provided, including:
an application layer, a local end manager and a remote end device;
the local end manager is provided with an API layer, and the remote end equipment is provided with a cross-platform SPI service layer and an SPI layer;
when the application layer needs to call a target SPI through an API, the API sends an API call request to a local end manager;
the local end manager generates a callback message object name, registers the callback message object name to a local message center, and sends the callback message object name plus the network address of the API to a cross-platform SPI service layer, so that a message subscription mechanism is realized;
the local end manager sends an API call request to a cross-platform SPI service layer;
the cross-platform SPI service layer executes target SPI call according to the API call request, and generates a completion message;
and the cross-platform SPI service layer sends the completion message to the terminal machine where the API is located through the local terminal manager according to the network address in the callback message object name.
Further, the local end manager establishes a network communication mode between the cross-platform SPI service layer and the API layer;
the network communication mode supports various operating systems;
the home terminal manager has a message service function based on a network communication mode, and the message service function supports object name registration and message sending.
Further, the home terminal manager reads preset configuration information, and determines SPI service call of the remote equipment according to the preset configuration information;
the home terminal manager selects a registration message callback function according to SPI service call of the remote terminal equipment, and generates a callback message object name;
and the home terminal manager sends the callback message object name plus the network address of the API to the cross-platform SPI service layer, so that a message subscription mechanism is realized.
Further, the local end manager adds a process character behind the callback message object name to obtain the internal message object name, and registers the internal message object name in the local message center.
Further, the home terminal manager adds the name of the callback message object with the network address of the API and then sends the callback message object name to the cross-platform SPI service layer;
registering the callback message object name and the network address of the API into the SPI layer by the cross-platform SPI service layer to generate a registration process event message;
the cross-platform SPI service layer judges whether the registration is successful according to the event message in the registration process; if the registration fails, no step is executed;
if the registration is successful, the cross-platform SPI service layer processes the event message in the registration process according to a preset message conversion rule to obtain a JSON character string, and the JSON character string is sent to a local end manager;
the local terminal manager converts the JSON character string into a parameter structure body with a preset structure, and sends the parameter structure body to the terminal machine where the API is located according to the network address of the API.
The invention has the beneficial effects that:
when the application layer needs to call a target SPI through an API, the API sends an API call request to a local end manager; the local end manager generates a callback message object name, registers the callback message object name to a local message center, adds the callback message object name with the network address of the API and sends the callback message object name to the cross-platform SPI service layer; the local end manager sends an API call request to a cross-platform SPI service layer; the cross-platform SPI service layer executes target SPI call according to the API call request, and generates a completion message; and the cross-platform SPI service layer sends the completion message to the terminal machine where the API is located through the local terminal manager according to the network address in the callback message object name. Through establishing the message subscription between the API and the cross-platform SPI service layer, the function of calling the SPI by the API in a cross-platform manner is realized, and the problem that communication between the API and the SPI is impossible between different operating system platforms based on PISA is solved.
Detailed Description
The invention is further described below with reference to the accompanying drawings. The following examples are only for more clearly illustrating the technical aspects of the present invention, and are not intended to limit the scope of the present invention.
The structure of the communication system of the cross-platform API and SPI based on PISA in the invention is shown in figure 1, which comprises an application layer 101, a local end manager 102 and a remote end device 103, wherein the local end manager 102 is provided with an API layer 104, and the remote end device 103 is provided with a cross-platform SPI service layer 105 and an SPI layer 106;
the home terminal manager 102 establishes a network communication mode between the cross-platform SPI service layer 105 and the API layer 104; the network communication mode supports various operating systems; the home terminal manager 102 is provided with a local message service center based on a network communication mode, and supports object name registration and message sending; the API layer 104 is used for completing the call from the API to the cross-platform SPI service layer; the cross-platform SPI service layer 105 provides SPI service implementation, provides external service capability, and realizes SPI service through an SPI interface of an SPI layer loading manufacturer.
The method for realizing the service of the API cross-platform call SPI in the embodiment of the invention is the same as the application for calling the local SPI or the cross-platform SPI when calling the API, the interface provided by the manufacturer SPI is the same, and the cross-platform call is realized by the capability provided by the local end manager.
Based on the above communication system based on the cross-platform API and the SPI of the PISA shown in fig. 1, as shown in fig. 2, an embodiment of the present invention provides a method for communicating between the cross-platform API and the SPI of the PISA, including:
201, when an application layer needs to call a target SPI through an API, the API sends an API call request to a local end manager;
the API call request contains interface information of the target SPI.
202, the home terminal manager generates a callback message object name, registers the callback message object name to a local message center, adds the network address of an API to the callback message object name and then sends the callback message object name to a cross-platform SPI service layer;
since this embodiment needs to solve the problem of SPI service call of the remote device, configuration information needs to be preset, and for SPI service call of the remote device, the uniform resource locator (Uniform Resource Locator, URL) address information of the configuration information needs to have information such as a network address, a service port, a network communication protocol, and a routing path of a server where the remote device is located. The present embodiment supports both as to whether the network address of the server where the remote device is located is a gateway-forwarded or real address;
the home terminal manager can determine SPI service call of the remote terminal device by reading the preset configuration information;
because the API supports two modes to acquire event messages of the home terminal manager, the event messages are respectively acquired for a registration message callback function and a message queue, and the principle of the registration message callback function is as follows: the local end manager receives the message of the message object name and triggers the callback function to inform the API layer, the API acquires the message interface of the message object name, and the first event message of the queue can be acquired from the queue of the message object name of the manager. Therefore, the home terminal manager selects a registration message callback function according to SPI service call of the remote terminal equipment, and generates a callback message object name;
because the APIs of different processes call the local end manager to possibly transmit the same message object names, the local end manager adds process characters, such as <.p process number > characters, behind the message object names so as to obtain the internal message object names, registers the internal message object names to a local message center, realizes the message subscription of the terminal machine where the APIs are located, enables the terminal machine where the APIs are located to be used as a message subscriber, and can notify the event message to the APIs according to the process characters when the message service of the local end server receives the event message corresponding to the internal message object names;
after the home terminal manager finishes the internal registration, the home terminal manager also needs to finish the registration at the remote terminal equipment side;
the local end manager adds the name of the callback message object and the network address of the API to the cross-platform SPI service layer, and the network address of the API is used for conveniently and accurately finding out the network equipment where the API is located;
registering the callback message object name and the network address of the API into the SPI layer by the cross-platform SPI service layer to generate a registration process event message;
the cross-platform SPI service layer judges whether the registration is successful according to the event message in the registration process; if the registration fails, no step is executed;
if the registration is successful, the cross-platform SPI service layer processes the event message in the registration process according to a preset message conversion rule to obtain a JSON character string, and the JSON character string is sent to a local end manager; the preset message conversion rule is to convert according to the known keywords described by the PISA document, and the name representation of the key in the JSON character string is named according to the parameter name described by the PISA document; the type rule processing of the value in the JSON string is as follows:
shaping and converting according to shaping;
the character string can be processed according to the character string;
the character array or invisible characters are processed according to the base64 characters; base64 is one of the common encoding schemes used to transmit 8Bit bytecodes;
the pointer is processed according to the JSON object;
the pointer array is processed according to the JSON object array;
the local end manager converts the JSON character string into a parameter structure body with a preset structure, and sends the parameter structure body to the API according to the network address of the API, so that the completion of a registration process event is determined, a message subscription mechanism is realized, the parameter structure body with the preset structure is specifically a C structure body, and specific structural rules of the C structure body are known in the prior art and are not repeated.
203, the home terminal manager sends an API call request to a cross-platform SPI service layer;
on the basis that the message subscription mechanism is completed and the realization of the cross-platform SPI call of the API is guaranteed, the local manager converts the API call request into a JSON character string and sends the JSON character string to the cross-platform SPI service layer.
204, the cross-platform SPI service layer executes target SPI call according to the API call request, and generates a completion message;
the cross-platform SPI service layer restores the JSON character string into an API call request, a target SPI call command can be determined according to interface information of a target SPI in the API call request, and after the API call request is received, the received condition is responded to the API through a local end manager;
and after the call of the target SPI is executed through the call command of the target SPI, generating a completion message.
And 205, the cross-platform SPI service layer sends the completion message to the terminal machine where the API is located through the local terminal manager according to the network address in the callback message object name.
Based on the established message subscription in the steps, the cross-platform SPI service layer converts the completion message into a JSON character string and then sends the JSON character string to the local end manager, and after the local end manager recovers the completion message, the local end manager sends the completion message to the end machine where the API is located, so that the completion of the API call target SPI can be determined.
The implementation principle of the embodiment of the invention is as follows:
when the application layer needs to call a target SPI through an API, the API sends an API call request to a local end manager; the local end manager generates a callback message object name, registers the callback message object name to a local message center, adds the callback message object name with the network address of the API and sends the callback message object name to the cross-platform SPI service layer; the local end manager sends an API call request to a cross-platform SPI service layer; the cross-platform SPI service layer executes target SPI call according to the API call request, and generates a completion message; and the cross-platform SPI service layer sends the completion message to the terminal machine where the API is located through the local terminal manager according to the network address in the callback message object name. Through establishing the message subscription between the API and the cross-platform SPI service layer, the function of calling the SPI by the API in a cross-platform manner is realized, and the problem that communication between the API and the SPI is impossible between different operating system platforms based on PISA is solved.
In combination with the system structure shown in fig. 1 and the communication method of the cross-platform API and the SPI based on PISA shown in fig. 2, the embodiment of the invention provides a communication system of the cross-platform API and the SPI based on PISA, which comprises:
an application layer 101, a home manager 102, and a remote device 103;
the local end manager 102 has an API layer 104, and the remote end device 103 has a cross-platform SPI service layer 105 and an SPI layer 106;
when the application layer 101 needs to call the target SPI through the API, the API sends an API call request to the local end manager 102;
the home terminal manager 102 generates a callback message object name, registers the callback message object name to a local message center, and sends the callback message object name plus the network address of the API to the cross-platform SPI service layer 105, so that a message subscription mechanism is realized;
the home manager 102 sends an API call request to the cross-platform SPI service layer 105;
the cross-platform SPI service layer executes target SPI call according to the API call request, and generates a completion message;
the cross-platform SPI service layer 105 sends the completion message to the end machine where the API is located through the home terminal manager 102 according to the network address in the callback message object name.
It should be noted that, in this embodiment, the message or data interaction between each unit, module, device or apparatus refers to the specific description in the embodiment shown in fig. 2, so as to achieve the purpose of calling the SPI by the API across platforms.
The implementation principle of the embodiment of the invention is as follows:
in the communication system of the cross-platform API and the SPI based on the PISA, when the application layer 101 needs to call a target SPI through the API, the API sends an API call request to the local end manager 102; the home terminal manager 102 generates a callback message object name, registers the callback message object name to a local message center, adds the network address of an API to the callback message object name, and sends the callback message object name to the cross-platform SPI service layer 105; the home manager 102 sends an API call request to the cross-platform SPI service layer 105; the cross-platform SPI service layer executes target SPI call according to the API call request, and generates a completion message; the cross-platform SPI service layer 105 sends a completion message to the end machine where the API is located through the home terminal manager 102 according to the network address in the callback message object name, so that the application layer determines that the API call target SPI is completed. By establishing a message subscription mechanism between the API and the cross-platform SPI service layer, the function of calling the SPI by the API in a cross-platform manner is realized, and the problem that communication between the API and the SPI is impossible between different operating system platforms based on PISA is solved.
It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The foregoing is illustrative of the present invention and is not to be construed as limiting thereof, but rather as providing for the use of additional embodiments and advantages of all such modifications, equivalents, improvements and similar to the present invention are intended to be included within the scope of the present invention as defined by the appended claims.