6 #define LOCK_ADVISE_TABLE printf ("locking advise table\n");
7 #define UNLOCK_ADVISE_TABLE printf ("unlocking advise table\n");
9 #define UNUSED(v) ((void) v) // compiler mitigation
12 int FreeWRL_RegisterNumber;
18 void (*functionHandler)(
X3DNode*, double,
void *arg);
22 int MaxEAIListeners = 0;
26 int X3DAdvise (X3DEventOut *node,
void *fn)
28 return X3DAdviseArg(node, fn, NULL);
31 int X3DAdviseArg (X3DEventOut *node,
void *fn,
void *arg) {
51 if (AdviseIndex >= MaxEAIListeners) {
54 MaxEAIListeners += 100;
55 EAI_ListenerTable = (
struct EAI_ListenerStruct*)realloc (EAI_ListenerTable,
sizeof(*EAI_ListenerTable) * MaxEAIListeners);
60 EAI_ListenerTable[AdviseIndex].type = node->datatype;
61 EAI_ListenerTable[AdviseIndex].FreeWRL_RegisterNumber = _X3D_queryno;
62 EAI_ListenerTable[AdviseIndex].datasize = node->datasize;
64 EAI_ListenerTable[AdviseIndex].dataArea = malloc (
sizeof(
int) + node->datasize);
66 EAI_ListenerTable[AdviseIndex].dataArea = malloc (
sizeof(
int));
67 EAI_ListenerTable[AdviseIndex].functionHandler = fn;
68 EAI_ListenerTable[AdviseIndex].arg = arg;
71 _RegisterListener (node,AdviseIndex);
78 void _handleFreeWRLcallback (
char *line) {
88 if (AdviseIndex < 0)
return;
90 if (strstr(line,
"EV_EOT") == NULL) {
91 printf (
"handle_callback - no eot in string %s\n",line);
94 while ((!isdigit(*line)) && (*line !=
'\0')) line++;
95 sscanf (line,
"%lf",&evTime);
98 while (!iscntrl(*line)) line++;
while (iscntrl(*line)) line++;
99 sscanf (line,
"%d",&evIndex);
102 while (!iscntrl(*line)) line++;
while (iscntrl(*line)) line++;
105 printf (
"event time %lf index %d data :%s:\n",evTime, evIndex, line);
110 while (EAI_ListenerTable[count].FreeWRL_RegisterNumber != evIndex) {
113 if (count > AdviseIndex) {
114 printf (
"hmmm - Advise retval %d >= max %d\n",count,AdviseIndex);
120 if (EAI_ListenerTable[count].datasize != 0) {
121 char *da = EAI_ListenerTable[count].dataArea;
122 Parser_scanStringValueToMem_C(&da[
sizeof(
int)],
123 EAI_ListenerTable[count].type, line, 0);
126 if (EAI_ListenerTable[count].functionHandler != 0) {
128 pnode = (
X3DNode *)EAI_ListenerTable[count].dataArea;
129 pnode->type = EAI_ListenerTable[count].type;
131 EAI_ListenerTable[count].functionHandler(pnode,evTime,EAI_ListenerTable[count].arg);
133 if (_X3D_FreeWRL_Swig_FD) {
135 send(_X3D_FreeWRL_Swig_FD, (
const char *) EAI_ListenerTable[count].FreeWRL_RegisterNumber,
sizeof(EAI_ListenerTable[count].FreeWRL_RegisterNumber),0);
136 send(_X3D_FreeWRL_Swig_FD, (
const char *) EAI_ListenerTable[count].dataArea,
sizeof(EAI_ListenerTable[count].dataArea),0);
143 memcpy(tmp,&(EAI_ListenerTable[count].FreeWRL_RegisterNumber),
146 wc = write(_X3D_FreeWRL_Swig_FD,
149 sizeof(EAI_ListenerTable[count].FreeWRL_RegisterNumber));
153 wc = write(_X3D_FreeWRL_Swig_FD,
154 EAI_ListenerTable[count].dataArea,
155 sizeof(EAI_ListenerTable[count].dataArea));
158 printf(
"no socket connected for callbacks!");