Mercurial > hg > xemacs-beta
comparison src/tooltalk.c @ 16:0293115a14e9 r19-15b91
Import from CVS: tag r19-15b91
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:49:20 +0200 |
parents | bcdc7deadc19 |
children | 859a2309aef8 |
comparison
equal
deleted
inserted
replaced
15:ad457d5f7d04 | 16:0293115a14e9 |
---|---|
195 XSETTOOLTALK_MESSAGE (val, msg); | 195 XSETTOOLTALK_MESSAGE (val, msg); |
196 return val; | 196 return val; |
197 } | 197 } |
198 | 198 |
199 Tt_message | 199 Tt_message |
200 unbox_tooltalk_message (Lisp_Object message) | 200 unbox_tooltalk_message (Lisp_Object msg) |
201 { | 201 { |
202 CHECK_TOOLTALK_MESSAGE (message); | 202 CHECK_TOOLTALK_MESSAGE (msg); |
203 return XTOOLTALK_MESSAGE (message)->m; | 203 return XTOOLTALK_MESSAGE (msg)->m; |
204 } | 204 } |
205 | 205 |
206 DEFUN ("tooltalk-message-p", Ftooltalk_message_p, Stooltalk_message_p, 1, 1, 0 /* | 206 DEFUN ("tooltalk-message-p", Ftooltalk_message_p, Stooltalk_message_p, 1, 1, 0 /* |
207 Return non-nil if OBJECT is a tooltalk message. | 207 Return non-nil if OBJECT is a tooltalk message. |
208 */ ) | 208 */ ) |
322 (ignore1, ignore2) | 322 (ignore1, ignore2) |
323 Lisp_Object ignore1, ignore2; /* filters are called with two arguments. */ | 323 Lisp_Object ignore1, ignore2; /* filters are called with two arguments. */ |
324 { | 324 { |
325 /* This function can GC */ | 325 /* This function can GC */ |
326 Tt_message mess = tt_message_receive (); | 326 Tt_message mess = tt_message_receive (); |
327 Lisp_Object message = make_tooltalk_message (mess); | 327 Lisp_Object msg = make_tooltalk_message (mess); |
328 struct gcpro gcpro1; | 328 struct gcpro gcpro1; |
329 | 329 |
330 GCPRO1 (message); | 330 GCPRO1 (msg); |
331 if (mess != NULL && !NILP (Vtooltalk_unprocessed_message_hook)) | 331 if (mess != NULL && !NILP (Vtooltalk_unprocessed_message_hook)) |
332 va_run_hook_with_args (Qtooltalk_unprocessed_message_hook, 1, | 332 va_run_hook_with_args (Qtooltalk_unprocessed_message_hook, 1, |
333 message); | 333 msg); |
334 UNGCPRO; | 334 UNGCPRO; |
335 | 335 |
336 /* see comment in event-stream.c about this return value. */ | 336 /* see comment in event-stream.c about this return value. */ |
337 return make_int (0); | 337 return make_int (0); |
338 } | 338 } |
340 static Tt_callback_action | 340 static Tt_callback_action |
341 tooltalk_message_callback (Tt_message m, Tt_pattern p) | 341 tooltalk_message_callback (Tt_message m, Tt_pattern p) |
342 { | 342 { |
343 /* This function can GC */ | 343 /* This function can GC */ |
344 Lisp_Object cb; | 344 Lisp_Object cb; |
345 Lisp_Object message; | 345 Lisp_Object msg; |
346 Lisp_Object pattern; | 346 Lisp_Object pattern; |
347 struct gcpro gcpro1, gcpro2; | 347 struct gcpro gcpro1, gcpro2; |
348 | 348 |
349 #ifdef TT_DEBUG | 349 #ifdef TT_DEBUG |
350 int i, j; | 350 int i, j; |
358 } | 358 } |
359 fprintf (tooltalk_log_file, "\n\n"); | 359 fprintf (tooltalk_log_file, "\n\n"); |
360 fflush (tooltalk_log_file); | 360 fflush (tooltalk_log_file); |
361 #endif | 361 #endif |
362 | 362 |
363 VOID_TO_LISP (message, tt_message_user (m, TOOLTALK_MESSAGE_KEY)); | 363 VOID_TO_LISP (msg, tt_message_user (m, TOOLTALK_MESSAGE_KEY)); |
364 pattern = make_tooltalk_pattern (p); | 364 pattern = make_tooltalk_pattern (p); |
365 cb = XTOOLTALK_MESSAGE (message)->callback; | 365 cb = XTOOLTALK_MESSAGE (msg)->callback; |
366 GCPRO2 (message, pattern); | 366 GCPRO2 (msg, pattern); |
367 if (!NILP (Vtooltalk_message_handler_hook)) | 367 if (!NILP (Vtooltalk_message_handler_hook)) |
368 va_run_hook_with_args (Qtooltalk_message_handler_hook, 2, message, | 368 va_run_hook_with_args (Qtooltalk_message_handler_hook, 2, msg, |
369 pattern); | 369 pattern); |
370 | 370 |
371 if ((SYMBOLP (cb) && EQ (Qt, Ffboundp (cb))) || | 371 if ((SYMBOLP (cb) && EQ (Qt, Ffboundp (cb))) || |
372 (CONSP (cb) && EQ (Qlambda, Fcar (cb)) && | 372 (CONSP (cb) && EQ (Qlambda, Fcar (cb)) && |
373 !NILP (Flistp (Fcar (Fcdr (cb)))))) | 373 !NILP (Flistp (Fcar (Fcdr (cb)))))) |
374 call2 (cb, message, pattern); | 374 call2 (cb, msg, pattern); |
375 UNGCPRO; | 375 UNGCPRO; |
376 | 376 |
377 tt_message_destroy (m); | 377 tt_message_destroy (m); |
378 Fremhash (message, Vtooltalk_message_gcpro); | 378 Fremhash (msg, Vtooltalk_message_gcpro); |
379 | 379 |
380 return TT_CALLBACK_PROCESSED; | 380 return TT_CALLBACK_PROCESSED; |
381 } | 381 } |
382 | 382 |
383 static Tt_callback_action | 383 static Tt_callback_action |
384 tooltalk_pattern_callback (Tt_message m, Tt_pattern p) | 384 tooltalk_pattern_callback (Tt_message m, Tt_pattern p) |
385 { | 385 { |
386 /* This function can GC */ | 386 /* This function can GC */ |
387 Lisp_Object cb; | 387 Lisp_Object cb; |
388 Lisp_Object message; | 388 Lisp_Object msg; |
389 Lisp_Object pattern; | 389 Lisp_Object pattern; |
390 struct gcpro gcpro1, gcpro2; | 390 struct gcpro gcpro1, gcpro2; |
391 | 391 |
392 #ifdef TT_DEBUG | 392 #ifdef TT_DEBUG |
393 int i, j; | 393 int i, j; |
401 } | 401 } |
402 fprintf (tooltalk_log_file, "\n\n"); | 402 fprintf (tooltalk_log_file, "\n\n"); |
403 fflush (tooltalk_log_file); | 403 fflush (tooltalk_log_file); |
404 #endif | 404 #endif |
405 | 405 |
406 message = make_tooltalk_message (m); | 406 msg = make_tooltalk_message (m); |
407 VOID_TO_LISP (pattern, tt_pattern_user (p, TOOLTALK_PATTERN_KEY)); | 407 VOID_TO_LISP (pattern, tt_pattern_user (p, TOOLTALK_PATTERN_KEY)); |
408 cb = XTOOLTALK_PATTERN (pattern)->callback; | 408 cb = XTOOLTALK_PATTERN (pattern)->callback; |
409 GCPRO2 (message, pattern); | 409 GCPRO2 (msg, pattern); |
410 if (!NILP (Vtooltalk_pattern_handler_hook)) | 410 if (!NILP (Vtooltalk_pattern_handler_hook)) |
411 va_run_hook_with_args (Qtooltalk_pattern_handler_hook, 2, message, | 411 va_run_hook_with_args (Qtooltalk_pattern_handler_hook, 2, msg, |
412 pattern); | 412 pattern); |
413 | 413 |
414 if (SYMBOLP (cb) && EQ (Qt, Ffboundp (cb))) | 414 if (SYMBOLP (cb) && EQ (Qt, Ffboundp (cb))) |
415 call2 (cb, message, pattern); | 415 call2 (cb, msg, pattern); |
416 UNGCPRO; | 416 UNGCPRO; |
417 | 417 |
418 tt_message_destroy (m); | 418 tt_message_destroy (m); |
419 return TT_CALLBACK_PROCESSED; | 419 return TT_CALLBACK_PROCESSED; |
420 } | 420 } |
580 define any semantics for the string value of 'arg_type. Conventionally | 580 define any semantics for the string value of 'arg_type. Conventionally |
581 \"string\" is used for strings and \"int\" for 32 bit integers. Note that | 581 \"string\" is used for strings and \"int\" for 32 bit integers. Note that |
582 Emacs Lisp stores the lengths of strings explicitly (unlike C) so treating the | 582 Emacs Lisp stores the lengths of strings explicitly (unlike C) so treating the |
583 value returned by 'arg_bval like a string is fine. | 583 value returned by 'arg_bval like a string is fine. |
584 */ ) | 584 */ ) |
585 (message, attribute, argn) | 585 (msg, attribute, argn) |
586 Lisp_Object message; | 586 Lisp_Object msg; |
587 Lisp_Object attribute; | 587 Lisp_Object attribute; |
588 Lisp_Object argn; | 588 Lisp_Object argn; |
589 { | 589 { |
590 Tt_message m = unbox_tooltalk_message (message); | 590 Tt_message m = unbox_tooltalk_message (msg); |
591 int n = 0; | 591 int n = 0; |
592 | 592 |
593 CHECK_SYMBOL (attribute); | 593 CHECK_SYMBOL (attribute); |
594 if (EQ (attribute, (Qtt_arg_bval)) || | 594 if (EQ (attribute, (Qtt_arg_bval)) || |
595 EQ (attribute, (Qtt_arg_ival)) || | 595 EQ (attribute, (Qtt_arg_ival)) || |
678 | 678 |
679 else if (EQ (attribute, Qtt_uid)) | 679 else if (EQ (attribute, Qtt_uid)) |
680 return make_int (tt_message_uid (m)); | 680 return make_int (tt_message_uid (m)); |
681 | 681 |
682 else if (EQ (attribute, Qtt_callback)) | 682 else if (EQ (attribute, Qtt_callback)) |
683 return XTOOLTALK_MESSAGE (message)->callback; | 683 return XTOOLTALK_MESSAGE (msg)->callback; |
684 | 684 |
685 else if (EQ (attribute, Qtt_prop)) | 685 else if (EQ (attribute, Qtt_prop)) |
686 return Fget (XTOOLTALK_MESSAGE (message)->plist_sym, argn, Qnil); | 686 return Fget (XTOOLTALK_MESSAGE (msg)->plist_sym, argn, Qnil); |
687 | 687 |
688 else if (EQ (attribute, Qtt_plist)) | 688 else if (EQ (attribute, Qtt_plist)) |
689 return Fcopy_sequence (Fsymbol_plist (XTOOLTALK_MESSAGE (message)-> | 689 return Fcopy_sequence (Fsymbol_plist (XTOOLTALK_MESSAGE (msg)-> |
690 plist_sym)); | 690 plist_sym)); |
691 | 691 |
692 else | 692 else |
693 signal_simple_error ("invalid value for `get-tooltalk-message-attribute'", | 693 signal_simple_error ("invalid value for `get-tooltalk-message-attribute'", |
694 attribute); | 694 attribute); |
715 | 715 |
716 If one of the argument attributes is specified, 'arg_val, 'arg_ival, or | 716 If one of the argument attributes is specified, 'arg_val, 'arg_ival, or |
717 'arg_bval then argn must be the number of an already created argument. | 717 'arg_bval then argn must be the number of an already created argument. |
718 New arguments can be added to a message with add-tooltalk-message-arg. | 718 New arguments can be added to a message with add-tooltalk-message-arg. |
719 */ ) | 719 */ ) |
720 (value, message, attribute, argn) | 720 (value, msg, attribute, argn) |
721 Lisp_Object value; | 721 Lisp_Object value; |
722 Lisp_Object message; | 722 Lisp_Object msg; |
723 Lisp_Object attribute; | 723 Lisp_Object attribute; |
724 Lisp_Object argn; | 724 Lisp_Object argn; |
725 { | 725 { |
726 Tt_message m = unbox_tooltalk_message (message); | 726 Tt_message m = unbox_tooltalk_message (msg); |
727 int n = 0; | 727 int n = 0; |
728 | 728 |
729 CHECK_SYMBOL (attribute); | 729 CHECK_SYMBOL (attribute); |
730 if (EQ (attribute, (Qtt_arg_bval)) || | 730 if (EQ (attribute, (Qtt_arg_bval)) || |
731 EQ (attribute, (Qtt_arg_ival)) || | 731 EQ (attribute, (Qtt_arg_ival)) || |
847 tt_message_status_string_set (m, value_ext); | 847 tt_message_status_string_set (m, value_ext); |
848 } | 848 } |
849 else if (EQ (attribute, Qtt_callback)) | 849 else if (EQ (attribute, Qtt_callback)) |
850 { | 850 { |
851 CHECK_SYMBOL (value); | 851 CHECK_SYMBOL (value); |
852 XTOOLTALK_MESSAGE (message)->callback = value; | 852 XTOOLTALK_MESSAGE (msg)->callback = value; |
853 } | 853 } |
854 else if (EQ (attribute, Qtt_prop)) | 854 else if (EQ (attribute, Qtt_prop)) |
855 { | 855 { |
856 return Fput (XTOOLTALK_MESSAGE (message)->plist_sym, argn, value); | 856 return Fput (XTOOLTALK_MESSAGE (msg)->plist_sym, argn, value); |
857 } | 857 } |
858 else | 858 else |
859 signal_simple_error ("invalid value for `set-tooltalk-message-attribute'", | 859 signal_simple_error ("invalid value for `set-tooltalk-message-attribute'", |
860 attribute); | 860 attribute); |
861 return Qnil; | 861 return Qnil; |
868 Send a reply to this message. The second argument can be | 868 Send a reply to this message. The second argument can be |
869 'reply, 'reject or 'fail; the default is 'reply. Before sending | 869 'reply, 'reject or 'fail; the default is 'reply. Before sending |
870 a reply all message arguments whose mode is TT_INOUT or TT_OUT should | 870 a reply all message arguments whose mode is TT_INOUT or TT_OUT should |
871 have been filled in - see set-tooltalk-message-attribute. | 871 have been filled in - see set-tooltalk-message-attribute. |
872 */ ) | 872 */ ) |
873 (message, mode) | 873 (msg, mode) |
874 Lisp_Object message, mode; | 874 Lisp_Object msg, mode; |
875 { | 875 { |
876 Tt_message m = unbox_tooltalk_message (message); | 876 Tt_message m = unbox_tooltalk_message (msg); |
877 | 877 |
878 if (NILP (mode)) | 878 if (NILP (mode)) |
879 mode = Qtt_reply; | 879 mode = Qtt_reply; |
880 else | 880 else |
881 CHECK_SYMBOL (mode); | 881 CHECK_SYMBOL (mode); |
907 */ ) | 907 */ ) |
908 (no_callback) | 908 (no_callback) |
909 Lisp_Object no_callback; | 909 Lisp_Object no_callback; |
910 { | 910 { |
911 Tt_message m = tt_message_create (); | 911 Tt_message m = tt_message_create (); |
912 Lisp_Object message = make_tooltalk_message (m); | 912 Lisp_Object msg = make_tooltalk_message (m); |
913 if (NILP (no_callback)) | 913 if (NILP (no_callback)) |
914 { | 914 { |
915 tt_message_callback_add (m, tooltalk_message_callback); | 915 tt_message_callback_add (m, tooltalk_message_callback); |
916 } | 916 } |
917 tt_message_session_set (m, tt_default_session ()); | 917 tt_message_session_set (m, tt_default_session ()); |
918 tt_message_user_set (m, TOOLTALK_MESSAGE_KEY, LISP_TO_VOID (message)); | 918 tt_message_user_set (m, TOOLTALK_MESSAGE_KEY, LISP_TO_VOID (msg)); |
919 return message; | 919 return msg; |
920 } | 920 } |
921 | 921 |
922 DEFUN ("destroy-tooltalk-message", | 922 DEFUN ("destroy-tooltalk-message", |
923 Fdestroy_tooltalk_message, | 923 Fdestroy_tooltalk_message, |
924 Sdestroy_tooltalk_message, | 924 Sdestroy_tooltalk_message, |
926 Apply tt_message_destroy() to the message. | 926 Apply tt_message_destroy() to the message. |
927 It's not necessary to destroy messages after they've been processed by | 927 It's not necessary to destroy messages after they've been processed by |
928 a message or pattern callback; the Lisp/Tooltalk callback machinery does | 928 a message or pattern callback; the Lisp/Tooltalk callback machinery does |
929 this for you. | 929 this for you. |
930 */ ) | 930 */ ) |
931 (message) | 931 (msg) |
932 Lisp_Object message; | 932 Lisp_Object msg; |
933 { | 933 { |
934 Tt_message m = unbox_tooltalk_message (message); | 934 Tt_message m = unbox_tooltalk_message (msg); |
935 | 935 |
936 if (VALID_TOOLTALK_MESSAGEP (m)) | 936 if (VALID_TOOLTALK_MESSAGEP (m)) |
937 /* #### Should we call Fremhash() here? It seems that | 937 /* #### Should we call Fremhash() here? It seems that |
938 a common paradigm is | 938 a common paradigm is |
939 | 939 |
968 Arguments can initialized by providing a value or with | 968 Arguments can initialized by providing a value or with |
969 `set-tooltalk-message-attribute'. The latter is neccessary if you | 969 `set-tooltalk-message-attribute'. The latter is neccessary if you |
970 want to initialize the argument with a string that can contain | 970 want to initialize the argument with a string that can contain |
971 embedded nulls (use 'arg_bval). | 971 embedded nulls (use 'arg_bval). |
972 */ ) | 972 */ ) |
973 (message, mode, vtype, value) | 973 (msg, mode, vtype, value) |
974 Lisp_Object message, mode, vtype, value; | 974 Lisp_Object msg, mode, vtype, value; |
975 { | 975 { |
976 Tt_message m = unbox_tooltalk_message (message); | 976 Tt_message m = unbox_tooltalk_message (msg); |
977 Tt_mode n; | 977 Tt_mode n; |
978 | 978 |
979 CHECK_STRING (vtype); | 979 CHECK_STRING (vtype); |
980 CHECK_TOOLTALK_CONSTANT (mode); | 980 CHECK_TOOLTALK_CONSTANT (mode); |
981 | 981 |
1008 1, 1, 0 /* | 1008 1, 1, 0 /* |
1009 Send the message on its way. | 1009 Send the message on its way. |
1010 Once the message has been sent it's almost always a good idea to get rid of | 1010 Once the message has been sent it's almost always a good idea to get rid of |
1011 it with `destroy-tooltalk-message'. | 1011 it with `destroy-tooltalk-message'. |
1012 */ ) | 1012 */ ) |
1013 (message) | 1013 (msg) |
1014 Lisp_Object message; | 1014 Lisp_Object msg; |
1015 { | 1015 { |
1016 Tt_message m = unbox_tooltalk_message (message); | 1016 Tt_message m = unbox_tooltalk_message (msg); |
1017 | 1017 |
1018 if (VALID_TOOLTALK_MESSAGEP (m)) | 1018 if (VALID_TOOLTALK_MESSAGEP (m)) |
1019 { | 1019 { |
1020 tt_message_send (m); | 1020 tt_message_send (m); |
1021 Fputhash (message, Qnil, Vtooltalk_message_gcpro); | 1021 Fputhash (msg, Qnil, Vtooltalk_message_gcpro); |
1022 } | 1022 } |
1023 | 1023 |
1024 return Qnil; | 1024 return Qnil; |
1025 } | 1025 } |
1026 | 1026 |