Skip to content

Commit

Permalink
Add delegate API methods to media clusters (#13259)
Browse files Browse the repository at this point in the history
* Update app/clusters with delegate methods

* Update test and Content App

* Update Linux TV app

* Update android TV app

* Run zap regen tool & update random other folders and references

* Restyle fix

* Fix TV app Linux build
  • Loading branch information
lazarkov authored and pull[bot] committed Jan 31, 2022
1 parent 4bbeb8c commit 61e6449
Show file tree
Hide file tree
Showing 119 changed files with 3,903 additions and 2,272 deletions.
1 change: 1 addition & 0 deletions examples/all-clusters-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ set(SRC_DIRS_LIST
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ias-zone-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ethernet-network-diagnostics-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/wifi-network-diagnostics-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/wake-on-lan-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/pump-configuration-and-control-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/power-source-configuration-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common/src"
Expand Down
1 change: 1 addition & 0 deletions examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ executable("chip-all-clusters-app") {
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/ota-requestor-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp",
"include/tv-callbacks.cpp",
"include/tv-callbacks.h",
"main.cpp",
]

Expand Down
5 changes: 2 additions & 3 deletions examples/all-clusters-app/linux/include/tv-callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
*******************************************************************************
******************************************************************************/

#include <list>
#include <string>
#include "tv-callbacks.h"

bool lowPowerClusterSleep()
bool LowPowerManager::HandleSleep()
{
return true;
}
31 changes: 31 additions & 0 deletions examples/all-clusters-app/linux/include/tv-callbacks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
*
* 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 TV stubs
*server stub implementation of TV cluster code.
*******************************************************************************
******************************************************************************/

#include <app/clusters/low-power-server/low-power-server.h>

class LowPowerManager : public chip::app::Clusters::LowPower::Delegate
{
public:
bool HandleSleep() override;
};
11 changes: 11 additions & 0 deletions examples/all-clusters-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

#include "include/tv-callbacks.h"
#include <app/CommandHandler.h>
#include <app/clusters/identify-server/identify-server.h>
#include <app/clusters/network-commissioning/network-commissioning.h>
Expand All @@ -28,6 +29,10 @@ using namespace chip;
using namespace chip::app;
using namespace chip::DeviceLayer;

namespace {
static LowPowerManager lowPowerManager;
} // namespace

bool emberAfBasicClusterMfgSpecificPingCallback(chip::app::CommandHandler * commandObj)
{
emberAfSendDefaultResponse(emberAfCurrentCommand(), EMBER_ZCL_STATUS_SUCCESS);
Expand Down Expand Up @@ -108,3 +113,9 @@ int main(int argc, char * argv[])
ChipLinuxAppMainLoop();
return 0;
}

void emberAfLowPowerClusterInitCallback(EndpointId endpoint)
{
ChipLogProgress(Zcl, "TV Linux App: LowPower::SetDefaultDelegate");
chip::app::Clusters::LowPower::SetDefaultDelegate(endpoint, &lowPowerManager);
}
1 change: 1 addition & 0 deletions examples/all-clusters-app/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ target_sources(${APP_TARGET} PRIVATE
${APP_CLUSTERS}/ethernet-network-diagnostics-server/ethernet-network-diagnostics-server.cpp
${APP_CLUSTERS}/software-diagnostics-server/software-diagnostics-server.cpp
${APP_CLUSTERS}/thread-network-diagnostics-server/thread-network-diagnostics-server.cpp
${APP_CLUSTERS}/wake-on-lan-server/wake-on-lan-server.cpp
${APP_CLUSTERS}/wifi-network-diagnostics-server/wifi-network-diagnostics-server.cpp
${APP_CLUSTERS}/pump-configuration-and-control-server/pump-configuration-and-control-server.cpp
${APP_CLUSTERS}/administrator-commissioning-server/administrator-commissioning-server.cpp
Expand Down
5 changes: 4 additions & 1 deletion examples/all-clusters-app/mbed/main/LowPowerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
* limitations under the License.
*/

bool lowPowerClusterSleep()
#include "LowPowerManager.h"

bool LowPowerManager::HandleSleep()
{
// TODO: Insert code here
return true;
}
27 changes: 27 additions & 0 deletions examples/all-clusters-app/mbed/main/include/LowPowerManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
*
* 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.
*/

#pragma once

#include <app/clusters/low-power-server/low-power-server.h>

class LowPowerManager : public chip::app::Clusters::LowPower::Delegate
{
public:
bool HandleSleep() override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "LowPowerManager.h"

bool lowPowerClusterSleep()
bool LowPowerManager::HandleSleep()
{
// TODO: Insert code here
return true;
Expand Down
5 changes: 3 additions & 2 deletions examples/thermostat/linux/include/low-power/LowPowerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

#pragma once

#include <lib/core/CHIPError.h>
#include <app/clusters/low-power-server/low-power-server.h>

class LowPowerManager
class LowPowerManager : public chip::app::Clusters::LowPower::Delegate
{
public:
bool HandleSleep() override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,75 +17,35 @@
*/

#include "AccountLoginManager.h"
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app-common/zap-generated/command-id.h>
#include <app-common/zap-generated/enums.h>
#include <app/CommandHandler.h>
#include <app/util/af.h>

using namespace std;
using namespace chip::app::Clusters::AccountLogin;

bool AccountLoginManager::isUserLoggedIn(string requestTempAccountIdentifier, string requestSetupPin)
bool AccountLoginManager::HandleLogin(const chip::CharSpan & tempAccountIdentifier, const chip::CharSpan & setupPin)
{
// TODO: Fix hardcoding length of strings
requestTempAccountIdentifier = requestTempAccountIdentifier.substr(0, 4);
requestSetupPin = requestSetupPin.substr(0, 10);
for (auto it = accounts.cbegin(); it != accounts.cend(); ++it)
{
ChipLogProgress(Zcl, "temporary account id: %s", it->first.c_str());
ChipLogProgress(Zcl, "setup pin %s", it->second.c_str());
}
string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size());
string setupPinString(setupPin.data(), setupPin.size());
ChipLogProgress(Zcl, "temporary account id: %s", tempAccountIdentifierString.c_str());
ChipLogProgress(Zcl, "setup pin %s", setupPinString.c_str());

if (accounts.find(requestTempAccountIdentifier) != accounts.end())
{
bool found = accounts[requestTempAccountIdentifier] == requestSetupPin;
if (!found)
{
ChipLogError(Zcl, "User is not logged in, failed to match request setup pin.");
}
return found;
}
else
{
ChipLogError(Zcl, "User is not logged in, failed to find temp account identifier.");
return false;
}
}

void AccountLoginManager::setTempAccountIdentifierForPin(string tempAccountIdentifier, string setupPin)
{
// TODO: Fix hardcoding length of strings
string tempId = tempAccountIdentifier.substr(0, 4);
accounts[tempId] = setupPin;
}

string AccountLoginManager::proxySetupPinRequest(string requestTempAccountIdentifier, chip::EndpointId endpoint)
{
// TODO: Insert your code here to send temp account identifier request
return "tempPin123";
// TODO: Insert your code here to handle login request
return true;
}

bool AccountLoginManager::proxyLogout()
bool AccountLoginManager::HandleLogout()
{
// TODO: Insert your code here to send logout request
return true;
}

bool accountLoginClusterIsUserLoggedIn(std::string requestTempAccountIdentifier, std::string requestSetupPin)
{
return AccountLoginManager().GetInstance().isUserLoggedIn(requestTempAccountIdentifier, requestSetupPin);
}

bool accountLoginClusterLogout()
{
return AccountLoginManager().GetInstance().proxyLogout();
}

std::string accountLoginClusterGetSetupPin(std::string requestTempAccountIdentifier, chip::EndpointId endpoint)
Commands::GetSetupPINResponse::Type AccountLoginManager::HandleGetSetupPin(const chip::CharSpan & tempAccountIdentifier)
{
string responseSetupPin = AccountLoginManager().proxySetupPinRequest(requestTempAccountIdentifier, endpoint);
AccountLoginManager().GetInstance().setTempAccountIdentifierForPin(requestTempAccountIdentifier, responseSetupPin);
return responseSetupPin;
string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size());
ChipLogProgress(Zcl, "temporary account id: %s", tempAccountIdentifierString.c_str());
// TODO: Insert your code here to handle get setup pin
Commands::GetSetupPINResponse::Type response;
response.setupPIN = chip::CharSpan("tempPin123", strlen("tempPin123"));
return response;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,15 @@

#pragma once

#include <app/clusters/account-login-server/account-login-server.h>

#include <app/util/af-types.h>
#include <lib/core/CHIPError.h>
#include <map>
#include <string>

class AccountLoginManager
class AccountLoginManager : public chip::app::Clusters::AccountLogin::Delegate
{
public:
bool isUserLoggedIn(std::string requestTempAccountIdentifier, std::string requestSetupPin);
bool proxyLogout();
std::string proxySetupPinRequest(std::string requestTempAccountIdentifier, chip::EndpointId endpoint);
void setTempAccountIdentifierForPin(std::string requestTempAccountIdentifier, std::string requestSetupPin);

static AccountLoginManager & GetInstance()
{
static AccountLoginManager instance;
return instance;
}

private:
std::map<std::string, std::string> accounts;
bool HandleLogin(const chip::CharSpan & tempAccountIdentifierString, const chip::CharSpan & setupPinString) override;
bool HandleLogout() override;
chip::app::Clusters::AccountLogin::Commands::GetSetupPINResponse::Type
HandleGetSetupPin(const chip::CharSpan & tempAccountIdentifierString) override;
};
Loading

0 comments on commit 61e6449

Please sign in to comment.