Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / lib / api / c / api_mp_otype.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
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: api_mp_otype.C /main/4 1995/11/21 19:34:39 cde-sun $                                                        
28 /*
29  *
30  * mp_api_otype.cc
31  *
32  * Copyright (c) 1990 by Sun Microsystems, Inc.
33  * 
34  * This file contains API functions related to the MP. For
35  * each API function named tt_<name> there is a _tt_<name> function in
36  * some file named api_mp_*.cc.
37  */
38
39 #include "mp/mp_c.h"
40 #include "mp/mp_rpc_interface.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"
46
47 /*
48  * These functions differ from the usual layering in the API/MP interface.
49  * Usually, we would realize the _Tt_otype and _Tt_otype_table objects on
50  * the client side, with the methods split up so the client side makes
51  * RPC calls and the server side does the work.  In this case, this would
52  * end up caching most of the otype information in the client side, which
53  * would give us cache-coherency problems we don't have time to deal with
54  * right now.  So we have a simpler interface of the API routines just
55  * making RPC calls to the server. RFM 11/7/90.
56  */
57
58 extern _Tt_c_mp *_tt_c_mp;
59
60
61 int
62 tt_otype_deriveds_count(const char *otype)
63 {
64         _Tt_audit audit;
65         Tt_status status = audit.entry("o", TT_OTYPE_DERIVEDS_COUNT, otype);
66         int result;
67
68         if (status != TT_OK) {
69                 audit.exit(error_int(status));
70                 return error_int(status);
71         }
72
73         result = _tt_otype_deriveds_count(otype);
74         audit.exit(result);
75
76         return result;
77 }
78
79
80 char *
81 tt_otype_derived(const char *otype, int i)
82 {
83         _Tt_audit audit;
84         Tt_status status = audit.entry("oi", TT_OTYPE_DERIVED, otype, i);
85         char *result;
86
87         if (status != TT_OK) {
88                 audit.exit((char *)error_pointer(status));
89                 return (char *)error_pointer(status);
90         }
91
92         result = _tt_otype_derived(otype, i);
93         audit.exit(result);
94
95         return result;
96 }
97
98
99 char *
100 tt_otype_base(const char *otype)
101 {
102         _Tt_audit audit;
103         Tt_status status = audit.entry("o", TT_OTYPE_BASE, otype);
104         char *result;
105  
106         if (status != TT_OK) {
107                 audit.exit((char *)error_pointer(status));
108                 return (char *)error_pointer(status);
109         }
110
111         result = _tt_otype_base(otype);
112         audit.exit(result);
113
114         return result;
115 }
116
117
118 int
119 tt_otype_is_derived(const char *derivedotype, const char *baseotype)
120 {
121         _Tt_audit audit;
122         Tt_status status = audit.entry("oo", TT_OTYPE_IS_DERIVED,
123                                        derivedotype, baseotype);
124         int result;
125
126         if (status != TT_OK) {
127                 audit.exit(error_int(status));
128                 return error_int(status);
129         }
130
131         result = _tt_otype_is_derived(derivedotype, baseotype);
132         audit.exit(result);
133
134         return result;
135 }
136
137
138 int
139 tt_otype_osig_count(const char *otype)
140 {
141         _Tt_audit audit;
142         Tt_status status = audit.entry("o", TT_OTYPE_OSIG_COUNT, otype);
143         int result;
144  
145         if (status != TT_OK) {
146                 audit.exit(error_int(status));
147                 return error_int(status);
148         }
149  
150         result = _tt_otype_osig_count(otype);
151         audit.exit(result);
152  
153         return result;
154 }
155
156
157 int
158 tt_otype_hsig_count(const char *otype)
159 {
160         _Tt_audit audit;
161         Tt_status status = audit.entry("o", TT_OTYPE_HSIG_COUNT, otype);
162         int result; 
163   
164         if (status != TT_OK) { 
165                 audit.exit(error_int(status));
166                 return error_int(status);
167         } 
168   
169         result = _tt_otype_hsig_count(otype);
170         audit.exit(result); 
171   
172         return result;
173 }
174
175
176 char *
177 tt_otype_osig_op(const char *otype, int sig)
178 {
179         _Tt_audit audit;
180         Tt_status status = audit.entry("oi", TT_OTYPE_OSIG_OP, otype, sig);
181         char *result;
182
183         if (status != TT_OK) {
184                 audit.exit((char *)error_pointer(status));
185                 return (char *)error_pointer(status);
186         }
187
188         result = _tt_otype_osig_op(otype, sig);
189         audit.exit(result);
190
191         return result;
192 }
193
194
195 char *
196 tt_otype_hsig_op(const char *otype, int sig)
197 {
198         _Tt_audit audit;
199         Tt_status status = audit.entry("oi", TT_OTYPE_HSIG_OP, otype, sig); 
200         char *result;
201  
202         if (status != TT_OK) { 
203                 audit.exit((char *)error_pointer(status));
204                 return (char *)error_pointer(status); 
205         } 
206  
207         result = _tt_otype_hsig_op(otype, sig);
208         audit.exit(result); 
209  
210         return result; 
211 }
212
213
214 int
215 tt_otype_osig_args_count(const char *otype, int sig)
216 {
217         _Tt_audit audit;
218         Tt_status status = audit.entry("oi", TT_OTYPE_OSIG_ARGS_COUNT, otype, sig);
219         int result;
220
221         if (status != TT_OK) {
222                 audit.exit(error_int(status));
223                 return error_int(status);
224         }
225
226         result = _tt_otype_osig_args_count(otype, sig);
227         audit.exit(result);
228
229         return result;
230 }
231
232
233 int
234 tt_otype_hsig_args_count(const char *otype, int sig)
235 {
236         _Tt_audit audit;
237         Tt_status status = audit.entry("oi", TT_OTYPE_HSIG_ARGS_COUNT, otype, sig);
238         int result; 
239  
240         if (status != TT_OK) { 
241                 audit.exit(error_int(status));
242                 return error_int(status); 
243         } 
244  
245         result = _tt_otype_hsig_args_count(otype, sig);
246         audit.exit(result); 
247  
248         return result; 
249 }
250
251
252 Tt_mode
253 tt_otype_osig_arg_mode(const char *otype, int sig, int arg)
254 {
255         _Tt_audit audit;
256         Tt_status status = audit.entry("oii", TT_OTYPE_OSIG_ARG_MODE, otype, sig, arg);
257         Tt_mode result;
258
259         if (status != TT_OK) {
260                 audit.exit((Tt_mode)error_int(status));
261                 return (Tt_mode) error_int(status);
262         }
263
264         result = _tt_otype_osig_arg_mode(otype, sig, arg);
265         audit.exit(result);
266
267         return result;
268 }
269
270
271 Tt_mode
272 tt_otype_hsig_arg_mode(const char *otype, int sig, int arg)
273 {
274         _Tt_audit audit;
275         Tt_status status = audit.entry("oii", TT_OTYPE_HSIG_ARG_MODE, otype, sig, arg);
276         Tt_mode result;
277
278         if (status != TT_OK) {
279                 audit.exit((Tt_mode)error_int(status));
280                 return (Tt_mode)error_int(status);
281         }
282
283         result = _tt_otype_hsig_arg_mode(otype, sig, arg);
284         audit.exit(result);
285
286         return result;
287 }
288
289
290 char *
291 tt_otype_osig_arg_type(const char *otype, int sig, int arg)
292 {
293         _Tt_audit audit;
294         Tt_status status = audit.entry("oii", TT_OTYPE_OSIG_ARG_TYPE, otype, sig, arg);
295         char *result;
296
297         if (status != TT_OK) {
298                 audit.exit((char *)error_pointer(status));
299                 return (char *)error_pointer(status);
300         }
301
302         result = _tt_otype_osig_arg_type(otype, sig, arg);
303         audit.exit(result);
304
305         return result;
306 }
307
308
309 char *
310 tt_otype_hsig_arg_type(const char *otype, int sig, int arg)
311 {
312         _Tt_audit audit;
313         Tt_status status = audit.entry("oii", TT_OTYPE_HSIG_ARG_TYPE, otype, sig, arg);
314         char *result;
315
316         if (status != TT_OK) {
317                 audit.exit((char *)error_pointer(status));
318                 return (char *)error_pointer(status);
319         }
320
321         result = _tt_otype_hsig_arg_type(otype, sig, arg);
322         audit.exit(result);
323
324         return result;
325 }
326
327
328 /*
329  * otype retrieval functions
330  */
331
332 int
333 _tt_otype_deriveds_count(const char * otype)
334 {
335         _Tt_otype_args args;
336         _Tt_rpc_result result;
337         _Tt_c_session *d_session;
338
339         d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
340         
341         args.base_otid = otype;
342         d_session->call(TT_RPC_OTYPE_DERIVEDS_COUNT,
343                          (xdrproc_t)tt_xdr_otype_args,
344                          (char *)&args,
345                          (xdrproc_t)tt_xdr_rpc_result,
346                          (char *)&result);
347         if (result.status!=TT_OK) {
348                 return error_int(result.status);
349         } else {
350                 return result.int_val;
351         }
352 }
353
354
355 char *
356 _tt_otype_derived(const char * otype, int i)
357 {
358         _Tt_otype_args args;
359         _Tt_rpc_result result;
360         _Tt_c_session   *d_session;
361
362         d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
363
364         args.base_otid = otype;
365         args.num = i;
366         d_session->call(TT_RPC_OTYPE_DERIVED,
367                          (xdrproc_t)tt_xdr_otype_args,
368                          (char *)&args,
369                          (xdrproc_t)tt_xdr_rpc_result,
370                          (char *)&result);
371         if (result.status!=TT_OK) {
372                 return (char *)error_pointer(result.status);
373         } else {
374                 return _tt_strdup(result.str_val);
375         }
376 }
377
378 char *
379 _tt_otype_base(const char *otype)
380 {
381         _Tt_otype_args args;
382         _Tt_rpc_result result;
383         _Tt_c_session *d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
384         
385         args.derived_otid = otype;
386         d_session->call(TT_RPC_OTYPE_BASE,
387                          (xdrproc_t)tt_xdr_otype_args,
388                          (char *)&args,
389                          (xdrproc_t)tt_xdr_rpc_result,
390                          (char *)&result);
391         if (result.status!=TT_OK) {
392                 return (char *)error_pointer(result.status);
393         } else {        
394                 return _tt_strdup(result.str_val);
395         }
396 }
397
398
399 int
400 _tt_otype_is_derived(const char *derivedotype,
401                      const char *baseotype)
402 {
403         _Tt_otype_args args;
404         _Tt_rpc_result result;
405         _Tt_c_session *d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
406
407
408         args.derived_otid = derivedotype;
409         args.base_otid = baseotype;
410         
411         d_session->call(TT_RPC_OTYPE_IS_DERIVED,
412                          (xdrproc_t)tt_xdr_otype_args,
413                          (char *)&args,
414                          (xdrproc_t)tt_xdr_rpc_result,
415                          (char *)&result);
416         if (result.status!=TT_OK) {
417                 return 0;       // Predicates that return failure are a pain
418         } else {
419                 return result.int_val;
420         }
421 }
422
423
424 int
425 _tt_otype_osig_count(const char *otype)
426 {
427         _Tt_otype_args args;
428         _Tt_rpc_result result;
429         _Tt_c_session *d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
430         
431         args.base_otid = otype;
432         
433         d_session->call(TT_RPC_OTYPE_OSIG_COUNT,
434                          (xdrproc_t)tt_xdr_otype_args,
435                          (char *)&args,
436                          (xdrproc_t)tt_xdr_rpc_result,
437                          (char *)&result);
438         if (result.status!=TT_OK) {
439                 return error_int(result.status);
440         } else {
441                 return result.int_val;
442         }
443 }
444
445
446 int
447 _tt_otype_hsig_count(const char *otype)
448 {
449         _Tt_otype_args args;
450         _Tt_rpc_result result;
451         _Tt_c_session *d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
452         
453         args.base_otid = otype;
454         
455         d_session->call(TT_RPC_OTYPE_HSIG_COUNT,
456                          (xdrproc_t)tt_xdr_otype_args,
457                          (char *)&args,
458                          (xdrproc_t)tt_xdr_rpc_result,
459                          (char *)&result);
460         if (result.status!=TT_OK) {
461                 return error_int(result.status);
462         } else {
463                 return result.int_val;
464         }
465 }
466
467
468 char *
469 _tt_otype_osig_op(const char *otype, int sig)
470 {
471         _Tt_otype_args args;
472         _Tt_rpc_result result;
473         _Tt_c_session *d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
474         
475         args.base_otid = otype;
476         args.num = sig;
477         
478         d_session->call(TT_RPC_OTYPE_OSIG_OP,
479                          (xdrproc_t)tt_xdr_otype_args,
480                          (char *)&args,
481                          (xdrproc_t)tt_xdr_rpc_result,
482                          (char *)&result);
483         if (result.status!=TT_OK) {
484                 return (char *)error_pointer(result.status);
485         } else {
486                 return _tt_strdup(result.str_val);
487         }
488 }
489
490
491 char *
492 _tt_otype_hsig_op(const char *otype, int sig)
493 {
494         _Tt_otype_args args;
495         _Tt_rpc_result result;
496         _Tt_c_session *d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
497         
498         args.base_otid = otype;
499         args.num = sig;
500         
501         d_session->call(TT_RPC_OTYPE_HSIG_OP,
502                          (xdrproc_t)tt_xdr_otype_args,
503                          (char *)&args,
504                          (xdrproc_t)tt_xdr_rpc_result,
505                          (char *)&result);
506         if (result.status!=TT_OK) {
507                 return (char *)error_pointer(result.status);
508         } else {
509                 return _tt_strdup(result.str_val);
510         }
511 }
512
513
514 int
515 _tt_otype_osig_args_count(const char *otype, int sig)
516 {
517         _Tt_otype_args args;
518         _Tt_rpc_result result;
519         _Tt_c_session *d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
520         
521         args.base_otid = otype;
522         args.num = sig;
523         
524         d_session->call(TT_RPC_OTYPE_OSIG_ARGS_COUNT,
525                          (xdrproc_t)tt_xdr_otype_args,
526                          (char *)&args,
527                          (xdrproc_t)tt_xdr_rpc_result,
528                          (char *)&result);
529         if (result.status!=TT_OK) {
530                 return error_int(result.status);
531         } else {
532                 return result.int_val;
533         }
534 }
535
536
537 int
538 _tt_otype_hsig_args_count(const char *otype, int sig)
539 {
540         _Tt_otype_args args;
541         _Tt_rpc_result result;
542         _Tt_c_session *d_session;
543
544         d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
545         
546         args.base_otid = otype;
547         args.num = sig;
548         
549         d_session->call(TT_RPC_OTYPE_HSIG_ARGS_COUNT,
550                          (xdrproc_t)tt_xdr_otype_args,
551                          (char *)&args,
552                          (xdrproc_t)tt_xdr_rpc_result,
553                          (char *)&result);
554         if (result.status!=TT_OK) {
555                 return error_int(result.status);
556         } else {
557                 return result.int_val;
558         }
559 }
560
561
562 Tt_mode
563 _tt_otype_osig_arg_mode(const char *otype, int sig, int arg)
564 {
565         _Tt_otype_args args;
566         _Tt_rpc_result result;
567         _Tt_c_session *d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
568         
569         args.base_otid = otype;
570         args.num = sig;
571         args.num2 = arg;
572         
573         d_session->call(TT_RPC_OTYPE_OSIG_ARG_MODE,
574                          (xdrproc_t)tt_xdr_otype_args,
575                          (char *)&args,
576                          (xdrproc_t)tt_xdr_rpc_result,
577                          (char *)&result);
578         if (result.status!=TT_OK) {
579                 return (Tt_mode)error_int(result.status);
580         } else {
581                 return (Tt_mode)result.int_val;
582         }
583 }
584
585
586 Tt_mode
587 _tt_otype_hsig_arg_mode(const char *otype, int sig, int arg)
588 {
589         _Tt_otype_args args;
590         _Tt_rpc_result result;
591         _Tt_c_session *d_session;
592
593         d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
594         
595         args.base_otid = otype;
596         args.num = sig;
597         args.num2 = arg;
598         
599         d_session->call(TT_RPC_OTYPE_HSIG_ARG_MODE,
600                          (xdrproc_t)tt_xdr_otype_args,
601                          (char *)&args,
602                          (xdrproc_t)tt_xdr_rpc_result,
603                          (char *)&result);
604         if (result.status!=TT_OK) {
605                 return (Tt_mode)error_int(result.status);
606         } else {
607                 return (Tt_mode)result.int_val;
608         }
609 }
610
611
612 char *
613 _tt_otype_osig_arg_type(const char *otype, int sig, int arg)
614 {
615         _Tt_otype_args args;
616         _Tt_rpc_result result;
617         _Tt_c_session *d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
618         
619         args.base_otid = otype;
620         args.num = sig;
621         args.num2 = arg;
622         
623         d_session->call(TT_RPC_OTYPE_OSIG_ARG_TYPE,
624                          (xdrproc_t)tt_xdr_otype_args,
625                          (char *)&args,
626                          (xdrproc_t)tt_xdr_rpc_result,
627                          (char *)&result);
628         if (result.status!=TT_OK) {
629                 return (char *)error_pointer(result.status);
630         } else {
631                 return _tt_strdup(result.str_val);
632         }
633 }
634
635
636 char *
637 _tt_otype_hsig_arg_type(const char *otype, int sig, int arg)
638 {
639         _Tt_otype_args args;
640         _Tt_rpc_result result;
641         _Tt_c_session *d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
642         
643         args.base_otid = otype;
644         args.num = sig;
645         args.num2 = arg;
646         
647         d_session->call(TT_RPC_OTYPE_HSIG_ARG_TYPE,
648                          (xdrproc_t)tt_xdr_otype_args,
649                          (char *)&args,
650                          (xdrproc_t)tt_xdr_rpc_result,
651                          (char *)&result);
652         if (result.status!=TT_OK) {
653                 return (char *)error_pointer(result.status);
654         } else {
655                 return _tt_strdup(result.str_val);
656         }
657 }
658
659 /* 
660  * Check to see if the given typename is a valid otype by getting its
661  * base class.  If the otype doesn't exist, an error will be returned.
662  */
663 Tt_status
664 _tt_valid_otype(const char *otype)
665 {
666         _Tt_otype_args args;
667         _Tt_rpc_result result;
668         _Tt_c_session *d_session;
669
670         d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
671         
672         args.derived_otid = otype;
673         d_session->call(TT_RPC_OTYPE_BASE,
674                          (xdrproc_t)tt_xdr_otype_args,
675                          (char *)&args,
676                          (xdrproc_t)tt_xdr_rpc_result,
677                          (char *)&result);
678         return result.status;
679 }