cli_utils.h
Go to the documentation of this file.
1 /*
2  * rcdiscover - the network discovery tool for Roboception devices
3  *
4  * Copyright (c) 2018 Roboception GmbH
5  * All rights reserved
6  *
7  * Author: Raphael Schaller
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the copyright holder nor the names of its contributors
20  * may be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef RCDISCOVER_CLI_UTILS_H
37 #define RCDISCOVER_CLI_UTILS_H
38 
39 #include <string>
40 #include <vector>
41 #include <map>
42 
43 #include <rcdiscover/deviceinfo.h>
44 
46 {
47  std::vector<std::string> name = {};
48  std::vector<std::string> serial = {};
49  std::vector<std::string> mac = {};
50  std::vector<std::string> iface = {};
51  std::vector<std::string> model = {};
52 };
53 
54 int parseFilterArguments(int argc, char **argv, DeviceFilter &filter);
55 
56 bool filterDevice(const rcdiscover::DeviceInfo &device_info,
57  const DeviceFilter &filter);
58 
59 std::vector<rcdiscover::DeviceInfo> discoverWithFilter(
60  const DeviceFilter &filter);
61 
62 void printTable(std::ostream &oss,
63  const std::vector<std::vector<std::string>> &to_be_printed);
64 
65 void printDeviceTable(std::ostream &oss,
66  const std::vector<rcdiscover::DeviceInfo> &devices,
67  bool print_header, bool iponly, bool serialonly);
68 
69 template<typename K, typename V>
70 int getMaxCommandLen(const std::map<K, V> &commands)
71 {
72  int max_size = 0;
73  for (const auto &cmd : commands)
74  {
75  max_size = std::max(max_size, static_cast<int>(cmd.first.length()));
76  }
77  return max_size;
78 }
79 
80 #endif //RCDISCOVER_CLI_UTILS_H
int parseFilterArguments(int argc, char **argv, DeviceFilter &filter)
Definition: cli_utils.cc:44
std::vector< std::string > serial
Definition: cli_utils.h:48
std::vector< std::string > name
Definition: cli_utils.h:47
int getMaxCommandLen(const std::map< K, V > &commands)
Definition: cli_utils.h:70
std::vector< std::string > model
Definition: cli_utils.h:51
bool filterDevice(const rcdiscover::DeviceInfo &device_info, const DeviceFilter &filter)
Definition: cli_utils.cc:81
std::vector< rcdiscover::DeviceInfo > discoverWithFilter(const DeviceFilter &filter)
Definition: cli_utils.cc:110
std::vector< std::string > iface
Definition: cli_utils.h:50
std::vector< std::string > mac
Definition: cli_utils.h:49
void printDeviceTable(std::ostream &oss, const std::vector< rcdiscover::DeviceInfo > &devices, bool print_header, bool iponly, bool serialonly)
Definition: cli_utils.cc:174
void printTable(std::ostream &oss, const std::vector< std::vector< std::string >> &to_be_printed)
Definition: cli_utils.cc:140
static const std::map< std::string, Command > commands
Definition: rcdiscover.cc:56


rcdiscover
Author(s): Heiko Hirschmueller , Raphael Schaller
autogenerated on Sun Apr 18 2021 02:16:32