Added LICENSE; Added GPL2 header to all source code files
[ArenaLive.git] / core.c
blob784c4424b66cf83cda3a59d4dfa2bc1a8981b9f3
1 /*
2 * (C) Copyright 2009 ZeXx86 (zexx86@gmail.com)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "glugin.h"
22 #include <GL/gl.h>
23 #include <GL/glu.h>
24 #include <unistd.h>
25 #include <math.h>
27 void guest_read_host_requests (pluginData *pd)
29 int cmd;
30 NPStream *s;
32 if (fread (&cmd, sizeof (int), 1, pd->pr) <= 0)
33 return; //no data
35 switch (cmd) {
36 case gln_new_stream:
37 fread (&s, sizeof (s), 1, pd->pr);
39 pd->handle_newstream (pd,s);
40 break;
41 case gln_destroy_stream:
42 fread (&s, sizeof (s), 1, pd->pr);
44 pd->handle_destroystream (pd, s);
45 break;
46 case gln_stream_data:
48 int32 off, len;
49 void *data;
51 fread (&s, sizeof (s), 1, pd->pr);
52 fread (&off, sizeof (off), 1, pd->pr);
53 fread (&len, sizeof (len), 1, pd->pr);
55 if (len > 0) {
56 data = malloc (len);
58 fread (data,len,1,pd->pr);
60 pd->handle_write (pd, s, off, len, data);
62 free (data);
63 } else
64 Log ("w: zero len!");
66 break;
67 default:
68 Log ("Unhandled request to guest: %d", cmd);
72 void guest_newstream (pluginData *pd, NPStream *s)
74 Log ("guest has NEWSTREAM: %p",s);
77 void guest_destroystream (pluginData *pd, NPStream *s)
79 Log ("guest has DESTROYSTREAM: %p",s);
82 void guest_write (pluginData *pd, NPStream*s, int32 off, int32 len, void *data)
84 Log ("guest has WRITE: %p %d %d, data followz:", s, off, len);
86 int i;
87 for (i = 0; i < len; ++ i)
88 Log ("%8X: %c",i, ((char *) data)[i]);
91 void glugin_proc (pluginData *pd)
93 while (!(pd->exit_request)) {
94 guest_read_host_requests (pd);
96 usleep (1000);
99 pd->exit_ack = 1;