FreeWRL/FreeX3D  3.0.0
EAIEventsOut.c
1 /*
2 
3 
4 Small routines to help with interfacing EAI to Daniel Kraft's parser.
5 
6 */
7 
8 
9 /****************************************************************************
10  This file is part of the FreeWRL/FreeX3D Distribution.
11 
12  Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
13 
14  FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
15  it under the terms of the GNU Lesser Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  FreeWRL/FreeX3D is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  GNU General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
26 ****************************************************************************/
27 
28 
29 #include <config.h>
30 #include <system.h>
31 #include <display.h>
32 #include <internal.h>
33 
34 #include <libFreeWRL.h>
35 
36 #include "../vrml_parser/Structs.h"
37 #include "../main/headers.h"
38 
39 #include "../input/EAIHeaders.h"
40 #include "../world_script/fieldGet.h"
41 
42 
43 #if !defined(EXCLUDE_EAI)
44 
45 /*****************************************************************
46 *
47 * EAIListener is called when a requested value changes.
48 *
49 * (see the CRoutes_Register call above for this routing setup)
50 *
51 * This routine decodes the data type and acts on it. The data type
52 * has (currently) an id number, that the client uses, and the data
53 * type.
54 *
55 ********************************************************************/
56 
57 #ifdef FOR_DEBUGGING
58 static void goThroughFields(struct X3D_Node *boxptr) {
59 
60 char utilBuf[10000];
61 char *tmpptr;
62 char ctmp;
63 char dtmp;
64 
65 int *np;
66 int myc;
67 int errcount;
68 
69 
70 np = (int *) NODE_OFFSETS[boxptr->_nodeType];
71  myc = 0;
72  while (*np != -1) {
73  /* is this a hidden field? */
74  if (0 != strncmp(stringFieldType(np[0]), "_", 1) ) {
75  ctmp = (char) mapFieldTypeToEAItype(np[2]) ;
76  dtmp = mapEAItypeToFieldType(ctmp) ;
77 
78  tmpptr = offsetPointer_deref (char *, boxptr,np[1]);
79  printf("%s,%d ",__FILE__,__LINE__) ;
80  printf("Field %d %s , ", myc, stringFieldType(np[0])) ;
81  printf("offset=%d bytes , ", np[1]) ;
82 
83  printf("field_type= %c (%d) , ", ctmp , dtmp) ;
84  printf("Routing=%s , ", stringKeywordType(np[3])) ;
85  printf("Spec=%d , ", np[4]) ;
86 
87  errcount = UtilEAI_Convert_mem_to_ASCII (dtmp,tmpptr, utilBuf);
88  if (0 == errcount) {
89  printf ("\t\tValue = %s\n",utilBuf);
90  } else {
91  printf ("\t\tValue = indeterminate....\n");
92  }
93  myc ++;
94  }
95  np +=5;
96  }
97 }
98 #endif // FOR_DEBUGGING
99 
100 /*
101 struct EAI_Extra_Data {
102  int field_id;
103  int node_id;
104  int field_type;
105  int listener_id;
106 };
107 */
108 
109 
110 
111 
112 void EAIListener () {
113  int node_id, field_id;
114  int field_type, listener_id;
115  char buf[EAIREADSIZE];
116  int eaiverbose;
117  //ppEAICore p;
118  ttglobal tg = gglobal();
119  eaiverbose = tg->EAI_C_CommonFunctions.eaiverbose;
120  //p = (ppEAICore)tg->EAICore.prv;
121 
122  /* get the type and the id.*/
123  struct EAI_Extra_Data *pp = (struct EAI_Extra_Data*) tg->CRoutes.CRoutesExtra;
124  field_id = pp->field_id;
125  node_id = pp->node_id;
126  field_type = pp->field_type;
127  listener_id = pp->listener_id;
128 
129 // field_id = tg->CRoutes.CRoutesExtra&0xff;
130 // node_id = (tg->CRoutes.CRoutesExtra & 0x00ffff00) >>8;
131 // field_type = ((tg->CRoutes.CRoutesExtra & 0xff000000) >>24);
132 
133  struct X3D_Node* tableNode = getEAINodeFromTable(node_id,field_id);
134  int actual_offs = getEAIActualOffset(node_id, field_id);
135 
136  #ifdef FOR_DEBUGGING
137 
138  printf ("EAIListener, from table, actual offset is %d\n",actual_offs);
139  printf ("EAIListener, frim table, field_type is :%d: %s\n",field_type,FIELDTYPES[field_type]);
140  printf ("EAIListener, from table, table node is %p\n",tableNode);
141  printf ("EAIListener, from a node of %s\n",stringNodeType(tableNode->_nodeType));
142  printf ("EAIListener, type %d, node id %d\n",field_id,node_id);
143  printf ("EAIListener, node type from table as a string is %s\n",stringNodeType(getEAINodeTypeFromTable(node_id)));
144  goThroughFields(tableNode);
145  #endif //FOR_DEBUGGING
146 
147 
148  char *field_pointer = offsetPointer_deref (char *, tableNode, actual_offs);
149  EAI_Convert_mem_to_ASCII (listener_id,"EV", field_type, field_pointer, buf);
150 
151  /* append the EV_EOT marker to the end of the string */
152  strcat (buf,"\nEV_EOT");
153 
154  if (eaiverbose) {
155  printf ("Handle Listener, returning %s\n",buf);
156  }
157 
158  /* send the EV data (not really a reply, but a system event) */
159  fwlio_RxTx_sendbuffer(__FILE__,__LINE__,CHANNEL_EAI,buf) ;
160 }
161 
162 #endif //EXCLUDE_EAI