2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Display an alert in Android GUI if possible
9 #include <aros/atomic.h>
10 #include <aros/libcall.h>
11 #include <aros/symbolsets.h>
12 #include <proto/exec.h>
16 #include "hostinterface.h"
17 #include "kernel_base.h"
18 #include "kernel_debug.h"
19 #include "kernel_android.h"
20 #include "kernel_unix.h"
32 /* We hold our pointers in global variables because we haven't allocated anything yet */
33 ssize_t (*host_write
)(int fd
, void *buf
, size_t count
);
36 int SendAlert(uint32_t code
, const char *text
)
38 struct AlertRequest req
;
41 /* Prepare a message to server */
42 req
.cmd
= 0x00001000; /* cmd_Alert */
43 req
.params
= 2; /* Two parameters: code and string address */
45 req
.text
= (IPTR
)text
;
48 res
= host_write(alertPipe
, &req
, sizeof(req
));
50 /* Return zero on pipe error */
51 return (res
== sizeof(req
));
55 * This attaches to display server pipe.
56 * We do it very early, because we want startup errors to be reported via Android alerts rather
57 * than just dumped into console.
58 * Basically we need host's write() function and pipe fd.
60 static int Alert_Init(void *libc
)
66 /* write() is located in system's libc */
67 host_write
= HostIFace
->hostlib_GetPointer(libc
, "write", &err
);
70 krnPanic(NULL
, "Failed to find \"write\" function\n%s", err
);
74 /* Now pick up display pipe fd from our bootstrap */
75 libHandle
= HostIFace
->hostlib_Open("libAROSBootstrap.so", &err
);
76 D(bug("[Alert_Init] Bootstrap handle: 0x%p\n", libHandle
));
79 krnPanic(NULL
, "Failed to open libAROSBootstrap.so\n%s\n", err
);
83 ptr
= HostIFace
->hostlib_GetPointer(libHandle
, "DisplayPipe", NULL
);
84 D(bug("[Alert_Init] DisplayPipe pointer: %p\n", ptr
));
86 alertPipe
= ptr
? *ptr
: -1;
88 HostIFace
->hostlib_Close(libHandle
, NULL
);
92 bug("Failed to estabilish communication with display server!\n");
99 /* kernel.resource's STARTUP set is executed on very early startup */
100 ADD2SET(Alert_Init
, STARTUP
, 0);