]>
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>. | |
5eaef520 | 10 | * |
de56407f | 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$"; | |
a43ce477 | 18 | #endif |
de56407f | 19 | |
babbc197 | 20 | #include <mit-copyright.h> |
f4c08abd | 21 | #include <string.h> |
8defc06b | 22 | #include "mr_private.h" |
de56407f | 23 | |
5f9f27e4 | 24 | |
25 | /* Invoke a DCM update. */ | |
26 | ||
5eaef520 | 27 | int mr_do_update(void) |
de56407f | 28 | { |
5eaef520 | 29 | int status; |
30 | mr_params param_st; | |
31 | struct mr_params *params = NULL; | |
32 | struct mr_params *reply = NULL; | |
de56407f | 33 | |
5eaef520 | 34 | CHECK_CONNECTED; |
35 | params = ¶m_st; | |
36 | params->mr_version_no = sending_version_no; | |
37 | params->mr_procno = MR_DO_UPDATE; | |
38 | params->mr_argc = 0; | |
39 | params->mr_argl = NULL; | |
40 | params->mr_argv = NULL; | |
41 | ||
42 | if ((status = mr_do_call(params, &reply)) == 0) | |
43 | status = reply->mr_status; | |
44 | ||
45 | mr_destroy_reply(reply); | |
46 | ||
47 | return status; | |
de56407f | 48 | } |
49 | ||
5f9f27e4 | 50 | |
8defc06b | 51 | /* Get the MR motd. This returns an MR status, and motd will either |
5f9f27e4 | 52 | * point to NULL or the motd in a static buffer. |
de56407f | 53 | */ |
5f9f27e4 | 54 | |
5eaef520 | 55 | int mr_motd(char **motd) |
5f9f27e4 | 56 | { |
5eaef520 | 57 | int status; |
58 | mr_params param_st; | |
59 | struct mr_params *params = NULL; | |
60 | struct mr_params *reply = NULL; | |
61 | static char buffer[1024]; | |
62 | ||
63 | *motd = NULL; | |
64 | CHECK_CONNECTED; | |
65 | params = ¶m_st; | |
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; | |
71 | ||
72 | if ((status = mr_do_call(params, &reply))) | |
73 | goto punt; | |
74 | ||
75 | while ((status = reply->mr_status) == MR_MORE_DATA) | |
76 | { | |
77 | if (reply->mr_argc > 0) | |
78 | { | |
79 | strncpy(buffer, reply->mr_argv[0], sizeof(buffer)); | |
80 | *motd = buffer; | |
5f9f27e4 | 81 | } |
5eaef520 | 82 | mr_destroy_reply(reply); |
83 | reply = NULL; | |
84 | ||
85 | initialize_operation(_mr_recv_op, mr_start_recv, &reply, NULL); | |
86 | queue_operation(_mr_conn, CON_INPUT, _mr_recv_op); | |
87 | ||
88 | mr_complete_operation(_mr_recv_op); | |
89 | if (OP_STATUS(_mr_recv_op) != OP_COMPLETE) | |
90 | { | |
91 | mr_disconnect(); | |
92 | status = MR_ABORTED; | |
93 | return status; | |
5f9f27e4 | 94 | } |
5eaef520 | 95 | } |
96 | punt: | |
97 | mr_destroy_reply(reply); | |
98 | /* for backwards compatability */ | |
99 | if (status == MR_UNKNOWN_PROC) | |
100 | return 0; | |
101 | else | |
102 | return status; | |
5f9f27e4 | 103 | } |
2bf6c690 | 104 | |
105 | ||
106 | /* Tell the library to take care of another input source while it is | |
107 | * processing a query. For instance, an X toolkit application would | |
108 | * do something like | |
8defc06b | 109 | * mr_set_alternate_input(ConnectionNumber(XtDisplay(widget)), doxinput); |
2bf6c690 | 110 | * where doxinput is defined as: |
111 | * doxinput() { | |
112 | * extern Widget toplevel; | |
113 | * XEvent event; | |
114 | * while (XPending(XtDisplay(toplevel))) { | |
115 | * XNextEvent(XtDisplay(toplevel), &event); | |
116 | * XtDispatchEvent(&event); | |
117 | * } | |
118 | * XFlush(XtDisplay(toplevel)); | |
119 | * } | |
120 | */ | |
121 | ||
8defc06b | 122 | static int mr_alternate_input = 0; |
123 | static int (*mr_alternate_handler)(); | |
2bf6c690 | 124 | |
5eaef520 | 125 | int mr_set_alternate_input(int fd, int (*proc)()) |
2bf6c690 | 126 | { |
5eaef520 | 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 | ||
5eaef520 | 139 | int mr_complete_operation(OPERATION op) |
2bf6c690 | 140 | { |
5eaef520 | 141 | long infd, outfd, exfd; |
142 | int rc; | |
143 | ||
144 | gdb_progress(); /* try for an immediate completion */ | |
145 | ||
146 | if (mr_alternate_input == 0) | |
147 | return complete_operation(op); | |
148 | ||
149 | infd = 1 << mr_alternate_input; | |
150 | outfd = exfd = 0; | |
151 | ||
152 | while (op->status != OP_COMPLETE && op->status != OP_CANCELLED) | |
153 | { | |
154 | rc = con_select(mr_alternate_input, (fd_set *)&infd, (fd_set *)&outfd, | |
155 | (fd_set *)&exfd, NULL); | |
156 | if (rc > 0 && mr_alternate_handler) | |
157 | (*mr_alternate_handler)(); | |
2bf6c690 | 158 | } |
5eaef520 | 159 | return op->status; |
2bf6c690 | 160 | } |
161 |