rllib  1
Public Member Functions | Private Attributes | List of all members
rlDataProviderClient Class Reference

#include <rldataprovider.h>

Collaboration diagram for rlDataProviderClient:
Collaboration graph
[legend]

Public Member Functions

 rlDataProviderClient ()
 
virtual ~rlDataProviderClient ()
 
int getInt (rlSocket *socket, int id, int *status)
 
float getFloat (rlSocket *socket, int id, int *status)
 
int getIntArray (rlSocket *socket, int id, int *array, int nmax)
 
int getFloatArray (rlSocket *socket, int id, float *array, int nmax)
 
const char * getString (rlSocket *socket, int id, int *status)
 
int setInt (rlSocket *socket, int id, int i)
 
int setFloat (rlSocket *socket, int id, float f)
 
int setIntArray (rlSocket *socket, int id, int *i, int num)
 
int setFloatArray (rlSocket *socket, int id, float *f, int num)
 
int setString (rlSocket *socket, int id, const char *str)
 
int getIntAndReset (rlSocket *socket, int id, int *status)
 
int setIntAndWaitForReset (rlSocket *socket, int id, int i)
 
int getInt0Semaphore (rlSocket *socket, int *status)
 

Private Attributes

rlInterpreter interpreter
 
char cret [rl_PRINTF_LENGTH]
 

Detailed Description

This class is a client that can access rlDataProvider over TCP.

Definition at line 62 of file rldataprovider.h.

Constructor & Destructor Documentation

◆ rlDataProviderClient()

rlDataProviderClient::rlDataProviderClient ( )

Definition at line 335 of file rldataprovider.cpp.

336 {
337  rlwsa();
338 }
int rlwsa()
Definition: rlsocket.cpp:68

◆ ~rlDataProviderClient()

rlDataProviderClient::~rlDataProviderClient ( )
virtual

Definition at line 340 of file rldataprovider.cpp.

341 {
342 }

Member Function Documentation

◆ getFloat()

float rlDataProviderClient::getFloat ( rlSocket socket,
int  id,
int *  status 
)

Definition at line 368 of file rldataprovider.cpp.

369 {
370  float ret;
371  int iret;
372 
373  *status = -1;
374  if(socket->isConnected() == 0) return 0.0f;
375  socket->printf("getFloat(%d)\n",id);
377  if(iret == 0) // timeout
378  {
379  socket->disconnect();
380  socket->connect();
381  *status = -2;
382  return 0;
383  }
384  if(interpreter.isCommand("floatResult("))
385  {
386  sscanf(interpreter.line,"floatResult(%f)",&ret);
387  *status = 0;
388  return ret;
389  }
390  return 0.0f;
391 }
#define rl_PRINTF_LENGTH
Definition: rldefine.h:71
int readStr(char *buf, int len, int timeout=0)
Definition: rlsocket.cpp:224
int isCommand(const char *command)
rlInterpreter interpreter
#define CLIENT_TIMEOUT
int connect()
Definition: rlsocket.cpp:321
int disconnect()
Definition: rlsocket.cpp:545
int isConnected()
Definition: rlsocket.cpp:559
int printf(const char *format,...)
Definition: rlsocket.cpp:586

◆ getFloatArray()

int rlDataProviderClient::getFloatArray ( rlSocket socket,
int  id,
float *  array,
int  nmax 
)

Definition at line 418 of file rldataprovider.cpp.

419 {
420  int status,ret;
421  const char *cptr = getString(socket,id,&status);
422  if(status != 0) return -1;
423 
424  ret = 0;
425  while(1)
426  {
427  if(cptr == NULL || *cptr == '\0') break;
428  if(*cptr != ',' && *cptr != '\"')
429  {
430  sscanf(cptr,"%f",&array[ret++]);
431  cptr = strchr(cptr,',');
432  if(cptr != NULL) cptr++;
433  if(ret >= nmax) break;
434  }
435  else
436  {
437  cptr++;
438  }
439  }
440  return ret;
441 }
const char * getString(rlSocket *socket, int id, int *status)

◆ getInt()

int rlDataProviderClient::getInt ( rlSocket socket,
int  id,
int *  status 
)

Definition at line 344 of file rldataprovider.cpp.

