next up previous contents index
Next: IO statement Up: External tools Previous: The TSF part

  
The tsfcom library

This section describes the C library tsfcom. It defines the protocol of communication used to implement the external tools.

 - int TsfCom_init(int *argc,char **argv)
 
Initialize the library. Must be called with the arguments given to the program. The arguments used by TsfCom_init are removed from the list. The function returns a non zero value when the initialization fails.
 - int TsfCom_connect(int s,int ms)
 
Open the connection and returns 0 if something goes wrong. When nothing appends after s seconds and ms microseconds then the connection fails and returns a non zero value.

 - int TsfCom_pending(void)
 
Return 1 if an event is waiting else 0.
 - int TsfCom_next_event(TsfComEvent *event)
 

The function does not return before an event occurs. The type of the event is given by event->type among the following values. The function returns a non zero value when an error occurs.

The function returns a non zero value when an error occurs.
 - int TsfCom_close(void)
 
Close the connection. The function returns a non zero value when an error occurs.

 - int TsfCom_send_int(int mesg)
 
Send an integer value (signed 32 bits). The function returns a non zero value when an error occurs. Warning: this function is not yet implemented. So for the moment, send the integer value as a string (see the next function) and cast it to an integer with the TOINT TSF function.

 - int TsfCom_send_string(const char *mesg)
 
Send a string. The function returns a non zero value when an error occurs.

#include <tsfcom.h>

int main(int argc, char **argv)
{
  TsfComEvent event ; 
  char *str ; 

  if (!TsfCom_init(int *argc,char **argv)) 
     error("The TSF arguments are missing\n") ; 
   
  if (!TsfCom_connect())
     error("The connection with TSF has failed\n"); 

  while(1) {
   
    while(!TsfCom_pending())
      do_something_else() ; 
   
    TsfCom_next_event(&event) ; 
    switch(event.type)
     {
       case TSF_RECV_INT: 
        printf("I have received the value %d\n",event.intval) ;
        break ;
       case TSF_RECV_STRING: 
        /* create a copy of the string */ 
        str = malloc(sizeof(char)*strlen(event.stringval)+1) ;
        strcpy(str,event.stringval) ;
        /* print a message */ 
        printf("I have received the string '%s'\n",event.stringval) ;
        /* send the answer */
        if (strcmp(event.stringval,"PI")==0)
          TsfCom_send_string("3.1415") ; 
        else if (strcmp(event.stringval,"SEVEN")==0)
          TsfCom_send_int(7) ; 
        /* Free the memory allocated for the copy*/
        free(str) ;
        break ;
       case TSF_CLOSE: 
        printf("The connection is closed\n") ;
        exit(0) ; 
        break ;
       
     }
  }
}


next up previous contents index
Next: IO statement Up: External tools Previous: The TSF part
Yann Mevel
1999-04-30