Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | ;;; pipe-skel.el - pipelined graph node skeleton |
| 2 | |
| 3 | (require 'skeleton) |
| 4 | |
Keith Burns (alagalah) | ca46d8c | 2016-03-18 07:22:15 -0700 | [diff] [blame] | 5 | (define-skeleton skel-periodic |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 6 | "Insert a skeleton periodic process node" |
| 7 | nil |
| 8 | '(setq node-name (skeleton-read "Name: ")) |
| 9 | '(setq uc-node-name (upcase node-name)) |
| 10 | '(setq poll-period (skeleton-read "Poll period (f64 seconds, e.g. 10.0): ")) |
| 11 | |
| 12 | " |
| 13 | #define " uc-node-name "_POLL_PERIOD " poll-period " |
| 14 | |
| 15 | static uword |
| 16 | " node-name "_process (vlib_main_t * vm, |
| 17 | vlib_node_runtime_t * rt, |
| 18 | vlib_frame_t * f) |
| 19 | { |
| 20 | f64 poll_time_remaining; |
| 21 | uword event_type, * event_data = 0; |
| 22 | |
| 23 | poll_time_remaining = " uc-node-name "_POLL_PERIOD; |
| 24 | while (1) { |
| 25 | int i; |
| 26 | |
| 27 | /* |
| 28 | * Sleep until next periodic call due, or until we receive event(s) |
| 29 | */ |
| 30 | poll_time_remaining = |
| 31 | vlib_process_wait_for_event_or_clock (vm, poll_time_remaining); |
| 32 | |
| 33 | event_type = vlib_process_get_events (vm, &event_data); |
| 34 | switch (event_type) { |
| 35 | case ~0: /* no events => timeout */ |
| 36 | break; |
| 37 | |
| 38 | /* |
| 39 | * $$$$ FIXME: add cases / handlers for each event type |
| 40 | */ |
| 41 | case EVENT1: |
| 42 | for (i = 0; i < vec_len (event_data); i++) |
| 43 | handle_event1 (mm, event_data[i]); |
| 44 | break; |
| 45 | |
| 46 | case EVENT2: |
| 47 | for (i = 0; i < vec_len (event_data); i++) |
| 48 | handle_event2 (vm, event_data[i]); |
| 49 | break; |
| 50 | |
| 51 | /* ... and so forth for each event type */ |
| 52 | |
| 53 | default: |
| 54 | /* This should never happen... */ |
| 55 | clib_warning (\"BUG: unhandled event type %d\", event_type); |
| 56 | break; |
| 57 | } |
| 58 | if (event_data) |
| 59 | _vec_len (event_data) = 0; |
| 60 | |
| 61 | /* Timer expired, call periodic function */ |
| 62 | if (vlib_process_suspend_time_is_zero (poll_time_remaining)) { |
| 63 | " node-name "_periodic (vm); |
| 64 | poll_time_remaining = " uc-node-name "_POLL_PERIOD; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * " node-name " periodic node declaration |
| 73 | */ |
| 74 | static VLIB_REGISTER_NODE (" node-name "_node) = { |
| 75 | .function = " node-name "_process, |
| 76 | .type = VLIB_NODE_TYPE_PROCESS, |
| 77 | .name = \"" node-name "-process\", |
| 78 | }; |
| 79 | |
| 80 | /* |
| 81 | * To signal an event: |
| 82 | * |
| 83 | * vlib_process_signal_event (vm, " node-name "_node.index, EVENTn, datum); |
| 84 | * |
| 85 | */ |
| 86 | ") |