-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDeviceIdentification.cpp
219 lines (176 loc) · 7.03 KB
/
DeviceIdentification.cpp
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2020 RDK Management
*
* 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.
*/
#include "DeviceIdentification.h"
#include "IdentityProvider.h"
#include <interfaces/IConfiguration.h>
namespace Thunder {
namespace Plugin {
namespace {
static Metadata<DeviceIdentification> metadata(
// Version
1, 0, 0,
// Preconditions
#ifdef DISABLE_DEVICEID_CONTROL
{ subsystem::PLATFORM, subsystem::IDENTIFIER },
#else
{ subsystem::PLATFORM },
#endif
// Terminations
{},
// Controls
#ifdef DISABLE_DEVICEID_CONTROL
{}
#else
{ subsystem::IDENTIFIER }
#endif
);
}
/* virtual */ const string DeviceIdentification::Initialize(PluginHost::IShell* service)
{
ASSERT(service != nullptr);
ASSERT(_service == nullptr);
ASSERT(_identifier == nullptr);
ASSERT(_connectionId == 0);
_service = service;
_service->AddRef();
string message;
// Register the Process::Notification stuff. The Remote process might die before we get a
// change to "register" the sink for these events !!! So do it ahead of instantiation.
service->Register(&_notification);
_identifier = service->Root<PluginHost::ISubSystem::IIdentifier>(_connectionId, RPC::CommunicationTimeOut, _T("DeviceImplementation"));
if (_identifier != nullptr) {
Exchange::IConfiguration* configure = _identifier->QueryInterface<Exchange::IConfiguration>();
if (configure != nullptr) {
configure->Configure(service);
configure->Release();
}
_deviceId = GetDeviceId();
Exchange::JDeviceIdentification::Register(*this, this);
if (_deviceId.empty() != true) {
#ifndef DISABLE_DEVICEID_CONTROL
service->SubSystems()->Set(PluginHost::ISubSystem::IDENTIFIER, _identifier);
#endif
}
else {
message = _T("DeviceIdentification plugin could not be instantiated. No DeviceID available");
}
}
else {
message = _T("DeviceIdentification plugin could not be instantiated.");
}
return message;
}
/* virtual */ void DeviceIdentification::Deinitialize(PluginHost::IShell* service)
{
if (_service != nullptr) {
ASSERT(_service == service);
_service->Unregister(&_notification);
if (_deviceId.empty() != true) {
#ifndef DISABLE_DEVICEID_CONTROL
service->SubSystems()->Set(PluginHost::ISubSystem::IDENTIFIER, nullptr);
#endif
_deviceId.clear();
}
if (_identifier != nullptr) {
Exchange::JDeviceIdentification::Unregister(*this);
// Stop processing:
RPC::IRemoteConnection* connection = service->RemoteConnection(_connectionId);
VARIABLE_IS_NOT_USED uint32_t result = _identifier->Release();
_identifier = 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;
}
}
/* virtual */ string DeviceIdentification::Information() const
{
// No additional info to report.
return (string());
}
string DeviceIdentification::GetDeviceId() const
{
string result;
#ifndef DISABLE_DEVICEID_CONTROL
ASSERT(_identifier != nullptr);
if (_identifier != nullptr) {
uint8_t myBuffer[64];
myBuffer[0] = _identifier->Identifier(sizeof(myBuffer) - 1, &(myBuffer[1]));
if (myBuffer[0] != 0) {
result = Core::SystemInfo::Instance().Id(myBuffer, ~0);
}
}
#else
ASSERT(_service != nullptr);
// extract DeviceId set by Thunder
if (_service->SubSystems()->IsActive(PluginHost::ISubSystem::IDENTIFIER) == true) {
const PluginHost::ISubSystem::IIdentifier* identifier(_service->SubSystems()->Get<PluginHost::ISubSystem::IIdentifier>());
if (identifier != nullptr) {
uint8_t myBuffer[64];
if ((myBuffer[0] = identifier->Identifier(sizeof(myBuffer) - 1, &(myBuffer[1]))) != 0) {
result = Core::SystemInfo::Instance().Id(myBuffer, ~0);
}
identifier->Release();
}
}
#endif
return result;
}
Core::hresult DeviceIdentification::Identification(Exchange::IDeviceIdentification::DeviceInfo& info) const
{
Core::hresult result = Core::ERROR_UNAVAILABLE;
ASSERT(_identifier != nullptr);
const string firmwareVersion = _identifier->FirmwareVersion();
const string chipset = _identifier->Chipset();
if (firmwareVersion.empty() == false) {
info.firmwareVersion = firmwareVersion;
}
if (chipset.empty() == false) {
info.chipset = chipset;
}
if (_deviceId.empty() == false) {
info.deviceID = _deviceId;
result = Core::ERROR_NONE;
}
return (result);
}
void DeviceIdentification::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));
}
}
} // namespace Plugin
} // namespace Thunder