-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathAppTv.h
170 lines (144 loc) · 8.21 KB
/
AppTv.h
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
/*
*
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* 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.
*/
/**
* @brief Manages Content Apps
*/
#pragma once
#include <app/app-platform/ContentApp.h>
#include <app/app-platform/ContentAppPlatform.h>
#include <app/util/attribute-storage.h>
#include <functional>
#include <stdbool.h>
#include <stdint.h>
#include "account-login/AccountLoginManager.h"
#include "application-basic/ApplicationBasicManager.h"
#include "application-launcher/ApplicationLauncherManager.h"
#include "channel/ChannelManager.h"
#include "content-control/ContentController.h"
#include "content-launcher/ContentLauncherManager.h"
#include "keypad-input/KeypadInputManager.h"
#include "media-playback/MediaPlaybackManager.h"
#include "target-navigator/TargetNavigatorManager.h"
#include <app/clusters/account-login-server/account-login-delegate.h>
#include <app/clusters/application-basic-server/application-basic-delegate.h>
#include <app/clusters/application-launcher-server/application-launcher-delegate.h>
#include <app/clusters/channel-server/channel-delegate.h>
#include <app/clusters/content-launch-server/content-launch-delegate.h>
#include <app/clusters/keypad-input-server/keypad-input-delegate.h>
#include <app/clusters/media-playback-server/media-playback-delegate.h>
#include <app/clusters/target-navigator-server/target-navigator-delegate.h>
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
namespace chip {
namespace AppPlatform {
using AccountLoginDelegate = app::Clusters::AccountLogin::Delegate;
using ApplicationBasicDelegate = app::Clusters::ApplicationBasic::Delegate;
using ApplicationLauncherDelegate = app::Clusters::ApplicationLauncher::Delegate;
using ChannelDelegate = app::Clusters::Channel::Delegate;
using ContentLauncherDelegate = app::Clusters::ContentLauncher::Delegate;
using ContentControllerDelegate = app::Clusters::ContentControl::Delegate;
using KeypadInputDelegate = app::Clusters::KeypadInput::Delegate;
using MediaPlaybackDelegate = app::Clusters::MediaPlayback::Delegate;
using TargetNavigatorDelegate = app::Clusters::TargetNavigator::Delegate;
using SupportedProtocolsBitmap = app::Clusters::ContentLauncher::SupportedProtocolsBitmap;
static const int kCatalogVendorId = CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID;
// for this platform, appid is just vendor id
#define BuildAppId(vid) std::to_string(vid).c_str()
class DLL_EXPORT ContentAppImpl : public ContentApp
{
public:
ContentAppImpl(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
const char * szApplicationVersion, const char * setupPIN) :
mApplicationBasicDelegate(kCatalogVendorId, BuildAppId(vendorId), szVendorName, vendorId, szApplicationName, productId,
szApplicationVersion),
mAccountLoginDelegate(setupPIN),
mContentLauncherDelegate({ "image/*", "video/*" },
to_underlying(SupportedProtocolsBitmap::kDash) | to_underlying(SupportedProtocolsBitmap::kHls)),
mTargetNavigatorDelegate({ "home", "search", "info", "guide", "menu" }, 0){};
virtual ~ContentAppImpl() {}
AccountLoginDelegate * GetAccountLoginDelegate() override { return &mAccountLoginDelegate; };
ApplicationBasicDelegate * GetApplicationBasicDelegate() override { return &mApplicationBasicDelegate; };
ApplicationLauncherDelegate * GetApplicationLauncherDelegate() override { return &mApplicationLauncherDelegate; };
ChannelDelegate * GetChannelDelegate() override { return &mChannelDelegate; };
ContentLauncherDelegate * GetContentLauncherDelegate() override { return &mContentLauncherDelegate; };
ContentControllerDelegate * GetContentControlDelegate() override { return &mContentControlDelegate; };
KeypadInputDelegate * GetKeypadInputDelegate() override { return &mKeypadInputDelegate; };
MediaPlaybackDelegate * GetMediaPlaybackDelegate() override { return &mMediaPlaybackDelegate; };
TargetNavigatorDelegate * GetTargetNavigatorDelegate() override { return &mTargetNavigatorDelegate; };
bool MatchesPidVid(uint16_t productId, uint16_t vendorId)
{
return vendorId == mApplicationBasicDelegate.HandleGetVendorId() &&
productId == mApplicationBasicDelegate.HandleGetProductId();
}
protected:
ApplicationBasicManager mApplicationBasicDelegate;
AccountLoginManager mAccountLoginDelegate;
ApplicationLauncherManager mApplicationLauncherDelegate;
ChannelManager mChannelDelegate;
ContentLauncherManager mContentLauncherDelegate;
ContentControlManager mContentControlDelegate;
KeypadInputManager mKeypadInputDelegate;
MediaPlaybackManager mMediaPlaybackDelegate;
TargetNavigatorManager mTargetNavigatorDelegate;
};
class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
{
#define APP_LIBRARY_SIZE 4
public:
ContentAppFactoryImpl();
virtual ~ContentAppFactoryImpl() {}
// Lookup CatalogVendor App for this client (vendor id/product id client)
// and then write it to destinationApp
// return error if not found
CHIP_ERROR LookupCatalogVendorApp(uint16_t vendorId, uint16_t productId, CatalogVendorApp * destinationApp) override;
// Lookup ContentApp for this catalog id / app id and load it
ContentApp * LoadContentApp(const CatalogVendorApp & vendorApp) override;
// Gets the catalog vendor ID used by this platform
uint16_t GetPlatformCatalogVendorId() override;
// Converts application (any catalog) into the platform's catalog Vendor
// and then writes it to destinationApp
CHIP_ERROR ConvertToPlatformCatalogVendorApp(const CatalogVendorApp & sourceApp, CatalogVendorApp * destinationApp) override;
// Get the privilege this vendorId should have on endpoints 1, 2, and content app endpoints
// In the case of casting video clients, this should usually be Access::Privilege::kOperate
// and for voice agents, this may be Access::Privilege::kAdminister
// When a vendor has admin privileges, it will get access to all clusters on ep1
Access::Privilege GetVendorPrivilege(uint16_t vendorId) override;
// Get the cluster list this vendorId/productId should have on static endpoints such as ep1 for casting video clients.
// When a vendor has admin privileges, it will get access to all clusters on ep1
std::list<ClusterId> GetAllowedClusterListForStaticEndpoint(EndpointId endpointId, uint16_t vendorId,
uint16_t productId) override;
void AddAdminVendorId(uint16_t vendorId);
// Add the app to the list of mContentApps
void InstallContentApp(uint16_t vendorId, uint16_t productId);
// Remove the app from the list of mContentApps
bool UninstallContentApp(uint16_t vendorId, uint16_t productId);
// Set App's Installation Status
void SetAppInstallationStatus(uint16_t vendorId, uint16_t productId,
Protocols::UserDirectedCommissioning::CommissionerDeclaration::CdError status);
// Get App's Installation Status
Protocols::UserDirectedCommissioning::CommissionerDeclaration::CdError GetAppInstallationStatus(uint16_t vendorId,
uint16_t productId);
protected:
std::vector<std::unique_ptr<ContentAppImpl>> mContentApps;
std::vector<uint16_t> mAdminVendorIds{};
std::map<std::string, Protocols::UserDirectedCommissioning::CommissionerDeclaration::CdError> mAppInstallationStatus{};
};
} // namespace AppPlatform
} // namespace chip
chip::AppPlatform::ContentAppFactoryImpl * GetContentAppFactoryImpl();
#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
CHIP_ERROR AppTvInit(void);