next up previous contents
Next: Initialising the device Up: Objects In C Previous: Source (.c) code

The device class C structure

In OIC each device class is represented by a C structure. Understanding this structure is vital to understanding OIC. This section will describe the various components of the class structure. The next section will describe how they should be initialised.

Each class structure is made up of a number of fields (cf. figure 3). Each of these fields is in itself a structure, called a partial structure. Each device class defines (in the private include file) its own partial structure. The partial structure contains all data which are common to all members of that class.

A class hierarchy is defined by the hierarchy of partial structures. For example if a class Z contains the partial structures X, Y and Z (in that order) then one knows that it belongs to the root class X, is a member of the subclass Y and is itself the class Z. Because all device classes are members of the root class DevServerClass, the first partial structure of any device class must be the DevServerClass partial structure, DevServerClassPart.

The DevServerClassPart plays a very special role in the implementation of OIC. It defines the fields necessary for implementing and inheriting methods. This is a fundamental part of OIC because the Objects In C method finder depends completely on the first partial structure of every class structure being of type DevServerClassPart.

The fact that the DevServerClass has a dual purpose i.e. implementing methods in OIC and device access can be confusing. The reasons for this are (as usual) historical. These two functions could have been implemented separatelygif. In OIC this has not been done and device server programmers have to be aware of this. The implications of this are that today only one root class exists - the DevServerClass, and that OIC is used only to implement device servers.

In the same way that the first partial structure of any device class has to be the root class (DevServerClass) so the device classes own partial structure should be the last partial structure. All partial structures in between should be in hierarchical order of the superclasses of the class.

A copy of each device classes C structure is created (space is reserved and it is initialised) once in every program where the device class is used. The structure has the same name as the device classes structure type except that the first character is a small letter. For example the class AGPowerSupplyClass has the device class structure type AGPowerSupplyClassRec whereas the copy of the device class structure is called aGPowerSupplyClassRec.

For each device class structure there is a corresponding device class. The device class is a pointer to the copy of the class structuregif. The same convention is followed for the device class as for device class structure. For example for the device class type AGPowerSupplyClass the actual device class (which must begin with a small letter) is aGPowerSupplyClass. A program which wants to instantiate a device of a certain class or wants to use a device class as one of its superclasses uses the pointer to the copy (the one which starts with a small letter) of the device class ( aGPowerSupplyClass in this example). The device class pointer is defined as external in the public include file and defined and initialised in the .c source code file which implements the device class. Referring to the class pointer in a program forces the loader to link the object code for the class being referred to with the program. This simple but efficient mechanism allows classes to be linked with a program without referring to any of the class source code.

  
Figure 3: The device class structure for the AGPowerSupplyClass, a class with three levels of hierarchy. This diagram demonstrates the organisation of the partial structures of each class. It should be noted that each class structure has its own (initialised) copy of the DevServerPart. Note also that aGPowerSupplyClass has an (uninitialised) copy of PowerSupplyClassPart.



next up previous contents
Next: Initialising the device Up: Objects In C Previous: Source (.c) code



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