Classes that can be instantiated require a DevMethodCreate method for creating devices of a device class. A convenience function, ds__create(), exists for calling this method. The DevMethodCreate method has the job of allocating the space for the new device and initialising it with its name and the contents of the template device. The method can also be used to do any other static housekeeping which might be required by the newly created device.
The device create method must have following calling syntax -
static long object_create(char *name, DevServer *ds_ptr, long *error)
Here is an example object create method (for the AGPowerSupplyClass) -
/*====================================================================== Function: static long object_create() Description: create a AGPowerSupply object. This involves allocating memory for this object and initialising its name. Arg(s) In: char *name - name of object. Arg(s) Out: DevServer *ds_ptr - pointer to object created. long *error - pointer to error code (in case of failure) =======================================================================*/ static long object_create(name, ds_ptr, error) char *name; DevServer *ds_ptr; long *error; { AGPowerSupply ps; printf("arrived in object_create(), name %s\n",name); ps = (AGPowerSupply)malloc(sizeof(AGPowerSupplyRec)); /* * initialise server with template */ *(AGPowerSupplyRec*)ps = *(AGPowerSupplyRec*)aGPowerSupply; /* * finally initialise the non-default values */ ps->devserver.name = (char*)malloc(strlen(name)); sprintf(ps->devserver.name,"%s",name); *ds_ptr = (DevServer)ps; printf("leaving object_create() and all OK\n"); return(DS_OK); }