blob: 55a839b28f29dd912464ca38d667605c38941443 [file] [log] [blame]
b.liuced8dd02024-06-28 13:28:29 +08001#include <string.h>
2#include "aboot-tiny.h"
3#include "jacana_callback.h"
4
5/*---------------------------------------------------------------------------*/
6static aboot_tiny_error_t rc;
7/*---------------------------------------------------------------------------*/
8aboot_tiny_error_t
9jacana_aboot_tiny_get_result(void)
10{
11 return rc;
12}
13/*---------------------------------------------------------------------------*/
14void
15jacana_aboot_tiny_set_result(aboot_tiny_error_t r)
16{
17 rc = r;
18}
19/*---------------------------------------------------------------------------*/
20void
21jacana_aboot_tiny_callback(const aboot_tiny_message_t *msg)
22{
23 switch(msg->event) {
24 case ABOOT_TINY_EVENT_START:
25 if(msg->u.message) {
26 aboot_tiny_log_printf("%s\n", msg->u.message);
27 }
28 if(!msg->error) {
29 if(!aboot_tiny_download()) {
30 break;
31 }
32 } else {
33 rc = msg->error;
34 aboot_tiny_stop();
35 }
36 break;
37
38 case ABOOT_TINY_EVENT_DOWNLOAD:
39 if(msg->u.message) {
40 aboot_tiny_log_printf("%s\n", msg->u.message);
41 }
42 if(msg->error) {
43 rc = msg->error;
44 aboot_tiny_stop();
45 }
46 break;
47
48 case ABOOT_TINY_EVENT_STOP:
49 if(msg->u.message) {
50 aboot_tiny_log_printf("%s\n", msg->u.message);
51 }
52 aboot_tiny_exit();
53 break;
54
55 case ABOOT_TINY_EVENT_PROGRESS:
56 aboot_tiny_log_printf("PROGRESS: %d\n", msg->u.progress);
57 break;
58
59 case ABOOT_TINY_EVENT_STATUS:
60 aboot_tiny_log_printf("STATUS: %s\n", msg->u.status);
61 if(msg->error ||
62 !strcmp(msg->u.status, ABOOT_TINY_STATUS_FAILED) ||
63 !strcmp(msg->u.status, ABOOT_TINY_STATUS_SUCCEEDED)) {
64 rc = msg->error;
65 aboot_tiny_stop();
66 }
67 break;
68
69 default:
70 aboot_tiny_log_printf("Unknown event: %d\n", msg->event);
71 break;
72 }
73}
74/*---------------------------------------------------------------------------*/