Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / lib / util / tt_global_env.h
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: tt_global_env.h /main/5 1995/12/05 09:25:41 rswiston $                                                       */
28 /*
29  *
30  * tt_global_env.h
31  *
32  * Copyright (c) 1990 by Sun Microsystems, Inc.
33  */
34 #ifndef TT_GLOBAL_ENV_H
35 #define TT_GLOBAL_ENV_H
36 #include "tt_options.h"
37 #include "util/tt_object.h"
38 #include "util/tt_host_utils.h"
39 #include "util/tt_file_system_entry_utils.h"
40 #include "mp/mp_rpc_interface.h"
41 #include "db/tt_db_hostname_redirection_map.h"
42
43 #ifdef OPT_XTHREADS
44 #include <X11/Xthreads.h>
45 #endif
46
47 //
48 // Global object to hang information needed by various server and
49 // client objects such as a cache of known hosts, and the current xdr
50 // version (see comment in tt_xdr_version.h).
51 //
52 class _Tt_global : public _Tt_object {
53       public:
54         _Tt_global();
55         ~_Tt_global();
56         // given a host ip address, return a pointer to a _Tt_host
57         // object which contains more information on the host.
58         int                             find_host(_Tt_string haddr,
59                                                   _Tt_host_ptr &h,
60                                                   int create_ifnot);
61
62         // same idea as find_host except a name is given instead
63         int                             find_host_byname(_Tt_string name,
64                                                          _Tt_host_ptr &h);
65
66         // return in h a pointer to a _Tt_host object representing the
67         // local host. Returns 1 for success and 0 for failure.
68         int                             get_local_host(_Tt_host_ptr &h);
69
70         // the name of the X11 session
71         _Tt_string                      xdisplayname;
72
73         // the name of the program name
74         _Tt_string                      progname;
75
76         // returns maximum number of fds
77         int                             maxfds();
78
79         // flag saying whether messages should be printed out.
80         int                             silent;
81
82         // returns current xdr/rpc version
83         int                             xdr_version();
84         
85         // sets the current xdr version, defaults to the
86         // TT_XDR_VERSION constant.
87         void            set_xdr_version(int v = TT_XDR_VERSION);
88
89         // Utilities for mt-safe-ness
90         void                            grab_mutex();
91         void                            drop_mutex();
92
93         // Test-and-set routine -- returns 1 if threading has not yet
94         // been turned on and this is the first TT API call.
95         // Note the assignment (*NOT* comparison test!) with _multithreaded
96         int                             set_multithreaded() {
97                 return _multithreaded = 1 && event_counter == 1;
98         };
99
100         int                             multithreaded() { return _multithreaded; };
101
102         // the uid of the process
103         uid_t                           uid;
104
105         // the gid of the process
106         gid_t                           gid;
107
108         // DB hostname redirection map
109         _Tt_db_hostname_redirection_map db_hr_map;
110
111         // Internal cache of mnttab entries.
112         _Tt_file_system_entry_list_ptr  fileSystemEntries;
113
114         // Universal _Tt_string buffer so that _Tt_strings don't
115         // do ridiculous initial allocations until the space is
116         // actually needed
117         _Tt_string_buf_ptr              universal_null_string;
118
119         // how many "events", typically API calls in libtt and or
120         // RPC calls in ttsession/dbserver, have been called in
121         // the life of this process.
122         int                             event_counter;
123
124         // next time that garbage collection should be done.
125         time_t                          next_garbage_run;
126
127 #ifdef OPT_XTHREADS
128         xmutex_rec                      global_mutex;
129         xthread_key_t                   threadkey;
130 #endif
131
132       private:
133         static int                      _maxfds;
134         int                             _multithreaded;
135         int                             _xdr_version;
136         _Tt_host_table_ptr              _host_cache;
137         _Tt_host_table_ptr              _host_byname_cache;
138         _Tt_host_ptr                    _local_host;
139 #ifdef OPT_XTHREADS
140         int                             _lock_free;
141         xcondition_rec                  _proceed;
142 #endif
143 };
144 extern  _Tt_global      *_tt_global;
145 #endif                          /* TT_GLOBAL_ENV_H */