83 if(
id < 0)
return 0.0f;
95 if(cptr == NULL)
return -1;
100 if(cptr == NULL || *cptr ==
'\0')
break;
101 if(*cptr !=
',' && *cptr !=
'\"')
103 sscanf(cptr,
"%d",&array[ret++]);
104 cptr = strchr(cptr,
',');
105 if(cptr != NULL) cptr++;
106 if(ret >= nmax)
break;
120 if(cptr == NULL)
return -1;
125 if(cptr == NULL || *cptr ==
'\0')
break;
126 if(*cptr !=
',' && *cptr !=
'\"')
128 sscanf(cptr,
"%f",&array[ret++]);
129 cptr = strchr(cptr,
',');
130 if(cptr != NULL) cptr++;
131 if(ret >= nmax)
break;
145 if(
id < 0)
return NULL;
155 if(
id < 0)
return -1;
165 if(
id < 0)
return -1;
178 if(num <= 0)
return -1;
182 for(ind=0; ind<num; ind++)
184 sprintf(val,
"%d,",array[ind]);
185 if(ipos+(
int)strlen(val) >= nmax)
return -1;
197 if(num <= 0)
return -1;
201 for(ind=0; ind<num; ind++)
203 sprintf(val,
"%f,",array[ind]);
204 if(ipos+(
int)strlen(val) >= nmax)
return -1;
213 if(
id < 0)
return -1;
217 strings[id] =
new char[strlen(str)+1];
227 if(
id < 0)
return -1;
238 if(
id < 0)
return -1;
283 sscanf(interpreter.
line,
"int(%d,%d)",&
id,&ival);
286 else if(interpreter.
isCommand(
"intAndReset("))
288 sscanf(interpreter.
line,
"intAndReset(%d,%d)",&
id,&ival);
293 sscanf(interpreter.
line,
"float(%d,%f)",&
id,&fval);
296 else if(interpreter.
isCommand(
"string("))
298 sscanf(interpreter.
line,
"string(%d,",&
id);
302 else if(interpreter.
isCommand(
"getInt("))
304 sscanf(interpreter.
line,
"getInt(%d)",&
id);
307 else if(interpreter.
isCommand(
"getIntAndReset("))
309 sscanf(interpreter.
line,
"getIntAndReset(%d)",&
id);
312 else if(interpreter.
isCommand(
"getInt0Semaphore("))
316 else if(interpreter.
isCommand(
"getFloat("))
318 sscanf(interpreter.
line,
"getFloat(%d)",&
id);
321 else if(interpreter.
isCommand(
"getString("))
323 sscanf(interpreter.
line,
"getString(%d)",&
id);
325 if(cptr == NULL) socket->
printf(
"stringResult(\"\")\n");
326 else socket->
printf(
"stringResult(\"%s\")\n",cptr);
333 #define CLIENT_TIMEOUT 1000 350 socket->
printf(
"getInt(%d)\n",
id);
375 socket->
printf(
"getFloat(%d)\n",
id);
396 const char *cptr =
getString(socket,
id,&status);
397 if(status != 0)
return -1;
402 if(cptr == NULL || *cptr ==
'\0')
break;
403 if(*cptr !=
',' && *cptr !=
'\"')
405 sscanf(cptr,
"%d",&array[ret++]);
406 cptr = strchr(cptr,
',');
407 if(cptr != NULL) cptr++;
408 if(ret >= nmax)
break;
421 const char *cptr =
getString(socket,
id,&status);
422 if(status != 0)
return -1;
427 if(cptr == NULL || *cptr ==
'\0')
break;
428 if(*cptr !=
',' && *cptr !=
'\"')
430 sscanf(cptr,
"%f",&array[ret++]);
431 cptr = strchr(cptr,
',');
432 if(cptr != NULL) cptr++;
433 if(ret >= nmax)
break;
449 socket->
printf(
"getString(%d)\n",
id);
470 return socket->
printf(
"int(%d,%d)\n",
id,i);
476 return socket->
printf(
"float(%d,%d)\n",
id,f);
484 if(num <= 0)
return -1;
486 sprintf(buf,
"string(%d,\"",
id);
488 for(ind=0; ind<num; ind++)
490 sprintf(val,
"%d,",i[ind]);
491 if(ipos+(
int)strlen(val) >= nmax)
return -1;
496 return socket->
printf(buf);
504 if(num <= 0)
return -1;
506 sprintf(buf,
"string(%d,\"",
id);
508 for(ind=0; ind<num; ind++)
510 sprintf(val,
"%f,",f[ind]);
511 if(ipos+(
int)strlen(val) >= nmax)
return -1;
516 return socket->
printf(buf);
522 return socket->
printf(
"string(%d,\"%d\")\n",
id,str);
531 socket->
printf(
"getIntAndReset(%d)\n",
id);
552 return socket->
printf(
"intAndReset(%d,%d)\n",
id,i);
561 socket->
printf(
"getInt0Semaphore()\n");
563 if(ret == 0) { *status = -2;
return 0; }
584 if(arg == NULL)
return NULL;
600 if(arg == NULL)
return NULL;
602 if(provider_threads == NULL)
return NULL;
609 worker_data.
thread = provider_threads;
630 if(
port <= 0)
return;
631 if(
port >= 256*256)
return;
virtual ~rlDataProviderThreads()
virtual ~rlDataProviderClient()
int setFloat(int id, float f)
int getFloatArray(rlSocket *socket, int id, float *array, int nmax)
int create(void *(*func)(void *), void *argument)
rlSemaphore int0semaphore
int getIntAndReset(int id)
const char * getString(rlSocket *socket, int id, int *status)
static void * rlDataProviderAccept(void *arg)
int readStr(char *buf, int len, int timeout=0)
char cret[rl_PRINTF_LENGTH]
const char * getString(int id)
int setString(int id, const char *str)
int run(rlSocket *socket)
rlDataProviderThreads(int Port, rlDataProvider *Provider)
int setInt(rlSocket *socket, int id, int i)
int setIntArray(rlSocket *socket, int id, int *i, int num)
int isCommand(const char *command)
virtual ~rlDataProvider()
int setIntAndWaitForReset(rlSocket *socket, int id, int i)
int getInt(rlSocket *socket, int id, int *status)
rlInterpreter interpreter
static void * workerThread(void *arg)
int setString(rlSocket *socket, int id, const char *str)
int setInt0Semaphore(int i)
int getIntArray(rlSocket *socket, int id, int *array, int nmax)
int getInt0Semaphore(rlSocket *socket, int *status)
float getFloat(rlSocket *socket, int id, int *status)
rlDataProvider * provider
rlDataProviderThreads * thread
int setIntAndWaitForReset(int id, int i)
void copyStringParam(char *destination, int index)
int setFloat(rlSocket *socket, int id, float f)
int setFloatArray(int id, float *f, int num)
int setIntArray(int id, int *i, int num)
int setInt(int id, int i)
int getFloatArray(int id, float *f, int nmax)
int getIntArray(int id, int *i, int nmax)
int getIntAndReset(rlSocket *socket, int id, int *status)
rlDataProvider(int numInteger, int numFloat=0, int numString=0)
int printf(const char *format,...)
int setFloatArray(rlSocket *socket, int id, float *f, int num)