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 2023 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 : #ifndef MESSAGE_DISPATCHER_H_
21 : #define MESSAGE_DISPATCHER_H_
22 :
23 : #include "IMessageDispatcher.h"
24 : #include <memory>
25 : #include <mutex>
26 : #include <set>
27 : #include <string>
28 : #include <vector>
29 :
30 : class MessageDispatcher : public IMessageDispatcher, public firebolt::rialto::IMediaKeysClient
31 : {
32 : class MessageDispatcherClient : public IMessageDispatcherClient
33 : {
34 : public:
35 : MessageDispatcherClient(MessageDispatcher &dispatcher, firebolt::rialto::IMediaKeysClient *client);
36 : ~MessageDispatcherClient() override;
37 :
38 : private:
39 : MessageDispatcher &m_dispatcher;
40 : firebolt::rialto::IMediaKeysClient *m_client;
41 : };
42 :
43 : public:
44 23 : MessageDispatcher() = default;
45 23 : ~MessageDispatcher() override = default;
46 :
47 : std::unique_ptr<IMessageDispatcherClient> createClient(firebolt::rialto::IMediaKeysClient *client) override;
48 :
49 : void onLicenseRequest(int32_t keySessionId, const std::vector<unsigned char> &licenseRequestMessage,
50 : const std::string &url) override;
51 : void onLicenseRenewal(int32_t keySessionId, const std::vector<unsigned char> &licenseRenewalMessage) override;
52 : void onKeyStatusesChanged(int32_t keySessionId, const firebolt::rialto::KeyStatusVector &keyStatuses) override;
53 :
54 : private:
55 : void addClient(firebolt::rialto::IMediaKeysClient *client);
56 : void removeClient(firebolt::rialto::IMediaKeysClient *client);
57 :
58 : private:
59 : std::mutex m_mutex;
60 : std::set<firebolt::rialto::IMediaKeysClient *> m_clients;
61 : };
62 :
63 : #endif // MESSAGE_DISPATCHER_H_
|