|
| 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 2022 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 "ContentProtection.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 | +namespace Plugin { |
| 28 | + |
| 29 | + namespace { |
| 30 | + static Metadata<ContentProtection> metadata( |
| 31 | + // Version (Major, Minor, Patch) |
| 32 | + API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH, |
| 33 | + // Preconditions |
| 34 | + {}, |
| 35 | + // Terminations |
| 36 | + {}, |
| 37 | + // Controls |
| 38 | + {}); |
| 39 | + } |
| 40 | + |
| 41 | + SERVICE_REGISTRATION(ContentProtection, API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH); |
| 42 | + |
| 43 | + const string ContentProtection::Initialize(PluginHost::IShell* service) |
| 44 | + { |
| 45 | + string result; |
| 46 | + |
| 47 | + ASSERT(service != nullptr); |
| 48 | + |
| 49 | + _implementation = Core::Service<Implementation>::Create< |
| 50 | + Exchange::IContentProtection>(*this); |
| 51 | + Exchange::JContentProtection::Register(*this, _implementation); |
| 52 | + |
| 53 | + string token; |
| 54 | + auto security = service->QueryInterfaceByCallsign< |
| 55 | + PluginHost::IAuthenticate>("SecurityAgent"); |
| 56 | + if (security != nullptr) { |
| 57 | + string payload = "http://localhost"; |
| 58 | + auto ret = security->CreateToken( |
| 59 | + static_cast<uint16_t>(payload.length()), |
| 60 | + reinterpret_cast<const uint8_t*>(payload.c_str()), |
| 61 | + token); |
| 62 | + if (ret != Core::ERROR_NONE) { |
| 63 | + SYSLOG(Logging::Startup, |
| 64 | + (_T("Couldn't create token: %d"), ret)); |
| 65 | + } |
| 66 | + security->Release(); |
| 67 | + } |
| 68 | + |
| 69 | + Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), |
| 70 | + (_T("127.0.0.1:9998"))); |
| 71 | + _secManager = Core::ProxyType<JSONRPCLink>::Create( |
| 72 | + _T("SecManager"), _T(""), "token=" + token); |
| 73 | + _watermark = Core::ProxyType<JSONRPCLink>::Create( |
| 74 | + _T("Watermark"), _T(""), "token=" + token); |
| 75 | + Subscribe(); |
| 76 | + |
| 77 | + return result; |
| 78 | + } |
| 79 | + |
| 80 | + void ContentProtection::Deinitialize(PluginHost::IShell*) |
| 81 | + { |
| 82 | + Unsubscribe(); |
| 83 | + Exchange::JContentProtection::Unregister(*this); |
| 84 | + if (_implementation != nullptr) { |
| 85 | + _implementation->Release(); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + string ContentProtection::Information() const |
| 90 | + { |
| 91 | + return (string()); |
| 92 | + } |
| 93 | + |
| 94 | +} // namespace Plugin |
| 95 | +} // namespace WPEFramework |
0 commit comments