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