1 ;;; Copyright (c) 2016 Cisco and/or its affiliates.
2 ;;; Licensed under the Apache License, Version 2.0 (the "License");
3 ;;; you may not use this file except in compliance with the License.
4 ;;; You may obtain a copy of the License at:
6 ;;; http://www.apache.org/licenses/LICENSE-2.0
8 ;;; Unless required by applicable law or agreed to in writing, software
9 ;;; distributed under the License is distributed on an "AS IS" BASIS,
10 ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 ;;; See the License for the specific language governing permissions and
12 ;;; limitations under the License.
14 ;;; pipe-skel.el - pipelined graph node skeleton
18 (define-skeleton skel-periodic
19 "Insert a skeleton periodic process node"
21 '(setq node-name (skeleton-read "Name: "))
22 '(setq uc-node-name (upcase node-name))
23 '(setq poll-period (skeleton-read "Poll period (f64 seconds, e.g. 10.0): "))
26 #define " uc-node-name "_POLL_PERIOD " poll-period "
29 " node-name "_process (vlib_main_t * vm,
30 vlib_node_runtime_t * rt,
33 f64 poll_time_remaining;
34 uword event_type, * event_data = 0;
36 poll_time_remaining = " uc-node-name "_POLL_PERIOD;
41 * Sleep until next periodic call due, or until we receive event(s)
44 vlib_process_wait_for_event_or_clock (vm, poll_time_remaining);
46 event_type = vlib_process_get_events (vm, &event_data);
48 case ~0: /* no events => timeout */
52 * $$$$ FIXME: add cases / handlers for each event type
55 for (i = 0; i < vec_len (event_data); i++)
56 handle_event1 (mm, event_data[i]);
60 for (i = 0; i < vec_len (event_data); i++)
61 handle_event2 (vm, event_data[i]);
64 /* ... and so forth for each event type */
67 /* This should never happen... */
68 clib_warning (\"BUG: unhandled event type %d\", event_type);
72 _vec_len (event_data) = 0;
74 /* Timer expired, call periodic function */
75 if (vlib_process_suspend_time_is_zero (poll_time_remaining)) {
76 " node-name "_periodic (vm);
77 poll_time_remaining = " uc-node-name "_POLL_PERIOD;
85 * " node-name " periodic node declaration
87 VLIB_REGISTER_NODE (" plugin-name "_periodic_node,static) = {
88 .function = " node-name "_process,
89 .type = VLIB_NODE_TYPE_PROCESS,
90 .name = \"" node-name "-process\",
96 * vlib_process_signal_event (vm, " node-name "_node.index, EVENTn, datum);