1 /*
2 * main routine for Visualization Data Explorer outboard modules.
3 *
4 * see below for the comment about defining USERMODULE.
5 * then compile this file and link with libDXlite.a and any other libraries
6 * (-lm, etc) which are necessary.
7 *
8 */
9
10
11
12 #include <dx/dx.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16
17
18 /*
19 * uncomment this next line and substitute your module name here,
20 * or compile this file with the -DUSERMODULE=m_MyModule flag
21 */
22
23 /* #define USERMODULE m_MyModule */
24
25 extern Error USERMODULE (Object *in, Object *out);
26
27 extern int DXConnectToServer (char *host, int port);
28 extern int DXInputAvailable (int dxfd);
29 extern Error DXCallOutboard (Error (*module)(Object *, Object *), int dxfd);
30
31
32
main(int argc,char ** argv)33 main (int argc, char **argv)
34 {
35 int dxfd;
36
37 /*
38 * this program gets called with two arguments: the host name
39 * and socket number which it should connect to.
40 */
41 if (argc != 3) {
42 fprintf (stderr,
43 "error in execution: hostname and port number not set\n");
44 exit (-1);
45 }
46
47 /*
48 * connect to the DX Executive which started the outboard.
49 */
50 dxfd = DXConnectToServer (argv[1], atoi(argv[2]));
51 if (dxfd < 0) {
52 fprintf (stderr, "couldn't connect to socket %d on host %s\n",
53 atoi(argv[2]), argv[1]);
54 exit (-1);
55 }
56
57 /*
58 * while the socket is open, read requests for work, call the
59 * module to execute them, and send the data back.
60 *
61 * if the module is a one-time module, DXCallOutboard closes the
62 * socket. if the module is persistent, the socket remains open.
63 */
64 while(1) {
65
66 if (DXInputAvailable (dxfd) <= 0)
67 break;
68
69 DXCallOutboard (USERMODULE, dxfd);
70
71 }
72
73 close (dxfd);
74 exit (0);
75 }
76
77