AppImpl.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. /*
  2. *
  3. * Copyright (c) 2021 Project CHIP Authors
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /**
  18. * @file Contains Implementation of the ContentApp and the ContentAppPlatform.
  19. */
  20. #include "AppImpl.h"
  21. #include <app-common/zap-generated/attribute-id.h>
  22. #include <app-common/zap-generated/cluster-id.h>
  23. #include <app-common/zap-generated/ids/Attributes.h>
  24. #include <app-common/zap-generated/ids/Clusters.h>
  25. #include <app/CommandHandler.h>
  26. #include <app/server/Dnssd.h>
  27. #include <app/server/Server.h>
  28. #include <app/util/af.h>
  29. #include <cstdio>
  30. #include <inttypes.h>
  31. #include <jni.h>
  32. #include <lib/core/CHIPCore.h>
  33. #include <lib/core/DataModelTypes.h>
  34. #include <lib/shell/Commands.h>
  35. #include <lib/shell/Engine.h>
  36. #include <lib/shell/commands/Help.h>
  37. #include <lib/support/CHIPArgParser.hpp>
  38. #include <lib/support/CHIPMem.h>
  39. #include <lib/support/CodeUtils.h>
  40. #include <lib/support/ZclString.h>
  41. #include <platform/CHIPDeviceLayer.h>
  42. using namespace chip;
  43. using namespace chip::AppPlatform;
  44. #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
  45. class MyUserPrompter : public UserPrompter
  46. {
  47. // tv should override this with a dialog prompt
  48. inline void PromptForCommissionOKPermission(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override
  49. {
  50. /*
  51. * Called to prompt the user for consent to allow the given commissioneeName/vendorId/productId to be commissioned.
  52. * For example "[commissioneeName] is requesting permission to cast to this TV, approve?"
  53. *
  54. * If user responds with OK then implementor should call CommissionerRespondOk();
  55. * If user responds with Cancel then implementor should call CommissionerRespondCancel();
  56. *
  57. */
  58. GetCommissionerDiscoveryController()->Ok();
  59. /**
  60. * For Demo: Launch Prime Video App
  61. */
  62. return;
  63. }
  64. // tv should override this with a dialog prompt
  65. inline void PromptForCommissionPincode(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override
  66. {
  67. /*
  68. * Called to prompt the user to enter the setup pincode displayed by the given commissioneeName/vendorId/productId to be
  69. * commissioned. For example "Please enter pin displayed in casting app."
  70. *
  71. * If user enters with pin then implementor should call CommissionerRespondPincode(uint32_t pincode);
  72. * If user responds with Cancel then implementor should call CommissionerRespondCancel();
  73. */
  74. GetCommissionerDiscoveryController()->CommissionWithPincode(20202021); // dummy pin code
  75. /**
  76. * For Demo: Launch Prime Video App
  77. */
  78. return;
  79. }
  80. // tv should override this with a dialog prompt
  81. inline void PromptCommissioningSucceeded(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override
  82. {
  83. return;
  84. }
  85. // tv should override this with a dialog prompt
  86. inline void PromptCommissioningFailed(const char * commissioneeName, CHIP_ERROR error) override { return; }
  87. };
  88. MyUserPrompter gMyUserPrompter;
  89. #endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
  90. #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
  91. class MyPincodeService : public PincodeService
  92. {
  93. uint32_t FetchCommissionPincodeFromContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId) override
  94. {
  95. return ContentAppPlatform::GetInstance().GetPincodeFromContentApp(vendorId, productId, rotatingId);
  96. }
  97. };
  98. MyPincodeService gMyPincodeService;
  99. class MyPostCommissioningListener : public PostCommissioningListener
  100. {
  101. void CommissioningCompleted(uint16_t vendorId, uint16_t productId, NodeId nodeId, OperationalDeviceProxy * device) override
  102. {
  103. ContentAppPlatform::GetInstance().ManageClientAccess(device, vendorId, GetDeviceCommissioner()->GetNodeId(),
  104. OnSuccessResponse, OnFailureResponse);
  105. }
  106. /* Callback when command results in success */
  107. static void OnSuccessResponse(void * context)
  108. {
  109. ChipLogProgress(Controller, "OnSuccessResponse - Binding Add Successfully");
  110. CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
  111. if (cdc != nullptr)
  112. {
  113. cdc->PostCommissioningSucceeded();
  114. }
  115. }
  116. /* Callback when command results in failure */
  117. static void OnFailureResponse(void * context, CHIP_ERROR error)
  118. {
  119. ChipLogProgress(Controller, "OnFailureResponse - Binding Add Failed");
  120. CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
  121. if (cdc != nullptr)
  122. {
  123. cdc->PostCommissioningFailed(error);
  124. }
  125. }
  126. };
  127. MyPostCommissioningListener gMyPostCommissioningListener;
  128. ContentAppFactoryImpl gFactory;
  129. namespace chip {
  130. namespace AppPlatform {
  131. // BEGIN DYNAMIC ENDPOINTS
  132. // =================================================================================
  133. static const int kNameSize = 32;
  134. // Current ZCL implementation of Struct uses a max-size array of 254 bytes
  135. static const int kDescriptorAttributeArraySize = 254;
  136. // Device types for dynamic endpoints: TODO Need a generated file from ZAP to define these!
  137. // (taken from chip-devices.xml)
  138. #define DEVICE_TYPE_CONTENT_APP 0x0024
  139. // ---------------------------------------------------------------------------
  140. //
  141. // CONTENT APP ENDPOINT: contains the following clusters:
  142. // - Descriptor
  143. // - Application Basic
  144. // Declare Descriptor cluster attributes
  145. DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(descriptorAttrs)
  146. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_DEVICE_LIST_ATTRIBUTE_ID, ARRAY, kDescriptorAttributeArraySize, 0), /* device list */
  147. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_SERVER_LIST_ATTRIBUTE_ID, ARRAY, kDescriptorAttributeArraySize, 0), /* server list */
  148. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_CLIENT_LIST_ATTRIBUTE_ID, ARRAY, kDescriptorAttributeArraySize, 0), /* client list */
  149. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_PARTS_LIST_ATTRIBUTE_ID, ARRAY, kDescriptorAttributeArraySize, 0), /* parts list */
  150. DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();
  151. // Declare Application Basic information cluster attributes
  152. // TODO: add missing attributes once schema is updated
  153. DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(applicationBasicAttrs)
  154. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_APPLICATION_VENDOR_NAME_ATTRIBUTE_ID, CHAR_STRING, kNameSize, 0), /* VendorName */
  155. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_APPLICATION_VENDOR_ID_ATTRIBUTE_ID, INT16U, 1, 0), /* VendorID */
  156. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_APPLICATION_NAME_ATTRIBUTE_ID, CHAR_STRING, kNameSize, 0), /* ApplicationName */
  157. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_APPLICATION_PRODUCT_ID_ATTRIBUTE_ID, INT16U, 1, 0), /* ProductID */
  158. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_APPLICATION_STATUS_ATTRIBUTE_ID, INT8U, 1, 0), /* ApplicationStatus */
  159. DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();
  160. // Declare Keypad Input cluster attributes
  161. DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(keypadInputAttrs)
  162. DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();
  163. // Declare Application Launcher cluster attributes
  164. // TODO: add missing attributes once schema is updated
  165. DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(applicationLauncherAttrs)
  166. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_APPLICATION_LAUNCHER_LIST_ATTRIBUTE_ID, ARRAY, kDescriptorAttributeArraySize, 0), /* catalog list */
  167. DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();
  168. // Declare Account Login cluster attributes
  169. DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(accountLoginAttrs)
  170. DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();
  171. // Declare Content Launcher cluster attributes
  172. DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(contentLauncherAttrs)
  173. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_CONTENT_LAUNCHER_ACCEPT_HEADER_ATTRIBUTE_ID, ARRAY, kDescriptorAttributeArraySize,
  174. 0), /* accept header list */
  175. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_CONTENT_LAUNCHER_SUPPORTED_STREAMING_PROTOCOLS_ATTRIBUTE_ID, BITMAP32, 1,
  176. 0), /* streaming protocols */
  177. DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();
  178. // Declare Media Playback cluster attributes
  179. // TODO: add missing attributes once schema is updated
  180. DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(mediaPlaybackAttrs)
  181. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_MEDIA_PLAYBACK_STATE_ATTRIBUTE_ID, ENUM8, 1, 0), /* current state */
  182. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_MEDIA_PLAYBACK_START_TIME_ATTRIBUTE_ID, EPOCH_US, 1, 0), /* start time */
  183. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_MEDIA_PLAYBACK_DURATION_ATTRIBUTE_ID, INT64U, 1, 0), /* duration */
  184. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_MEDIA_PLAYBACK_PLAYBACK_SPEED_ATTRIBUTE_ID, SINGLE, 1, 0), /* playback speed */
  185. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_MEDIA_PLAYBACK_PLAYBACK_SEEK_RANGE_END_ATTRIBUTE_ID, INT64U, 1, 0), /* seek range end */
  186. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_MEDIA_PLAYBACK_PLAYBACK_SEEK_RANGE_START_ATTRIBUTE_ID, INT64U, 1, 0), /* seek range start */
  187. DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();
  188. // Declare Target Navigator cluster attributes
  189. DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(targetNavigatorAttrs)
  190. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_TARGET_NAVIGATOR_LIST_ATTRIBUTE_ID, ARRAY, kDescriptorAttributeArraySize, 0), /* target list */
  191. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_TARGET_NAVIGATOR_CURRENT_TARGET_ATTRIBUTE_ID, INT8U, 1, 0), /* current target */
  192. DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();
  193. // Declare Channel cluster attributes
  194. DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(channelAttrs)
  195. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_CHANNEL_LIST_ATTRIBUTE_ID, ARRAY, kDescriptorAttributeArraySize, 0), /* channel list */
  196. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_CHANNEL_LINEUP_ATTRIBUTE_ID, STRUCT, 1, 0), /* lineup */
  197. DECLARE_DYNAMIC_ATTRIBUTE(ZCL_CHANNEL_CURRENT_CHANNEL_ATTRIBUTE_ID, STRUCT, 1, 0), /* current channel */
  198. DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();
  199. constexpr CommandId keypadInputIncomingCommands[] = {
  200. app::Clusters::KeypadInput::Commands::SendKey::Id,
  201. kInvalidCommandId,
  202. };
  203. constexpr CommandId keypadInputOutgoingCommands[] = {
  204. app::Clusters::KeypadInput::Commands::SendKeyResponse::Id,
  205. kInvalidCommandId,
  206. };
  207. constexpr CommandId applicationLauncherIncomingCommands[] = {
  208. app::Clusters::ApplicationLauncher::Commands::LaunchApp::Id,
  209. app::Clusters::ApplicationLauncher::Commands::StopApp::Id,
  210. app::Clusters::ApplicationLauncher::Commands::HideApp::Id,
  211. kInvalidCommandId,
  212. };
  213. constexpr CommandId applicationLauncherOutgoingCommands[] = {
  214. app::Clusters::ApplicationLauncher::Commands::LauncherResponse::Id,
  215. kInvalidCommandId,
  216. };
  217. constexpr CommandId accountLoginIncomingCommands[] = {
  218. app::Clusters::AccountLogin::Commands::GetSetupPIN::Id,
  219. app::Clusters::AccountLogin::Commands::Login::Id,
  220. app::Clusters::AccountLogin::Commands::Logout::Id,
  221. kInvalidCommandId,
  222. };
  223. constexpr CommandId accountLoginOutgoingCommands[] = {
  224. app::Clusters::AccountLogin::Commands::GetSetupPINResponse::Id,
  225. kInvalidCommandId,
  226. };
  227. // TODO: Sort out when the optional commands here should be listed.
  228. constexpr CommandId contentLauncherIncomingCommands[] = {
  229. app::Clusters::ContentLauncher::Commands::LaunchContent::Id,
  230. app::Clusters::ContentLauncher::Commands::LaunchURL::Id,
  231. kInvalidCommandId,
  232. };
  233. constexpr CommandId contentLauncherOutgoingCommands[] = {
  234. app::Clusters::ContentLauncher::Commands::LaunchResponse::Id,
  235. kInvalidCommandId,
  236. };
  237. // TODO: Sort out when the optional commands here should be listed.
  238. constexpr CommandId mediaPlaybackIncomingCommands[] = {
  239. app::Clusters::MediaPlayback::Commands::Play::Id, app::Clusters::MediaPlayback::Commands::Pause::Id,
  240. app::Clusters::MediaPlayback::Commands::StopPlayback::Id, app::Clusters::MediaPlayback::Commands::StartOver::Id,
  241. app::Clusters::MediaPlayback::Commands::Previous::Id, app::Clusters::MediaPlayback::Commands::Next::Id,
  242. app::Clusters::MediaPlayback::Commands::Rewind::Id, app::Clusters::MediaPlayback::Commands::FastForward::Id,
  243. app::Clusters::MediaPlayback::Commands::SkipForward::Id, app::Clusters::MediaPlayback::Commands::SkipBackward::Id,
  244. app::Clusters::MediaPlayback::Commands::Seek::Id, kInvalidCommandId,
  245. };
  246. constexpr CommandId mediaPlaybackOutgoingCommands[] = {
  247. app::Clusters::MediaPlayback::Commands::PlaybackResponse::Id,
  248. kInvalidCommandId,
  249. };
  250. constexpr CommandId targetNavigatorIncomingCommands[] = {
  251. app::Clusters::TargetNavigator::Commands::NavigateTarget::Id,
  252. kInvalidCommandId,
  253. };
  254. constexpr CommandId targetNavigatorOutgoingCommands[] = {
  255. app::Clusters::TargetNavigator::Commands::NavigateTargetResponse::Id,
  256. kInvalidCommandId,
  257. };
  258. // TODO: Sort out when the optional commands here should be listed.
  259. constexpr CommandId channelIncomingCommands[] = {
  260. app::Clusters::Channel::Commands::ChangeChannel::Id,
  261. app::Clusters::Channel::Commands::ChangeChannelByNumber::Id,
  262. app::Clusters::Channel::Commands::SkipChannel::Id,
  263. kInvalidCommandId,
  264. };
  265. constexpr CommandId channelOutgoingCommands[] = {
  266. app::Clusters::Channel::Commands::ChangeChannelResponse::Id,
  267. kInvalidCommandId,
  268. };
  269. // Declare Cluster List for Content App endpoint
  270. DECLARE_DYNAMIC_CLUSTER_LIST_BEGIN(contentAppClusters)
  271. DECLARE_DYNAMIC_CLUSTER(ZCL_DESCRIPTOR_CLUSTER_ID, descriptorAttrs, nullptr, nullptr),
  272. DECLARE_DYNAMIC_CLUSTER(ZCL_APPLICATION_BASIC_CLUSTER_ID, applicationBasicAttrs, nullptr, nullptr),
  273. DECLARE_DYNAMIC_CLUSTER(ZCL_KEYPAD_INPUT_CLUSTER_ID, keypadInputAttrs, keypadInputIncomingCommands,
  274. keypadInputOutgoingCommands),
  275. DECLARE_DYNAMIC_CLUSTER(ZCL_APPLICATION_LAUNCHER_CLUSTER_ID, applicationLauncherAttrs, applicationLauncherIncomingCommands,
  276. applicationLauncherOutgoingCommands),
  277. DECLARE_DYNAMIC_CLUSTER(ZCL_ACCOUNT_LOGIN_CLUSTER_ID, accountLoginAttrs, accountLoginIncomingCommands,
  278. accountLoginOutgoingCommands),
  279. DECLARE_DYNAMIC_CLUSTER(ZCL_CONTENT_LAUNCH_CLUSTER_ID, contentLauncherAttrs, contentLauncherIncomingCommands,
  280. contentLauncherOutgoingCommands),
  281. DECLARE_DYNAMIC_CLUSTER(ZCL_MEDIA_PLAYBACK_CLUSTER_ID, mediaPlaybackAttrs, mediaPlaybackIncomingCommands,
  282. mediaPlaybackOutgoingCommands),
  283. DECLARE_DYNAMIC_CLUSTER(ZCL_TARGET_NAVIGATOR_CLUSTER_ID, targetNavigatorAttrs, targetNavigatorIncomingCommands,
  284. targetNavigatorOutgoingCommands),
  285. DECLARE_DYNAMIC_CLUSTER(ZCL_CHANNEL_CLUSTER_ID, channelAttrs, channelIncomingCommands, channelOutgoingCommands),
  286. DECLARE_DYNAMIC_CLUSTER_LIST_END;
  287. // Declare Content App endpoint
  288. DECLARE_DYNAMIC_ENDPOINT(contentAppEndpoint, contentAppClusters);
  289. namespace {
  290. DataVersion gDataVersions[APP_LIBRARY_SIZE][ArraySize(contentAppClusters)];
  291. EmberAfDeviceType gContentAppDeviceType[] = { { DEVICE_TYPE_CONTENT_APP, 1 } };
  292. } // anonymous namespace
  293. ContentAppFactoryImpl::ContentAppFactoryImpl() {}
  294. uint16_t ContentAppFactoryImpl::GetPlatformCatalogVendorId()
  295. {
  296. return kCatalogVendorId;
  297. }
  298. CHIP_ERROR ContentAppFactoryImpl::LookupCatalogVendorApp(uint16_t vendorId, uint16_t productId, CatalogVendorApp * destinationApp)
  299. {
  300. std::string appId = BuildAppId(vendorId);
  301. destinationApp->catalogVendorId = GetPlatformCatalogVendorId();
  302. Platform::CopyString(destinationApp->applicationId, sizeof(destinationApp->applicationId), appId.c_str());
  303. return CHIP_NO_ERROR;
  304. }
  305. CHIP_ERROR ContentAppFactoryImpl::ConvertToPlatformCatalogVendorApp(const CatalogVendorApp & sourceApp,
  306. CatalogVendorApp * destinationApp)
  307. {
  308. destinationApp->catalogVendorId = GetPlatformCatalogVendorId();
  309. std::string appId(sourceApp.applicationId);
  310. if (appId == "applicationId")
  311. {
  312. // regression test case passes "applicationId", map this to our test suite app
  313. Platform::CopyString(destinationApp->applicationId, sizeof(destinationApp->applicationId), "1111");
  314. }
  315. else if (appId == "exampleid")
  316. {
  317. // cert test case passes "exampleid", map this to our test suite app
  318. Platform::CopyString(destinationApp->applicationId, sizeof(destinationApp->applicationId), "1");
  319. }
  320. else if (appId == "exampleString")
  321. {
  322. // cert test case passes "exampleString", map this to our test suite app
  323. Platform::CopyString(destinationApp->applicationId, sizeof(destinationApp->applicationId), "65521");
  324. }
  325. else
  326. {
  327. // for now, just return the applicationId passed in
  328. Platform::CopyString(destinationApp->applicationId, sizeof(destinationApp->applicationId), sourceApp.applicationId);
  329. }
  330. return CHIP_NO_ERROR;
  331. }
  332. ContentApp * ContentAppFactoryImpl::LoadContentApp(const CatalogVendorApp & vendorApp)
  333. {
  334. ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl: LoadContentAppByAppId catalogVendorId=%d applicationId=%s ",
  335. vendorApp.catalogVendorId, vendorApp.applicationId);
  336. for (size_t i = 0; i < mContentApps.size(); ++i)
  337. {
  338. auto & app = mContentApps.at(i);
  339. ChipLogProgress(DeviceLayer, " Looking next=%s ", app.GetApplicationBasicDelegate()->GetCatalogVendorApp()->applicationId);
  340. if (app.GetApplicationBasicDelegate()->GetCatalogVendorApp()->Matches(vendorApp))
  341. {
  342. ContentAppPlatform::GetInstance().AddContentApp(&app, &contentAppEndpoint, Span<DataVersion>(gDataVersions[i]),
  343. Span<const EmberAfDeviceType>(gContentAppDeviceType));
  344. return &app;
  345. }
  346. }
  347. ChipLogProgress(DeviceLayer, "LoadContentAppByAppId NOT FOUND catalogVendorId=%d applicationId=%s ", vendorApp.catalogVendorId,
  348. vendorApp.applicationId);
  349. return nullptr;
  350. }
  351. EndpointId ContentAppFactoryImpl::AddContentApp(ContentAppImpl & app)
  352. {
  353. DataVersion dataVersionBuf[ArraySize(contentAppClusters)];
  354. EndpointId epId = ContentAppPlatform::GetInstance().AddContentApp(&app, &contentAppEndpoint, Span<DataVersion>(dataVersionBuf),
  355. Span<const EmberAfDeviceType>(gContentAppDeviceType));
  356. ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl AddContentApp endpoint returned %d. Endpoint set %d", epId,
  357. app.GetEndpointId());
  358. mContentApps.push_back(app);
  359. return epId;
  360. }
  361. /**
  362. * @brief Code for testing the message flow path.
  363. *
  364. */
  365. class TestCommandHandlerCallback : public app::CommandHandler::Callback
  366. {
  367. void OnDone(app::CommandHandler & apCommandObj) {}
  368. void DispatchCommand(app::CommandHandler & apCommandObj, const app::ConcreteCommandPath & aCommandPath,
  369. TLV::TLVReader & apPayload)
  370. {}
  371. Protocols::InteractionModel::Status CommandExists(const app::ConcreteCommandPath & aCommandPath)
  372. {
  373. return Protocols::InteractionModel::Status::Success;
  374. }
  375. };
  376. /**
  377. * @brief Code for testing the message flow path.
  378. *
  379. */
  380. void ContentAppFactoryImpl::SendTestMessage(EndpointId epId, const char * message)
  381. {
  382. ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl SendTestMessage called with message %s & endpointId %d", message, epId);
  383. for (size_t i = 0; i < mContentApps.size(); ++i)
  384. {
  385. ContentAppImpl app = mContentApps.at(i);
  386. ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl checking app with endpointId %d", app.ContentApp::GetEndpointId());
  387. if (app.GetEndpointId() == epId)
  388. {
  389. ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl SendTestMessage endpoint found");
  390. app::ConcreteCommandPath commandPath(epId, app::Clusters::ContentLauncher::Id,
  391. app::Clusters::ContentLauncher::Commands::LaunchURL::Id);
  392. chip::AppPlatform::TestCommandHandlerCallback callback;
  393. app::CommandHandler commandHandler(&callback);
  394. CommandResponseHelper<LaunchResponseType> helper(&commandHandler, commandPath);
  395. chip::app::Clusters::ContentLauncher::Structs::BrandingInformation::Type branding;
  396. app.GetContentLauncherDelegate()->HandleLaunchUrl(helper, CharSpan::fromCharString(message),
  397. CharSpan::fromCharString("Temp Display"), branding);
  398. }
  399. }
  400. }
  401. } // namespace AppPlatform
  402. } // namespace chip
  403. #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
  404. CHIP_ERROR InitVideoPlayerPlatform()
  405. {
  406. #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
  407. ContentAppPlatform::GetInstance().SetupAppPlatform();
  408. ContentAppPlatform::GetInstance().SetContentAppFactory(&gFactory);
  409. #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
  410. #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
  411. CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
  412. if (cdc != nullptr)
  413. {
  414. cdc->SetPincodeService(&gMyPincodeService);
  415. cdc->SetUserPrompter(&gMyUserPrompter);
  416. cdc->SetPostCommissioningListener(&gMyPostCommissioningListener);
  417. }
  418. ChipLogProgress(AppServer, "Starting commissioner");
  419. ReturnErrorOnFailure(InitCommissioner(CHIP_PORT + 2 + 10, CHIP_UDC_PORT));
  420. ChipLogProgress(AppServer, "Started commissioner");
  421. #endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
  422. return CHIP_NO_ERROR;
  423. }
  424. CHIP_ERROR PreServerInit()
  425. {
  426. /**
  427. * Apply any user-defined configurations prior to initializing Server.
  428. *
  429. * Ex.
  430. * DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(userTimeoutSecs);
  431. *
  432. */
  433. return CHIP_NO_ERROR;
  434. }
  435. EndpointId AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
  436. const char * szApplicationVersion, jobject manager)
  437. {
  438. ContentAppImpl app =
  439. ContentAppImpl(szVendorName, vendorId, szApplicationName, productId, szApplicationVersion, "34567890", manager);
  440. ChipLogProgress(DeviceLayer, "AppImpl: AddContentApp vendorId=%d applicationName=%s ", vendorId, szApplicationName);
  441. return gFactory.AddContentApp(app);
  442. }
  443. void SendTestMessage(EndpointId epID, const char * message)
  444. {
  445. gFactory.SendTestMessage(epID, message);
  446. }