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: mp_pattern.C /main/5 1999/10/14 18:48:24 mgreess $
30 * @(#)mp_pattern.C 1.28 30 Jul 1993
32 * Tool Talk Message Passer (MP) - mp_pattern.cc
34 * Copyright (c) 1990,1992 by Sun Microsystems, Inc.
36 #include "api/c/api_spec_map_ref.h"
37 #include "mp/mp_global.h"
38 #include "mp/mp_arg.h"
39 #include "mp/mp_pat_context.h"
41 #include "mp/mp_pattern.h"
42 #include "mp/mp_message.h"
43 #include "mp/mp_session.h"
44 #include "mp/mp_xdr_functions.h"
45 #include "util/tt_enumname.h"
46 #include "util/tt_global_env.h"
47 #include "util/tt_port.h"
50 // Base constructor for _Tt_pattern objects. Should be called by all
51 // other _Tt_pattern constructors.
57 _category = TT_CATEGORY_LAST;
63 _files = new _Tt_string_list();
64 _handler_ptypes = new _Tt_string_list();
65 _handlers = new _Tt_string_list();
66 _objects = new _Tt_string_list();
67 _observer_ptypes = new _Tt_string_list();
68 _opnums = new _Tt_int_rec_list();
69 _ops = new _Tt_string_list();
70 _args = new _Tt_arg_list();
71 _contexts = new _Tt_pat_context_list;
72 _otypes = new _Tt_string_list();
73 _sender_ptypes = new _Tt_string_list();
74 _senders = new _Tt_string_list();
75 _sessions = new _Tt_string_list();
86 // Deletes the given argument from the _files field of this object.
88 Tt_status _Tt_pattern::
89 del_file(const _Tt_string &f)
91 _Tt_string_list_cursor fcursor(_files);
93 while (fcursor.next()) {
103 // Deletes the given argument from the _sessions field of this object.
105 Tt_status _Tt_pattern::
106 del_session(const _Tt_string &s)
108 _Tt_string_list_cursor scursor(_sessions);
110 while (scursor.next()) {
120 // Adds the given object id to the _objects field. Will return
121 // TT_WRN_STALE_OBJID if the oid is a stale object id.
123 Tt_status _Tt_pattern::
124 add_object(const _Tt_string &oid)
126 _Tt_api_spec_map_ref spec_map;
127 _Tt_objid_spec_ptr spec = spec_map.getSpec(oid);
130 if (spec.is_null()) {
131 return(TT_ERR_OBJID);
134 switch (spec->getDBResults()) {
138 case TT_DB_WRN_FORWARD_POINTER:
139 status = TT_WRN_STALE_OBJID;
142 return(TT_ERR_OBJID);
144 add_field(oid, _objects);
151 // Generic function for adding an integer to a _Tt_int_rec_list if it
152 // isn't already there.
155 add_field(int v, _Tt_int_rec_list_ptr &vlist)
157 _Tt_int_rec_list_cursor c(vlist);
164 vlist->push(new _Tt_int_rec((int)v));
169 // Generic function for adding a string to a _Tt_string_list if it
170 // isn't already there.
173 add_field(const _Tt_string &v, _Tt_string_list_ptr &vlist)
175 _Tt_string_list_cursor c(vlist);
186 _Tt_pat_context_ptr _Tt_pattern::
187 context(const char *slotname) const
189 _Tt_pat_context_list_cursor contextC( _contexts );
190 while (contextC.next()) {
191 if (contextC->slotName() == slotname) {
199 _Tt_pat_context_ptr _Tt_pattern::
202 if ((i >= 0) && (i < _contexts->count())) {
203 return (*_contexts)[ i ];
210 contextsCount() const
212 if (_contexts.is_null()) {
215 return _contexts->count();
219 _Tt_pattern::add_netfile(
220 const _Tt_string &filepath,
221 int fallback_2_local_netfile
225 Tt_status status = TT_OK;
226 int __scopes = scopes();
228 if ((__scopes&(1<<TT_FILE)) || (__scopes&(1<<TT_BOTH))) {
229 abspath = _Tt_db_file::getNetworkPath(filepath);
230 if ((abspath.len() == 0) && (! fallback_2_local_netfile)) {
234 if (abspath.len() == 0) {
235 abspath = _tt_local_network_path(filepath);
236 if (abspath.len() == 0) {
240 return(add_file(abspath));
245 // XDR encodes/decodes a pattern.
250 if (! tt_xdr_string(xdrs, &_pattern_id)) {
253 if (! xdr_int(xdrs, (int *)&_category)) {
256 if (! xdr_int(xdrs, (int *)&_classes)) {
259 if (! xdr_int(xdrs, (int *)&_states)) {
262 if (! xdr_int(xdrs, (int *)&_paradigms)) {
265 if (! xdr_int(xdrs, (int *)&_scopes)) {
268 if (! xdr_int(xdrs, (int *)&_reliabilities)) {
271 if (! _files.xdr(xdrs)) {
274 if (! _sessions.xdr(xdrs)) {
277 if (! _ops.xdr(xdrs)) {
280 if (! _opnums.xdr(xdrs)) {
283 if (! _objects.xdr(xdrs)) {
286 if (! _otypes.xdr(xdrs)) {
289 if (! _senders.xdr(xdrs)) {
292 if (! _handlers.xdr(xdrs)) {
295 if (! _sender_ptypes.xdr(xdrs)) {
298 if (! _handler_ptypes.xdr(xdrs)) {
301 if (! _args.xdr(xdrs)) {
304 if (_tt_global->xdr_version() >= TT_CONTEXTS_XDR_VERSION) {
305 if (! _contexts.xdr(xdrs)) {
315 // Function wrapper so that the xdr method for a pattern can be invoked
316 // from the C RPC interface.
318 bool_t tt_xdr_pattern(XDR *xdrs, _Tt_pattern_ptr *pat)
320 return((*pat)->xdr(xdrs));
324 // methods and functions associated with printing patterns
330 return(_tt_enumname((Tt_class)r));
334 int_to_paradigm(int r)
336 return(_tt_enumname((Tt_address) r));
342 return(_tt_enumname((Tt_state) r));
348 return(_tt_enumname((Tt_scope) r));
353 // Used to print out a generic list of integers. The given conversion
354 // function ppfn returns an appropiate string to print for each integer.
355 // See all the int_to_* functions above.
358 print_enum_mask(const _Tt_ostream &os, int start, int end, int mask,
359 const char *(*ppfn)(int a))
363 for (i=start;i <= end;i++) {
365 os << (*ppfn)(i) << " ";
372 // Used by the generic list and table packages to print out elements.
373 // Should not be used otherwise.
376 _tt_int_rec_print(const _Tt_ostream &os, const _Tt_object *obj)
378 ((_Tt_int_rec *)obj)->print(os);
383 // Prints out a pattern object. Used for debugging and for printing out
384 // patterns being considered when tracing is turned on.
387 print(const _Tt_ostream &os) const
390 os << _pattern_id << "\n";
391 os << "category:\t" << _tt_enumname(_category) << "\n";
394 print_enum_mask(os,(int)TT_CLASS_UNDEFINED,(int)TT_CLASS_LAST,
395 _classes, int_to_class);
400 print_enum_mask(os,(int)TT_CREATED, (int)TT_STATE_LAST,
401 _states, int_to_state);
404 if (_paradigms != 0) {
405 os << "addresses:\t";
406 print_enum_mask(os,(int)TT_PROCEDURE,(int)TT_HANDLER,
407 _paradigms, int_to_paradigm);
412 print_enum_mask(os,(int)TT_SCOPE_NONE,(int)TT_FILE_IN_SESSION,
413 _scopes, int_to_scope);
416 if (_files->count()) {
418 _files->print(_tt_string_print, os);
421 if (_sessions->count()) {
423 _sessions->print(_tt_string_print, os);
428 _ops->print(_tt_string_print, os);
431 if (_args->count()) {
433 _Tt_string indent = os.indent();
434 os.set_indent( indent.cat( "\t" ));
435 _Tt_arg_list_cursor argC( _args );
436 while (argC.next()) {
439 os.set_indent( indent );
441 if (_contexts->count()) {
443 _Tt_string indent = os.indent();
444 os.set_indent( indent.cat( "\t" ));
445 _Tt_pat_context_list_cursor contextC( _contexts );
446 while (contextC.next()) {
447 contextC->print( os );
449 os.set_indent( indent );
451 if (_opnums->count()) {
453 _opnums->print(_tt_int_rec_print, os);
456 if (_otypes->count()) {
458 _otypes->print(_tt_string_print, os);
461 if (_senders->count()) {
463 _senders->print(_tt_string_print, os);
466 if (_handlers->count()) {
468 _handlers->print(_tt_string_print, os);
471 if (_sender_ptypes->count()) {
472 os << "sender_ptypes:\t";
473 _sender_ptypes->print(_tt_string_print, os);
476 if (_handler_ptypes->count()) {
477 os << "handler_ptypes:\t";
478 _handler_ptypes->print(_tt_string_print, os);