68#include <libFreeWRL.h>
70#include "../vrml_parser/Structs.h"
71#include "../main/headers.h"
72#include "../vrml_parser/CParseGeneral.h"
73#include "../vrml_parser/CParseLexer.h"
74#include "../vrml_parser/CParseParser.h"
75#include "../vrml_parser/CParse.h"
76#include "../world_script/JScript.h"
77#include "../world_script/CScripts.h"
78#include "../world_script/fieldGet.h"
80#include "../input/EAIHeaders.h"
81#include "../world_script/fieldSet.h"
82#include "../scenegraph/Viewer.h"
83#include "../opengl/OpenGL_Utils.h"
84#include "../scenegraph/RenderFuncs.h"
85#include "../opengl/OpenGL_Utils.h"
86#include "../opengl/Textures.h"
87#include "../x3d_parser/X3DParser.h"
88#include "../vrml_parser/CRoutes.h"
90#include "EAIHelpers.h"
91#include "EAIHeaders.h"
95#define EAI_BUFFER_CUR tg->EAICore.EAIbuffer[bufPtr]
101static void makeFIELDDEFret(
int,
int);
102static void handleRoute (
char command,
char *bufptr,
int repno);
103static void handleGETNODE (
char *bufptr,
int repno);
104static void handleGETNODEPARENTS (
char *bufptr,
int repno);
105static void handleGETROUTES (
char *bufptr,
int repno);
106static void handleGETEAINODETYPE (
char *bufptr,
int repno);
107extern void dump_scene (FILE *fp,
int level,
struct X3D_Node* node);
131int waiting_for_anchor;
134void *EAIEventsIn_constructor()
140void EAIEventsIn_init(
struct tEAIEventsIn* t)
146 t->prv = EAIEventsIn_constructor();
149 p->waiting_for_anchor = FALSE;
161 pthread_mutex_t eaibufferlock;
164void *EAICore_constructor()
166 void *v = MALLOC(
void *,
sizeof(
struct pEAICore));
167 memset(v,0,
sizeof(
struct pEAICore));
170void EAICore_init(
struct tEAICore* t){
172 t->prv = EAICore_constructor();
175 pthread_mutex_init(&(p->eaibufferlock), NULL);
178 t->EAIbufsize = EAIREADSIZE ;
181struct X3D_Anchor* get_EAIEventsIn_AnchorNode()
184 return (
struct X3D_Anchor*)&p->EAI_AnchorNode;
187#if !defined(EXCLUDE_EAI)
188int fwl_EAI_allDone() {
193 bufPtr = tg->EAICore.EAIbufpos;
194 stillToDo = (int)strlen((&EAI_BUFFER_CUR));
195 eaiverbose = tg->EAI_C_CommonFunctions.eaiverbose;
196 if (eaiverbose && stillToDo > 0) {
197 printf (
"EAI_allDone still to do: strlen %d str :%s:\n",stillToDo, (&EAI_BUFFER_CUR));
202char * fwl_EAI_handleRest() {
206 struct tEAIHelpers *th;
208 bufPtr = tg->EAICore.EAIbufpos;
209 stillToDo = (int)strlen((&EAI_BUFFER_CUR));
210 eaiverbose = tg->EAI_C_CommonFunctions.eaiverbose;
212 if(NULL == tg->EAICore.EAIbuffer) {
213 printf(
"fwl_EAI_handleRest() did not have a buffer, WTF!!") ;
218 printf(
"%s:%d fwl_EAI_handleRest: Buffer at %p , bufPtr=%d , still to do=%d str :%s:\n",\
219 __FILE__,__LINE__,tg->EAICore.EAIbuffer,bufPtr,(
int)strlen((&EAI_BUFFER_CUR)), (&EAI_BUFFER_CUR));
222 EAI_core_commands() ;
224 th = &tg->EAIHelpers;
225 return th->outBuffer ;
231char * EAI_handleBuffer(
char *fromFront,
bool useSockets) {
234 int len = (int)strlen(fromFront) ;
236 struct tEAIHelpers *th;
237 eaiverbose = tg->EAI_C_CommonFunctions.eaiverbose;
244 if(tg->EAICore.EAIbufsize > EAIREADSIZE && len < EAIREADSIZE)
247 printf(
"EAI_handleBuffer() does not need that much space, so we clear at %p\n",tg->EAICore.EAIbuffer) ;
251 if(NULL != tg->EAICore.EAIbuffer)
253 FREE(tg->EAICore.EAIbuffer);
254 tg->EAICore.EAIbuffer = NULL;
258 tg->EAICore.EAIbufsize = EAIREADSIZE;
260 else if(len >= tg->EAICore.EAIbufsize)
263 printf(
"EAI_handleBuffer() needs a larger buffer, so we clear one at %p\n",tg->EAICore.EAIbuffer) ;
266 if(NULL != tg->EAICore.EAIbuffer)
268 FREE(tg->EAICore.EAIbuffer);
269 tg->EAICore.EAIbuffer = NULL;
273 tg->EAICore.EAIbufsize = len+1;
278 if(NULL == tg->EAICore.EAIbuffer) {
279 tg->EAICore.EAIbuffer = MALLOC(
char *, tg->EAICore.EAIbufsize * sizeof (
char));
281 printf(
"fwl_EAI_handleBuffer() did not have a buffer, so create one at %p\n",tg->EAICore.EAIbuffer) ;
285 printf(
"%s:%d fwl_EAI_handleBuffer: Buffer at %p is %d chars,",__FILE__,__LINE__,fromFront,len);
286 printf(
"Copy to buffer at %p\n", tg->EAICore.EAIbuffer);
290 if(!useSockets || len <= EAIREADSIZE) {
293 tg->EAICore.EAIbuffer[len] =
'\0';
294 memcpy(tg->EAICore.EAIbuffer, fromFront, len);
298 tg->EAICore.EAIbufpos = 0;
299 tg->EAICore.EAIbufcount = 0;
301 EAI_core_commands() ;
303 th = &tg->EAIHelpers;
304 return th->outBuffer ;
307 fwlio_RxTx_control(CHANNEL_EAI,RxTx_STOP) ;
313char * fwl_EAI_handleBufferNoSKT(
char *fromFront)
315 return EAI_handleBuffer(fromFront,
false);
318char * fwl_EAI_handleBuffer(
char *fromFront) {
319 return EAI_handleBuffer(fromFront,
true);
358void EAI_core_commands () {
360 char ctmp[EAIREADSIZE];
361 char dtmp[EAIREADSIZE];
370 int tmp_a, tmp_b, tmp_c;
388 struct tEAIHelpers *th;
395 eaiverbose = tg->EAI_C_CommonFunctions.eaiverbose;
396 th = &tg->EAIHelpers;
400 bufPtr = tg->EAICore.EAIbufpos;
403 th->outBufferLen = EAIREADSIZE;
404 th->outBuffer = MALLOC(
char *, th->outBufferLen);
405 th->outBuffer[0] = 0;
407 if (EAI_BUFFER_CUR> 0) {
409 printf (
"EAI_core_commands: strlen %d str :%s:\n",(
int)strlen((&EAI_BUFFER_CUR)), (&EAI_BUFFER_CUR));
413 if (sscanf ((&EAI_BUFFER_CUR),
"%d",&count) != 1) {
414 printf (
"EAI_core_commands, expected a sequence number on command :%s:\n",(&EAI_BUFFER_CUR));
418 printf (
"EAI - seq number %d\n",count);
421 if (count != (p->oldCount+1)) {
422 printf (
"COUNT MISMATCH, expected %d got %d\n",p->oldCount+1,count);
428 while (isdigit(EAI_BUFFER_CUR)) bufPtr++;
433 while (EAI_BUFFER_CUR ==
' ') bufPtr++;
442 printf (
"EAI command %s (%c) strlen %d\n",eaiPrintCommand(
command),
command,(
int)strlen(&EAI_BUFFER_CUR));
448 printf (
"\n... %d ",count);
454 int sendNameNotFile = 1 ;
458 dumpname = TEMPNAM(gglobal()->Mainloop.tmpFileLocation,
"fwtmp");
459 dumpfd = fopen(dumpname,
"w+");
460 dump_scene(dumpfd, 0, (
struct X3D_Node*) rootNode());
462 if (sendNameNotFile) {
464 throwAway = sprintf (th->outBuffer,
"RE\n%f\n%d\n%s",TickTime(),count,dumpname);
466 dumpfsize = (int) ftell(dumpfd) ;
467 fseek(dumpfd, 0L, SEEK_SET) ;
469 th->outBuffer = REALLOC(th->outBuffer,dumpfsize+200);
470 dumpInt = sprintf (th->outBuffer,
"RE\n%f\n%d\n",TickTime(),count);
471 throwAway = (int) fread(th->outBuffer+dumpInt, dumpfsize, 1, dumpfd);
472 dumpInt += dumpfsize;
474 th->outBuffer[dumpInt] =
'\0';
485 sprintf (th->outBuffer,
"RE\n%f\n%d\n%s %dx%d %d %s %d %f",TickTime(),count,
487 rdr_caps->system_max_texture_size, rdr_caps->runtime_max_texture_size,
488 rdr_caps->texture_units,
490 tg->OpenGL_Utils.displayDepth,
499 sprintf (th->outBuffer,
"RE\n%f\n%d\n%s",TickTime(),count,BrowserName);
503 sprintf (th->outBuffer,
"RE\n%f\n%d\n%s",TickTime(),count,libFreeWRL_get_version());
507 sprintf (th->outBuffer,
"RE\n%f\n%d\n%d",TickTime(),count,tg->Mainloop.currentFileVersion);
513 sprintf (th->outBuffer,
"RE\n%f\n%d\n%f",TickTime(),count,gglobal()->Mainloop.BrowserSpeed);
517 sprintf (th->outBuffer,
"RE\n%f\n%d\n%f",TickTime(),count,gglobal()->Mainloop.BrowserFPS);
521 sprintf (th->outBuffer,
"RE\n%f\n%d\n%s",TickTime(),count,BrowserFullPath);
525 handleGETNODE(&EAI_BUFFER_CUR,count);
529 handleGETROUTES(&EAI_BUFFER_CUR,count);
533 case GETEAINODETYPE: {
534 handleGETEAINODETYPE(&EAI_BUFFER_CUR,count);
540 retint = sscanf(&EAI_BUFFER_CUR,
"%d",(&cNode));
541 if (eaiverbose) { printf (
"\n"); }
543 boxptr = getEAINodeFromTable(cNode,-1);
544 sprintf (th->outBuffer,
"RE\n%f\n%d\n%d",TickTime(),count,getSAI_X3DNodeType (
547 sprintf (th->outBuffer,
"RE\n%f\n%d\n-1",TickTime(),count);
559 retint=sscanf (&EAI_BUFFER_CUR,
"%d %s %s",&xtmp, ctmp,dtmp);
560 if (eaiverbose) { printf (
"\n"); }
562 printf (
"GETFIELDTYPE cptr %d %s %s\n",xtmp, ctmp, dtmp);
565 EAI_GetType (xtmp, ctmp, dtmp, &ra, &rb, &rc, &rd, &scripttype, &xxx);
566 sprintf (th->outBuffer,
"RE\n%lf\n%d\n%d %d %d %c %d %s",TickTime(),count,(
int)ra,(
int)rb,(
int)rc,(
int)rd,
567 scripttype,stringKeywordType(xxx));
572 setField_FromEAI (&EAI_BUFFER_CUR);
573 th->outBuffer[0] = 0;
575 printf (
"after SENDEVENT, strlen %d\n",(
int)strlen(&EAI_BUFFER_CUR));
585 retGroup = createNewX3DNode(NODE_Group);
590 int currentWaitCount=0;
593 if(
command==CREATEVS) printf (
"CREATEVS %s\n",&EAI_BUFFER_CUR);
594 if(
command==CREATEXS) printf (
"CREATEXS %s\n",&EAI_BUFFER_CUR);
597 EOT = strstr(&EAI_BUFFER_CUR,
"\nEOT\n");
605 while (EOT == NULL && topWaitLimit >= currentWaitCount) {
606 if(fwlio_RxTx_control(CHANNEL_EAI,RxTx_REFRESH) == 0) {
611 if(fwlio_RxTx_waitfor(CHANNEL_EAI,
"\nEOT\n") != (
char *)NULL) {
612 char *tempEAIdata = fwlio_RxTx_getbuffer(CHANNEL_EAI) ;
613 if(tempEAIdata != (
char *)NULL) {
614 strcat(&EAI_BUFFER_CUR,tempEAIdata) ;
623 EOT = strstr(&EAI_BUFFER_CUR,
"\nEOT\n");
625 if (topWaitLimit <= currentWaitCount) {
627 sprintf (th->outBuffer,
"RE\n%f\n%d\n-1",TickTime(),count);
632 ra = EAI_CreateVrml(
"String",(&EAI_BUFFER_CUR),rootNode(),retGroup);
634 ra = EAI_CreateX3d(
"String",(&EAI_BUFFER_CUR),rootNode(),retGroup);
636 bufPtr = (int) (EOT+3-tg->EAICore.EAIbuffer);
644 while ((EAI_BUFFER_CUR!=0) && (EAI_BUFFER_CUR <=
' ')) bufPtr++;
645 while (EAI_BUFFER_CUR >
' ') { ctmp[rb] = EAI_BUFFER_CUR; rb ++; bufPtr++; }
651 mypath = STRDUP(ctmp);
652 DEBUG_MSG(
"CREATEVU, mypath %s\n", mypath);
666 ra = EAI_CreateVrml(
"URL", mypath, rootNode(), retGroup);
672 sprintf (th->outBuffer,
"RE\n%f\n%d\n",TickTime(),count);
673 for (rb = 0; rb < retGroup->children.n; rb++) {
675 node = X3D_NODE(retGroup->children.p[rb]);
678 sprintf (ctmp,
"%d ", registerEAINodeForAccess(node));
683 remove_parent(node,X3D_NODE(retGroup));
687 markForDispose(X3D_NODE(retGroup),FALSE);
697 retint=sscanf (&EAI_BUFFER_CUR,
"%d %d %s %d",&ra,&rb,ctmp,&rc);
699 node = getEAINodeFromTable(ra,rb);
700 address = getEAIMemoryPointer (ra,rb);
703 printf (
"SENDCHILD Parent: %u ParentField: %u %s Child at: %d\n",(
unsigned int) ra, (
unsigned int)rb, ctmp, rc);
710 getMFNodetype (getEAINodeFromTable(rc,-1),(
struct Multi_Node *)address, node, 1);
713 MARK_EVENT(node,getEAIActualOffset(ra,rb));
715 sprintf (th->outBuffer,
"RE\n%f\n%d\n0",TickTime(),count);
721 int directionFlag = 0;
724 retint=sscanf (&EAI_BUFFER_CUR,
"%d %d %c %d",&tmp_a,&tmp_b,ctmp,&tmp_c);
725printf (
"REGLISTENER, calling getEAINodeFromTable(%d, %d)\n",tmp_a,tmp_b);
726 node = getEAINodeFromTable(tmp_a, tmp_b);
727printf (
"REGLISTENER, calling getEAIActualOffset(%d, %d)\n",tmp_a,tmp_b);
728 offset = getEAIActualOffset(tmp_a, tmp_b);
729printf (
"REGLISTENER, have node %p, offset %d (%s)\n",node,offset, stringNodeType(node->_nodeType));
730printf (
"REGLISTENER, ctmp tells us that type is %c\n",ctmp[0]);
733 if (node->_nodeType == NODE_Script) {
737 sp = (
struct Shader_Script *) (X3D_SCRIPT(node)->__scriptObj);
744 node = offsetPointer_deref(
struct X3D_Node *,0,sp->num);
745 directionFlag = FROM_SCRIPT;
752 printf (
"REGISTERLISTENER from %p foffset %d fieldlen %d type %s \n",
753 node, offset ,tmp_c,ctmp);
760 if (eaiverbose) printf (
"going to register route for RegisterListener, have type %d\n",tmp_c);
765 ed->field_type = mapEAItypeToFieldType(ctmp[0]);
766 ed->listener_id = count;
767 ed->field_id = tmp_b;
768 ed-> node_id = tmp_a;
779printf (
"registering, field_id %d, node_id %d, field_type %d, listener_id %d\n",ed->field_id, ed->node_id, ed->field_type, ed->listener_id);
782 CRoutes_Register (1,node, offset, NULL, 0, (
int) tmp_c,(
void *)
783 &EAIListener, directionFlag, ed);
790 sprintf (th->outBuffer,
"RE\n%f\n%d\n0",TickTime(),count);
794 case UNREGLISTENER: {
799 int directionFlag = 0;
802 retint=sscanf (&EAI_BUFFER_CUR,
"%d %d %c %d",&tmp_a,&tmp_b,ctmp,&tmp_c);
803 node = getEAINodeFromTable(tmp_a,tmp_b);
804 offset = getEAIActualOffset(tmp_a,tmp_b);
806 if (node->_nodeType == NODE_Script) {
810 sp = (
struct Shader_Script *) (X3D_SCRIPT(node)->__scriptObj);
817 node = offsetPointer_deref(
struct X3D_Node *,0,sp->num);
818 directionFlag = FROM_SCRIPT;
824 if (eaiverbose) printf (
"UNREGISTERLISTENER from %p foffset %d fieldlen %d type %s \n",
825 node, offset ,tmp_c,ctmp);
832 iextra = (count<<8)+mapEAItypeToFieldType(ctmp[0]);
835 memcpy(vextra,&iextra,4);
836 CRoutes_Register (0,node, offset, NULL, 0, (
int) tmp_c,(
void *)
837 &EAIListener, directionFlag, vextra );
839 sprintf (th->outBuffer,
"RE\n%f\n%d\n0",TickTime(),count);
844 handleEAIGetValue(
command, &EAI_BUFFER_CUR,count);
848 EAI_RW(&EAI_BUFFER_CUR);
849 sprintf (th->outBuffer,
"RE\n%f\n%d\n0",TickTime(),count);
854 sprintf (th->outBuffer,
"RE\n%f\n%d\n%s",TickTime(),count,SAI_StrRetCommand ((
char)
command,&EAI_BUFFER_CUR));
862 printf (
"SV int ret command ..%s\n",&EAI_BUFFER_CUR);
864 sprintf (th->outBuffer,
"RE\n%f\n%d\n%d",TickTime(),count,
865 SAI_IntRetCommand ((
char)
command,&EAI_BUFFER_CUR));
870 handleRoute (
command, &EAI_BUFFER_CUR,count);
875 if (!RUNNINGASPLUGIN) {
876 fwl_doQuit(__FILE__,__LINE__);
882 if (!strncmp(&EAI_BUFFER_CUR,
" NEXT",5)) fwl_Next_ViewPoint();
883 if (!strncmp(&EAI_BUFFER_CUR,
" FIRST",6)) fwl_First_ViewPoint();
884 if (!strncmp(&EAI_BUFFER_CUR,
" LAST",5)) fwl_Last_ViewPoint();
885 if (!strncmp(&EAI_BUFFER_CUR,
" PREV",5)) fwl_Prev_ViewPoint();
887 sprintf (th->outBuffer,
"RE\n%f\n%d\n0",TickTime(),count);
893 p->waiting_for_anchor = TRUE;
896 createLoadURL(&EAI_BUFFER_CUR);
900 sprintf (th->outBuffer,
"RE\n%f\n%d\n",TickTime(),count);
917 setAnchorsAnchor( get_EAIEventsIn_AnchorNode());
918 tg->RenderFuncs.BrowserAction = TRUE;
926 while ((EAI_BUFFER_CUR!=0) && (EAI_BUFFER_CUR <=
' ')) bufPtr++;
927 while (EAI_BUFFER_CUR >
' ') { ctmp[rb] = EAI_BUFFER_CUR; rb ++; bufPtr++; }
931 printf (
"CREATENODE/PROTO %s\n",ctmp);
935 sprintf (th->outBuffer,
"RE\n%f\n%d\n",TickTime(),count);
937 retGroup = createNewX3DNode(NODE_Group);
940 printf (
"CREATENODE, %s is this a simple node? %d\n",ctmp,findFieldInNODES(ctmp));
943 ctype = findFieldInNODES(ctmp);
946 sprintf (ctmp,
"%ld",(
long int) createNewX3DNode(ctype));
951 ra = EAI_CreateVrml(
"CREATENODE",ctmp,rootNode(),retGroup);
953 }
else if (
command == CREATEPROTO)
954 ra = EAI_CreateVrml(
"CREATEPROTO",ctmp,rootNode(),retGroup);
956 printf (
"eai - huh????\n");
959 for (rb = 0; rb < retGroup->children.n; rb++) {
960 sprintf (ctmp,
"%ld ", (
long int) retGroup->children.p[rb]);
962printf (
"Possible EAI problem, children of container group should have this parent removed\n");
967 markForDispose(X3D_NODE(retGroup),FALSE);
973 sscanf (&EAI_BUFFER_CUR,
"%d",&ra);
974 makeFIELDDEFret(ra,count);
978 case GETNODEDEFNAME: {
980 sprintf (th->outBuffer,
"RE\n%f\n%d\n%s",TickTime(),count,
981 SAI_StrRetCommand ((
char)
command,&EAI_BUFFER_CUR));
987 handleGETNODEPARENTS(&EAI_BUFFER_CUR,count);
993 outBufferCat(
"unknown_EAI_command");
1000 while (EAI_BUFFER_CUR >=
' ') bufPtr++;
1002 while ((EAI_BUFFER_CUR == 10) || (EAI_BUFFER_CUR == 13)) bufPtr++;
1005 printf (
"end of command, remainder %d chars ",(
int)strlen(&EAI_BUFFER_CUR));
1007 printf (
"and :%s: thread %lu\n",(&EAI_BUFFER_CUR),(
unsigned long) pthread_self().p);
1009 printf (
"and :%s: thread %lu\n",(&EAI_BUFFER_CUR),(
unsigned long) pthread_self());
1015 th->outBuffer[0] = 0;
1018 if (
command != LOADURL) outBufferCat(
"\nRE_EOT");
1021 tg->EAICore.EAIbufpos = bufPtr;
1027static void handleGETROUTES (
char *bufptr,
int repno) {
1035 struct tEAIHelpers* th = &gglobal()->EAIHelpers;
1037 sprintf (th->outBuffer,
"RE\n%f\n%d\n",TickTime(),repno);
1039 numRoutes = getRoutesCount();
1041 if (numRoutes < 2) {
1047 sprintf (ctmp,
"%d ",numRoutes-2);
1051 for (count = 1; count < (numRoutes-1); count++) {
1052 getSpecificRoute (count,&fromNode, &fromOffset, &toNode, &toOffset);
1054 sprintf (ctmp,
"%p %s %p %s ",fromNode,
1055 findFIELDNAMESfromNodeOffset(fromNode,fromOffset),
1057 findFIELDNAMESfromNodeOffset(toNode,toOffset)
1066static void handleGETNODE (
char *bufptr,
int repno) {
1069 struct tEAIHelpers* th;
1072 eaiverbose = tg->EAI_C_CommonFunctions.eaiverbose;
1073 th = &tg->EAIHelpers;
1078 retint=sscanf (bufptr,
" %s",ctmp);
1081 printf (
"GETNODE %s\n",ctmp);
1085 if (strcmp(ctmp,SYSTEMROOTNODE)) {
1086 sprintf (th->outBuffer,
"RE\n%f\n%d\n%d",TickTime(),repno, EAI_GetNode(ctmp));
1089 sprintf (th->outBuffer,
"RE\n%f\n%d\n%d",TickTime(),repno, EAI_GetRootNode());
1092 printf (
"GETNODE returns %s\n",th->outBuffer);
1096static void handleGETNODEPARENTS (
char *bufptr,
int repno)
1100 char buffer[EAIREADSIZE];
1101 struct tEAIHelpers* th;
1109 eaiverbose = tg->EAI_C_CommonFunctions.eaiverbose;
1110 th = &tg->EAIHelpers;
1116 sscanf(bufptr,
"%d",&nodeHandle);
1119 printf (
"GETNODEPARENTS %d\n",nodeHandle);
1122 result = EAI_GetNodeParents(nodeHandle,&parentArray);
1124 snprintf(buffer,EAIREADSIZE,
"RE\n%f\n%d\n",TickTime(),repno);
1128 for(index = 0; index < result; index++)
1130 snprintf(parentAdr,10,
"%d ",parentArray[index]);
1131 strncat(buffer,parentAdr,strlen(parentAdr));
1136 snprintf(parentAdr,10,
"%d ",result);
1137 strncat(buffer,parentAdr,strlen(parentAdr));
1140 outBufferCat(buffer);
1143 printf (
"GETNODE returns %s\n",th->outBuffer);
1152static void handleGETEAINODETYPE (
char *bufptr,
int repno) {
1158 struct tEAIHelpers *th = &gglobal()->EAIHelpers;
1161 wlen=sscanf (bufptr,
" %d",&nodeHandle);
1162 if (wlen != 1) ConsoleMessage (
"handleGETEAINODETYPE - expected to handle 1 number, got %d",wlen);
1164 myNode = getEAINodeFromTable(nodeHandle,-1);
1166 if (myNode == NULL) {
1167 printf (
"Internal EAI error, node %d not found\n",nodeHandle);
1168 sprintf (th->outBuffer,
"RE\n%f\n%d\n__UNDEFINED __UNDEFINED",TickTime(),repno);
1175 if (isProto(myNode)) {
1176 myNT = parser_getPROTONameFromNode(myNode);
1181 myNT = (
char *) stringNodeType(myNode->_nodeType);
1188 cptr = X3DParser_getNameFromNode(myNode);
1192 sprintf (th->outBuffer,
"RE\n%f\n%d\n%s %s",TickTime(),repno,myNT, cptr);
1197 cptr= parser_getNameFromNode(myNode);
1202 sprintf (th->outBuffer,
"RE\n%f\n%d\n\"%s\" \"%s\"",TickTime(),repno,myNT, cptr);
1208 sprintf (th->outBuffer,
"RE\n%f\n%d\n%s __UNDEFINED",TickTime(),repno,myNT);
1213static void handleRoute (
char command,
char *bufptr,
int repno) {
1216 char fieldTemp[2000];
1217 int fromOffset, toOffset;
1218 int fromfieldType, fromfieldNode, fromretNode, fromretField, fromdataLen;
1221 int tofieldNode, toretNode, toretField, todataLen, tofieldType;
1229 struct tEAIHelpers *th = &gglobal()->EAIHelpers;
1230 eaiverbose = gglobal()->EAI_C_CommonFunctions.eaiverbose;
1235 sprintf (th->outBuffer,
"RE\n%f\n%d\n",TickTime(),repno);
1237 if (eaiverbose) printf (
"handleRoute, string %s\n",bufptr);
1242 while (*bufptr ==
' ') bufptr++;
1245 sscanf(bufptr,
"%u", (
unsigned int *)&fromfieldNode);
1248 x = fieldTemp; ftlen = 0;
1251 while (*bufptr !=
' ') bufptr++;
1252 while (*bufptr ==
' ') bufptr++;
1255 while ((*bufptr >
' ') && (ftlen <1000)) { *x = *bufptr; x++; bufptr++; ftlen++;}
1259 EAI_GetType (fromfieldNode, fieldTemp,
"outputOnly", &fromretNode, &fromretField, &fromdataLen, &fromfieldType, &fromscripttype, &fromxxx);
1263 while (*bufptr !=
' ') bufptr++;
1264 while (*bufptr ==
' ') bufptr++;
1269 sscanf(bufptr,
"%u", (
unsigned int *)&tofieldNode);
1272 x = fieldTemp; ftlen = 0;
1275 while (*bufptr !=
' ') bufptr++;
1276 while (*bufptr ==
' ') bufptr++;
1279 while ((*bufptr >
' ') && (ftlen <1000)) { *x = *bufptr; x++; bufptr++; ftlen++;}
1283 EAI_GetType (tofieldNode, fieldTemp,
"inputOnly", &toretNode, &toretField, &todataLen, &tofieldType, &toscripttype, &toxxx);
1285 if (eaiverbose) printf (
"so, we are routing from %d:%d to %d:%d, fieldtypes %d:%d, datalen %d:%d\n",
1286 fromretNode, toretNode, fromretField,
1287 toretField, fromfieldType,tofieldType, fromdataLen,todataLen);
1290 rv= ((fromfieldType==tofieldType) &&(fromfieldType != -1));
1295 fromNode = (
struct X3D_Node*) getEAINodeFromTable(fromretNode,fromretField);
1296 toNode = (
struct X3D_Node*) getEAINodeFromTable(toretNode,toretField);
1297 fromOffset = getEAIActualOffset((
int)fromretNode,fromretField);
1298 toOffset = getEAIActualOffset(toretNode,toretField);
1301 if (
command == ADDROUTE) CRoutes_RegisterSimple(fromNode,fromOffset,toNode,toOffset,fromfieldType);
1302 else CRoutes_RemoveSimple(fromNode,fromOffset,toNode,toOffset,fromfieldType);
1312static void makeFIELDDEFret(
int myptr,
int repno) {
1321 char utilBuf[EAIREADSIZE];
1325 struct tEAIHelpers *th = &tg->EAIHelpers;
1326 eaiverbose = tg->EAI_C_CommonFunctions.eaiverbose;
1328 memset(utilBuf,
'\0',
sizeof(utilBuf));
1330 boxptr = getEAINodeFromTable(myptr,-1);
1333 printf (
"GETFIELDDEFS, node %u -> %p\n",(
unsigned int)myptr, boxptr);
1337 printf (
"makeFIELDDEFret have null node here \n");
1338 sprintf (th->outBuffer,
"RE\n%f\n%d\n0",TickTime(),repno);
1342 printf (
"node type is %s\n",stringNodeType(boxptr->_nodeType));
1345 np = (
int *) NODE_OFFSETS[boxptr->_nodeType];
1349 if (0 != strncmp(stringFieldType(np[0]),
"_", 1) ) {
1351 ctmp = (char) mapFieldTypeToEAItype(np[2]) ;
1352 dtmp = mapEAItypeToFieldType(ctmp) ;
1354 tmpptr = offsetPointer_deref (
char *, boxptr,np[1]);
1355 printf(
"%s,%d ",__FILE__,__LINE__) ;
1356 printf(
"Field %d %s , ", myc, stringFieldType(np[0])) ;
1357 printf(
"offset=%d bytes , ", np[1]) ;
1359 printf(
"field_type= %c (%d) , ", ctmp , dtmp) ;
1360 printf(
"Routing=%s , ", stringKeywordType(np[3])) ;
1361 printf(
"Spec=%d , ", np[4]) ;
1363 errcount = UtilEAI_Convert_mem_to_ASCII (dtmp,tmpptr, utilBuf);
1364 if (0 == errcount) {
1365 printf (
"\t\tValue = %s\n",utilBuf);
1367 printf (
"\t\tValue = indeterminate....\n");
1372 np += FIELDOFFSET_LENGTH;
1375 sprintf (th->outBuffer,
"RE\n%f\n%d\n",TickTime(),repno);
1384 np = (
int *) NODE_OFFSETS[boxptr->_nodeType];
1387 if (0 != strncmp(stringFieldType(np[0]),
"_", 1) ) {
1392 sprintf (myline,
"\"%s\" ",stringFieldType(np[0])) ;
1393 outBufferCat( myline);
1395 np += FIELDOFFSET_LENGTH;
1409void EAI_RW(
char *str) {
1414 printf(
"EAI replace world, calling kill_oldWorld\n");
1415 kill_oldWorld(FALSE,TRUE,__FILE__,__LINE__);
1419 while ((*str !=
' ') && (strlen(str) > 0)) str++;
1420 while (isspace(*str)) str++;
1421 while (strlen(str) > 0) {
1422 i = sscanf (str,
"%u",(
unsigned int *)&newNode);
1425 AddRemoveChildren (X3D_NODE(rootNode()),offsetPointer_deref(
void*,rootNode(),offsetof (
struct X3D_Group, children)),&newNode,1,1,__FILE__,__LINE__);
1427 while (isdigit(*str)) str++;
1428 while (isspace(*str)) str++;
1434void createLoadURL(
char *bufptr) {
1435 #define strbrk " :loadURLStringBreak:"
1445 p->EAI_AnchorNode.description = newASCIIString(
"From EAI");
1448 while (*bufptr==
' ') bufptr++;
1449 retint=sscanf (bufptr,
"%d",&p->EAI_AnchorNode.url.n);
1450 while (*bufptr>
' ') bufptr++;
1451 while (*bufptr==
' ') bufptr++;
1452 retint=sscanf (bufptr,
"%d",&p->EAI_AnchorNode.parameter.n);
1453 while (*bufptr>
' ') bufptr++;
1454 while (*bufptr==
' ') bufptr++;
1460 if (p->EAI_AnchorNode.url.n > 0) p->EAI_AnchorNode.url.p = MALLOC(
struct Uni_String **, p->EAI_AnchorNode.url.n * sizeof (
struct Uni_String));
1461 if (p->EAI_AnchorNode.parameter.n > 0) p->EAI_AnchorNode.parameter.p = MALLOC(
struct Uni_String **, p->EAI_AnchorNode.parameter.n * sizeof (
struct Uni_String));
1463 for (count=0; count<p->EAI_AnchorNode.url.n; count++) {
1464 bufptr += strlen(strbrk);
1468 spbrk = strstr(bufptr,strbrk);
1469 if (spbrk!=NULL) *spbrk=
'\0';
1471 p->EAI_AnchorNode.url.p[count] = newASCIIString(bufptr);
1473 if (spbrk!=NULL) bufptr = spbrk;
1475 for (count=0; count<p->EAI_AnchorNode.parameter.n; count++) {
1476 bufptr += strlen(strbrk);
1480 spbrk = strstr(bufptr,strbrk);
1481 if (spbrk!=NULL) *spbrk=
'\0';
1482 if (p->EAI_AnchorNode.parameter.p != NULL)
1484 p->EAI_AnchorNode.parameter.p[count] = newASCIIString(bufptr);
1486 if (spbrk!=NULL) bufptr = spbrk;
1490#if !defined(EXCLUDE_EAI)
1497void EAI_Anchor_Response (
int resp) {
1504 if (p->waiting_for_anchor) {
1505 if (resp) strcpy (myline,
"OK\nRE_EOT");
1506 else strcpy (myline,
"FAIL\nRE_EOT");
1507 fwlio_RxTx_sendbuffer (__FILE__,__LINE__,CHANNEL_EAI,myline);
1509 p->waiting_for_anchor = FALSE;
1512void EAI_Anchor_Response (
int resp) {
1519 p->waiting_for_anchor = FALSE;