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 //%% $XConsortium: mp_self_procid.C /main/3 1995/10/23 12:00:55 rswiston $
29 * @(#)mp_self_procid.cc 1.3 93/07/25
31 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
35 #include "mp_self_procid.h"
37 #include "mp/mp_session.h"
38 #include "mp/mp_message.h"
39 #include "mp/mp_arg.h"
40 #include "mp_s_pattern.h"
41 #include "util/tt_global_env.h"
42 #include "util/tt_host.h"
43 #include "util/tt_port.h"
44 #include "util/tt_trace.h"
46 _Tt_self_procid::_Tt_self_procid()
50 _Tt_self_procid::~_Tt_self_procid()
55 _Tt_self_procid::init()
57 _id = _tt_s_mp->alloc_procid_key();
58 _id = _id.cat(" ").cat(_tt_s_mp->initial_session->address_string());
60 // XXX Probably could just set _version and return at this point
62 // _Tt_s_procid::init() expects _proc_host_ipaddr to be initialized
63 if (! _tt_global->get_local_host(_proc_host)) {
66 _proc_host_ipaddr = _proc_host->addr();
67 return _Tt_s_procid::init();
71 // We just go ahead and process the messages when we signal ourself
72 // that we have new messages.
75 _Tt_self_procid::signal_new_message()
77 // XXX do we need to muck with _TT_PROC_SIGNALLED? I think not.
78 _Tt_next_message_args args;
79 Tt_status status = next_message( args );
80 _Tt_message_list_cursor msgC( args.msgs );
82 while (status == TT_OK) {
84 // In theory, we should at this point do the things
85 // that _Tt_c_procid::next_message() and tt_message_receive()
86 // do: check the queue for file-scoped messages,
87 // and run pattern callbacks. But ttsession declares
88 // no ptypes, and we lack the client-side machinery
89 // for callbacks. So we use our own.
93 _process_msg( *msgC );
95 status = next_message( args );
97 if (status == TT_WRN_NOTFOUND) {
104 _Tt_self_procid::handle_Session_Trace(
105 const _Tt_message_ptr &msg,
109 return ((_Tt_self_procid *)proc)->_handle_Session_Trace( msg );
113 _Tt_self_procid::observe_Saved(
114 const _Tt_message_ptr &msg,
118 return ((_Tt_self_procid *)proc)->_observe_Saved( msg );
122 _Tt_self_procid::s_pattern_create()
124 _Tt_s_pattern *pat = new _Tt_s_pattern();
125 pat->set_id(_tt_s_mp->initial_session->address_string());
130 // This is a very simple callback server-side pattern callback scheme.
131 // It does not do everything that client-side callbacks do.
134 _Tt_self_procid::_process_msg(
135 const _Tt_message_ptr &msg
138 _Tt_string pat_id = msg->pattern_id();
139 if (pat_id.len() == 0) {
142 _Tt_pattern_list_cursor patC( _patterns );
143 while (patC.next()) {
144 if (patC->id() == pat_id) {
145 if (patC->server_callback != 0) {
146 if ( (*(patC->server_callback))( msg, this )
147 == TT_CALLBACK_PROCESSED)
158 _Tt_self_procid::_reply(
159 const _Tt_message_ptr &msg
162 return update_message( msg, TT_HANDLED );
166 _Tt_self_procid::_fail(
167 const _Tt_message_ptr &msg,
171 Tt_status status = msg->set_status( return_status );
172 if (status != TT_OK) {
175 return update_message( msg, TT_FAILED );
179 _Tt_self_procid::update_message(
180 const _Tt_message_ptr &msg,
185 // This is the sort of checking done by
186 // _Tt_c_procid::update_message().
188 if (msg->message_class() != TT_REQUEST) {
191 if (msg->handler().is_null()) {
192 return TT_ERR_NOTHANDLER;
194 _Tt_procid_ptr me = (_Tt_procid *)this;
195 if (! me->is_equal( msg->handler() )) {
196 return TT_ERR_NOTHANDLER;
198 switch (msg->state()) {
201 return(TT_ERR_INVALID);
205 return _Tt_s_procid::update_message( msg, new_state );
209 _Tt_self_procid::_handle_Session_Trace(
210 const _Tt_message_ptr &msg
213 _Tt_arg_list_ptr args = new _Tt_arg_list( *msg->args() );
214 _Tt_arg_list_cursor argC( args );
216 _fail( msg, TT_DESKTOP_EPROTO );
217 return TT_CALLBACK_PROCESSED;
220 Tt_status status = (*argC)->data_string( script );
221 if (status != TT_OK) {
222 _fail( msg, (int)status );
223 return TT_CALLBACK_PROCESSED;
225 if ((script.len() == 0) && (msg->file().len() > 0)) {
226 script = _tt_network_path_to_local_path(msg->file());
229 _fail( msg, TT_DESKTOP_ENOTSUP );
230 return TT_CALLBACK_PROCESSED;
232 if (_tt_putenv( TRACE_SCRIPT, script ) == 0) {
233 _fail( msg, TT_DESKTOP_ENOMEM );
234 return TT_CALLBACK_PROCESSED;
236 tt_trace_control( 0 );
237 tt_trace_control( 1 );
239 return TT_CALLBACK_PROCESSED;
243 _Tt_self_procid::_observe_Saved(
244 const _Tt_message_ptr &
247 if (kill( getpid(), SIGTYPES ) < 0) {
248 _tt_syslog(0, LOG_ERR, "kill(): %m");
250 return TT_CALLBACK_PROCESSED;