-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[examples] Extract common Linux platform app start up code (#6222)
* [examples] Extract common Linux platform app start up code * Restyled by gn * Use LogDeviceConfig + PrintOnboardingCodes * Move PW_RPC_ENABLED back to program * Add PW_RPC_ENABLED * Fix Linux build Co-authored-by: Restyled.io <commits@restyled.io>
- Loading branch information
Showing
13 changed files
with
218 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include <iostream> | ||
#include <thread> | ||
|
||
#include <platform/CHIPDeviceLayer.h> | ||
#include <platform/PlatformManager.h> | ||
|
||
#include <app/server/OnboardingCodesUtil.h> | ||
#include <app/server/Server.h> | ||
#include <core/CHIPError.h> | ||
#include <setup_payload/QRCodeSetupPayloadGenerator.h> | ||
#include <setup_payload/SetupPayload.h> | ||
#include <support/CHIPMem.h> | ||
#include <support/RandUtils.h> | ||
|
||
#if defined(PW_RPC_ENABLED) | ||
#include <CommonRpc.h> | ||
#endif | ||
|
||
#include "Options.h" | ||
|
||
using namespace chip; | ||
using namespace chip::Inet; | ||
using namespace chip::Transport; | ||
using namespace chip::DeviceLayer; | ||
|
||
namespace { | ||
void EventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg) | ||
{ | ||
(void) arg; | ||
if (event->Type == chip::DeviceLayer::DeviceEventType::kCHIPoBLEConnectionEstablished) | ||
{ | ||
ChipLogProgress(DeviceLayer, "Receive kCHIPoBLEConnectionEstablished"); | ||
} | ||
} | ||
} // namespace | ||
|
||
int ChipLinuxAppInit(int argc, char ** argv) | ||
{ | ||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
|
||
err = chip::Platform::MemoryInit(); | ||
SuccessOrExit(err); | ||
|
||
err = ParseArguments(argc, argv); | ||
SuccessOrExit(err); | ||
|
||
err = chip::DeviceLayer::PlatformMgr().InitChipStack(); | ||
SuccessOrExit(err); | ||
|
||
ConfigurationMgr().LogDeviceConfig(); | ||
PrintOnboardingCodes(chip::RendezvousInformationFlag::kBLE); | ||
|
||
#if defined(PW_RPC_ENABLED) | ||
chip::rpc::Init(); | ||
ChipLogProgress(NotSpecified, "PW_RPC initialized."); | ||
#endif // defined(PW_RPC_ENABLED) | ||
|
||
chip::DeviceLayer::PlatformMgrImpl().AddEventHandler(EventHandler, 0); | ||
|
||
chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName(nullptr); // Use default device name (CHIP-XXXX) | ||
|
||
#if CONFIG_NETWORK_LAYER_BLE | ||
chip::DeviceLayer::Internal::BLEMgrImpl().ConfigureBle(LinuxDeviceOptions::GetInstance().mBleDevice, false); | ||
#endif | ||
|
||
chip::DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(true); | ||
|
||
#if CHIP_DEVICE_CONFIG_ENABLE_WPA | ||
if (LinuxDeviceOptions::GetInstance().mWiFi) | ||
{ | ||
chip::DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement(); | ||
} | ||
#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA | ||
|
||
#if CHIP_ENABLE_OPENTHREAD | ||
if (LinuxDeviceOptions::GetInstance().mThread) | ||
{ | ||
SuccessOrExit(err = chip::DeviceLayer::ThreadStackMgrImpl().InitThreadStack()); | ||
ChipLogProgress(NotSpecified, "Thread initialized."); | ||
} | ||
#endif // CHIP_ENABLE_OPENTHREAD | ||
|
||
exit: | ||
if (err != CHIP_NO_ERROR) | ||
{ | ||
ChipLogProgress(NotSpecified, "Failed to run Linux Lighting App: %s ", ErrorStr(err)); | ||
// End the program with non zero error code to indicate a error. | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
void ChipLinuxAppMainLoop() | ||
{ | ||
// Init ZCL Data Model and CHIP App Server | ||
InitServer(); | ||
|
||
chip::DeviceLayer::PlatformMgr().RunEventLoop(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* | ||
* 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 | ||
|
||
int ChipLinuxAppInit(int argc, char ** argv); | ||
void ChipLinuxAppMainLoop(); |
Oops, something went wrong.