blob: fcee09524cae06d75db091b3fa7befd8f583c871 [file] [log] [blame]
/*
*
* Copyright (c) 2025 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 "JFAManager.h"
#include "rpc/RpcServer.h"
#include <AppMain.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/ConcreteAttributePath.h>
#include <app/server/Server.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/DeviceInstanceInfoProvider.h>
#include <string>
using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::DeviceLayer;
namespace {
class ExampleDeviceInstanceInfoProvider : public DeviceInstanceInfoProvider
{
public:
void Init(DeviceInstanceInfoProvider * defaultProvider) { mDefaultProvider = defaultProvider; }
CHIP_ERROR GetVendorName(char * buf, size_t bufSize) override { return mDefaultProvider->GetVendorName(buf, bufSize); }
CHIP_ERROR GetVendorId(uint16_t & vendorId) override { return mDefaultProvider->GetVendorId(vendorId); }
CHIP_ERROR GetProductName(char * buf, size_t bufSize) override { return mDefaultProvider->GetProductName(buf, bufSize); }
CHIP_ERROR GetProductId(uint16_t & productId) override { return mDefaultProvider->GetProductId(productId); }
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override { return mDefaultProvider->GetPartNumber(buf, bufSize); }
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override { return mDefaultProvider->GetProductURL(buf, bufSize); }
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override { return mDefaultProvider->GetProductLabel(buf, bufSize); }
CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) override { return mDefaultProvider->GetSerialNumber(buf, bufSize); }
CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override
{
return mDefaultProvider->GetManufacturingDate(year, month, day);
}
CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override
{
return mDefaultProvider->GetHardwareVersion(hardwareVersion);
}
CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override
{
return mDefaultProvider->GetHardwareVersionString(buf, bufSize);
}
CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) override
{
return mDefaultProvider->GetRotatingDeviceIdUniqueId(uniqueIdSpan);
}
CHIP_ERROR GetJointFabricMode(uint8_t & jointFabricMode) override { return JFAMgr().GetJointFabricMode(jointFabricMode); }
private:
DeviceInstanceInfoProvider * mDefaultProvider;
};
ExampleDeviceInstanceInfoProvider gExampleDeviceInstanceInfoProvider;
} // namespace
void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size,
uint8_t * value)
{}
void EventHandler(const ChipDeviceEvent * event, intptr_t arg)
{
(void) arg;
if (event->Type == DeviceEventType::kCommissioningComplete)
{
JFAMgr().HandleCommissioningCompleteEvent();
}
}
void ApplicationInit()
{
auto * defaultProvider = GetDeviceInstanceInfoProvider();
if (defaultProvider != &gExampleDeviceInstanceInfoProvider)
{
gExampleDeviceInstanceInfoProvider.Init(defaultProvider);
SetDeviceInstanceInfoProvider(&gExampleDeviceInstanceInfoProvider);
}
JFAMgr().Init(Server::GetInstance());
Server::GetInstance().GetJointFabricAdministrator().SetDelegate(&JFAMgr());
PlatformMgrImpl().AddEventHandler(EventHandler, 0);
}
void ApplicationShutdown() {}
#ifdef __NuttX__
// NuttX requires the main function to be defined with C-linkage. However, marking
// the main as extern "C" is not strictly conformant with the C++ standard. Since
// clang >= 20 such code triggers -Wmain warning.
extern "C" {
#endif
int main(int argc, char * argv[])
{
LinuxDeviceOptions::GetInstance().rpcServerPort = RPC_SERVER_PORT;
if (ChipLinuxAppInit(argc, argv) != 0)
{
return -1;
}
ChipLinuxAppMainLoop();
return 0;
}
#ifdef __NuttX__
}
#endif