Kestrel Interface
Loading...
Searching...
No Matches
kest_pipeline.c
Go to the documentation of this file.
1#include "kest_int.h"
2
3#ifndef PRINTLINES_ALLOWED
4#define PRINTLINES_ALLOWED 0
5#endif
6
7static const char *FNAME = "kest_pipeline.c";
8
10{
11 if (!pipeline)
12 return ERR_NULL_PTR;
13
14 pipeline->effects = NULL;
15
16 return NO_ERROR;
17}
18
20{
21 if (!pipeline || !eff)
22 return NULL;
23
24 kest_effect *effect = kest_alloc(sizeof(kest_effect));
25
26 if (!effect)
27 return NULL;
28
29 kest_effect_pll *node = kest_alloc(sizeof(kest_effect_pll));
30
31 if (!node)
32 return NULL;
33
34 node->data = effect;
35 node->next = NULL;
36
38
39 if (!pipeline->effects)
40 {
41 effect->id = 0;
42 pipeline->effects = node;
43 }
44 else
45 {
46 int least_free_id = 0;
47 kest_effect_pll *current = pipeline->effects;
48
49 while (current)
50 {
51 if (current->data)
52 {
53 if (current->data->id >= least_free_id)
54 least_free_id = current->data->id + 1;
55 }
56
57 if (current->next)
58 current = current->next;
59 else
60 break;
61 }
62
63 effect->id = least_free_id;
64 current->next = node;
65 }
66
67 return effect;
68}
69
70int kest_pipeline_remove_effect(kest_pipeline *pipeline, uint16_t id)
71{
72 KEST_PRINTF("kest_pipeline_remove_effect\n");
73 if (!pipeline)
74 return ERR_NULL_PTR;
75
76 kest_effect_pll *current = pipeline->effects;
77 kest_effect_pll *prev = NULL;
78
79 while (current)
80 {
81 if (current->data && current->data->id == id)
82 {
83 if (current->data)
84 free_effect(current->data);
85
86 if (prev)
87 prev->next = current->next;
88 else
89 pipeline->effects = current->next;
90
91 kest_free(current);
92
93 KEST_PRINTF("kest_pipeline_remove_effect found and vanquished the effect\n");
94 return NO_ERROR;
95 }
96
97 prev = current;
98 current = current->next;
99 }
100
101
102 KEST_PRINTF("kest_pipeline_remove_effect finished without finding the effect\n");
104}
105
106int kest_pipeline_move_effect(kest_pipeline *pipeline, int new_pos, int old_pos)
107{
108 if (!pipeline)
109 return ERR_NULL_PTR;
110
111 if (!pipeline->effects)
112 return ERR_BAD_ARGS;
113
114 kest_effect_pll *target = NULL;
115
116 int i = 0;
117 kest_effect_pll *current = pipeline->effects;
118 kest_effect_pll *prev = NULL;
119
120 while (current && i < old_pos)
121 {
122 prev = current;
123 current = current->next;
124 i++;
125 }
126
127 if (!current)
128 return ERR_BAD_ARGS;
129
130 target = current;
131
132 if (prev)
133 prev->next = target->next;
134 else
135 pipeline->effects = target->next;
136
137 i = 0;
138 prev = NULL;
139 current = pipeline->effects;
140
141 while (current && i < new_pos)
142 {
143 prev = current;
144 current = current->next;
145 i++;
146 }
147
148 target->next = current;
149
150 if (!prev)
151 pipeline->effects = target;
152 else
153 prev->next = target;
154
155 return NO_ERROR;
156}
157
159{
160 if (!pipeline)
161 return -ERR_NULL_PTR;
162
163 int n = 0;
164
165 kest_effect_pll *current = pipeline->effects;
166
167 while (current)
168 {
169 if (current->data)
170 n++;
171 current = current->next;
172 }
173
174 return n;
175}
176
178{
179 if (!src || !dest)
180 return ERR_NULL_PTR;
181
182 KEST_PRINTF("Cloning pipeline...\n");
183
184 kest_effect_pll *current = src->effects;
185 kest_effect_pll *nl;
186 kest_effect *effect = NULL;
187
188 int i = 0;
189 while (current)
190 {
191 KEST_PRINTF("Cloning effect %d... current = %p, current->next = %p\n", i, current, current->next);
192 if (current->data)
193 {
194 effect = kest_alloc(sizeof(kest_effect));
195
196 if (!effect)
197 return ERR_ALLOC_FAIL;
198
199 clone_effect(effect, current->data);
200
201 nl = kest_effect_pll_append(dest->effects, effect);
202
203 if (nl)
204 dest->effects = nl;
205 }
206
207 current = current->next;
208 i++;
209 }
210
211 return NO_ERROR;
212}
213
215{
216 if (!pipeline)
217 return;
218
219 kest_effect_pll_destroy(pipeline->effects, free_effect);
220 pipeline->effects = NULL;
221}
222
224{
225 KEST_PRINTF("kest_pipeline_create_fpga_transfer_batch(pipeline = %p, batch = %p)\n", pipeline, batch);
226 if (!batch)
227 return ERR_NULL_PTR;
228
229 int ret_val = NO_ERROR;
230
231 if (!pipeline)
232 {
233 ret_val = ERR_BAD_ARGS;
234 goto return_nothing;
235 }
236
238
240
242
243 int pos = 0;
244 if (pipeline->effects)
245 ret_val = kest_fpga_batch_append_effects(&result, pipeline->effects, &rpt, &pos);
246
247 if (ret_val != NO_ERROR)
248 {
250 goto return_nothing;
251 }
252
254
255 *batch = result;
256
257 KEST_PRINTF("kest_pipeline_create_fpga_transfer_batch done (%s)\n", kest_error_code_to_string(ret_val));
258 return ret_val;
259
260return_nothing:
261 batch->buf = NULL;
262 batch->buf_len = 0;
263 batch->len = 0;
264 batch->buffer_owned = 1;
265
266 KEST_PRINTF("kest_pipeline_create_fpga_transfer_batch failed (%s)\n", kest_error_code_to_string(ret_val));
267 return ret_val;
268}
269
270
272{
273 if (!pipeline)
274 return NULL;
275
276 KEST_PRINTF("searching pipelime %p for a effect with ID %d.\n", pipeline, id);
277
278 kest_effect_pll *current = pipeline->effects;
279 int i = 0;
280 KEST_PRINTF("Beginning on the list%s\n", (!current) ? "..... which is empty! :0\n" : "");
281
282 while (current)
283 {
284 KEST_PRINTF("Transformer %d", i);
285
286 if (current->data)
287 {
288 KEST_PRINTF(" had ID %d\n", current->data->id);
289 }
290 else
291 {
292 KEST_PRINTF("... doesn't exist!!!!! :(\n");
293 }
294 if (current->data && current->data->id == id)
295 {
296 KEST_PRINTF("This is the desired effect! Great. Return it\n");
297 return current->data;
298 }
299 current = current->next;
300 i++;
301 }
302
303 KEST_PRINTF("The desired effect was not found :(\n");
304
305 return NULL;
306}
void kest_free(void *ptr)
Definition kest_alloc.c:32
void * kest_alloc(size_t size)
Definition kest_alloc.c:11
void free_effect(kest_effect *effect)
int init_effect_from_effect_desc(kest_effect *effect, kest_effect_desc *eff)
int clone_effect(kest_effect *dest, kest_effect *src)
const char * kest_error_code_to_string(int error_code)
#define ERR_ALLOC_FAIL
#define ERR_BAD_ARGS
#define ERR_INVALID_TRANSFORMER_ID
#define NO_ERROR
#define ERR_NULL_PTR
int kest_fpga_batch_append_effects(kest_fpga_transfer_batch *batch, kest_effect_pll *list, kest_eff_resource_report *res, int *pos)
int kest_fpga_batch_append(kest_fpga_transfer_batch *seq, uint8_t x)
void kest_free_fpga_transfer_batch(kest_fpga_transfer_batch batch)
kest_fpga_transfer_batch kest_new_fpga_transfer_batch()
#define COMMAND_BEGIN_PROGRAM
Definition kest_fpga_io.h:8
#define COMMAND_END_PROGRAM
int kest_pipeline_move_effect(kest_pipeline *pipeline, int new_pos, int old_pos)
kest_effect * kest_pipeline_append_effect_eff(kest_pipeline *pipeline, kest_effect_desc *eff)
kest_effect * kest_pipeline_get_effect_by_id(kest_pipeline *pipeline, int id)
int kest_pipeline_get_n_effects(kest_pipeline *pipeline)
int init_m_pipeline(kest_pipeline *pipeline)
int kest_pipeline_remove_effect(kest_pipeline *pipeline, uint16_t id)
int kest_pipeline_create_fpga_transfer_batch(kest_pipeline *pipeline, kest_fpga_transfer_batch *batch)
void gut_pipeline(kest_pipeline *pipeline)
int clone_pipeline(kest_pipeline *dest, kest_pipeline *src)
#define KEST_PRINTF(...)
Definition kest_printf.h:10
kest_eff_resource_report empty_m_eff_resource_report()
uint16_t id
Definition kest_effect.h:21
kest_effect_pll * effects