|
| 1 | +/* |
| 2 | +* If not stated otherwise in this file or this component's LICENSE file the |
| 3 | +* following copyright and licenses apply: |
| 4 | +* |
| 5 | +* Copyright 2025 RDK Management |
| 6 | +* |
| 7 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +* you may not use this file except in compliance with the License. |
| 9 | +* You may obtain a copy of the License at |
| 10 | +* |
| 11 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +* |
| 13 | +* Unless required by applicable law or agreed to in writing, software |
| 14 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +* See the License for the specific language governing permissions and |
| 17 | +* limitations under the License. |
| 18 | +*/ |
| 19 | + |
| 20 | +#include "FirmwareDownload.h" |
| 21 | + |
| 22 | +#define API_VERSION_NUMBER_MAJOR 1 |
| 23 | +#define API_VERSION_NUMBER_MINOR 0 |
| 24 | +#define API_VERSION_NUMBER_PATCH 0 |
| 25 | + |
| 26 | +namespace WPEFramework |
| 27 | +{ |
| 28 | + |
| 29 | + namespace { |
| 30 | + |
| 31 | + static Plugin::Metadata<Plugin::FirmwareDownload> metadata( |
| 32 | + // Version (Major, Minor, Patch) |
| 33 | + API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH, |
| 34 | + // Preconditions |
| 35 | + {}, |
| 36 | + // Terminations |
| 37 | + {}, |
| 38 | + // Controls |
| 39 | + {} |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + namespace Plugin |
| 44 | + { |
| 45 | + |
| 46 | + /* |
| 47 | + *Register FirmwareDownload module as wpeframework plugin |
| 48 | + **/ |
| 49 | + SERVICE_REGISTRATION(FirmwareDownload, API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH); |
| 50 | + |
| 51 | + FirmwareDownload::FirmwareDownload() : _service(nullptr), _connectionId(0), _firmwareDownload(nullptr), _firmwareDownloadNotification(this) |
| 52 | + { |
| 53 | + SYSLOG(Logging::Startup, (_T("FirmwareDownload Constructor"))); |
| 54 | + } |
| 55 | + |
| 56 | + FirmwareDownload::~FirmwareDownload() |
| 57 | + { |
| 58 | + SYSLOG(Logging::Shutdown, (string(_T("FirmwareDownload Destructor")))); |
| 59 | + } |
| 60 | + |
| 61 | + const string FirmwareDownload::Initialize(PluginHost::IShell* service) |
| 62 | + { |
| 63 | + string message=""; |
| 64 | + |
| 65 | + ASSERT(nullptr != service); |
| 66 | + ASSERT(nullptr == _service); |
| 67 | + ASSERT(nullptr == _firmwareDownload); |
| 68 | + ASSERT(0 == _connectionId); |
| 69 | + |
| 70 | + SYSLOG(Logging::Startup, (_T("FirmwareDownload::Initialize: PID=%u"), getpid())); |
| 71 | + |
| 72 | + _service = service; |
| 73 | + _service->AddRef(); |
| 74 | + _service->Register(&_firmwareDownloadNotification); |
| 75 | + _firmwareDownload = _service->Root<Exchange::IFirmwareDownload>(_connectionId, 5000, _T("FirmwareDownloadImplementation")); |
| 76 | + |
| 77 | + if(nullptr != _firmwareDownload) |
| 78 | + { |
| 79 | + // Register for notifications |
| 80 | + _firmwareDownload->Register(&_firmwareDownloadNotification); |
| 81 | + // Invoking Plugin API register to wpeframework |
| 82 | + Exchange::JFirmwareDownload::Register(*this, _firmwareDownload); |
| 83 | + } |
| 84 | + else |
| 85 | + { |
| 86 | + SYSLOG(Logging::Startup, (_T("FirmwareDownload::Initialize: Failed to initialise FirmwareDownload plugin"))); |
| 87 | + message = _T("FirmwareDownload plugin could not be initialised"); |
| 88 | + } |
| 89 | + |
| 90 | + return message; |
| 91 | + } |
| 92 | + |
| 93 | + void FirmwareDownload::Deinitialize(PluginHost::IShell* service) |
| 94 | + { |
| 95 | + ASSERT(_service == service); |
| 96 | + |
| 97 | + SYSLOG(Logging::Shutdown, (string(_T("FirmwareDownload::Deinitialize")))); |
| 98 | + |
| 99 | + // Make sure the Activated and Deactivated are no longer called before we start cleaning up.. |
| 100 | + _service->Unregister(&_firmwareDownloadNotification); |
| 101 | + |
| 102 | + if (nullptr != _firmwareDownload) |
| 103 | + { |
| 104 | + |
| 105 | + _firmwareDownload->Unregister(&_firmwareDownloadNotification); |
| 106 | + Exchange::JFirmwareDownload::Unregister(*this); |
| 107 | + |
| 108 | + // Stop processing: |
| 109 | + RPC::IRemoteConnection* connection = service->RemoteConnection(_connectionId); |
| 110 | + VARIABLE_IS_NOT_USED uint32_t result = _firmwareDownload->Release(); |
| 111 | + |
| 112 | + _firmwareDownload = nullptr; |
| 113 | + |
| 114 | + // It should have been the last reference we are releasing, |
| 115 | + // so it should endup in a DESTRUCTION_SUCCEEDED, if not we |
| 116 | + // are leaking... |
| 117 | + ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED); |
| 118 | + |
| 119 | + // If this was running in a (container) process... |
| 120 | + if (nullptr != connection) |
| 121 | + { |
| 122 | + // Lets trigger the cleanup sequence for |
| 123 | + // out-of-process code. Which will guard |
| 124 | + // that unwilling processes, get shot if |
| 125 | + // not stopped friendly :-) |
| 126 | + try |
| 127 | + { |
| 128 | + connection->Terminate(); |
| 129 | + // Log success if needed |
| 130 | + LOGWARN("Connection terminated successfully."); |
| 131 | + } |
| 132 | + catch (const std::exception& e) |
| 133 | + { |
| 134 | + std::string errorMessage = "Failed to terminate connection: "; |
| 135 | + errorMessage += e.what(); |
| 136 | + LOGWARN("%s",errorMessage.c_str()); |
| 137 | + } |
| 138 | + |
| 139 | + connection->Release(); |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + _connectionId = 0; |
| 144 | + _service->Release(); |
| 145 | + _service = nullptr; |
| 146 | + SYSLOG(Logging::Shutdown, (string(_T("FirmwareDownload de-initialised")))); |
| 147 | + } |
| 148 | + |
| 149 | + string FirmwareDownload::Information() const |
| 150 | + { |
| 151 | + return string(); |
| 152 | + } |
| 153 | + |
| 154 | + void FirmwareDownload::Deactivated(RPC::IRemoteConnection* connection) |
| 155 | + { |
| 156 | + if (connection->Id() == _connectionId) { |
| 157 | + ASSERT(nullptr != _service); |
| 158 | + Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE)); |
| 159 | + } |
| 160 | + } |
| 161 | +} // namespace Plugin |
| 162 | +} // namespace WPEFramework |
0 commit comments