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]
101 static void makeFIELDDEFret(
int,
int);
102 static void handleRoute (
char command,
char *bufptr,
int repno);
103 static void handleGETNODE (
char *bufptr,
int repno);
104 static void handleGETNODEPARENTS (
char *bufptr,
int repno);
105 static void handleGETROUTES (
char *bufptr,
int repno);
106 static void handleGETEAINODETYPE (
char *bufptr,
int repno);
107 extern void dump_scene (FILE *fp,
int level,
struct X3D_Node* node);
131 int waiting_for_anchor;
134 void *EAIEventsIn_constructor()
140 void EAIEventsIn_init(
struct tEAIEventsIn* t)
146 t->prv = EAIEventsIn_constructor();
149 p->waiting_for_anchor = FALSE;
161 pthread_mutex_t eaibufferlock;
164 void *EAICore_constructor()
166 void *v = MALLOC(
void *,
sizeof(
struct pEAICore));
167 memset(v,0,
sizeof(
struct pEAICore));
170 void EAICore_init(
struct tEAICore* t){
172 t->prv = EAICore_constructor();
175 pthread_mutex_init(&(p->eaibufferlock), NULL);
178 t->EAIbufsize = EAIREADSIZE ;
181 struct X3D_Anchor* get_EAIEventsIn_AnchorNode()
184 return (
struct X3D_Anchor*)&p->EAI_AnchorNode;
187 #if !defined(EXCLUDE_EAI)
188 int 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));
202 char * 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 ;
231 char * 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) ;
313 char * fwl_EAI_handleBufferNoSKT(
char *fromFront)
315 return EAI_handleBuffer(fromFront,
false);
318 char * fwl_EAI_handleBuffer(
char *fromFront) {
319 return EAI_handleBuffer(fromFront,
true);
358 void 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++;
440 command = EAI_BUFFER_CUR;
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);
588 if (command == CREATEVS || command == CREATEXS) {
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);
631 if(command==CREATEVS)
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);
725 printf (
"REGLISTENER, calling getEAINodeFromTable(%d, %d)\n",tmp_a,tmp_b);
726 node = getEAINodeFromTable(tmp_a, tmp_b);
727 printf (
"REGLISTENER, calling getEAIActualOffset(%d, %d)\n",tmp_a,tmp_b);
728 offset = getEAIActualOffset(tmp_a, tmp_b);
729 printf (
"REGLISTENER, have node %p, offset %d (%s)\n",node,offset, stringNodeType(node->_nodeType));
730 printf (
"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;
779 printf (
"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: {
797 int directionFlag = 0;
800 retint=sscanf (&EAI_BUFFER_CUR,
"%d %d %c %d",&tmp_a,&tmp_b,ctmp,&tmp_c);
801 node = getEAINodeFromTable(tmp_a,tmp_b);
802 offset = getEAIActualOffset(tmp_a,tmp_b);
804 if (node->_nodeType == NODE_Script) {
808 sp = (
struct Shader_Script *) (X3D_SCRIPT(node)->__scriptObj);
815 node = offsetPointer_deref(
struct X3D_Node *,0,sp->num);
816 directionFlag = FROM_SCRIPT;
822 if (eaiverbose) printf (
"UNREGISTERLISTENER from %p foffset %d fieldlen %d type %s \n",
823 node, offset ,tmp_c,ctmp);
829 CRoutes_Register (0,node, offset, NULL, 0, (
int) tmp_c,(
void *)
830 &EAIListener, directionFlag, (count<<8)+mapEAItypeToFieldType(ctmp[0]));
832 sprintf (th->outBuffer,
"RE\n%f\n%d\n0",TickTime(),count);
837 handleEAIGetValue(command, &EAI_BUFFER_CUR,count);
841 EAI_RW(&EAI_BUFFER_CUR);
842 sprintf (th->outBuffer,
"RE\n%f\n%d\n0",TickTime(),count);
847 sprintf (th->outBuffer,
"RE\n%f\n%d\n%s",TickTime(),count,SAI_StrRetCommand ((
char) command,&EAI_BUFFER_CUR));
855 printf (
"SV int ret command ..%s\n",&EAI_BUFFER_CUR);
857 sprintf (th->outBuffer,
"RE\n%f\n%d\n%d",TickTime(),count,
858 SAI_IntRetCommand ((
char) command,&EAI_BUFFER_CUR));
863 handleRoute (command, &EAI_BUFFER_CUR,count);
868 if (!RUNNINGASPLUGIN) {
869 fwl_doQuit(__FILE__,__LINE__);
875 if (!strncmp(&EAI_BUFFER_CUR,
" NEXT",5)) fwl_Next_ViewPoint();
876 if (!strncmp(&EAI_BUFFER_CUR,
" FIRST",6)) fwl_First_ViewPoint();
877 if (!strncmp(&EAI_BUFFER_CUR,
" LAST",5)) fwl_Last_ViewPoint();
878 if (!strncmp(&EAI_BUFFER_CUR,
" PREV",5)) fwl_Prev_ViewPoint();
880 sprintf (th->outBuffer,
"RE\n%f\n%d\n0",TickTime(),count);
886 p->waiting_for_anchor = TRUE;
889 createLoadURL(&EAI_BUFFER_CUR);
893 sprintf (th->outBuffer,
"RE\n%f\n%d\n",TickTime(),count);
910 setAnchorsAnchor( get_EAIEventsIn_AnchorNode());
911 tg->RenderFuncs.BrowserAction = TRUE;
919 while ((EAI_BUFFER_CUR!=0) && (EAI_BUFFER_CUR <=
' ')) bufPtr++;
920 while (EAI_BUFFER_CUR >
' ') { ctmp[rb] = EAI_BUFFER_CUR; rb ++; bufPtr++; }
924 printf (
"CREATENODE/PROTO %s\n",ctmp);
928 sprintf (th->outBuffer,
"RE\n%f\n%d\n",TickTime(),count);
930 retGroup = createNewX3DNode(NODE_Group);
931 if (command == CREATENODE) {
933 printf (
"CREATENODE, %s is this a simple node? %d\n",ctmp,findFieldInNODES(ctmp));
936 ctype = findFieldInNODES(ctmp);
939 sprintf (ctmp,
"%ld",(
long int) createNewX3DNode(ctype));
944 ra = EAI_CreateVrml(
"CREATENODE",ctmp,rootNode(),retGroup);
946 }
else if (command == CREATEPROTO)
947 ra = EAI_CreateVrml(
"CREATEPROTO",ctmp,rootNode(),retGroup);
949 printf (
"eai - huh????\n");
952 for (rb = 0; rb < retGroup->children.n; rb++) {
953 sprintf (ctmp,
"%ld ", (
long int) retGroup->children.p[rb]);
955 printf (
"Possible EAI problem, children of container group should have this parent removed\n");
960 markForDispose(X3D_NODE(retGroup),FALSE);
966 sscanf (&EAI_BUFFER_CUR,
"%d",&ra);
967 makeFIELDDEFret(ra,count);
971 case GETNODEDEFNAME: {
973 sprintf (th->outBuffer,
"RE\n%f\n%d\n%s",TickTime(),count,
974 SAI_StrRetCommand ((
char) command,&EAI_BUFFER_CUR));
980 handleGETNODEPARENTS(&EAI_BUFFER_CUR,count);
985 printf (
"unhandled command :%c: %d\n",command,command);
986 outBufferCat(
"unknown_EAI_command");
993 while (EAI_BUFFER_CUR >=
' ') bufPtr++;
995 while ((EAI_BUFFER_CUR == 10) || (EAI_BUFFER_CUR == 13)) bufPtr++;
998 printf (
"end of command, remainder %d chars ",(
int)strlen(&EAI_BUFFER_CUR));
1000 printf (
"and :%s: thread %lu\n",(&EAI_BUFFER_CUR),(
unsigned long) pthread_self().p);
1002 printf (
"and :%s: thread %lu\n",(&EAI_BUFFER_CUR),(
unsigned long) pthread_self());
1006 if (command == SENDEVENT ) {
1008 th->outBuffer[0] = 0;
1011 if (command != LOADURL) outBufferCat(
"\nRE_EOT");
1014 tg->EAICore.EAIbufpos = bufPtr;
1020 static void handleGETROUTES (
char *bufptr,
int repno) {
1028 struct tEAIHelpers* th = &gglobal()->EAIHelpers;
1030 sprintf (th->outBuffer,
"RE\n%f\n%d\n",TickTime(),repno);
1032 numRoutes = getRoutesCount();
1034 if (numRoutes < 2) {
1040 sprintf (ctmp,
"%d ",numRoutes-2);
1044 for (count = 1; count < (numRoutes-1); count++) {
1045 getSpecificRoute (count,&fromNode, &fromOffset, &toNode, &toOffset);
1047 sprintf (ctmp,
"%p %s %p %s ",fromNode,
1048 findFIELDNAMESfromNodeOffset(fromNode,fromOffset),
1050 findFIELDNAMESfromNodeOffset(toNode,toOffset)
1059 static void handleGETNODE (
char *bufptr,
int repno) {
1062 struct tEAIHelpers* th;
1065 eaiverbose = tg->EAI_C_CommonFunctions.eaiverbose;
1066 th = &tg->EAIHelpers;
1071 retint=sscanf (bufptr,
" %s",ctmp);
1074 printf (
"GETNODE %s\n",ctmp);
1078 if (strcmp(ctmp,SYSTEMROOTNODE)) {
1079 sprintf (th->outBuffer,
"RE\n%f\n%d\n%d",TickTime(),repno, EAI_GetNode(ctmp));
1082 sprintf (th->outBuffer,
"RE\n%f\n%d\n%d",TickTime(),repno, EAI_GetRootNode());
1085 printf (
"GETNODE returns %s\n",th->outBuffer);
1089 static void handleGETNODEPARENTS (
char *bufptr,
int repno)
1093 char buffer[EAIREADSIZE];
1094 struct tEAIHelpers* th;
1102 eaiverbose = tg->EAI_C_CommonFunctions.eaiverbose;
1103 th = &tg->EAIHelpers;
1109 sscanf(bufptr,
"%d",&nodeHandle);
1112 printf (
"GETNODEPARENTS %d\n",nodeHandle);
1115 result = EAI_GetNodeParents(nodeHandle,&parentArray);
1117 snprintf(buffer,EAIREADSIZE,
"RE\n%f\n%d\n",TickTime(),repno);
1121 for(index = 0; index < result; index++)
1123 snprintf(parentAdr,10,
"%d ",parentArray[index]);
1124 strncat(buffer,parentAdr,strlen(parentAdr));
1129 snprintf(parentAdr,10,
"%d ",result);
1130 strncat(buffer,parentAdr,strlen(parentAdr));
1133 outBufferCat(buffer);
1136 printf (
"GETNODE returns %s\n",th->outBuffer);
1145 static void handleGETEAINODETYPE (
char *bufptr,
int repno) {
1151 struct tEAIHelpers *th = &gglobal()->EAIHelpers;
1154 wlen=sscanf (bufptr,
" %d",&nodeHandle);
1155 if (wlen != 1) ConsoleMessage (
"handleGETEAINODETYPE - expected to handle 1 number, got %d",wlen);
1157 myNode = getEAINodeFromTable(nodeHandle,-1);
1159 if (myNode == NULL) {
1160 printf (
"Internal EAI error, node %d not found\n",nodeHandle);
1161 sprintf (th->outBuffer,
"RE\n%f\n%d\n__UNDEFINED __UNDEFINED",TickTime(),repno);
1168 if (isProto(myNode)) {
1169 myNT = parser_getPROTONameFromNode(myNode);
1174 myNT = (
char *) stringNodeType(myNode->_nodeType);
1181 cptr = X3DParser_getNameFromNode(myNode);
1185 sprintf (th->outBuffer,
"RE\n%f\n%d\n%s %s",TickTime(),repno,myNT, cptr);
1190 cptr= parser_getNameFromNode(myNode);
1195 sprintf (th->outBuffer,
"RE\n%f\n%d\n\"%s\" \"%s\"",TickTime(),repno,myNT, cptr);
1201 sprintf (th->outBuffer,
"RE\n%f\n%d\n%s __UNDEFINED",TickTime(),repno,myNT);
1206 static void handleRoute (
char command,
char *bufptr,
int repno) {
1209 char fieldTemp[2000];
1210 int fromOffset, toOffset;
1211 int fromfieldType, fromfieldNode, fromretNode, fromretField, fromdataLen;
1214 int tofieldNode, toretNode, toretField, todataLen, tofieldType;
1222 struct tEAIHelpers *th = &gglobal()->EAIHelpers;
1223 eaiverbose = gglobal()->EAI_C_CommonFunctions.eaiverbose;
1228 sprintf (th->outBuffer,
"RE\n%f\n%d\n",TickTime(),repno);
1230 if (eaiverbose) printf (
"handleRoute, string %s\n",bufptr);
1235 while (*bufptr ==
' ') bufptr++;
1238 sscanf(bufptr,
"%u", (
unsigned int *)&fromfieldNode);
1241 x = fieldTemp; ftlen = 0;
1244 while (*bufptr !=
' ') bufptr++;
while (*bufptr ==
' ') bufptr++;
1247 while ((*bufptr >
' ') && (ftlen <1000)) { *x = *bufptr; x++; bufptr++; ftlen++;}
1251 EAI_GetType (fromfieldNode, fieldTemp,
"outputOnly", &fromretNode, &fromretField, &fromdataLen, &fromfieldType, &fromscripttype, &fromxxx);
1255 while (*bufptr !=
' ') bufptr++;
while (*bufptr ==
' ') bufptr++;
1260 sscanf(bufptr,
"%u", (
unsigned int *)&tofieldNode);
1263 x = fieldTemp; ftlen = 0;
1266 while (*bufptr !=
' ') bufptr++;
while (*bufptr ==
' ') bufptr++;
1269 while ((*bufptr >
' ') && (ftlen <1000)) { *x = *bufptr; x++; bufptr++; ftlen++;}
1273 EAI_GetType (tofieldNode, fieldTemp,
"inputOnly", &toretNode, &toretField, &todataLen, &tofieldType, &toscripttype, &toxxx);
1275 if (eaiverbose) printf (
"so, we are routing from %d:%d to %d:%d, fieldtypes %d:%d, datalen %d:%d\n",
1276 fromretNode, toretNode, fromretField,
1277 toretField, fromfieldType,tofieldType, fromdataLen,todataLen);
1280 rv= ((fromfieldType==tofieldType) &&(fromfieldType != -1));
1285 fromNode = (
struct X3D_Node*) getEAINodeFromTable(fromretNode,fromretField);
1286 toNode = (
struct X3D_Node*) getEAINodeFromTable(toretNode,toretField);
1287 fromOffset = getEAIActualOffset((
int)fromretNode,fromretField);
1288 toOffset = getEAIActualOffset(toretNode,toretField);
1291 if (command == ADDROUTE) CRoutes_RegisterSimple(fromNode,fromOffset,toNode,toOffset,fromfieldType);
1292 else CRoutes_RemoveSimple(fromNode,fromOffset,toNode,toOffset,fromfieldType);
1302 static void makeFIELDDEFret(
int myptr,
int repno) {
1311 char utilBuf[EAIREADSIZE];
1315 struct tEAIHelpers *th = &tg->EAIHelpers;
1316 eaiverbose = tg->EAI_C_CommonFunctions.eaiverbose;
1318 memset(utilBuf,
'\0',
sizeof(utilBuf));
1320 boxptr = getEAINodeFromTable(myptr,-1);
1323 printf (
"GETFIELDDEFS, node %u -> %p\n",(
unsigned int)myptr, boxptr);
1327 printf (
"makeFIELDDEFret have null node here \n");
1328 sprintf (th->outBuffer,
"RE\n%f\n%d\n0",TickTime(),repno);
1332 printf (
"node type is %s\n",stringNodeType(boxptr->_nodeType));
1335 np = (
int *) NODE_OFFSETS[boxptr->_nodeType];
1339 if (0 != strncmp(stringFieldType(np[0]),
"_", 1) ) {
1341 ctmp = (char) mapFieldTypeToEAItype(np[2]) ;
1342 dtmp = mapEAItypeToFieldType(ctmp) ;
1344 tmpptr = offsetPointer_deref (
char *, boxptr,np[1]);
1345 printf(
"%s,%d ",__FILE__,__LINE__) ;
1346 printf(
"Field %d %s , ", myc, stringFieldType(np[0])) ;
1347 printf(
"offset=%d bytes , ", np[1]) ;
1349 printf(
"field_type= %c (%d) , ", ctmp , dtmp) ;
1350 printf(
"Routing=%s , ", stringKeywordType(np[3])) ;
1351 printf(
"Spec=%d , ", np[4]) ;
1353 errcount = UtilEAI_Convert_mem_to_ASCII (dtmp,tmpptr, utilBuf);
1354 if (0 == errcount) {
1355 printf (
"\t\tValue = %s\n",utilBuf);
1357 printf (
"\t\tValue = indeterminate....\n");
1365 sprintf (th->outBuffer,
"RE\n%f\n%d\n",TickTime(),repno);
1374 np = (
int *) NODE_OFFSETS[boxptr->_nodeType];
1377 if (0 != strncmp(stringFieldType(np[0]),
"_", 1) ) {
1382 sprintf (myline,
"\"%s\" ",stringFieldType(np[0])) ;
1383 outBufferCat( myline);
1394 #endif //EXCLUDE_EAI
1399 void EAI_RW(
char *str) {
1404 printf(
"EAI replace world, calling kill_oldWorld\n");
1405 kill_oldWorld(FALSE,TRUE,__FILE__,__LINE__);
1409 while ((*str !=
' ') && (strlen(str) > 0)) str++;
1410 while (isspace(*str)) str++;
1411 while (strlen(str) > 0) {
1412 i = sscanf (str,
"%u",(
unsigned int *)&newNode);
1415 AddRemoveChildren (X3D_NODE(rootNode()),offsetPointer_deref(
void*,rootNode(),offsetof (
struct X3D_Group, children)),&newNode,1,1,__FILE__,__LINE__);
1417 while (isdigit(*str)) str++;
1418 while (isspace(*str)) str++;
1424 void createLoadURL(
char *bufptr) {
1425 #define strbrk " :loadURLStringBreak:"
1435 p->EAI_AnchorNode.description = newASCIIString(
"From EAI");
1438 while (*bufptr==
' ') bufptr++;
1439 retint=sscanf (bufptr,
"%d",&p->EAI_AnchorNode.url.n);
1440 while (*bufptr>
' ') bufptr++;
1441 while (*bufptr==
' ') bufptr++;
1442 retint=sscanf (bufptr,
"%d",&p->EAI_AnchorNode.parameter.n);
1443 while (*bufptr>
' ') bufptr++;
1444 while (*bufptr==
' ') bufptr++;
1450 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));
1451 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));
1453 for (count=0; count<p->EAI_AnchorNode.url.n; count++) {
1454 bufptr += strlen(strbrk);
1458 spbrk = strstr(bufptr,strbrk);
1459 if (spbrk!=NULL) *spbrk=
'\0';
1461 p->EAI_AnchorNode.url.p[count] = newASCIIString(bufptr);
1463 if (spbrk!=NULL) bufptr = spbrk;
1465 for (count=0; count<p->EAI_AnchorNode.parameter.n; count++) {
1466 bufptr += strlen(strbrk);
1470 spbrk = strstr(bufptr,strbrk);
1471 if (spbrk!=NULL) *spbrk=
'\0';
1472 if (p->EAI_AnchorNode.parameter.p != NULL)
1474 p->EAI_AnchorNode.parameter.p[count] = newASCIIString(bufptr);
1476 if (spbrk!=NULL) bufptr = spbrk;
1480 #if !defined(EXCLUDE_EAI)
1487 void EAI_Anchor_Response (
int resp) {
1494 if (p->waiting_for_anchor) {
1495 if (resp) strcpy (myline,
"OK\nRE_EOT");
1496 else strcpy (myline,
"FAIL\nRE_EOT");
1497 fwlio_RxTx_sendbuffer (__FILE__,__LINE__,CHANNEL_EAI,myline);
1499 p->waiting_for_anchor = FALSE;
1502 void EAI_Anchor_Response (
int resp) {
1509 p->waiting_for_anchor = FALSE;
1511 #endif //EXCLUDE_EAI