Data server that maintains a shared state among processes


ds &

Runs on:

QNX Neutrino




The data server is a process that maintains a shared state among other processes—it's like a global environment. Processes can store or retrieve data using a set of data server library calls. You can use it for many tasks, but specifically you can access it from the Slinger webserver in support of dynamic HTML. The HTTP server, slinger, uses the data server and the data server library.

Data is stored using variable names that represent buffers of data. All of the variables are global, any process can access them (no attempt is made to restrict access), so only one instance of the variable (name) can exist in the data server.

Data server library

The data server library consists of these functions, which are described in the C Library Reference:

Register your application with the data server.
Deregister your application with the data server.
Create a data server variable.
Delete a data server variable.
Set a data server variable.
Get a data server variable.
Set the flags for a data server variable.


Here's a simple (and nonfunctional) example of monitoring the temperature of an oven from a remote client:

Note: This example uses HTML as the interface to the data server, but the data server isn't limited to HTML.

Here's what the qnxvar tokens on the client's web page look like:

<!--Show the current oven temperature-->
<!--#qnxvar format="<P>The oven temperature is %s degrees F." -->
<!--#qnxvar read="oven1 5" -->

If the temperature of the oven is currently 500 degrees F, the output looks like:

<P>The oven temperature is 500 degrees F.

Here's what the application monitoring the oven looks like:

// This program obtains the temperature of an oven, and
// then updates a data variable in the data server, to
// be read by slinger if the appropriate token is in an
// html page slinger is serving. 

#include <stdlib.h>
#include <stdio.h>
#include <ds.h>
#include <string.h>

#define MAXLEN 4

int main(void)
  ds_t ds_descriptor;
  char ovenID[7], oven_temp[MAXLEN], flag=0;
  int length = MAXLEN;

  ds_descriptor = ds_register();

  if(ds_create(ds_descriptor, ovenID, flag, 0)==-1){
  // Obtain the an initial temperature for the oven
  // to initialize the data server variable. strcpy
  // that value into oven_temp 
  //Now let's update the temperature at some time interval

  //you might want some kind of decision to exit the program. 
     //obtain the current temperature from the oven

     //strcpy that temp reading into the oven_temp variable


     //wait a predetermined amount of time



The output HTML page reflects the current temperature stored in the data server.

When this process exits, the data server variable is no longer available because the flag argument passed to ds_create() was 0.

If this application needs some data passed from HTML text, another variable is created by calling ds_create() and is used to pass information to it by using the qnxvar write token in some HTML text. The application gets the data by calling ds_get() and/or react to the change in data by receiving a proxy or signal.

Here's what's happening:

Figure 1. Monitoring an oven via the data server.

In summary:

For information about the qnxvar token, see slinger.