Lines Matching refs:a
67 int (*func)(Action* a, int status, const char* resp);
91 static int cb_default(Action* a, int status, const char* resp) { in cb_default() argument
96 fprintf(stderr,"OKAY [%7.3fs]\n", (split - a->start)); in cb_default()
97 a->start = split; in cb_default()
107 Action* a = reinterpret_cast<Action*>(calloc(1, sizeof(Action))); in queue_action() local
108 if (a == nullptr) die("out of memory"); in queue_action()
111 cmdsize = vsnprintf(a->cmd, sizeof(a->cmd), fmt, ap); in queue_action()
114 if (cmdsize >= sizeof(a->cmd)) { in queue_action()
115 free(a); in queue_action()
116 die("Command length (%d) exceeds maximum size (%d)", cmdsize, sizeof(a->cmd)); in queue_action()
120 action_last->next = a; in queue_action()
122 action_list = a; in queue_action()
124 action_last = a; in queue_action()
125 a->op = op; in queue_action()
126 a->func = cb_default; in queue_action()
128 a->start = -1; in queue_action()
130 return a; in queue_action()
135 Action *a; in fb_set_active() local
136 a = queue_action(OP_COMMAND, "set_active:%s", slot); in fb_set_active()
137 a->msg = mkmsg("Setting current slot to '%s'", slot); in fb_set_active()
142 Action *a; in fb_queue_erase() local
143 a = queue_action(OP_COMMAND, "erase:%s", ptn); in fb_queue_erase()
144 a->msg = mkmsg("erasing '%s'", ptn); in fb_queue_erase()
149 Action *a; in fb_queue_flash() local
151 a = queue_action(OP_DOWNLOAD, ""); in fb_queue_flash()
152 a->data = data; in fb_queue_flash()
153 a->size = sz; in fb_queue_flash()
154 a->msg = mkmsg("sending '%s' (%d KB)", ptn, sz / 1024); in fb_queue_flash()
156 a = queue_action(OP_COMMAND, "flash:%s", ptn); in fb_queue_flash()
157 a->msg = mkmsg("writing '%s'", ptn); in fb_queue_flash()
162 Action *a; in fb_queue_flash_sparse() local
164 a = queue_action(OP_DOWNLOAD_SPARSE, ""); in fb_queue_flash_sparse()
165 a->data = s; in fb_queue_flash_sparse()
166 a->size = 0; in fb_queue_flash_sparse()
167 a->msg = mkmsg("sending sparse '%s' %zu/%zu (%d KB)", ptn, current, total, sz / 1024); in fb_queue_flash_sparse()
169 a = queue_action(OP_COMMAND, "flash:%s", ptn); in fb_queue_flash_sparse()
170 a->msg = mkmsg("writing '%s' %zu/%zu", ptn, current, total); in fb_queue_flash_sparse()
196 static int cb_check(Action* a, int status, const char* resp, int invert) in cb_check() argument
198 const char** value = reinterpret_cast<const char**>(a->data); in cb_check()
199 unsigned count = a->size; in cb_check()
208 if (a->prod) { in cb_check()
209 if (strcmp(a->prod, cur_product) != 0) { in cb_check()
212 cur_product, a->prod, (split - a->start)); in cb_check()
213 a->start = split; in cb_check()
223 fprintf(stderr,"OKAY [%7.3fs]\n", (split - a->start)); in cb_check()
224 a->start = split; in cb_check()
229 fprintf(stderr,"Device %s is '%s'.\n", a->cmd + 7, resp); in cb_check()
239 static int cb_require(Action*a, int status, const char* resp) { in cb_require() argument
240 return cb_check(a, status, resp, 0); in cb_require()
243 static int cb_reject(Action* a, int status, const char* resp) { in cb_reject() argument
244 return cb_check(a, status, resp, 1); in cb_reject()
250 Action *a; in fb_queue_require() local
251 a = queue_action(OP_QUERY, "getvar:%s", var); in fb_queue_require()
252 a->prod = prod; in fb_queue_require()
253 a->data = value; in fb_queue_require()
254 a->size = nvalues; in fb_queue_require()
255 a->msg = mkmsg("checking %s", var); in fb_queue_require()
256 a->func = invert ? cb_reject : cb_require; in fb_queue_require()
257 if (a->data == nullptr) die("out of memory"); in fb_queue_require()
260 static int cb_display(Action* a, int status, const char* resp) { in cb_display() argument
262 fprintf(stderr, "%s FAILED (%s)\n", a->cmd, resp); in cb_display()
265 fprintf(stderr, "%s: %s\n", (char*) a->data, resp); in cb_display()
271 Action *a; in fb_queue_display() local
272 a = queue_action(OP_QUERY, "getvar:%s", var); in fb_queue_display()
273 a->data = strdup(prettyname); in fb_queue_display()
274 if (a->data == nullptr) die("out of memory"); in fb_queue_display()
275 a->func = cb_display; in fb_queue_display()
278 static int cb_save(Action* a, int status, const char* resp) { in cb_save() argument
280 fprintf(stderr, "%s FAILED (%s)\n", a->cmd, resp); in cb_save()
283 strncpy(reinterpret_cast<char*>(a->data), resp, a->size); in cb_save()
289 Action *a; in fb_queue_query_save() local
290 a = queue_action(OP_QUERY, "getvar:%s", var); in fb_queue_query_save()
291 a->data = (void *)dest; in fb_queue_query_save()
292 a->size = dest_size; in fb_queue_query_save()
293 a->func = cb_save; in fb_queue_query_save()
303 Action *a = queue_action(OP_COMMAND, "reboot"); in fb_queue_reboot() local
304 a->func = cb_do_nothing; in fb_queue_reboot()
305 a->msg = "rebooting"; in fb_queue_reboot()
310 Action *a = queue_action(OP_COMMAND, cmd); in fb_queue_command() local
311 a->msg = msg; in fb_queue_command()
316 Action *a = queue_action(OP_DOWNLOAD, ""); in fb_queue_download() local
317 a->data = data; in fb_queue_download()
318 a->size = size; in fb_queue_download()
319 a->msg = mkmsg("downloading '%s'", name); in fb_queue_download()
324 Action *a = queue_action(OP_NOTICE, ""); in fb_queue_notice() local
325 a->data = (void*) notice; in fb_queue_notice()
335 Action *a; in fb_execute_queue() local
339 a = action_list; in fb_execute_queue()
340 if (!a) in fb_execute_queue()
345 for (a = action_list; a; a = a->next) { in fb_execute_queue()
346 a->start = now(); in fb_execute_queue()
347 if (start < 0) start = a->start; in fb_execute_queue()
348 if (a->msg) { in fb_execute_queue()
350 fprintf(stderr,"%s...\n",a->msg); in fb_execute_queue()
352 if (a->op == OP_DOWNLOAD) { in fb_execute_queue()
353 status = fb_download_data(transport, a->data, a->size); in fb_execute_queue()
354 status = a->func(a, status, status ? fb_get_error() : ""); in fb_execute_queue()
356 } else if (a->op == OP_COMMAND) { in fb_execute_queue()
357 status = fb_command(transport, a->cmd); in fb_execute_queue()
358 status = a->func(a, status, status ? fb_get_error() : ""); in fb_execute_queue()
360 } else if (a->op == OP_QUERY) { in fb_execute_queue()
361 status = fb_command_response(transport, a->cmd, resp); in fb_execute_queue()
362 status = a->func(a, status, status ? fb_get_error() : resp); in fb_execute_queue()
364 } else if (a->op == OP_NOTICE) { in fb_execute_queue()
365 fprintf(stderr,"%s\n",(char*)a->data); in fb_execute_queue()
366 } else if (a->op == OP_DOWNLOAD_SPARSE) { in fb_execute_queue()
367 status = fb_download_data_sparse(transport, reinterpret_cast<sparse_file*>(a->data)); in fb_execute_queue()
368 status = a->func(a, status, status ? fb_get_error() : ""); in fb_execute_queue()
370 } else if (a->op == OP_WAIT_FOR_DISCONNECT) { in fb_execute_queue()