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
24 * (c) Copyright 1995 Digital Equipment Corporation.
25 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
27 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
28 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
29 * (c) Copyright 1995 FUJITSU LIMITED.
30 * (c) Copyright 1995 Hitachi.
32 * $XConsortium: broadcast.c /main/4 1996/08/12 18:34:24 barstow $
34 * broadcast - dynamic pattern and procedural notification example
39 #include <sys/param.h>
40 #include <sys/types.h>
45 Widget toplevel, base_frame, controls, slider, gauge, button;
48 void broadcast_value();
49 void receive_tt_message();
50 void create_ui_components();
63 * Initialize Motif and create ui components
65 toplevel = XtVaAppInitialize(&app, "ttsample1", NULL, 0,
66 &argc, argv, NULL, NULL);
67 XtVaSetValues(toplevel, XmNtitle, "ToolTalk Sample 1", 0);
68 create_ui_components();
71 * Initialize ToolTalk, using the initial default session, and
72 * obtain the file descriptor that will become active whenever
73 * ToolTalk has a message for this process.
76 my_procid = tt_open();
80 * Arrange for Motif to call receive_tt_message when the ToolTalk
81 * file descriptor becomes active.
84 XtAppAddInput(app, ttfd, (XtPointer) XtInputReadMask,
85 receive_tt_message, 0);
88 * Create and register a pattern so ToolTalk knows we are interested
89 * in "ttsample1_value" messages within the session we join.
92 pat = tt_pattern_create();
93 tt_pattern_category_set(pat, TT_OBSERVE);
94 tt_pattern_scope_add(pat, TT_SESSION);
95 tt_pattern_op_add(pat, "ttsample1_value");
96 tt_pattern_register(pat);
99 * Join the default session
102 tt_session_join(tt_default_session());
105 * Turn control over to Motif.
107 XtRealizeWidget(toplevel);
111 * Before leaving, allow ToolTalk to clean up.
120 * When the button is pressed, broadcast the new slider value.
123 broadcast_value(widget, client_data, call_data)
125 XtPointer client_data, call_data;
131 * Create and send a ToolTalk notice message
132 * ttsample1_value(in int <new value)
135 XtVaGetValues(slider, XmNvalue, &slider_value, 0);
137 XtVaSetValues(slider, XmNvalue, slider_value, 0);
139 msg_out = tt_pnotice_create(TT_SESSION, "ttsample1_value");
140 tt_message_arg_add(msg_out, TT_IN, "integer", NULL);
141 tt_message_arg_ival_set(msg_out, 0, slider_value);
142 tt_message_send(msg_out);
145 * Since this message is a notice, we don't expect a reply, so
146 * there's no reason to keep a handle for the message.
149 tt_message_destroy(msg_out);
153 * When a ToolTalk message is available, receive it; if it's a
154 * ttsample1_value message, update the gauge with the new value.
157 receive_tt_message(client_data, fid, id)
158 XtPointer client_data;
168 msg_in = tt_message_receive();
171 * It's possible that the file descriptor would become active
172 * even though ToolTalk doesn't really have a message for us.
173 * The returned message handle is NULL in this case.
176 if (msg_in == NULL) return;
180 * Get a storage mark so we can easily free all the data
181 * ToolTalk returns to us.
186 op = tt_message_op(msg_in);
187 err = tt_ptr_error(op);
188 if (err > TT_WRN_LAST) {
189 printf( "tt_message_op(): %s\n", tt_status_message(err));
190 } else if (op != 0) {
191 if (0==strcmp("ttsample1_value", tt_message_op(msg_in))) {
192 tt_message_arg_ival(msg_in, 0, &val_in);
193 XtVaSetValues(gauge, XmNvalue, val_in, 0);
197 tt_message_destroy(msg_in);
203 * Straight Motif calls for creating the ui elements. No
204 * ToolTalk-specific code here.
207 create_ui_components()
210 Widget glabel, slabel;
213 base_frame = XtVaCreateManagedWidget("base_frame",
214 xmMainWindowWidgetClass, toplevel,
218 XtVaGetValues(base_frame, XmNmwmDecorations, &decor, 0);
219 decor &= ~MWM_DECOR_RESIZEH;
220 XtVaSetValues(base_frame, XmNmwmDecorations, &decor, 0);
222 controls = XtVaCreateManagedWidget("controls",
223 xmFormWidgetClass, base_frame, NULL, 0, 0);
225 slabel = XtVaCreateManagedWidget("Send:",
226 xmLabelWidgetClass, controls,
227 XmNleftAttachment, XmATTACH_WIDGET,
228 XmNtopAttachment, XmATTACH_WIDGET,
229 XmNtopWidget, controls,
233 slider = XtVaCreateManagedWidget("slider",
234 xmScaleWidgetClass, controls,
235 XmNleftAttachment, XmATTACH_WIDGET,
236 XmNleftWidget, controls,
238 XmNtopAttachment, XmATTACH_WIDGET,
239 XmNtopWidget, slabel,
244 XmNorientation, XmHORIZONTAL,
248 glabel = XtVaCreateManagedWidget("Received:",
249 xmLabelWidgetClass, controls,
250 XmNleftAttachment, XmATTACH_WIDGET,
251 XmNtopAttachment, XmATTACH_WIDGET,
253 XmNtopWidget, slider,
255 gauge = XtVaCreateManagedWidget("gauge",
256 xmScaleWidgetClass, controls,
257 XmNleftAttachment, XmATTACH_WIDGET,
258 XmNleftWidget, controls,
260 XmNtopAttachment, XmATTACH_WIDGET,
261 XmNtopWidget, glabel,
262 XmNorientation, XmHORIZONTAL,
270 label = XmStringCreateSimple("Broadcast");
271 button = XtVaCreateManagedWidget("button",
272 xmPushButtonWidgetClass, controls,
274 XmNtopAttachment, XmATTACH_WIDGET,
277 XmNleftWidget, controls,
278 XmNleftAttachment, XmATTACH_WIDGET,
280 XmNlabelString, label,
283 XtAddCallback(button, XmNactivateCallback, broadcast_value, 0);