Debian Codegraph @

xpa/gtkloop.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2006 Smithsonian Astrophysical Observatory
3 */
4
5 #include <xpap.h>
6
7 #ifdef HAVE_GTK
8
9 #include <gtk/gtk.h>
10 #include <gtk/gtkmain.h>
11
12 /*----------------------------------------------------------------------------
13 *
14 * Private Routines and Data
15 *
16 *----------------------------------------------------------------------------
17 */
18
19 /* record struct for maintining gtk info in gtk select loop */
20 typedef struct xpagtkrec{
21 int fd;
22 void *client_data;
23 int id;
24 } *XPAGtk, XPAGtkRec;
25
26 /*----------------------------------------------------------------------------
27 *
28 * Routine: XPAGtkHandler
29 *
30 * Purpose: handle one request for an xpaset or xpaget
31 *
32 * Return: none
33 *
34 *----------------------------------------------------------------------------
35 */
36 static gboolean XPAGtkHandler(GIOChannel *gio, GIOCondition condition,
37 gpointer data)
38 {
39 XPAGtk xptr = (XPAGtk)data;
40 if( (xptr == NULL) || (xptr->client_data == NULL) )
41 return TRUE;
42 XPAHandler((XPA)xptr->client_data, xptr->fd);
43 return TRUE;
44 }
45
46 /*----------------------------------------------------------------------------
47 *
48 * Routine: XPAGtkEnableOneInput
49 *
50 * Purpose: Enable 1 XPA entry from the Xt event loop
51 *
52 * Results: none
53 *
54 *----------------------------------------------------------------------------
55 */
56 static void XPAGtkEnableOneInput (void *client_data)
57 {
58 XPAGtk xptr = (XPAGtk)client_data;
59
60 if( xptr && !xptr->id ){
61 GIOChannel* ioc = g_io_channel_unix_new(xptr->fd);
62 xptr->id = g_io_add_watch(ioc, (G_IO_IN | G_IO_HUP | G_IO_NVAL),
63 XPAGtkHandler, xptr);
64 }
65 }
66
67 /*----------------------------------------------------------------------------
68 *
69 * Routine: XPAGtkDisableOneInput
70 *
71 * Purpose: Disable 1 XPA entry from the Xt event loop
72 *
73 * Results: none
74 *
75 *----------------------------------------------------------------------------
76 */
77 static void XPAGtkDisableOneInput (void *client_data)
78 {
79 XPAGtk xptr = (XPAGtk)client_data;
80
81 if(xptr && xptr->id){
82 g_source_remove(xptr->id);
83 xptr->id = 0;
84 }
85 }
86
87 /*----------------------------------------------------------------------------
88 *
89 * Routine: XPAGtkAddOneInput
90 *
91 * Purpose: Add 1 XPA entry to the gtk event loop
92 *
93 * Results: none
94 *
95 *----------------------------------------------------------------------------
96 */
97 static void* XPAGtkAddOneInput (void *client_data, int fd)
98 {
99 XPAGtk xptr;
100 if( fd < 0 )
101 return(NULL);
102 xptr = (XPAGtk)calloc(1, sizeof(XPAGtkRec));
103 xptr->fd = fd;
104 xptr->client_data = client_data;
105 XPAGtkEnableOneInput(xptr);
106 return(xptr);
107 }
108
109 /*----------------------------------------------------------------------------
110 *
111 * Routine: XPAGtkDelOneInput
112 *
113 * Purpose: Delete 1 XPA entry from the gtk event loop (called by XPAFree)
114 *
115 * Results: none
116 *
117 *----------------------------------------------------------------------------
118 */
119
120 static void XPAGtkDelOneInput (void *client_data)
121 {
122 XPAGtk xptr = (XPAGtk)client_data;
123 if( xptr == NULL)
124 return;
125 XPAGtkDisableOneInput(xptr);
126 free(xptr);
127 }
128
129 /*----------------------------------------------------------------------------
130 *
131 * Public Routines and Data
132 *
133 *----------------------------------------------------------------------------
134 */
135
136 /*----------------------------------------------------------------------------
137 *
138 * Routine: XPAGtkAddInput
139 *
140 * Purpose: Add XPA entries to the Xt event loop
141 *
142 * Results: number of xpa entried added
143 *
144 *----------------------------------------------------------------------------
145 */
146 int XPAGtkAddInput (XPA xpa)
147 {
148 XPA cur;
149 int got=0;
150
151 /* if a specific xpa was specified, just add it */
152 if( xpa != NULL ){
153 /* remove old one */
154 if( xpa->seldel && xpa->selptr ){
155 (xpa->seldel)(xpa->selptr);
156 }
157 /* add new one */
158 xpa->seldel = XPAGtkDelOneInput;
159 xpa->seladd = XPAGtkAddOneInput;
160 xpa->selon = XPAGtkEnableOneInput;
161 xpa->seloff = XPAGtkDisableOneInput;
162 xpa->selptr = XPAGtkAddOneInput((void *)xpa, xpa->fd);
163 got = 1;
164 }
165 /* otherwise set up all xpa's */
166 else{
167 for(cur=(XPA)XPAListHead(); cur!=NULL; cur=cur->next){
168 /* remove old one */
169 if( cur->seldel && cur->selptr ){
170 (cur->seldel)(cur->selptr);
171 }
172 /* add new one */
173 cur->seldel = XPAGtkDelOneInput;
174 cur->seladd = XPAGtkAddOneInput;
175 cur->selon = XPAGtkEnableOneInput;
176 cur->seloff = XPAGtkDisableOneInput;
177 cur->selptr = XPAGtkAddOneInput((void *)cur, cur->fd);
178 got++;
179 }
180 }
181 return(got);
182 }
183
184 int xpa_gtk = 1;
185
186 #else
187
188 int xpa_gtk = 0;
189
190 #endif