22parse_int_optstring(
char const *optstring,
int *out)
27 long num = strtol(optstring, &endp, 10);
30 if (errno || *endp !=
'\0' || num < INT_MIN || num > INT_MAX)
39verbosity_mask_from_string(
char const *str,
unsigned *mask)
41 if (strcmp(
"quiet", str) == 0)
46 if (strcmp(
"warn", str) == 0)
51 if (strcmp(
"info", str) == 0)
53 *mask = Dbg::Warn | Dbg::Info;
56 if (strcmp(
"debug", str) == 0)
58 *mask = Dbg::Warn | Dbg::Info | Dbg::Debug;
61 if (strcmp(
"trace", str) == 0)
63 *mask = Dbg::Warn | Dbg::Info | Dbg::Debug | Dbg::Trace;
100set_verbosity(
char const *str)
103 if (verbosity_mask_from_string(str, &mask) == 0)
105 Dbg::set_verbosity(mask);
109 static char const *
const components[] =
110 {
"core",
"virtio",
"port",
"request",
"queue",
"packet" };
112 static_assert(std::extent<
decltype(components)>::value == Dbg::Max_component,
113 "Component names must match 'enum Component'.");
115 for (
unsigned i = 0; i < Dbg::Max_component; ++i)
117 auto len = strlen(components[i]);
118 if (strncmp(components[i], str, len) == 0 && str[len] ==
'='
119 && verbosity_mask_from_string(str + len + 1, &mask) == 0)
121 Dbg::set_verbosity(i, mask);
128Options::parse_cmd_line(
int argc,
char **argv,
129 std::shared_ptr<Ds_vector> trusted_dataspaces)
133 struct option options[] =
135 {
"size", 1, 0,
's' },
136 {
"ports", 1, 0,
'p' },
138 {
"debug", 1, 0,
'D' },
139 {
"verbose", 0, 0,
'v' },
140 {
"quiet", 0, 0,
'q' },
141 {
"register-ds", 1, 0,
'd' },
145 unsigned long verbosity = Dbg::Warn;
147 Dbg info(Dbg::Core, Dbg::Info);
149 Dbg::set_verbosity(Dbg::Core, Dbg::Info);
150 info.printf(
"Arguments:\n");
151 for (
int i = 0; i < argc; ++i)
152 info.printf(
"\t%s\n", argv[i]);
154 Dbg::set_verbosity(verbosity);
155 while ( (opt = getopt_long(argc, argv,
"s:p:mqvD:d:", options, &index)) != -1)
162 if (!parse_int_optstring(optarg, &_virtq_max_num)
163 || _virtq_max_num < 1 || _virtq_max_num > 32768
164 || (_virtq_max_num & (_virtq_max_num - 1)))
166 Err().printf(
"Max number of virtqueue buffers must be power of 2"
167 " between 1 and 32768. Invalid value %i or argument "
169 _virtq_max_num, optarg);
172 info.printf(
"Max number of buffers in virtqueue: %i\n",
176 if (parse_int_optstring(optarg, &_max_ports))
177 info.printf(
"Max number of ports: %u\n", _max_ports);
180 Err().printf(
"Invalid number of ports argument: %s\n", optarg);
185 verbosity = Dbg::Quiet;
186 Dbg::set_verbosity(verbosity);
189 verbosity = (verbosity << 1) | 1;
190 Dbg::set_verbosity(verbosity);
193 set_verbosity(optarg);
196 info.printf(
"Assigning mac addresses\n");
203 "Find a dataspace capability.\n");
204 trusted_dataspaces->push_back(ds);
208 Err().printf(
"Unknown command line option '%c' (%d)\n", opt, opt);
215static Options options;
218Options::get_options()
222Options::parse_options(
int argc,
char **argv,
223 std::shared_ptr<Ds_vector> trusted_dataspaces)
225 if (options.parse_cmd_line(argc, argv, trusted_dataspaces) < 0)
static Env const * env() noexcept
Returns the initial environment for the current task.
C++ interface for capabilities.
@ L4_ENOENT
No such entity.
T chkcap(T &&cap, char const *extra="", long err=-L4_ENOMEM)
Check for valid capability or raise C++ exception.