aboutsummaryrefslogtreecommitdiffstats
path: root/extras/emacs/periodic-skel.el
blob: 9e73d00dec8d34fabc3977fa451a8dbc4f216451 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
;;; Copyright (c) 2016 Cisco and/or its affiliates.
;;; Licensed under the Apache License, Version 2.0 (the "License");
;;; you may not use this file except in compliance with the License.
;;; You may obtain a copy of the License at:
;;;
;;;     http://www.apache.org/licenses/LICENSE-2.0
;;;
;;; Unless required by applicable law or agreed to in writing, software
;;; distributed under the License is distributed on an "AS IS" BASIS,
;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;; See the License for the specific language governing permissions and
;;; limitations under the License.

;;; 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 
 */
VLIB_REGISTER_NODE (" plugin-name "_periodic_node,static) = {
    .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);
 *
 */
")