WhiteBoard Project using C RPC
A Project in Distributed Computing at IIIT-Delhi
wbadmin.c
Go to the documentation of this file.
1 /*
2  * An example 730-C-RPC White Board Administration program
3  *
4  * compile with: gcc wbadmin.c -std=c99 -o wbadmin
5  */
6 
7 #include "wb.h"
8 
9 /* The declarations for BClient, BBoard, XferWBArg, query, newserver,
10  * and transferwhiteboard should go into the new server.x */
11 
12 struct BClient { /* cf with AClient */
13  struct BClient *next;
14  ClientData * clientdata;
15  /* CLIENT *callback; removed */
16 };
17 
18 struct BBoard { /* cf with ABoard */
19  struct BBoard *next;
20  struct BClient *clients;
21  ALine *lines;
22 };
23 
24 #define NMSZ 50
25 
26 struct XferWBArg {
27  char boardnm[NMSZ]; /* board name to be transferred */
28  char machinenm[NMSZ]; /* name of the receiving machine */
29  int nprogram; /* rpc prog num of the server above */
30  int nversion; /* registered version number */
31 };
32 
33 struct BBoard * query_1(int * unused, CLIENT * clp) { return 0;}
34 int newserver_1(char * machineName, CLIENT * clp) { return 0; }
35 int transferwhiteboard_1(struct XferWBArg a, CLIENT * clp) { return 0; }
36 
37 void usage()
38 {
39  fprintf
40  (stderr,
41  "\nNote: Linked with dummy query, newserver, transferwhiteboard functions.\n\n"
42  "Usage: -q for query, -n for new server create, -t for transfer board\n"
43  "wbadmin -q <server-machine-nm> <prognum-in-hex>\n"
44  "wbadmin -n <existing-server-machine-nm> <prognum-in-hex> <new-server-machine-nm>\n"
45  "wbadmin -t <from-server-machine-nm> <prognum-in-hex> <wb-nm> <to-server-machine-nm> <prognum>\n");
46 }
47 
48 int queryServer(char * snm, int prgn, CLIENT * clp)
49 {
50  int dummy = 0;
51  struct BBoard * b = query_1(&dummy, clp);
52  if (b == 0)
53  printf("Server has no boards.\n");
54  else
55  for (; b; b = b->next) {
56  printf("Board %s on server %s prognum %x has\n",
57  b->clients->clientdata->boardnm, snm, prgn);
58  if (b->clients == 0) /* for robustness and better functionality ... */
59  printf("\tno clients\n");
60  else
61  for (struct BClient * c = b->clients; c; c = c->next)
62  printf("\tclient on server %s displayed at %s with prognum %x\n",
63  c->clientdata->machinenm,
64  c->clientdata->xdisplaynm,
65  c->clientdata->nprogram);
66  }
67  return 0;
68 }
69 
70 int main(int argc, char * argv[])
71 {
72  CLIENT * clp = 0;
73  int result = -1;
74 
75  if (argc < 4)
76  goto error;
77  char * cmd = argv[1];
78  if (cmd[0] != '-')
79  goto error;
80 
81  char * host = argv[2];
82  int prognum = strtol(argv[3], 0, 16);
83  printf("prgn %x\n", prognum);
84  clp = clnt_create(host, prognum, WhiteBoardServerVersion, "tcp");
85  if (clp == 0)
86  goto error;
87 
88  switch (cmd[1]) {
89  case 'q':
90  result = queryServer(host, prognum, clp);
91  break;
92  case 'n':
93  if (argc < 5)
94  goto error;
95  result = newserver_1(argv[4], clp); /* result == prog num of new server */
96  break;
97  case 't':
98  if (argc < 6)
99  goto error;
100  struct XferWBArg xa;
101  strcpy(xa.boardnm, argv[4]);
102  strcpy(xa.machinenm, argv[5]);
103  xa.nprogram = strtol(argv[6], 0, 16);
104  xa.nversion = WhiteBoardServerVersion;
105  result = transferwhiteboard_1(xa, clp);
106  break;
107  default:
108  goto error;
109  }
110 done:
111  if (clp)
112  clnt_destroy(clp);
113  printf("result %d\n", result);
114  return result;
115 
116 error: /* more elaborate error reporting is better */
117  usage();
118  goto done;
119 }
120 
121 /* -eof- */
char boardnm[NMSZ]
Definition: wbadmin.c:27
static CLIENT * clp
Definition: client.c:16
ALine * lines
Definition: wbadmin.c:21
struct BClient * clients
Definition: wbadmin.c:20
int nprogram
Definition: wbadmin.c:29
Definition: wbadmin.c:18
char machinenm[NMSZ]
Definition: wbadmin.c:28
int nversion
Definition: wbadmin.c:30
struct BClient * next
Definition: wbadmin.c:13
void usage()
Definition: wbadmin.c:37
#define NMSZ
Definition: wbadmin.c:24
struct BBoard * query_1(int *unused, CLIENT *clp)
Definition: wbadmin.c:33
struct BBoard * next
Definition: wbadmin.c:19
ClientData * clientdata
Definition: wbadmin.c:14
int queryServer(char *snm, int prgn, CLIENT *clp)
Definition: wbadmin.c:48
int main(int argc, char *argv[])
Definition: wbadmin.c:70
int transferwhiteboard_1(struct XferWBArg a, CLIENT *clp)
Definition: wbadmin.c:35
int newserver_1(char *machineName, CLIENT *clp)
Definition: wbadmin.c:34