vxlan: vxlan/vxlan.api API cleanup
[vpp.git] / extras / emacs / plugin-periodic-skel.el
1 ;;; plugin-periodic-skel.el - periodic (process) node skeleton
2 ;;;
3 ;;; Copyright (c) 2016 Cisco and/or its affiliates.
4 ;;; Licensed under the Apache License, Version 2.0 (the "License");
5 ;;; you may not use this file except in compliance with the License.
6 ;;; You may obtain a copy of the License at:
7 ;;;
8 ;;;     http://www.apache.org/licenses/LICENSE-2.0
9 ;;;
10 ;;; Unless required by applicable law or agreed to in writing, software
11 ;;; distributed under the License is distributed on an "AS IS" BASIS,
12 ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ;;; See the License for the specific language governing permissions and
14 ;;; limitations under the License.
15
16 (require 'skeleton)
17
18 (define-skeleton skel-plugin-periodic
19 "Insert a periodic node skeleton "
20 nil
21 '(if (not (boundp 'plugin-name))
22      (setq plugin-name (read-string "Plugin name: ")))
23 '(setq PLUGIN-NAME (upcase plugin-name))
24 '(setq capital-oh-en "ON")
25 '(setq main-p (concat (substring plugin-name 0 1) "mp"))
26 "/*
27  * " plugin-name "_periodic.c - skeleton plug-in periodic function
28  *
29  * Copyright (c) <current-year> <your-organization>
30  * Licensed under the Apache License, Version 2.0 (the \"License\");
31  * you may not use this file except in compliance with the License.
32  * You may obtain a copy of the License at:
33  *
34  *     http://www.apache.org/licenses/LICENSE-2.0
35  *
36  * Unless required by applicable law or agreed to in writing, software
37  * distributed under the License is distributed on an \"AS IS\" BASIS,
38  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39  * See the License for the specific language governing permissions and
40  * limitations under the License.
41  */
42
43 #include <vlib/vlib.h>
44 #include <vppinfra/error.h>
45 #include <" plugin-name "/" plugin-name ".h>
46
47 static void
48 handle_event1 (" plugin-name "_main_t *pm, f64 now, uword event_data)
49 {
50   clib_warning (\"received " PLUGIN-NAME "_EVENT1\");
51 }
52
53 static void
54 handle_event2 (" plugin-name "_main_t *pm, f64 now, uword event_data)
55 {
56   clib_warning (\"received " PLUGIN-NAME "_EVENT2\");
57 }
58
59 static void
60 handle_periodic_enable_disable (" plugin-name"_main_t *pm, f64 now, uword event_data)
61 {
62    clib_warning (\"Periodic timeouts now %s\",
63      event_data ? \"enabled\" : \"disabled\");
64    pm->periodic_timer_enabled = event_data;
65 }
66
67 static void
68 handle_timeout (" plugin-name"_main_t *pm, f64 now)
69 {
70   clib_warning (\"timeout at %.2f\", now);
71 }
72
73 static uword
74 " plugin-name "_periodic_process (vlib_main_t * vm,
75                           vlib_node_runtime_t * rt, vlib_frame_t * f)
76 {
77   " plugin-name "_main_t *pm = &" plugin-name "_main;
78   f64 now;
79   f64 timeout = 10.0;
80   uword *event_data = 0;
81   uword event_type;
82   int i;
83
84   while (1)
85     {
86       if (pm->periodic_timer_enabled)
87         vlib_process_wait_for_event_or_clock (vm, timeout);
88       else
89         vlib_process_wait_for_event (vm);
90
91       now = vlib_time_now (vm);
92
93       event_type = vlib_process_get_events (vm, (uword **) & event_data);
94
95       switch (event_type)
96         {
97           /* Handle " PLUGIN-NAME "_EVENT1 */
98         case " PLUGIN-NAME "_EVENT1:
99           for (i = 0; i < vec_len (event_data); i++)
100             handle_event1 (pm, now, event_data[i]);
101           break;
102
103           /* Handle " PLUGIN-NAME "_EVENT2 */
104         case " PLUGIN-NAME"_EVENT2:
105           for (i = 0; i < vec_len (event_data); i++)
106             handle_event2 (pm, now, event_data[i]);
107           break;
108           /* Handle the periodic timer on/off event */
109         case " PLUGIN-NAME"_EVENT_PERIODIC_ENABLE_DISABLE:
110           for (i = 0; i < vec_len (event_data); i++)
111             handle_periodic_enable_disable (pm, now, event_data[i]);
112           break;
113
114           /* Handle periodic timeouts */
115         case ~0:
116           handle_timeout (pm, now);
117           break;
118         }
119       vec_reset_length (event_data);
120     }
121   return 0;                     /* or not */
122 }
123
124 void " plugin-name "_create_periodic_process (" plugin-name "_main_t *" main-p")
125 {
126   /* Already created the process node? */
127   if (" main-p "->periodic_node_index > 0)
128     return;
129
130   /* No, create it now and make a note of the node index */
131   " main-p "->periodic_node_index = vlib_process_create (" main-p "->vlib_main,
132     \"" plugin-name "-periodic-process\",
133     " plugin-name "_periodic_process, 16 /* log2_n_stack_bytes */);
134 }
135
136 /*
137  * fd.io coding-style-patch-verification: " capital-oh-en "
138  *
139  * Local Variables:
140  * eval: (c-set-style \"gnu\")
141  * End:
142  */
143 ")