next up previous contents
Next: The device C Up: Objects In C Previous: The device class

Initialising the device class structure

Each device class is a subclass of DevServerClass (the root class). This means that the first structure within a device class structure is the partial part of the DevServerClass i.e. DevServerClassPart. DevServerClassPart structure contains :

typedef struct _DevServerClassPart {
   int                  n_methods;       /*number of methods*/
   DevMethodList        methods_list;    /*pointer to list of methods*/
   DevServerClass       superclass;      /*pointer to superclass*/
   DevString            class_name;      /*name of class*/
   DevBoolean           class_inited;    /*flag indicating if class initialised*/
   int                  n_commands;      /*number of commands*/
   DevCommandList       commands_list;   /*pointer to list of commands*/
   DevString            server_name;     /*server name*/
   DevString            host_name;       /*host name*/
   long                 prog_number;     /*NFS/RPC program number of server*/
   long                 vers_number;     /*NFS/RPC version number of server*/
                                  }
               DevServerClassPart;

All device classes have their own copy of this structure pointed to by the class pointer e.g. aGPowerSupplyClass. This is necessary so that each class can have its own list of implemented methods, its own superclass, its own class name, its own class_inited flag and its own commands list. The server name, host name, program number and version number are stored only once - in the DevServerClassPart of the DevServer class.

The n_methods and methods_list are crucial for the implementing of classes. The method_finder (cf. below) uses these two fields to locate the method which will be executed. In order not to be tied down by the definition of the DevServerClassPart structure it was decided very early on in the development of the device servers that these two fields will be the only ones which are initialised at compile time i.e. in static data area. The other fields will be initialised in the class_initialise method by assignment statements. This makes existing code upwards compatible even if the DevServerClassPart structure is reorganised or other fields added to it in the future. The fields n_methods and methods_list have to be initialised with the number of methods and the list of methods in the .c file before any code is executed i.e. at compile and load time.

The following fields of DevServerClassPart are initialised in the class_initialise method -

After initialising the DevServerClassPart the class should initialise its own partial part. Taking the same example as used above - this means initialising AGPowerSupplyClassPart (of the structure pointed to by aGPowerSupplyClass).



next up previous contents
Next: The device C Up: Objects In C Previous: The device class



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