Skip to content

Commit 46fe14e

Browse files
authored
Merge pull request rdkcentral#5946 from madanagopalt/sprint/24Q4
RDK-53203: Add appmanager support
2 parents 15a33b9 + 65daa83 commit 46fe14e

19 files changed

+3912
-0
lines changed

AppManager/AppManager.conf.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
precondition = ["Platform"]
2+
callsign = "org.rdk.AppManager"
3+
autostart = "false"

AppManager/AppManager.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set (autostart false)
2+
set (preconditions Platform)
3+
set (callsign "org.rdk.AppManager")

AppManager/AppManager.cpp

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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

AppManager/AppManager.h

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
#pragma once
21+
22+
#include "Module.h"
23+
#include <interfaces/json/JsonData_AppManager.h>
24+
#include <interfaces/json/JAppManager.h>
25+
#include <interfaces/IAppManager.h>
26+
#include "UtilsLogging.h"
27+
#include "tracing/Logging.h"
28+
#include <mutex>
29+
30+
namespace WPEFramework {
31+
namespace Plugin {
32+
33+
class AppManager: public PluginHost::IPlugin, public PluginHost::JSONRPC
34+
{
35+
private:
36+
class Notification : public RPC::IRemoteConnection::INotification,
37+
public Exchange::IAppManager::INotification
38+
{
39+
private:
40+
Notification() = delete;
41+
Notification(const Notification&) = delete;
42+
Notification& operator=(const Notification&) = delete;
43+
44+
public:
45+
explicit Notification(AppManager* parent)
46+
: _parent(*parent)
47+
{
48+
ASSERT(parent != nullptr);
49+
}
50+
51+
virtual ~Notification()
52+
{
53+
}
54+
55+
BEGIN_INTERFACE_MAP(Notification)
56+
INTERFACE_ENTRY(Exchange::IAppManager::INotification)
57+
INTERFACE_ENTRY(RPC::IRemoteConnection::INotification)
58+
END_INTERFACE_MAP
59+
60+
void Activated(RPC::IRemoteConnection*) override
61+
{
62+
LOGINFO("AppManager Notification Activated");
63+
}
64+
65+
void Deactivated(RPC::IRemoteConnection *connection) override
66+
{
67+
LOGINFO("AppManager Notification Deactivated");
68+
_parent.Deactivated(connection);
69+
}
70+
71+
void onAppStateChanged(const string& appId, const uint32_t appInstanceId, const Exchange::IAppManager::LifecycleState newState, const Exchange::IAppManager::LifecycleState oldState) override
72+
{
73+
LOGINFO("AppManager on appstate changed: %s\n", appId.c_str());
74+
Exchange::JAppManager::Event::OnAppStateChanged(_parent, appId, appInstanceId, newState, oldState);
75+
}
76+
77+
private:
78+
AppManager& _parent;
79+
};
80+
81+
public:
82+
// We do not allow this plugin to be copied !!
83+
AppManager(const AppManager&) = delete;
84+
AppManager& operator=(const AppManager&) = delete;
85+
86+
AppManager();
87+
virtual ~AppManager();
88+
89+
BEGIN_INTERFACE_MAP(AppManager)
90+
INTERFACE_ENTRY(PluginHost::IPlugin)
91+
INTERFACE_ENTRY(PluginHost::IDispatcher)
92+
INTERFACE_AGGREGATE(Exchange::IAppManager, mAppManager)
93+
END_INTERFACE_MAP
94+
95+
// IPlugin methods
96+
// -------------------------------------------------------------------------------------------------------
97+
const string Initialize(PluginHost::IShell* service) override;
98+
void Deinitialize(PluginHost::IShell* service) override;
99+
string Information() const override;
100+
101+
private:
102+
void Deactivated(RPC::IRemoteConnection* connection);
103+
104+
private:
105+
PluginHost::IShell* _service{};
106+
uint32_t _connectionId{};
107+
Exchange::IAppManager* mAppManager{};
108+
Core::Sink<Notification> mAppManagerNotification;
109+
};
110+
111+
} // namespace Plugin
112+
} // namespace WPEFramework

0 commit comments

Comments
 (0)