next up previous contents
Next: The device class Up: Objects In C Previous: Public (.h) include

Source (.c) code files

The source code can be divided into two parts (a) the code to implement the device class (e.g. AGPowerSupply.c), and (b) the code to implement the startup procedure. The startup is only required when a server process is being customised. This will be treated in chapter 5.

The source file implementing the device class normally contains the entire code for implementing the device class. The class implementation is private and is meant to be accessed only via the class structure i.e. via its methods. For this reason all functions appearing in this file, especially the class methods and all device server commands are declared as static in C. The source file initialises the class structure defined in the Private include file. The method_list and n_methods variables are initialised by static assignments before load time. All other initialisation is done at runtime - this is more flexible and makes the code upwards compatible.

Here is an example of the header and all related declarations for the AGPowerSupplyClass .c file -

static char RcsId[] = "@(#) $Header: class_header.c.tex,v 1.1 93/04/05 18:16:11 goetz Exp $ ";

/*********************************************************************

 File:         AGPowerSupply.c

 Project:      Device Servers

 Description:  Code for implementing the AG Power Supply class
               The AG Power Supply is a simulation of a typical
               power supply at the ESRF. This means it has two
               main state DEVON and DEVOFF, DEVSTANDBY is unknown.
               All the common power supply commands are implemented.
               The simulation runs under OS9 and Unix. It has been
               developed for application program developers who want to
               test their applications without accessing real devices

 Author(s);    A. Goetz 

 Original:     March 1991

 $Log:	class_header.c.tex,v $
Revision 1.1  93/04/05  18:16:11  18:16:11  goetz (Andy Goetz)
Initial revision

 * Revision 1.1  91/05/02  08:25:31  08:25:31  goetz (Andy Goetz)
 * Initial revision
 * 

 Copyright (c) 1991 by European Synchrotron Radiation Facility, 
                      Grenoble, France



 *********************************************************************/

#include <API.h>
#include <DevServer.h>
#include <DevErrors.h>
#include <DevServerP.h>
#include <PowerSupply.h>
#include <AGPowerSupplyP.h>
#include <AGPowerSupply.h>

/*
 * public methods
 */

static long class_initialise();
static long object_create();
static long object_initialise();
static long state_handler();

static DevMethodListEntry methods_list[] = {
 {DevMethodClassInitialise, class_initialise},
 {DevMethodCreate, object_create},
 {DevMethodInitialise, object_initialise},
 {DevMethodStateHandler, state_handler},
};

AGPowerSupplyClassRec aGPowerSupplyClassRec = {
   /* n_methods */     sizeof(methods_list)/sizeof(DevMethodListEntry),
   /* methods_list */  methods_list,
};

AGPowerSupplyClass aGPowerSupplyClass = 
                   (AGPowerSupplyClass)&aGPowerSupplyClassRec;

/*
 * public commands 
 */

static long dev_off();
static long dev_on();
static long dev_state();
static long dev_setvalue();
static long dev_readvalue();
static long dev_reset();
static long dev_error();
static long dev_local();
static long dev_remote();
static long dev_status();
static long dev_update();

static DevCommandListEntry commands_list[] = {
 {DevOff, dev_off, D_VOID_TYPE, D_VOID_TYPE},
 {DevOn, dev_on, D_VOID_TYPE, D_VOID_TYPE},
 {DevState, dev_state, D_VOID_TYPE, D_SHORT_TYPE},
 {DevSetValue, dev_setvalue, D_FLOAT_TYPE, D_VOID_TYPE},
 {DevReadValue, dev_readvalue, D_VOID_TYPE, D_FLOAT_READPOINT},
 {DevReset, dev_reset, D_VOID_TYPE, D_VOID_TYPE},
 {DevStatus, dev_status, D_VOID_TYPE, D_STRING_TYPE},
 {DevError, dev_error, D_VOID_TYPE, D_VOID_TYPE},
 {DevLocal, dev_local, D_VOID_TYPE, D_VOID_TYPE},
 {DevRemote, dev_remote, D_VOID_TYPE, D_VOID_TYPE},
 {DevUpdate, dev_update, D_VOID_TYPE, D_STATE_FLOAT_READPOINT},
};

static long n_commands = sizeof(commands_list)/sizeof(DevCommandListEntry);

/*
 * a template copy of the default powersupply that normally gets created
 * by the DevMethodCreate. it is initialised in DevMethodCLassInitialise 
 * to default values. these defaults can also be specified in the resource 
 * file or via an admin command.
 */

static AGPowerSupplyRec aGPowerSupplyRec;
static AGPowerSupply aGPowerSupply =
                     (AGPowerSupply)&aGPowerSupplyRec;

/*
 * template resource table used to access the static database
 */
  
   db_resource res_table[] = {
               {"state",D_LONG_TYPE},
               {"set_val",D_FLOAT_TYPE},
               {"channel",D_SHORT_TYPE},
               {"n_ave",D_SHORT_TYPE},
               {"conv_unit",D_STRING_TYPE},
               {"set_offset",D_FLOAT_TYPE},
               {"read_offset",D_FLOAT_TYPE},
               {"set_u_limit",D_FLOAT_TYPE},
               {"set_l_limit",D_FLOAT_TYPE},
               {"polarity",D_SHORT_TYPE},
                             };
   int res_tab_size = sizeof(res_table)/sizeof(db_resource);



Andy Goetz
Tue Jan 28 13:58:13 MET 1997