Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / lib / mp / mp_session.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 /*%%  $TOG: mp_session.h /main/4 1999/08/30 10:59:15 mgreess $                                                   */
28 /* 
29  * @(#)mp_session.h     1.36 95/01/25
30  * 
31  * Copyright (c) 1990 by Sun Microsystems, Inc.
32  * 
33  * This file contains the implementation of the _Tt_session object which
34  * represents the minimal message-passing domain. The primary
35  * responsibility of the _Tt_session is to advertise its presence in
36  * whatever form is appropriate (ie. as an X atom for X11, in the root
37  * directory of an NSE environment, etc.). When the _Tt_session object is
38  * created as part of a client application it represents mostly a
39  * connection to a _Tt_session object that is part of the message server.
40  * This server instance is responsible for storing session-queued
41  * messages, handling RPC requests to the server, and storing client
42  * properties. When clients will be able to join multiple sessions the
43  * server instance of _Tt_session will also be responsible for
44  * forwarding messages to other sessions (ie. the clients still pass
45  * messages through the same default session (to insure the proper
46  * flowcontrol) but those messages are passed on to their respective
47  * sessions. 
48  */
49 #ifndef MP_SESSION_H
50 #define MP_SESSION_H
51 #include "tt_options.h"
52 #include "util/tt_host_utils.h"
53 #include "mp/mp_auth.h"
54 #include "mp/mp_global.h"
55 #include "mp/mp_mp.h"
56 #include "mp/mp_rpc.h"
57 #include "mp/mp_desktop_utils.h"
58 #include "mp/mp_rpc_client_utils.h"
59 #include "mp/mp_session_utils.h"
60 #include "mp/mp_session_prop_utils.h"
61 #include "mp/mp_message_utils.h"
62 #include "mp/mp_pattern_utils.h"
63 #include "mp/mp_procid_utils.h"
64
65 /* 
66  * string used to advertise a tt session in both the X and
67  * process-tree sessions. Note that in X ICCCM compliance
68  * dictates that the atom name be prefixed by the vendor
69  * string. Since there's no good reason for them to be different,
70  * the same name is used for process-tree sessions.
71  */
72 #define         TT_XATOM_NAME           "_SUN_TT_SESSION"
73 #define         TT_CDE_XATOM_NAME       "TT_SESSION"
74 #define         TT_START_TOKEN          "_SUN_TT_TOKEN"
75 #define         TT_CDE_START_TOKEN      "TT_TOKEN"
76 #define         TT_FILE_HINT            "_SUN_TT_FILE"
77 #define         TT_CDE_FILE_HINT        "TT_FILE"
78 #define         TT_START_SID            "_SUN_TT_SID"
79 #define         TT_CDE_START_SID        "_TT_SID"
80 enum _Tt_env {
81         _TT_ENV_X11,
82         _TT_ENV_PROCESS_TREE,
83         _TT_ENV_LAST
84 };
85
86
87 class _Tt_session : public _Tt_object {
88       public:
89         _Tt_session();
90         virtual ~_Tt_session();
91
92         _Tt_string              address_string();
93         _Tt_string              auth_cookie() {
94                 return _auth.auth_cookie();
95         }
96         _Tt_auth_level          auth_level() {
97                 return _auth.auth_level();
98         }
99         Tt_status               call(int rpc_proc,
100                                      xdrproc_t xdr_arg_fn, char *arg,
101                                      xdrproc_t xdr_res_fn, char *res,
102                                      int timeout = -1, int rebind = 0);
103         _Tt_env                 env();
104         const _Tt_host_ptr      &host() {
105                 return _host;
106         }
107         const _Tt_string        &id() const {
108                 return _id;
109         }
110
111         Tt_status               ping();
112         //void                  print(FILE *fs = stdout) const;
113         int                     rpc_program() {
114                 return _rpc_program;
115         }
116         int                     rpc_version() {
117                 return _rpc_version;
118         }
119         Tt_status               set_auth_level(_Tt_auth_level auth_level) {
120                 return _auth.set_auth_level(auth_level);
121         }
122         void                    set_env(_Tt_env env, _Tt_string arg);
123         _Tt_string              Xid(_Tt_string xdisp);
124         bool_t                  xdr(XDR *xdrs);
125         int                     desktop_event_callback();
126         _Tt_string              displayname();
127         Tt_status               set_id(char *sid = (char *)0);
128         Tt_status               client_session_init();
129         _Tt_string              process_tree_id();
130
131         // Determine if this session is in a list of sessions.
132         int                     has_id(const _Tt_string &id);
133         int                     has_id(const _Tt_string_list_ptr slist_p);
134
135       protected:
136         Tt_status               auto_start_init();
137         Tt_status               client_session_init_byid(_Tt_string sid); 
138         Tt_status               find_advertised_address(_Tt_string &addr);
139         Tt_status               parsed_address(_Tt_string &session_addr);
140
141         //
142         // state variables
143         //
144         _Tt_string                      _address_string;
145         _Tt_auth                        _auth;
146         _Tt_string                      _displayname;
147         _Tt_env                         _env;
148         _Tt_host_ptr                    _host;
149         _Tt_string                      _hostaddr;
150         _Tt_string                      _id;
151         int                             _is_server;
152         int                             _is_dead;
153         pid_t                           _pid;
154         _Tt_session_prop_list_ptr       _properties;
155         _Tt_message_list_ptr            _queued_messages;
156         _Tt_rpc_client_ptr              _rpc_client;
157         int                             _rpc_program;
158         int                             _rpc_version;
159         pid_t                           _server_num;
160         uid_t                           _server_uid;
161         _Tt_string                      _type;
162         _Tt_desktop_ptr                 _desktop;
163 #ifdef OPT_UNIX_SOCKET_RPC
164         int                             _u_sock;
165         char                            *local_socket_name();
166         _Tt_string                      _socket_name;
167 #endif                  /* OPT_UNIX_SOCKET_RPC */
168
169         friend class _Tt_s_mp;
170         friend class _Tt_s_session;
171         friend _Tt_mp::find_session_by_fd(int, _Tt_session_ptr &);
172 };
173
174 _Tt_string _tt_session_address(_Tt_object_ptr &o);
175 #endif                          /*  MP_SESSION_H */