Writing a Code-Driven Application: POSIX (GN)#
Build and entrypoint deltas for converting
examples/all-devices-app/posix/ into a single-device product
application. See Writing a Code-Driven Application
for architecture and device class implementation.
1. GN Build Deltas (posix/BUILD.gn, posix/linux/BUILD.gn, posix/darwin/BUILD.gn)#
Remove Simulator & Example Scaffolding:
Remove
all-devices-common/device-factoryandDeviceFactoryPlatformOverride.hfromposix/BUILD.gn,posix/linux/BUILD.gn, andposix/darwin/BUILD.gn(if your target device relies on platform setup inDeviceFactoryPlatformOverride.h, such asPosixAudioManagerorCommissioningProxytransport adapters, move that initialization into your entrypoint before removing the header).Remove
all-devices-common/device-factoryand:device-type-parserfromposix/app_options/BUILD.gn, remove<app_options/DeviceTypeParser.h>andGetDeviceTypeEntries()fromAppOptions.h, and remove--device/NoHooksDeviceFactoryhandling fromAppOptions.cpp(include<lib/support/BytesToHex.h>directly inAppOptions.cppifHexToBytesis retained).Remove
oob-accessors,posix/named_pipe, sample peripheral sources (PosixAudioManager.cpp,PosixChime.cpp,PosixSpeaker.cpp), unuseddevice/types/*targets, and all:posixsub-targets (which compileNamedPipeTranslators.cppand depend onposix/named_pipe; mock delegates live in:loggingor:simulatedsub-targets). Also remove unusedcommissioning-proxy,miniaudio, andjsoncppdependencies fromposix/BUILD.gn,posix/linux/BUILD.gn, andposix/darwin/BUILD.gn.
Keep Platform & Root Node Dependencies:
Keep
posix/app_options:app-options,device/types/root-node(and:wifi), and the single base device target (e.g.,device/types/speaker). If copyingposix/into a standalone directory, preserve thebuild_overridesandthird_partysymlinks and update//examples/all-devices-app/posix/...paths inargs.gniandBUILD.gn:
sources = [
"MyProductSpeaker.cpp",
"MyProductSpeaker.h",
"include/CHIPProjectAppConfig.h",
"main.cpp",
]
deps = [
"${chip_root}/examples/all-devices-app/all-devices-common/device/types/root-node",
"${chip_root}/examples/all-devices-app/all-devices-common/device/types/root-node:wifi",
"${chip_root}/examples/all-devices-app/all-devices-common/device/types/speaker",
"${chip_root}/examples/all-devices-app/posix/app_options:app-options",
# ... keep existing platform/linux, providers, and codedriven persistence deps ...
]
2. Entrypoint Deltas (posix/main.cpp)#
Keep:
Platform initialization,
mAttributePersistence,mDataModelProvider, andmRootNode(AppRootNode) construction inCodeDrivenDataModelDevices(note thatAppRootNodeonly wraps plain and Wi-Fi root nodes by default; enabling OTA on POSIX requires linkingdevice/types/root-node:otaand composingOtaFeature).
Remove:
All
PosixDeviceFactoryregistration, CLI--devicetopology loops, named pipe setup, and sample audio manager hooks (including the audio-onlyApplicationShutdown()helper).
Replace:
Own a member instance
MyProductSpeaker mProductDeviceinCodeDrivenDataModelDevicesand register/unregister it inStartup()andShutdown()alongsidemRootNode.RootDevice():
CHIP_ERROR Startup()
{
ReturnErrorOnFailure(mAttributePersistence.Init(&mContext.storageDelegate));
ReturnErrorOnFailure(mRootNode.RootDevice().Register(kRootEndpointId, mDataModelProvider));
ReturnErrorOnFailure(mProductDevice.Register(EndpointId(1), mDataModelProvider));
return CHIP_NO_ERROR;
}
void Shutdown()
{
mProductDevice.Unregister(mDataModelProvider);
mRootNode.RootDevice().Unregister(mDataModelProvider);
}