lp_template.c 4.44 KB
Newer Older
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
/*
 * Copyright (C) 2014 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

/* This is meant to be a template file to use when developing new LPs. 
 * Roughly follows the format of the existing LPs in the CODES repos */

#include "lp_template.h"
#include "codes/codes_mapping.h"
#include "codes/lp-type-lookup.h"
#include "codes/jenkins-hash.h"
#include "codes/codes.h"

/**** BEGIN SIMULATION DATA STRUCTURES ****/

static int template_magic; /* use this as sanity check on events */

typedef struct template_state template_state;
typedef struct template_msg template_msg;

/* event types */
enum template_event
{
    TEMPLATE_A,
    TEMPLATE_B,
};

struct template_state {
};

struct template_msg {
    enum template_event event_type;
    int magic;
};

/**** END SIMULATION DATA STRUCTURES ****/

/**** BEGIN LP, EVENT PROCESSING FUNCTION DECLS ****/

/* ROSS LP processing functions */  
static void template_lp_init(
    template_state * ns,
    tw_lp * lp);
static void template_event_handler(
    template_state * ns,
    tw_bf * b,
    template_msg * m,
    tw_lp * lp);
static void template_rev_handler(
    template_state * ns,
    tw_bf * b,
    template_msg * m,
    tw_lp * lp);
static void template_finalize(
    template_state * ns,
    tw_lp * lp);

/* event type handlers */
static void handle_template_a(
    template_state * ns,
Jonathan Jenkins's avatar
Jonathan Jenkins committed
63
    tw_bf * b,
64
65
66
67
    template_msg * m,
    tw_lp * lp);
static void handle_template_b(
    template_state * ns,
Jonathan Jenkins's avatar
Jonathan Jenkins committed
68
    tw_bf * b,
69
70
71
72
    template_msg * m,
    tw_lp * lp);
static void handle_template_a_rev(
    template_state * ns,
Jonathan Jenkins's avatar
Jonathan Jenkins committed
73
    tw_bf * b,
74
75
76
77
    template_msg * m,
    tw_lp * lp);
static void handle_template_b_rev(
    template_state * ns,
Jonathan Jenkins's avatar
Jonathan Jenkins committed
78
    tw_bf * b,
79
80
81
82
83
    template_msg * m,
    tw_lp * lp);

/* ROSS function pointer table for this LP */
tw_lptype template_lp = {
84
85
86
87
88
89
90
    (init_f) template_lp_init,
    (pre_run_f) NULL,
    (event_f) template_event_handler,
    (revent_f) template_rev_handler,
    (final_f)  template_finalize, 
    (map_f) codes_mapping,
    sizeof(template_state),
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
};

/**** END LP, EVENT PROCESSING FUNCTION DECLS ****/

/**** BEGIN IMPLEMENTATIONS ****/

void template_init(){
    uint32_t h1=0, h2=0;

    bj_hashlittle2("template", strlen("template"), &h1, &h2);
    template_magic = h1+h2;

    lp_type_register("template", &template_lp);
}

void template_lp_init(
        template_state * ns,
        tw_lp * lp){
Jonathan Jenkins's avatar
Jonathan Jenkins committed
109
110
    (void)ns; // avoid warnings...
    (void)lp;
111
112
113
114
115
116
117
118
119
120
121
122
    /* Fill me in... */
}

void template_event_handler(
        template_state * ns,
        tw_bf * b,
        template_msg * m,
        tw_lp * lp){
    assert(m->magic == template_magic);
    
    switch (m->event_type){
        case TEMPLATE_A:
Jonathan Jenkins's avatar
Jonathan Jenkins committed
123
            handle_template_a(ns, b, m, lp);
124
125
            break;
        case TEMPLATE_B:
Jonathan Jenkins's avatar
Jonathan Jenkins committed
126
            handle_template_b(ns, b, m, lp);
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
            break;
        /* ... */
        default:
            assert(!"template event type not known");
            break;
    }
}

void template_rev_handler(
        template_state * ns,
        tw_bf * b,
        template_msg * m,
        tw_lp * lp){
    assert(m->magic == template_magic);
    
    switch (m->event_type){
        case TEMPLATE_A:
Jonathan Jenkins's avatar
Jonathan Jenkins committed
144
            handle_template_a_rev(ns, b, m, lp);
145
146
            break;
        case TEMPLATE_B:
Jonathan Jenkins's avatar
Jonathan Jenkins committed
147
            handle_template_b_rev(ns, b, m, lp);
148
149
150
151
152
153
154
155
156
157
158
            break;
        /* ... */
        default:
            assert(!"template event type not known");
            break;
    }
}

void template_finalize(
        template_state * ns,
        tw_lp * lp){
Jonathan Jenkins's avatar
Jonathan Jenkins committed
159
160
    (void)ns; // avoid warnings...
    (void)lp;
161
162
163
164
165
166
    /* Fill me in... */
}

/* event type handlers */
void handle_template_a(
    template_state * ns,
Jonathan Jenkins's avatar
Jonathan Jenkins committed
167
    tw_bf * b,
168
169
    template_msg * m,
    tw_lp * lp){
Jonathan Jenkins's avatar
Jonathan Jenkins committed
170
171
172
173
    (void)ns; // avoid warnings...
    (void)b;
    (void)m;
    (void)lp;
174
175
176
177

}
void handle_template_b(
    template_state * ns,
Jonathan Jenkins's avatar
Jonathan Jenkins committed
178
    tw_bf * b,
179
180
181
    template_msg * m,
    tw_lp * lp){

Jonathan Jenkins's avatar
Jonathan Jenkins committed
182
183
184
185
    (void)ns; // avoid warnings...
    (void)b;
    (void)m;
    (void)lp;
186
187
188
}
void handle_template_a_rev(
    template_state * ns,
Jonathan Jenkins's avatar
Jonathan Jenkins committed
189
    tw_bf * b,
190
191
192
    template_msg * m,
    tw_lp * lp){

Jonathan Jenkins's avatar
Jonathan Jenkins committed
193
194
195
196
    (void)ns; // avoid warnings...
    (void)b;
    (void)m;
    (void)lp;
197
198
199
}
void handle_template_b_rev(
    template_state * ns,
Jonathan Jenkins's avatar
Jonathan Jenkins committed
200
    tw_bf * b,
201
202
203
    template_msg * m,
    tw_lp * lp){

Jonathan Jenkins's avatar
Jonathan Jenkins committed
204
205
206
207
    (void)ns; // avoid warnings...
    (void)b;
    (void)m;
    (void)lp;
208
209
210
211
212
213
214
215
216
217
218
219
}

/**** END IMPLEMENTATIONS ****/

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ft=c ts=8 sts=4 sw=4 expandtab
 */