Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Most of the up-to-data examples, definitely with the new JSONRPC, can be found here: https://github.com/WebPlatformForEmbedded/ThunderNanoServices/tree/master/examples

This directory contains two Example plugins, called: JSONRPCPlugin and OutOfProcessPlugin.

This directory also contains an example on how to communicate from outside of the Thunder framework, to the ThunderFramework (bidirectional). It is not the recommended way forward to develop services "out-side" of the Thunder framework but for legacy it is shown here how that could work by the JSONRPCClient. The JSONRPC Client is a stand-alone application that connect to the JSONRPCPlugin.

For using the plugins, the documentation (API documentation ) is pretty well documented. This is due to the fact that the documentation is automatically generated from the interface specification. The API specifications for each plugin can be found here:
https://github.com/WebPlatformForEmbedded/ThunderNanoServices/blob/master/README.md


Plugins can be developed in a large variety, in process, out-of-process, out-of host, and each plugin can exploit a large scale over communication protocols, JSONRPC/COMRPC, MessagePackRPC.

Steps involved in implementing new Thunder Plug-In


  1. <PluginName>.json
    Add <PluginName>.json in wpeframework module so as to define the interfaces.

          https://github.com/WebPlatformForEmbedded/Thunder/tree/master/Source/interfaces/json

          Refer : DeviceInfo.json

          After adding the json file and compilation of wpeframework, it will autogenerate header file JsonData_PluginName.h 

          eg: JsonData_DeviceInfo.h

          This header will be used from wpeframework-plugins module. 


2. In wpeframework-plugins repo:

https://github.com/WebPlatformForEmbedded/ThunderNanoServices/

Create PluginName folder


2.1) Create a Makefile “CmakeLists.txt” to compile the Plug-in code and to generate the shared library (“.so”)

This will handle all the dependencies as well

2.2) Module.h: This header file includes the support for JSON request, response, logging etc.,

2.3) Module.cpp: This file is used to declare the module name for the Plug-in

2.4) <PluginName>Plugin.json:

This file contains the plugin's information like schema, information and interface json file etc.,

            Ex:-

                        {

                                       "$schema": "plugin.schema.json",

                                       "info": {

                                       "title": "PluginName Plugin",

                                       "callsign": "PluginName",

                                       "locator": "libWPEFrameworkPluginName.so",

                                       "status": "production",

                                       "description": "The PluginName plugin allows retrieving of various plugin-related information.",

                                       "version": "1.0"

                                        },

                                       "interface": {

                                                "$ref": "{interfacedir}/PluginName.json#"

                                        }

                        }

2.5) <PluginName>.config: This file is used to set some configurations of the Plug-in 

Ex:- set (autostart true)

Used to make the Plug-in to start automatically aling with wpeframework daemon

We can set some other parameters based on our need

2.6) <PluginName>.h

Declare the plugin class in this which should contains all the structures, variables and methods which are needed for plugin implementation.

            Ex:-   Declare the class in the following name space with constructor and destructor: 

                                     namespace WPEFramework {

                                                namespace Plugin {

                                                            class PluginName :: public PluginHost::IPlugin, public PluginHost::IWeb, public PluginHost::JSONRPC {

                                                             public:

                                                                         PluginName()

                                                                                 : _skipURL(0)

                                                                                 , _service(nullptr)

                                                                                 , _subSystem(nullptr)

                                                                             {

                                                                                           RegisterAll();

                                                                              }

 

                                                                         virtual ~PluginName()

                                                                            {

                                                                                    UnregisterAll();

                                                                             }

                                                                 }         

            Declare the methods in the above class, required to implement the functionality of the plugin 

  • These methods are used to place collection of plugin JSON interface methods to register & unregister with JSON RPCs APIs

                          void RegisterAll();

                          void UnregisterAll(); 

  • These methods are used to initialize and deinitialize the handlers for the plug-in service

                          virtual const string Initialize(PluginHost::IShell* service);

                          virtual void Deinitialize(PluginHost::IShell* service); 

  • These are are the JSON interface (get/set) methods to communicate with plugin

                         uint32_t get_method(JsonData::Plugin::ClassName& response) const;

                         uint32_t set_method(JsonData::Plugin::ClassName& response) const; 

  • This method is used to process the REST APIs request such as GET/POST/SET and return the response 

virtual Core::ProxyType<Web::Response> Process(const Web::Request& request) override;