Initial IBM OpenAFS 1.0 tree
[openafs.git] / src / ubik / utst_client.c
1 /*
2  * (C) COPYRIGHT IBM CORPORATION 1987, 1988
3  * LICENSED MATERIALS - PROPERTY OF IBM
4  */
5
6 #include <afs/param.h>
7 #include <sys/types.h>
8 #ifdef AFS_NT40_ENV
9 #include <winsock2.h>
10 #include <afsutil.h>
11 #else
12 #include <sys/file.h>
13 #include <netdb.h>
14 #include <netinet/in.h>
15 #endif
16 #include <time.h>
17 #include <stdio.h>
18 #include <rx/xdr.h>
19 #include <rx/rx.h>
20 #include <lock.h>
21 #include "ubik.h"
22 #include "utst_int.h"
23
24 extern int SAMPLE_Inc(), SAMPLE_Test(), SAMPLE_Get(),
25     SAMPLE_Trun(), SAMPLE_QGet();
26
27 /* main program */
28
29 #include "AFS_component_version_number.c"
30
31 main(argc, argv)
32     int argc;
33     char **argv; {
34     register afs_int32 code;
35     struct ubik_client *cstruct=0;
36     afs_int32 serverList[MAXSERVERS];
37     struct rx_connection *serverconns[MAXSERVERS];
38     struct rx_securityClass *sc;
39     register afs_int32 i;
40     afs_int32 temp;
41
42     if (argc == 1) {
43         printf("uclient: usage is 'uclient -servers ... [-try] [-get] [-inc] [-minc] [-trunc]\n");
44         exit(0);
45     }
46 #ifdef AFS_NT40_ENV 
47     /* initialize winsock */
48      if (afs_winsockInit()<0) 
49         return -1;
50 #endif
51     /* first parse '-servers <server-1> <server-2> ... <server-n>' from command line */
52     code = ubik_ParseClientList(argc, argv, serverList);
53     if (code) {
54         printf("could not parse server list, code %d\n", code);
55         exit(1);
56     }
57     rx_Init(0);
58     sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
59     for (i=0; i<MAXSERVERS; i++) {
60         if (serverList[i]){
61             serverconns[i] = rx_NewConnection(serverList[i], htons(3000),
62                                               USER_SERVICE_ID, sc, 0);
63         } else {
64             serverconns[i] = (struct rx_connection *)0;
65             break;
66         }
67     }
68     
69     /* next, pass list of server rx_connections (in serverconns), and
70      * a place to put the returned client structure that we'll use in
71      * all of our rpc calls (via ubik_Calll) */
72     code = ubik_ClientInit(serverconns, &cstruct);
73
74     /* check code from init */
75     if (code) {
76         printf("ubik client init failed with code %d\n", code);
77         return;
78     }
79     
80     /* parse command line for our own operations */
81     for(i=1;i<argc;i++) {
82         if (!strcmp(argv[i], "-inc")) {
83             /* use ubik_Call to do the work, finding an up server and handling
84                 the job of finding a sync site, if need be */
85             code = ubik_Call(SAMPLE_Inc, cstruct, 0);
86             printf("return code is %d\n", code);
87         }
88         else if (!strcmp(argv[i], "-try")) {
89             code = ubik_Call(SAMPLE_Test, cstruct, 0);
90             printf("return code is %d\n", code);
91         }
92         else if (!strcmp(argv[i], "-qget")) {
93             code = ubik_Call(SAMPLE_QGet, cstruct, 0, &temp);
94             printf("got quick value %d (code %d)\n", temp, code);
95         }
96         else if (!strcmp(argv[i], "-get")) {
97             code = ubik_Call(SAMPLE_Get, cstruct, 0, &temp);
98             printf("got value %d (code %d)\n", temp, code);
99         }
100         else if (!strcmp(argv[i], "-trunc")) {
101             code = ubik_Call(SAMPLE_Trun, cstruct, 0);
102             printf("return code is %d\n", code);
103         }
104        else if (!strcmp(argv[i], "-minc")) {
105          afs_int32 temp; 
106          struct timeval tv; 
107          tv.tv_sec = 1; tv.tv_usec = 0;
108          printf("ubik_client: Running minc...\n");
109          
110          while (1) {
111            temp=0; 
112            code = ubik_Call(SAMPLE_Get, cstruct, 0, &temp); 
113            if (code != 0) {
114              printf("SAMPLE_Inc #1 failed with code %ld\n", code);
115            }
116            else {
117              printf("SAMPLE_Get #1 succeeded, got value %d\n", temp);
118            }
119
120            temp=0; 
121            code = ubik_Call(SAMPLE_Inc, cstruct, 0); 
122            if (code != 0) {
123              printf("SAMPLE_Inc #1 failed with code %ld\n", code);
124            }
125            else {
126              printf("SAMPLE_Inc #1 succeeded, incremented integer\n");
127            }
128            temp=0; 
129            code = ubik_Call(SAMPLE_Get, cstruct, 0, &temp); 
130            if (code != 0) {
131              printf("SAMPLE_Get #2 failed with code %ld\n", code);
132            } 
133            else {
134              printf("SAMPLE_Get #2 succeeded, got value %d\n", temp);
135            }
136                          
137            temp=0; 
138            code = ubik_Call(SAMPLE_Inc, cstruct, 0); 
139            if (code != 0) 
140              printf("SAMPLE_Inc #2 failed with code %ld\n", code);
141            else printf("SAMPLE_Inc #2 succeeded, incremented integer\n");
142                          
143            tv.tv_sec = 1; tv.tv_usec = 0; 
144            IOMGR_Select(0, 0, 0, 0, &tv);
145            printf("Repeating the SAMPLE operations again...\n");
146          } 
147        }
148         else if (!strcmp(argv[i], "-mget")) {
149             afs_int32 temp;
150             struct timeval tv;
151             tv.tv_sec = 1;
152             tv.tv_usec = 0;
153             while (1) {
154                 code = ubik_Call(SAMPLE_Get, cstruct, 0, &temp);
155                 printf("got value %d (code %d)\n", temp, code);
156
157                 code = ubik_Call(SAMPLE_Inc, cstruct, 0);
158                 printf("update return code is %d\n", code);
159
160                 code = ubik_Call(SAMPLE_Get, cstruct, 0, &temp);
161                 printf("got value %d (code %d)\n", temp, code);
162
163                 code = ubik_Call(SAMPLE_Get, cstruct, 0, &temp);
164                 printf("got value %d (code %d)\n", temp, code);
165                 
166                 tv.tv_sec = 1;
167                 tv.tv_usec = 0;
168                 IOMGR_Select(0, 0, 0, 0, &tv);
169             }
170         }
171     }
172 }