blob: b744fcd46d229c5a0125b83eb4768c92bbee5c18 [file] [log] [blame]
Dave Barach8d0f2f02018-03-12 09:31:36 -04001;;; 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:
5;;;
6;;; http://www.apache.org/licenses/LICENSE-2.0
7;;;
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.
13
Ed Warnickecb9cada2015-12-08 15:45:58 -070014;;; pipe-skel.el - pipelined graph node skeleton
15
16(require 'skeleton)
17
Keith Burns (alagalah)ca46d8c2016-03-18 07:22:15 -070018(define-skeleton skel-periodic
Ed Warnickecb9cada2015-12-08 15:45:58 -070019"Insert a skeleton periodic process node"
20nil
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): "))
24
25"
26#define " uc-node-name "_POLL_PERIOD " poll-period "
27
28static uword
29" node-name "_process (vlib_main_t * vm,
30 vlib_node_runtime_t * rt,
31 vlib_frame_t * f)
32{
33 f64 poll_time_remaining;
34 uword event_type, * event_data = 0;
35
36 poll_time_remaining = " uc-node-name "_POLL_PERIOD;
37 while (1) {
38 int i;
39
40 /*
41 * Sleep until next periodic call due, or until we receive event(s)
42 */
43 poll_time_remaining =
44 vlib_process_wait_for_event_or_clock (vm, poll_time_remaining);
45
46 event_type = vlib_process_get_events (vm, &event_data);
47 switch (event_type) {
48 case ~0: /* no events => timeout */
49 break;
50
51 /*
52 * $$$$ FIXME: add cases / handlers for each event type
53 */
54 case EVENT1:
55 for (i = 0; i < vec_len (event_data); i++)
56 handle_event1 (mm, event_data[i]);
57 break;
58
59 case EVENT2:
60 for (i = 0; i < vec_len (event_data); i++)
61 handle_event2 (vm, event_data[i]);
62 break;
63
64 /* ... and so forth for each event type */
65
66 default:
67 /* This should never happen... */
68 clib_warning (\"BUG: unhandled event type %d\", event_type);
69 break;
70 }
71 if (event_data)
72 _vec_len (event_data) = 0;
73
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;
78 }
79 }
80
81 return 0;
82}
83
84/*
85 * " node-name " periodic node declaration
86 */
87static VLIB_REGISTER_NODE (" node-name "_node) = {
88 .function = " node-name "_process,
89 .type = VLIB_NODE_TYPE_PROCESS,
90 .name = \"" node-name "-process\",
91};
92
93/*
94 * To signal an event:
95 *
96 * vlib_process_signal_event (vm, " node-name "_node.index, EVENTn, datum);
97 *
98 */
99")