In C all programs have a main() function. It is the first function called at runtime. This is no different for device servers. However because device servers spend most of their lives sleeping waiting for clients to access them (in an NFS/RPC routine called rwait()) the main has to be implemented in a special manner. Rather than providing the user with the source code for the device server main the programmer is given an entry point, the startup() routine, which will be called by the common main.
The startup() has the job of creating all devices of a given class and exporting them onto the network. It can also be used to do global initialisation or other non-standard actions like exporting sub-objects. The startup should return a long status which indicates whether the startup has worked or not. A non-zero status will be interpreted as a failure and the main will do an exit.
The startup function is called by main() with the following syntax -
long startup(char *svr_name, long *error)Where svr_name is the personal name referred to below.
An example is the startup for the AGPowerSupplyClass -
/********************************************************************* File: startup.c Project: Device Servers Description: Startup procedure for AGPowerSupplyClass. The startup procedure is the first procedure called from main() when the device server starts up. All toplevel devices to be created for the device server should be done in startup(). The startup should make use of the database to determine which devices it should create. Initialisation of devices is normally done from startup(). Author(s); A. Goetz Original: March 1991 $Log: startup.c.tex,v $ Revision 1.2 93/04/05 18:16:44 18:16:44 goetz (Andy Goetz) *** empty log message *** Copyright (c) 1990 by European Synchrotron Radiation Facility, Grenoble, France *********************************************************************/ #include <Admin.h> #include <API.h> #include <DevServer.h> #include <DevErrors.h> #include <DevServerP.h> #include <AGPowerSupplyP.h> #include <AGPowerSupply.h> /***************************/ /* AG PowerSupply startup */ /***************************/ long startup(svr_name, error) char *svr_name; long *error; { AGPowerSupply ps_list[MAX_NO_OF_DEVICES]; int i,status; /* * pointer to list of devices returned by database. */ char **dev_list; int dev_no; if (db_getdevlist(svr_name,&dev_list,&dev_no,error)) { printf("startup(): db_getdevlist() failed, error %d\n",*error); break; } else { printf("following devices found in static database \n\n"); for (i=0;i<dev_no;i++) { printf("%s\n",dev_list[i]); } } /* * create, initialise and export all devices served by this server */ for (i=0; i < dev_no; i++) { if (ds__create(dev_list[i], aGPowerSupplyClass, &(ps_list[i]),error) != 0) { break; } /* * initialise the newly created powersupply */ if (ds__method_finder(ps_list[i],DevMethodInitialise)(ps_list[i],error) != 0) { break; } /* * now export it to the outside world */ printf("created %s, going to export it\n",dev_list[i]); if (dev_export(dev_list[i],ps_list[i],error) != 0) { break; } printf("export worked !\n"); } printf("left startup and all's OK\n"); return(DS_OK); }