Structure of the program

Much like the client side, the DIET SeD is a library. So the server developer needs to define the main function. Within the main, the DIET server will be launched with a call to diet_SeD which will never return (except if some errors occur, or if a SIGINT or SIGTERM signal is sent to the SeD). The complete server side interface is described in the files DIET_data.h (see Chapter 3) and DIET_server.h found in install_dir/include. Do not forget to include the DIET_server.h (DIET_server.h includes DIET_data.h) at the beginning of your server source code.

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

#include "DIET_server.h"

The second step is to define a function whose prototype is “DIET-normalized” and which will be able to convert the function into the library function prototype. Let us consider a library function with the following prototype:

int service(int arg1, char *arg2, double *arg3);

This function cannot be called directly by DIET, since such a prototype is hard to manipulate dynamically. The user must define a “solve” function whose prototype only consists of a diet_profile_t. This function will be called by the DIET SeD through a pointer.

int solve_service(diet_profile_t *pb)
{
   int    *arg1;
   char   *arg2;
   double *arg3;

   diet_scalar_get(diet_parameter(pb,0), &arg1, NULL);
   diet_string_get(diet_parameter(pb,1), &arg2, NULL);
   diet_scalar_get(diet_parameter(pb,2), &arg3, NULL);
   return service(*arg1, arg2, arg3);
}

Several API functions help the user to write this “solve” function, particularly for getting IN arguments as well as setting OUT arguments.



Subsections
The DIET Team - Mer 29 nov 2017 15:09:02 EST