Line data Source code
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 Sky UK
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 <IIpcController.h>
21 : #include <algorithm>
22 : #include <cstdint>
23 :
24 : #include "ICdmService.h"
25 : #include "MediaKeysCapabilitiesModuleService.h"
26 : #include "RialtoServerLogging.h"
27 :
28 : namespace firebolt::rialto::server::ipc
29 : {
30 1 : std::shared_ptr<IMediaKeysCapabilitiesModuleServiceFactory> IMediaKeysCapabilitiesModuleServiceFactory::createFactory()
31 : {
32 1 : std::shared_ptr<IMediaKeysCapabilitiesModuleServiceFactory> factory;
33 :
34 : try
35 : {
36 1 : factory = std::make_shared<MediaKeysCapabilitiesModuleServiceFactory>();
37 : }
38 0 : catch (const std::exception &e)
39 : {
40 0 : RIALTO_SERVER_LOG_ERROR("Failed to create the media keys capabilities module service factory, reason: %s",
41 : e.what());
42 : }
43 :
44 1 : return factory;
45 : }
46 :
47 : std::shared_ptr<IMediaKeysCapabilitiesModuleService>
48 1 : MediaKeysCapabilitiesModuleServiceFactory::create(service::ICdmService &cdmService) const
49 : {
50 1 : std::shared_ptr<IMediaKeysCapabilitiesModuleService> mediaKeysCapabilitiesModule;
51 :
52 : try
53 : {
54 1 : mediaKeysCapabilitiesModule = std::make_shared<MediaKeysCapabilitiesModuleService>(cdmService);
55 : }
56 0 : catch (const std::exception &e)
57 : {
58 0 : RIALTO_SERVER_LOG_ERROR("Failed to create the media keys capabilities module service, reason: %s", e.what());
59 : }
60 :
61 1 : return mediaKeysCapabilitiesModule;
62 : }
63 :
64 8 : MediaKeysCapabilitiesModuleService::MediaKeysCapabilitiesModuleService(service::ICdmService &cdmService)
65 8 : : m_cdmService{cdmService}
66 : {
67 : }
68 :
69 : MediaKeysCapabilitiesModuleService::~MediaKeysCapabilitiesModuleService() {}
70 :
71 1 : void MediaKeysCapabilitiesModuleService::clientConnected(const std::shared_ptr<::firebolt::rialto::ipc::IClient> &ipcClient)
72 : {
73 1 : RIALTO_SERVER_LOG_INFO("Client Connected!");
74 1 : ipcClient->exportService(shared_from_this());
75 : }
76 :
77 0 : void MediaKeysCapabilitiesModuleService::clientDisconnected(const std::shared_ptr<::firebolt::rialto::ipc::IClient> &ipcClient)
78 : {
79 0 : RIALTO_SERVER_LOG_INFO("Client disconnected!");
80 : }
81 :
82 1 : void MediaKeysCapabilitiesModuleService::getSupportedKeySystems(
83 : ::google::protobuf::RpcController *controller, const ::firebolt::rialto::GetSupportedKeySystemsRequest *request,
84 : ::firebolt::rialto::GetSupportedKeySystemsResponse *response, ::google::protobuf::Closure *done)
85 : {
86 1 : RIALTO_SERVER_LOG_DEBUG("entry:");
87 1 : auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
88 1 : if (!ipcController)
89 : {
90 0 : RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
91 0 : controller->SetFailed("ipc library provided incompatible controller object");
92 0 : done->Run();
93 0 : return;
94 : }
95 :
96 1 : std::vector<std::string> keySystems = m_cdmService.getSupportedKeySystems();
97 :
98 4 : for (auto it = keySystems.begin(); it != keySystems.end(); it++)
99 : {
100 3 : response->add_key_systems(*it);
101 : }
102 1 : done->Run();
103 : }
104 :
105 1 : void MediaKeysCapabilitiesModuleService::supportsKeySystem(::google::protobuf::RpcController *controller,
106 : const ::firebolt::rialto::SupportsKeySystemRequest *request,
107 : ::firebolt::rialto::SupportsKeySystemResponse *response,
108 : ::google::protobuf::Closure *done)
109 : {
110 1 : RIALTO_SERVER_LOG_DEBUG("entry:");
111 1 : auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
112 1 : if (!ipcController)
113 : {
114 0 : RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
115 0 : controller->SetFailed("ipc library provided incompatible controller object");
116 0 : done->Run();
117 0 : return;
118 : }
119 :
120 1 : response->set_is_supported(m_cdmService.supportsKeySystem(request->key_system()));
121 1 : done->Run();
122 : }
123 :
124 2 : void MediaKeysCapabilitiesModuleService::getSupportedKeySystemVersion(
125 : ::google::protobuf::RpcController *controller, const ::firebolt::rialto::GetSupportedKeySystemVersionRequest *request,
126 : ::firebolt::rialto::GetSupportedKeySystemVersionResponse *response, ::google::protobuf::Closure *done)
127 : {
128 2 : RIALTO_SERVER_LOG_DEBUG("entry:");
129 2 : auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
130 2 : if (!ipcController)
131 : {
132 0 : RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
133 0 : controller->SetFailed("ipc library provided incompatible controller object");
134 0 : done->Run();
135 0 : return;
136 : }
137 :
138 2 : std::string version;
139 2 : bool status = m_cdmService.getSupportedKeySystemVersion(request->key_system(), version);
140 2 : if (status)
141 : {
142 1 : response->set_version(version);
143 : }
144 : else
145 : {
146 1 : RIALTO_SERVER_LOG_ERROR("Failed to get the key system version");
147 1 : controller->SetFailed("Operation failed");
148 : }
149 :
150 2 : done->Run();
151 : }
152 :
153 1 : void MediaKeysCapabilitiesModuleService::isServerCertificateSupported(
154 : ::google::protobuf::RpcController *controller, const ::firebolt::rialto::IsServerCertificateSupportedRequest *request,
155 : ::firebolt::rialto::IsServerCertificateSupportedResponse *response, ::google::protobuf::Closure *done)
156 : {
157 1 : RIALTO_SERVER_LOG_DEBUG("entry:");
158 1 : auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
159 1 : if (!ipcController)
160 : {
161 0 : RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
162 0 : controller->SetFailed("ipc library provided incompatible controller object");
163 0 : done->Run();
164 0 : return;
165 : }
166 :
167 1 : response->set_is_supported(m_cdmService.isServerCertificateSupported(request->key_system()));
168 1 : done->Run();
169 : }
170 :
171 : } // namespace firebolt::rialto::server::ipc
|