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 //%% $TOG: api_pattern.C /main/5 1999/09/17 18:26:08 mgreess $
30 * @(#)api_pattern.C 1.29 07 Sep 1993
32 * Tool Talk API - api_pattern.cc
34 * Copyright (c) 1990,1992 by Sun Microsystems, Inc.
37 #include "util/tt_path.h"
39 #include "mp/mp_pat_context.h"
40 #include "mp/mp_c_msg_context.h"
41 #include "api/c/tt_c.h"
42 #include "api/c/api_api.h"
43 #include "api/c/api_mp.h"
44 #include "api/c/api_handle.h"
45 #include "util/tt_audit.h"
50 char * _tt_pattern_print(Tt_pattern);
51 Tt_status _tt_pattern_xarg_add(Tt_pattern, Tt_mode, const char *,
53 Tt_status _tt_pattern_context_add(Tt_pattern, const char *, const char *);
54 Tt_status _tt_pattern_icontext_add(Tt_pattern, const char *, int );
55 Tt_status _tt_pattern_xcontext_add(Tt_pattern p, const char *slotname,
56 xdrproc_t xdr_proc, void *value);
57 Tt_status _tt_pattern_opnum_add(Tt_pattern, int);
58 Tt_status _tt_pattern_bcontext_add(Tt_pattern, const char *,
59 const unsigned char *, int);
60 Tt_status _tt_session_types_load(const char *);
61 Tt_status _tt_context_join(const char *, const char *);
62 Tt_status _tt_icontext_join(const char *, int);
63 Tt_status _tt_bcontext_join(const char *, const unsigned char *, int);
64 Tt_status _tt_context_quit(const char *, const char *);
65 Tt_status _tt_icontext_quit(const char *, int);
66 Tt_status _tt_bcontext_quit(const char *, const unsigned char *, int);
67 Tt_status _tt_xcontext_join(const char *, xdrproc_t, void *);
68 Tt_status _tt_xcontext_quit(const char *, xdrproc_t, void *);
72 tt_pattern_print(Tt_pattern p)
75 Tt_status status = audit.entry("P", TT_PATTERN_PRINT, p);
78 if (status != TT_OK) {
79 audit.exit((char *)error_pointer(status));
80 return (char *)error_pointer(status);
83 result = _tt_pattern_print(p);
91 * extern "C" { int _tt_x_pattern_match(Tt_pattern p, Tt_message m); }
95 tt_pattern_create(void)
98 Tt_status status = audit.entry("v", TT_PATTERN_CREATE, 0);
101 if (status != TT_OK) {
102 audit.exit((Tt_pattern)error_pointer(status));
103 return (Tt_pattern)error_pointer(status);
106 result = _tt_pattern_create();
114 tt_pattern_destroy(Tt_pattern p)
117 Tt_status status = audit.entry("P", TT_PATTERN_DESTROY, p);
119 if (status != TT_OK) {
124 status = _tt_pattern_destroy(p);
132 tt_pattern_register(Tt_pattern p)
135 Tt_status status = audit.entry("P", TT_PATTERN_REGISTER, p);
137 if (status != TT_OK) {
142 status = _tt_pattern_register(p);
150 tt_pattern_unregister(Tt_pattern p)
153 Tt_status status = audit.entry("P", TT_PATTERN_UNREGISTER, p);
155 if (status != TT_OK) {
160 status = _tt_pattern_unregister(p);
168 tt_pattern_callback_add(Tt_pattern p, Tt_message_callback f)
171 Tt_status status = audit.entry("PX", TT_PATTERN_CALLBACK_ADD, p, f);
173 if (status != TT_OK) {
178 status = _tt_pattern_callback_add(p, f);
186 tt_pattern_user(Tt_pattern p, int key)
189 Tt_status status = audit.entry("Pi", TT_PATTERN_USER, p, key);
192 if (status != TT_OK) {
193 audit.exit((void *)error_pointer(status));
194 return (void *)error_pointer(status);
197 result = _tt_pattern_user(p, key);
205 tt_pattern_user_set(Tt_pattern p, int key, void *v)
208 Tt_status status = audit.entry("PiA", TT_PATTERN_USER_SET, p, key, v);
210 if (status != TT_OK) {
215 status = _tt_pattern_user_set(p,key, v);
224 tt_pattern_category(Tt_pattern p)
227 Tt_status status = audit.entry("P", TT_PATTERN_CATEGORY, p);
230 if (status != TT_OK) {
231 audit.exit((Tt_category)error_int(status));
232 return (Tt_category)error_int(status);
235 result = _tt_pattern_category(p);
243 tt_pattern_category_set(Tt_pattern p, Tt_category c)
246 Tt_status status = audit.entry("Pa", TT_PATTERN_CATEGORY_SET, p, c);
248 if (status != TT_OK) {
253 status = _tt_pattern_category_set(p, c);
261 tt_pattern_arg_add(Tt_pattern p, Tt_mode n,
262 const char *vtype, const char *value)
265 Tt_status status = audit.entry("POTA", TT_PATTERN_ARG_ADD, p, n,
268 if (status != TT_OK) {
273 status = _tt_pattern_arg_add(p, n, vtype, value);
281 tt_pattern_barg_add(Tt_pattern p, Tt_mode n, const char *vtype,
282 const unsigned char *value, int len)
285 Tt_status status = audit.entry("POTnI", TT_PATTERN_BARG_ADD, p, n,
288 if (status != TT_OK) {
293 status = _tt_pattern_barg_add(p, n, vtype, value, len);
301 tt_pattern_iarg_add(Tt_pattern p, Tt_mode n, const char *vtype, int value)
304 Tt_status status = audit.entry("POTi", TT_PATTERN_IARG_ADD, p, n,
307 if (status != TT_OK) {
312 status = _tt_pattern_iarg_add(p, n, vtype, value);
321 tt_pattern_xarg_add(Tt_pattern p, Tt_mode n, const char *vtype,
322 xdrproc_t xdr_proc, void *value)
325 Tt_status status = audit.entry("POTXA", TT_PATTERN_XARG_ADD, p,
326 n, vtype, xdr_proc, value);
328 if (status != TT_OK) {
333 status = _tt_pattern_xarg_add(p, n, vtype, xdr_proc, value);
341 tt_pattern_context_add(Tt_pattern p, const char *slotname, const char *value)
344 Tt_status status = audit.entry("PSC", TT_PATTERN_CONTEXT_ADD, p,
347 if (status != TT_OK) {
352 status = _tt_pattern_context_add(p, slotname, value);
360 tt_pattern_icontext_add(Tt_pattern p, const char *slotname, int value)
363 Tt_status status = audit.entry("PSi", TT_PATTERN_ICONTEXT_ADD, p,
366 if (status != TT_OK) {
371 status = _tt_pattern_icontext_add(p, slotname, value);
379 tt_pattern_xcontext_add(Tt_pattern p, const char *slotname,
380 xdrproc_t xdr_proc, void *value)
383 Tt_status status = audit.entry("PSXA", TT_PATTERN_XCONTEXT_ADD, p,
384 slotname, xdr_proc, value);
386 if (status != TT_OK) {
391 status = _tt_pattern_xcontext_add(p, slotname, xdr_proc, value);
399 tt_pattern_bcontext_add(Tt_pattern p, const char *slotname,
400 const unsigned char *value, int len)
403 Tt_status status = audit.entry("PlnI", TT_PATTERN_BCONTEXT_ADD, p,
404 slotname, (void *) value, len);
406 if (status != TT_OK) {
411 status = _tt_pattern_bcontext_add(p, slotname, value, len);
419 tt_pattern_class_add(Tt_pattern p, Tt_class c)
422 Tt_status status = audit.entry("PL", TT_PATTERN_CLASS_ADD, p, c);
424 if (status != TT_OK) {
429 status = _tt_pattern_class_add(p, c);
437 tt_pattern_file_add(Tt_pattern p, const char *filepath)
440 Tt_status status = audit.entry("PC", TT_PATTERN_FILE_ADD, p, filepath);
442 if (status != TT_OK) {
447 status = _tt_pattern_file_add(p, filepath);
455 tt_pattern_object_add(Tt_pattern p, const char * objid)
458 Tt_status status = audit.entry("Po", TT_PATTERN_OBJECT_ADD, p,
461 if (status != TT_OK) {
466 status = _tt_pattern_object_add(p, objid);
474 tt_pattern_op_add(Tt_pattern p, const char *opname)
477 Tt_status status = audit.entry("PC", TT_PATTERN_OP_ADD, p,
480 if (status != TT_OK) {
485 status = _tt_pattern_op_add(p, opname);
493 tt_pattern_opnum_add(Tt_pattern p, int opnum)
496 Tt_status status = audit.entry("Pi", TT_PATTERN_OPNUM_ADD, p, opnum);
498 if (status != TT_OK) {
503 status = _tt_pattern_opnum_add(p, opnum);
511 tt_pattern_otype_add(Tt_pattern p, const char * otype)
514 Tt_status status = audit.entry("PC", TT_PATTERN_OTYPE_ADD, p, otype);
516 if (status != TT_OK) {
521 status = _tt_pattern_otype_add(p, otype);
529 tt_pattern_address_add(Tt_pattern p, Tt_address d)
532 Tt_status status = audit.entry("PD", TT_PATTERN_ADDRESS_ADD, p, d);
534 if (status != TT_OK) {
539 status = _tt_pattern_address_add(p, d);
547 tt_pattern_disposition_add(Tt_pattern p, Tt_disposition r)
550 Tt_status status = audit.entry("Pd", TT_PATTERN_DISPOSITION_ADD, p, r);
552 if (status != TT_OK) {
557 status = _tt_pattern_disposition_add(p, r);
565 tt_pattern_scope_add(Tt_pattern p, Tt_scope s)
568 Tt_status status = audit.entry("PS", TT_PATTERN_SCOPE_ADD, p, s);
570 if (status != TT_OK) {
575 status = _tt_pattern_scope_add(p, s);
583 tt_pattern_sender_add(Tt_pattern p, const char *procid)
586 Tt_status status = audit.entry("PC", TT_PATTERN_SENDER_ADD, p, procid);
588 if (status != TT_OK) {
593 status = _tt_pattern_sender_add(p, procid);
601 tt_pattern_sender_ptype_add(Tt_pattern p, const char *ptid)
604 Tt_status status = audit.entry("PC", TT_PATTERN_SENDER_PTYPE_ADD, p,
607 if (status != TT_OK) {
612 status = _tt_pattern_sender_ptype_add(p, ptid);
620 tt_pattern_session_add(Tt_pattern p, const char *sessid)
623 Tt_status status = audit.entry("PC", TT_PATTERN_SESSION_ADD, p,
626 if (status != TT_OK) {
631 status = _tt_pattern_session_add(p, sessid);
639 tt_pattern_state_add(Tt_pattern p, Tt_state s)
642 Tt_status status = audit.entry("Pe", TT_PATTERN_STATE_ADD, p, s);
644 if (status != TT_OK) {
649 status = _tt_pattern_state_add(p, s);
657 tt_ptype_declare(const char * ptid)
660 Tt_status status = audit.entry("C", TT_PTYPE_DECLARE, ptid);
662 if (status != TT_OK) {
667 status = _tt_ptype_declare(ptid);
675 tt_ptype_undeclare(const char * ptid)
678 Tt_status status = audit.entry("C", TT_PTYPE_UNDECLARE, ptid);
680 if (status != TT_OK) {
685 status = _tt_ptype_undeclare(ptid);
693 tt_ptype_exists(const char * ptid)
696 Tt_status status = audit.entry("C", TT_PTYPE_EXISTS, ptid);
698 if (status != TT_OK) {
703 status = _tt_ptype_exists(ptid);
711 tt_session_types_load(const char * sessid, const char *filename)
714 Tt_status status = audit.entry("EC", TT_SESSION_TYPES_LOAD, sessid,
717 if (status != TT_OK) {
722 // XXX: Should check that the supplied sessid is the session that the
723 // default procid is talking to, but we don't have a tt_session_equal.
725 // Really, things like
726 // tt_ptype_exists that don\'t really require a procid should
727 // all take a sessid and do this, to pave the way for a possible
728 // implementation that allows multiple sessions per procid.
730 status = _tt_session_types_load(filename);
738 tt_context_join(const char *slotname, const char *value)
741 Tt_status status = audit.entry("lC", TT_CONTEXT_JOIN, slotname,
744 if (status != TT_OK) {
749 status = _tt_context_join(slotname, value);
757 tt_icontext_join(const char *slotname, int value)
760 Tt_status status = audit.entry("li", TT_ICONTEXT_JOIN, slotname, value);
762 if (status != TT_OK) {
767 status = _tt_icontext_join(slotname, value);
775 tt_bcontext_join(const char *slotname, const unsigned char *value, int len)
778 Tt_status status = audit.entry("lnI", TT_BCONTEXT_JOIN, slotname,
781 if (status != TT_OK) {
786 status = _tt_bcontext_join(slotname, value, len);
794 tt_context_quit(const char *slotname, const char *value)
797 Tt_status status = audit.entry("lC", TT_CONTEXT_QUIT, slotname,
800 if (status != TT_OK) {
805 status = _tt_context_quit(slotname, value);
813 tt_icontext_quit(const char *slotname, int value)
816 Tt_status status = audit.entry("li", TT_ICONTEXT_QUIT, slotname, value);
818 if (status != TT_OK) {
823 status = _tt_icontext_quit(slotname, value);
831 tt_bcontext_quit(const char *slotname, const unsigned char *value, int len)
834 Tt_status status = audit.entry("lnI", TT_BCONTEXT_QUIT, slotname,
837 if (status != TT_OK) {
842 status = _tt_bcontext_quit(slotname, value, len);
850 tt_xcontext_join(const char *slotname, xdrproc_t xdr_proc, void *value)
853 Tt_status status = audit.entry("lXA", TT_XCONTEXT_JOIN, slotname,
856 if (status != TT_OK) {
861 status = _tt_xcontext_join(slotname, xdr_proc, value);
869 tt_xcontext_quit(const char *slotname, xdrproc_t xdr_proc, void *value)
872 Tt_status status = audit.entry("lXA", TT_XCONTEXT_QUIT, slotname,
875 if (status != TT_OK) {
880 status = _tt_xcontext_quit(slotname, xdr_proc, value);
887 /***************************************************************************
889 ***************************************************************************/
892 // Print the pattern the user has passed in into a buffer & return
893 // that buffer to him.
895 _tt_pattern_print(Tt_pattern p)
897 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
902 return _tt_strdup(buf);
907 * Creation, alteration, and destruction (FSpec A.9.1)
911 * Create a new pattern object and returns a handle for it; use this
912 * handle in future calls to manipulate the pattern object.
915 _tt_pattern_create(void)
920 pat = new _Tt_pattern();
921 result = _tt_htab->lookup_phandle(pat);
926 * Destroys a pattern object. Destroying a pattern object implicitly
927 * unregisters the pattern.
930 _tt_pattern_destroy(Tt_pattern p)
932 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
933 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
938 status = _tt_c_mp->default_c_procid()->del_pattern(pat->id());
942 // Ignore errors about pattern not found. This prevents
943 // tt_pattern_unregister(pat) followed by tt_pattern_destroy(pat)
944 // from returning a warning. (bug #1158125)
946 if (status == TT_WRN_NOTFOUND) {
954 * Registers the pattern constructed in the pattern object with the
955 * message server, so that the process will start receiving messages that
956 * match the pattern. Once a pattern is registered, no further changes
957 * can be made in the pattern (except for the implicit changes performed
958 * by joining files and sessions)
961 _tt_pattern_register(Tt_pattern p)
963 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
964 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
967 if (pat->is_registered()) {
968 return TT_ERR_INVALID;
971 st = _tt_c_mp->default_c_procid()->add_pattern(pat);
973 pat->set_registered();
980 * Unregisters the pattern so that the process stops receiving messages
984 _tt_pattern_unregister(Tt_pattern p)
986 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
987 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
990 if (! pat->is_registered()) {
994 st = _tt_c_mp->default_c_procid()->del_pattern(pat->id());
996 pat->clr_registered();
1003 * Sets a callback on messages retrieved through pattern p
1006 _tt_pattern_callback_add(Tt_pattern p, Tt_message_callback f)
1009 return(TT_ERR_NOMP);
1012 if (_tt_pointer_error(p)!=TT_OK) return TT_ERR_POINTER;
1013 return _tt_htab->add_callback(p,f);
1018 _tt_pattern_user(Tt_pattern p, int key)
1020 return _tt_htab->fetch(p,key);
1025 _tt_pattern_user_set(Tt_pattern p,int key, void *v)
1027 return _tt_htab->store(p,key,v);
1032 * Category (FSpec A.9.3)
1036 * Returns the category of the pattern object associated with p.
1039 _tt_pattern_category(Tt_pattern p)
1041 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1043 // _Tt_pattern::category seems not to exist.
1044 return pat->category();
1049 * Sets the category of the pattern object associated with p.
1052 _tt_pattern_category_set(Tt_pattern p, Tt_category c)
1054 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1056 return(pat->set_category(c));
1061 * Pattern Attributes (FSpec A.9.4)
1066 * Adds a new argument to a message object. vtype is the name of a valid
1067 * value type. Use NULL for values of mode out.
1070 _tt_pattern_arg_add(Tt_pattern p, Tt_mode n,
1071 const char *vtype, const char *value)
1073 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1076 arg = new _Tt_arg(n, vtype);
1077 // NULL arg value means leave value unset (which matches everything)
1078 if (value != (char *)0) {
1079 arg->set_data_string(value);
1082 return pat->add_arg(arg);
1087 * Adds a new opaque argument to a pattern.
1090 _tt_pattern_barg_add(Tt_pattern p, Tt_mode n, const char *vtype,
1091 const unsigned char *value, int len)
1093 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1097 arg = new _Tt_arg(n, vtype);
1099 // NULL arg value means leave value unset (which matches everything)
1100 if (value != (unsigned char *) 0) {
1101 arg->set_data_string( _Tt_string(value, len) );
1104 return pat->add_arg(arg);
1109 * Adds a new integer argument to a pattern object. vtype is the name of
1110 * a valid value type.
1113 _tt_pattern_iarg_add(Tt_pattern p, Tt_mode n, const char *vtype,
1116 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1119 arg = new _Tt_arg(n, vtype);
1120 arg->set_data_int(value);
1121 return pat->add_arg(arg);
1126 * Adds a new argument w/ an XDR'ed value to a pattern object.
1129 _tt_pattern_xarg_add(Tt_pattern p, Tt_mode n, const char *vtype,
1130 xdrproc_t xdr_proc, void *value)
1132 _Tt_pattern_ptr pat_p = _tt_htab->lookup_pat(p);
1136 // Encode the XDR arg or return failure.
1139 if (_tt_xdr_encode(xdr_proc, value, xdr_arg) == 0) {
1143 // Set the argument.
1144 arg = new _Tt_arg(n, vtype);
1146 _Tt_string s(xdr_arg);
1148 arg->set_data_string(s);
1150 return pat_p->add_arg(arg);
1155 * Adds a string value to a context slot.
1158 _tt_pattern_context_add(Tt_pattern p, const char *slotname, const char *value)
1160 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1161 _Tt_pat_context_ptr cntxt;
1165 cntxt = pat->context(slotname);
1166 if (cntxt.is_null()) {
1167 cntxt = new _Tt_pat_context;
1168 if (cntxt.is_null()) {
1169 return TT_ERR_NOMEM;
1171 status = cntxt->setName(slotname);
1172 if (status != TT_OK) {
1177 // NULL value means leave value unset (which matches everything)
1178 if (value != (char *)0) {
1179 _Tt_string valString(value);
1180 status = cntxt->addValue(valString);
1181 if (status != TT_OK) {
1186 return pat->add_context( cntxt );
1193 * Adds an integer value to a context slot.
1196 _tt_pattern_icontext_add(Tt_pattern p, const char *slotname, int value)
1198 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1199 _Tt_pat_context_ptr cntxt;
1203 cntxt = pat->context(slotname);
1204 if (cntxt.is_null()) {
1205 cntxt = new _Tt_pat_context;
1206 if (cntxt.is_null()) {
1207 return TT_ERR_NOMEM;
1209 status = cntxt->setName(slotname);
1210 if (status != TT_OK) {
1215 status = cntxt->addValue(value);
1216 if (status != TT_OK) {
1220 return pat->add_context(cntxt);
1227 * XDR equivalent of tt_pattern_bcontext_add.
1230 _tt_pattern_xcontext_add(Tt_pattern p, const char *slotname,
1231 xdrproc_t xdr_proc, void *value)
1234 _Tt_pattern_ptr pat_p = _tt_htab->lookup_pat(p);
1235 _Tt_pat_context_ptr cntxt_p;
1239 cntxt_p = pat_p->context(slotname);
1240 if (cntxt_p.is_null()) {
1241 cntxt_p = new _Tt_pat_context;
1242 if (cntxt_p.is_null()) {
1243 return TT_ERR_NOMEM;
1245 status = cntxt_p->setName(slotname);
1246 if (status != TT_OK) {
1252 // Encode the XDR context or return failure.
1253 _Tt_string xdr_context;
1255 if (_tt_xdr_encode(xdr_proc, value, xdr_context) == 0) {
1259 // add the XDR'ed context
1260 status = cntxt_p->addValue(xdr_context);
1261 if (status != TT_OK) {
1265 return pat_p->add_context(cntxt_p);
1272 * Adds a byte-string value to a context slot.
1275 _tt_pattern_bcontext_add(Tt_pattern p, const char *slotname,
1276 const unsigned char *value, int len)
1278 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1279 _Tt_pat_context_ptr cntxt;
1284 cntxt = pat->context( slotname );
1285 if (cntxt.is_null()) {
1286 cntxt = new _Tt_pat_context;
1287 if (cntxt.is_null()) {
1288 return TT_ERR_NOMEM;
1290 status = cntxt->setName( slotname );
1291 if (status != TT_OK) {
1296 // NULL value means leave value unset (which matches everything)
1297 if (value != (unsigned char *)0) {
1298 _Tt_string valString( value, len );
1300 status = cntxt->addValue( valString );
1301 if (status != TT_OK) {
1306 return pat->add_context( cntxt );
1313 _tt_pattern_class_add(Tt_pattern p, Tt_class c)
1315 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1317 return(pat->add_message_class(c));
1322 _tt_pattern_file_add(Tt_pattern p, const char *filepath)
1324 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1326 return(pat->add_netfile(filepath));
1331 _tt_pattern_object_add(Tt_pattern p, const char * objid)
1333 _Tt_string oid = objid;
1334 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1336 return(pat->add_object(oid.unquote_nulls()));
1341 _tt_pattern_op_add(Tt_pattern p, const char *opname)
1343 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1345 return(pat->add_op(opname));
1350 _tt_pattern_opnum_add(Tt_pattern p, int opnum)
1353 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1355 return(pat->add_opnum(opnum));
1360 _tt_pattern_otype_add(Tt_pattern p, const char * otype)
1362 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1365 if (TT_WRN_LAST < (rc = _tt_valid_otype(otype))) {
1368 return(pat->add_otype(otype));
1373 _tt_pattern_address_add(Tt_pattern p, Tt_address d)
1375 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1377 return(pat->add_paradigm(d));
1382 _tt_pattern_disposition_add(Tt_pattern p,Tt_disposition r)
1385 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1387 return(pat->add_reliability(r));
1392 _tt_pattern_scope_add(Tt_pattern p, Tt_scope s)
1394 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1396 return(pat->add_scope(s));
1401 _tt_pattern_sender_add(Tt_pattern p, const char *procid)
1403 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1405 return(pat->add_sender(procid));
1410 _tt_pattern_sender_ptype_add(Tt_pattern p, const char *ptid)
1412 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1414 return(pat->add_sender_ptype(ptid));
1419 _tt_pattern_session_add(Tt_pattern p, const char *sessid)
1422 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1423 _Tt_session_ptr sptr;
1424 _Tt_string strsessid = (char *)0;
1427 // Add the P on if isn't already.
1428 _prepend_P_to_sessid(sessid, strsessid);
1430 status = _tt_c_mp->find_session(strsessid, sptr, 1);
1431 if (TT_OK != status) return status;
1433 return(pat->add_session(sptr->id()));
1438 _tt_pattern_state_add(Tt_pattern p, Tt_state s)
1440 _Tt_pattern_ptr pat = _tt_htab->lookup_pat(p);
1442 return(pat->add_state(s));
1447 * --> Experimental function for PE internal dispatch. Not to be advertised
1448 * in the header files yet.
1452 * _tt_x_pattern_match(Tt_pattern p, Tt_message m)
1454 * _Tt_message_ptr msg;
1455 * _Tt_pattern_ptr pat;
1457 * if (tt_ptr_error(m) != TT_OK || tt_ptr_error(p) != TT_OK) {
1460 * msg = _tt_htab->lookup_msg(m);
1461 * pat = _tt_htab->lookup_pat(p);
1462 * if (msg.is_null() || pat.is_null()) {
1465 * return(pat->match(msg));
1470 * Ptype functions (FSpec A.10)
1475 * Used to declare a ptype for a process.
1478 _tt_ptype_declare(const char * ptid)
1480 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
1486 status = _tt_c_mp->default_c_procid()->declare_ptype(sptid);
1487 if (status < TT_WRN_LAST) {
1488 _tt_c_mp->default_c_procid()->set_default_ptype(sptid);
1495 * Used to undeclare a ptype for a process.
1498 _tt_ptype_undeclare(const char * ptid)
1500 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
1506 status = _tt_c_mp->default_c_procid()->undeclare_ptype(sptid);
1511 * Used to check if a ptype is known by the default session.
1514 _tt_ptype_exists(const char * ptid)
1516 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
1522 status = _tt_c_mp->default_c_procid()->exists_ptype(sptid);
1527 * Used to load new types into the default session.
1530 _tt_session_types_load(const char *filename)
1532 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
1538 struct stat typefile_stat;
1540 if (-1==(fd=open(filename, O_RDONLY))) {
1543 fcntl(fd, F_SETFD, 1); /* Close on exec */
1545 if (-1==fstat(fd, &typefile_stat)) {
1549 _Tt_string typebuffer((int)typefile_stat.st_size);
1550 if (typefile_stat.st_size !=
1551 read(fd, (void *)(char *)typebuffer,
1552 (unsigned int)typefile_stat.st_size)) {
1556 if (-1==close(fd)) {
1559 status = _tt_c_mp->default_c_procid()->load_types(typebuffer);
1565 * Contexts and static patterns
1569 * Add a string context to all patterns.
1572 _tt_context_join(const char *slotname, const char *value)
1574 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
1579 _Tt_c_msg_context_ptr cntxt = new _Tt_c_msg_context;
1581 status = cntxt->setName( slotname );
1582 if (status != TT_OK) {
1585 _Tt_string valString( value );
1586 status = cntxt->setValue( valString );
1587 if (status != TT_OK) {
1591 return cntxt->c_join( *_tt_c_mp->default_c_procid()->default_session(),
1592 _tt_c_mp->default_c_procid() );
1597 * Add an integer context to all patterns.
1600 _tt_icontext_join(const char *slotname, int value)
1602 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
1607 _Tt_c_msg_context_ptr cntxt = new _Tt_c_msg_context;
1608 status = cntxt->setName( slotname );
1609 if (status != TT_OK) {
1612 status = cntxt->setValue( value );
1613 if (status != TT_OK) {
1617 return cntxt->c_join( *_tt_c_mp->default_c_procid()->default_session(),
1618 _tt_c_mp->default_c_procid() );
1623 * Add a byte-array context to all patterns.
1626 _tt_bcontext_join(const char *slotname, const unsigned char *value, int len)
1628 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
1633 _Tt_c_msg_context_ptr cntxt = new _Tt_c_msg_context;
1634 status = cntxt->setName( slotname );
1635 if (status != TT_OK) {
1638 _Tt_string valString( value, len );
1639 status = cntxt->setValue( valString );
1640 if (status != TT_OK) {
1644 return cntxt->c_join( *_tt_c_mp->default_c_procid()->default_session(),
1645 _tt_c_mp->default_c_procid() );
1650 * Remove a string context from all patterns.
1653 _tt_context_quit(const char *slotname, const char *value)
1655 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
1660 _Tt_c_msg_context_ptr cntxt = new _Tt_c_msg_context;
1661 status = cntxt->setName( slotname );
1662 if (status != TT_OK) {
1665 _Tt_string valString( value );
1666 status = cntxt->setValue( valString );
1667 if (status != TT_OK) {
1671 return cntxt->c_quit( *_tt_c_mp->default_c_procid()->default_session(),
1672 _tt_c_mp->default_c_procid() );
1677 * Remove an integer context from all patterns.
1680 _tt_icontext_quit(const char *slotname, int value)
1682 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
1687 _Tt_c_msg_context_ptr cntxt = new _Tt_c_msg_context;
1688 status = cntxt->setName( slotname );
1689 if (status != TT_OK) {
1692 status = cntxt->setValue( value );
1693 if (status != TT_OK) {
1697 return cntxt->c_quit( *_tt_c_mp->default_c_procid()->default_session(),
1698 _tt_c_mp->default_c_procid() );
1703 * Remove a byte-array context from all patterns.
1706 _tt_bcontext_quit(const char *slotname, const unsigned char *value, int len)
1708 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
1713 _Tt_c_msg_context_ptr cntxt = new _Tt_c_msg_context;
1714 status = cntxt->setName( slotname );
1715 if (status != TT_OK) {
1718 _Tt_string valString( value, len );
1719 status = cntxt->setValue( valString );
1720 if (status != TT_OK) {
1724 return cntxt->c_quit(*_tt_c_mp->default_c_procid()->default_session(),
1725 _tt_c_mp->default_c_procid());
1730 * XDR equivalent of tt_bcontext_join.
1733 _tt_xcontext_join(const char *slotname, xdrproc_t xdr_proc, void *value)
1735 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
1740 _Tt_c_msg_context_ptr cntxt_p = new _Tt_c_msg_context;
1742 status = cntxt_p->setName(slotname);
1743 if (status != TT_OK) {
1747 // Encode the XDR context or return failure.
1748 _Tt_string xdr_context;
1750 if (_tt_xdr_encode(xdr_proc, value, xdr_context) == 0) {
1754 // join the new context to the existing patterns
1755 _Tt_string valString(xdr_context);
1757 status = cntxt_p->setValue(valString);
1758 if (status != TT_OK) {
1762 return cntxt_p->c_join( *_tt_c_mp->default_c_procid()->default_session(),
1763 _tt_c_mp->default_c_procid() );
1768 * XDR equivalent of tt_bcontext_quit.
1771 _tt_xcontext_quit(const char *slotname, xdrproc_t xdr_proc, void *value)
1773 _Tt_c_procid *d_procid = _tt_c_mp->default_c_procid().c_pointer();
1778 // setup target context.
1779 _Tt_c_msg_context_ptr cntxt_p;
1781 cntxt_p = new _Tt_c_msg_context;
1782 status = cntxt_p->setName(slotname);
1783 if (status != TT_OK) {
1787 // Encode the XDR context or return failure.
1788 _Tt_string xdr_context;
1790 if (_tt_xdr_encode(xdr_proc, value, xdr_context) == 0) {
1794 // try to quit the specified, now encoded, context.
1795 _Tt_string valString(xdr_context);
1797 status = cntxt_p->setValue(valString);
1798 if (status != TT_OK) {
1802 return cntxt_p->c_quit(*_tt_c_mp->default_c_procid()->default_session(),
1803 _tt_c_mp->default_c_procid());