revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-android / kernel / _displayalert.c
blob4db6a3eb5258b863a1bf3d1e34f2062c36f4f4db
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Display an alert in Android GUI if possible
6 Lang: english
7 */
9 #include <aros/atomic.h>
10 #include <aros/libcall.h>
11 #include <aros/symbolsets.h>
12 #include <proto/exec.h>
14 #include <inttypes.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"
22 #define D(x)
24 struct AlertRequest
26 ULONG cmd;
27 ULONG params;
28 ULONG code;
29 ULONG text;
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);
34 int alertPipe = -1;
36 int SendAlert(uint32_t code, const char *text)
38 struct AlertRequest req;
39 int res;
41 /* Prepare a message to server */
42 req.cmd = 0x00001000; /* cmd_Alert */
43 req.params = 2; /* Two parameters: code and string address */
44 req.code = code;
45 req.text = (IPTR)text;
47 /* Send the packet */
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)
62 APTR libHandle;
63 int *ptr;
64 char *err;
66 /* write() is located in system's libc */
67 host_write = HostIFace->hostlib_GetPointer(libc, "write", &err);
68 if (!host_write)
70 krnPanic(NULL, "Failed to find \"write\" function\n%s", err);
71 return FALSE;
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));
77 if (!libHandle)
79 krnPanic(NULL, "Failed to open libAROSBootstrap.so\n%s\n", err);
80 return FALSE;
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);
90 if (alertPipe == -1)
92 bug("Failed to estabilish communication with display server!\n");
93 return FALSE;
96 return TRUE;
99 /* kernel.resource's STARTUP set is executed on very early startup */
100 ADD2SET(Alert_Init, STARTUP, 0);