16
16
* limitations under the License.
17
17
*/
18
18
19
+ #include < app/OperationalDeviceProxy.h>
19
20
#include < app/server/Dnssd.h>
20
21
#include < app/server/Server.h>
21
22
#include < controller/CHIPCommissionableNodeController.h>
27
28
#include < lib/support/SafeInt.h>
28
29
#include < platform/CHIPDeviceLayer.h>
29
30
#include < platform/ConfigurationManager.h>
31
+ #include < platform/DeviceControlServer.h>
30
32
#include < system/SystemLayer.h>
31
33
#include < transport/raw/PeerAddress.h>
34
+ #include < zap-generated/CHIPClusters.h>
32
35
33
36
#include < list>
34
37
#include < string>
@@ -39,6 +42,7 @@ using namespace chip::Credentials;
39
42
using chip::ArgParser::HelpOptions;
40
43
using chip::ArgParser::OptionDef;
41
44
using chip::ArgParser::OptionSet;
45
+ using namespace chip ::app::Clusters::ContentLauncher::Commands;
42
46
43
47
struct TVExampleDeviceType
44
48
{
@@ -52,10 +56,17 @@ constexpr uint16_t kOptionDeviceType = 't';
52
56
constexpr uint16_t kCommissioningWindowTimeoutInSec = 3 * 60 ;
53
57
constexpr uint32_t kCommissionerDiscoveryTimeoutInMs = 5 * 1000 ;
54
58
59
+ // TODO: Accept these values over CLI
60
+ const char * kContentUrl = " https://www.test.com/videoid" ;
61
+ const char * kContentDisplayStr = " Test video" ;
62
+ constexpr EndpointId kTvEndpoint = 1 ;
63
+
55
64
CommissionableNodeController gCommissionableNodeController ;
56
65
chip::System::SocketWatchToken gToken ;
57
66
Dnssd::DiscoveryFilter gDiscoveryFilter = Dnssd::DiscoveryFilter();
58
67
68
+ CASEClientPool<CHIP_CONFIG_DEVICE_MAX_ACTIVE_CASE_CLIENTS> gCASEClientPool ;
69
+
59
70
bool HandleOptions (const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue)
60
71
{
61
72
switch (aIdentifier)
@@ -188,6 +199,68 @@ void InitCommissioningFlow(intptr_t commandArg)
188
199
}
189
200
}
190
201
202
+ void OnContentLauncherSuccessResponse (void * context, const LaunchURLResponse::DecodableType & response)
203
+ {
204
+ ChipLogProgress (AppServer, " ContentLauncher: Default Success Response" );
205
+ }
206
+
207
+ void OnContentLauncherFailureResponse (void * context, EmberAfStatus status)
208
+ {
209
+ ChipLogError (AppServer, " ContentLauncher: Default Failure Response: %" PRIu8, status);
210
+ }
211
+
212
+ void DeviceEventCallback (const DeviceLayer::ChipDeviceEvent * event, intptr_t arg)
213
+ {
214
+ if (event->Type == DeviceLayer::DeviceEventType::kCommissioningComplete )
215
+ {
216
+ chip::NodeId tvNodeId = chip::DeviceLayer::DeviceControlServer::DeviceControlSvr ().GetPeerNodeId ();
217
+ chip::FabricIndex peerFabricIndex = chip::DeviceLayer::DeviceControlServer::DeviceControlSvr ().GetFabricIndex ();
218
+
219
+ Server * server = &(chip::Server::GetInstance ());
220
+ chip::FabricInfo * fabric = server->GetFabricTable ().FindFabricWithIndex (peerFabricIndex);
221
+ if (fabric == nullptr )
222
+ {
223
+ ChipLogError (AppServer, " Did not find fabric for index %d" , peerFabricIndex);
224
+ return ;
225
+ }
226
+
227
+ chip::DeviceProxyInitParams initParams = {
228
+ .sessionManager = &(server->GetSecureSessionManager ()),
229
+ .exchangeMgr = &(server->GetExchangeManager ()),
230
+ .idAllocator = &(server->GetSessionIDAllocator ()),
231
+ .fabricTable = &(server->GetFabricTable ()),
232
+ .clientPool = &gCASEClientPool ,
233
+ .imDelegate = chip::Platform::New<chip::Controller::DeviceControllerInteractionModelDelegate>(),
234
+ };
235
+
236
+ PeerId peerID = fabric->GetPeerIdForNode (tvNodeId);
237
+ chip::OperationalDeviceProxy * operationalDeviceProxy =
238
+ chip::Platform::New<chip::OperationalDeviceProxy>(initParams, peerID);
239
+ if (operationalDeviceProxy == nullptr )
240
+ {
241
+ ChipLogError (AppServer, " Failed in creating an instance of OperationalDeviceProxy" );
242
+ return ;
243
+ }
244
+
245
+ SessionHandle handle = server->GetSecureSessionManager ().FindSecureSessionForNode (tvNodeId);
246
+ operationalDeviceProxy->SetConnectedSession (handle);
247
+
248
+ ContentLauncherCluster cluster;
249
+ CHIP_ERROR err = cluster.Associate (operationalDeviceProxy, kTvEndpoint );
250
+ if (err != CHIP_NO_ERROR)
251
+ {
252
+ ChipLogError (AppServer, " Associate() failed: %" CHIP_ERROR_FORMAT, err.Format ());
253
+ return ;
254
+ }
255
+ LaunchURL::Type request;
256
+ request.contentURL = chip::CharSpan (kContentUrl , strlen (kContentUrl ));
257
+ request.displayString = chip::CharSpan (kContentDisplayStr , strlen (kContentDisplayStr ));
258
+ request.brandingInformation = chip::app::DataModel::List<
259
+ const chip::app::Clusters::ContentLauncher::Structs::ContentLaunchBrandingInformation::Type>();
260
+ cluster.InvokeCommand (request, nullptr , OnContentLauncherSuccessResponse, OnContentLauncherFailureResponse);
261
+ }
262
+ }
263
+
191
264
int main (int argc, char * argv[])
192
265
{
193
266
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -218,7 +291,8 @@ int main(int argc, char * argv[])
218
291
chip::System::Clock::Milliseconds32 (kCommissionerDiscoveryTimeoutInMs ),
219
292
[](System::Layer *, void *) { chip::DeviceLayer::PlatformMgr ().ScheduleWork (InitCommissioningFlow); }, nullptr );
220
293
221
- // TBD: Content casting commands
294
+ // Add callback to send Content casting commands after commissioning completes
295
+ chip::DeviceLayer::PlatformMgrImpl ().AddEventHandler (DeviceEventCallback, 0 );
222
296
223
297
DeviceLayer::PlatformMgr ().RunEventLoop ();
224
298
exit :
0 commit comments