428
|
1 /* Tooltalk support for Emacs.
|
|
2 Copyright (C) 1993, 1994 Sun Microsystems, Inc.
|
|
3 Copyright (C) 1995 Free Software Foundation, Inc.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 /* Written by John Rose <john.rose@eng.sun.com>.
|
|
25 Heavily modified and cleaned up by Ben Wing <ben@xemacs.org>. */
|
|
26
|
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29
|
|
30 #include <X11/Xlib.h>
|
|
31
|
|
32 #include "buffer.h"
|
|
33 #include "elhash.h"
|
|
34 #include "process.h"
|
|
35 #include "tooltalk.h"
|
442
|
36 #include "syssignal.h"
|
428
|
37
|
|
38 Lisp_Object Vtooltalk_fd;
|
|
39
|
|
40 #ifdef TT_DEBUG
|
|
41 static FILE *tooltalk_log_file;
|
|
42 #endif
|
|
43
|
|
44 static Lisp_Object
|
|
45 Vtooltalk_message_handler_hook,
|
|
46 Vtooltalk_pattern_handler_hook,
|
|
47 Vtooltalk_unprocessed_message_hook;
|
|
48
|
|
49 static Lisp_Object
|
|
50 Qtooltalk_message_handler_hook,
|
|
51 Qtooltalk_pattern_handler_hook,
|
|
52 Qtooltalk_unprocessed_message_hook;
|
|
53
|
|
54 static Lisp_Object
|
|
55 Qreceive_tooltalk_message,
|
|
56 Qtt_address,
|
|
57 Qtt_args_count,
|
|
58 Qtt_arg_bval,
|
|
59 Qtt_arg_ival,
|
|
60 Qtt_arg_mode,
|
|
61 Qtt_arg_type,
|
|
62 Qtt_arg_val,
|
|
63 Qtt_class,
|
|
64 Qtt_category,
|
|
65 Qtt_disposition,
|
|
66 Qtt_file,
|
|
67 Qtt_gid,
|
|
68 Qtt_handler,
|
|
69 Qtt_handler_ptype,
|
|
70 Qtt_object,
|
|
71 Qtt_op,
|
|
72 Qtt_opnum,
|
|
73 Qtt_otype,
|
|
74 Qtt_scope,
|
|
75 Qtt_sender,
|
|
76 Qtt_sender_ptype,
|
|
77 Qtt_session,
|
|
78 Qtt_state,
|
|
79 Qtt_status,
|
|
80 Qtt_status_string,
|
|
81 Qtt_uid,
|
|
82 Qtt_callback,
|
|
83 Qtt_plist,
|
|
84 Qtt_prop,
|
|
85
|
|
86 Qtt_reject, /* return-tooltalk-message */
|
|
87 Qtt_reply,
|
|
88 Qtt_fail,
|
|
89
|
|
90 Q_TT_MODE_UNDEFINED, /* enum Tt_mode */
|
|
91 Q_TT_IN,
|
|
92 Q_TT_OUT,
|
|
93 Q_TT_INOUT,
|
|
94 Q_TT_MODE_LAST,
|
|
95
|
|
96 Q_TT_SCOPE_NONE, /* enum Tt_scope */
|
|
97 Q_TT_SESSION,
|
|
98 Q_TT_FILE,
|
|
99 Q_TT_BOTH,
|
|
100 Q_TT_FILE_IN_SESSION,
|
|
101
|
|
102 Q_TT_CLASS_UNDEFINED, /* enum Tt_class */
|
|
103 Q_TT_NOTICE,
|
|
104 Q_TT_REQUEST,
|
|
105 Q_TT_CLASS_LAST,
|
|
106
|
|
107 Q_TT_CATEGORY_UNDEFINED, /* enum Tt_category */
|
|
108 Q_TT_OBSERVE,
|
|
109 Q_TT_HANDLE,
|
|
110 Q_TT_CATEGORY_LAST,
|
|
111
|
|
112 Q_TT_PROCEDURE, /* typedef enum Tt_address */
|
|
113 Q_TT_OBJECT,
|
|
114 Q_TT_HANDLER,
|
|
115 Q_TT_OTYPE,
|
|
116 Q_TT_ADDRESS_LAST,
|
|
117
|
|
118 Q_TT_CREATED, /* enum Tt_state */
|
|
119 Q_TT_SENT,
|
|
120 Q_TT_HANDLED,
|
|
121 Q_TT_FAILED,
|
|
122 Q_TT_QUEUED,
|
|
123 Q_TT_STARTED,
|
|
124 Q_TT_REJECTED,
|
|
125 Q_TT_STATE_LAST,
|
|
126
|
|
127 Q_TT_DISCARD, /* enum Tt_disposition */
|
|
128 Q_TT_QUEUE,
|
|
129 Q_TT_START;
|
|
130
|
|
131 static Lisp_Object Tooltalk_Message_plist_str, Tooltalk_Pattern_plist_str;
|
|
132
|
|
133 Lisp_Object Qtooltalk_error;
|
|
134
|
|
135 /* Used to GCPRO tooltalk message and pattern objects while
|
|
136 they're sitting inside of some active tooltalk message or pattern.
|
|
137 There may not be any other pointers to these objects. */
|
|
138 Lisp_Object Vtooltalk_message_gcpro, Vtooltalk_pattern_gcpro;
|
|
139
|
|
140
|
|
141 /* */
|
|
142 /* machinery for tooltalk-message type */
|
|
143 /* */
|
|
144
|
|
145 Lisp_Object Qtooltalk_messagep;
|
|
146
|
|
147 struct Lisp_Tooltalk_Message
|
|
148 {
|
|
149 struct lcrecord_header header;
|
|
150 Lisp_Object plist_sym, callback;
|
|
151 Tt_message m;
|
|
152 };
|
|
153
|
|
154 static Lisp_Object
|
|
155 mark_tooltalk_message (Lisp_Object obj)
|
|
156 {
|
|
157 mark_object (XTOOLTALK_MESSAGE (obj)->callback);
|
|
158 return XTOOLTALK_MESSAGE (obj)->plist_sym;
|
|
159 }
|
|
160
|
|
161 static void
|
|
162 print_tooltalk_message (Lisp_Object obj, Lisp_Object printcharfun,
|
|
163 int escapeflag)
|
|
164 {
|
440
|
165 Lisp_Tooltalk_Message *p = XTOOLTALK_MESSAGE (obj);
|
428
|
166
|
|
167 if (print_readably)
|
563
|
168 printing_unreadable_object ("#<tooltalk_message 0x%x>",
|
|
169 p->header.uid);
|
428
|
170
|
800
|
171 write_fmt_string (printcharfun, "#<tooltalk_message id:0x%lx 0x%x>",
|
|
172 (long) (p->m), p->header.uid);
|
428
|
173 }
|
|
174
|
|
175 DEFINE_LRECORD_IMPLEMENTATION ("tooltalk-message", tooltalk_message,
|
|
176 mark_tooltalk_message, print_tooltalk_message,
|
|
177 0, 0, 0, 0,
|
440
|
178 Lisp_Tooltalk_Message);
|
428
|
179
|
|
180 static Lisp_Object
|
|
181 make_tooltalk_message (Tt_message m)
|
|
182 {
|
|
183 Lisp_Object val;
|
440
|
184 Lisp_Tooltalk_Message *msg =
|
|
185 alloc_lcrecord_type (Lisp_Tooltalk_Message, &lrecord_tooltalk_message);
|
428
|
186
|
|
187 msg->m = m;
|
|
188 msg->callback = Qnil;
|
|
189 msg->plist_sym = Fmake_symbol (Tooltalk_Message_plist_str);
|
793
|
190 return wrap_tooltalk_message (msg);
|
428
|
191 }
|
|
192
|
|
193 Tt_message
|
|
194 unbox_tooltalk_message (Lisp_Object msg)
|
|
195 {
|
|
196 CHECK_TOOLTALK_MESSAGE (msg);
|
|
197 return XTOOLTALK_MESSAGE (msg)->m;
|
|
198 }
|
|
199
|
|
200 DEFUN ("tooltalk-message-p", Ftooltalk_message_p, 1, 1, 0, /*
|
|
201 Return non-nil if OBJECT is a tooltalk message.
|
|
202 */
|
|
203 (object))
|
|
204 {
|
|
205 return TOOLTALK_MESSAGEP (object) ? Qt : Qnil;
|
|
206 }
|
|
207
|
|
208
|
|
209
|
|
210
|
|
211 /* */
|
|
212 /* machinery for tooltalk-pattern type */
|
|
213 /* */
|
|
214
|
|
215 Lisp_Object Qtooltalk_patternp;
|
|
216
|
|
217 struct Lisp_Tooltalk_Pattern
|
|
218 {
|
|
219 struct lcrecord_header header;
|
|
220 Lisp_Object plist_sym, callback;
|
|
221 Tt_pattern p;
|
|
222 };
|
|
223
|
|
224 static Lisp_Object
|
|
225 mark_tooltalk_pattern (Lisp_Object obj)
|
|
226 {
|
|
227 mark_object (XTOOLTALK_PATTERN (obj)->callback);
|
|
228 return XTOOLTALK_PATTERN (obj)->plist_sym;
|
|
229 }
|
|
230
|
|
231 static void
|
|
232 print_tooltalk_pattern (Lisp_Object obj, Lisp_Object printcharfun,
|
|
233 int escapeflag)
|
|
234 {
|
440
|
235 Lisp_Tooltalk_Pattern *p = XTOOLTALK_PATTERN (obj);
|
428
|
236
|
|
237 if (print_readably)
|
563
|
238 printing_unreadable_object ("#<tooltalk_pattern 0x%x>",
|
|
239 p->header.uid);
|
428
|
240
|
800
|
241 write_fmt_string (printcharfun, "#<tooltalk_pattern id:0x%lx 0x%x>",
|
|
242 (long) (p->p), p->header.uid);
|
428
|
243 }
|
|
244
|
|
245 DEFINE_LRECORD_IMPLEMENTATION ("tooltalk-pattern", tooltalk_pattern,
|
|
246 mark_tooltalk_pattern, print_tooltalk_pattern,
|
|
247 0, 0, 0, 0,
|
440
|
248 Lisp_Tooltalk_Pattern);
|
428
|
249
|
|
250 static Lisp_Object
|
|
251 make_tooltalk_pattern (Tt_pattern p)
|
|
252 {
|
440
|
253 Lisp_Tooltalk_Pattern *pat =
|
|
254 alloc_lcrecord_type (Lisp_Tooltalk_Pattern, &lrecord_tooltalk_pattern);
|
428
|
255 Lisp_Object val;
|
|
256
|
|
257 pat->p = p;
|
|
258 pat->callback = Qnil;
|
|
259 pat->plist_sym = Fmake_symbol (Tooltalk_Pattern_plist_str);
|
|
260
|
793
|
261 return wrap_tooltalk_pattern (pat);
|
428
|
262 }
|
|
263
|
|
264 static Tt_pattern
|
|
265 unbox_tooltalk_pattern (Lisp_Object pattern)
|
|
266 {
|
|
267 CHECK_TOOLTALK_PATTERN (pattern);
|
|
268 return XTOOLTALK_PATTERN (pattern)->p;
|
|
269 }
|
|
270
|
|
271 DEFUN ("tooltalk-pattern-p", Ftooltalk_pattern_p, 1, 1, 0, /*
|
|
272 Return non-nil if OBJECT is a tooltalk pattern.
|
|
273 */
|
|
274 (object))
|
|
275 {
|
|
276 return TOOLTALK_PATTERNP (object) ? Qt : Qnil;
|
|
277 }
|
|
278
|
|
279
|
|
280
|
|
281
|
|
282 static int
|
|
283 tooltalk_constant_value (Lisp_Object s)
|
|
284 {
|
|
285 if (INTP (s))
|
|
286 return XINT (s);
|
|
287 else if (SYMBOLP (s))
|
|
288 return XINT (XSYMBOL (s)->value);
|
|
289 else
|
|
290 return 0; /* should never occur */
|
|
291 }
|
|
292
|
|
293 static void
|
|
294 check_status (Tt_status st)
|
|
295 {
|
|
296 if (tt_is_err (st))
|
563
|
297 {
|
665
|
298 CIntbyte *err;
|
563
|
299
|
|
300 EXTERNAL_TO_C_STRING (tt_status_message (st), err, Qnative);
|
|
301 signal_error (Qtooltalk_error, err, Qunbound);
|
|
302 }
|
428
|
303 }
|
|
304
|
|
305 DEFUN ("receive-tooltalk-message", Freceive_tooltalk_message, 0, 2, 0, /*
|
|
306 Run tt_message_receive().
|
|
307 This function is the process handler for the ToolTalk connection process.
|
|
308 */
|
|
309 (ignore1, ignore2))
|
|
310 {
|
|
311 /* This function can GC */
|
|
312 Tt_message mess = tt_message_receive ();
|
|
313 Lisp_Object message_ = make_tooltalk_message (mess);
|
|
314 struct gcpro gcpro1;
|
|
315
|
|
316 GCPRO1 (message_);
|
|
317 if (mess != NULL && !NILP (Vtooltalk_unprocessed_message_hook))
|
|
318 va_run_hook_with_args (Qtooltalk_unprocessed_message_hook, 1, message_);
|
|
319 UNGCPRO;
|
|
320
|
|
321 /* see comment in event-stream.c about this return value. */
|
|
322 return Qzero;
|
|
323 }
|
|
324
|
|
325 static Tt_callback_action
|
|
326 tooltalk_message_callback (Tt_message m, Tt_pattern p)
|
|
327 {
|
|
328 /* This function can GC */
|
|
329 Lisp_Object cb;
|
|
330 Lisp_Object message_;
|
|
331 Lisp_Object pattern;
|
|
332 struct gcpro gcpro1, gcpro2;
|
|
333
|
|
334 #ifdef TT_DEBUG
|
|
335 int i, j;
|
|
336
|
|
337 fprintf (tooltalk_log_file, "message_cb: %d\n", m);
|
|
338 fprintf (tooltalk_log_file, "op: %s (", tt_message_op (m));
|
|
339 for (j = tt_message_args_count (m), i = 0; i < j; i++) {
|
|
340 fprintf (tooltalk_log_file, "%s \"%s\"", tt_message_arg_type (m, i),
|
|
341 tt_message_arg_val (m, i));
|
|
342 fprintf (tooltalk_log_file, "%s", i == j-1 ? ")" : ", ");
|
|
343 }
|
|
344 fprintf (tooltalk_log_file, "\n\n");
|
|
345 fflush (tooltalk_log_file);
|
|
346 #endif
|
|
347
|
826
|
348 message_ = VOID_TO_LISP (tt_message_user (m, TOOLTALK_MESSAGE_KEY));
|
428
|
349 pattern = make_tooltalk_pattern (p);
|
|
350 cb = XTOOLTALK_MESSAGE (message_)->callback;
|
|
351 GCPRO2 (message_, pattern);
|
|
352 if (!NILP (Vtooltalk_message_handler_hook))
|
|
353 va_run_hook_with_args (Qtooltalk_message_handler_hook, 2,
|
|
354 message_, pattern);
|
|
355
|
|
356 if ((SYMBOLP (cb) && EQ (Qt, Ffboundp (cb))) ||
|
|
357 (CONSP (cb) && EQ (Qlambda, Fcar (cb)) &&
|
|
358 !NILP (Flistp (Fcar (Fcdr (cb))))))
|
|
359 call2 (cb, message_, pattern);
|
|
360 UNGCPRO;
|
|
361
|
|
362 tt_message_destroy (m);
|
|
363 Fremhash (message_, Vtooltalk_message_gcpro);
|
|
364
|
|
365 return TT_CALLBACK_PROCESSED;
|
|
366 }
|
|
367
|
|
368 static Tt_callback_action
|
|
369 tooltalk_pattern_callback (Tt_message m, Tt_pattern p)
|
|
370 {
|
|
371 /* This function can GC */
|
|
372 Lisp_Object cb;
|
|
373 Lisp_Object message_;
|
|
374 Lisp_Object pattern;
|
|
375 struct gcpro gcpro1, gcpro2;
|
|
376
|
|
377 #ifdef TT_DEBUG
|
|
378 int i, j;
|
|
379
|
|
380 fprintf (tooltalk_log_file, "pattern_cb: %d\n", m);
|
|
381 fprintf (tooltalk_log_file, "op: %s (", tt_message_op (m));
|
|
382 for (j = tt_message_args_count (m), i = 0; i < j; i++) {
|
|
383 fprintf (tooltalk_log_file, "%s \"%s\"", tt_message_arg_type (m, i),
|
|
384 tt_message_arg_val (m, i));
|
|
385 fprintf (tooltalk_log_file, "%s", i == j-1 ? ")" : ", ");
|
|
386 }
|
|
387 fprintf (tooltalk_log_file, "\n\n");
|
|
388 fflush (tooltalk_log_file);
|
|
389 #endif
|
|
390
|
|
391 message_ = make_tooltalk_message (m);
|
826
|
392 pattern = VOID_TO_LISP (tt_pattern_user (p, TOOLTALK_PATTERN_KEY));
|
428
|
393 cb = XTOOLTALK_PATTERN (pattern)->callback;
|
|
394 GCPRO2 (message_, pattern);
|
|
395 if (!NILP (Vtooltalk_pattern_handler_hook))
|
|
396 va_run_hook_with_args (Qtooltalk_pattern_handler_hook, 2,
|
|
397 message_, pattern);
|
|
398
|
|
399 if (SYMBOLP (cb) && EQ (Qt, Ffboundp (cb)))
|
|
400 call2 (cb, message_, pattern);
|
|
401 UNGCPRO;
|
|
402
|
|
403 tt_message_destroy (m);
|
|
404 return TT_CALLBACK_PROCESSED;
|
|
405 }
|
|
406
|
|
407 static Lisp_Object
|
|
408 tt_mode_symbol (Tt_mode n)
|
|
409 {
|
|
410 switch (n)
|
|
411 {
|
|
412 case TT_MODE_UNDEFINED: return Q_TT_MODE_UNDEFINED;
|
|
413 case TT_IN: return Q_TT_IN;
|
|
414 case TT_OUT: return Q_TT_OUT;
|
|
415 case TT_INOUT: return Q_TT_INOUT;
|
|
416 case TT_MODE_LAST: return Q_TT_MODE_LAST;
|
|
417 default: return Qnil;
|
|
418 }
|
|
419 }
|
|
420
|
|
421 static Lisp_Object
|
|
422 tt_scope_symbol (Tt_scope n)
|
|
423 {
|
|
424 switch (n)
|
|
425 {
|
|
426 case TT_SCOPE_NONE: return Q_TT_SCOPE_NONE;
|
|
427 case TT_SESSION: return Q_TT_SESSION;
|
|
428 case TT_FILE: return Q_TT_FILE;
|
|
429 case TT_BOTH: return Q_TT_BOTH;
|
|
430 case TT_FILE_IN_SESSION: return Q_TT_FILE_IN_SESSION;
|
|
431 default: return Qnil;
|
|
432 }
|
|
433 }
|
|
434
|
|
435
|
|
436 static Lisp_Object
|
|
437 tt_class_symbol (Tt_class n)
|
|
438 {
|
|
439 switch (n)
|
|
440 {
|
|
441 case TT_CLASS_UNDEFINED: return Q_TT_CLASS_UNDEFINED;
|
|
442 case TT_NOTICE: return Q_TT_NOTICE;
|
|
443 case TT_REQUEST: return Q_TT_REQUEST;
|
|
444 case TT_CLASS_LAST: return Q_TT_CLASS_LAST;
|
|
445 default: return Qnil;
|
|
446 }
|
|
447 }
|
|
448
|
|
449 /*
|
|
450 * This is not being used. Is that a mistake or is this function
|
|
451 * simply not necessary?
|
|
452 */
|
|
453 #if 0
|
|
454 static Lisp_Object
|
|
455 tt_category_symbol (Tt_category n)
|
|
456 {
|
|
457 switch (n)
|
|
458 {
|
|
459 case TT_CATEGORY_UNDEFINED: return Q_TT_CATEGORY_UNDEFINED;
|
|
460 case TT_OBSERVE: return Q_TT_OBSERVE;
|
|
461 case TT_HANDLE: return Q_TT_HANDLE;
|
|
462 case TT_CATEGORY_LAST: return Q_TT_CATEGORY_LAST;
|
|
463 default: return Qnil;
|
|
464 }
|
|
465 }
|
|
466 #endif /* 0 */
|
|
467
|
|
468 static Lisp_Object
|
|
469 tt_address_symbol (Tt_address n)
|
|
470 {
|
|
471 switch (n)
|
|
472 {
|
|
473 case TT_PROCEDURE: return Q_TT_PROCEDURE;
|
|
474 case TT_OBJECT: return Q_TT_OBJECT;
|
|
475 case TT_HANDLER: return Q_TT_HANDLER;
|
|
476 case TT_OTYPE: return Q_TT_OTYPE;
|
|
477 case TT_ADDRESS_LAST: return Q_TT_ADDRESS_LAST;
|
|
478 default: return Qnil;
|
|
479 }
|
|
480 }
|
|
481
|
|
482 static Lisp_Object
|
|
483 tt_state_symbol (Tt_state n)
|
|
484 {
|
|
485 switch (n)
|
|
486 {
|
|
487 case TT_CREATED: return Q_TT_CREATED;
|
|
488 case TT_SENT: return Q_TT_SENT;
|
|
489 case TT_HANDLED: return Q_TT_HANDLED;
|
|
490 case TT_FAILED: return Q_TT_FAILED;
|
|
491 case TT_QUEUED: return Q_TT_QUEUED;
|
|
492 case TT_STARTED: return Q_TT_STARTED;
|
|
493 case TT_REJECTED: return Q_TT_REJECTED;
|
|
494 case TT_STATE_LAST: return Q_TT_STATE_LAST;
|
|
495 default: return Qnil;
|
|
496 }
|
|
497 }
|
|
498
|
|
499 static Lisp_Object
|
771
|
500 tt_build_c_string (char *s)
|
428
|
501 {
|
|
502 return build_string (s ? s : "");
|
|
503 }
|
|
504
|
|
505 static Lisp_Object
|
|
506 tt_opnum_string (int n)
|
|
507 {
|
|
508 char buf[32];
|
|
509
|
|
510 sprintf (buf, "%u", n);
|
|
511 return build_string (buf);
|
|
512 }
|
|
513
|
|
514 static Lisp_Object
|
|
515 tt_message_arg_ival_string (Tt_message m, int n)
|
|
516 {
|
603
|
517 char buf[DECIMAL_PRINT_SIZE (long)];
|
428
|
518 int value;
|
|
519
|
|
520 check_status (tt_message_arg_ival (m, n, &value));
|
|
521 long_to_string (buf, value);
|
|
522 return build_string (buf);
|
|
523 }
|
|
524
|
|
525 static Lisp_Object
|
|
526 tt_message_arg_bval_vector (Tt_message m, int n)
|
|
527 {
|
|
528 /* !!#### This function has not been Mule-ized */
|
665
|
529 Intbyte *value;
|
428
|
530 int len = 0;
|
|
531
|
|
532 check_status (tt_message_arg_bval (m, n, &value, &len));
|
|
533
|
|
534 return make_string (value, len);
|
|
535 }
|
|
536
|
|
537 DEFUN ("get-tooltalk-message-attribute", Fget_tooltalk_message_attribute,
|
|
538 2, 3, 0, /*
|
|
539 Return the indicated Tooltalk message attribute. Attributes are
|
|
540 identified by symbols with the same name (underscores and all) as the
|
|
541 suffix of the Tooltalk tt_message_<attribute> function that extracts the value.
|
|
542 String attribute values are copied, enumerated type values (except disposition)
|
|
543 are converted to symbols - e.g. TT_HANDLER is 'TT_HANDLER, uid and gid are
|
|
544 represented by fixnums (small integers), opnum is converted to a string,
|
|
545 and disposition is converted to a fixnum. We convert opnum (a C int) to a
|
|
546 string, e.g. 123 => "123" because there's no guarantee that opnums will fit
|
|
547 within the range of Lisp integers.
|
|
548
|
|
549 Use the 'plist attribute instead of the C API 'user attribute
|
|
550 for user defined message data. To retrieve the value of a message property
|
|
551 specify the indicator for argn. For example to get the value of a property
|
|
552 called 'rflag, use
|
|
553 (get-tooltalk-message-attribute message 'plist 'rflag)
|
|
554
|
|
555 To get the value of a message argument use one of the 'arg_val (strings),
|
|
556 'arg_ival (integers), or 'arg_bval (strings with embedded nulls), attributes.
|
|
557 For example to get the integer value of the third argument:
|
|
558
|
|
559 (get-tooltalk-message-attribute message 'arg_ival 2)
|
|
560
|
|
561 As you can see, argument numbers are zero based. The type of each argument
|
|
562 can be retrieved with the 'arg_type attribute; however, Tooltalk doesn't
|
|
563 define any semantics for the string value of 'arg_type. Conventionally
|
|
564 "string" is used for strings and "int" for 32 bit integers. Note that
|
|
565 Emacs Lisp stores the lengths of strings explicitly (unlike C) so treating the
|
|
566 value returned by 'arg_bval like a string is fine.
|
|
567 */
|
|
568 (message_, attribute, argn))
|
|
569 {
|
|
570 Tt_message m = unbox_tooltalk_message (message_);
|
|
571 int n = 0;
|
|
572
|
|
573 CHECK_SYMBOL (attribute);
|
|
574 if (EQ (attribute, (Qtt_arg_bval)) ||
|
|
575 EQ (attribute, (Qtt_arg_ival)) ||
|
|
576 EQ (attribute, (Qtt_arg_mode)) ||
|
|
577 EQ (attribute, (Qtt_arg_type)) ||
|
|
578 EQ (attribute, (Qtt_arg_val)))
|
|
579 {
|
|
580 CHECK_INT (argn);
|
|
581 n = XINT (argn);
|
|
582 }
|
|
583
|
|
584 if (!VALID_TOOLTALK_MESSAGEP (m))
|
|
585 return Qnil;
|
|
586
|
|
587 else if (EQ (attribute, Qtt_arg_bval))
|
|
588 return tt_message_arg_bval_vector (m, n);
|
|
589
|
|
590 else if (EQ (attribute, Qtt_arg_ival))
|
|
591 return tt_message_arg_ival_string (m, n);
|
|
592
|
|
593 else if (EQ (attribute, Qtt_arg_mode))
|
|
594 return tt_mode_symbol (tt_message_arg_mode (m, n));
|
|
595
|
|
596 else if (EQ (attribute, Qtt_arg_type))
|
771
|
597 return tt_build_c_string (tt_message_arg_type (m, n));
|
428
|
598
|
|
599 else if (EQ (attribute, Qtt_arg_val))
|
|
600 return tt_message_arg_bval_vector (m, n);
|
|
601
|
|
602 else if (EQ (attribute, Qtt_args_count))
|
|
603 return make_int (tt_message_args_count (m));
|
|
604
|
|
605 else if (EQ (attribute, Qtt_address))
|
|
606 return tt_address_symbol (tt_message_address (m));
|
|
607
|
|
608 else if (EQ (attribute, Qtt_class))
|
|
609 return tt_class_symbol (tt_message_class (m));
|
|
610
|
|
611 else if (EQ (attribute, Qtt_disposition))
|
|
612 return make_int (tt_message_disposition (m));
|
|
613
|
|
614 else if (EQ (attribute, Qtt_file))
|
771
|
615 return tt_build_c_string (tt_message_file (m));
|
428
|
616
|
|
617 else if (EQ (attribute, Qtt_gid))
|
|
618 return make_int (tt_message_gid (m));
|
|
619
|
|
620 else if (EQ (attribute, Qtt_handler))
|
771
|
621 return tt_build_c_string (tt_message_handler (m));
|
428
|
622
|
|
623 else if (EQ (attribute, Qtt_handler_ptype))
|
771
|
624 return tt_build_c_string (tt_message_handler_ptype (m));
|
428
|
625
|
|
626 else if (EQ (attribute, Qtt_object))
|
771
|
627 return tt_build_c_string (tt_message_object (m));
|
428
|
628
|
|
629 else if (EQ (attribute, Qtt_op))
|
771
|
630 return tt_build_c_string (tt_message_op (m));
|
428
|
631
|
|
632 else if (EQ (attribute, Qtt_opnum))
|
|
633 return tt_opnum_string (tt_message_opnum (m));
|
|
634
|
|
635 else if (EQ (attribute, Qtt_otype))
|
771
|
636 return tt_build_c_string (tt_message_otype (m));
|
428
|
637
|
|
638 else if (EQ (attribute, Qtt_scope))
|
|
639 return tt_scope_symbol (tt_message_scope (m));
|
|
640
|
|
641 else if (EQ (attribute, Qtt_sender))
|
771
|
642 return tt_build_c_string (tt_message_sender (m));
|
428
|
643
|
|
644 else if (EQ (attribute, Qtt_sender_ptype))
|
771
|
645 return tt_build_c_string (tt_message_sender_ptype (m));
|
428
|
646
|
|
647 else if (EQ (attribute, Qtt_session))
|
771
|
648 return tt_build_c_string (tt_message_session (m));
|
428
|
649
|
|
650 else if (EQ (attribute, Qtt_state))
|
|
651 return tt_state_symbol (tt_message_state (m));
|
|
652
|
|
653 else if (EQ (attribute, Qtt_status))
|
|
654 return make_int (tt_message_status (m));
|
|
655
|
|
656 else if (EQ (attribute, Qtt_status_string))
|
771
|
657 return tt_build_c_string (tt_message_status_string (m));
|
428
|
658
|
|
659 else if (EQ (attribute, Qtt_uid))
|
|
660 return make_int (tt_message_uid (m));
|
|
661
|
|
662 else if (EQ (attribute, Qtt_callback))
|
|
663 return XTOOLTALK_MESSAGE (message_)->callback;
|
|
664
|
|
665 else if (EQ (attribute, Qtt_prop))
|
|
666 return Fget (XTOOLTALK_MESSAGE (message_)->plist_sym, argn, Qnil);
|
|
667
|
|
668 else if (EQ (attribute, Qtt_plist))
|
|
669 return Fcopy_sequence (Fsymbol_plist
|
|
670 (XTOOLTALK_MESSAGE (message_)->plist_sym));
|
|
671
|
|
672 else
|
563
|
673 invalid_constant ("Invalid value for `get-tooltalk-message-attribute'",
|
428
|
674 attribute);
|
|
675
|
|
676 return Qnil;
|
|
677 }
|
|
678
|
|
679 DEFUN ("set-tooltalk-message-attribute", Fset_tooltalk_message_attribute,
|
|
680 3, 4, 0, /*
|
|
681 Initialize one Tooltalk message attribute.
|
|
682
|
|
683 Attribute names and values are the same as for
|
|
684 `get-tooltalk-message-attribute'. A property list is provided for user
|
|
685 data (instead of the 'user message attribute); see
|
|
686 `get-tooltalk-message-attribute'.
|
|
687
|
|
688 The value of callback should be the name of a function of one argument.
|
|
689 It will be applied to the message and matching pattern each time the state of the
|
|
690 message changes. This is usually used to notice when the messages state has
|
|
691 changed to TT_HANDLED (or TT_FAILED), so that reply argument values
|
|
692 can be used.
|
|
693
|
|
694 If one of the argument attributes is specified, 'arg_val, 'arg_ival, or
|
|
695 'arg_bval then argn must be the number of an already created argument.
|
|
696 New arguments can be added to a message with add-tooltalk-message-arg.
|
|
697 */
|
|
698 (value, message_, attribute, argn))
|
|
699 {
|
|
700 Tt_message m = unbox_tooltalk_message (message_);
|
|
701 int n = 0;
|
440
|
702 Tt_status (*fun_str) (Tt_message, const char *) = 0;
|
428
|
703
|
|
704 CHECK_SYMBOL (attribute);
|
440
|
705
|
428
|
706 if (EQ (attribute, (Qtt_arg_bval)) ||
|
|
707 EQ (attribute, (Qtt_arg_ival)) ||
|
|
708 EQ (attribute, (Qtt_arg_val)))
|
|
709 {
|
|
710 CHECK_INT (argn);
|
|
711 n = XINT (argn);
|
|
712 }
|
|
713
|
|
714 if (!VALID_TOOLTALK_MESSAGEP (m))
|
|
715 return Qnil;
|
|
716
|
440
|
717 if (EQ (attribute, Qtt_address))
|
428
|
718 {
|
|
719 CHECK_TOOLTALK_CONSTANT (value);
|
|
720 tt_message_address_set (m, (Tt_address) tooltalk_constant_value (value));
|
|
721 }
|
|
722 else if (EQ (attribute, Qtt_class))
|
|
723 {
|
|
724 CHECK_TOOLTALK_CONSTANT (value);
|
|
725 tt_message_class_set (m, (Tt_class) tooltalk_constant_value (value));
|
|
726 }
|
|
727 else if (EQ (attribute, Qtt_disposition))
|
|
728 {
|
|
729 CHECK_TOOLTALK_CONSTANT (value);
|
|
730 tt_message_disposition_set (m, ((Tt_disposition)
|
|
731 tooltalk_constant_value (value)));
|
|
732 }
|
|
733 else if (EQ (attribute, Qtt_scope))
|
|
734 {
|
|
735 CHECK_TOOLTALK_CONSTANT (value);
|
|
736 tt_message_scope_set (m, (Tt_scope) tooltalk_constant_value (value));
|
|
737 }
|
440
|
738 else if (EQ (attribute, Qtt_file))
|
|
739 fun_str = tt_message_file_set;
|
|
740 else if (EQ (attribute, Qtt_handler_ptype))
|
|
741 fun_str = tt_message_handler_ptype_set;
|
|
742 else if (EQ (attribute, Qtt_handler))
|
|
743 fun_str = tt_message_handler_set;
|
|
744 else if (EQ (attribute, Qtt_object))
|
|
745 fun_str = tt_message_object_set;
|
|
746 else if (EQ (attribute, Qtt_op))
|
|
747 fun_str = tt_message_op_set;
|
|
748 else if (EQ (attribute, Qtt_otype))
|
|
749 fun_str = tt_message_otype_set;
|
428
|
750 else if (EQ (attribute, Qtt_sender_ptype))
|
440
|
751 fun_str = tt_message_sender_ptype_set;
|
428
|
752 else if (EQ (attribute, Qtt_session))
|
440
|
753 fun_str = tt_message_session_set;
|
|
754 else if (EQ (attribute, Qtt_status_string))
|
|
755 fun_str = tt_message_status_string_set;
|
428
|
756 else if (EQ (attribute, Qtt_arg_bval))
|
|
757 {
|
|
758 Extbyte *value_ext;
|
665
|
759 Bytecount value_ext_len;
|
428
|
760 CHECK_STRING (value);
|
440
|
761 TO_EXTERNAL_FORMAT (LISP_STRING, value,
|
|
762 ALLOCA, (value_ext, value_ext_len),
|
|
763 Qnative);
|
444
|
764 tt_message_arg_bval_set (m, n, (unsigned char *) value_ext, value_ext_len);
|
428
|
765 }
|
|
766 else if (EQ (attribute, Qtt_arg_ival))
|
|
767 {
|
|
768 CHECK_INT (value);
|
|
769 tt_message_arg_ival_set (m, n, XINT (value));
|
|
770 }
|
|
771 else if (EQ (attribute, Qtt_arg_val))
|
|
772 {
|
442
|
773 const char *value_ext;
|
428
|
774 CHECK_STRING (value);
|
442
|
775 LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
|
428
|
776 tt_message_arg_val_set (m, n, value_ext);
|
|
777 }
|
|
778 else if (EQ (attribute, Qtt_status))
|
|
779 {
|
|
780 CHECK_INT (value);
|
|
781 tt_message_status_set (m, XINT (value));
|
|
782 }
|
|
783 else if (EQ (attribute, Qtt_callback))
|
|
784 {
|
|
785 CHECK_SYMBOL (value);
|
|
786 XTOOLTALK_MESSAGE (message_)->callback = value;
|
|
787 }
|
|
788 else if (EQ (attribute, Qtt_prop))
|
|
789 {
|
|
790 return Fput (XTOOLTALK_MESSAGE (message_)->plist_sym, argn, value);
|
|
791 }
|
|
792 else
|
563
|
793 invalid_constant ("Invalid value for `set-tooltalk-message-attribute'",
|
428
|
794 attribute);
|
440
|
795
|
|
796 if (fun_str)
|
|
797 {
|
442
|
798 const char *value_ext;
|
440
|
799 CHECK_STRING (value);
|
442
|
800 LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
|
440
|
801 (*fun_str) (m, value_ext);
|
|
802 }
|
|
803
|
428
|
804 return Qnil;
|
|
805 }
|
|
806
|
|
807 DEFUN ("return-tooltalk-message", Freturn_tooltalk_message, 1, 2, 0, /*
|
|
808 Send a reply to this message. The second argument can be
|
|
809 'reply, 'reject or 'fail; the default is 'reply. Before sending
|
|
810 a reply all message arguments whose mode is TT_INOUT or TT_OUT should
|
|
811 have been filled in - see set-tooltalk-message-attribute.
|
|
812 */
|
|
813 (message_, mode))
|
|
814 {
|
|
815 Tt_message m = unbox_tooltalk_message (message_);
|
|
816
|
|
817 if (NILP (mode))
|
|
818 mode = Qtt_reply;
|
|
819 else
|
|
820 CHECK_SYMBOL (mode);
|
|
821
|
|
822 if (!VALID_TOOLTALK_MESSAGEP (m))
|
|
823 return Qnil;
|
|
824 else if (EQ (mode, Qtt_reply))
|
|
825 tt_message_reply (m);
|
|
826 else if (EQ (mode, Qtt_reject))
|
|
827 tt_message_reject (m);
|
|
828 else if (EQ (mode, Qtt_fail))
|
|
829 tt_message_fail (m);
|
|
830
|
|
831 return Qnil;
|
|
832 }
|
|
833
|
|
834 DEFUN ("create-tooltalk-message", Fcreate_tooltalk_message, 0, 1, 0, /*
|
|
835 Create a new tooltalk message.
|
|
836 The messages session attribute is initialized to the default session.
|
|
837 Other attributes can be initialized with `set-tooltalk-message-attribute'.
|
|
838 `make-tooltalk-message' is the preferred to create and initialize a message.
|
|
839
|
|
840 Optional arg NO-CALLBACK says don't add a C-level callback at all.
|
|
841 Normally don't do that; just don't specify the Lisp callback when
|
|
842 calling `make-tooltalk-message'.
|
|
843 */
|
|
844 (no_callback))
|
|
845 {
|
|
846 Tt_message m = tt_message_create ();
|
|
847 Lisp_Object message_ = make_tooltalk_message (m);
|
|
848 if (NILP (no_callback))
|
|
849 {
|
|
850 tt_message_callback_add (m, tooltalk_message_callback);
|
|
851 }
|
|
852 tt_message_session_set (m, tt_default_session ());
|
|
853 tt_message_user_set (m, TOOLTALK_MESSAGE_KEY, LISP_TO_VOID (message_));
|
|
854 return message_;
|
|
855 }
|
|
856
|
|
857 DEFUN ("destroy-tooltalk-message", Fdestroy_tooltalk_message, 1, 1, 0, /*
|
|
858 Apply tt_message_destroy() to the message.
|
|
859 It's not necessary to destroy messages after they've been processed by
|
|
860 a message or pattern callback; the Lisp/Tooltalk callback machinery does
|
|
861 this for you.
|
|
862 */
|
|
863 (message_))
|
|
864 {
|
|
865 Tt_message m = unbox_tooltalk_message (message_);
|
|
866
|
|
867 if (VALID_TOOLTALK_MESSAGEP (m))
|
|
868 /* #### Should we call Fremhash() here? It seems that
|
|
869 a common paradigm is
|
|
870
|
|
871 (send-tooltalk-message)
|
|
872 (destroy-tooltalk-message)
|
|
873
|
|
874 which would imply that destroying a sent ToolTalk message
|
|
875 doesn't actually destroy it; when a response is sent back,
|
|
876 the callback for the message will still be called.
|
|
877
|
|
878 But then maybe not: Maybe it really does destroy it,
|
|
879 and the reason for that paradigm is that the author
|
|
880 of `send-tooltalk-message' didn't really know what he
|
|
881 was talking about when he said that it's a good idea
|
|
882 to call `destroy-tooltalk-message' after sending it. */
|
|
883 tt_message_destroy (m);
|
|
884
|
|
885 return Qnil;
|
|
886 }
|
|
887
|
|
888
|
|
889 DEFUN ("add-tooltalk-message-arg", Fadd_tooltalk_message_arg, 3, 4, 0, /*
|
|
890 Append one new argument to the message.
|
|
891 MODE must be one of TT_IN, TT_INOUT, or TT_OUT; VTYPE must be a string;
|
|
892 and VALUE can be a string or an integer. Tooltalk doesn't
|
|
893 define any semantics for VTYPE, so only the participants in the
|
|
894 protocol you're using need to agree what types mean (if anything).
|
|
895 Conventionally "string" is used for strings and "int" for 32 bit integers.
|
|
896 Arguments can initialized by providing a value or with
|
|
897 `set-tooltalk-message-attribute'. The latter is necessary if you
|
|
898 want to initialize the argument with a string that can contain
|
|
899 embedded nulls (use 'arg_bval).
|
|
900 */
|
|
901 (message_, mode, vtype, value))
|
|
902 {
|
|
903 Tt_message m = unbox_tooltalk_message (message_);
|
|
904 Tt_mode n;
|
|
905
|
|
906 CHECK_STRING (vtype);
|
|
907 CHECK_TOOLTALK_CONSTANT (mode);
|
|
908
|
|
909 n = (Tt_mode) tooltalk_constant_value (mode);
|
|
910
|
|
911 if (!VALID_TOOLTALK_MESSAGEP (m))
|
|
912 return Qnil;
|
|
913 {
|
442
|
914 const char *vtype_ext;
|
428
|
915
|
442
|
916 LISP_STRING_TO_EXTERNAL (vtype, vtype_ext, Qnative);
|
428
|
917 if (NILP (value))
|
|
918 tt_message_arg_add (m, n, vtype_ext, NULL);
|
|
919 else if (STRINGP (value))
|
|
920 {
|
442
|
921 const char *value_ext;
|
|
922 LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
|
428
|
923 tt_message_arg_add (m, n, vtype_ext, value_ext);
|
|
924 }
|
|
925 else if (INTP (value))
|
|
926 tt_message_iarg_add (m, n, vtype_ext, XINT (value));
|
|
927 }
|
|
928
|
|
929 return Qnil;
|
|
930 }
|
|
931
|
|
932 DEFUN ("send-tooltalk-message", Fsend_tooltalk_message, 1, 1, 0, /*
|
|
933 Send the message on its way.
|
|
934 Once the message has been sent it's almost always a good idea to get rid of
|
|
935 it with `destroy-tooltalk-message'.
|
|
936 */
|
|
937 (message_))
|
|
938 {
|
|
939 Tt_message m = unbox_tooltalk_message (message_);
|
|
940
|
|
941 if (VALID_TOOLTALK_MESSAGEP (m))
|
|
942 {
|
|
943 tt_message_send (m);
|
|
944 Fputhash (message_, Qnil, Vtooltalk_message_gcpro);
|
|
945 }
|
|
946
|
|
947 return Qnil;
|
|
948 }
|
|
949
|
|
950 DEFUN ("create-tooltalk-pattern", Fcreate_tooltalk_pattern, 0, 0, 0, /*
|
|
951 Create a new Tooltalk pattern.
|
|
952 Its session attribute is initialized to be the default session.
|
|
953 */
|
|
954 ())
|
|
955 {
|
|
956 Tt_pattern p = tt_pattern_create ();
|
|
957 Lisp_Object pattern = make_tooltalk_pattern (p);
|
|
958
|
|
959 tt_pattern_callback_add (p, tooltalk_pattern_callback);
|
|
960 tt_pattern_session_add (p, tt_default_session ());
|
|
961 tt_pattern_user_set (p, TOOLTALK_PATTERN_KEY, LISP_TO_VOID (pattern));
|
|
962
|
|
963 return pattern;
|
|
964 }
|
|
965
|
|
966
|
|
967 DEFUN ("destroy-tooltalk-pattern", Fdestroy_tooltalk_pattern, 1, 1, 0, /*
|
|
968 Apply tt_pattern_destroy() to the pattern.
|
|
969 This effectively unregisters the pattern.
|
|
970 */
|
|
971 (pattern))
|
|
972 {
|
|
973 Tt_pattern p = unbox_tooltalk_pattern (pattern);
|
|
974
|
|
975 if (VALID_TOOLTALK_PATTERNP (p))
|
|
976 {
|
|
977 tt_pattern_destroy (p);
|
|
978 Fremhash (pattern, Vtooltalk_pattern_gcpro);
|
|
979 }
|
|
980
|
|
981 return Qnil;
|
|
982 }
|
|
983
|
|
984
|
|
985 DEFUN ("add-tooltalk-pattern-attribute", Fadd_tooltalk_pattern_attribute, 3, 3, 0, /*
|
|
986 Add one value to the indicated pattern attribute.
|
|
987 All Tooltalk pattern attributes are supported except 'user. The names
|
|
988 of attributes are the same as the Tooltalk accessors used to set them
|
|
989 less the "tooltalk_pattern_" prefix and the "_add" ...
|
|
990 */
|
|
991 (value, pattern, attribute))
|
|
992 {
|
|
993 Tt_pattern p = unbox_tooltalk_pattern (pattern);
|
|
994
|
|
995 CHECK_SYMBOL (attribute);
|
|
996
|
|
997 if (!VALID_TOOLTALK_PATTERNP (p))
|
|
998 return Qnil;
|
|
999
|
|
1000 else if (EQ (attribute, Qtt_category))
|
|
1001 {
|
|
1002 CHECK_TOOLTALK_CONSTANT (value);
|
|
1003 tt_pattern_category_set (p, ((Tt_category)
|
|
1004 tooltalk_constant_value (value)));
|
|
1005 }
|
|
1006 else if (EQ (attribute, Qtt_address))
|
|
1007 {
|
|
1008 CHECK_TOOLTALK_CONSTANT (value);
|
|
1009 tt_pattern_address_add (p, ((Tt_address)
|
|
1010 tooltalk_constant_value (value)));
|
|
1011 }
|
|
1012 else if (EQ (attribute, Qtt_class))
|
|
1013 {
|
|
1014 CHECK_TOOLTALK_CONSTANT (value);
|
|
1015 tt_pattern_class_add (p, (Tt_class) tooltalk_constant_value (value));
|
|
1016 }
|
|
1017 else if (EQ (attribute, Qtt_disposition))
|
|
1018 {
|
|
1019 CHECK_TOOLTALK_CONSTANT (value);
|
|
1020 tt_pattern_disposition_add (p, ((Tt_disposition)
|
|
1021 tooltalk_constant_value (value)));
|
|
1022 }
|
|
1023 else if (EQ (attribute, Qtt_file))
|
|
1024 {
|
442
|
1025 const char *value_ext;
|
428
|
1026 CHECK_STRING (value);
|
442
|
1027 LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
|
428
|
1028 tt_pattern_file_add (p, value_ext);
|
|
1029 }
|
|
1030 else if (EQ (attribute, Qtt_object))
|
|
1031 {
|
442
|
1032 const char *value_ext;
|
428
|
1033 CHECK_STRING (value);
|
442
|
1034 LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
|
428
|
1035 tt_pattern_object_add (p, value_ext);
|
|
1036 }
|
|
1037 else if (EQ (attribute, Qtt_op))
|
|
1038 {
|
442
|
1039 const char *value_ext;
|
428
|
1040 CHECK_STRING (value);
|
442
|
1041 LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
|
428
|
1042 tt_pattern_op_add (p, value_ext);
|
|
1043 }
|
|
1044 else if (EQ (attribute, Qtt_otype))
|
|
1045 {
|
442
|
1046 const char *value_ext;
|
428
|
1047 CHECK_STRING (value);
|
442
|
1048 LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
|
428
|
1049 tt_pattern_otype_add (p, value_ext);
|
|
1050 }
|
|
1051 else if (EQ (attribute, Qtt_scope))
|
|
1052 {
|
|
1053 CHECK_TOOLTALK_CONSTANT (value);
|
|
1054 tt_pattern_scope_add (p, (Tt_scope) tooltalk_constant_value (value));
|
|
1055 }
|
|
1056 else if (EQ (attribute, Qtt_sender))
|
|
1057 {
|
442
|
1058 const char *value_ext;
|
428
|
1059 CHECK_STRING (value);
|
442
|
1060 LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
|
428
|
1061 tt_pattern_sender_add (p, value_ext);
|
|
1062 }
|
|
1063 else if (EQ (attribute, Qtt_sender_ptype))
|
|
1064 {
|
442
|
1065 const char *value_ext;
|
428
|
1066 CHECK_STRING (value);
|
442
|
1067 LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
|
428
|
1068 tt_pattern_sender_ptype_add (p, value_ext);
|
|
1069 }
|
|
1070 else if (EQ (attribute, Qtt_session))
|
|
1071 {
|
442
|
1072 const char *value_ext;
|
428
|
1073 CHECK_STRING (value);
|
442
|
1074 LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
|
428
|
1075 tt_pattern_session_add (p, value_ext);
|
|
1076 }
|
|
1077 else if (EQ (attribute, Qtt_state))
|
|
1078 {
|
|
1079 CHECK_TOOLTALK_CONSTANT (value);
|
|
1080 tt_pattern_state_add (p, (Tt_state) tooltalk_constant_value (value));
|
|
1081 }
|
|
1082 else if (EQ (attribute, Qtt_callback))
|
|
1083 {
|
|
1084 CHECK_SYMBOL (value);
|
|
1085 XTOOLTALK_PATTERN (pattern)->callback = value;
|
|
1086 }
|
|
1087
|
|
1088 return Qnil;
|
|
1089 }
|
|
1090
|
|
1091
|
|
1092 DEFUN ("add-tooltalk-pattern-arg", Fadd_tooltalk_pattern_arg, 3, 4, 0, /*
|
|
1093 Add one fully specified argument to a tooltalk pattern.
|
|
1094 Mode must be one of TT_IN, TT_INOUT, or TT_OUT, type must be a string.
|
|
1095 Value can be an integer, string or nil. If value is an integer then
|
|
1096 an integer argument (tt_pattern_iarg_add) added otherwise a string argument
|
|
1097 is added. At present there's no way to add a binary data argument.
|
|
1098 */
|
|
1099 (pattern, mode, vtype, value))
|
|
1100 {
|
|
1101 Tt_pattern p = unbox_tooltalk_pattern (pattern);
|
|
1102 Tt_mode n;
|
|
1103
|
|
1104 CHECK_STRING (vtype);
|
|
1105 CHECK_TOOLTALK_CONSTANT (mode);
|
|
1106
|
|
1107 n = (Tt_mode) tooltalk_constant_value (mode);
|
|
1108
|
|
1109 if (!VALID_TOOLTALK_PATTERNP (p))
|
|
1110 return Qnil;
|
|
1111
|
|
1112 {
|
442
|
1113 const char *vtype_ext;
|
428
|
1114
|
442
|
1115 LISP_STRING_TO_EXTERNAL (vtype, vtype_ext, Qnative);
|
428
|
1116 if (NILP (value))
|
|
1117 tt_pattern_arg_add (p, n, vtype_ext, NULL);
|
|
1118 else if (STRINGP (value))
|
|
1119 {
|
442
|
1120 const char *value_ext;
|
|
1121 LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
|
428
|
1122 tt_pattern_arg_add (p, n, vtype_ext, value_ext);
|
|
1123 }
|
|
1124 else if (INTP (value))
|
|
1125 tt_pattern_iarg_add (p, n, vtype_ext, XINT (value));
|
|
1126 }
|
|
1127
|
|
1128 return Qnil;
|
|
1129 }
|
|
1130
|
|
1131
|
|
1132 DEFUN ("register-tooltalk-pattern", Fregister_tooltalk_pattern, 1, 1, 0, /*
|
|
1133 Emacs will begin receiving messages that match this pattern.
|
|
1134 */
|
|
1135 (pattern))
|
|
1136 {
|
|
1137 Tt_pattern p = unbox_tooltalk_pattern (pattern);
|
|
1138
|
|
1139 if (VALID_TOOLTALK_PATTERNP (p) && tt_pattern_register (p) == TT_OK)
|
|
1140 {
|
|
1141 Fputhash (pattern, Qnil, Vtooltalk_pattern_gcpro);
|
|
1142 return Qt;
|
|
1143 }
|
|
1144 else
|
|
1145 return Qnil;
|
|
1146 }
|
|
1147
|
|
1148
|
|
1149 DEFUN ("unregister-tooltalk-pattern", Funregister_tooltalk_pattern, 1, 1, 0, /*
|
|
1150 Emacs will stop receiving messages that match this pattern.
|
|
1151 */
|
|
1152 (pattern))
|
|
1153 {
|
|
1154 Tt_pattern p = unbox_tooltalk_pattern (pattern);
|
|
1155
|
|
1156 if (VALID_TOOLTALK_PATTERNP (p))
|
|
1157 {
|
|
1158 tt_pattern_unregister (p);
|
|
1159 Fremhash (pattern, Vtooltalk_pattern_gcpro);
|
|
1160 }
|
|
1161
|
|
1162 return Qnil;
|
|
1163 }
|
|
1164
|
|
1165
|
|
1166 DEFUN ("tooltalk-pattern-prop-get", Ftooltalk_pattern_prop_get, 2, 2, 0, /*
|
|
1167 Return the value of PROPERTY in tooltalk pattern PATTERN.
|
|
1168 This is the last value set with `tooltalk-pattern-prop-set'.
|
|
1169 */
|
|
1170 (pattern, property))
|
|
1171 {
|
|
1172 CHECK_TOOLTALK_PATTERN (pattern);
|
|
1173 return Fget (XTOOLTALK_PATTERN (pattern)->plist_sym, property, Qnil);
|
|
1174 }
|
|
1175
|
|
1176
|
|
1177 DEFUN ("tooltalk-pattern-prop-set", Ftooltalk_pattern_prop_set, 3, 3, 0, /*
|
|
1178 Set the value of PROPERTY to VALUE in tooltalk pattern PATTERN.
|
|
1179 It can be retrieved with `tooltalk-pattern-prop-get'.
|
|
1180 */
|
|
1181 (pattern, property, value))
|
|
1182 {
|
|
1183 CHECK_TOOLTALK_PATTERN (pattern);
|
|
1184 return Fput (XTOOLTALK_PATTERN (pattern)->plist_sym, property, value);
|
|
1185 }
|
|
1186
|
|
1187
|
|
1188 DEFUN ("tooltalk-pattern-plist-get", Ftooltalk_pattern_plist_get, 1, 1, 0, /*
|
|
1189 Return the a list of all the properties currently set in PATTERN.
|
|
1190 */
|
|
1191 (pattern))
|
|
1192 {
|
|
1193 CHECK_TOOLTALK_PATTERN (pattern);
|
|
1194 return
|
|
1195 Fcopy_sequence (Fsymbol_plist (XTOOLTALK_PATTERN (pattern)->plist_sym));
|
|
1196 }
|
|
1197
|
|
1198 DEFUN ("tooltalk-default-procid", Ftooltalk_default_procid, 0, 0, 0, /*
|
|
1199 Return current default process identifier for your process.
|
|
1200 */
|
|
1201 ())
|
|
1202 {
|
|
1203 char *procid = tt_default_procid ();
|
|
1204 return procid ? build_string (procid) : Qnil;
|
|
1205 }
|
|
1206
|
|
1207 DEFUN ("tooltalk-default-session", Ftooltalk_default_session, 0, 0, 0, /*
|
|
1208 Return current default session identifier for the current default procid.
|
|
1209 */
|
|
1210 ())
|
|
1211 {
|
|
1212 char *session = tt_default_session ();
|
|
1213 return session ? build_string (session) : Qnil;
|
|
1214 }
|
|
1215
|
|
1216 static void
|
|
1217 init_tooltalk (void)
|
|
1218 {
|
|
1219 /* This function can GC */
|
|
1220 char *retval;
|
|
1221 Lisp_Object lp;
|
|
1222 Lisp_Object fil;
|
|
1223
|
|
1224
|
440
|
1225 /* tt_open() messes with our signal handler flags (at least when no
|
|
1226 ttsessions is running on the machine), therefore we save the
|
428
|
1227 actions and restore them after the call */
|
|
1228 #ifdef HAVE_SIGPROCMASK
|
|
1229 {
|
|
1230 struct sigaction ActSIGQUIT;
|
|
1231 struct sigaction ActSIGINT;
|
|
1232 struct sigaction ActSIGCHLD;
|
|
1233 sigaction (SIGQUIT, NULL, &ActSIGQUIT);
|
|
1234 sigaction (SIGINT, NULL, &ActSIGINT);
|
|
1235 sigaction (SIGCHLD, NULL, &ActSIGCHLD);
|
|
1236 #endif
|
|
1237 retval = tt_open ();
|
|
1238 #ifdef HAVE_SIGPROCMASK
|
|
1239 sigaction (SIGQUIT, &ActSIGQUIT, NULL);
|
|
1240 sigaction (SIGINT, &ActSIGINT, NULL);
|
|
1241 sigaction (SIGCHLD, &ActSIGCHLD, NULL);
|
|
1242 }
|
|
1243 #endif
|
|
1244
|
|
1245
|
|
1246 if (tt_ptr_error (retval) != TT_OK)
|
|
1247 return;
|
|
1248
|
|
1249 Vtooltalk_fd = make_int (tt_fd ());
|
|
1250
|
|
1251 tt_session_join (tt_default_session ());
|
|
1252
|
|
1253 lp = connect_to_file_descriptor (build_string ("tooltalk"), Qnil,
|
|
1254 Vtooltalk_fd, Vtooltalk_fd);
|
|
1255 if (!NILP (lp))
|
|
1256 {
|
|
1257 /* Don't ask the user for confirmation when exiting Emacs */
|
|
1258 Fprocess_kill_without_query (lp, Qnil);
|
793
|
1259 fil = wrap_subr (&SFreceive_tooltalk_message);
|
428
|
1260 set_process_filter (lp, fil, 1);
|
|
1261 }
|
|
1262 else
|
|
1263 {
|
|
1264 tt_close ();
|
|
1265 Vtooltalk_fd = Qnil;
|
|
1266 return;
|
|
1267 }
|
|
1268
|
|
1269 #if defined (SOLARIS2)
|
|
1270 /* Apparently the tt_message_send_on_exit() function does not exist
|
|
1271 under SunOS 4.x or IRIX 5 or various other non-Solaris-2 systems.
|
|
1272 No big deal if we don't do the following under those systems. */
|
|
1273 {
|
|
1274 Tt_message exit_msg = tt_message_create ();
|
|
1275
|
|
1276 tt_message_op_set (exit_msg, "emacs-aborted");
|
|
1277 tt_message_scope_set (exit_msg, TT_SESSION);
|
|
1278 tt_message_class_set (exit_msg, TT_NOTICE);
|
|
1279 tt_message_send_on_exit (exit_msg);
|
|
1280 tt_message_destroy (exit_msg);
|
|
1281 }
|
|
1282 #endif
|
|
1283 }
|
|
1284
|
|
1285 DEFUN ("tooltalk-open-connection", Ftooltalk_open_connection, 0, 0, 0, /*
|
|
1286 Opens a connection to the ToolTalk server.
|
|
1287 Returns t if successful, nil otherwise.
|
|
1288 */
|
|
1289 ())
|
|
1290 {
|
|
1291 if (!NILP (Vtooltalk_fd))
|
563
|
1292 signal_error (Qio_error, "Already connected to ToolTalk", Qunbound);
|
428
|
1293 if (noninteractive)
|
563
|
1294 signal_error (Qio_error, "Can't connect to ToolTalk in batch mode", Qunbound);
|
428
|
1295 init_tooltalk ();
|
|
1296 return NILP (Vtooltalk_fd) ? Qnil : Qt;
|
|
1297 }
|
|
1298
|
|
1299
|
|
1300 void
|
|
1301 syms_of_tooltalk (void)
|
|
1302 {
|
442
|
1303 INIT_LRECORD_IMPLEMENTATION (tooltalk_message);
|
|
1304 INIT_LRECORD_IMPLEMENTATION (tooltalk_pattern);
|
|
1305
|
563
|
1306 DEFSYMBOL_MULTIWORD_PREDICATE (Qtooltalk_messagep);
|
428
|
1307 DEFSUBR (Ftooltalk_message_p);
|
563
|
1308 DEFSYMBOL_MULTIWORD_PREDICATE (Qtooltalk_patternp);
|
428
|
1309 DEFSUBR (Ftooltalk_pattern_p);
|
563
|
1310 DEFSYMBOL (Qtooltalk_message_handler_hook);
|
|
1311 DEFSYMBOL (Qtooltalk_pattern_handler_hook);
|
|
1312 DEFSYMBOL (Qtooltalk_unprocessed_message_hook);
|
428
|
1313
|
|
1314 DEFSUBR (Freceive_tooltalk_message);
|
|
1315 DEFSUBR (Fcreate_tooltalk_message);
|
|
1316 DEFSUBR (Fdestroy_tooltalk_message);
|
|
1317 DEFSUBR (Fadd_tooltalk_message_arg);
|
|
1318 DEFSUBR (Fget_tooltalk_message_attribute);
|
|
1319 DEFSUBR (Fset_tooltalk_message_attribute);
|
|
1320 DEFSUBR (Fsend_tooltalk_message);
|
|
1321 DEFSUBR (Freturn_tooltalk_message);
|
|
1322 DEFSUBR (Fcreate_tooltalk_pattern);
|
|
1323 DEFSUBR (Fdestroy_tooltalk_pattern);
|
|
1324 DEFSUBR (Fadd_tooltalk_pattern_attribute);
|
|
1325 DEFSUBR (Fadd_tooltalk_pattern_arg);
|
|
1326 DEFSUBR (Fregister_tooltalk_pattern);
|
|
1327 DEFSUBR (Funregister_tooltalk_pattern);
|
|
1328 DEFSUBR (Ftooltalk_pattern_plist_get);
|
|
1329 DEFSUBR (Ftooltalk_pattern_prop_set);
|
|
1330 DEFSUBR (Ftooltalk_pattern_prop_get);
|
|
1331 DEFSUBR (Ftooltalk_default_procid);
|
|
1332 DEFSUBR (Ftooltalk_default_session);
|
|
1333 DEFSUBR (Ftooltalk_open_connection);
|
|
1334
|
563
|
1335 DEFSYMBOL (Qreceive_tooltalk_message);
|
428
|
1336 defsymbol (&Qtt_address, "address");
|
|
1337 defsymbol (&Qtt_args_count, "args_count");
|
|
1338 defsymbol (&Qtt_arg_bval, "arg_bval");
|
|
1339 defsymbol (&Qtt_arg_ival, "arg_ival");
|
|
1340 defsymbol (&Qtt_arg_mode, "arg_mode");
|
|
1341 defsymbol (&Qtt_arg_type, "arg_type");
|
|
1342 defsymbol (&Qtt_arg_val, "arg_val");
|
|
1343 defsymbol (&Qtt_class, "class");
|
|
1344 defsymbol (&Qtt_category, "category");
|
|
1345 defsymbol (&Qtt_disposition, "disposition");
|
|
1346 defsymbol (&Qtt_file, "file");
|
|
1347 defsymbol (&Qtt_gid, "gid");
|
|
1348 defsymbol (&Qtt_handler, "handler");
|
|
1349 defsymbol (&Qtt_handler_ptype, "handler_ptype");
|
|
1350 defsymbol (&Qtt_object, "object");
|
|
1351 defsymbol (&Qtt_op, "op");
|
|
1352 defsymbol (&Qtt_opnum, "opnum");
|
|
1353 defsymbol (&Qtt_otype, "otype");
|
|
1354 defsymbol (&Qtt_scope, "scope");
|
|
1355 defsymbol (&Qtt_sender, "sender");
|
|
1356 defsymbol (&Qtt_sender_ptype, "sender_ptype");
|
|
1357 defsymbol (&Qtt_session, "session");
|
|
1358 defsymbol (&Qtt_state, "state");
|
|
1359 defsymbol (&Qtt_status, "status");
|
|
1360 defsymbol (&Qtt_status_string, "status_string");
|
|
1361 defsymbol (&Qtt_uid, "uid");
|
|
1362 defsymbol (&Qtt_callback, "callback");
|
|
1363 defsymbol (&Qtt_prop, "prop");
|
|
1364 defsymbol (&Qtt_plist, "plist");
|
|
1365 defsymbol (&Qtt_reject, "reject");
|
|
1366 defsymbol (&Qtt_reply, "reply");
|
|
1367 defsymbol (&Qtt_fail, "fail");
|
|
1368
|
442
|
1369 DEFERROR (Qtooltalk_error, "ToolTalk error", Qio_error);
|
428
|
1370 }
|
|
1371
|
|
1372 void
|
|
1373 vars_of_tooltalk (void)
|
|
1374 {
|
|
1375 Fprovide (intern ("tooltalk"));
|
|
1376
|
|
1377 DEFVAR_LISP ("tooltalk-fd", &Vtooltalk_fd /*
|
|
1378 File descriptor returned by tt_initialize; nil if not connected to ToolTalk.
|
|
1379 */ );
|
|
1380 Vtooltalk_fd = Qnil;
|
|
1381
|
|
1382 DEFVAR_LISP ("tooltalk-message-handler-hook",
|
|
1383 &Vtooltalk_message_handler_hook /*
|
|
1384 List of functions to be applied to each ToolTalk message reply received.
|
|
1385 This will always occur as a result of our sending a request message.
|
|
1386 Functions will be called with two arguments, the message and the
|
|
1387 corresponding pattern. This hook will not be called if the request
|
|
1388 message was created without a C-level callback function (see
|
|
1389 `tooltalk-unprocessed-message-hook').
|
|
1390 */ );
|
|
1391 Vtooltalk_message_handler_hook = Qnil;
|
|
1392
|
|
1393 DEFVAR_LISP ("tooltalk-pattern-handler-hook",
|
|
1394 &Vtooltalk_pattern_handler_hook /*
|
|
1395 List of functions to be applied to each pattern-matching ToolTalk message.
|
|
1396 This is all messages except those handled by `tooltalk-message-handler-hook'.
|
|
1397 Functions will be called with two arguments, the message and the
|
|
1398 corresponding pattern.
|
|
1399 */ );
|
|
1400 Vtooltalk_pattern_handler_hook = Qnil;
|
|
1401
|
|
1402 DEFVAR_LISP ("tooltalk-unprocessed-message-hook",
|
|
1403 &Vtooltalk_unprocessed_message_hook /*
|
|
1404 List of functions to be applied to each unprocessed ToolTalk message.
|
|
1405 Unprocessed messages are messages that didn't match any patterns.
|
|
1406 */ );
|
|
1407 Vtooltalk_unprocessed_message_hook = Qnil;
|
|
1408
|
771
|
1409 Tooltalk_Message_plist_str = build_msg_string ("Tooltalk Message plist");
|
|
1410 Tooltalk_Pattern_plist_str = build_msg_string ("Tooltalk Pattern plist");
|
428
|
1411
|
|
1412 staticpro(&Tooltalk_Message_plist_str);
|
|
1413 staticpro(&Tooltalk_Pattern_plist_str);
|
|
1414
|
|
1415 #define MAKE_CONSTANT(name) do { \
|
|
1416 defsymbol (&Q_ ## name, #name); \
|
|
1417 Fset (Q_ ## name, make_int (name)); \
|
|
1418 } while (0)
|
|
1419
|
|
1420 MAKE_CONSTANT (TT_MODE_UNDEFINED);
|
|
1421 MAKE_CONSTANT (TT_IN);
|
|
1422 MAKE_CONSTANT (TT_OUT);
|
|
1423 MAKE_CONSTANT (TT_INOUT);
|
|
1424 MAKE_CONSTANT (TT_MODE_LAST);
|
|
1425
|
|
1426 MAKE_CONSTANT (TT_SCOPE_NONE);
|
|
1427 MAKE_CONSTANT (TT_SESSION);
|
|
1428 MAKE_CONSTANT (TT_FILE);
|
|
1429 MAKE_CONSTANT (TT_BOTH);
|
|
1430 MAKE_CONSTANT (TT_FILE_IN_SESSION);
|
|
1431
|
|
1432 MAKE_CONSTANT (TT_CLASS_UNDEFINED);
|
|
1433 MAKE_CONSTANT (TT_NOTICE);
|
|
1434 MAKE_CONSTANT (TT_REQUEST);
|
|
1435 MAKE_CONSTANT (TT_CLASS_LAST);
|
|
1436
|
|
1437 MAKE_CONSTANT (TT_CATEGORY_UNDEFINED);
|
|
1438 MAKE_CONSTANT (TT_OBSERVE);
|
|
1439 MAKE_CONSTANT (TT_HANDLE);
|
|
1440 MAKE_CONSTANT (TT_CATEGORY_LAST);
|
|
1441
|
|
1442 MAKE_CONSTANT (TT_PROCEDURE);
|
|
1443 MAKE_CONSTANT (TT_OBJECT);
|
|
1444 MAKE_CONSTANT (TT_HANDLER);
|
|
1445 MAKE_CONSTANT (TT_OTYPE);
|
|
1446 MAKE_CONSTANT (TT_ADDRESS_LAST);
|
|
1447
|
|
1448 MAKE_CONSTANT (TT_CREATED);
|
|
1449 MAKE_CONSTANT (TT_SENT);
|
|
1450 MAKE_CONSTANT (TT_HANDLED);
|
|
1451 MAKE_CONSTANT (TT_FAILED);
|
|
1452 MAKE_CONSTANT (TT_QUEUED);
|
|
1453 MAKE_CONSTANT (TT_STARTED);
|
|
1454 MAKE_CONSTANT (TT_REJECTED);
|
|
1455 MAKE_CONSTANT (TT_STATE_LAST);
|
|
1456
|
|
1457 MAKE_CONSTANT (TT_DISCARD);
|
|
1458 MAKE_CONSTANT (TT_QUEUE);
|
|
1459 MAKE_CONSTANT (TT_START);
|
|
1460
|
|
1461 #undef MAKE_CONSTANT
|
|
1462
|
|
1463 staticpro (&Vtooltalk_message_gcpro);
|
|
1464 staticpro (&Vtooltalk_pattern_gcpro);
|
|
1465 Vtooltalk_message_gcpro =
|
|
1466 make_lisp_hash_table (10, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
|
|
1467 Vtooltalk_pattern_gcpro =
|
|
1468 make_lisp_hash_table (10, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
|
|
1469 }
|