plumb.ms 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429
  1. .HTML "Plumbing and Other Utilities
  2. .TL
  3. Plumbing and Other Utilities
  4. .AU
  5. Rob Pike
  6. .AI
  7. .MH
  8. .AB
  9. .LP
  10. Plumbing is a new mechanism for inter-process communication in Plan 9,
  11. specifically the passing of messages between interactive programs as part of
  12. the user interface.
  13. Although plumbing shares some properties with familiar notions
  14. such as cut and paste,
  15. it offers a more general data exchange mechanism without imposing
  16. a particular user interface.
  17. .LP
  18. The core of the plumbing system is a program called the
  19. .I plumber ,
  20. which handles all messages and dispatches and reformats them
  21. according to configuration rules written in a special-purpose language.
  22. This approach allows the contents and context of a piece of data to define how
  23. it is handled.
  24. Unlike with drag and drop or cut and paste,
  25. the user doesn't need to deliver the data;
  26. the contents of a plumbing message, as interpreted by the plumbing rules,
  27. determine its destination.
  28. .LP
  29. The plumber has an unusual architecture: it is a language-driven file server.
  30. This design has distinct advantages.
  31. It makes plumbing easy to add to an existing, Unix-like command environment;
  32. it guarantees uniform handling of inter-application messages;
  33. it off-loads from those applications most of the work of extracting and dispatching messages;
  34. and it works transparently across a network.
  35. .AE
  36. .SH
  37. Introduction
  38. .LP
  39. Data moves from program to program in myriad ways.
  40. Command-line arguments,
  41. shell pipe lines,
  42. cut and paste,
  43. drag and drop, and other user interface techniques all provide some form
  44. of interprocess communication.
  45. Then there are tricks associated with special domains,
  46. such as HTML hyperlinks or the heuristics mail readers
  47. use to highlight URLs embedded in mail messages.
  48. Some systems provide implicit ways to automate the attachment of program to data\(emthe
  49. best known examples are probably the resource forks in MacOS and the
  50. file name extension `associations' in Microsoft Windows\(embut in practice
  51. humans must too often carry their data from program to program.
  52. .LP
  53. Why should a human do the work?
  54. Usually there is one obvious thing to do with a piece of data,
  55. and the data itself suggests what this is.
  56. Resource forks and associations speak to this issue directly, but statically and narrowly and with
  57. little opportunity to control the behavior.
  58. Mechanisms with more generality,
  59. such as cut and paste or drag and drop, demand too much manipulation by
  60. the user and are (therefore) too error-prone.
  61. .LP
  62. We want a system that, given a piece of data,
  63. hands it to the appropriate application by default with little or no human intervention,
  64. while still permitting the user to override the defaults if desired.
  65. .LP
  66. The plumbing system is an attempt to address some of these issues in a single,
  67. coherent, central way.
  68. It provides a mechanism for
  69. formatting and sending arbitrary messages between applications,
  70. typically interactive programs such as text editors, web browsers, and the window system,
  71. under the control of a central message-handling server called the
  72. .I plumber .
  73. Interactive programs provide application-specific connections to the plumber,
  74. triggering with minimal user action the transfer of data or control to other programs.
  75. The result is similar to a hypertext system in which all the links are implicit,
  76. extracted automatically by examining the data and the user's actions.
  77. It obviates
  78. cut and paste and other such hand-driven interprocess communication mechanisms.
  79. Plumbing delivers the goods to the right place automatically.
  80. .SH
  81. Overview
  82. .LP
  83. The plumber is implemented as a Plan 9 file server [Pike93];
  84. programs send messages by writing them to the plumber's file
  85. .CW /mnt/plumb/send ,
  86. and receive messages by reading them from
  87. .I ports ,
  88. which are other plumber files in
  89. .CW /mnt/plumb .
  90. For example,
  91. .CW /mnt/plumb/edit
  92. is by convention the file from which a text editor reads messages requesting it to
  93. open and display a file for editing.
  94. (See Figure 1.)
  95. .if h .B1 10 60
  96. .KF
  97. .PS
  98. down
  99. P1: ellipse "ProgramA"
  100. move
  101. P2: ellipse "ProgramB"
  102. move
  103. P3: ellipse "ProgramC"
  104. right
  105. INVIS: box wid 1.3 invis at P2.e
  106. SEND: arrow from INVIS.e "\f(CWsend \fP" ""
  107. arrow -> right 0.2 from P1.e; spline -> right 0.2 then down 1 to SEND.w
  108. arrow -> right 0.2 from P2.e; arrow -> to SEND.w
  109. arrow -> right 0.2 from P3.e; spline -> right 0.2 then up 1 to SEND.w
  110. right
  111. PL: box height 1 "plumber" with .w at SEND.e
  112. A3: arrow 0.8 -> "\f(CWimage\fP" ""; arrow ->
  113. O3: ellipse "Viewer"
  114. O2: ellipse "Browser" with .s at O3.n + (0, 0.1)
  115. O1: ellipse "Editor" with .s at O2.n + (0, 0.1)
  116. O4: ellipse "Faces" with .n at O3.s + (0, -0.1)
  117. O5: ellipse "..." with .n at O4.s + (0, -0.1)
  118. right
  119. A1: arrow 0.8 -> "\f(CWedit\fP" "" from PL.e + (0, .4); spline -> right 0.15 then up 0.7 then to O1.w
  120. right
  121. A2: arrow 0.8 -> "\f(CWweb\fP" "" from PL.e + (0, .2); spline -> right 0.3 then up 0.3 then to O2.w
  122. right
  123. A4: arrow 0.8 -> "\f(CWnewmail\fP" "" from PL.e + (0, -.2); spline -> right 0.3 then down 0.3 then to O4.w
  124. right
  125. A5: arrow 0.8 -> "\f(CW...\fP" "" from PL.e + (0, -.4); spline -> right 0.15 then down 0.7 then to O5.w
  126. .PE
  127. .IP
  128. .ps -1
  129. Figure 1. The plumber controls the flow of messages between applications.
  130. Programs write to the file
  131. .CW send
  132. and receive on `ports' of various names representing services such as
  133. .CW edit
  134. or
  135. .CW web .
  136. Although the figure doesn't illustrate it, some programs may both send and receive messages,
  137. and some ports are read by multiple applications.
  138. .sp
  139. .KE
  140. .if h .B2
  141. .LP
  142. The plumber takes messages from the
  143. .CW send
  144. file and interprets their contents using rules defined by
  145. a special-purpose pattern-action language.
  146. The language specifies any rewriting of the message that is to be done by the plumber
  147. and defines how to dispose of a message, such as by sending it to a port or
  148. starting a new process to handle it.
  149. .LP
  150. The behavior is best described by example.
  151. Imagine that the user has, in a terminal emulator window,
  152. just run a compilation that has failed:
  153. .P1
  154. % make
  155. cc -c rmstar.c
  156. rmstar.c:32: syntax error
  157. \&...
  158. .P2
  159. The user points the typing cursor somewhere in the string
  160. .CW rmstar.c:32:
  161. and executes the
  162. .CW plumb
  163. menu entry.
  164. This causes the terminal emulator to format a plumbing message
  165. containing the entire string surrounding the cursor,
  166. .CW rmstar:32: ,
  167. and to write it to
  168. .CW /mnt/plumb/send .
  169. The plumber receives this message and compares it sequentially to the various
  170. patterns in its configuration.
  171. Eventually, it will find one that breaks the string into pieces,
  172. .CW rmstar.c ,
  173. a colon,
  174. .CW 32 ,
  175. and the final colon.
  176. Other associated patterns verify that
  177. .CW rmstar.c
  178. is a file in the current directory of the program generating
  179. the message, and that
  180. .CW 32
  181. looks like a line number within it.
  182. The plumber rewrites the message,
  183. setting the data to the string
  184. .CW rmstar.c
  185. and attaching an indication that
  186. .CW 32
  187. is a line number to display.
  188. Finally, it sends the resulting message to the
  189. .CW edit
  190. port.
  191. The text editor picks up the message, opens
  192. .CW rmstar.c
  193. (if it's not already open) and highlights line 32, the location of the syntax error.
  194. .LP
  195. From the user's point of view, this process is simple: the error message appears,
  196. it is `plumbed', and the editor jumps to the problem.
  197. .LP
  198. Of course, there are many different ways to cause compiler messages to
  199. pop up the source of an error,
  200. but the design of the plumber addresses more general issues than the specific
  201. goal of shortening the compile/debug/edit cycle.
  202. It facilitates the general exchange of data among programs, interactive or otherwise,
  203. throughout the environment, and its
  204. architecture\(ema central, language-driven file server\(emalthough
  205. unusual, has distinct advantages.
  206. It makes plumbing easy to add to an existing, Unix-like command environment;
  207. it guarantees uniform handling of inter-application messages;
  208. it off-loads from those applications most of the work of extracting and dispatching messages;
  209. and it works transparently and effortlessly across a network.
  210. .LP
  211. This paper is organized bottom-up, beginning with the format of the messages
  212. and proceeding through the plumbing language, the handling of messages,
  213. and the interactive user interface.
  214. The last sections discuss the implications of the design
  215. and compare the plumbing system to other environments that
  216. provide similar services.
  217. .SH
  218. Format of messages
  219. .LP
  220. Since the language that controls the plumber is defined in terms of the
  221. contents of plumbing messages, we begin by describing their layout.
  222. .LP
  223. Plumbing messages have a fixed-format textual
  224. header followed by a free-format data section.
  225. The header consists of six lines of text, in set order,
  226. each specifying a property of the message.
  227. Any line may be blank except the last, which is the length of the data portion of the
  228. message, as a decimal string.
  229. The lines are, in order:
  230. .IP
  231. The source application, the name of the program generating the message.
  232. .IP
  233. The destination port, the name of the port to which the messages should be sent.
  234. .IP
  235. The working directory in which the message was generated.
  236. .IP
  237. The type of the data, analogous to a MIME type, such as
  238. .CW text
  239. or
  240. .CW image/gif .
  241. .IP
  242. Attributes of the message, given as blank-separated
  243. .I name\f(CW=\fPvalue
  244. pairs.
  245. The values may be quoted to protect
  246. blanks or quotes; values may not contain newlines.
  247. .IP
  248. The length of the data section, in bytes.
  249. .LP
  250. Here is a sample message, one that (conventionally) tells the editor to open the file
  251. .CW /usr/rob/src/mem.c
  252. and display line
  253. 27 within it:
  254. .P1
  255. plumbtest
  256. edit
  257. /usr/rob/src
  258. text
  259. addr=27
  260. 5
  261. mem.c
  262. .P2
  263. Because in general it need not be text, the data section of the message has no terminating newline.
  264. .LP
  265. A library interface simplifies the processing of messages by translating them
  266. to and from a data structure,
  267. .CW Plumbmsg ,
  268. defined like this:
  269. .P1
  270. .ta 4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n
  271. typedef struct Plumbattr Plumbattr;
  272. typedef struct Plumbmsg Plumbmsg;
  273. struct Plumbmsg
  274. {
  275. char *src; /* source application */
  276. char *dst; /* destination port */
  277. char *wdir; /* working directory */
  278. char *type; /* type of data */
  279. Plumbattr *attr; /* attribute list */
  280. int ndata; /* #bytes of data */
  281. char *data;
  282. };
  283. struct Plumbattr
  284. {
  285. char *name;
  286. char *value;
  287. Plumbattr *next;
  288. };
  289. .P2
  290. The library also includes routines to send a message, receive a message,
  291. manipulate the attribute list, and so on.
  292. .SH
  293. The Language
  294. .LP
  295. An instance of the plumber runs for each user on each terminal or workstation.
  296. It
  297. begins by reading its rules from the file
  298. .CW lib/plumbing
  299. in the user's home directory,
  300. which in turn may use
  301. .CW include
  302. statements to interpolate macro definitions and
  303. rules from standard plumbing rule libraries stored in
  304. .CW /sys/lib/plumb .
  305. .LP
  306. The rules control the processing of messages.
  307. They are written in
  308. a pattern-action language comprising a sequence of blank-line-separated
  309. .I rule
  310. .I sets ,
  311. each of which contains one or more
  312. .I patterns
  313. followed by one or more
  314. .I actions .
  315. Each incoming message is compared against the rule sets in order.
  316. If all the patterns within a rule set succeed,
  317. one of the associated actions is taken and processing completes.
  318. .LP
  319. The syntax of the language is straightforward.
  320. Each rule (pattern or action) has three components, separated by white space:
  321. an
  322. .I object ,
  323. a
  324. .I verb ,
  325. and optional
  326. .I arguments .
  327. The object
  328. identifies a part of the message, such as
  329. the source application
  330. .CW src ), (
  331. or the data
  332. portion of the message
  333. .CW data ), (
  334. or the rule's own arguments
  335. .CW arg ); (
  336. or it is the keyword
  337. .CW plumb ,
  338. which introduces an action.
  339. The verb specifies an operation to perform on the object, such as the word
  340. .CW is ' `
  341. to require precise equality between the object and the argument, or
  342. .CW isdir ' `
  343. to require that the object be the name of a directory.
  344. .LP
  345. For instance, this rule set sends messages containing the names of files
  346. ending in
  347. .CW .gif ,
  348. .CW .jpg ,
  349. etc. to a program,
  350. .CW page ,
  351. to display them; it is analogous to a Windows association rule:
  352. .P1
  353. # image files go to page
  354. type is text
  355. data matches '[a-zA-Z0-9_\e-./]+'
  356. data matches '([a-zA-Z0-9_\e-./]+)\e.(jpe?g|gif|bit|tiff|ppm)'
  357. arg isfile $0
  358. plumb to image
  359. plumb client page -wi
  360. .P2
  361. (Lines beginning with
  362. .CW #
  363. are commentary.)
  364. Consider how this rule handles the following message, annotated down the left column for clarity:
  365. .P1
  366. .ta 10n
  367. \f2src\fP plumbtest
  368. \f2dst\fP
  369. \f2wdir\fP /usr/rob/pics
  370. \f2type\fP text
  371. \f2attr\fP
  372. \f2ndata\fP 9
  373. \f2data\fP horse.gif
  374. .P2
  375. The
  376. .CW is
  377. verb specifies a precise match, and the
  378. .CW type
  379. field of the message is the string
  380. .CW text ,
  381. so the first pattern succeeds.
  382. The
  383. .CW matches
  384. verb invokes a regular expression pattern match of the object (here
  385. .CW data )
  386. against the argument pattern.
  387. Both
  388. .CW matches
  389. patterns in this rule set will succeed, and in the process set the variables
  390. .CW $0
  391. to the matched string,
  392. .CW $1
  393. to the first parenthesized submatch, and so on (analogous to
  394. .CW & ,
  395. .CW \e1 ,
  396. etc. in
  397. .CW ed 's
  398. regular expressions).
  399. The pattern
  400. .CW arg
  401. .CW isfile
  402. .CW $0
  403. verifies that the named file,
  404. .CW horse.gif ,
  405. is an actual file in the directory
  406. .CW /usr/rob/pics .
  407. If all the patterns succeed, one of the actions will be executed.
  408. .LP
  409. There are two actions in this rule set.
  410. The
  411. .CW plumb
  412. .CW to
  413. rule specifies
  414. .CW image
  415. as the destination port of the message.
  416. By convention, the plumber mounts its services in the directory
  417. .CW /mnt/plumb ,
  418. so in this case if the file
  419. .CW /mnt/plumb/image
  420. has been opened, the message will be made available to the program reading from it.
  421. Note that the message does not name a port, but the rule set that matches
  422. the message does, and that is sufficient to dispatch the message.
  423. If on the other hand a message matches no rule but has an explicit port mentioned,
  424. that too is sufficient.
  425. .LP
  426. If no client has opened the
  427. .CW image
  428. port,
  429. that is, if the program
  430. .CW page
  431. is not already running, the
  432. .CW plumb
  433. .CW client
  434. action gives the execution script to start the application
  435. and send the message on its way; the
  436. .CW -wi
  437. arguments tell
  438. .CW page
  439. to create a window and to receive its initial arguments from the plumbing port.
  440. The process by which the plumber starts a program is described in more detail in the next section.
  441. .LP
  442. It may seem odd that there are two
  443. .CW matches
  444. rules in this example.
  445. The reason is related to the way the plumber can use the rules themselves
  446. to refine the
  447. .I data
  448. in the message, somewhat in the manner of Structural Regular Expressions [Pike87a].
  449. For example, consider what happens if the cursor is at the last character of
  450. .P1
  451. % make nightmare>horse.gif
  452. .P2
  453. and the user asks to plumb what the cursor is pointing at.
  454. The program creating the plumbing
  455. message\(emin this case the terminal emulator running the window\(emcan send the
  456. entire white-space-delimited string
  457. .CW nightmare>horse.gif
  458. or even the entire line, and the combination of
  459. .CW matches
  460. rules can determine that the user was referring to the string
  461. .CW horse.gif .
  462. The user could of course select the entire string
  463. .CW horse.gif ,
  464. but it's more convenient just to point in the general location and let the machine
  465. figure out what should be done.
  466. The process is as follows.
  467. .LP
  468. The application generating the message adds a special attribute to the message, named
  469. .CW click ,
  470. whose numerical value is the offset of the cursor\(emthe selection point\(emwithin the data string.
  471. This attribute tells the plumber two things:
  472. first, that the regular expressions in
  473. .CW matches
  474. rules should be used to identify the relevant data;
  475. and second, approximately where the relevant data lies.
  476. The plumber
  477. will then use the first
  478. .CW matches
  479. pattern to identify the longest leftmost match that touches the cursor, which will extract the string
  480. .CW horse.gif ,
  481. and the second pattern will then verify that that names a picture file.
  482. The rule set succeeds and the data is winnowed to the matching substring
  483. before being sent to its destination.
  484. .LP
  485. Each
  486. .CW matches
  487. pattern within a given rule set must match the same portion of the string, which
  488. guarantees that the rule set fails to match a string for which the
  489. second pattern matches only a portion.
  490. For instance, our example rule set should not execute if the data is the string
  491. .CW horse.gift ,
  492. and although the first pattern will match
  493. .CW horse.gift ,
  494. the second will match only
  495. .CW horse.gif
  496. and the rule set will fail.
  497. .LP
  498. The same approach of multiple
  499. .CW matches
  500. rules can be used to exclude, for instance, a terminal period from
  501. a file name or URL, so a file name or URL at the end of a sentence is recognized properly.
  502. .LP
  503. If a
  504. .CW click
  505. attribute is not specified, all patterns must match the entire string,
  506. so the user has an option:
  507. he or she may select exactly what data to send,
  508. or may instead indicate where the data is by clicking the selection button on the mouse
  509. and letting the machine locate the URL or image file name within the text.
  510. In other words,
  511. the user can control the contents of the message precisely when required,
  512. but the default, simplest action in the user interface does the right thing most of the time.
  513. .SH
  514. How Messages are Handled in the Plumber
  515. .LP
  516. An application creates a message header, fills in whatever fields it wishes to define,
  517. attaches the data, and writes the result to the file
  518. .CW send
  519. in the plumber's service directory,
  520. .CW /mnt/plumb .
  521. The plumber receives the message and applies the plumbing rules successively to it.
  522. When a rule set matches, the message is dispatched as indicated by that rule set
  523. and processing continues with the next message.
  524. If no rule set matches the message, the plumber indicates this by returning a write
  525. error to the application, that is, the write to
  526. .CW /mnt/plumb/send
  527. fails, with the resulting error string
  528. describing the failure.
  529. (Plan 9 uses strings rather than pre-defined numbers to describe error conditions.)
  530. Thus a program can discover whether a plumbing message has been sent successfully.
  531. .LP
  532. After a matching rule set has been identified, the plumber applies a series of rewriting
  533. steps to the message. Some rewritings are defined by the rule set; others are implicit.
  534. For example, if the message does not specify a destination port, the outgoing message
  535. will be rewritten to identify it.
  536. If the message does specify the port, the rule set will only match if any
  537. .CW plumb
  538. .CW to
  539. action in the rule set names the same port.
  540. (If it matches no rule sets, but mentions a port, it will be sent there unmodified.)
  541. .LP
  542. The rule set may contain actions that explicitly rewrite components of the message.
  543. These may modify the attribute list or replace the data section of the message.
  544. Here is a sample rule set that does both.
  545. It matches strings of the form
  546. .CW plumb.h
  547. or
  548. .CW plumb.h:27 .
  549. If that string identifies a file in the standard C include directory,
  550. .CW /sys/include ,
  551. perhaps with an optional line number, the outgoing message
  552. is rewritten to contain the full path name and an attribute,
  553. .CW addr ,
  554. to hold the line number:
  555. .P1
  556. # .h files are looked up in /sys/include and passed to edit
  557. type is text
  558. data matches '([a-zA-Z0-9]+\e.h)(:([0-9]+))?'
  559. arg isfile /sys/include/$1
  560. data set /sys/include/$1
  561. attr add addr=$3
  562. plumb to edit
  563. .P2
  564. The
  565. .CW data
  566. .CW set
  567. rule replaces the contents of the data, and the
  568. .CW attr
  569. .CW add
  570. rule adds a new attribute to the message.
  571. The intent of this rule is to permit one to plumb an include file name in a C program
  572. to trigger the opening of that file, perhaps at a specified line, in the text editor.
  573. A variant of this rule, discussed below,
  574. tells the editor how to interpret syntax errors from the compiler,
  575. or the output of
  576. .CW grep
  577. .CW -n ,
  578. both of which use a fixed syntax
  579. .I file\f(CW:\fPline
  580. to identify a line of source.
  581. .LP
  582. The Plan 9 text editors interpret the
  583. .CW addr
  584. attribute as the definition of which portion of the file to display.
  585. In fact, the real rule includes a richer definition of the address syntax,
  586. so one may plumb strings such as
  587. .CW plumb.h:/plumbsend
  588. (using a regular expression after the
  589. .CW / )
  590. to pop up the declaration of a function in a C header file.
  591. .LP
  592. Another form of rewriting is that the plumber may modify the attribute list of
  593. the message to clarify how to handle the message.
  594. The primary example of this involves the treatment of the
  595. .CW click
  596. attribute, described in the previous section.
  597. If the message contains a
  598. .CW click
  599. attribute and the matching rule set uses it to extract the matching substring from the data,
  600. the plumber
  601. deletes the
  602. .CW click
  603. attribute and replaces the data with the matching substring.
  604. .LP
  605. Once the message is rewritten, the actions of the matching rule set are examined.
  606. If the rule set contains a
  607. .CW plumb
  608. .CW to
  609. action and the corresponding port is open\(emthat is, if a program is already reading
  610. from that port\(emthe message is delivered to the port.
  611. The application will receive the message and handle it as it sees fit.
  612. If the port is not open, a
  613. .CW plumb
  614. .CW start
  615. or
  616. .CW plumb
  617. .CW client
  618. action will start a new program to handle the message.
  619. .LP
  620. The
  621. .CW plumb
  622. .CW start
  623. action is the simpler: its argument specifies a command to run
  624. instead of passing on the message; the message is discarded.
  625. Here for instance is a rule that, given the process id (pid) of an existing process,
  626. starts the
  627. .CW acid
  628. debugger [Wint94] in a new window to examine that process:
  629. .P1
  630. # processes go to acid (assuming strlen(pid) >= 2)
  631. type is text
  632. data matches '[a-zA-Z0-9.:_\e-/]+'
  633. data matches '[0-9][0-9]+'
  634. arg isdir /proc/$0
  635. plumb start window acid $0
  636. .P2
  637. (Note the use of multiple
  638. .CW matches
  639. rules to avoid misfires from strings like
  640. .CW party.1999 .)
  641. The
  642. .CW arg
  643. .CW isdir
  644. rule checks that the pid represents a running process (or broken one; Plan 9 does not create
  645. .CW core
  646. files but leaves broken processes around for debugging) by checking that the process file
  647. system has a directory for that pid [Kill84].
  648. Using this rule, one may plumb the pid string printed by the
  649. .CW ps
  650. command or by the operating system when the program breaks;
  651. the debugger will then start automatically.
  652. .LP
  653. The other startup action,
  654. .CW plumb
  655. .CW client ,
  656. is used when a program will read messages from the plumbing port.
  657. For example,
  658. text editors can read files specified as command arguments, so one could use a
  659. .CW plumb
  660. .CW start
  661. rule to begin editing a file.
  662. If, however, the editor will read messages from the
  663. .CW edit
  664. plumbing port, letting it read the message
  665. from the port insures that it uses other information in the message,
  666. such as the line number to display.
  667. The
  668. .CW plumb
  669. .CW client
  670. action is therefore like
  671. .CW plumb
  672. .CW start ,
  673. but keeps the message around for delivery when the application opens the port.
  674. Here is the full rule set to pass a regular file to the text editor:
  675. .P1
  676. # existing files, possibly tagged by address, go to editor
  677. type is text
  678. data matches '([.a-zA-Z0-9_/\e-]*[a-zA-Z0-9_/\e-])('$addr')?'
  679. arg isfile $1
  680. data set $1
  681. attr add addr=$3
  682. plumb to edit
  683. plumb client window $editor
  684. .P2
  685. If the editor is already running, the
  686. .CW plumb
  687. .CW to
  688. rule causes it to receive the message on the port.
  689. If not,
  690. the command
  691. .CW window "" `
  692. .CW $editor '
  693. will create a new window (using the Plan 9 program
  694. .CW window )
  695. to run the editor, and once that starts it will open the
  696. .CW edit
  697. plumbing port as usual and discover this first message already waiting.
  698. .LP
  699. The variables
  700. .CW $editor
  701. and
  702. .CW $addr
  703. in this rule set
  704. are macros defined in the plumbing rules file; they specify the name of the user's favorite text editor
  705. and a regular expression
  706. that matches that editor's address syntax, such as line numbers and patterns.
  707. This rule set lives in a library of shared plumbing rules that
  708. users' private rules can build on,
  709. so the rule set needs to be adaptable to different editors and their address syntax.
  710. The macro definitions for Acme and Sam [Pike94,Pike87b] look like this:
  711. .P1
  712. editor=acme
  713. # or editor=sam
  714. addrelem='((#?[0-9]+)|(/[A-Za-z0-9_\e^]+/?)|[.$])'
  715. addr=:($addrelem([,;+\e-]$addrelem)*)
  716. .P2
  717. .LP
  718. Finally, the application reads the message from the appropriate port, such as
  719. .CW /mnt/plumb/edit ,
  720. unpacks it, and goes to work.
  721. .SH
  722. Message Delivery
  723. .LP
  724. In summary, a message is delivered by writing it to the
  725. .CW send
  726. file and having the plumber, perhaps after some rewriting, send it to the destination
  727. port or start a new application to handle it.
  728. If no destination can be found by the plumber, the original write to the
  729. .CW send
  730. file will fail, and the application will know the message could not be delivered.
  731. .LP
  732. If multiple applications are reading from the destination port, each will receive
  733. an identical copy of the message; that is, the plumber implements fan-out.
  734. The number of messages delivered is equal to the number of clients that have
  735. opened the destination port.
  736. The plumber queues the messages and makes sure that each application that opened
  737. the port before the message was written gets exactly one copy.
  738. .LP
  739. This design minimizes blocking in the sending applications, since the write to the
  740. .CW send
  741. file can complete as soon as the message has been queued for the appropriate port.
  742. If the plumber waited for the message to be read by the recipient, the sender could
  743. block unnecessarily.
  744. Unfortunately, this design also means that there is no way for a sender to know when
  745. the message has been handled; in fact, there are cases when
  746. the message will not be delivered at all, such as if the recipient exits while there are
  747. still messages in the queue.
  748. Since the plumber is part of a user interface, and not
  749. an autonomous message delivery system,
  750. the decision was made to give the
  751. non-blocking property priority over reliability of message delivery.
  752. In practice, this tradeoff has worked out well:
  753. applications almost always know when a message has failed to be delivered (the
  754. .CW write
  755. fails because no destination could be found),
  756. and those occasions when the sender believes incorrectly that the message has been delivered
  757. are both extremely rare and easily recognized by the user\(emusually because the recipient
  758. application has exited.
  759. .SH
  760. The Rules File
  761. .LP
  762. The plumber begins execution by reading the user's startup plumbing rules file,
  763. .CW lib/plumbing .
  764. Since the plumber is implemented as a file server, it can also present its current rules
  765. as a dynamic file, a design that provides an easily understood way to maintain the rules.
  766. .LP
  767. The file
  768. .CW /mnt/plumb/rules
  769. is the text of the rule set the plumber is currently using,
  770. and it may be edited like a regular file to update those rules.
  771. To clear the rules, truncate that file;
  772. to add a new rule set, append to it:
  773. .P1
  774. % echo 'type is text
  775. data is self-destruct
  776. plumb start rm -rf $HOME' >> /mnt/plumb/rules
  777. .P2
  778. This rule set will take effect immediately.
  779. If it has a syntax error, the write will fail with an error message from the plumber,
  780. such as `malformed rule' or 'undefined verb'.
  781. .LP
  782. To restore the plumber to its startup configuration,
  783. .P1
  784. % cp /usr/$user/lib/plumbing /mnt/plumb/rules
  785. .P2
  786. For more sophisticated changes,
  787. one can of course use a regular text editor to modify
  788. .CW /mnt/plumb/rules .
  789. .LP
  790. This simple way of maintaining an active service could profitably be adopted by other systems.
  791. It avoids the need to reboot, to update registries with special tools, or to send asynchronous signals
  792. to critical programs.
  793. .SH
  794. The User Interface
  795. .LP
  796. One unusual property of the plumbing system is that
  797. the user interface that programs provide to access it can vary considerably, yet
  798. the result is nonetheless a unifying force in the environment.
  799. Shells talk to editors, image viewers, and web browsers; debuggers talk to editors;
  800. editors talk to themselves; and the window system talks to everybody.
  801. .LP
  802. The plumber grew out of some of the ideas of the Acme editor/window-system/user interface [Pike94],
  803. in particular its `acquisition' feature.
  804. With a three-button mouse, clicking the right button in Acme on a piece of text tells Acme to
  805. get the thing being pointed to.
  806. If it is a file name, open the file;
  807. if it is a directory, open a viewer for its contents;
  808. if a line number, go to that line;
  809. if a regular expression, search for it.
  810. This one-click access to anything describable textually was very powerful but had several
  811. limitations, of which the most important were that Acme's rules for interpreting the
  812. text (that is, the implicit hyperlinks) were hard-wired and inflexible, and
  813. that they only applied to and within Acme itself.
  814. One could not, for example, use Acme's power to open an image file, since Acme is
  815. a text-only system.
  816. .LP
  817. The plumber addresses these limitations, even with Acme itself:
  818. Acme now uses the plumber to interpret the right button clicks for it.
  819. When the right button is clicked on some text,
  820. Acme constructs a plumbing message much as described above,
  821. using the
  822. .CW click
  823. attribute and the white-space-delimited text surrounding the click.
  824. It then writes the message to the plumber; if the write succeeds, all is well.
  825. If not, it falls back to its original, internal rules, which will result in a context search
  826. for the word within the current document.
  827. .LP
  828. If the message is sent successfully, the recipient is likely to be Acme itself, of course:
  829. the request may be to open a file, for example.
  830. Thus Acme has turned the plumber into an external component of its own operation,
  831. while expanding the possibilities; the operation might be to start an image viewer to
  832. open a picture file, something Acme cannot do itself.
  833. The plumber expands the power of Acme's original user interface.
  834. .LP
  835. Traditional menu-driven programs such as the text editor Sam [Pike87b] and the default
  836. shell window of the window
  837. system
  838. .CW 8½
  839. [Pike91] cannot dedicate a mouse button solely to plumbing, but they can certainly
  840. dedicate a menu entry.
  841. The editing menu for such programs now contains an entry,
  842. .CW plumb ,
  843. that creates a plumbing message using the current selection.
  844. (Acme manages to send a message by clicking on the text with one button;
  845. other programs require a click with the select button and then a menu operation.)
  846. For example, after this happens in a shell window:
  847. .P1
  848. % make
  849. cc -c shaney.c
  850. shaney.c:232: i undefined
  851. \&...
  852. .P2
  853. one can click anywhere on the string
  854. .CW shaney.c:232 ,
  855. execute the
  856. .CW plumb
  857. menu entry, and have line 232 appear in the text editor, be it Sam or Acme\(emwhichever has the
  858. .CW edit
  859. port open.
  860. (If this were an Acme shell window, it would be sufficient to right-click on the string.)
  861. .LP
  862. [An interesting side line is how the window system knows what directory the
  863. shell is running in; in other words, what value to place in the
  864. .CW wdir
  865. field of the plumb message.
  866. Recall that
  867. .CW 8½
  868. is, like many Plan 9 programs, a file server.
  869. It now serves a new file,
  870. .CW /dev/wdir ,
  871. that is private to each window.
  872. Programs, in particular the
  873. Plan 9 shell,
  874. .CW rc ,
  875. can write that file to inform the window system of its current directory.
  876. When a
  877. .CW cd
  878. command is executed in an interactive shell,
  879. .CW rc
  880. updates the contents of
  881. .CW /dev/wdir
  882. and plumbing can proceed with local file names.]
  883. .LP
  884. Of course, users can plumb image file names, process ids, URLs, and other items\(emany string
  885. whose syntax and disposition are defined in the plumbing rules file.
  886. An example of how the pieces fit together is the way Plan 9 now handles mail, particularly
  887. MIME-encoded messages.
  888. .LP
  889. When a new mail message arrives, the mail receiver process sends a plumbing message to the
  890. .CW newmail
  891. port, which notifies any interested process that new mail is here.
  892. The plumbing message contains information about the mail, including
  893. its sender, date, and current location in the file system.
  894. The interested processes include a program,
  895. .CW faces ,
  896. that gives a graphical display of the mail box using
  897. faces to represent the senders of messages [PiPr85],
  898. as well as interactive mail programs such as the Acme mail viewer [Pike94].
  899. The user can then click on the face that appears, and the
  900. .CW faces
  901. program will send another plumbing message, this time to the
  902. .CW showmail
  903. port.
  904. Here is the rule for that port:
  905. .P1
  906. # faces -> new mail window for message
  907. type is text
  908. data matches '[a-zA-Z0-9_\e-./]+'
  909. data matches '/mail/fs/[a-zA-Z0-9/]+/[0-9]+'
  910. plumb to showmail
  911. plumb start window edmail -s $0
  912. .P2
  913. If a program, such as the Acme mail reader, is reading that port, it will open a new window
  914. in which to display the message.
  915. If not, the
  916. .CW plumb
  917. .CW start
  918. rule will create a new window and run
  919. .CW edmail ,
  920. a conventional mail reading process, to examine it.
  921. Notice how the plumbing connects the components of the interface together the same way
  922. regardless of which components are actually being used to view mail.
  923. .LP
  924. There is more to the mail story.
  925. Naturally, mail boxes in Plan 9 are treated as little file systems, which are synthesized
  926. on demand by a special-purpose file server that takes a flat mail box file and converts
  927. it into a set of directories, one per message, with component files containing the header,
  928. body, MIME information, and so on.
  929. Multi-part MIME messages are unpacked into multi-level directories, like this:
  930. .P1
  931. % ls -l /mail/fs/mbox/25
  932. d-r-xr-xr-x M 20 rob rob 0 Nov 21 13:06 /mail/fs/mbox/25/1
  933. d-r-xr-xr-x M 20 rob rob 0 Nov 21 13:06 /mail/fs/mbox/25/2
  934. --r--r--r-- M 20 rob rob 28678 Nov 21 13:06 /mail/fs/mbox/25/body
  935. --r--r--r-- M 20 rob rob 0 Nov 21 13:06 /mail/fs/mbox/25/cc
  936. \&...
  937. % mail
  938. 25 messages
  939. : 25
  940. From: presotto
  941. Date: Sun Nov 21 13:05:51 EST 1999
  942. To: rob
  943. Check this out.
  944. ===> 2/ (image/jpeg) [inline]
  945. /mail/fs/mbox/25/2/fabio.jpg
  946. :
  947. .P2
  948. Since the components are all (synthetic) files, the user can plumb the pieces
  949. to view embedded pictures, URLs, and so on.
  950. Note that the mail program can plumb the contents of
  951. .CW inline
  952. attachments automatically, without user interaction;
  953. in other words, plumbing lets the mailer handle multimedia data
  954. without itself interpreting it.
  955. .LP
  956. At a more mundane level, a shell command,
  957. .CW plumb ,
  958. can be used to send messages:
  959. .P1
  960. % cd /usr/rob/src
  961. % plumb mem.c
  962. .P2
  963. will send the appropriate message to the
  964. .CW edit
  965. port.
  966. A surprising use of the
  967. .CW plumb
  968. command is in actions within the plumbing rules file.
  969. In our lab, we commonly receive Microsoft Word documents by mail,
  970. but we do not run Microsoft operating systems on our machines so we cannot
  971. view them without at least rebooting.
  972. Therefore, when a Word document arrives in mail, we could plumb the
  973. .CW .doc
  974. file but the text editor could not decode it.
  975. However, we have a program,
  976. .CW doc2txt ,
  977. that decodes the Word file format to extract and format the embedded text.
  978. The solution is to use
  979. .CW plumb
  980. in a
  981. .CW plumb
  982. .CW start
  983. action to invoke
  984. .CW doc2txt
  985. on
  986. .CW .doc
  987. files and synthesize a plain text file:
  988. .P1
  989. # rule set for microsoft word documents
  990. type is text
  991. data matches '[a-zA-Z0-9_\e-./]+'
  992. data matches '([a-zA-Z0-9_\e-./]+)\e.doc'
  993. arg isfile $0
  994. plumb start doc2txt $data | \e
  995. plumb -i -d edit -a action=showdata -a filename=$0
  996. .P2
  997. The arguments to
  998. .CW plumb
  999. tell it to take standard input as its data rather than the text of the arguments
  1000. .CW -i ), (
  1001. define the destination port
  1002. .CW -d "" (
  1003. .CW edit ),
  1004. and set a conventional attribute so the editor knows to show the message data
  1005. itself rather than interpret it as a file name
  1006. .CW -a "" (
  1007. .CW action=showdata )
  1008. and provide the original file name
  1009. .CW -a "" (
  1010. .CW filename=$0 ).
  1011. Now when a user plumbs a
  1012. .CW .doc
  1013. file the plumbing rules run a process to extract the text and send it as a
  1014. temporary file to the editor for viewing.
  1015. It's imperfect, but it's easy and it beats rebooting.
  1016. .LP
  1017. Another simple example is a rule that turns man pages into hypertext.
  1018. Manual page entries of the form
  1019. .CW plumber(1)
  1020. can be clicked on to pop up a window containing the formatted `man page'.
  1021. That man page will in turn contain more such citations, which will also be clickable.
  1022. The rule is a little like that for Word documents:
  1023. .P1
  1024. # man index entries are synthesized
  1025. type is text
  1026. data matches '([a-zA-Z0-9_\e-./]+)\e(([0-9])\e)'
  1027. plumb start man $2 $1 | \e
  1028. plumb -i -d edit -a action=showdata -a filename=/man/$1($2)
  1029. .P2
  1030. .LP
  1031. There are many other inventive uses of plumbing.
  1032. One more should give some of the flavor.
  1033. We have a shell script,
  1034. .CW src ,
  1035. that takes as argument the name of an executable binary file.
  1036. It examines the symbol table of the binary to find the source file
  1037. from which it was compiled.
  1038. Since the Plan 9 compilers place full source path names in the symbol table,
  1039. .CW src
  1040. can discover the complete file name.
  1041. That is then passed to
  1042. .CW plumb ,
  1043. complete with the line number to find the
  1044. symbol
  1045. .CW main .
  1046. For example,
  1047. .P1
  1048. % src plumb
  1049. .P2
  1050. is all it takes to pop up an editor window on the
  1051. .CW main
  1052. routine of the
  1053. .CW plumb
  1054. command, beginning at line 39 of
  1055. .CW /sys/src/cmd/plumb/plumb.c .
  1056. Like most uses of plumbing,
  1057. this is not a breakthrough in functionality, but it is a great convenience.
  1058. .SH
  1059. Why This Architecture?
  1060. .LP
  1061. The design of the plumbing system is peculiar:
  1062. a centralized language-based file server does most of the work,
  1063. while compared to other systems the applications themselves
  1064. contribute relatively little.
  1065. This architecture is deliberate, of course.
  1066. .LP
  1067. That the plumber's behavior is derived from a linguistic description
  1068. gives the system great flexibility and dynamism\(emrules can be added
  1069. and changed at will, without rebooting\(embut the existence of a central library of rules
  1070. ensures that, for most users, the environment behaves in well-established ways.
  1071. .LP
  1072. That the plumber is a file server is perhaps the most unusual aspect of its design,
  1073. but is also one of the most important.
  1074. Messages are passed by regular I/O operations on files, so no extra technology
  1075. such as remote procedure call or request brokers needs to be provided;
  1076. messages are transmitted by familiar means.
  1077. Almost every service in Plan 9 is a file server, so services can be exported
  1078. trivially using the system's remote file system operations [Pike93].
  1079. The plumber is no exception;
  1080. plumbing messages pass routinely across the network to remote applications without
  1081. any special provision,
  1082. in contrast to some commercial IPC mechanisms that become
  1083. significantly more complex when they involve multiple machines.
  1084. As I write this, my window system is talking to applications running on three
  1085. different machines, but they all share a single instance of the plumber and so
  1086. can interoperate to integrate my environment.
  1087. Plan 9 uses a shared file name space
  1088. to combine multiple networked machines\(emcompute servers,
  1089. file servers, and interactive workstations\(eminto a single
  1090. computing environment; plumbing's design as a file server
  1091. is a natural by-product of, and contributor to, the overall system architecture
  1092. [Pike92].
  1093. .LP
  1094. The centrality of the plumber is also unusual.
  1095. Other systems tend to let the applications determine where messages will go;
  1096. consider mail readers that recognize and highlight URLs in the messages.
  1097. Why should just the mail readers do this, and why should they just do it for URLs?
  1098. (Acme was guilty of similar crimes.)
  1099. The plumber, by removing such decisions to a central authority,
  1100. guarantees that all applications behave the same and simultaneously
  1101. frees them all from figuring out what's important.
  1102. The ability for the plumber to excerpt useful data from within a message
  1103. is critical to the success of this model.
  1104. .LP
  1105. The entire system is remarkably small.
  1106. The plumber itself is only about two thousand lines of C code.
  1107. Most applications work fine in a plumbing environment without knowing about it at all;
  1108. some need trivial changes such as to standardize their error output;
  1109. a few need to generate and receive plumbing messages.
  1110. But even to add the ability to send and receive messages in a program such as text editor is short work,
  1111. involving typically a few dozen lines of code.
  1112. Plumbing fits well into the existing environment.
  1113. .LP
  1114. But plumbing is new and it hasn't been pushed far enough yet.
  1115. Most of the work so far has been with textual messages, although
  1116. the underlying system is capable of handling general data.
  1117. We plan to reimplement some of the existing data movement operations,
  1118. such as cut and paste or drag and drop, to use plumbing as their exchange mechanism.
  1119. Since the plumber is a central message handler, it is an obvious place to store the `clipboard'.
  1120. The clipboard could be built as a special port that holds onto messages rather than
  1121. deleting them after delivery.
  1122. Since the clipboard would then be holding a plumbing
  1123. message rather than plain text, as in the current Plan 9 environment,
  1124. it would become possible to cut and paste arbitrary data without
  1125. providing new mechanism.
  1126. In effect, we would be providing a new user interface to the existing plumbing facilities.
  1127. .LP
  1128. Another possible extension is the ability to override plumbing operations interactively.
  1129. Originally, the plan was to provide a mechanism, perhaps a pop-up menu, that one could
  1130. use to direct messages, for example to send a PostScript file to the editor rather than the
  1131. PostScript viewer by naming an explicit destination in the message.
  1132. Although this deficiency should one day be addressed, it should be done without
  1133. complicating the interface for invoking the default behavior.
  1134. Meanwhile, in practice the default behavior seems to work very well in practice\(emas it
  1135. must if plumbing is to be successful\(emso the lack of
  1136. overrides is not keenly felt.
  1137. .SH
  1138. Comparison with Other Systems
  1139. .LP
  1140. The ideas of the plumbing system grew from an
  1141. attempt to generalize the way Acme acquires files and data.
  1142. Systems further from that lineage also share some properties with plumbing.
  1143. Most, however, require explicit linking or message passing rather than
  1144. plumbing's implicit, context-based pattern matching, and none
  1145. has the plumber's design of a language-based file server.
  1146. .LP
  1147. Reiss's FIELD system [Reis95] probably comes the closest to providing the facilities of the plumber.
  1148. It has a central message-passing mechanism that connects applications together through
  1149. a combination of a library and a pattern-matching central message dispatcher that handles
  1150. message send and reply.
  1151. The main differences between FIELD's message dispatcher and the plumber are first
  1152. that the plumber is based on a special-purpose language while the FIELD
  1153. system uses an object-oriented library, second that the plumber has no concept
  1154. of a reply to a message, and finally that the FIELD system
  1155. has no concept of port.
  1156. But the key distinction is probably in the level of use.
  1157. In FIELD, the message dispatcher is a critical integrating force of the underlying
  1158. programming environment, handling everything from debugging events to
  1159. changing the working directory of a program.
  1160. Plumbing, by contrast, is intended primarily for integrating the user interface
  1161. of existing tools; it is more modest and very much simpler.
  1162. The central advantage of the plumber is its convenience and dynamism;
  1163. the FIELD system does not share the ease with which
  1164. message dispatch rules can be added or modified.
  1165. .LP
  1166. The inspiration for Acme was
  1167. the user interface to the object-oriented Oberon system [WiGu92].
  1168. Oberon's user interface interprets mouse clicks on strings such as
  1169. .CW Obj.meth
  1170. to invoke calls to the method
  1171. .CW meth
  1172. of the object
  1173. .CW Obj .
  1174. This was the starting point for Acme's middle-button execution [Pike94],
  1175. but nothing in Oberon is much like Acme's right-button `acquisition',
  1176. which was the starting point for the plumber.
  1177. Oberon's implicit method-based linking is not nearly as general as the pattern-matched
  1178. linking of the plumber, nor does its style of user-triggered method call
  1179. correspond well to the more general idea of inter-application communication
  1180. of plumbing messages.
  1181. .LP
  1182. Microsoft's OLE interface is another relative.
  1183. It allows one application to
  1184. .I embed
  1185. its own data within another's,
  1186. for example to place an Excel spreadsheet within a Frame document;
  1187. when Frame needs to format the page, it will start Excel itself, or at least some of its
  1188. DLLs, to format the spreadsheet.
  1189. OLE data can only be understood by the application that created it;
  1190. plumbing messages, by contrast, contain arbitrary data with a rigidly formatted header
  1191. that will be interpreted by the pattern matcher and the destination application.
  1192. The plumber's simplified message format may limit its
  1193. flexibility but makes messages easy and efficient to dispatch and to interpret.
  1194. At least for the cut-and-paste style of exchange OLE encourages,
  1195. plumbing gives up some power in return for simplicity, while avoiding
  1196. the need to invoke a vestigial program (if Excel can be called a vestige) every time
  1197. the pasted data is examined.
  1198. Plumbing is also better suited to
  1199. other styles of data exchange, such as connecting compiler errors to the
  1200. text editor.
  1201. .LP
  1202. The Hyperbole [Wein] package for Emacs adds hypertext facilities to existing documents.
  1203. It includes explicit links and, like plumbing, a rule-driven way to form implicit links.
  1204. Since Emacs is purely textual, like Acme, Hyperbole does not easily extend to driving
  1205. graphical applications, nor does it provide a general interprocess communication method.
  1206. For instance, although Hyperbole provides some integration for mail applications,
  1207. it cannot provide the glue that allows a click on a face icon in an external program to open a
  1208. mail message within the viewer.
  1209. Moreover, since it is not implemented as a file server,
  1210. Hyperbole does not share the advantages of that architecture.
  1211. .LP
  1212. Henry's
  1213. .CW error
  1214. program in 4BSD echoes a small but common use of plumbing.
  1215. It takes the error messages produced by a compiler and drives a text editor
  1216. through the steps of looking at each one in turn; the notion is to quicken the
  1217. compile/edit/debug cycle.
  1218. Similar results are achieved in EMACS by writing special M-LISP
  1219. macros to parse the error messages from various compilers.
  1220. Although for this particular purpose they may be more convenient than plumbing,
  1221. these are specific solutions to a specific problem and lack plumbing's generality.
  1222. .LP
  1223. Of course, the resource forks in MacOS and the association rules for
  1224. file name extensions in Windows also provide some of the functionality of
  1225. the plumber, although again without the generality or dynamic nature.
  1226. .LP
  1227. Closer to home, Ousterhout's Tcl (Tool Command Language) [Oust90]
  1228. was originally designed to embed a little command interpreter
  1229. in each application to control interprocess communication and
  1230. provide a level of integration.
  1231. Plumbing, on the other hand, provides minimal support within
  1232. the application, offloading most of the message handling and all the
  1233. command execution to the central plumber.
  1234. .LP
  1235. The most obvious relative to plumbing is perhaps the hypertext links of a web browser.
  1236. Plumbing differs by synthesizing
  1237. the links on demand.
  1238. Rather than constructing links within a document as in HTML,
  1239. plumbing uses the context of a button click to derive what it should link to.
  1240. That the rules for this decision can be modified dynamically gives it a more
  1241. fluid feel than a standard web browsing world.
  1242. One possibility for future work is to adapt a web browser to use
  1243. plumbing as its link-following engine, much as Acme used plumbing to offload
  1244. its acquisition rules.
  1245. This would connect the web browser to the existing tools, rather than the
  1246. current trend in most systems of replacing the tools by a browser.
  1247. .LP
  1248. Each of these prior systems\(emand there are others, e.g. [Pasa93, Free93]\(emaddresses
  1249. a particular need or subset of the
  1250. issues of system integration.
  1251. Plumbing differs because its particular choices were different.
  1252. It focuses on two key issues:
  1253. centralizing and automating the handling of interprocess communication
  1254. among interactive programs,
  1255. and maximizing the convenience (or minimizing the trouble) for the human user
  1256. of its services.
  1257. Moreover, the plumber's implementation as a file server, with messages
  1258. passed over files it controls,
  1259. permits the architecture to work transparently across a network.
  1260. None of the other systems discussed here integrates distributed systems
  1261. as smoothly as local ones without the addition of significant extra technology.
  1262. .SH
  1263. Discussion
  1264. .LP
  1265. There were a few surprises during the development of plumbing.
  1266. The first version of plumbing was done for the Inferno system [Dorw97a,Dorw97b],
  1267. using its file-to-channel mechanism to mediate the IPC.
  1268. Although it was very simple to build, it encountered difficulties because
  1269. the plumber was too disconnected from its clients; in particular, there was
  1270. no way to discover whether a port was in use.
  1271. When plumbing was implemented afresh for Plan 9, it was provided through a true file server.
  1272. Although this was much more work, it paid off handsomely.
  1273. The plumber now knows whether a port is open, which makes it easy to decide whether
  1274. a new program must be started to handle a message,
  1275. and the ability to edit the rules file dynamically is a major advantage.
  1276. Other advantages arise from the file-server design,
  1277. such as
  1278. the ease of exporting plumbing ports across the network to remote machines
  1279. and the implicit security model a file-based interface provides: no one has
  1280. permission to open my private plumbing files.
  1281. .LP
  1282. On the other hand, Inferno was an all-new environment and the user interface for plumbing was
  1283. able to be made uniform for all applications.
  1284. This was impractical for Plan 9, so more
  1285. .I "ad hoc
  1286. interfaces had to be provided for that environment.
  1287. Yet even in Plan 9 the advantages of efficient,
  1288. convenient, dynamic interprocess communication outweigh the variability of
  1289. the user interface.
  1290. In fact, it is perhaps a telling point that the system works well for a variety of interfaces;
  1291. the provision of a central, convenient message-passing
  1292. service is a good idea regardless of how the programs use it.
  1293. .LP
  1294. Plumbing's rule language uses only regular expressions and a few special
  1295. rules such as
  1296. .CW isfile
  1297. for matching text.
  1298. There is much more that could be done. For example, in the current system a JPEG
  1299. file can be recognized by a
  1300. .CW .jpg
  1301. suffix but not by its contents, since the plumbing language has no facility
  1302. for examining the
  1303. .I contents
  1304. of files named in its messages.
  1305. To address this issue without adding more special rules requires rethinking
  1306. the language itself.
  1307. Although the current system seems a good balance of complexity
  1308. and functionality,
  1309. perhaps a richer, more general-purpose language would
  1310. permit more exotic applications of the plumbing model.
  1311. .LP
  1312. In conclusion, plumbing adds an effective, easy-to-use inter-application
  1313. communication mechanism to the Plan 9
  1314. user interface.
  1315. Its unusual design as a language-driven file server makes it easy to add
  1316. context-dependent, dynamically interpreted, general-purpose hyperlinks
  1317. to the desktop, for both existing tools and new ones.
  1318. .SH
  1319. Acknowledgements
  1320. .LP
  1321. Dave Presotto wrote the mail file system and
  1322. .CW edmail .
  1323. He, Russ Cox, Sape Mullender, and Cliff Young influenced the design, offered useful suggestions,
  1324. and suffered early versions of the software.
  1325. They also made helpful comments on this paper, as did Dennis Ritchie and Brian Kernighan.
  1326. .SH
  1327. References
  1328. .LP
  1329. [Dorw97a]
  1330. Sean Dorward, Rob Pike, David Leo Presotto, Dennis M. Ritchie,
  1331. Howard W. Trickey, and Philip Winterbottom,
  1332. ``Inferno'',
  1333. .I "Proceedings of the IEEE Compcon 97 Conference" ,
  1334. San Jose, 1997, pp. 241-244.
  1335. .LP
  1336. [Dorw97b]
  1337. Sean Dorward, Rob Pike, David Leo Presotto, Dennis M. Ritchie,
  1338. Howard W. Trickey, and Philip Winterbottom,
  1339. ``The Inferno Operating System'',
  1340. .I "Bell Labs Technical Journal" ,
  1341. .B 2 ,
  1342. 1, Winter, 1997.
  1343. .LP
  1344. [Free93]
  1345. FreeBSD,
  1346. Syslog configuration file manual
  1347. .I syslog.conf (0).
  1348. .LP
  1349. [Kill84]
  1350. T. J. Killian,
  1351. ``Processes as Files'',
  1352. .I "Proceedings of the Summer 1984 USENIX Conference" ,
  1353. Salt Lake City, 1984, pp. 203-207.
  1354. .LP
  1355. [Oust90]
  1356. John K. Ousterhout,
  1357. ``Tcl: An Embeddable Command Languages'',
  1358. .I "Proceedings of the Winter 1990 USENIX Conference" ,
  1359. Washington, 1990, pp. 133-146.
  1360. .LP
  1361. [Pasa93]
  1362. Vern Paxson and Chris Saltmarsh,
  1363. "Glish: A User-Level Software Bus for Loosely-Coupled Distributed Systems" ,
  1364. .I "Proceedings of the Winter 1993 USENIX Conference" ,
  1365. San Diego, 1993, pp. 141-155.
  1366. .LP
  1367. [Pike87a]
  1368. Rob Pike,
  1369. ``Structural Regular Expressions'',
  1370. .I "EUUG Spring 1987 Conference Proceedings" ,
  1371. Helsinki, May 1987, pp. 21-28.
  1372. .LP
  1373. [Pike87b]
  1374. Rob Pike,
  1375. ``The Text Editor sam'',
  1376. .I "Software - Practice and Experience" ,
  1377. .B 17 ,
  1378. 5, Nov. 1987, pp. 813-845.
  1379. .LP
  1380. [Pike91]
  1381. Rob Pike,
  1382. ``8½, the Plan 9 Window System'',
  1383. .I "Proceedings of the Summer 1991 USENIX Conference" ,
  1384. Nashville, 1991, pp. 257-265.
  1385. .LP
  1386. [Pike93]
  1387. Rob Pike, Dave Presotto, Ken Thompson, Howard Trickey, and Phil Winterbottom,
  1388. ``The Use of Name Spaces in Plan 9'',
  1389. .I "Operating Systems Review" ,
  1390. .B 27 ,
  1391. 2, April 1993, pp. 72-76.
  1392. .LP
  1393. [Pike94]
  1394. Rob Pike,
  1395. ``Acme: A User Interface for Programmers'',
  1396. .I "Proceedings of the Winter 1994 USENIX Conference",
  1397. San Francisco, 1994, pp. 223-234.
  1398. .LP
  1399. [PiPr85]
  1400. Rob Pike and Dave Presotto,
  1401. ``Face the Nation'',
  1402. .I "Proceedings of the USENIX Summer 1985 Conference" ,
  1403. Portland, 1985, pg. 81.
  1404. .LP
  1405. [Reis95]
  1406. Steven P. Reiss,
  1407. .I "The FIELD Programming Environment: A Friendly Integrated Environment for Learning and Development" ,
  1408. Kluwer, Boston, 1995.
  1409. .LP
  1410. [Wein]
  1411. Bob Weiner,
  1412. .I "Hyperbole User Manual" ,
  1413. .CW http://www.cs.indiana.edu/elisp/hyperbole/hyperbole_1.html
  1414. .LP
  1415. [Wint94]
  1416. Philip Winterbottom,
  1417. ``ACID: A Debugger based on a Language'',
  1418. .I "Proceedings of the USENIX Winter Conference" ,
  1419. San Francisco, CA, 1994.
  1420. .LP
  1421. [WiGu92]
  1422. Niklaus Wirth and Jurg Gutknecht,
  1423. .I "Project Oberon: The Design of an Operating System and Compilers" ,
  1424. Addison-Wesley, Reading, 1992.