2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 //%% (c) Copyright 1993, 1994 Hewlett-Packard Company
24 //%% (c) Copyright 1993, 1994 International Business Machines Corp.
25 //%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
26 //%% (c) Copyright 1993, 1994 Novell, Inc.
27 //%% $XConsortium: tttkpattern.C /main/3 1995/10/23 10:33:41 rswiston $
29 * @(#)tttkpattern.C 1.3 93/09/07
31 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
33 #include "api/c/tt_c.h"
34 #include "tttk/tttk.h"
35 #include "tttk/tttkmessage.h"
36 #include "tttk/tttk2free.h"
37 #include "tttk/tttkutils.h"
40 _tttk_patterns_destroy(
47 Tt_status worst = tt_ptr_error( pats );
51 Tt_pattern *pats2free = pats;
53 if (tt_ptr_error( *pats ) == TT_OK) {
54 Tt_status status = tt_pattern_destroy( *pats );
55 if (status != TT_OK) {
62 free( (caddr_t)pats2free );
68 // This is the only pattern callback that we use. It retrieves and
69 // calls the op-specific internal unmarshalling routine, which in turn
70 // will call the user's op-specific callback.
72 static Tt_callback_action
78 // XXX optimization: use 1 key, store a struct w/ all 3 datums
79 _TtDtMessageCB cb = (_TtDtMessageCB)
80 tt_pattern_user( pat, _TttkCBKey );
81 Tt_status status = tt_ptr_error( cb );
82 if (status != TT_OK) {
83 return TT_CALLBACK_PROCESSED;
86 return TT_CALLBACK_CONTINUE;
88 void *clientCB = tt_pattern_user( pat, _TttkClientCBKey );
89 status = tt_ptr_error( clientCB );
90 if (status != TT_OK) {
91 return TT_CALLBACK_PROCESSED;
93 // clientCB is allowed to be 0. cf. TTDT_QUIT in ttdt_session_join
94 void *clientData = tt_pattern_user( pat, _TttkClientDataKey );
95 status = tt_ptr_error( clientData );
96 if (status != TT_OK) {
97 return TT_CALLBACK_PROCESSED;
99 msg = (*cb)( msg, pat, clientCB, clientData );
100 return _ttDtCallbackAction( msg );
105 Tt_category category,
116 Tt_pattern pat = tt_pattern_create();
117 Tt_status status = tt_ptr_error( pat );
118 if (status != TT_OK) {
121 _TttkItem2Free fuse( pat );
122 status = tt_pattern_category_set( pat, category );
123 if (status != TT_OK) {
124 return (Tt_pattern)tt_error_pointer( status );
126 // we only observe notices and only handle requests
127 if (category == TT_HANDLE) {
128 status = tt_pattern_class_add( pat, TT_REQUEST );
130 if (category == TT_OBSERVE) {
131 status = tt_pattern_class_add( pat, TT_NOTICE );
133 if (status != TT_OK) {
134 return (Tt_pattern)tt_error_pointer( status );
136 status = tt_pattern_scope_add( pat, theScope );
137 if (status != TT_OK) {
138 return (Tt_pattern)tt_error_pointer( status );
140 if (addDefaultSess) {
141 char *sess = tt_default_session();
142 status = tt_pattern_session_add( pat, sess );
144 if (status != TT_OK) {
145 return (Tt_pattern)tt_error_pointer( status );
149 status = tt_pattern_file_add( pat, file );
150 if (status != TT_OK) {
151 return (Tt_pattern)tt_error_pointer( status );
155 status = tt_pattern_op_add( pat, _ttDtOp( op ) );
156 if (status != TT_OK) {
157 return (Tt_pattern)tt_error_pointer( status );
160 status = tt_pattern_callback_add( pat, _ttDtPatternCB );
161 if (status != TT_OK) {
162 return (Tt_pattern)tt_error_pointer( status );
164 status = tt_pattern_user_set( pat, _TttkCBKey, (void *)cb );
165 if (status != TT_OK) {
166 return (Tt_pattern)tt_error_pointer( status );
168 status = tt_pattern_user_set( pat, _TttkClientCBKey, clientCB );
169 if (status != TT_OK) {
170 return (Tt_pattern)tt_error_pointer( status );
172 status = tt_pattern_user_set( pat, _TttkClientDataKey, clientData );
173 if (status != TT_OK) {
174 return (Tt_pattern)tt_error_pointer( status );
177 status = tt_pattern_register( pat );
178 if (status != TT_OK) {
179 return (Tt_pattern)tt_error_pointer( status );
187 _tttk_pattern_contract(
191 void *p = tt_pattern_user( pat, _TttkContractKey );
192 Tt_status status = tt_ptr_error( p );
193 if (status != TT_OK) {
196 return (Tt_message)p;