forked from rdkcentral/PackageManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackageManager.cpp
More file actions
141 lines (114 loc) · 4.88 KB
/
PackageManager.cpp
File metadata and controls
141 lines (114 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Copyright 2023 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "PackageManager.h"
namespace WPEFramework {
namespace Plugin {
namespace {
static Metadata<PackageManager> metadata(
// Version
1, 1, 0,
// Preconditions
{},
// Terminations
{},
// Controls
{ subsystem::INSTALLATION }
);
}
const string PackageManager::Initialize(PluginHost::IShell* service)
{
string message;
ASSERT(service != nullptr);
ASSERT(_service == nullptr);
ASSERT(_connectionId == 0);
ASSERT(_packageManager == nullptr);
ASSERT(_pluginimpl == nullptr);
_service = service;
_service->AddRef();
_service->Register(&_notification);
_packageManager = service->Root<Exchange::IPackageManager>(_connectionId, 2000, _T("PackageManagerImplementation"));
if (_packageManager != nullptr) {
Exchange::JPackageManager::Register(*this, _packageManager);
_packageManager->Register(&_notification);
_pluginimpl = _packageManager->QueryInterface<PluginHost::IPlugin>();
if (_pluginimpl != nullptr) {
_adminLock.Lock();
_info = _pluginimpl->Information();
_adminLock.Unlock();
message = _pluginimpl->Initialize(service);
}
} else {
message = _T("PackageManager could not be instantiated. Could not acquire PackageManager interface");
}
return message;
}
void PackageManager::Deinitialize(PluginHost::IShell* service)
{
if (_service != nullptr) {
ASSERT(service == _service);
_service->Unregister(&_notification);
if (_packageManager != nullptr) {
_packageManager->Unregister(&_notification);
Exchange::JPackageManager::Unregister(*this);
if (_pluginimpl != nullptr) {
_pluginimpl->Deinitialize(service);
_pluginimpl->Release();
_pluginimpl = nullptr;
}
// Stop processing:
RPC::IRemoteConnection* connection = service->RemoteConnection(_connectionId);
VARIABLE_IS_NOT_USED uint32_t result = _packageManager->Release();
_packageManager = nullptr;
// It should have been the last reference we are releasing,
// so it should endup in a DESTRUCTION_SUCCEEDED, if not we
// are leaking...
ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED);
// If this was running in a (container) process...
if (connection != nullptr) {
// Lets trigger the cleanup sequence for
// out-of-process code. Which will guard
// that unwilling processes, get shot if
// not stopped friendly :-)
connection->Terminate();
connection->Release();
}
}
_connectionId = 0;
_service->Release();
_service = nullptr;
}
}
string PackageManager::Information() const
{
Core::SafeSyncType<Core::CriticalSection> _guard(_adminLock);
return _info;
}
void PackageManager::Deactivated(RPC::IRemoteConnection* connection)
{
// This can potentially be called on a socket thread, so the deactivation (wich in turn kills this object) must be done
// on a seperate thread. Also make sure this call-stack can be unwound before we are totally destructed.
if (_connectionId == connection->Id()) {
ASSERT(_service != nullptr);
Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE));
}
}
void PackageManager::OperationStatus(const string& handle, const string& operation, const string& type, const string& id, const string& version, const string& status, const string& details) {
Exchange::JPackageManager::Event::OperationStatus(*this, handle, operation, type, id, version, status, details);
}
} // namespace Plugin
} // namespace WPEFramework