1
/* $XConsortium: send.c /main/5 1995/07/15 20:42:54 drk $ */
3
* @OPENGROUP_COPYRIGHT@
5
* Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
6
* Copyright (c) 1996, 1997, 1998, 1999, 2000 The Open Group
7
* ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
8
* the full copyright text.
10
* This software is subject to an open license. It may only be
11
* used on, with or for operating systems which are themselves open
12
* source systems. You must contact The Open Group for a license
13
* allowing distribution and sublicensing of this software on, with,
14
* or for operating systems which are not Open Source programs.
16
* See http://www.opengroup.org/openmotif/license for full
17
* details of the license agreement. Any use, reproduction, or
18
* distribution of the program constitutes recipient's acceptance of
21
* EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
22
* PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23
* KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
24
* WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
25
* OR FITNESS FOR A PARTICULAR PURPOSE
27
* EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
28
* NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT,
29
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30
* DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED
31
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33
* ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
34
* EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
35
* POSSIBILITY OF SUCH DAMAGES.
42
#include <Xm/Transfer.h>
43
#include "wsm_proto.h"
46
typedef struct _RequestInfo {
47
WSMReplyCallbackFunc reply_callback; /* The reply callback func */
48
XtPointer reply_data; /* The user data for the callback func */
49
WSMRequestType request_type; /* The kind of request for cross check. */
50
Atom send_atom; /* The atom that we sent this message to. */
53
static void UTMReplyReceived(
54
Widget, XtPointer, XtPointer
57
static void ReplyReceived(
58
Widget, XtPointer, Atom *, Atom *, XtPointer, unsigned long *, int *
61
static UTMPackageRec *_WSMBuildUtmPackage(
62
Atom, int, unsigned long, XtPointer, XtPointer
65
/* Function Name: WSMSendMessage
66
* Description: Sends a message to WSM or WM on the screen
67
* and display specified.
68
* Arguments: w - any widget on this display and screen that
69
* also has destination callback.
70
* Note - This widget MUST have the destination
71
* callback set to UTMDestinationProc that
72
* is defined in utm_send.c.
73
* send_to - either WSMWorkspaceManager or WSMWindowManager
74
* request - the request to send.
75
* reply_callback - The routine to call when the
77
* reply_data - Client data passed to the reply_callback.
78
* Returns: True if an attempt is made to retrieve the selection,
79
* False if an obvious error occured.
81
* NOTE: Reply callback will be called with reply == NULL if unable
86
WSMSendMessage(Widget w, WSMClientType send_to, WSMRequest *request,
87
WSMReplyCallbackFunc reply_callback, XtPointer reply_data)
89
int screen_num = XScreenNumberOfScreen(XtScreen(w));
90
Display *dpy = XtDisplay(w);
91
Atom send_atom = _WSMGetSelectionAtom(dpy, screen_num, send_to);
93
unsigned long msg_len;
94
RequestInfo *req_info;
96
UTMPackageRec *pUtmData;
97
Time time = GetTimestamp(dpy); /* 0 or CurrentTime not allowed. */
99
if (send_atom == None) {
100
fprintf(stderr, "%s: Could not get selection atom to send message\n",
106
* Package human-readable request data into protocol package.
108
msg_data = _WSMPackRequest(dpy, screen_num, request, &msg_len, &error);
109
if (msg_data == NULL) {
110
(*reply_callback)(w, reply_data, NULL, error);
114
req_info = (RequestInfo *) XtMalloc(sizeof(RequestInfo));
115
req_info->reply_callback = reply_callback; /* The reply callback func */
116
req_info->reply_data = reply_data; /* user data for the callback func */
117
req_info->request_type = request->any.type;/*request kind for cross check*/
118
req_info->send_atom = send_atom; /* Atom we sent this message to. */
120
if (!XtIsRealized(w)) {
121
fprintf(stderr, "%s WSMSendMessage must be realized, and is not.\n",
122
"Programmer Error: Widget passed to");
128
_WSMReqTypeToTarget(dpy, request->any.type),
129
(XtPointer) msg_data, msg_len, WSM_PROTO_FMT,
130
UTMReplyReceived, req_info,
136
/************************************************************
140
************************************************************/
143
/* Function Name: UTMReplyReceived
144
* Description: Called after the selection owner's convert proc
146
* Arguments: w - The widget who initiated the request.
152
UTMReplyReceived(Widget w, XtPointer clientData, XtPointer callData)
154
XmSelectionCallbackStruct *scs = (XmSelectionCallbackStruct *) callData;
155
RequestInfo *req_info = (RequestInfo *) clientData;
156
Boolean errorFound = False;
157
Atom type = _WSMReqTypeToTarget(XtDisplay(w), req_info->request_type);
159
/* Let's check some other values just to make sure things are ok. */
160
if (scs->reason != XmCR_OK) {
161
fprintf(stderr, "ERROR: Bad reason value received in UTMReplyReceived.\n");
164
if (scs->type == XT_CONVERT_FAIL) {
165
fprintf(stderr, "ERROR: Convert failure detected in UTMReplyReceived.\n");
168
if (scs->flags != XmSELECTION_DEFAULT) {
169
fprintf(stderr, "ERROR: Bad flags value received in UTMReplyReceived.\n");
176
req_info, /* the request info pointer to fill in. */
178
&type, /* type of request that was made. */
179
scs->value, /* data returned from conversion. */
185
/* Function Name: ReplyReceived
186
* Description: Called when a reply is received from a request
187
* initiated by a WSMSendMessage.
188
* Arguments: w - The widget who initiated the request.
189
* req_info_ptr - pointer to the request info.
190
* selection - The selection that has been converted.
191
* req_type_atom - The type of request that was made.
192
* length - the amount of message data.
193
* format - the format of the reply.
197
ReplyReceived(Widget w, XtPointer req_info_ptr,
198
Atom *selection, Atom *req_type_atom,
199
XtPointer value, unsigned long *length, int *format)
201
RequestInfo *req_info = (RequestInfo *) req_info_ptr;
203
Display *dpy = XtDisplay(w);
205
WSMErrorCode fail_code = WSM_SUCCESS;
208
* First a few checks to make sure everything is as we expect.
211
if (*selection != req_info->send_atom) {
212
fprintf(stderr, "%s, request %d - reply %d\n",
213
"Selection of the reply is not the same as the request",
214
(int) req_info->send_atom, (int) *selection);
216
fail_code = WSM_ERROR_INTERNAL;
218
if (*req_type_atom != _WSMReqTypeToTarget(dpy, req_info->request_type)) {
219
if (*req_type_atom == None) {
220
if (XGetSelectionOwner(dpy, *selection) == None)
222
fail_code = WSM_ERROR_NO_SEL_OWNER;
223
printf("No owner for selection #%d\n", (int)*selection);
226
fail_code = WSM_ERROR_CONVERSION_FAILED;
228
else if (*req_type_atom == XT_CONVERT_FAIL)
229
fail_code = WSM_ERROR_TIMEOUT;
231
fprintf(stderr, "%s, request %s - reply %d:%s\n",
232
"Target of the reply is not the same as the request",
233
_WSMReqTypeToName(req_info->request_type),
234
(int) *req_type_atom,
235
_WSMReqTypeToName(_WSMTargetToReqType(dpy, *req_type_atom)));
237
fail_code = WSM_ERROR_INTERNAL;
240
if (*format != WSM_PROTO_FMT) {
241
fprintf(stderr, "%s, request %d - reply %d\n",
242
"Format of the reply is not the same as the request",
243
(int) WSM_PROTO_FMT, (int) *format);
245
fail_code = WSM_ERROR_INTERNAL;
248
if (fail_code != WSM_SUCCESS) {
250
* Failure, call callback with NULL reply.
253
(*req_info->reply_callback)(w, req_info->reply_data, NULL, fail_code);
256
screen_num = XScreenNumberOfScreen(XtScreen(w));
258
_WSMUnpackReply(dpy, screen_num, value, *length,
259
req_info->request_type, &reply);
261
(*req_info->reply_callback)(w, req_info->reply_data, &reply,fail_code);
266
XtFree((XtPointer) req_info_ptr);
273
* Arguments: target - target to make request against. this is the
274
* same as the request type.
275
* fmt - format of param data (should be WSM_PROTO_FMT).
276
* len - length of param in fmt units.
277
* param - parameter data to send to selection owner.
278
* Returns: The UTM data package.
280
static UTMPackageRec *
288
UTMPackageRec *pUtmData;
290
pUtmData = (UTMPackageRec *) XtMalloc(sizeof(UTMPackageRec));
293
pUtmData->target = target;
294
pUtmData->param = param;
295
pUtmData->closure = closure;