Initiate the process of registering a procedure.
CS_RETCODE srv_regdefine(spp, procnamep,
namelen, funcp)
SRV_PROC *spp; CS_CHAR *procnamep; CS_INT namelen; SRV_EVENTHANDLE_FUNC(*funcp)();
A pointer to an internal thread control structure.
A pointer to the name of the procedure.
The length of the procedure name. If the string in *proc_namep is null terminated, namelen can be CS_NULLTERM.
A pointer to the function to be called each time the procedure is executed. Setting this parameter to null registers a “notification” procedure. Notification procedures are useful for inter-client communication. See “Registered procedures”.
Returns |
To indicate |
---|---|
CS_SUCCEED |
The routine completed successfully. |
CS_FAIL |
The routine failed. |
#include <ospublic.h>
#include <stdio.h>
/*
** Local Prototype.
*/
CS_RETCODE ex_srv_regdefine PROTOTYPE((
SRV_SERVER *server
));
CS_RETCODE stop_serv PROTOTYPE((
SRV_PROC *spp
));
/*
** Local defines.
*/
#define STOP_SERV “stop_serv”
/*
** STOP_SERV
** This function is called when the client sends the stop_serv
** registered procedure.
**
** Arguments:
** spp A pointer to internal thread control structure.
**
** Returns:
** SRV_CONTINUE
*/
CS_INT stop_serv(spp)
SRV_PROC *spp;
{
/* Queue a SRV_STOP event. */
(CS_VOID)srv_log((SRV_SERVER *)NULL, CS_TRUE,
“Stopping Server\n”, CS_NULLTERM);
/* Send a final DONE to client to acknowledge the command. */
if (srv_senddone(spp, SRV_DONE_FINAL, CS_TRAN_UNDEFINED,
(CS_INT)0)
== CS_FAIL)
{
fprintf(stderr, “srv_senddone failed\n”);
}
/* Queue a SRV_STOP event to shut down the server. */
if (srv_event(spp, SRV_STOP, (CS_VOID *)NULL)
== CS_FAIL)
{
fprintf(stderr, “Error queuing SRV_STOP event\n”);
}
return (SRV_CONTINUE);
}
/*
** EX_SRV_REGDEFINE
**
** Example routine to illustrate the use of srv_regdefine to
** register a procedure.
**
** Arguments:
** server A pointer to the Open Server control structure.
**
** Returns:
**
** CS_SUCCEED If procedure was registered successfully.
** CS_FAIL If an error occurred in registering the
** procedure.
*/
CS_RETCODE ex_srv_regdefine (server)
SRV_SERVER *server;
{
SRV_PROC *spp;
CS_INT info;
/* Create a thread. */
spp = srv_createproc(server);
if (spp == (SRV_PROC *)NULL)
return (CS_FAIL);
/* Define the procedure. */
if (srv_regdefine(spp, STOP_SERV, CS_NULLTERM, stop_serv)
== CS_FAIL)
return (CS_FAIL);
/* Complete the registration. */
if (srv_regcreate(spp, &info) == CS_FAIL)
return (CS_FAIL);
/*
** Terminate the thread created here. We do not care about
** the return code from srv_termproc here.
*/
(CS_VOID)srv_termproc(spp);
return (CS_SUCCEED);
}
srv_regdefine is the first step in the process of registering a procedure. Once it is registered, a procedure can be invoked by clients or from within the Open Server application program.
After calling srv_regdefine, define the procedure’s parameters with srv_regparam.
Complete the processing of registering the procedure by calling srv_regcreate.
If a registered procedure exists with a name identical to the one in procnamep, the error is detected and reported when srv_regcreate is called.
All requested procedures should return SRV_CONTINUE.