|
| 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 2024 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 "AppManager.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::AppManager> 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 | + *Register AppManager module as wpeframework plugin |
| 47 | + **/ |
| 48 | + SERVICE_REGISTRATION(AppManager, API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH); |
| 49 | + |
| 50 | + AppManager::AppManager() : _service(nullptr), _connectionId(0), mAppManager(nullptr), mAppManagerNotification(this) |
| 51 | + { |
| 52 | + SYSLOG(Logging::Startup, (_T("AppManager Constructor"))); |
| 53 | + } |
| 54 | + |
| 55 | + AppManager::~AppManager() |
| 56 | + { |
| 57 | + SYSLOG(Logging::Shutdown, (string(_T("AppManager Destructor")))); |
| 58 | + } |
| 59 | + |
| 60 | + const string AppManager::Initialize(PluginHost::IShell* service) |
| 61 | + { |
| 62 | + string message=""; |
| 63 | + |
| 64 | + ASSERT(nullptr != service); |
| 65 | + ASSERT(nullptr == _service); |
| 66 | + ASSERT(nullptr == mAppManager); |
| 67 | + ASSERT(0 == _connectionId); |
| 68 | + |
| 69 | + SYSLOG(Logging::Startup, (_T("AppManager::Initialize: PID=%u"), getpid())); |
| 70 | + |
| 71 | + _service = service; |
| 72 | + _service->AddRef(); |
| 73 | + _service->Register(&mAppManagerNotification); |
| 74 | + mAppManager = _service->Root<Exchange::IAppManager>(_connectionId, 5000, _T("AppManagerImplementation")); |
| 75 | + |
| 76 | + if(nullptr != mAppManager) |
| 77 | + { |
| 78 | + Core::hresult result = mAppManager->Initialize(_service); |
| 79 | + if (result == Core::ERROR_NONE) |
| 80 | + { |
| 81 | + // Register for notifications |
| 82 | + mAppManager->Register(&mAppManagerNotification); |
| 83 | + // Invoking Plugin API register to wpeframework |
| 84 | + Exchange::JAppManager::Register(*this, mAppManager); |
| 85 | + } |
| 86 | + else |
| 87 | + { |
| 88 | + message = _T("AppManager plugin could not be initialised, as remote failed"); |
| 89 | + } |
| 90 | + } |
| 91 | + else |
| 92 | + { |
| 93 | + SYSLOG(Logging::Startup, (_T("AppManager::Initialize: Failed to initialise AppManager plugin"))); |
| 94 | + Deinitialize(service); |
| 95 | + message = _T("AppManager plugin could not be initialised"); |
| 96 | + } |
| 97 | + return message; |
| 98 | + } |
| 99 | + |
| 100 | + void AppManager::Deinitialize(PluginHost::IShell* service) |
| 101 | + { |
| 102 | + ASSERT(_service == service); |
| 103 | + |
| 104 | + SYSLOG(Logging::Shutdown, (string(_T("AppManager::Deinitialize")))); |
| 105 | + |
| 106 | + // Make sure the Activated and Deactivated are no longer called before we start cleaning up.. |
| 107 | + _service->Unregister(&mAppManagerNotification); |
| 108 | + |
| 109 | + if (nullptr != mAppManager) |
| 110 | + { |
| 111 | + mAppManager->Unregister(&mAppManagerNotification); |
| 112 | + mAppManager->Deinitialize(_service); |
| 113 | + Exchange::JAppManager::Unregister(*this); |
| 114 | + |
| 115 | + // Stop processing: |
| 116 | + RPC::IRemoteConnection* connection = service->RemoteConnection(_connectionId); |
| 117 | + VARIABLE_IS_NOT_USED uint32_t result = mAppManager->Release(); |
| 118 | + |
| 119 | + mAppManager = nullptr; |
| 120 | + |
| 121 | + // It should have been the last reference we are releasing, |
| 122 | + // so it should endup in a DESTRUCTION_SUCCEEDED, if not we |
| 123 | + // are leaking... |
| 124 | + ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED); |
| 125 | + |
| 126 | + // If this was running in a (container) process... |
| 127 | + if (nullptr != connection) |
| 128 | + { |
| 129 | + // Lets trigger the cleanup sequence for |
| 130 | + // out-of-process code. Which will guard |
| 131 | + // that unwilling processes, get shot if |
| 132 | + // not stopped friendly :-) |
| 133 | + connection->Terminate(); |
| 134 | + connection->Release(); |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + _connectionId = 0; |
| 139 | + _service->Release(); |
| 140 | + _service = nullptr; |
| 141 | + SYSLOG(Logging::Shutdown, (string(_T("AppManager de-initialised")))); |
| 142 | + } |
| 143 | + |
| 144 | + string AppManager::Information() const |
| 145 | + { |
| 146 | + // No additional info to report |
| 147 | + return (string()); |
| 148 | + } |
| 149 | + |
| 150 | + void AppManager::Deactivated(RPC::IRemoteConnection* connection) |
| 151 | + { |
| 152 | + if (connection->Id() == _connectionId) |
| 153 | + { |
| 154 | + ASSERT(nullptr != _service); |
| 155 | + Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE)); |
| 156 | + } |
| 157 | + } |
| 158 | +} // namespace Plugin |
| 159 | +} // namespace WPEFramework |
0 commit comments