revert between 56095 -> 55830 in arch
[AROS.git] / workbench / network / stacks / AROSTCP / MUI.MiamiPanel / muimiamipanel_commands.c
blob9017daa0032cb2514b4ac3507631f683d5a4142b
1 /*
2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <proto/intuition.h>
8 #include <proto/alib.h>
10 #include <stdarg.h>
12 #include "muimiamipanel_intern.h"
13 #include "muimiamipanel_message.h"
15 ULONG
16 MiamiPanelFun(struct MiamiPanelBase_intern *MiamiPanelBaseIntern, ULONG id, ...)
18 #if defined(__MORPHOS__) || defined(__AROS__)
19 va_list va;
20 #else
21 UBYTE *va;
22 #endif
23 long num;
25 switch (id)
27 case MIAMIPANELV_CallBack_Code_HideMainGUI:
28 case MIAMIPANELV_CallBack_Code_ShowMainGUI:
29 case MIAMIPANELV_CallBack_Code_ClosePanel:
30 case MIAMIPANELV_CallBack_Code_QuitMiami:
31 num = 0;
32 break;
34 case MIAMIPANELV_CallBack_Code_UnitOnline:
35 case MIAMIPANELV_CallBack_Code_UnitOffline:
36 num = 1;
37 break;
39 default:
40 return 0;
43 #if defined(__MORPHOS__) || defined(__AROS__)
44 va_start(va,id);
46 if (*(UWORD *)MiamiPanelBaseIntern->mpb_asynccb >= (UWORD)0xFF00) REG_A7 -= 4;
48 ((ULONG *)REG_A7)[-1] = (ULONG)va->overflow_arg_area;
49 ((ULONG *)REG_A7)[-2] = (ULONG)num;
50 ((ULONG *)REG_A7)[-3] = (ULONG)id;
52 REG_A7 -= 12;
54 MyEmulHandle->EmulCallDirect68k(MiamiPanelBaseIntern->mpb_asynccb);
56 REG_A7 += 12;
57 if (*(UWORD *)MiamiPanelBaseIntern->mpb_asynccb >= (UWORD)0xFF00) REG_A7 += 4;
59 va_end(va);
60 #else
61 va = (UBYTE *)(&id+1);
62 (*MiamiPanelBaseIntern->mpb_asynccb)(id,num,va);
63 #endif
65 return 0;
68 /****************************************************************************/
70 struct sizes
72 LONG id;
73 ULONG size;
76 struct sizes sizes[] =
78 MPV_Msg_Type_Cleanup, sizeof(struct MPS_Msg),
79 MPV_Msg_Type_AddInterface, sizeof(struct MPS_Msg_AddInterface),
80 MPV_Msg_Type_DelInterface, sizeof(struct MPS_Msg_DelInterface),
81 MPV_Msg_Type_SetInterfaceState, sizeof(struct MPS_Msg_SetInterfaceState),
82 MPV_Msg_Type_SetInterfaceSpeed, sizeof(struct MPS_Msg_SetInterfaceSpeed),
83 MPV_Msg_Type_InterfaceReport, sizeof(struct MPS_Msg_InterfaceReport),
84 MPV_Msg_Type_ToFront, sizeof(struct MPS_Msg),
85 MPV_Msg_Type_InhibitRefresh, sizeof(struct MPS_Msg_InhibitRefresh),
86 MPV_Msg_Type_GetCoord, sizeof(struct MPS_Msg_GetCoord),
87 MPV_Msg_Type_Event, sizeof(struct MPS_Msg_Event),
88 MPV_Msg_Type_RefreshName, sizeof(struct MPS_Msg_RefreshName),
91 void DoCommand(struct MiamiPanelBase_intern *MiamiPanelBaseIntern, ULONG id,...)
93 #if defined(__MORPHOS__) || defined(__AROS__)
94 va_list va;
95 #else
96 #if defined(__AROS__)
98 #else
99 ULONG *va;
100 #endif
101 #endif
102 struct MsgPort reply;
103 struct MPS_Msg *msg;
104 ULONG size, istoreply;
105 int sig = 0; // gcc
107 if (id<MPV_Msg_Type_Last) size = sizes[id].size;
108 else return;
110 ObtainSemaphore(&MiamiPanelBaseIntern->mpb_libSem);
112 if (!MiamiPanelBaseIntern->mpb_port)
114 ReleaseSemaphore(&MiamiPanelBaseIntern->mpb_libSem);
115 return;
118 if (AttemptSemaphore(&MiamiPanelBaseIntern->mpb_procSem))
120 ReleaseSemaphore(&MiamiPanelBaseIntern->mpb_procSem);
121 ReleaseSemaphore(&MiamiPanelBaseIntern->mpb_libSem);
122 return;
125 if (!(msg = createMsg(size, MiamiPanelBaseIntern)))
127 // We break the rules here: Cleanup must be got
128 if (id==MPV_Msg_Type_Cleanup)
129 DoMethod(MiamiPanelBaseIntern->mpb_app, MUIM_Application_PushMethod,
130 (ULONG)MiamiPanelBaseIntern->mpb_app,
131 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
133 ReleaseSemaphore(&MiamiPanelBaseIntern->mpb_libSem);
134 return;
137 istoreply = 0;
139 #if defined(__MORPHOS__) || defined(__AROS__)
140 va_start(va,id);
141 #else
142 va = (ULONG *)(&id+1);
143 #endif
145 switch (id)
147 case MPV_Msg_Type_Cleanup:
148 case MPV_Msg_Type_ToFront:
149 break;
151 case MPV_Msg_Type_AddInterface:
153 struct MPS_Msg_AddInterface *m = (struct MPS_Msg_AddInterface *)msg;
155 #if defined(__MORPHOS__) || defined(__AROS__)
156 m->unit = va_arg(va,long);
157 m->name = va_arg(va,UBYTE *);
158 m->state = va_arg(va,long);
159 m->ontime = va_arg(va,long);
160 m->speed = va_arg(va,UBYTE *);
161 #else
162 m->unit = *va++;
163 m->name = (UBYTE *)*va++;
164 m->state = *va++;
165 m->ontime = *va++;
166 m->speed = (UBYTE *)*va;
167 #endif
169 istoreply = 1;
170 break;
173 case MPV_Msg_Type_InterfaceReport:
175 struct MPS_Msg_InterfaceReport *m = (struct MPS_Msg_InterfaceReport *)msg;
177 #if defined(__MORPHOS__) || defined(__AROS__)
178 m->unit = va_arg(va,long);
179 m->rate = va_arg(va,long);
180 m->now = va_arg(va,long);
181 m->total.hi = va_arg(va,ULONG);
182 m->total.lo = va_arg(va,ULONG);
183 #else
184 m->unit = *va++;
185 m->rate = *va++;
186 m->now = *va++;
187 m->total.hi = *va++;
188 m->total.lo = *va;
189 #endif
191 break;
194 case MPV_Msg_Type_DelInterface:
196 struct MPS_Msg_DelInterface *m = (struct MPS_Msg_DelInterface *)msg;
198 #if defined(__MORPHOS__) || defined(__AROS__)
199 m->unit = va_arg(va,long);
200 #else
201 m->unit = *va;
202 #endif
204 break;
207 case MPV_Msg_Type_SetInterfaceState:
209 struct MPS_Msg_SetInterfaceState *m = (struct MPS_Msg_SetInterfaceState *)msg;
211 #if defined(__MORPHOS__) || defined(__AROS__)
212 m->unit = va_arg(va,long);
213 m->state = va_arg(va,long);
214 m->ontime = va_arg(va,long);
215 #else
216 m->unit = *va++;
217 m->state = *va++;
218 m->ontime = *va;
219 #endif
221 break;
224 case MPV_Msg_Type_SetInterfaceSpeed:
226 struct MPS_Msg_SetInterfaceSpeed *m = (struct MPS_Msg_SetInterfaceSpeed *)msg;
228 #if defined(__MORPHOS__) || defined(__AROS__)
229 m->unit = va_arg(va,long);
230 m->speed = va_arg(va,UBYTE *);
231 #else
232 m->unit = *va++;
233 m->speed = (UBYTE *)*va;
234 #endif
236 istoreply = 1;
238 break;
241 case MPV_Msg_Type_RefreshName:
243 struct MPS_Msg_RefreshName *m = (struct MPS_Msg_RefreshName *)msg;
245 #if defined(__MORPHOS__) || defined(__AROS__)
246 m->unit = va_arg(va,long);
247 m->name = va_arg(va,UBYTE *);
248 #else
249 m->unit = *va++;
250 m->name = (UBYTE *)*va;
251 #endif
253 istoreply = 1;
255 break;
258 case MPV_Msg_Type_InhibitRefresh:
260 struct MPS_Msg_InhibitRefresh *m = (struct MPS_Msg_InhibitRefresh *)msg;
262 #if defined(__MORPHOS__) || defined(__AROS__)
263 m->val = va_arg(va,long);
264 #else
265 m->val = *va;
266 #endif
268 break;
272 #if defined(__MORPHOS__) || defined(__AROS__)
273 va_end(va);
274 #endif
276 if (istoreply)
278 if ((sig = AllocSignal(-1))<0)
280 freeMsg(msg, MiamiPanelBaseIntern);
281 ReleaseSemaphore(&MiamiPanelBaseIntern->mpb_libSem);
282 return;
285 INITPORT(&reply, sig);
286 INITMESSAGE(msg, &reply,size);
287 msg->flags |= MPV_Msg_Flags_Reply;
290 msg->type = id;
292 PutMsg(MiamiPanelBaseIntern->mpb_port, (struct Message *)msg);
294 if (istoreply)
296 WaitPort(&reply);
297 freeMsg(msg, MiamiPanelBaseIntern);
298 FreeSignal(sig);
301 ReleaseSemaphore(&MiamiPanelBaseIntern->mpb_libSem);