KID User Library Usage


Introduction

In order to handle more than an input data source at a time, the KID user library is handler-based; one handler has to be opened for every input data source in use. Once a valid handler has been returned, the associated data will be delivered until the data source get closed (by the user or by an external event).

For every input data source, the user has to follow the following steps:

  1. obtain a valid handler
  2. retrieve the data using that handler
  3. dispose the handler

See the following paragraphs for a more detailed description of the single steps.


Obtaining a handler

Obtaining a new handler is a very basic operation; only the kid_in_open or the kid_in_try_open function has to be called.

The definition of the kid_in_open and the kid_in_try_open functions are:

where
The return values are:

The difference between the two functions is in the way they treat the error conditions:

An example:

#include <kid_in.h>
...
KID_IN_id handler;
int err;
...
err = kid_in_open("spy:/tmp/B_1_1",&handler);
if (err!=KID_IN_ERROR_OK)
  {
    Print_Error();
    return ERROR;
  }
...
   


During the life of a handler, a user can decide to look at another input data source but still maintain the same handler (for example, a pointer to the handler could be stored in some data structure the user don't want to modify). To do so, the kid_in_switch can be used.

The definition of the kid_in_switch function is:

where

If the function returns KID_IN_ERROR_OK, the handler will point to the new KID URI, else an error occured and the handler will be in an undefined state. (although still valid)


Retrieving the data

Once the user have a valid handler, it can start retrieving data from it.

The functions to use are:

The difference between the three is in the way they return the data found:

The use of one or another function is context dependant; kid_in_get_reference is surelly the fastest one, but can be error prone and requires carfull code planning; kid_in_get_dynamic is the easiest to use, but is also the least efficient. It is up to the user to decide wheater it is worth the pain to use the more efficient ones instead of simplifying the code.

The definition of kid_in_dynamic, kid_in_get_static and kid_in_get_reference functions are:

where If the function returns:

An example

#include <kdata.h>
#include <kid_in.h>

int print_one(KID_IN_id handler)
{
  kevent *event;
  int evsize;
  int err;

  while ((err = kid_in_get_reference(handler,&event,&evsize))==KID_IN_ERROR_EMPTY)
   {
     sleep(1);
   }

  /* Do not consider _AT_START and _AT_END in this example */
  if (err==KID_IN_ERROR_OK)
    {
      print_event(event);
      return OK;
    }
  else
    return ERROR;
}
   


Disposal of a handler

Once an input data source is of no use anymore for the user, he (or she) should dispose the handler, using the kid_in_close function, to free the resources used by it.

The definition of the kid_in_close function is:

where
#include <kid_in.h>
...
KID_IN_id handler;
int err;
...
err = kid_in_open("spy:/tmp/B_1_1",&handler);
if (err==KID_IN_ERROR_OK)
  {
    Do_Whatever_Needed(handler);
    kid_in_close(handler);
  }
...
   


Send comments to: Igor Sfiligoi

Last modified: Fri Sep 8 10:40:07 MET DST