1 Notes about the Background Only application template |
|
2 ==================================================== |
|
3 |
|
4 RCS: @(#) $Id: Background.doc,v 1.2 1998/09/14 18:40:03 stanton Exp $ |
|
5 |
|
6 We have included sample code and project files for making a Background-Only |
|
7 application (BOA) in Tcl. This could be used for server processes (like the |
|
8 Tcl Web-Server). |
|
9 |
|
10 Files: |
|
11 ------ |
|
12 |
|
13 * BOA_TclShells.¼ - This is the project file. |
|
14 * tclMacBOAAppInit.c - This is the AppInit file for the BOA App. |
|
15 * tclMacBOAMain - This is a replacement for the Tcl_Main for BOA's. |
|
16 |
|
17 Caveat: |
|
18 ------- |
|
19 |
|
20 This is an unsupported addition to MacTcl. The main feature that will certainly |
|
21 change is how we handle AppleEvents. Currently, all the AppleEvent handling is |
|
22 done on the Tk side, which is not really right. Also, there is no way to |
|
23 register your own AppleEvent handlers, which is obviously something that would be |
|
24 useful in a BOA App. We will address these issues in Tcl8.1. If you need to |
|
25 register your own AppleEvent Handlers in the meantime, be aware that your code |
|
26 will probably break in Tcl8.1. |
|
27 |
|
28 I will also improve the basic code here based on feedback that I recieve. This |
|
29 is to be considered a first cut only at writing a BOA in Tcl. |
|
30 |
|
31 Introduction: |
|
32 ------------- |
|
33 |
|
34 This project makes a double-clickable BOA application. It obviously needs |
|
35 some Tcl code to get it started. It will look for this code first in a |
|
36 'TEXT' resource in the application shell whose name is "bgScript.tcl". If |
|
37 it does not find any such resource, it will look for a file called |
|
38 bgScript.tcl in the application's folder. Otherwise it will quit with an |
|
39 error. |
|
40 |
|
41 It creates three files in the application folder to store stdin, stdout & |
|
42 stderr. They are imaginatively called temp.in, temp.out & temp.err. They |
|
43 will be opened append, so you do not need to erase them after each use of |
|
44 the BOA. |
|
45 |
|
46 The app does understand the "quit", and the "doScript" AppleEvents, so you can |
|
47 kill it with the former, and instruct it with the latter. It also has an |
|
48 aete, so you can target it with Apple's "Script Editor". |
|
49 |
|
50 For more information on Macintosh BOA's, see the Apple TechNote: 1070. |
|
51 |
|
52 Notifications: |
|
53 -------------- |
|
54 |
|
55 BOA's are not supposed to have direct contact with the outside world. They |
|
56 are, however, allowed to go through the Notification Manager to post |
|
57 alerts. To this end, I have added a Tcl command called "bgnotify" to the |
|
58 shell, that simply posts a notification through the notification manager. |
|
59 |
|
60 To use it, say: |
|
61 |
|
62 bgnotify "Hi, there little buddy" |
|
63 |
|
64 It will make the system beep, and pop up an annoying message box with the |
|
65 text of the first argument to the command. While the message is up, Tcl |
|
66 is yielding processor time, but not processing any events. |
|
67 |
|
68 Errors: |
|
69 ------- |
|
70 |
|
71 Usually a Tcl background application will have some startup code, opening |
|
72 up a server socket, or whatever, and at the end of this, will use the |
|
73 vwait command to kick off the event loop. If an error occurs in the |
|
74 startup code, it will kill the application, and a notification of the error |
|
75 will be posted through the Notification Manager. |
|
76 |
|
77 If an error occurs in the event handling code after the |
|
78 vwait, the error message will be written to the file temp.err. However, |
|
79 if you would like to have these errors post a notification as well, just |
|
80 define a proc called bgerror that takes one argument, the error message, |
|
81 and passes that off to "bgnotify", thusly: |
|
82 |
|
83 proc bgerror {mssg} { |
|
84 bgnotify "A background error has occured\n $mssg" |
|
85 } |
|
86 |
|
87 Support: |
|
88 -------- |
|
89 |
|
90 If you have any questions, contact me at: |
|
91 |
|
92 jim.ingham@eng.sun.com |
|