|
NAMEttmedia_ptype_declare — declare the ptype of a Media Exchange media editor SYNOPSIS#include &<Tt/tttk.h> Tt_status ttmedia_ptype_declare( const char *ptype, int base_opnum, Ttmedia_load_pat_cb cb, void *clientdata, int declare); DESCRIPTIONThe ttmedia_ptype_declare function is used to initialize an editor that implements the Media Exchange message interface for a particular media type. The ttmedia_ptype_declare function notifies the ToolTalk service that the cb callback is to be called when the editor is asked to edit a document of the kind supported by ptype. The ttmedia_ptype_declare function installs an implementation-specific opnum callback on a series of signatures that ptype is assumed to contain. These signatures are listed below, with their corresponding opnum offsets. Opnums in ptype for these signatures start at base_opnum, which must be zero or a multiple of 1000. The implementation-specific opnum callback will pass clientdata to cb when a request is received that matches one of these signatures. If declare is True, ttmedia_ptype_declare calls tt_ptype_declare with the ptype argument. If ptype implements Media Exchange for several different media types, then ttmedia_ptype_declare can be called multiple times, with a different base_opnum each time, and with declare being True only once. The Ttmedia_load_pat_cb argument is a callback defined as: Tt_message (*Ttmedia_load_pat_cb)(Tt_message msg, The msg argument is a TT_REQUEST in Tt_state TT_SENT. The client program becomes responsible for either failing, rejecting or replying to it. This can either be done inside the callback, or the message can be saved and dismissed later (that is, after the callback returns). Usually, the callback will either immediately reject/fail the request, or it will start processing the request, perhaps by associating it with a new window. When the request is finally dismissed, it should be destroyed, for example, using tt_message_destroy. If the callback knows it will handle the request (either fail or reply to it, but not reject it), then it should call ttdt_message_accept(3). But if the return value of tt_message_status(3) of msg is TT_WRN_START_MESSAGE, then the callback should probably do ttdt_session_join, and perhaps a ttdt_file_join, before accepting the message. The op argument is the op of the incoming request, one of TTME_COMPOSE, TTME_EDIT or TTME_DISPLAY. The diagnosis argument is the recommended error code; if the ToolTalk service detects a problem with the request (for example, TT_DESKTOP_ENODATA), then it passes in the error code that it recommends the request should be failed with. If diagnosis was not TT_OK and the Ttmedia_load_pat_cb returns msg, then the ToolTalk service will fail and destroy msg. The ToolTalk service does not simply fail the request transparently, because the request may be the reason that the client process was started by ToolTalk in the first place. So if diagnosis is not TT_OK and the tt_message_status of msg is TT_WRN_START_MESSAGE, then many applications will decide that they have no reason to continue running. If such an application chooses to exit in the callback, then it should first dismiss the request. Otherwise, it can set some global flag, return msg (thus allowing the ToolTalk service to dismiss the message), and then have main check the flag and exit before even entering the event loop. (Exiting without dismissing the request would fail it with status TT_ERR_PROCID, instead of with diagnostic.) The contents, len, and file arguments represent the contents of the arriving document. If len is zero, then the document is contained in file. If contents or file are non- NULL, they can be freed using tt_free. The docname argument is the name of the document, if any. The clientdata argument is the clientdata passed to ttmedia_ptype_declare. A Ttmedia_load_pat_cb should return zero if it processes msg successfully, or a tt_error_pointer cast to Tt_message if processing results in an error. It should return the msg if it does not consume it. If diagnosis is not TT_OK and msg is returned, then the ToolTalk service will consume (namely, fail and destroy) it. If diagnosis is TT_OK and msg is returned, then the ToolTalk service will pass TT_CALLBACK_CONTINUE down the call stack, so that msg will be offered to other callbacks or (more likely) be returned from tt_message_receive(3). Applications will rarely want msg to get processed by other callbacks or in the main event loop. RETURN VALUEUpon successful completion, the ttmedia_ptype_declare function returns the status of the operation. The application can use tt_ptr_error(3) to extract one of the following Tt_status values from the returned handle:
EXAMPLESThis is the typical algorithm of a Ttmedia_load_pat_cb: Tt_message myAcmeSheetLoadCB( This is the signature layout to which ptype should conform: ptype Acme_Calc { SEE ALSOTt/tttk.h - Tttttk(5), tt_ptype_declare(3), tt_ptype_undeclare(3), ttdt_message_accept(3), ttdt_session_join(3), ttdt_file_join(3), tt_free(3), tt_message_receive(3).
|