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