1 ;;; plugin-periodic-skel.el - periodic (process) node skeleton
3 ;;; Copyright (c) 2016 Cisco and/or its affiliates.
4 ;;; Licensed under the Apache License, Version 2.0 (the "License");
5 ;;; you may not use this file except in compliance with the License.
6 ;;; You may obtain a copy of the License at:
8 ;;; http://www.apache.org/licenses/LICENSE-2.0
10 ;;; Unless required by applicable law or agreed to in writing, software
11 ;;; distributed under the License is distributed on an "AS IS" BASIS,
12 ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ;;; See the License for the specific language governing permissions and
14 ;;; limitations under the License.
18 (define-skeleton skel-plugin-periodic
19 "Insert a periodic node skeleton "
21 '(if (not (boundp 'plugin-name))
22 (setq plugin-name (read-string "Plugin name: ")))
23 '(setq PLUGIN-NAME (upcase plugin-name))
24 '(setq capital-oh-en "ON")
25 '(setq main-p (concat (substring plugin-name 0 1) "mp"))
27 * " plugin-name "_periodic.c - skeleton plug-in periodic function
29 * Copyright (c) <current-year> <your-organization>
30 * Licensed under the Apache License, Version 2.0 (the \"License\");
31 * you may not use this file except in compliance with the License.
32 * You may obtain a copy of the License at:
34 * http://www.apache.org/licenses/LICENSE-2.0
36 * Unless required by applicable law or agreed to in writing, software
37 * distributed under the License is distributed on an \"AS IS\" BASIS,
38 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39 * See the License for the specific language governing permissions and
40 * limitations under the License.
43 #include <vlib/vlib.h>
44 #include <vppinfra/error.h>
45 #include <" plugin-name "/" plugin-name ".h>
48 handle_event1 (" plugin-name "_main_t *pm, f64 now, uword event_data)
50 clib_warning (\"received " PLUGIN-NAME "_EVENT1\");
54 handle_event2 (" plugin-name "_main_t *pm, f64 now, uword event_data)
56 clib_warning (\"received " PLUGIN-NAME "_EVENT2\");
60 handle_periodic_enable_disable (" plugin-name"_main_t *pm, f64 now, uword event_data)
62 clib_warning (\"Periodic timeouts now %s\",
63 event_data ? \"enabled\" : \"disabled\");
64 pm->periodic_timer_enabled = event_data;
68 handle_timeout (" plugin-name"_main_t *pm, f64 now)
70 clib_warning (\"timeout at %.2f\", now);
74 " plugin-name "_periodic_process (vlib_main_t * vm,
75 vlib_node_runtime_t * rt, vlib_frame_t * f)
77 " plugin-name "_main_t *pm = &" plugin-name "_main;
80 uword *event_data = 0;
86 if (pm->periodic_timer_enabled)
87 vlib_process_wait_for_event_or_clock (vm, timeout);
89 vlib_process_wait_for_event (vm);
91 now = vlib_time_now (vm);
93 event_type = vlib_process_get_events (vm, (uword **) & event_data);
97 /* Handle " PLUGIN-NAME "_EVENT1 */
98 case " PLUGIN-NAME "_EVENT1:
99 for (i = 0; i < vec_len (event_data); i++)
100 handle_event1 (pm, now, event_data[i]);
103 /* Handle " PLUGIN-NAME "_EVENT2 */
104 case " PLUGIN-NAME"_EVENT2:
105 for (i = 0; i < vec_len (event_data); i++)
106 handle_event2 (pm, now, event_data[i]);
108 /* Handle the periodic timer on/off event */
109 case " PLUGIN-NAME"_EVENT_PERIODIC_ENABLE_DISABLE:
110 for (i = 0; i < vec_len (event_data); i++)
111 handle_periodic_enable_disable (pm, now, event_data[i]);
114 /* Handle periodic timeouts */
116 handle_timeout (pm, now);
119 vec_reset_length (event_data);
121 return 0; /* or not */
124 void " plugin-name "_create_periodic_process (" plugin-name "_main_t *" main-p")
126 /* Already created the process node? */
127 if (" main-p "->periodic_node_index > 0)
130 /* No, create it now and make a note of the node index */
131 " main-p "->periodic_node_index = vlib_process_create (" main-p "->vlib_main,
132 \"" plugin-name "-periodic-process\",
133 " plugin-name "_periodic_process, 16 /* log2_n_stack_bytes */);
137 * fd.io coding-style-patch-verification: " capital-oh-en "
140 * eval: (c-set-style \"gnu\")