20 main (
int argc,
char *argv[])
30 if ((error = unix_physmem_init (vm)))
50 format_my_node_frame (
u8 * s, va_list * va)
56 s =
format (s,
"scalar %d, vector { ", g->scalar);
58 s =
format (s,
"%d, ", g->vector[i]);
79 f, format_my_node_frame, f);
91 for (i = 0; i < 5; i++)
97 y->vector[
i] = y->scalar +
i;
114 .scalar_size =
sizeof (my_frame_t),
127 .scalar_size =
sizeof (my_frame_t),
140 } my_process_completion_type_t;
146 } my_process_event_data_t;
149 format_my_process_event_data (
u8 * s, va_list * va)
151 my_process_event_data_t *d = va_arg (*va, my_process_event_data_t *);
152 return format (s,
"{ a %d b %.6f}", d->a, d->b);
165 for (i = 0; i < 5; i++)
177 for (n_events_seen = 0; n_events_seen < 2;)
181 n_events_seen +=
vec_len (data);
192 uword n_events_seen,
i, type;
193 my_process_event_data_t *
data;
194 for (n_events_seen = 0; n_events_seen < 2;)
203 format_my_process_event_data, data);
205 n_events_seen +=
vec_len (data);
230 i == 1 ? MY_EVENT_TYPE1 : MY_EVENT_TYPE2,
234 my_process_event_data_t *d;
256 .function = my_proc_input,
258 .name =
"my-proc-input",
265 u32 prec = va_arg (*args,
u32);
266 f64 *result = va_arg (*args,
f64 *);
271 "+%U",
"-%U",
"/%U",
"*%U",
"^%U",
278 for (p = prec; p <
ARRAY_LEN (binops); p++)
280 if (
unformat (
i, binops[p], _unformat_farith, prec + 0, &tmp[1]))
282 switch (binops[p][0])
285 result[0] = tmp[0] + tmp[1];
288 result[0] = tmp[0] - tmp[1];
291 result[0] = tmp[0] / tmp[1];
294 result[0] = tmp[0] * tmp[1];
297 result[0] = pow (tmp[0], tmp[1]);
309 else if (
unformat (
i,
"-%U", _unformat_farith, prec + 0, &tmp[0]))
315 else if (
unformat (
i,
"(%U)", _unformat_farith, 0, &tmp[0]))
332 f64 *result = va_arg (*args,
f64 *);
346 .name =
"decimal_integer",.short_help =
352 .name =
"float_expression",.short_help =
353 "floating point expression",.unformat_function =
354 unformat_farith,.data_size =
sizeof (
f64),};
390 .path =
"bar %decimal_integer",
391 .short_help =
"bar1 command",
392 .function = bar_command,
396 .path =
"bar %decimal_integer %decimal_integer",
397 .short_help =
"bar2 command",
398 .function = bar_command,
402 .path =
"zap %float_expression",
403 .short_help =
"bar3 command",
404 .function = bar_command,
int vlib_unix_main(int argc, char *argv[])
#define vec_foreach_index(var, v)
Iterate over vector indices.
#define VLIB_CLI_PARSE_RULE(x)
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
static void * vlib_cli_get_parse_rule_result(vlib_main_t *vm, uword index)
static f64 vlib_time_now(vlib_main_t *vm)
int main(int argc, char *argv[])
static clib_error_t * unix_cli_init(vlib_main_t *vm)
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
#define VLIB_INIT_FUNCTION(x)
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
#define vlib_call_init_function(vm, x)
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
u32 node_index
Node index.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
#define VLIB_REGISTER_NODE(x,...)
static void * vlib_process_signal_event_at_time(vlib_main_t *vm, f64 dt, uword node_index, uword type_opaque, uword n_data_elts, uword n_data_elt_bytes)
#define vec_free(V)
Free vector's memory (no header).
static void * vlib_frame_scalar_args(vlib_frame_t *f)
Get pointer to frame scalar data.
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
#define VLIB_CLI_COMMAND(x,...)
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
static void * vlib_process_get_event_data(vlib_main_t *vm, uword *return_event_type_opaque)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void vlib_process_put_event_data(vlib_main_t *vm, void *event_data)
#define STRUCT_SIZE_OF(t, f)
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static clib_error_t * main_stub_init(vlib_main_t *vm)