blob: 40cd8c007e8baade1c9d152b14f90d1136d458e1 [file] [log] [blame]
/*
*
* Copyright (c) 2024 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.
*/
#include "Device.h"
#include <cstdio>
#include <platform/CHIPDeviceLayer.h>
#include <string>
using namespace chip::app::Clusters::Actions;
Device::Device(const char * szDeviceName, std::string szLocation)
{
chip::Platform::CopyString(mName, szDeviceName);
mLocation = szLocation;
mReachable = false;
mEndpointId = 0;
}
bool Device::IsReachable()
{
return mReachable;
}
void Device::SetReachable(bool aReachable)
{
bool changed = (mReachable != aReachable);
mReachable = aReachable;
if (aReachable)
{
ChipLogProgress(DeviceLayer, "Device[%s]: ONLINE", mName);
}
else
{
ChipLogProgress(DeviceLayer, "Device[%s]: OFFLINE", mName);
}
if (changed)
{
HandleDeviceChange(this, kChanged_Reachable);
}
}
void Device::SetName(const char * szName)
{
bool changed = (strncmp(mName, szName, sizeof(mName)) != 0);
ChipLogProgress(DeviceLayer, "Device[%s]: New Name=\"%s\"", mName, szName);
chip::Platform::CopyString(mName, szName);
if (changed)
{
HandleDeviceChange(this, kChanged_Name);
}
}