AppImpl.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. *
  3. * Copyright (c) 2021 Project CHIP Authors
  4. * All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /**
  19. * @brief Manages Content Apps
  20. */
  21. #pragma once
  22. #include <app-common/zap-generated/enums.h>
  23. #include <app/app-platform/ContentApp.h>
  24. #include <app/app-platform/ContentAppPlatform.h>
  25. #include <app/util/attribute-storage.h>
  26. #include <functional>
  27. #include <jni.h>
  28. #include <lib/support/JniReferences.h>
  29. #include <stdbool.h>
  30. #include <stdint.h>
  31. #include "../include/account-login/AccountLoginManager.h"
  32. #include "../include/application-basic/ApplicationBasicManager.h"
  33. #include "../include/application-launcher/ApplicationLauncherManager.h"
  34. #include "../include/content-launcher/AppContentLauncherManager.h"
  35. #include "../include/target-navigator/TargetNavigatorManager.h"
  36. #include "ChannelManager.h"
  37. #include "CommissionerMain.h"
  38. #include "ContentAppCommandDelegate.h"
  39. #include "KeypadInputManager.h"
  40. #include "MediaPlaybackManager.h"
  41. #include <app/clusters/account-login-server/account-login-delegate.h>
  42. #include <app/clusters/application-basic-server/application-basic-delegate.h>
  43. #include <app/clusters/application-launcher-server/application-launcher-delegate.h>
  44. #include <app/clusters/channel-server/channel-delegate.h>
  45. #include <app/clusters/content-launch-server/content-launch-delegate.h>
  46. #include <app/clusters/keypad-input-server/keypad-input-delegate.h>
  47. #include <app/clusters/media-playback-server/media-playback-delegate.h>
  48. #include <app/clusters/target-navigator-server/target-navigator-delegate.h>
  49. CHIP_ERROR InitVideoPlayerPlatform();
  50. CHIP_ERROR PreServerInit();
  51. EndpointId AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
  52. const char * szApplicationVersion, jobject manager);
  53. void SendTestMessage(EndpointId epID, const char * message);
  54. #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
  55. namespace chip {
  56. namespace AppPlatform {
  57. using AccountLoginDelegate = app::Clusters::AccountLogin::Delegate;
  58. using ApplicationBasicDelegate = app::Clusters::ApplicationBasic::Delegate;
  59. using ApplicationLauncherDelegate = app::Clusters::ApplicationLauncher::Delegate;
  60. using ChannelDelegate = app::Clusters::Channel::Delegate;
  61. using ContentLauncherDelegate = app::Clusters::ContentLauncher::Delegate;
  62. using KeypadInputDelegate = app::Clusters::KeypadInput::Delegate;
  63. using MediaPlaybackDelegate = app::Clusters::MediaPlayback::Delegate;
  64. using TargetNavigatorDelegate = app::Clusters::TargetNavigator::Delegate;
  65. using SupportedStreamingProtocol = app::Clusters::ContentLauncher::SupportedStreamingProtocol;
  66. using ContentAppCommandDelegate = chip::AppPlatform::ContentAppCommandDelegate;
  67. static const int kCatalogVendorId = CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID;
  68. // for this platform, appid is just vendor id
  69. #define BuildAppId(vid) std::to_string(vid).c_str()
  70. class DLL_EXPORT ContentAppImpl : public ContentApp
  71. {
  72. public:
  73. ContentAppImpl(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
  74. const char * szApplicationVersion, const char * setupPIN, jobject manager) :
  75. mApplicationBasicDelegate(kCatalogVendorId, BuildAppId(vendorId), szVendorName, vendorId, szApplicationName, productId,
  76. szApplicationVersion),
  77. mAccountLoginDelegate(setupPIN), mContentLauncherDelegate(ContentAppCommandDelegate(manager), { "image/*", "video/*" },
  78. to_underlying(SupportedStreamingProtocol::kDash) |
  79. to_underlying(SupportedStreamingProtocol::kHls)),
  80. mTargetNavigatorDelegate({ "home", "search", "info", "guide", "menu" }, 0){};
  81. virtual ~ContentAppImpl() {}
  82. AccountLoginDelegate * GetAccountLoginDelegate() override { return &mAccountLoginDelegate; };
  83. ApplicationBasicDelegate * GetApplicationBasicDelegate() override { return &mApplicationBasicDelegate; };
  84. ApplicationLauncherDelegate * GetApplicationLauncherDelegate() override { return &mApplicationLauncherDelegate; };
  85. ChannelDelegate * GetChannelDelegate() override { return &mChannelDelegate; };
  86. ContentLauncherDelegate * GetContentLauncherDelegate() override
  87. {
  88. mContentLauncherDelegate.SetEndpointId(GetEndpointId());
  89. return &mContentLauncherDelegate;
  90. };
  91. KeypadInputDelegate * GetKeypadInputDelegate() override { return &mKeypadInputDelegate; };
  92. MediaPlaybackDelegate * GetMediaPlaybackDelegate() override { return &mMediaPlaybackDelegate; };
  93. TargetNavigatorDelegate * GetTargetNavigatorDelegate() override { return &mTargetNavigatorDelegate; };
  94. protected:
  95. ApplicationBasicManager mApplicationBasicDelegate;
  96. AccountLoginManager mAccountLoginDelegate;
  97. ApplicationLauncherManager mApplicationLauncherDelegate;
  98. ChannelManager mChannelDelegate;
  99. AppContentLauncherManager mContentLauncherDelegate;
  100. KeypadInputManager mKeypadInputDelegate;
  101. MediaPlaybackManager mMediaPlaybackDelegate;
  102. TargetNavigatorManager mTargetNavigatorDelegate;
  103. };
  104. class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
  105. {
  106. #define APP_LIBRARY_SIZE 4
  107. public:
  108. ContentAppFactoryImpl();
  109. virtual ~ContentAppFactoryImpl() {}
  110. // Lookup CatalogVendor App for this client (vendor id/product id client)
  111. // and then write it to destinationApp
  112. // return error if not found
  113. CHIP_ERROR LookupCatalogVendorApp(uint16_t vendorId, uint16_t productId, CatalogVendorApp * destinationApp) override;
  114. // Lookup ContentApp for this catalog id / app id and load it
  115. ContentApp * LoadContentApp(const CatalogVendorApp & vendorApp) override;
  116. EndpointId AddContentApp(ContentAppImpl & app);
  117. void SendTestMessage(EndpointId epID, const char * message);
  118. // Gets the catalog vendor ID used by this platform
  119. uint16_t GetPlatformCatalogVendorId() override;
  120. // Converts application (any catalog) into the platform's catalog Vendor
  121. // and then writes it to destinationApp
  122. CHIP_ERROR ConvertToPlatformCatalogVendorApp(const CatalogVendorApp & sourceApp, CatalogVendorApp * destinationApp) override;
  123. protected:
  124. std::vector<ContentAppImpl> mContentApps{
  125. ContentAppImpl("Vendor1", 1, "exampleid", 11, "Version1", "34567890", nullptr),
  126. ContentAppImpl("Vendor2", 65521, "exampleString", 32768, "Version2", "20202021", nullptr),
  127. ContentAppImpl("Vendor3", 9050, "App3", 22, "Version3", "20202021", nullptr),
  128. ContentAppImpl("TestSuiteVendor", 1111, "applicationId", 22, "v2", "20202021", nullptr)
  129. };
  130. };
  131. } // namespace AppPlatform
  132. } // namespace chip
  133. #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED