diff options
author | Ed Warnicke <eaw@cisco.com> | 2015-12-08 15:45:58 -0700 |
---|---|---|
committer | Ed Warnicke <eaw@cisco.com> | 2015-12-08 15:47:27 -0700 |
commit | cb9cadad578297ffd78fa8a33670bdf1ab669e7e (patch) | |
tree | 6ac2be912482cc7849a26f0ab845561c3d7f4e26 /build-root/emacs-lisp/periodic-skel.el | |
parent | fb0815d4ae4bb0fe27bd9313f34b45c8593b907e (diff) |
Initial commit of vpp code.v1.0.0
Change-Id: Ib246f1fbfce93274020ee93ce461e3d8bd8b9f17
Signed-off-by: Ed Warnicke <eaw@cisco.com>
Diffstat (limited to 'build-root/emacs-lisp/periodic-skel.el')
-rw-r--r-- | build-root/emacs-lisp/periodic-skel.el | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/build-root/emacs-lisp/periodic-skel.el b/build-root/emacs-lisp/periodic-skel.el new file mode 100644 index 00000000000..37c20856c64 --- /dev/null +++ b/build-root/emacs-lisp/periodic-skel.el @@ -0,0 +1,86 @@ +;;; pipe-skel.el - pipelined graph node skeleton + +(require 'skeleton) + +(define-skeleton periodic-skel +"Insert a skeleton periodic process node" +nil +'(setq node-name (skeleton-read "Name: ")) +'(setq uc-node-name (upcase node-name)) +'(setq poll-period (skeleton-read "Poll period (f64 seconds, e.g. 10.0): ")) + +" +#define " uc-node-name "_POLL_PERIOD " poll-period " + +static uword +" node-name "_process (vlib_main_t * vm, + vlib_node_runtime_t * rt, + vlib_frame_t * f) +{ + f64 poll_time_remaining; + uword event_type, * event_data = 0; + + poll_time_remaining = " uc-node-name "_POLL_PERIOD; + while (1) { + int i; + + /* + * Sleep until next periodic call due, or until we receive event(s) + */ + poll_time_remaining = + vlib_process_wait_for_event_or_clock (vm, poll_time_remaining); + + event_type = vlib_process_get_events (vm, &event_data); + switch (event_type) { + case ~0: /* no events => timeout */ + break; + + /* + * $$$$ FIXME: add cases / handlers for each event type + */ + case EVENT1: + for (i = 0; i < vec_len (event_data); i++) + handle_event1 (mm, event_data[i]); + break; + + case EVENT2: + for (i = 0; i < vec_len (event_data); i++) + handle_event2 (vm, event_data[i]); + break; + + /* ... and so forth for each event type */ + + default: + /* This should never happen... */ + clib_warning (\"BUG: unhandled event type %d\", event_type); + break; + } + if (event_data) + _vec_len (event_data) = 0; + + /* Timer expired, call periodic function */ + if (vlib_process_suspend_time_is_zero (poll_time_remaining)) { + " node-name "_periodic (vm); + poll_time_remaining = " uc-node-name "_POLL_PERIOD; + } + } + + return 0; +} + +/* + * " node-name " periodic node declaration + */ +static VLIB_REGISTER_NODE (" node-name "_node) = { + .function = " node-name "_process, + .type = VLIB_NODE_TYPE_PROCESS, + .name = \"" node-name "-process\", +}; + +/* + * To signal an event: + * + * vlib_process_signal_event (vm, " node-name "_node.index, EVENTn, datum); + * + */ +") |