Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / apps / zde / appsrv.c
blob2738904e8242a11a491b3fbc560764937cc5040f
1 /*
2 * ZeX/OS
3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <fcntl.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <pthread.h>
25 #include <libx/base.h>
26 #include <libx/object.h>
27 #include <libx/image.h>
28 #include <libx/cursor.h>
29 #include <libx/text.h>
30 #include <ipc.h>
32 #include "appcl.h"
33 #include "appsrv.h"
34 #include "dialog.h"
35 #include "cursor.h"
37 int appsrv_fd;
38 int appcl_fd;
39 char appsrv_buf[100];
41 int appsrv_accept (int fd)
43 ipc_send (fd, "ZDE", 3);
45 return 0;
48 int appsrv_redraw (zde_dobj_appcl_t *appcl)
50 if (!appcl)
51 return -1;
53 /* new window (client) */
54 if (appcl->fd == -1 && appcl_fd != -1) {
55 appcl->fd = appcl_fd;
56 appcl_fd = -1;
59 if (appcl->fd > 0 && !(appcl->state & APPCL_STATE_REDRAW)) {
60 appcl->state |= APPCL_STATE_REDRAW;
62 zde_drawlock ();
64 ipc_send (appcl->fd, (char *) appcl, sizeof (appcl_t));
66 int ret = ipc_recv (appcl->fd, (char *) appsrv_buf, 99);
68 if (ret > 0) {
69 memcpy (appcl, appsrv_buf, sizeof (appcl_t));
71 if (appcl->state & APPCL_STATE_RECVOK) {
72 appcl->state &= ~APPCL_STATE_RECVOK;
73 zde_drawunlock ();
76 return 0;
80 return -1;
83 int appsrv_exit (zde_dobj_appcl_t *appcl)
85 if (!appcl)
86 return -1;
88 /* new window (client) ? */
89 if (appcl->fd == -1)
90 return -1;
92 appcl->state |= APPCL_STATE_EXIT;
94 ipc_send (appcl->fd, (char *) appcl, sizeof (appcl_t));
96 return 0;
99 void *handler_appsrv (void *p)
101 for (;; schedule ()) {
102 int fd = ipc_accept (appsrv_fd);
104 if (fd > 0) {
105 appsrv_accept (fd);
106 appcl_fd = fd;
110 return (0);
113 int init_appsrv ()
115 appsrv_fd = ipc_create ("/zdeserver", 0);
117 if (appsrv_fd < 1)
118 return -1;
120 appcl_fd = -1;
122 pthread_t thread;
124 pthread_create (&thread, NULL, handler_appsrv, 0);
126 return 0;