]>
Commit | Line | Data |
---|---|---|
c9104dd4 | 1 | /* $Header$ */ |
2 | ||
3 | #include <stdio.h> | |
4 | #include <WcCreate.h> | |
5 | #include <X11/StringDefs.h> | |
6 | #include <X11/Xaw/Text.h> | |
7 | #include <moira.h> | |
8 | #include <moira_site.h> | |
9 | ||
10 | extern void AriRegisterAthena(); | |
11 | ||
12 | typedef struct _ClusterResources { | |
13 | char *server; | |
14 | } ClusterResources; | |
15 | ||
16 | static XrmOptionDescRec options[] = { | |
17 | {"-server", "*moiraServer", XrmoptionSepArg, NULL}, | |
18 | }; | |
19 | ||
20 | #define Offset(field) (XtOffset(ClusterResources *, field)) | |
21 | ||
22 | static XtResource my_resources[] = { | |
23 | {"moiraServer", XtCString, XtRString, sizeof(String), | |
24 | Offset(server), XtRImmediate, "" }, | |
25 | }; | |
26 | ||
27 | #undef Offset | |
28 | ||
29 | void getClusters(), getMachines(), localErrorHandler(), mr_x_input(); | |
30 | ||
31 | XtActionsRec actions[] = { | |
32 | { "getClusters", getClusters }, | |
33 | { "getMachines", getMachines }, | |
34 | }; | |
35 | ||
36 | Widget appShell; | |
37 | ClusterResources resources; | |
38 | Display *dpy; | |
39 | char *program_name; | |
40 | char *clusters[256], *machines[100]; | |
41 | int nclusters = 0, nmachines = 0; | |
42 | ||
43 | void | |
44 | main(argc, argv) | |
45 | int argc; | |
46 | char* argv[]; | |
47 | { | |
48 | int status; | |
49 | char *motd; | |
50 | XtAppContext app; | |
51 | ||
52 | if ((program_name = rindex(argv[0], '/')) == NULL) | |
53 | program_name = argv[0]; | |
54 | else | |
55 | program_name++; | |
56 | program_name = strsave(program_name); | |
57 | ||
58 | /* | |
59 | * Intialize Toolkit creating the application shell, and get | |
60 | * application resources. | |
61 | */ | |
62 | appShell = XtInitialize("cluster", "Cluster", | |
63 | options, XtNumber(options), | |
64 | &argc, argv); | |
65 | app = XtWidgetToApplicationContext(appShell); | |
66 | XtAppSetErrorHandler(app, localErrorHandler); | |
67 | dpy = XtDisplay(appShell); | |
68 | XtAppAddActions(app, actions, XtNumber(actions)); | |
69 | XtGetApplicationResources(appShell, (caddr_t) &resources, | |
70 | my_resources, XtNumber(my_resources), | |
71 | NULL, (Cardinal) 0); | |
72 | WcRegisterCallback(app, "getClusters", getClusters, NULL); | |
73 | /* Register all Athena widget classes */ | |
74 | AriRegisterAthena(app); | |
75 | ||
76 | status = mr_connect(resources.server); | |
77 | if (status) { | |
78 | com_err(program_name, status, " connecting to server"); | |
79 | exit(1); | |
80 | } | |
81 | ||
82 | status = mr_motd(&motd); | |
83 | if (status) { | |
84 | com_err(program_name, status, " connecting to server"); | |
85 | exit(1); | |
86 | } | |
87 | if (motd) { | |
88 | fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", | |
89 | motd); | |
90 | mr_disconnect(); | |
91 | exit(1); | |
92 | } | |
93 | ||
94 | status = mr_auth("cluster"); | |
95 | if (status == MR_USER_AUTH) { | |
96 | char buf[BUFSIZ]; | |
97 | com_err(program_name, status, "\nPress [RETURN] to continue"); | |
98 | gets(buf); | |
99 | } else if (status) { | |
100 | com_err(program_name, status, "; authorization failed - may need to run kinit"); | |
101 | exit(1); | |
102 | } | |
103 | ||
104 | /* Create widget tree below toplevel shell using Xrm database */ | |
105 | WcWidgetCreation(appShell); | |
106 | /* | |
107 | * Realize the widget tree, finish up initializing, | |
108 | * and enter the main application loop | |
109 | */ | |
110 | XtRealizeWidget(appShell); | |
111 | mr_set_alternate_input(ConnectionNumber(dpy), mr_x_input); | |
112 | XtMainLoop(); | |
113 | } | |
114 | ||
115 | ||
116 | int collect(argc, argv, sq) | |
117 | int argc; | |
118 | char **argv; | |
119 | struct save_queue *sq; | |
120 | { | |
121 | sq_save_args(argc, argv, sq); | |
122 | return(MR_CONT); | |
123 | } | |
124 | ||
125 | void getClusters() | |
126 | { | |
127 | Arg args[2]; | |
128 | char *clu, **argv; | |
129 | struct save_queue *sq; | |
130 | int status; | |
131 | ||
132 | sq = sq_create(); | |
133 | XtSetArg(args[0], XtNstring, &clu); | |
134 | XtGetValues(WcFullNameToWidget(appShell, "*clufilter"), args, 1); | |
135 | status = MoiraQuery("get_cluster", 1, &clu, collect, sq); | |
136 | if (status) | |
137 | com_err(program_name, status, " while fetching clusters"); | |
138 | while (sq_get_data(sq, &argv)) { | |
139 | /* add_to_widget("*clusterlist", argv[0]); */ | |
140 | clusters[nclusters++] = argv[0]; | |
141 | } | |
142 | XawListChange(WcFullNameToWidget(appShell, "*clusterlist"), | |
143 | clusters, nclusters, 0, False); | |
144 | } | |
145 | ||
146 | void getMachines() | |
147 | { | |
148 | } | |
149 | ||
150 | /* Called from within the toolkit */ | |
151 | void localErrorHandler(s) | |
152 | String s; | |
153 | { | |
154 | fprintf(stderr, "Moira X error: %s\n", s); | |
155 | exit(1); | |
156 | } | |
157 | ||
158 | ||
159 | void mr_x_input() | |
160 | { | |
161 | XEvent event; | |
162 | ||
163 | XtAppNextEvent(_XtDefaultAppContext(), &event); | |
164 | XtDispatchEvent(&event); | |
165 | } | |
166 | ||
167 | ||
168 | int MoiraQuery(query, argc, argv, callback, data) | |
169 | char *query; | |
170 | int argc; | |
171 | char **argv; | |
172 | int (*callback)(); | |
173 | caddr_t data; | |
174 | { | |
175 | int status; | |
176 | ||
177 | /* MakeWatchCursor(toplevel); */ | |
178 | status = mr_query(query, argc, argv, callback, data); | |
179 | if (status != MR_ABORTED && status != MR_NOT_CONNECTED) { | |
180 | /* MakeNormalCursor(toplevel); */ | |
181 | return(status); | |
182 | } | |
183 | status = mr_connect(resources.server); | |
184 | if (status) { | |
185 | com_err(program_name, status, " while re-connecting to server %s", | |
186 | resources.server); | |
187 | /* MakeNormalCursor(toplevel); */ | |
188 | return(MR_ABORTED); | |
189 | } | |
190 | status = mr_auth("mmoira"); | |
191 | if (status) { | |
192 | com_err(program_name, status, " while re-authenticating to server %s", | |
193 | resources.server); | |
194 | mr_disconnect(); | |
195 | /* MakeNormalCursor(toplevel); */ | |
196 | return(MR_ABORTED); | |
197 | } | |
198 | status = mr_query(query, argc, argv, callback, data); | |
199 | /* MakeNormalCursor(toplevel); */ | |
200 | return(status); | |
201 | } | |
202 | ||
203 | ||
204 | add_to_widget(wn, s) | |
205 | char *wn; | |
206 | char *s; | |
207 | { | |
208 | XawTextBlock tb; | |
209 | int ret, i; | |
210 | XawTextPosition size; | |
211 | Widget w; | |
212 | Arg args[2]; | |
213 | char buf[512]; | |
214 | ||
215 | sprintf(buf, "%s\n", s); | |
216 | w = WcFullNameToWidget(appShell, wn); | |
217 | if (w == NULL) | |
218 | com_err(program_name, 0, " unable to find widget \"%s\"", wn); | |
219 | tb.firstPos = 0; | |
220 | tb.length = strlen(s); | |
221 | tb.ptr = buf; | |
222 | tb.format = FMT8BIT; | |
223 | XtSetArg(args[0], XtNlength, &size); | |
224 | XtGetValues(w, args, 1); | |
225 | ret = XawTextReplace(w, size, size, &tb); | |
226 | if (ret != XawEditDone) | |
227 | fprintf(stderr, "Text Edit failed: %d\n", ret); | |
228 | } | |
229 |