Link with C++ linker
[oweals/cde.git] / cde / programs / dtpdmd / dispatch.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
24 /******************************************************************************
25  ******************************************************************************
26  **
27  ** File:         dispatch.c
28  ** RCS:          $XConsortium: dispatch.c /main/4 1996/05/28 13:33:53 cde-hp $
29  **
30  ** Description:
31  **
32  ** (c) Copyright 1995, Hewlett-Packard Company, all rights reserved.
33  **
34  ******************************************************************************
35  *****************************************************************************/
36
37 #define DISPATCH_DOT_C
38
39 #include "dtpdmdP.h"
40
41
42 /******************************************************************************
43  *
44  * Dispatch PDM_MANAGER requests
45  *
46  * note: 'rec->pdm_exec_errorcode' is set to 0 (zero) and
47  *       stays that way as long as no errors occur.
48  *       Ultimately it gets set to either and error or
49  *       success code.
50  */
51 void dispatch_mgr( XEvent *report )
52 {
53     XpPdmServiceRec *rec;
54
55
56     /*
57      * Locate or create a client record for this request.
58      */
59     rec = find_rec( report->xselectionrequest.requestor );
60
61     /*
62      * Setup the client record per the request.
63      */
64     mgr_initialize( report, rec );
65
66     if ( rec->pdm_exec_errorcode ) {
67         /*
68          * Reply to requestor, but with bad news that
69          * basic initialization in prep to launch a
70          * pdm could not be completed.
71          */
72         mgr_launch_reply( rec );
73
74         delete_rec( rec );
75         return;
76     }
77
78     /*
79      * Locate the pdm to be launched.
80      */
81     mgr_fetch_pdm( rec );
82
83     if ( rec->pdm_exec_errorcode ) {
84         /*
85          * Reply to requestor, but with bad news that
86          * selection of a pdm to launch could not be
87          * completed.
88          */
89         mgr_launch_reply( rec );
90
91         delete_rec( rec );
92         return;
93     }
94
95     /*
96      * Launch the pdm.
97      */
98     mgr_launch_pdm( rec );
99
100     if ( rec->pdm_exec_errorcode ) {
101         /*
102          * Reply to requestor, but with bad news that
103          * the pdm could not be launched.
104          */
105         mgr_launch_reply( rec );
106
107         delete_rec( rec );
108         return;
109     }
110
111     /*
112      * Set state flags indicating a pdm has been started, but
113      * defer the calling of 'mgr_launch_reply' until after the
114      * pdm itself tells us it is up and running.
115      *
116      * The pdm can generate stderr which we will trap, and can
117      * generate a SIGCLD which we will also trap and take
118      * significant on.
119      */
120     rec->pdm_exec_errorcode = g.pdm_start_ok;
121     rec->do_launch_reply = True;
122     /* sometime later someone else calls mgr_launch_reply( rec ) */
123
124     return;
125 }
126
127 /******************************************************************************
128  *
129  * Dispatch MBOX and MAIL requests
130  */
131 void dispatch_mbox( XEvent *report )
132 {
133     XpPdmServiceRec *rec;
134
135
136     if (report->type == SelectionRequest) {
137         /*
138          * Locate or create a client record for this request.
139          */
140         rec = find_rec( report->xselectionrequest.requestor );
141
142         mbox_initialize( report, rec );
143
144         mbox_build( rec );
145
146         mbox_reply( rec );
147     }
148     else /* if (report->type == ClientMessage) */ {
149         /*
150          * Locate (do not create) a client record for this request.
151          */
152         rec = find_rec_by_mbox_win( report->xclient.window );
153
154         mbox_receive( rec, report );
155     }
156
157     return;
158 }
159
160 /******************************************************************************
161  *
162  * Dispatch TARGETS requests
163  */
164 void dispatch_targets( XEvent *report )
165 {
166     Atom   *target_list;
167     int    target_count;
168     XEvent reply;
169     Status status;
170
171
172     target_count = 4;
173
174     target_list = (Atom *) Xmalloc( sizeof(Atom) * target_count );
175
176     target_list[0] = g.pdm_targets;
177     target_list[1] = g.pdm_start;
178     target_list[2] = g.pdm_timestamp;
179     target_list[3] = g.pdm_mbox;
180
181     /* target_list[4] = g.pdm_multiple; */
182
183     XChangeProperty( report->xselectionrequest.display,
184                      report->xselectionrequest.requestor,
185                      report->xselectionrequest.property,
186                      XA_ATOM,
187                      32,
188                      PropModeReplace,
189                      (unsigned char *) target_list,
190                      target_count );
191
192     reply.xselection.type      = SelectionNotify;
193     reply.xselection.requestor = report->xselectionrequest.requestor;
194     reply.xselection.selection = report->xselectionrequest.selection;
195     reply.xselection.target    = report->xselectionrequest.target;
196     reply.xselection.property  = report->xselectionrequest.property;
197     reply.xselection.time      = report->xselectionrequest.time;
198
199     status = XSendEvent( report->xselectionrequest.display,
200                          report->xselectionrequest.requestor,
201                          True, 0, &reply );
202 }
203
204
205 /******************************************************************************
206  *
207  * Dispatch MULTIPLE requests
208  */
209 void dispatch_multiple( XEvent *report )
210 {
211 }
212
213
214 /******************************************************************************
215  *
216  * Dispatch TIMESTAMP requests
217  */
218 void dispatch_timestamp( XEvent *report )
219 {
220     XEvent reply;
221     Status status;
222
223
224     XChangeProperty( report->xselectionrequest.display,
225                      report->xselectionrequest.requestor,
226                      report->xselectionrequest.property,
227                      XA_INTEGER,
228                      32,
229                      PropModeReplace,
230                      (unsigned char *) &g.time,
231                      1 );
232
233     reply.xselection.type      = SelectionNotify;
234     reply.xselection.requestor = report->xselectionrequest.requestor;
235     reply.xselection.selection = report->xselectionrequest.selection;
236     reply.xselection.target    = report->xselectionrequest.target;
237     reply.xselection.property  = report->xselectionrequest.property;
238     reply.xselection.time      = report->xselectionrequest.time;
239
240     status = XSendEvent( report->xselectionrequest.display,
241                          report->xselectionrequest.requestor,
242                          True, 0, &reply );
243 }
244
245 /******************************************************************************
246  *
247  * Dispatch unsupported selection requests
248  */
249 void dispatch_not_supported( XEvent *report )
250 {
251     XEvent reply;
252     Status status;
253
254     reply.xselection.type      = SelectionNotify;
255     reply.xselection.requestor = report->xselectionrequest.requestor;
256     reply.xselection.selection = report->xselectionrequest.selection;
257     reply.xselection.target    = report->xselectionrequest.target;
258     reply.xselection.property  = None;
259     reply.xselection.time      = report->xselectionrequest.time;
260
261     status = XSendEvent( report->xselectionrequest.display,
262                          report->xselectionrequest.requestor,
263                          True, 0, &reply );
264 }
265