pty_decl.sgm 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <!-- $XConsortium: pty_decl.sgm /main/6 1996/09/08 20:23:05 rws $ -->
  2. <!-- (c) Copyright 1995 Digital Equipment Corporation. -->
  3. <!-- (c) Copyright 1995 Hewlett-Packard Company. -->
  4. <!-- (c) Copyright 1995 International Business Machines Corp. -->
  5. <!-- (c) Copyright 1995 Sun Microsystems, Inc. -->
  6. <!-- (c) Copyright 1995 Novell, Inc. -->
  7. <!-- (c) Copyright 1995 FUJITSU LIMITED. -->
  8. <!-- (c) Copyright 1995 Hitachi. -->
  9. <![ %CDE.C.CDE; [<RefEntry Id="CDEMX.XCDI.MAN272.rsml.1">]]>
  10. <![ %CDE.C.XO; [<RefEntry Id="XCDI.MAN272.rsml.1">]]>
  11. <RefMeta>
  12. <RefEntryTitle>ttmedia_ptype_declare</RefEntryTitle>
  13. <ManVolNum>library call</ManVolNum>
  14. </RefMeta>
  15. <RefNameDiv>
  16. <RefName><Function>ttmedia_ptype_declare</Function></RefName>
  17. <RefPurpose>declare the ptype of a Media Exchange media editor
  18. </RefPurpose>
  19. </RefNameDiv>
  20. <!-- $XConsortium: pty_decl.sgm /main/6 1996/09/08 20:23:05 rws $-->
  21. <!-- CDE Common Source Format, Version 1.0.0-->
  22. <!-- (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company-->
  23. <!-- (c) Copyright 1993, 1994, 1995 International Business Machines Corp.-->
  24. <!-- (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.-->
  25. <!-- (c) Copyright 1993, 1994, 1995 Novell, Inc.-->
  26. <RefSynopsisDiv>
  27. <FuncSynopsis Remap="ANSI">
  28. <FuncSynopsisInfo>#include &lt;Tt/tttk.h>
  29. </FuncSynopsisInfo>
  30. <FuncDef>Tt_status <Function>ttmedia_ptype_declare</Function></FuncDef>
  31. <ParamDef>const char *<Parameter>ptype</Parameter></ParamDef>
  32. <ParamDef>int <Parameter>base_opnum</Parameter></ParamDef>
  33. <ParamDef>Ttmedia_load_pat_cb <Parameter>cb</Parameter></ParamDef>
  34. <ParamDef>void *<Parameter>clientdata</Parameter></ParamDef>
  35. <ParamDef>int <Parameter>declare</Parameter></ParamDef>
  36. </FuncSynopsis>
  37. </RefSynopsisDiv>
  38. <RefSect1>
  39. <Title>DESCRIPTION</Title>
  40. <Para>The
  41. <Function>ttmedia_ptype_declare</Function> function
  42. is used to initialize an editor that implements the Media Exchange
  43. message interface for a particular media type.
  44. The
  45. <Function>ttmedia_ptype_declare</Function> function
  46. notifies
  47. the ToolTalk service
  48. that the
  49. <Emphasis>cb</Emphasis> callback is to be called when the editor is asked to edit a document
  50. of the kind supported by
  51. ptype.
  52. The
  53. <Function>ttmedia_ptype_declare</Function> function
  54. installs an implementation-specific
  55. <Emphasis>opnum</Emphasis> callback on a series of signatures that
  56. ptype
  57. is assumed to contain.
  58. These signatures are listed below, with
  59. their corresponding opnum offsets.
  60. Opnums in
  61. ptype
  62. for these signatures start at
  63. <Emphasis>base_opnum</Emphasis>, which must be zero or a multiple of 1000.
  64. The implementation-specific
  65. opnum callback will pass
  66. <Emphasis>clientdata</Emphasis> to
  67. <Emphasis>cb</Emphasis> when a request is received that matches one of these signatures.
  68. </Para>
  69. <Para>If
  70. <Emphasis>declare</Emphasis> is True,
  71. <Function>ttmedia_ptype_declare</Function> calls
  72. <Function>tt_ptype_declare</Function> with the
  73. ptype
  74. argument.
  75. If
  76. ptype
  77. implements Media Exchange for several different media types,
  78. then
  79. <Function>ttmedia_ptype_declare</Function> can be called multiple times, with a different
  80. <Emphasis>base_opnum</Emphasis> each time, and with
  81. <Emphasis>declare</Emphasis> being True only once.
  82. </Para>
  83. <Para>The
  84. <StructName Role="typedef">Ttmedia_load_pat_cb</StructName> argument is a callback defined as:
  85. </Para>
  86. <InformalExample Remap="indent">
  87. <ProgramListing>Tt_message (*Ttmedia_load_pat_cb)(Tt_message <Emphasis>msg</Emphasis>,
  88. void *<Emphasis>clientdata</Emphasis>,
  89. Tttk_op <Symbol Role="Variable">op</Symbol>,
  90. Tt_status <Emphasis>diagnosis</Emphasis>,
  91. unsigned char *<Emphasis>contents</Emphasis>,
  92. int <Emphasis>len</Emphasis>,
  93. char *<Symbol Role="Variable">file</Symbol>,
  94. char *<Emphasis>docname</Emphasis>);
  95. </ProgramListing>
  96. </InformalExample>
  97. <Para>The
  98. <Emphasis>msg</Emphasis> argument is a
  99. <SystemItem Class="Constant">TT_REQUEST</SystemItem> in
  100. <StructName Role="typedef">Tt_state</StructName> <SystemItem Class="Constant">TT_SENT</SystemItem>. The client
  101. program becomes responsible for either failing, rejecting or replying
  102. to it.
  103. This can either be done inside the callback, or the message
  104. can be saved and dismissed later (that is, after the callback returns).
  105. Usually, the callback will either immediately reject/fail the request,
  106. or it will start processing the request, perhaps by associating it
  107. with a new window.
  108. When the request is finally dismissed, it should
  109. be destroyed, for example, using
  110. <Function>tt_message_destroy</Function>.</Para>
  111. <Para>If the callback knows it will handle the request (either fail or reply
  112. to it, but not reject it), then it should call
  113. &cdeman.ttdt.message.accept;. But if the return value of
  114. &cdeman.tt.message.status; of
  115. <Emphasis>msg</Emphasis> is
  116. <SystemItem Class="Constant">TT_WRN_START_MESSAGE</SystemItem>, then the callback should probably do
  117. <Function>ttdt_session_join</Function>, and perhaps a
  118. <Function>ttdt_file_join</Function>, before accepting the message.
  119. The
  120. <Symbol Role="Variable">op</Symbol> argument is the
  121. op of the incoming request,
  122. one of
  123. <SystemItem Class="Constant">TTME_COMPOSE</SystemItem>, <SystemItem Class="Constant">TTME_EDIT</SystemItem> or
  124. <SystemItem Class="Constant">TTME_DISPLAY</SystemItem>. The
  125. <Emphasis>diagnosis</Emphasis> argument is the
  126. recommended error code;
  127. if the ToolTalk service
  128. detects a problem with the request (for example,
  129. <SystemItem Class="Constant">TT_DESKTOP_ENODATA</SystemItem>), then it passes in the error code
  130. that it recommends the request should be failed with.
  131. If
  132. <Emphasis>diagnosis</Emphasis> was not
  133. <SystemItem Class="Constant">TT_OK</SystemItem> and the
  134. <StructName Role="typedef">Ttmedia_load_pat_cb</StructName> returns
  135. <Emphasis>msg</Emphasis>, then the ToolTalk service
  136. will fail and destroy
  137. <Emphasis>msg</Emphasis>.</Para>
  138. <Para>The ToolTalk service
  139. does not simply fail the request transparently, because
  140. the request may be the reason that the client process was started
  141. by ToolTalk in the first place.
  142. So if
  143. <Emphasis>diagnosis</Emphasis> is not
  144. <SystemItem Class="Constant">TT_OK</SystemItem> and the
  145. <Function>tt_message_status</Function> of
  146. <Emphasis>msg</Emphasis> is
  147. <SystemItem Class="Constant">TT_WRN_START_MESSAGE</SystemItem>, then many applications will
  148. decide that they have no reason to continue running.
  149. If such an application chooses to exit in the callback, then
  150. it should first dismiss the request.
  151. Otherwise, it can set
  152. some global flag, return
  153. <Emphasis>msg</Emphasis> (thus allowing the ToolTalk service
  154. to dismiss the message), and then
  155. have
  156. <Function>main</Function> check the flag and exit before even entering the
  157. event loop.
  158. (Exiting without dismissing the request would fail
  159. it with status
  160. <SystemItem Class="Constant">TT_ERR_PROCID</SystemItem>, instead of with
  161. <Emphasis>diagnostic</Emphasis>.)</Para>
  162. <Para>The
  163. <Emphasis>contents</Emphasis>, <Emphasis>len</Emphasis>, and
  164. <Symbol Role="Variable">file</Symbol> arguments represent the
  165. contents of the arriving document.
  166. If
  167. <Emphasis>len</Emphasis> is zero, then the document is contained in
  168. <Symbol Role="Variable">file</Symbol>. If
  169. <Emphasis>contents</Emphasis> or
  170. <Symbol Role="Variable">file</Symbol> are non-
  171. <SystemItem Class="Constant">NULL</SystemItem>, they can be freed using
  172. <Function>tt_free</Function>.</Para>
  173. <Para>The
  174. <Emphasis>docname</Emphasis> argument is the
  175. name of the document, if any.
  176. The
  177. <Emphasis>clientdata</Emphasis> argument is the
  178. <Emphasis>clientdata</Emphasis> passed to
  179. <Function>ttmedia_ptype_declare</Function>.</Para>
  180. <Para>A
  181. <StructName Role="typedef">Ttmedia_load_pat_cb</StructName> should return zero if it processes
  182. <Emphasis>msg</Emphasis> successfully, or a
  183. <Function>tt_error_pointer</Function> cast to
  184. <StructName Role="typedef">Tt_message</StructName> if processing results in an error.
  185. It should return the
  186. <Emphasis>msg</Emphasis> if it does not consume it.
  187. If
  188. <Emphasis>diagnosis</Emphasis> is not
  189. <SystemItem Class="Constant">TT_OK</SystemItem> and
  190. <Emphasis>msg</Emphasis> is returned, then the ToolTalk service
  191. will consume (namely, fail and destroy) it.
  192. If
  193. <Emphasis>diagnosis</Emphasis> is
  194. <SystemItem Class="Constant">TT_OK</SystemItem> and
  195. <Emphasis>msg</Emphasis> is returned, then the ToolTalk service will pass
  196. <SystemItem Class="Constant">TT_CALLBACK_CONTINUE</SystemItem> down the call stack, so that
  197. <Emphasis>msg</Emphasis> will be offered to other callbacks or (more likely) be returned from
  198. &cdeman.tt.message.receive;. Applications will rarely want
  199. <Emphasis>msg</Emphasis> to get processed by other callbacks or in the main event loop.
  200. </Para>
  201. </RefSect1>
  202. <RefSect1>
  203. <Title>RETURN VALUE</Title>
  204. <Para>Upon successful completion, the
  205. <Function>ttmedia_ptype_declare</Function> function returns the status of the operation.
  206. The application can use
  207. &cdeman.tt.ptr.error; to extract one of the following
  208. <StructName Role="typedef">Tt_status</StructName> values from the returned handle:
  209. </Para>
  210. <VariableList>
  211. <VarListEntry>
  212. <Term>TT_OK</Term>
  213. <ListItem>
  214. <Para>The operation completed successfully.
  215. </Para>
  216. </ListItem>
  217. </VarListEntry>
  218. <VarListEntry>
  219. <Term>TT_ERR_NOMP</Term>
  220. <ListItem>
  221. <Para>The
  222. &cdeman.ttsession; process is not running and the ToolTalk service cannot restart it.
  223. </Para>
  224. </ListItem>
  225. </VarListEntry>
  226. <VarListEntry>
  227. <Term>TT_ERR_POINTER</Term>
  228. <ListItem>
  229. <Para>The pointer passed does not point to an object
  230. of the correct type for this operation.
  231. </Para>
  232. </ListItem>
  233. </VarListEntry>
  234. <VarListEntry>
  235. <Term>TT_ERR_PROCID</Term>
  236. <ListItem>
  237. <Para>The specified process identifier is out of date or invalid.
  238. </Para>
  239. </ListItem>
  240. </VarListEntry>
  241. <VarListEntry>
  242. <Term>TT_ERR_PTYPE</Term>
  243. <ListItem>
  244. <Para>The specified process type is not the name of an installed process type.
  245. </Para>
  246. </ListItem>
  247. </VarListEntry>
  248. </VariableList>
  249. </RefSect1>
  250. <RefSect1>
  251. <Title>EXAMPLES</Title>
  252. <Para>This is the typical algorithm of a
  253. <StructName Role="typedef">Ttmedia_load_pat_cb</StructName>:</Para>
  254. <InformalExample>
  255. <ProgramListing>Tt_message
  256. myAcmeSheetLoadCB(
  257. Tt_message msg,
  258. void *client_data,
  259. Tttk_op op,
  260. Tt_status diagnosis,
  261. unsigned char *contents,
  262. int len,
  263. char *file,
  264. char *docname
  265. )
  266. {
  267. Tt_status status = TT_OK;
  268. if (diagnosis != TT_OK) {
  269. /* toolkit detected an error */
  270. if (tt_message_status(msg) == TT_WRN_START_MESSAGE) {
  271. /*
  272. * Error is in start message! We now have no
  273. * reason to live, so tell main() to exit().
  274. */
  275. myAbortCode = 2;
  276. }
  277. /* let toolkit handle the error */
  278. return msg;
  279. }
  280. if ((op == TTME_COMPOSE)&amp;&amp;(file == 0)) {
  281. /* open empty new buffer */
  282. } else if (len > 0) {
  283. /* load contents into new buffer */
  284. } else if (file != 0) {
  285. if (ttdt_Get_Modified(msg, file, TT_BOTH, myCntxt, 5000)) {
  286. switch(myUserChoice("Save, Revert, Ignore?")) {
  287. case 0:
  288. ttdt_Save(msg, file, TT_BOTH, myCntxt, 5000);
  289. break;
  290. case 1:
  291. ttdt_Revert(msg, file, TT_BOTH, myCntxt, 5000);
  292. break;
  293. }
  294. }
  295. /* load file into new buffer */
  296. } else {
  297. tttk_message_fail(msg, TT_DESKTOP_ENODATA, 0, 1);
  298. tt_free(contents); tt_free(file); tt_free(docname);
  299. return 0;
  300. }
  301. int w, h, x, y = INT_MAX;
  302. ttdt_sender_imprint_on(0, msg, 0, &amp;w, &amp;h, &amp;x, &amp;y, myCntxt, 5000);
  303. positionMyWindowRelativeTo(w, h, x, y);
  304. if (maxBuffersAreNowOpen) {
  305. /* Un-volunteer to handle future requests until less busy */
  306. tt_ptype_undeclare("Acme_Calc");
  307. }
  308. if (tt_message_status(msg) == TT_WRN_START_MESSAGE) {
  309. /*
  310. * Join session before accepting start message,
  311. * to prevent unnecessary starts of our ptype
  312. */
  313. ttdt_session_join(0, myContractCB, myShell, 0, 1);
  314. }
  315. ttdt_message_accept(msg, myContractCB, myShell, 0, 1, 1);
  316. tt_free(contents); tt_free(file); tt_free(docname);
  317. return 0;
  318. }
  319. </ProgramListing>
  320. </InformalExample>
  321. <Para>This is the signature layout to which
  322. ptype should conform:
  323. </Para>
  324. <InformalExample>
  325. <ProgramListing>ptype Acme_Calc {
  326. start "acalc";
  327. handle:
  328. <![ %CDE.C.CDE; [ /*
  329. * Instantiate Acme_Sheet
  330. * Include in tool's ptype if tool can be a document factory.
  331. */
  332. session Instantiate(in Acme_Sheet template) => start opnum = 401;
  333. ]]> /*
  334. * Display Acme_Sheet
  335. * Include in tool's ptype if tool can display a document.
  336. */
  337. session Display( in Acme_Sheet contents) => start opnum = 1;
  338. session Display( in Acme_Sheet contents,
  339. in messageID counterfoil) => start opnum = 2;
  340. session Display( in Acme_Sheet contents,
  341. in title docName) => start opnum = 3;
  342. session Display( in Acme_Sheet contents,
  343. in messageID counterfoil,
  344. in title docName) => start opnum = 4;
  345. /*
  346. * Edit Acme_Sheet
  347. * Include in tool's ptype if tool can edit a document.
  348. */
  349. session Edit( inout Acme_Sheet contents) => start opnum = 101;
  350. session Edit( inout Acme_Sheet contents,
  351. in messageID counterfoil) => start opnum = 102;
  352. session Edit( inout Acme_Sheet contents,
  353. in title docName) => start opnum = 103;
  354. session Edit( inout Acme_Sheet contents,
  355. in messageID counterfoil,
  356. in title docName) => start opnum = 104;
  357. /*
  358. * Compose Acme_Sheet
  359. * Include in tool's ptype if tool can compose a document from scratch.
  360. */
  361. session Edit( out Acme_Sheet contents) => start opnum = 201;
  362. session Edit( out Acme_Sheet contents,
  363. in messageID counterfoil) => start opnum = 202;
  364. session Edit( out Acme_Sheet contents,
  365. in title docName) => start opnum = 203;
  366. session Edit( out Acme_Sheet contents,
  367. in messageID counterfoil,
  368. in title docName) => start opnum = 204;
  369. /*
  370. * Mail Acme_Sheet
  371. * Include in tool's ptype if tool can mail a document.
  372. */
  373. session Mail( in Acme_Sheet contents) => start opnum = 301;
  374. session Mail( inout Acme_Sheet contents) => start opnum = 311;
  375. session Mail( inout Acme_Sheet contents,
  376. in title docName) => start opnum = 313;
  377. session Mail( out Acme_Sheet contents) => start opnum = 321;
  378. session Mail( out Acme_Sheet contents,
  379. in messageID counterfoil) => start opnum = 323;
  380. };
  381. </ProgramListing>
  382. </InformalExample>
  383. </RefSect1>
  384. <RefSect1>
  385. <Title>SEE ALSO</Title>
  386. <Para>&cdeman.Tt.tttk.h;, &cdeman.tt.ptype.declare;, &cdeman.tt.ptype.undeclare;, &cdeman.ttdt.message.accept;, &cdeman.ttdt.session.join;, &cdeman.ttdt.file.join;, &cdeman.tt.free;, &cdeman.tt.message.receive;.</Para>
  387. </RefSect1>
  388. </RefEntry>
  389. <!--fickle 1.12 mancsf-to-docbook 1.2 08/07/95 23:18:47-->