| Previous | Menu | Next |
|
The following code listing provides a trivial example of servicing annotation requests. In order to keep the example small, safety checks such as examining API call return values are not performed.
#include <stdio.h>
#ifndef _WIN32
#include <unistd.h> /* for getopt() */
#include <sys/signal.h>
#include <sys/param.h>
#endif
#include <sys/types.h>
#ifndef _WIN32
#include <sys/time.h>
#include <sys/socket.h>
#else
#include <WINSOCK.H>
#include <SIGNAL.H>
#endif
#include <ANNO/ANNO.h>
/* Receive function - handles the incoming
annotation request */
int32
recvFn (
ANNO_ConnectionId annoId,
ANNO_RequestId requestId,
EV_AttrValue *annoRequest
)
{
EV_AttrValue *annoResponse = 0;
char *circuitName = 0;
char *annoNodeName = 0;
int32 seqNum;
/* optional call */
ANNO_getRequestInfo(requestId,
circuitName,
annoNodeName,
&seqNum);
free(circuitName);
free(annoNodeName);
printf("annotate request, circuit=(%s),
node=(%s), seq=(%d)\n",
circuitName, annoNodeName, seqNum);
/* build a response goes here */
/* send response */
ANNO_sendResponse(annoId, requestId,
annoResponse);
}
int
main( int argc, char *argv[] )
{
ESOK_Remote remote;
ESOK_ConnectionId conId= 0;
ANNO_ConnectionId annoId = 0;
int errflg = 0;
int hflag = 0;
char* syntax = NULL;
extern char* optarg;
ESOK_stackInit (); /*manpage*/
ANNO_stackInit (); /*manpage*/
ESOK_open( &remote, &conId ); /*manpage*/
/*manpage*/
ANNO_open (conId, 0, 0, *annoId);
/*manpage*/
ANNO_registerReceiveFn(
annoId,
recvFn);
/* poll once per second until
the connection fails */
/*manpage*/
while (ESOK_process(1000) >= 0);
ANNO_close(annoId); /*manpage*/
ANNO_stackReset(); /*manpage*/
ESOK_close( cid ); /*manpage*/
ESOK_stackReset(); /*manpage*/
"../refs/c/esok_stackReset.htm"
exit (0);
}
|