srv_regdefine

Description

Initiate the process of registering a procedure.

Syntax

CS_RETCODE srv_regdefine(spp, procnamep, 
                    namelen, funcp)
SRV_PROC            *spp;
CS_CHAR              *procnamep;
CS_INT                   namelen;
SRV_EVENTHANDLE_FUNC(*funcp)();

Parameters

spp

A pointer to an internal thread control structure.

procnamep

A pointer to the name of the procedure.

namelen

The length of the procedure name. If the string in *proc_namep is null terminated, namelen can be CS_NULLTERM.

funcp

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. For more information on notification procedure, see “Registered procedures”.

Returns

Table 3-92: Return values (srv_regdefine)

Returns

To indicate

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

Examples

Example 1

#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);
}

Usage

See also

srv_regcreate, srv_regdrop, srv_reglist, srv_regparam