Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle Add delegate API methods to media clusters #13260

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
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;
}
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