lp_template.c 3.92 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * 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,
    template_msg * m,
    tw_lp * lp);
static void handle_template_b(
    template_state * ns,
    template_msg * m,
    tw_lp * lp);
static void handle_template_a_rev(
    template_state * ns,
    template_msg * m,
    tw_lp * lp);
static void handle_template_b_rev(
    template_state * ns,
    template_msg * m,
    tw_lp * lp);

/* ROSS function pointer table for this LP */
tw_lptype template_lp = {
80
81
82
83
84
85
86
    (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),
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
};

/**** 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){
    /* 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:
            handle_template_a(ns, m, lp);
            break;
        case TEMPLATE_B:
            handle_template_b(ns, m, lp);
            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:
            handle_template_a_rev(ns, m, lp);
            break;
        case TEMPLATE_B:
            handle_template_b_rev(ns, m, lp);
            break;
        /* ... */
        default:
            assert(!"template event type not known");
            break;
    }
}

void template_finalize(
        template_state * ns,
        tw_lp * lp){
    /* Fill me in... */
}

/* event type handlers */
void handle_template_a(
    template_state * ns,
    template_msg * m,
    tw_lp * lp){

}
void handle_template_b(
    template_state * ns,
    template_msg * m,
    tw_lp * lp){

}
void handle_template_a_rev(
    template_state * ns,
    template_msg * m,
    tw_lp * lp){

}
void handle_template_b_rev(
    template_state * ns,
    template_msg * m,
    tw_lp * lp){

}

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

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