slave_test.c

A static test example to link against libslave

#include <stdio.h>

#include "slave.h"

/* This propery list is statically encoded into the main program,
 * we don't generate it here from an XML description. */

enum {
        device_dummy,
        id2251236,
        MAXPROP_example // = Number of Properties
};

static
PROPINDEX
g_root_example[] = {
        id2251236,
        INVALID_INDEX
};

static
PropertyDesc
g_props_example[] = {

/* ROOT NODE (always on top of the list!) */

        { "DummyDevice", DC_ROOT,
                F_RO ,
                DC_STATIC, { .base = 0 } , g_root_example },

        { "StaticString" /* id2251236 */,  DC_STRING, 
                F_RW,
                DC_STATIC, { .s_string = "This is a minimal slave server sample" },
                        0 /* no children */ },

        { 0 }
};

/* Properties */

enum {
        g_index_example,

        N_DEVICES
};
        

DeviceDesc g_devices[] = {
        { g_props_example, 0, 0,  MAXPROP_example },
};
        
int g_ndevices = N_DEVICES;

// mingw32 hack: We don't support weak syms, so we don't use these

#ifndef __MINGW32__
/* Must be implemented by user and return device index. Normally 0
 * if only one device definition is used.
 */

TOKEN local_getroot(DEVICE d)
{
        int index = 0;
        return DEVICE_TOKEN(index);
}

#endif

/* We don't need to define device_read() and device_write() functions.
 * They exist in libslave as weak symbols, calling a dummy function.
 */
        
int main(int argc, char **argv)
{
        // Important: Register property list
        const char *devname = NULL;
        register_proplist(g_devices, g_ndevices);

        if (argc == 2) {
                devname = argv[1];
        }
        return start_server(0, NULL);
}


Generated on Thu Feb 24 13:50:16 2011 for Device Control library by  doxygen 1.6.1