|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2024 Project CHIP Authors |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +#include <AppMain.h> |
| 20 | +#include <app/server/TermsAndConditionsManager.h> |
| 21 | +#include <app/server/TermsAndConditionsProvider.h> |
| 22 | + |
| 23 | +using namespace chip; |
| 24 | +using namespace chip::ArgParser; |
| 25 | + |
| 26 | +static uint16_t sTcMinRequiredVersion = 0; |
| 27 | +static uint16_t sTcRequiredAcknowledgements = 0; |
| 28 | + |
| 29 | +static OptionDef sTermsAndConditionsOptions[] = { |
| 30 | + { "tc-min-required-version", kArgumentRequired, 'm' }, |
| 31 | + { "tc-required-acknowledgements", kArgumentRequired, 'r' }, |
| 32 | + { nullptr }, |
| 33 | +}; |
| 34 | + |
| 35 | +static const char * const sTermsAndConditionsOptionHelp = |
| 36 | + "-m, --tc-min-required-version <number>\n Configure the minimum required TC version.\n\n" |
| 37 | + "-r, --tc-required-acknowledgements <number (bitfield)>\n Configure the required TC acknowledgements.\n\n"; |
| 38 | + |
| 39 | +static bool HandleOption(const char * progName, OptionSet * optSet, int id, const char * name, const char * arg) |
| 40 | +{ |
| 41 | + switch (id) |
| 42 | + { |
| 43 | + case 'm': |
| 44 | + sTcMinRequiredVersion = static_cast<uint16_t>(atoi(arg)); |
| 45 | + break; |
| 46 | + case 'r': |
| 47 | + sTcRequiredAcknowledgements = static_cast<uint16_t>(atoi(arg)); |
| 48 | + break; |
| 49 | + default: |
| 50 | + PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", progName, name); |
| 51 | + return false; |
| 52 | + } |
| 53 | + |
| 54 | + return true; |
| 55 | +} |
| 56 | + |
| 57 | +static OptionSet sTermsAndConditionsCmdLineOptions = { |
| 58 | + HandleOption, |
| 59 | + sTermsAndConditionsOptions, |
| 60 | + "TERMS AND CONDITIONS OPTIONS", |
| 61 | + sTermsAndConditionsOptionHelp, |
| 62 | +}; |
| 63 | + |
| 64 | +void ApplicationInit() |
| 65 | +{ |
| 66 | + const app::TermsAndConditions termsAndConditions = app::TermsAndConditions(sTcRequiredAcknowledgements, sTcMinRequiredVersion); |
| 67 | + PersistentStorageDelegate & persistentStorageDelegate = Server::GetInstance().GetPersistentStorage(); |
| 68 | + app::TermsAndConditionsManager::GetInstance()->Init(&persistentStorageDelegate, MakeOptional(termsAndConditions)); |
| 69 | +} |
| 70 | + |
| 71 | +void ApplicationShutdown() {} |
| 72 | + |
| 73 | +int main(int argc, char * argv[]) |
| 74 | +{ |
| 75 | + if (ChipLinuxAppInit(argc, argv, &sTermsAndConditionsCmdLineOptions) != 0) |
| 76 | + { |
| 77 | + return -1; |
| 78 | + } |
| 79 | + |
| 80 | + ChipLinuxAppMainLoop(); |
| 81 | + return 0; |
| 82 | +} |
0 commit comments