]>
Commit | Line | Data |
---|---|---|
de56407f | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
8defc06b | 6 | * Copyright (C) 1987, 1989, 1990 by the Massachusetts Institute of |
7 | * Technology | |
babbc197 | 8 | * For copying and distribution information, please see the file |
9 | * <mit-copyright.h>. | |
de56407f | 10 | * |
11 | * This routine is part of the client library. It handles | |
5f9f27e4 | 12 | * the protocol operations: invoking an update and getting the |
8defc06b | 13 | * MR message of the day. |
de56407f | 14 | */ |
15 | ||
16 | #ifndef lint | |
17 | static char *rcsid_sms_do_update_c = "$Header$"; | |
18 | #endif lint | |
19 | ||
babbc197 | 20 | #include <mit-copyright.h> |
8defc06b | 21 | #include "mr_private.h" |
de56407f | 22 | |
5f9f27e4 | 23 | |
24 | /* Invoke a DCM update. */ | |
25 | ||
8defc06b | 26 | int mr_do_update() |
de56407f | 27 | { |
28 | int status; | |
8defc06b | 29 | mr_params param_st; |
30 | struct mr_params *params = NULL; | |
31 | struct mr_params *reply = NULL; | |
de56407f | 32 | |
33 | CHECK_CONNECTED; | |
34 | params = ¶m_st; | |
8defc06b | 35 | params->mr_version_no = sending_version_no; |
36 | params->mr_procno = MR_DO_UPDATE; | |
37 | params->mr_argc = 0; | |
38 | params->mr_argl = NULL; | |
39 | params->mr_argv = NULL; | |
de56407f | 40 | |
8defc06b | 41 | if ((status = mr_do_call(params, &reply)) == 0) |
42 | status = reply->mr_status; | |
de56407f | 43 | |
8defc06b | 44 | mr_destroy_reply(reply); |
de56407f | 45 | |
46 | return status; | |
47 | } | |
48 | ||
5f9f27e4 | 49 | |
8defc06b | 50 | /* Get the MR motd. This returns an MR status, and motd will either |
5f9f27e4 | 51 | * point to NULL or the motd in a static buffer. |
de56407f | 52 | */ |
5f9f27e4 | 53 | |
8defc06b | 54 | int mr_motd(motd) |
5f9f27e4 | 55 | char **motd; |
56 | { | |
57 | int status; | |
8defc06b | 58 | mr_params param_st; |
59 | struct mr_params *params = NULL; | |
60 | struct mr_params *reply = NULL; | |
5f9f27e4 | 61 | static char buffer[1024]; |
62 | ||
63 | *motd = NULL; | |
64 | CHECK_CONNECTED; | |
65 | params = ¶m_st; | |
8defc06b | 66 | params->mr_version_no = sending_version_no; |
67 | params->mr_procno = MR_MOTD; | |
68 | params->mr_argc = 0; | |
69 | params->mr_argl = NULL; | |
70 | params->mr_argv = NULL; | |
5f9f27e4 | 71 | |
8defc06b | 72 | if ((status = mr_do_call(params, &reply))) |
5f9f27e4 | 73 | goto punt; |
74 | ||
8defc06b | 75 | while ((status = reply->mr_status) == MR_MORE_DATA) { |
76 | if (reply->mr_argc > 0) { | |
77 | strncpy(buffer, reply->mr_argv[0], sizeof(buffer)); | |
5f9f27e4 | 78 | *motd = buffer; |
79 | } | |
8defc06b | 80 | mr_destroy_reply(reply); |
5f9f27e4 | 81 | reply = NULL; |
82 | ||
8defc06b | 83 | initialize_operation(_mr_recv_op, mr_start_recv, &reply, |
5f9f27e4 | 84 | (int (*)())NULL); |
8defc06b | 85 | queue_operation(_mr_conn, CON_INPUT, _mr_recv_op); |
5f9f27e4 | 86 | |
8defc06b | 87 | mr_complete_operation(_mr_recv_op); |
88 | if (OP_STATUS(_mr_recv_op) != OP_COMPLETE) { | |
89 | mr_disconnect(); | |
90 | status = MR_ABORTED; | |
5f9f27e4 | 91 | return(status); |
92 | } | |
93 | } | |
94 | punt: | |
8defc06b | 95 | mr_destroy_reply(reply); |
6ffcc74c | 96 | /* for backwards compatability */ |
8defc06b | 97 | if (status == MR_UNKNOWN_PROC) |
6ffcc74c | 98 | return(0); |
99 | else | |
100 | return(status); | |
5f9f27e4 | 101 | } |
2bf6c690 | 102 | |
103 | ||
104 | /* Tell the library to take care of another input source while it is | |
105 | * processing a query. For instance, an X toolkit application would | |
106 | * do something like | |
8defc06b | 107 | * mr_set_alternate_input(ConnectionNumber(XtDisplay(widget)), doxinput); |
2bf6c690 | 108 | * where doxinput is defined as: |
109 | * doxinput() { | |
110 | * extern Widget toplevel; | |
111 | * XEvent event; | |
112 | * while (XPending(XtDisplay(toplevel))) { | |
113 | * XNextEvent(XtDisplay(toplevel), &event); | |
114 | * XtDispatchEvent(&event); | |
115 | * } | |
116 | * XFlush(XtDisplay(toplevel)); | |
117 | * } | |
118 | */ | |
119 | ||
8defc06b | 120 | static int mr_alternate_input = 0; |
121 | static int (*mr_alternate_handler)(); | |
2bf6c690 | 122 | |
8defc06b | 123 | int mr_set_alternate_input(fd, proc) |
2bf6c690 | 124 | int fd; |
125 | int (*proc)(); | |
126 | { | |
8defc06b | 127 | if (mr_alternate_input != 0) |
128 | return(MR_ALREADY_CONNECTED); | |
129 | mr_alternate_input = fd; | |
130 | mr_alternate_handler = proc; | |
131 | return(MR_SUCCESS); | |
2bf6c690 | 132 | } |
133 | ||
134 | ||
135 | /* This is used by the parts of the library that must wait for GDB. It | |
136 | * handles alternate input streams (such as X) as well. | |
137 | */ | |
138 | ||
8defc06b | 139 | mr_complete_operation(op) |
2bf6c690 | 140 | OPERATION op; |
141 | { | |
142 | long infd, outfd, exfd; | |
143 | int rc; | |
144 | ||
145 | gdb_progress(); /* try for an immediate completion */ | |
146 | ||
8defc06b | 147 | if (mr_alternate_input == 0) |
2bf6c690 | 148 | return(complete_operation(op)); |
149 | ||
8defc06b | 150 | infd = (1<<mr_alternate_input); |
2bf6c690 | 151 | outfd = exfd = 0; |
152 | ||
153 | while(op->status != OP_COMPLETE && op->status != OP_CANCELLED) { | |
8defc06b | 154 | rc = con_select(mr_alternate_input, (fd_set *)&infd, (fd_set *)&outfd, |
2bf6c690 | 155 | (fd_set *)&exfd, (struct timeval *)NULL); |
8defc06b | 156 | if (rc > 0 && mr_alternate_handler) { |
157 | (*mr_alternate_handler)(); | |
2bf6c690 | 158 | } |
159 | } | |
160 | return(op->status); | |
161 | } | |
162 |