|
| 1 | +--- |
| 2 | +description: Guidelines for C++ files and header files that share the same name as their parent folder. |
| 3 | +applyTo: "**/*.cpp,**/*.h" |
| 4 | +--- |
| 5 | + |
| 6 | +# Instructions summary |
| 7 | + 1. [Interface Implementation](#interface-implementation) |
| 8 | + 2. [Service Registration](#service-registration) |
| 9 | + 3. [JSON-RPC Stub Registration](#json-rpc-stub-registration) |
| 10 | + 4. [Handling Out-of-Process Plugin Failures](#handling-out-of-process-plugin-failures) |
| 11 | + |
| 12 | +### Interface Implementation |
| 13 | + |
| 14 | +### Requirement |
| 15 | + |
| 16 | +Each plugin must implement the appropriate Thunder interfaces. |
| 17 | + |
| 18 | +-> PluginHost::IPlugin – Mandatory for all plugins. |
| 19 | + |
| 20 | +-> PluginHost::IDispatcher or derive from PluginHost::JSONRPC – Mandatory If the plugin handles JSON-RPC. |
| 21 | + |
| 22 | +-> Custom interfaces (like IHdcpProfile for HdcpProfile plugin) must be added to ThunderInterfaces for RPC. |
| 23 | + |
| 24 | +-> PluginHost::IWeb – If the plugin handles web requests. |
| 25 | + |
| 26 | + |
| 27 | +### Example |
| 28 | + |
| 29 | +```cpp |
| 30 | +BEGIN_INTERFACE_MAP(HdcpProfile) |
| 31 | + INTERFACE_ENTRY(PluginHost::IPlugin) |
| 32 | + INTERFACE_ENTRY(PluginHost::IDispatcher) |
| 33 | + INTERFACE_AGGREGATE(Exchange::IHdcpProfile, _hdcpProfile) |
| 34 | +END_INTERFACE_MAP |
| 35 | +``` |
| 36 | +
|
| 37 | +### Service Registration |
| 38 | +
|
| 39 | +### Requirement |
| 40 | +
|
| 41 | +All Thunder services must be registered using the SERVICE_REGISTRATION macro with name, major, minor and patch versions of service. Register the service using the following macro: |
| 42 | +
|
| 43 | +``` |
| 44 | +SERVICE_REGISTRATION(ServiceName, MAJOR, MINOR, PATCH) |
| 45 | +``` |
| 46 | +
|
| 47 | +For better readability, it is always good to define the following plugin metadata which is not mandatory: |
| 48 | +
|
| 49 | +- **Precondition** - List of Thunder subsystems that must be active in order for the plugin to activate. This can also be set in Plugin.conf.in file. |
| 50 | +
|
| 51 | +- **Terminations** - List of Thunder subsystems that will cause the plugin to deactivate if they are marked inactive whilst the plugin is running. |
| 52 | +
|
| 53 | +- **Controls** - List of the subsystems that are controlled by the plugin. |
| 54 | +
|
| 55 | +### Example |
| 56 | +
|
| 57 | +```cpp |
| 58 | +namespace WPEFramework { |
| 59 | + namespace { |
| 60 | + static Plugin::Metadata<Plugin::HdcpProfile> metadata( |
| 61 | + API_VERSION_NUMBER_MAJOR, |
| 62 | + API_VERSION_NUMBER_MINOR, |
| 63 | + API_VERSION_NUMBER_PATCH, |
| 64 | + {}, // Preconditions |
| 65 | + {}, // Terminations |
| 66 | + {} // Controls |
| 67 | + ); |
| 68 | + } |
| 69 | +
|
| 70 | + namespace Plugin { |
| 71 | + // Register HdcpProfile service with Thunder |
| 72 | + SERVICE_REGISTRATION(HdcpProfile,API_VERSION_NUMBER_MAJOR,API_VERSION_NUMBER_MINOR,API_VERSION_NUMBER_PATCH); |
| 73 | + } |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +### JSON-RPC Stub Registration |
| 78 | + |
| 79 | +### Requirement |
| 80 | + |
| 81 | +If the plugin includes <interfaces/IPluginName*.h>, <interfaces/JsonData_PluginName.h>, and <interfaces/JPluginName.h> and inherits from PluginHost::JsonRPC, then it provides JSON‑RPC support and uses autogenerated JSON‑RPC stubs. |
| 82 | + |
| 83 | +These autogenerated stubs are the Exchange::J* C++ classes (for example, Exchange::JHdcpProfile and JsonData_HdcpProfile.h) that are produced by the Thunder JSON‑RPC code generator from the IPluginName* interface headers; they expose the C++ interface over JSON‑RPC so you do not have to call Register() for each method manually. |
| 84 | + |
| 85 | +Plugins using autogenerated JSON-RPC stubs (Exchange::J* classes) must register and unregister them in Initialize() and Deinitialize() methods. Do not register or unregister them in the constructor or destructor. |
| 86 | + |
| 87 | +In Initialize(): |
| 88 | + |
| 89 | +```cpp |
| 90 | +Exchange::JHdcpProfile::Register(*this, _hdcpProfile); |
| 91 | +``` |
| 92 | +
|
| 93 | +In Deinitialize(): |
| 94 | +
|
| 95 | +```cpp |
| 96 | +Exchange::JHdcpProfile::Unregister(*this); |
| 97 | +``` |
| 98 | + |
| 99 | +It is strongly recommended to use the autogenerated JSON-RPC stubs rather than registering the json-rpc methods manually as below. |
| 100 | + |
| 101 | +```cpp |
| 102 | +RDKShell::RDKShell() |
| 103 | + ... |
| 104 | +{ |
| 105 | + ..... |
| 106 | + Register(RDKSHELL_METHOD_MOVE_TO_FRONT, &RDKShell::moveToFrontWrapper, this); |
| 107 | + Register(RDKSHELL_METHOD_MOVE_TO_BACK, &RDKShell::moveToBackWrapper, this); |
| 108 | + ... |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +### Handling Out-of-Process Plugin Failures |
| 113 | + |
| 114 | +### Requirement |
| 115 | + |
| 116 | +- If the plugin runs as out-of-process, then it should implement RPC::IRemoteConnection::INotification interface inside your plugin. |
| 117 | + |
| 118 | +### Example |
| 119 | + |
| 120 | +```cpp |
| 121 | +class TestPlugin : public PluginHost::IPlugin, public PluginHost::JSONRPC { |
| 122 | +private: |
| 123 | + class Notification : public RPC::IRemoteConnection::INotification { |
| 124 | + public: |
| 125 | + explicit Notification(TestPlugin* parent) |
| 126 | + : _parent(*parent) |
| 127 | + { |
| 128 | + ASSERT(parent != nullptr); |
| 129 | + } |
| 130 | + |
| 131 | + ~Notification() override = default; |
| 132 | + |
| 133 | + Notification(Notification&&) = delete; |
| 134 | + Notification(const Notification&) = delete; |
| 135 | + Notification& operator=(Notification&&) = delete; |
| 136 | + Notification& operator=(const Notification&) = delete; |
| 137 | + |
| 138 | + public: |
| 139 | + void Activated(RPC::IRemoteConnection* /* connection */) override |
| 140 | + { |
| 141 | + } |
| 142 | + void Deactivated(RPC::IRemoteConnection* connectionId) override |
| 143 | + { |
| 144 | + _parent.Deactivated(connectionId); |
| 145 | + } |
| 146 | + |
| 147 | + BEGIN_INTERFACE_MAP(Notification) |
| 148 | + INTERFACE_ENTRY(RPC::IRemoteConnection::INotification) |
| 149 | + END_INTERFACE_MAP |
| 150 | + |
| 151 | + private: |
| 152 | + TestPlugin& _parent; |
| 153 | + }; |
| 154 | + |
| 155 | +public: |
| 156 | + TestPlugin() |
| 157 | + : _connectionId(0) |
| 158 | + , _service(nullptr) |
| 159 | + , _testPlugin(nullptr) |
| 160 | + , _notification(this) |
| 161 | + { |
| 162 | + } |
| 163 | + ~TestPlugin() override = default; |
| 164 | + |
| 165 | + TestPlugin(TestPlugin&&) = delete; |
| 166 | + TestPlugin(const TestPlugin&) = delete; |
| 167 | + TestPlugin& operator=(TestPlugin&&) = delete; |
| 168 | + TestPlugin& operator=(const TestPlugin&) = delete; |
| 169 | + |
| 170 | + BEGIN_INTERFACE_MAP(TestPlugin) |
| 171 | + INTERFACE_ENTRY(PluginHost::IPlugin) |
| 172 | + INTERFACE_ENTRY(PluginHost::IDispatcher) |
| 173 | + INTERFACE_AGGREGATE(Exchange::ITestPlugin, _testPlugin) |
| 174 | + END_INTERFACE_MAP |
| 175 | + |
| 176 | +public: |
| 177 | + // IPlugin methods |
| 178 | + const string Initialize(PluginHost::IShell* service) override; |
| 179 | + void Deinitialize(PluginHost::IShell* service) override; |
| 180 | + string Information() const override; |
| 181 | + |
| 182 | +private: |
| 183 | + void Deactivated(RPC::IRemoteConnection* connection); |
| 184 | + |
| 185 | +private: |
| 186 | + uint32_t _connectionId; |
| 187 | + PluginHost::IShell* _service; |
| 188 | + Exchange::ITestPlugin* _testPlugin; |
| 189 | + Core::Sink<Notification> _notification; |
| 190 | +}; |
| 191 | +``` |
| 192 | +
|
| 193 | +- It should be registered during Initialize() to get itself notified when the remote process connects or disconnects. |
| 194 | +
|
| 195 | +### Example |
| 196 | +
|
| 197 | +```cpp |
| 198 | +const string TestPlugin::Initialize(PluginHost::IShell* service) |
| 199 | +{ |
| 200 | + // Register for COM-RPC connection/disconnection notifications |
| 201 | + _service->Register(&_notification); |
| 202 | +} |
| 203 | +``` |
0 commit comments