345 {
346  int ret;
347 
348  *status = -1;
349  if(socket->isConnected() == 0) return 0;
350  socket->printf("getInt(%d)\n",id);
352  if(ret == 0) // timeout
353  {
354  socket->disconnect();
355  socket->connect();
356  *status = -2;
357  return 0;
358  }
359  if(interpreter.isCommand("intResult("))
360  {
361  sscanf(interpreter.line,"intResult(%d)",&ret);
362  *status = 0;
363  return ret;
364  }
365  return 0;
366 }
#define rl_PRINTF_LENGTH
Definition: rldefine.h:71
int readStr(char *buf, int len, int timeout=0)
Definition: rlsocket.cpp:224
int isCommand(const char *command)
rlInterpreter interpreter
#define CLIENT_TIMEOUT
int connect()
Definition: rlsocket.cpp:321
int disconnect()
Definition: rlsocket.cpp:545
int isConnected()
Definition: rlsocket.cpp:559
int printf(const char *format,...)
Definition: rlsocket.cpp:586

◆ getInt0Semaphore()

int rlDataProviderClient::getInt0Semaphore ( rlSocket socket,
int *  status 
)

Definition at line 555 of file rldataprovider.cpp.

556 {
557  int ret;
558 
559  *status = -1;
560  if(socket->isConnected() == 0) return 0;
561  socket->printf("getInt0Semaphore()\n");
562  ret = socket->readStr(interpreter.line,rl_PRINTF_LENGTH-1,CLIENT_TIMEOUT*60*60); // 1 hour timeout
563  if(ret == 0) { *status = -2; return 0; } // timeout
564  if(interpreter.isCommand("intResult("))
565  {
566  sscanf(interpreter.line,"intResult(%d)",&ret);
567  *status = 0;
568  return ret;
569  }
570  return 0;
571 }
#define rl_PRINTF_LENGTH
Definition: rldefine.h:71
int readStr(char *buf, int len, int timeout=0)
Definition: rlsocket.cpp:224
int isCommand(const char *command)
rlInterpreter interpreter
#define CLIENT_TIMEOUT
int isConnected()
Definition: rlsocket.cpp:559
int printf(const char *format,...)
Definition: rlsocket.cpp:586

◆ getIntAndReset()

int rlDataProviderClient::getIntAndReset ( rlSocket socket,
int  id,
int *  status 
)

Definition at line 525 of file rldataprovider.cpp.

526 {
527  int ret;
528 
529  *status = -1;
530  if(socket->isConnected() == 0) return 0;
531  socket->printf("getIntAndReset(%d)\n",id);
533  if(ret == 0) // timeout
534  {
535  socket->disconnect();
536  socket->connect();
537  *status = -2;
538  return 0;
539  }
540  if(interpreter.isCommand("intResult("))
541  {
542  sscanf(interpreter.line,"intResult(%d)",&ret);
543  *status = 0;
544  return ret;
545  }
546  return 0;
547 }
#define rl_PRINTF_LENGTH
Definition: rldefine.h:71
int readStr(char *buf, int len, int timeout=0)
Definition: rlsocket.cpp:224
int isCommand(const char *command)
rlInterpreter interpreter
#define CLIENT_TIMEOUT
int connect()
Definition: rlsocket.cpp:321
int disconnect()
Definition: rlsocket.cpp:545
int isConnected()
Definition: rlsocket.cpp:559
int printf(const char *format,...)
Definition: rlsocket.cpp:586

◆ getIntArray()

int rlDataProviderClient::getIntArray ( rlSocket socket,
int  id,
int *  array,
int  nmax 
)

Definition at line 393 of file rldataprovider.cpp.

394 {
395  int status,ret;
396  const char *cptr = getString(socket,id,&status);
397  if(status != 0) return -1;
398 
399  ret = 0;
400  while(1)
401  {
402  if(cptr == NULL || *cptr == '\0') break;
403  if(*cptr != ',' && *cptr != '\"')
404  {
405  sscanf(cptr,"%d",&array[ret++]);
406  cptr = strchr(cptr,',');
407  if(cptr != NULL) cptr++;
408  if(ret >= nmax) break;
409  }
410  else
411  {
412  cptr++;
413  }
414  }
415  return ret;
416 }
const char * getString(rlSocket *socket, int id, int *status)

◆ getString()

const char * rlDataProviderClient::getString ( rlSocket socket,
int  id,
int *  status 
)

Definition at line 443 of file rldataprovider.cpp.

444 {
445  int ret;
446 
447  *status = -1;
448  if(socket->isConnected() == 0) return NULL;
449  socket->printf("getString(%d)\n",id);
451  if(ret == 0) // timeout
452  {
453  socket->disconnect();
454  socket->connect();
455  *status = -2;
456  return 0;
457  }
458  if(interpreter.isCommand("stringResult("))
459  {
461  *status = 0;
462  return cret;
463  }
464  return NULL;
465 }
#define rl_PRINTF_LENGTH
Definition: rldefine.h:71
int readStr(char *buf, int len, int timeout=0)
Definition: rlsocket.cpp:224
char cret[rl_PRINTF_LENGTH]
int isCommand(const char *command)
rlInterpreter interpreter
#define CLIENT_TIMEOUT
int connect()
Definition: rlsocket.cpp:321
int disconnect()
Definition: rlsocket.cpp:545
int isConnected()
Definition: rlsocket.cpp:559
void copyStringParam(char *destination, int index)
int printf(const char *format,...)
Definition: rlsocket.cpp:586

