summaryrefslogtreecommitdiffstats
path: root/extras/emacs/periodic-skel.el
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2017-04-20 11:42:28 +0200
committerDamjan Marion <dmarion.lists@gmail.com>2017-04-24 14:49:00 +0000
commit757585db71b78c4edf91ba011be419264de43d1a (patch)
treed12a78253ba81a0feab0c40dcae2aefc13438873 /extras/emacs/periodic-skel.el
parent53129423a6f4e43b39f7547424fbaea99e56f7e2 (diff)
Move emacs stuff to extras/
Change-Id: Ibbb7d8500e9064215cf912bd00bdf72a748f8a27 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'extras/emacs/periodic-skel.el')
-rw-r--r--extras/emacs/periodic-skel.el86
1 files changed, 86 insertions, 0 deletions
diff --git a/extras/emacs/periodic-skel.el b/extras/emacs/periodic-skel.el
new file mode 100644
index 00000000000..a8f3ef6db82
--- /dev/null
+++ b/extras/emacs/periodic-skel.el
@@ -0,0 +1,86 @@
+;;; pipe-skel.el - pipelined graph node skeleton
+
+(require 'skeleton)
+
+(define-skeleton skel-periodic
+"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);
+ *
+ */
+")