Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / bridge-app / linux / Options.cpp
1 /*
2  *
3  *    Copyright (c) 2021 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 "Options.h"
20
21 #include <core/CHIPError.h>
22 #include <support/CHIPArgParser.hpp>
23
24 using namespace chip;
25 using namespace chip::ArgParser;
26
27 namespace {
28 LinuxDeviceOptions gDeviceOptions;
29
30 // Follow the code style of command line arguments in case we need to add more options in the future.
31 enum
32 {
33     kDeviceOption_BleDevice = 0x1000,
34 };
35
36 OptionDef sDeviceOptionDefs[] = { { "ble-device", kArgumentRequired, kDeviceOption_BleDevice }, {} };
37
38 const char * sDeviceOptionHelp = "  --ble-device <number>\n"
39                                  "       The device number for CHIPoBLE, without 'hci' prefix, can be found by hciconfig.\n"
40                                  "\n";
41
42 bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue)
43 {
44     bool retval = true;
45
46     switch (aIdentifier)
47     {
48
49     case kDeviceOption_BleDevice:
50         if (!ParseInt(aValue, LinuxDeviceOptions::GetInstance().mBleDevice))
51         {
52             PrintArgError("%s: invalid value specified for ble device number: %s\n", aProgram, aValue);
53             retval = false;
54         }
55         break;
56
57     default:
58         PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
59         retval = false;
60         break;
61     }
62
63     return (retval);
64 }
65
66 OptionSet sDeviceOptions = { HandleOption, sDeviceOptionDefs, "GENERAL OPTIONS", sDeviceOptionHelp };
67
68 OptionSet * sLinuxDeviceOptionSets[] = { &sDeviceOptions, nullptr };
69 } // namespace
70
71 CHIP_ERROR ParseArguments(int argc, char * argv[])
72 {
73     if (!ParseArgs(argv[0], argc, argv, sLinuxDeviceOptionSets))
74     {
75         return CHIP_ERROR_INVALID_ARGUMENT;
76     }
77     return CHIP_NO_ERROR;
78 }
79
80 LinuxDeviceOptions & LinuxDeviceOptions::GetInstance()
81 {
82     return gDeviceOptions;
83 }