◆ setFloat()

int rlDataProviderClient::setFloat ( rlSocket socket,
int  id,
float  f 
)

Definition at line 473 of file rldataprovider.cpp.

474 {
475  if(socket->isConnected() == 0) return -1;
476  return socket->printf("float(%d,%d)\n",id,f);
477 }
int isConnected()
Definition: rlsocket.cpp:559
int printf(const char *format,...)
Definition: rlsocket.cpp:586

◆ setFloatArray()

int rlDataProviderClient::setFloatArray ( rlSocket socket,
int  id,
float *  f,
int  num 
)

Definition at line 499 of file rldataprovider.cpp.

500 {
501  char buf[rl_PRINTF_LENGTH],val[100];
502  int nmax,ipos,ind;
503 
504  if(num <= 0) return -1;
505  nmax = rl_PRINTF_LENGTH - strlen("\")\n") - 1;
506  sprintf(buf,"string(%d,\"",id);
507  ipos = strlen(buf);
508  for(ind=0; ind<num; ind++)
509  {
510  sprintf(val,"%f,",f[ind]);
511  if(ipos+(int)strlen(val) >= nmax) return -1;
512  strcat(buf,val);
513  ipos = strlen(buf);
514  }
515  strcat(buf,"\"\n");
516  return socket->printf(buf);
517 }
#define rl_PRINTF_LENGTH
Definition: rldefine.h:71
int printf(const char *format,...)
Definition: rlsocket.cpp:586

◆ setInt()

int rlDataProviderClient::setInt ( rlSocket socket,
int  id,
int  i 
)

Definition at line 467 of file rldataprovider.cpp.

468 {
469  if(socket->isConnected() == 0) return -1;
470  return socket->printf("int(%d,%d)\n",id,i);
471 }
int isConnected()
Definition: rlsocket.cpp:559
int printf(const char *format,...)
Definition: rlsocket.cpp:586

◆ setIntAndWaitForReset()

int rlDataProviderClient::setIntAndWaitForReset ( rlSocket socket,
int  id,
int  i 
)

Definition at line 549 of file rldataprovider.cpp.

550 {
551  if(socket->isConnected() == 0) return -1;
552  return socket->printf("intAndReset(%d,%d)\n",id,i);
553 }
int isConnected()
Definition: rlsocket.cpp:559
int printf(const char *format,...)
Definition: rlsocket.cpp:586

◆ setIntArray()

int rlDataProviderClient::setIntArray ( rlSocket socket,
int  id,
int *  i,
int  num 
)

Definition at line 479 of file rldataprovider.cpp.

480 {
481  char buf[rl_PRINTF_LENGTH],val[100];
482  int nmax,ipos,ind;
483 
484  if(num <= 0) return -1;
485  nmax = rl_PRINTF_LENGTH - strlen("\")\n") - 1;
486  sprintf(buf,"string(%d,\"",id);
487  ipos = strlen(buf);
488  for(ind=0; ind<num; ind++)
489  {
490  sprintf(val,"%d,",i[ind]);
491  if(ipos+(int)strlen(val) >= nmax) return -1;
492  strcat(buf,val);
493  ipos = strlen(buf);
494  }
495  strcat(buf,"\"\n");
496  return socket->printf(buf);
497 }
#define rl_PRINTF_LENGTH
Definition: rldefine.h:71
int printf(const char *format,...)
Definition: rlsocket.cpp:586

◆ setString()

int rlDataProviderClient::setString ( rlSocket socket,
int  id,
const char *  str 
)

Definition at line 519 of file rldataprovider.cpp.

520 {
521  if(socket->isConnected() == 0) return -1;
522  return socket->printf("string(%d,\"%d\")\n",id,str);
523 }
int isConnected()
Definition: rlsocket.cpp:559
int printf(const char *format,...)
Definition: rlsocket.cpp:586

Member Data Documentation

◆ cret

char rlDataProviderClient::cret[rl_PRINTF_LENGTH]
private

Definition at line 82 of file rldataprovider.h.

◆ interpreter

rlInterpreter rlDataProviderClient::interpreter
private

Definition at line 81 of file rldataprovider.h.


The documentation for this class was generated from the following files: