2 * oddbuf_periodic.c - skeleton plug-in periodic function
4 * Copyright (c) <current-year> <your-organization>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vlib/vlib.h>
19 #include <vppinfra/error.h>
20 #include <oddbuf/oddbuf.h>
23 handle_event1 (oddbuf_main_t * pm, f64 now, uword event_data)
25 clib_warning ("received ODDBUF_EVENT1");
29 handle_event2 (oddbuf_main_t * pm, f64 now, uword event_data)
31 clib_warning ("received ODDBUF_EVENT2");
35 handle_periodic_enable_disable (oddbuf_main_t * pm, f64 now, uword event_data)
37 clib_warning ("Periodic timeouts now %s",
38 event_data ? "enabled" : "disabled");
39 pm->periodic_timer_enabled = event_data;
43 handle_timeout (oddbuf_main_t * pm, f64 now)
45 clib_warning ("timeout at %.2f", now);
49 oddbuf_periodic_process (vlib_main_t * vm,
50 vlib_node_runtime_t * rt, vlib_frame_t * f)
52 oddbuf_main_t *pm = &oddbuf_main;
55 uword *event_data = 0;
61 if (pm->periodic_timer_enabled)
62 vlib_process_wait_for_event_or_clock (vm, timeout);
64 vlib_process_wait_for_event (vm);
66 now = vlib_time_now (vm);
68 event_type = vlib_process_get_events (vm, (uword **) & event_data);
72 /* Handle ODDBUF_EVENT1 */
74 for (i = 0; i < vec_len (event_data); i++)
75 handle_event1 (pm, now, event_data[i]);
78 /* Handle ODDBUF_EVENT2 */
80 for (i = 0; i < vec_len (event_data); i++)
81 handle_event2 (pm, now, event_data[i]);
83 /* Handle the periodic timer on/off event */
84 case ODDBUF_EVENT_PERIODIC_ENABLE_DISABLE:
85 for (i = 0; i < vec_len (event_data); i++)
86 handle_periodic_enable_disable (pm, now, event_data[i]);
89 /* Handle periodic timeouts */
91 handle_timeout (pm, now);
94 vec_reset_length (event_data);
96 return 0; /* or not */
100 oddbuf_create_periodic_process (oddbuf_main_t * omp)
102 /* Already created the process node? */
103 if (omp->periodic_node_index > 0)
106 /* No, create it now and make a note of the node index */
107 omp->periodic_node_index = vlib_process_create (omp->vlib_main, "oddbuf-periodic-process", oddbuf_periodic_process, 16 /* log2_n_stack_bytes */
112 * fd.io coding-style-patch-verification: ON
115 * eval: (c-set-style "gnu")