224 lines
9.2 KiB
HTML
224 lines
9.2 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="reference" />
|
||
|
<meta name="DC.Title" content="Example: TI-RPC simplified-level service API" />
|
||
|
<meta name="abstract" content="This code example illustrates one of the simplified-level service APIs that are used in developing TI-RPC services." />
|
||
|
<meta name="description" content="This code example illustrates one of the simplified-level service APIs that are used in developing TI-RPC services." />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rzahpservicecode.htm" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="rzahpsimpservice" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>Example: TI-RPC simplified-level service API</title>
|
||
|
</head>
|
||
|
<body id="rzahpsimpservice"><a name="rzahpsimpservice"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Example: TI-RPC simplified-level service API</h1>
|
||
|
<div><p>This code example illustrates one of the simplified-level service
|
||
|
APIs that are used in developing TI-RPC services.</p>
|
||
|
<div class="section"><p>In this code example, notice how each procedure is registered
|
||
|
independently from the rest. At the simplified level, a service might have
|
||
|
multiple procedures, but each one must be registered separately. If the service
|
||
|
is unregistered, all of the procedures are unregistered at once. There is
|
||
|
no method that is provided to unregister an individual procedure while leaving
|
||
|
the remaining procedures intact.</p>
|
||
|
<p>This level is a good choice for services
|
||
|
with a small number of procedures. It is also useful for prototyping a much
|
||
|
larger service by using a limited number of the final procedures. As with
|
||
|
all the service levels, the final call in the service should be to svc_run(),
|
||
|
which goes into Select Wait (waiting for a connection from a client).</p>
|
||
|
<div class="note"><span class="notetitle">Note:</span> By
|
||
|
using the code example, you agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
|
||
|
<pre>#include <stdio.h>
|
||
|
#include <netconfig.h>
|
||
|
#include <rpc/rpc.h>
|
||
|
#include <errno.h>
|
||
|
#include "myapp.h"
|
||
|
int main(int argc, char *argv[]) {
|
||
|
|
||
|
bool_t rslt; /* return value for rpc_call() */
|
||
|
|
||
|
/* unregister any existing copy of this service */
|
||
|
/* (void)svc_unreg(program, version) */
|
||
|
svc_unreg(PROGNUM, VERSNUM);
|
||
|
|
||
|
/* (bool_t)rpc_reg(prognum, versnum, procnum, procname, */
|
||
|
/* xdr_in, xdr_out, nettype) */
|
||
|
rslt = rpc_reg(PROGNUM, VERSNUM, GET_UID, myapp_get_uid,
|
||
|
xdr_wrapstring, xdr_u_int, NETTYPE);
|
||
|
|
||
|
/* check for errors calling rpc_reg() */
|
||
|
if (rslt == FALSE) {
|
||
|
/* print error messages and exit */
|
||
|
fprintf(stderr, "Error calling rpc_reg for %s\n", "GET_UID");
|
||
|
fprintf(stderr, "PROG: %lu\tVERS: %lu\tNET: %s\n",
|
||
|
PROGNUM, VERSNUM, NETTYPE);
|
||
|
/* clean up before exiting */
|
||
|
svc_unreg(PROGNUM, VERSNUM);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
/* (bool_t)rpc_reg(prognum, versnum, procnum, procname, */
|
||
|
/* xdr_in, xdr_out, nettype) */
|
||
|
rslt = rpc_reg(PROGNUM, VERSNUM, GET_UID_STRING, myapp_get_uid_string,
|
||
|
xdr_wrapstring, xdr_wrapstring, NETTYPE);
|
||
|
|
||
|
/* check for errors calling rpc_reg() */
|
||
|
if (rslt == FALSE) {
|
||
|
/* print error messages and exit */
|
||
|
fprintf(stderr, "Error calling rpc_reg for %s\n", "GET_UID_STRING");
|
||
|
fprintf(stderr, "PROG: %lu\tVERS: %lu\tNET: %s\n",
|
||
|
PROGNUM, VERSNUM, NETTYPE);
|
||
|
/* clean up before exiting */
|
||
|
svc_unreg(PROGNUM, VERSNUM);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
/* (bool_t)rpc_reg(prognum, versnum, procnum, procname, */
|
||
|
/* xdr_in, xdr_out, nettype) */
|
||
|
rslt = rpc_reg(PROGNUM, VERSNUM, GET_SIZE, myapp_get_size,
|
||
|
xdr_wrapstring, xdr_int, NETTYPE);
|
||
|
|
||
|
/* check for errors calling rpc_reg() */
|
||
|
if (rslt == FALSE) {
|
||
|
/* print error messages and exit */
|
||
|
fprintf(stderr, "Error calling rpc_reg for %s\n", "GET_SIZE");
|
||
|
fprintf(stderr, "PROG: %lu\tVERS: %lu\tNET: %s\n",
|
||
|
PROGNUM, VERSNUM, NETTYPE);
|
||
|
/* clean up before exiting */
|
||
|
svc_unreg(PROGNUM, VERSNUM);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
/* (bool_t)rpc_reg(prognum, versnum, procnum, procname, */
|
||
|
/* xdr_in, xdr_out, nettype) */
|
||
|
rslt = rpc_reg(PROGNUM, VERSNUM, GET_MTIME, myapp_get_mtime,
|
||
|
xdr_wrapstring, xdr_long, NETTYPE);
|
||
|
|
||
|
/* check for errors calling rpc_reg() */
|
||
|
if (rslt == FALSE) {
|
||
|
/* print error messages and exit */
|
||
|
fprintf(stderr, "Error calling rpc_reg for %s\n", "GET_MTIME");
|
||
|
fprintf(stderr, "PROG: %lu\tVERS: %lu\tNET: %s\n",
|
||
|
PROGNUM, VERSNUM, NETTYPE);
|
||
|
/* clean up before exiting */
|
||
|
svc_unreg(PROGNUM, VERSNUM);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
/* (bool_t)rpc_reg(prognum, versnum, procnum, procname, */
|
||
|
/* xdr_in, xdr_out, nettype) */
|
||
|
rslt = rpc_reg(PROGNUM, VERSNUM, GET_MTIME_STRING, myapp_get_mtime_string,
|
||
|
xdr_wrapstring, xdr_wrapstring, NETTYPE);
|
||
|
|
||
|
/* check for errors calling rpc_reg() */
|
||
|
if (rslt == FALSE) {
|
||
|
/* print error messages and exit */
|
||
|
fprintf(stderr, "Error calling rpc_reg for %s\n", "GET_MTIME_STRING");
|
||
|
fprintf(stderr, "PROG: %lu\tVERS: %lu\tNET: %s\n",
|
||
|
PROGNUM, VERSNUM, NETTYPE);
|
||
|
/* clean up before exiting */
|
||
|
svc_unreg(PROGNUM, VERSNUM);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
/* (bool_t)rpc_reg(prognum, versnum, procnum, procname, */
|
||
|
/* xdr_in, xdr_out, nettype) */
|
||
|
rslt = rpc_reg(PROGNUM, VERSNUM, GET_CODEPAGE, myapp_get_codepage,
|
||
|
xdr_wrapstring, xdr_u_short, NETTYPE);
|
||
|
|
||
|
/* check for errors calling rpc_reg() */
|
||
|
if (rslt == FALSE) {
|
||
|
/* print error messages and exit */
|
||
|
fprintf(stderr, "Error calling rpc_reg for %s\n", "GET_CODEPAGE");
|
||
|
fprintf(stderr, "PROG: %lu\tVERS: %lu\tNET: %s\n",
|
||
|
PROGNUM, VERSNUM, NETTYPE);
|
||
|
/* clean up before exiting */
|
||
|
svc_unreg(PROGNUM, VERSNUM);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
/* (bool_t)rpc_reg(prognum, versnum, procnum, procname, */
|
||
|
/* xdr_in, xdr_out, nettype) */
|
||
|
rslt = rpc_reg(PROGNUM, VERSNUM, GET_OBJTYPE, myapp_get_objtype,
|
||
|
xdr_wrapstring, xdr_wrapstring, NETTYPE);
|
||
|
|
||
|
/* check for errors calling rpc_reg() */
|
||
|
if (rslt == FALSE) {
|
||
|
/* print error messages and exit */
|
||
|
fprintf(stderr, "Error calling rpc_reg for %s\n", "GET_OBJTYPE");
|
||
|
fprintf(stderr, "PROG: %lu\tVERS: %lu\tNET: %s\n",
|
||
|
PROGNUM, VERSNUM, NETTYPE);
|
||
|
/* clean up before exiting */
|
||
|
svc_unreg(PROGNUM, VERSNUM);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
/* (bool_t)rpc_reg(prognum, versnum, procnum, procname, */
|
||
|
/* xdr_in, xdr_out, nettype) */
|
||
|
rslt = rpc_reg(PROGNUM, VERSNUM, GET_FILETYPE, myapp_get_filetype,
|
||
|
xdr_wrapstring, xdr_wrapstring, NETTYPE);
|
||
|
|
||
|
/* check for errors calling rpc_reg() */
|
||
|
if (rslt == FALSE) {
|
||
|
/* print error messages and exit */
|
||
|
fprintf(stderr, "Error calling rpc_reg for %s\n", "GET_FILETYPE");
|
||
|
fprintf(stderr, "PROG: %lu\tVERS: %lu\tNET: %s\n",
|
||
|
PROGNUM, VERSNUM, NETTYPE);
|
||
|
/* clean up before exiting */
|
||
|
svc_unreg(PROGNUM, VERSNUM);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
/* (bool_t)rpc_reg(prognum, versnum, procnum, procname, */
|
||
|
/* xdr_in, xdr_out, nettype) */
|
||
|
rslt = rpc_reg(PROGNUM, VERSNUM, END_SERVER, myapp_end_server,
|
||
|
(xdrproc_t)xdr_void, (xdrproc_t)xdr_void, NETTYPE);
|
||
|
|
||
|
/* check for errors calling rpc_reg() */
|
||
|
if (rslt == FALSE) {
|
||
|
/* print error messages and exit */
|
||
|
fprintf(stderr, "Error calling rpc_reg for %s\n", "END_SERVER");
|
||
|
fprintf(stderr, "PROG: %lu\tVERS: %lu\tNET: %s\n",
|
||
|
PROGNUM, VERSNUM, NETTYPE);
|
||
|
/* clean up before exiting */
|
||
|
svc_unreg(PROGNUM, VERSNUM);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
/* this should loop indefinitely waiting for client connections */
|
||
|
svc_run();
|
||
|
|
||
|
/* if we get here, svc_run() returned */
|
||
|
fprintf(stderr, "svc_run() returned. ERROR has occurred.\n");
|
||
|
fprintf(stderr, "errno: %d\n", errno);
|
||
|
|
||
|
/* clean up by unregistering. then, exit */
|
||
|
svc_unreg(PROGNUM, VERSNUM);
|
||
|
|
||
|
return 1;
|
||
|
|
||
|
} /* end of main() */</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzahpservicecode.htm" title="Transport independent remote procedure call (TI-RPC) programming provides an effective method for developing distributed client-server based applications on i5/OS.">Examples: Develop service applications based on TI-RPC code</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|