Mercurial > hg > xemacs-beta
comparison src/tooltalk.c @ 173:8eaf7971accc r20-3b13
Import from CVS: tag r20-3b13
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:49:09 +0200 |
parents | 15872534500d |
children | 3d6bfa290dbd |
comparison
equal
deleted
inserted
replaced
172:a38aed19690b | 173:8eaf7971accc |
---|---|
182 } | 182 } |
183 | 183 |
184 static Lisp_Object | 184 static Lisp_Object |
185 make_tooltalk_message (Tt_message m) | 185 make_tooltalk_message (Tt_message m) |
186 { | 186 { |
187 struct Lisp_Tooltalk_Message *msg | 187 struct Lisp_Tooltalk_Message *message_ |
188 = alloc_lcrecord (sizeof (struct Lisp_Tooltalk_Message), | 188 = alloc_lcrecord (sizeof (struct Lisp_Tooltalk_Message), |
189 lrecord_tooltalk_message); | 189 lrecord_tooltalk_message); |
190 Lisp_Object val; | 190 Lisp_Object val; |
191 | 191 |
192 msg->m = m; | 192 message_->m = m; |
193 msg->callback = Qnil; | 193 message_->callback = Qnil; |
194 msg->plist_sym = Fmake_symbol (Tooltalk_Message_plist_str); | 194 message_->plist_sym = Fmake_symbol (Tooltalk_Message_plist_str); |
195 XSETTOOLTALK_MESSAGE (val, msg); | 195 XSETTOOLTALK_MESSAGE (val, message_); |
196 return val; | 196 return val; |
197 } | 197 } |
198 | 198 |
199 Tt_message | 199 Tt_message |
200 unbox_tooltalk_message (Lisp_Object msg) | 200 unbox_tooltalk_message (Lisp_Object message_) |
201 { | 201 { |
202 CHECK_TOOLTALK_MESSAGE (msg); | 202 CHECK_TOOLTALK_MESSAGE (message_); |
203 return XTOOLTALK_MESSAGE (msg)->m; | 203 return XTOOLTALK_MESSAGE (message_)->m; |
204 } | 204 } |
205 | 205 |
206 DEFUN ("tooltalk-message-p", Ftooltalk_message_p, 1, 1, 0, /* | 206 DEFUN ("tooltalk-message-p", Ftooltalk_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 */ |
209 (object)) | 209 (object)) |
210 { | 210 { |
211 return (TOOLTALK_MESSAGEP (object) ? Qt : Qnil); | 211 return TOOLTALK_MESSAGEP (object) ? Qt : Qnil; |
212 } | 212 } |
213 | 213 |
214 | 214 |
215 | 215 |
216 | 216 |
283 DEFUN ("tooltalk-pattern-p", Ftooltalk_pattern_p, 1, 1, 0, /* | 283 DEFUN ("tooltalk-pattern-p", Ftooltalk_pattern_p, 1, 1, 0, /* |
284 Return non-nil if OBJECT is a tooltalk pattern. | 284 Return non-nil if OBJECT is a tooltalk pattern. |
285 */ | 285 */ |
286 (object)) | 286 (object)) |
287 { | 287 { |
288 return (TOOLTALK_PATTERNP (object) ? Qt : Qnil); | 288 return TOOLTALK_PATTERNP (object) ? Qt : Qnil; |
289 } | 289 } |
290 | 290 |
291 | 291 |
292 | 292 |
293 | 293 |
316 */ | 316 */ |
317 (ignore1, ignore2)) | 317 (ignore1, ignore2)) |
318 { | 318 { |
319 /* This function can GC */ | 319 /* This function can GC */ |
320 Tt_message mess = tt_message_receive (); | 320 Tt_message mess = tt_message_receive (); |
321 Lisp_Object msg = make_tooltalk_message (mess); | 321 Lisp_Object message_ = make_tooltalk_message (mess); |
322 struct gcpro gcpro1; | 322 struct gcpro gcpro1; |
323 | 323 |
324 GCPRO1 (msg); | 324 GCPRO1 (message_); |
325 if (mess != NULL && !NILP (Vtooltalk_unprocessed_message_hook)) | 325 if (mess != NULL && !NILP (Vtooltalk_unprocessed_message_hook)) |
326 va_run_hook_with_args (Qtooltalk_unprocessed_message_hook, 1, | 326 va_run_hook_with_args (Qtooltalk_unprocessed_message_hook, 1, message_); |
327 msg); | |
328 UNGCPRO; | 327 UNGCPRO; |
329 | 328 |
330 /* see comment in event-stream.c about this return value. */ | 329 /* see comment in event-stream.c about this return value. */ |
331 return make_int (0); | 330 return make_int (0); |
332 } | 331 } |
334 static Tt_callback_action | 333 static Tt_callback_action |
335 tooltalk_message_callback (Tt_message m, Tt_pattern p) | 334 tooltalk_message_callback (Tt_message m, Tt_pattern p) |
336 { | 335 { |
337 /* This function can GC */ | 336 /* This function can GC */ |
338 Lisp_Object cb; | 337 Lisp_Object cb; |
339 Lisp_Object msg; | 338 Lisp_Object message_; |
340 Lisp_Object pattern; | 339 Lisp_Object pattern; |
341 struct gcpro gcpro1, gcpro2; | 340 struct gcpro gcpro1, gcpro2; |
342 | 341 |
343 #ifdef TT_DEBUG | 342 #ifdef TT_DEBUG |
344 int i, j; | 343 int i, j; |
352 } | 351 } |
353 fprintf (tooltalk_log_file, "\n\n"); | 352 fprintf (tooltalk_log_file, "\n\n"); |
354 fflush (tooltalk_log_file); | 353 fflush (tooltalk_log_file); |
355 #endif | 354 #endif |
356 | 355 |
357 VOID_TO_LISP (msg, tt_message_user (m, TOOLTALK_MESSAGE_KEY)); | 356 VOID_TO_LISP (message_, tt_message_user (m, TOOLTALK_MESSAGE_KEY)); |
358 pattern = make_tooltalk_pattern (p); | 357 pattern = make_tooltalk_pattern (p); |
359 cb = XTOOLTALK_MESSAGE (msg)->callback; | 358 cb = XTOOLTALK_MESSAGE (message_)->callback; |
360 GCPRO2 (msg, pattern); | 359 GCPRO2 (message_, pattern); |
361 if (!NILP (Vtooltalk_message_handler_hook)) | 360 if (!NILP (Vtooltalk_message_handler_hook)) |
362 va_run_hook_with_args (Qtooltalk_message_handler_hook, 2, msg, | 361 va_run_hook_with_args (Qtooltalk_message_handler_hook, 2, |
363 pattern); | 362 message_, pattern); |
364 | 363 |
365 if ((SYMBOLP (cb) && EQ (Qt, Ffboundp (cb))) || | 364 if ((SYMBOLP (cb) && EQ (Qt, Ffboundp (cb))) || |
366 (CONSP (cb) && EQ (Qlambda, Fcar (cb)) && | 365 (CONSP (cb) && EQ (Qlambda, Fcar (cb)) && |
367 !NILP (Flistp (Fcar (Fcdr (cb)))))) | 366 !NILP (Flistp (Fcar (Fcdr (cb)))))) |
368 call2 (cb, msg, pattern); | 367 call2 (cb, message_, pattern); |
369 UNGCPRO; | 368 UNGCPRO; |
370 | 369 |
371 tt_message_destroy (m); | 370 tt_message_destroy (m); |
372 Fremhash (msg, Vtooltalk_message_gcpro); | 371 Fremhash (message_, Vtooltalk_message_gcpro); |
373 | 372 |
374 return TT_CALLBACK_PROCESSED; | 373 return TT_CALLBACK_PROCESSED; |
375 } | 374 } |
376 | 375 |
377 static Tt_callback_action | 376 static Tt_callback_action |
378 tooltalk_pattern_callback (Tt_message m, Tt_pattern p) | 377 tooltalk_pattern_callback (Tt_message m, Tt_pattern p) |
379 { | 378 { |
380 /* This function can GC */ | 379 /* This function can GC */ |
381 Lisp_Object cb; | 380 Lisp_Object cb; |
382 Lisp_Object msg; | 381 Lisp_Object message_; |
383 Lisp_Object pattern; | 382 Lisp_Object pattern; |
384 struct gcpro gcpro1, gcpro2; | 383 struct gcpro gcpro1, gcpro2; |
385 | 384 |
386 #ifdef TT_DEBUG | 385 #ifdef TT_DEBUG |
387 int i, j; | 386 int i, j; |
395 } | 394 } |
396 fprintf (tooltalk_log_file, "\n\n"); | 395 fprintf (tooltalk_log_file, "\n\n"); |
397 fflush (tooltalk_log_file); | 396 fflush (tooltalk_log_file); |
398 #endif | 397 #endif |
399 | 398 |
400 msg = make_tooltalk_message (m); | 399 message_ = make_tooltalk_message (m); |
401 VOID_TO_LISP (pattern, tt_pattern_user (p, TOOLTALK_PATTERN_KEY)); | 400 VOID_TO_LISP (pattern, tt_pattern_user (p, TOOLTALK_PATTERN_KEY)); |
402 cb = XTOOLTALK_PATTERN (pattern)->callback; | 401 cb = XTOOLTALK_PATTERN (pattern)->callback; |
403 GCPRO2 (msg, pattern); | 402 GCPRO2 (message_, pattern); |
404 if (!NILP (Vtooltalk_pattern_handler_hook)) | 403 if (!NILP (Vtooltalk_pattern_handler_hook)) |
405 va_run_hook_with_args (Qtooltalk_pattern_handler_hook, 2, msg, | 404 va_run_hook_with_args (Qtooltalk_pattern_handler_hook, 2, |
406 pattern); | 405 message_, pattern); |
407 | 406 |
408 if (SYMBOLP (cb) && EQ (Qt, Ffboundp (cb))) | 407 if (SYMBOLP (cb) && EQ (Qt, Ffboundp (cb))) |
409 call2 (cb, msg, pattern); | 408 call2 (cb, message_, pattern); |
410 UNGCPRO; | 409 UNGCPRO; |
411 | 410 |
412 tt_message_destroy (m); | 411 tt_message_destroy (m); |
413 return TT_CALLBACK_PROCESSED; | 412 return TT_CALLBACK_PROCESSED; |
414 } | 413 } |
541 check_status (tt_message_arg_bval (m, n, &value, &len)); | 540 check_status (tt_message_arg_bval (m, n, &value, &len)); |
542 | 541 |
543 return make_string (value, len); | 542 return make_string (value, len); |
544 } | 543 } |
545 | 544 |
546 DEFUN ("get-tooltalk-message-attribute", Fget_tooltalk_message_attribute, 2, 3, 0, /* | 545 DEFUN ("get-tooltalk-message-attribute", |
546 Fget_tooltalk_message_attribute, 2, 3, 0, /* | |
547 Return the indicated Tooltalk message attribute. Attributes are | 547 Return the indicated Tooltalk message attribute. Attributes are |
548 identified by symbols with the same name (underscores and all) as the | 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. | 549 suffix of the Tooltalk tt_message_<attribute> function that extracts the value. |
550 String attribute values are copied, enumerated type values (except disposition) | 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 | 551 are converted to symbols - e.g. TT_HANDLER is 'TT_HANDLER, uid and gid are |
571 define any semantics for the string value of 'arg_type. Conventionally | 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 | 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 | 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. | 574 value returned by 'arg_bval like a string is fine. |
575 */ | 575 */ |
576 (msg, attribute, argn)) | 576 (message_, attribute, argn)) |
577 { | 577 { |
578 Tt_message m = unbox_tooltalk_message (msg); | 578 Tt_message m = unbox_tooltalk_message (message_); |
579 int n = 0; | 579 int n = 0; |
580 | 580 |
581 CHECK_SYMBOL (attribute); | 581 CHECK_SYMBOL (attribute); |
582 if (EQ (attribute, (Qtt_arg_bval)) || | 582 if (EQ (attribute, (Qtt_arg_bval)) || |
583 EQ (attribute, (Qtt_arg_ival)) || | 583 EQ (attribute, (Qtt_arg_ival)) || |
666 | 666 |
667 else if (EQ (attribute, Qtt_uid)) | 667 else if (EQ (attribute, Qtt_uid)) |
668 return make_int (tt_message_uid (m)); | 668 return make_int (tt_message_uid (m)); |
669 | 669 |
670 else if (EQ (attribute, Qtt_callback)) | 670 else if (EQ (attribute, Qtt_callback)) |
671 return XTOOLTALK_MESSAGE (msg)->callback; | 671 return XTOOLTALK_MESSAGE (message_)->callback; |
672 | 672 |
673 else if (EQ (attribute, Qtt_prop)) | 673 else if (EQ (attribute, Qtt_prop)) |
674 return Fget (XTOOLTALK_MESSAGE (msg)->plist_sym, argn, Qnil); | 674 return Fget (XTOOLTALK_MESSAGE (message_)->plist_sym, argn, Qnil); |
675 | 675 |
676 else if (EQ (attribute, Qtt_plist)) | 676 else if (EQ (attribute, Qtt_plist)) |
677 return Fcopy_sequence (Fsymbol_plist (XTOOLTALK_MESSAGE (msg)-> | 677 return Fcopy_sequence (Fsymbol_plist |
678 plist_sym)); | 678 (XTOOLTALK_MESSAGE (message_)->plist_sym)); |
679 | 679 |
680 else | 680 else |
681 signal_simple_error ("invalid value for `get-tooltalk-message-attribute'", | 681 signal_simple_error ("invalid value for `get-tooltalk-message-attribute'", |
682 attribute); | 682 attribute); |
683 | 683 |
701 | 701 |
702 If one of the argument attributes is specified, 'arg_val, 'arg_ival, or | 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. | 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. | 704 New arguments can be added to a message with add-tooltalk-message-arg. |
705 */ | 705 */ |
706 (value, msg, attribute, argn)) | 706 (value, message_, attribute, argn)) |
707 { | 707 { |
708 Tt_message m = unbox_tooltalk_message (msg); | 708 Tt_message m = unbox_tooltalk_message (message_); |
709 int n = 0; | 709 int n = 0; |
710 | 710 |
711 CHECK_SYMBOL (attribute); | 711 CHECK_SYMBOL (attribute); |
712 if (EQ (attribute, (Qtt_arg_bval)) || | 712 if (EQ (attribute, (Qtt_arg_bval)) || |
713 EQ (attribute, (Qtt_arg_ival)) || | 713 EQ (attribute, (Qtt_arg_ival)) || |
829 tt_message_status_string_set (m, value_ext); | 829 tt_message_status_string_set (m, value_ext); |
830 } | 830 } |
831 else if (EQ (attribute, Qtt_callback)) | 831 else if (EQ (attribute, Qtt_callback)) |
832 { | 832 { |
833 CHECK_SYMBOL (value); | 833 CHECK_SYMBOL (value); |
834 XTOOLTALK_MESSAGE (msg)->callback = value; | 834 XTOOLTALK_MESSAGE (message_)->callback = value; |
835 } | 835 } |
836 else if (EQ (attribute, Qtt_prop)) | 836 else if (EQ (attribute, Qtt_prop)) |
837 { | 837 { |
838 return Fput (XTOOLTALK_MESSAGE (msg)->plist_sym, argn, value); | 838 return Fput (XTOOLTALK_MESSAGE (message_)->plist_sym, argn, value); |
839 } | 839 } |
840 else | 840 else |
841 signal_simple_error ("invalid value for `set-tooltalk-message-attribute'", | 841 signal_simple_error ("invalid value for `set-tooltalk-message-attribute'", |
842 attribute); | 842 attribute); |
843 return Qnil; | 843 return Qnil; |
847 Send a reply to this message. The second argument can be | 847 Send a reply to this message. The second argument can be |
848 'reply, 'reject or 'fail; the default is 'reply. Before sending | 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 | 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. | 850 have been filled in - see set-tooltalk-message-attribute. |
851 */ | 851 */ |
852 (msg, mode)) | 852 (message_, mode)) |
853 { | 853 { |
854 Tt_message m = unbox_tooltalk_message (msg); | 854 Tt_message m = unbox_tooltalk_message (message_); |
855 | 855 |
856 if (NILP (mode)) | 856 if (NILP (mode)) |
857 mode = Qtt_reply; | 857 mode = Qtt_reply; |
858 else | 858 else |
859 CHECK_SYMBOL (mode); | 859 CHECK_SYMBOL (mode); |
881 calling `make-tooltalk-message'. | 881 calling `make-tooltalk-message'. |
882 */ | 882 */ |
883 (no_callback)) | 883 (no_callback)) |
884 { | 884 { |
885 Tt_message m = tt_message_create (); | 885 Tt_message m = tt_message_create (); |
886 Lisp_Object msg = make_tooltalk_message (m); | 886 Lisp_Object message_ = make_tooltalk_message (m); |
887 if (NILP (no_callback)) | 887 if (NILP (no_callback)) |
888 { | 888 { |
889 tt_message_callback_add (m, tooltalk_message_callback); | 889 tt_message_callback_add (m, tooltalk_message_callback); |
890 } | 890 } |
891 tt_message_session_set (m, tt_default_session ()); | 891 tt_message_session_set (m, tt_default_session ()); |
892 tt_message_user_set (m, TOOLTALK_MESSAGE_KEY, LISP_TO_VOID (msg)); | 892 tt_message_user_set (m, TOOLTALK_MESSAGE_KEY, LISP_TO_VOID (message_)); |
893 return msg; | 893 return message_; |
894 } | 894 } |
895 | 895 |
896 DEFUN ("destroy-tooltalk-message", Fdestroy_tooltalk_message, 1, 1, 0, /* | 896 DEFUN ("destroy-tooltalk-message", Fdestroy_tooltalk_message, 1, 1, 0, /* |
897 Apply tt_message_destroy() to the message. | 897 Apply tt_message_destroy() to the message. |
898 It's not necessary to destroy messages after they've been processed by | 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 | 899 a message or pattern callback; the Lisp/Tooltalk callback machinery does |
900 this for you. | 900 this for you. |
901 */ | 901 */ |
902 (msg)) | 902 (message_)) |
903 { | 903 { |
904 Tt_message m = unbox_tooltalk_message (msg); | 904 Tt_message m = unbox_tooltalk_message (message_); |
905 | 905 |
906 if (VALID_TOOLTALK_MESSAGEP (m)) | 906 if (VALID_TOOLTALK_MESSAGEP (m)) |
907 /* #### Should we call Fremhash() here? It seems that | 907 /* #### Should we call Fremhash() here? It seems that |
908 a common paradigm is | 908 a common paradigm is |
909 | 909 |
935 Arguments can initialized by providing a value or with | 935 Arguments can initialized by providing a value or with |
936 `set-tooltalk-message-attribute'. The latter is necessary if you | 936 `set-tooltalk-message-attribute'. The latter is necessary if you |
937 want to initialize the argument with a string that can contain | 937 want to initialize the argument with a string that can contain |
938 embedded nulls (use 'arg_bval). | 938 embedded nulls (use 'arg_bval). |
939 */ | 939 */ |
940 (msg, mode, vtype, value)) | 940 (message_, mode, vtype, value)) |
941 { | 941 { |
942 Tt_message m = unbox_tooltalk_message (msg); | 942 Tt_message m = unbox_tooltalk_message (message_); |
943 Tt_mode n; | 943 Tt_mode n; |
944 | 944 |
945 CHECK_STRING (vtype); | 945 CHECK_STRING (vtype); |
946 CHECK_TOOLTALK_CONSTANT (mode); | 946 CHECK_TOOLTALK_CONSTANT (mode); |
947 | 947 |
971 DEFUN ("send-tooltalk-message", Fsend_tooltalk_message, 1, 1, 0, /* | 971 DEFUN ("send-tooltalk-message", Fsend_tooltalk_message, 1, 1, 0, /* |
972 Send the message on its way. | 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 | 973 Once the message has been sent it's almost always a good idea to get rid of |
974 it with `destroy-tooltalk-message'. | 974 it with `destroy-tooltalk-message'. |
975 */ | 975 */ |
976 (msg)) | 976 (message_)) |
977 { | 977 { |
978 Tt_message m = unbox_tooltalk_message (msg); | 978 Tt_message m = unbox_tooltalk_message (message_); |
979 | 979 |
980 if (VALID_TOOLTALK_MESSAGEP (m)) | 980 if (VALID_TOOLTALK_MESSAGEP (m)) |
981 { | 981 { |
982 tt_message_send (m); | 982 tt_message_send (m); |
983 Fputhash (msg, Qnil, Vtooltalk_message_gcpro); | 983 Fputhash (message_, Qnil, Vtooltalk_message_gcpro); |
984 } | 984 } |
985 | 985 |
986 return Qnil; | 986 return Qnil; |
987 } | 987 } |
988 | 988 |
1225 Return the a list of all the properties currently set in PATTERN. | 1225 Return the a list of all the properties currently set in PATTERN. |
1226 */ | 1226 */ |
1227 (pattern)) | 1227 (pattern)) |
1228 { | 1228 { |
1229 CHECK_TOOLTALK_PATTERN (pattern); | 1229 CHECK_TOOLTALK_PATTERN (pattern); |
1230 return Fcopy_sequence | 1230 return |
1231 (Fsymbol_plist (XTOOLTALK_PATTERN (pattern)->plist_sym)); | 1231 Fcopy_sequence (Fsymbol_plist (XTOOLTALK_PATTERN (pattern)->plist_sym)); |
1232 } | 1232 } |
1233 | 1233 |
1234 DEFUN ("tooltalk-default-procid", Ftooltalk_default_procid, 0, 0, 0, /* | 1234 DEFUN ("tooltalk-default-procid", Ftooltalk_default_procid, 0, 0, 0, /* |
1235 Return current default process identifier for your process. | 1235 Return current default process identifier for your process. |
1236 */ | 1236 */ |
1310 if (!NILP (Vtooltalk_fd)) | 1310 if (!NILP (Vtooltalk_fd)) |
1311 error ("Already connected to ToolTalk."); | 1311 error ("Already connected to ToolTalk."); |
1312 if (noninteractive) | 1312 if (noninteractive) |
1313 error ("Can't connect to ToolTalk in batch mode."); | 1313 error ("Can't connect to ToolTalk in batch mode."); |
1314 init_tooltalk (); | 1314 init_tooltalk (); |
1315 return (NILP (Vtooltalk_fd) ? Qnil : Qt); | 1315 return NILP (Vtooltalk_fd) ? Qnil : Qt; |
1316 } | 1316 } |
1317 | 1317 |
1318 | 1318 |
1319 void | 1319 void |
1320 syms_of_tooltalk (void) | 1320 syms_of_tooltalk (void) |