Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / ubik / utst_client.c
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12 #include <afs/stds.h>
13
14 #include <roken.h>
15
16 #include <rx/xdr.h>
17 #include <rx/rx.h>
18 #include <lock.h>
19
20 #include "ubik.h"
21 #include "utst_int.h"
22
23 /* main program */
24
25 #include "AFS_component_version_number.c"
26
27 int
28 main(int argc, char **argv)
29 {
30 afs_int32 code;
31 struct ubik_client *cstruct = 0;
32 afs_uint32 serverList[MAXSERVERS];
33 struct rx_connection *serverconns[MAXSERVERS];
34 struct rx_securityClass *sc;
35 afs_int32 i;
36 afs_int32 temp;
37
38 if (argc == 1) {
39 printf
40 ("uclient: usage is 'uclient -servers ... [-try] [-get] [-inc] [-minc] [-trunc]\n");
41 exit(0);
42 }
43 #ifdef AFS_NT40_ENV
44 /* initialize winsock */
45 if (afs_winsockInit() < 0)
46 return -1;
47 #endif
48 /* first parse '-servers <server-1> <server-2> ... <server-n>' from command line */
49 code = ubik_ParseClientList(argc, argv, serverList);
50 if (code) {
51 printf("could not parse server list, code %d\n", code);
52 exit(1);
53 }
54 rx_Init(0);
55 sc = rxnull_NewClientSecurityObject();
56 for (i = 0; i < MAXSERVERS; i++) {
57 if (serverList[i]) {
58 serverconns[i] =
59 rx_NewConnection(serverList[i], htons(3000), USER_SERVICE_ID,
60 sc, 0);
61 } else {
62 serverconns[i] = (struct rx_connection *)0;
63 break;
64 }
65 }
66
67 /* next, pass list of server rx_connections (in serverconns), and
68 * a place to put the returned client structure that we'll use in
69 * all of our rpc calls (via ubik_Calll) */
70 code = ubik_ClientInit(serverconns, &cstruct);
71
72 /* check code from init */
73 if (code) {
74 printf("ubik client init failed with code %d\n", code);
75 exit(1);
76 }
77
78 /* parse command line for our own operations */
79 for (i = 1; i < argc; i++) {
80 if (!strcmp(argv[i], "-inc")) {
81 /* use ubik_Call to do the work, finding an up server and handling
82 * the job of finding a sync site, if need be */
83 code = ubik_SAMPLE_Inc(cstruct, 0);
84 printf("return code is %d\n", code);
85 } else if (!strcmp(argv[i], "-try")) {
86 code = ubik_SAMPLE_Test(cstruct, 0);
87 printf("return code is %d\n", code);
88 } else if (!strcmp(argv[i], "-qget")) {
89 code = ubik_SAMPLE_QGet(cstruct, 0, &temp);
90 printf("got quick value %d (code %d)\n", temp, code);
91 } else if (!strcmp(argv[i], "-get")) {
92 code = ubik_SAMPLE_Get(cstruct, 0, &temp);
93 printf("got value %d (code %d)\n", temp, code);
94 } else if (!strcmp(argv[i], "-trunc")) {
95 code = ubik_SAMPLE_Trun(cstruct, 0);
96 printf("return code is %d\n", code);
97 } else if (!strcmp(argv[i], "-minc")) {
98 afs_int32 temp;
99 struct timeval tv;
100 tv.tv_sec = 1;
101 tv.tv_usec = 0;
102 printf("ubik_client: Running minc...\n");
103
104 while (1) {
105 temp = 0;
106 code = ubik_SAMPLE_Get(cstruct, 0, &temp);
107 if (code != 0) {
108 printf("SAMPLE_Get #1 failed with code %ld\n",
109 afs_printable_int32_ld(code));
110 } else {
111 printf("SAMPLE_Get #1 succeeded, got value %ld\n",
112 afs_printable_int32_ld(temp));
113 }
114
115 temp = 0;
116 code = ubik_SAMPLE_Inc(cstruct, 0);
117 if (code != 0) {
118 printf("SAMPLE_Inc #1 failed with code %ld\n",
119 afs_printable_int32_ld(code));
120 } else {
121 printf("SAMPLE_Inc #1 succeeded, incremented integer\n");
122 }
123 temp = 0;
124 code = ubik_SAMPLE_Get(cstruct, 0, &temp);
125 if (code != 0) {
126 printf("SAMPLE_Get #2 failed with code %ld\n",
127 afs_printable_int32_ld(code));
128 } else {
129 printf("SAMPLE_Get #2 succeeded, got value %ld\n",
130 afs_printable_int32_ld(temp));
131 }
132
133 temp = 0;
134 code = ubik_SAMPLE_Inc(cstruct, 0);
135 if (code != 0)
136 printf("SAMPLE_Inc #2 failed with code %ld\n",
137 afs_printable_int32_ld(code));
138 else
139 printf("SAMPLE_Inc #2 succeeded, incremented integer\n");
140
141 tv.tv_sec = 1;
142 tv.tv_usec = 0;
143 #ifdef AFS_PTHREAD_ENV
144 select(0, 0, 0, 0, &tv);
145 #else
146 IOMGR_Select(0, 0, 0, 0, &tv);
147 #endif
148 printf("Repeating the SAMPLE operations again...\n");
149 }
150 } else if (!strcmp(argv[i], "-mget")) {
151 afs_int32 temp;
152 struct timeval tv;
153 tv.tv_sec = 1;
154 tv.tv_usec = 0;
155 while (1) {
156 code = ubik_SAMPLE_Get(cstruct, 0, &temp);
157 printf("got value %d (code %d)\n", temp, code);
158
159 code = ubik_SAMPLE_Inc(cstruct, 0);
160 printf("update return code is %d\n", code);
161
162 code = ubik_SAMPLE_Get(cstruct, 0, &temp);
163 printf("got value %d (code %d)\n", temp, code);
164
165 code = ubik_SAMPLE_Get(cstruct, 0, &temp);
166 printf("got value %d (code %d)\n", temp, code);
167
168 tv.tv_sec = 1;
169 tv.tv_usec = 0;
170 #ifdef AFS_PTHREAD_ENV
171 select(0, 0, 0, 0, &tv);
172 #else
173 IOMGR_Select(0, 0, 0, 0, &tv);
174 #endif
175 }
176 }
177 }
178 return 0;
179 }