blob: c88daf9b6065b64e657cfe13cbdc3eb513746186 [file] [log] [blame]
/**
*
* Copyright (c) 2021 Project CHIP Authors
*
* 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.
*/
/****************************************************************************
* @file
* @brief Routines for the Application Launcher plugin, the
*server implementation of the Application Launcher cluster.
*******************************************************************************
******************************************************************************/
#include <app-common/zap-generated/af-structs.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/enums.h>
#include <app/CommandHandler.h>
#include <app/ConcreteCommandPath.h>
#include <app/clusters/application-launcher-server/application-launcher-server.h>
#include <app/util/af.h>
using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ApplicationLauncher;
ApplicationLauncherResponse applicationLauncherClusterLaunchApp(EndpointId endpoint, ::Application application, std::string data);
ApplicationLauncherResponse applicationLauncherClusterStopApp(EndpointId endpoint, ::Application application, std::string data);
ApplicationLauncherResponse applicationLauncherClusterHideApp(EndpointId endpoint, ::Application application, std::string data);
bool emberAfApplicationLauncherClusterLaunchAppCallback(app::CommandHandler * commandObj,
const app::ConcreteCommandPath & commandPath, EndpointId endpoint,
uint8_t *, uint8_t *,
Commands::LaunchAppRequest::DecodableType & commandData)
{
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
emberAfSendImmediateDefaultResponse(status);
return true;
}
void sendResponse(app::CommandHandler * command, app::ConcreteCommandPath path, ApplicationLauncherResponse response)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
SuccessOrExit(err = command->PrepareCommand(path));
VerifyOrExit((writer = command->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
SuccessOrExit(err = writer->Put(TLV::ContextTag(0), response.status));
SuccessOrExit(err = writer->PutString(TLV::ContextTag(1), reinterpret_cast<const char *>(response.data)));
SuccessOrExit(err = command->FinishCommand());
exit:
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "Failed to send LauncherResponse. Error:%s", ErrorStr(err));
}
}
::Application getApplicationFromCommand(uint16_t catalogVendorId, CharSpan applicationId)
{
::Application application = {};
application.applicationId = applicationId;
application.catalogVendorId = catalogVendorId;
return application;
}
bool emberAfApplicationLauncherClusterLaunchAppRequestCallback(app::CommandHandler * command,
const app::ConcreteCommandPath & commandPath,
const Commands::LaunchAppRequest::DecodableType & commandData)
{
auto & requestData = commandData.data;
auto & requestApplicationCatalogVendorId = commandData.application.catalogVendorId;
auto & requestApplicationId = commandData.application.applicationId;
app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ApplicationLauncher::Id, Commands::LauncherResponse::Id };
::Application application = getApplicationFromCommand(requestApplicationCatalogVendorId, requestApplicationId);
std::string reqestDataString(requestData.data(), requestData.size());
ApplicationLauncherResponse response =
applicationLauncherClusterLaunchApp(emberAfCurrentEndpoint(), application, reqestDataString);
sendResponse(command, path, response);
return true;
}
/**
* @brief Application Launcher Cluster StopApp Command callback (from client)
*/
bool emberAfApplicationLauncherClusterStopAppRequestCallback(app::CommandHandler * command,
const app::ConcreteCommandPath & commandPath,
const Commands::StopAppRequest::DecodableType & commandData)
{
auto & requestApplicationCatalogVendorId = commandData.application.catalogVendorId;
auto & requestApplicationId = commandData.application.applicationId;
app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ApplicationLauncher::Id, Commands::LauncherResponse::Id };
::Application application = getApplicationFromCommand(requestApplicationCatalogVendorId, requestApplicationId);
ApplicationLauncherResponse response = applicationLauncherClusterStopApp(emberAfCurrentEndpoint(), application, "data");
sendResponse(command, path, response);
return true;
}
/**
* @brief Application Launcher Cluster HideApp Command callback (from client)
*/
bool emberAfApplicationLauncherClusterHideAppRequestCallback(app::CommandHandler * command,
const app::ConcreteCommandPath & commandPath,
const Commands::HideAppRequest::DecodableType & commandData)
{
auto & requestApplicationCatalogVendorId = commandData.application.catalogVendorId;
auto & requestApplicationId = commandData.application.applicationId;
app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ApplicationLauncher::Id, Commands::LauncherResponse::Id };
::Application application = getApplicationFromCommand(requestApplicationCatalogVendorId, requestApplicationId);
ApplicationLauncherResponse response = applicationLauncherClusterHideApp(emberAfCurrentEndpoint(), application, "data");
sendResponse(command, path, response);
return true;
}
void MatterApplicationLauncherPluginServerInitCallback() {}