Artur Tynecki | 6e33196 | 2023-07-11 22:53:56 +0200 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) 2022 Project CHIP Authors |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | |
| 21 | #include <lib/support/logging/CHIPLogging.h> |
| 22 | |
| 23 | #include "openiotsdk_platform.h" |
| 24 | |
| 25 | #include "AppTv.h" |
| 26 | |
| 27 | #ifdef CHIP_TV_APP_SHELL_CMD_ENABLE |
| 28 | #include "AppTvShellCommands.h" |
| 29 | #include <lib/shell/Engine.h> |
| 30 | using namespace ::chip::Shell; |
| 31 | #endif // CHIP_TV_APP_SHELL_CMD_ENABLE |
| 32 | |
| 33 | using namespace ::chip; |
| 34 | |
| 35 | int main() |
| 36 | { |
| 37 | if (openiotsdk_platform_init()) |
| 38 | { |
| 39 | ChipLogError(NotSpecified, "Open IoT SDK platform initialization failed"); |
| 40 | return EXIT_FAILURE; |
| 41 | } |
| 42 | |
| 43 | if (openiotsdk_chip_init()) |
| 44 | { |
| 45 | ChipLogError(NotSpecified, "Open IoT SDK CHIP stack initialization failed"); |
| 46 | return EXIT_FAILURE; |
| 47 | } |
| 48 | |
| 49 | ChipLogProgress(NotSpecified, "Open IoT SDK tv-app example application start"); |
| 50 | |
| 51 | if (openiotsdk_network_init(true)) |
| 52 | { |
| 53 | ChipLogError(NotSpecified, "Network initialization failed"); |
| 54 | return EXIT_FAILURE; |
| 55 | } |
| 56 | |
| 57 | if (openiotsdk_chip_run()) |
| 58 | { |
| 59 | ChipLogError(NotSpecified, "CHIP stack run failed"); |
| 60 | return EXIT_FAILURE; |
| 61 | } |
| 62 | |
| 63 | #ifdef CHIP_TV_APP_SHELL_CMD_ENABLE |
| 64 | // Initialize the default streamer that was linked. |
| 65 | int ret = Engine::Root().Init(); |
| 66 | if (ret) |
| 67 | { |
| 68 | ChipLogError(Shell, "Streamer initialization failed [%d]", ret); |
| 69 | return EXIT_FAILURE; |
| 70 | } |
| 71 | |
| 72 | RegisterAppTvCommands(); |
| 73 | #endif // CHIP_TV_APP_SHELL_CMD_ENABLE |
| 74 | |
| 75 | CHIP_ERROR err = AppTvInit(); |
| 76 | if (err != CHIP_NO_ERROR) |
| 77 | { |
| 78 | ChipLogError(NotSpecified, "App TV initialization failed: %s", err.AsString()); |
| 79 | return EXIT_FAILURE; |
| 80 | } |
| 81 | |
| 82 | ChipLogProgress(NotSpecified, "Open IoT SDK tv-app example application run"); |
| 83 | |
| 84 | #ifdef CHIP_TV_APP_SHELL_CMD_ENABLE |
| 85 | Engine::Root().RunMainLoop(); |
| 86 | #else |
| 87 | while (true) |
| 88 | { |
| 89 | // Add forever delay to ensure proper workload for this thread |
| 90 | osDelay(osWaitForever); |
| 91 | } |
| 92 | #endif // CHIP_TV_APP_SHELL_CMD_ENABLE |
| 93 | |
| 94 | openiotsdk_chip_shutdown(); |
| 95 | |
| 96 | return EXIT_SUCCESS; |
| 97 | } |