2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #include <sys/types.h>
22 #include <netinet/in.h>
32 extern int SAMPLE_Inc(), SAMPLE_Test(), SAMPLE_Get(),
33 SAMPLE_Trun(), SAMPLE_QGet();
37 #include "AFS_component_version_number.c"
42 register afs_int32 code;
43 struct ubik_client *cstruct=0;
44 afs_int32 serverList[MAXSERVERS];
45 struct rx_connection *serverconns[MAXSERVERS];
46 struct rx_securityClass *sc;
51 printf("uclient: usage is 'uclient -servers ... [-try] [-get] [-inc] [-minc] [-trunc]\n");
55 /* initialize winsock */
56 if (afs_winsockInit()<0)
59 /* first parse '-servers <server-1> <server-2> ... <server-n>' from command line */
60 code = ubik_ParseClientList(argc, argv, serverList);
62 printf("could not parse server list, code %d\n", code);
66 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
67 for (i=0; i<MAXSERVERS; i++) {
69 serverconns[i] = rx_NewConnection(serverList[i], htons(3000),
70 USER_SERVICE_ID, sc, 0);
72 serverconns[i] = (struct rx_connection *)0;
77 /* next, pass list of server rx_connections (in serverconns), and
78 * a place to put the returned client structure that we'll use in
79 * all of our rpc calls (via ubik_Calll) */
80 code = ubik_ClientInit(serverconns, &cstruct);
82 /* check code from init */
84 printf("ubik client init failed with code %d\n", code);
88 /* parse command line for our own operations */
90 if (!strcmp(argv[i], "-inc")) {
91 /* use ubik_Call to do the work, finding an up server and handling
92 the job of finding a sync site, if need be */
93 code = ubik_Call(SAMPLE_Inc, cstruct, 0);
94 printf("return code is %d\n", code);
96 else if (!strcmp(argv[i], "-try")) {
97 code = ubik_Call(SAMPLE_Test, cstruct, 0);
98 printf("return code is %d\n", code);
100 else if (!strcmp(argv[i], "-qget")) {
101 code = ubik_Call(SAMPLE_QGet, cstruct, 0, &temp);
102 printf("got quick value %d (code %d)\n", temp, code);
104 else if (!strcmp(argv[i], "-get")) {
105 code = ubik_Call(SAMPLE_Get, cstruct, 0, &temp);
106 printf("got value %d (code %d)\n", temp, code);
108 else if (!strcmp(argv[i], "-trunc")) {
109 code = ubik_Call(SAMPLE_Trun, cstruct, 0);
110 printf("return code is %d\n", code);
112 else if (!strcmp(argv[i], "-minc")) {
115 tv.tv_sec = 1; tv.tv_usec = 0;
116 printf("ubik_client: Running minc...\n");
120 code = ubik_Call(SAMPLE_Get, cstruct, 0, &temp);
122 printf("SAMPLE_Inc #1 failed with code %ld\n", code);
125 printf("SAMPLE_Get #1 succeeded, got value %d\n", temp);
129 code = ubik_Call(SAMPLE_Inc, cstruct, 0);
131 printf("SAMPLE_Inc #1 failed with code %ld\n", code);
134 printf("SAMPLE_Inc #1 succeeded, incremented integer\n");
137 code = ubik_Call(SAMPLE_Get, cstruct, 0, &temp);
139 printf("SAMPLE_Get #2 failed with code %ld\n", code);
142 printf("SAMPLE_Get #2 succeeded, got value %d\n", temp);
146 code = ubik_Call(SAMPLE_Inc, cstruct, 0);
148 printf("SAMPLE_Inc #2 failed with code %ld\n", code);
149 else printf("SAMPLE_Inc #2 succeeded, incremented integer\n");
151 tv.tv_sec = 1; tv.tv_usec = 0;
152 IOMGR_Select(0, 0, 0, 0, &tv);
153 printf("Repeating the SAMPLE operations again...\n");
156 else if (!strcmp(argv[i], "-mget")) {
162 code = ubik_Call(SAMPLE_Get, cstruct, 0, &temp);
163 printf("got value %d (code %d)\n", temp, code);
165 code = ubik_Call(SAMPLE_Inc, cstruct, 0);
166 printf("update return code is %d\n", code);
168 code = ubik_Call(SAMPLE_Get, cstruct, 0, &temp);
169 printf("got value %d (code %d)\n", temp, code);
171 code = ubik_Call(SAMPLE_Get, cstruct, 0, &temp);
172 printf("got value %d (code %d)\n", temp, code);
176 IOMGR_Select(0, 0, 0, 0, &tv);