3 #include <proto/intuition.h>
5 #include <devices/timer.h>
7 #include <dos/dosextens.h>
8 #include <dos/dostags.h>
10 #include <emul/emulinterface.h>
12 #include <exec/libraries.h>
13 #include <intuition/intuition.h>
14 #include <libraries/miamipanel.h>
15 #include <proto/dos.h>
16 #include <proto/exec.h>
17 #include <proto/miamipanel.h>
18 #include <kern/amiga_dhcp.h>
19 #include <kern/amiga_gui.h>
20 #include <kern/amiga_log.h>
21 #include <sys/synch.h>
25 /* Panel preferences */
26 struct gui_cnf gui_cnf
= {NULL
};
27 LONG gui_show
[6] = {TRUE
, TRUE
, TRUE
, TRUE
, TRUE
, TRUE
};
28 ULONG gui_refresh
= 1;
32 UBYTE GUI_Running
= 0;
34 struct Library
*MiamiPanelBase
= NULL
;
35 struct MsgPort
*gui_msgport
= NULL
;
36 struct timerequest
*gui_timerio
= NULL
;
37 ULONG InternalProc
= 0;
39 extern struct ifnet
*ifnet
;
40 extern struct Task
*AmiTCP_Task
;
41 extern TEXT panels_path
[];
58 void SAVEDS
gui_async_op(ULONG code
, ULONG unit
)
62 DGUI(log(LOG_DEBUG
,"gui_async_op(%lu, %lu) called", code
, unit
);)
63 for (ifp
= ifnet
; ifp
; ifp
= ifp
->if_next
) {
64 if (ifp
->if_index
== unit
) {
65 DGUI(log(LOG_DEBUG
,"Found ifp = 0x%08lx", ifp
);)
66 ifupdown(ifp
, (code
== MIAMIPANELV_CallBack_Code_UnitOffline
));
74 #define getarg(x, y) (y)*x++
75 long callback_function(void)
77 long *m68k_stack
= (ULONG
*)REG_A7
;
78 long code
= m68k_stack
[1];
79 long count
= m68k_stack
[2];
80 ULONG
*args
= (ULONG
*)m68k_stack
[3];
83 long callback(long code
, long count
, va_list args
)
87 struct SysLogPacket
*msg
;
90 case MIAMIPANELV_CallBack_Code_Localize
:
91 nstr
= getarg(args
, ULONG
) - 5000;
92 DGUI(KPrintF("Callback: localize(%lu), result: %s", nstr
, strings
[nstr
]);)
93 /* TODO: full localization */
94 return (long)strings
[nstr
];
95 case MIAMIPANELV_CallBack_Code_UnitOnline
:
96 case MIAMIPANELV_CallBack_Code_UnitOffline
:
97 nstr
= getarg(args
, ULONG
);
99 if (!(CreateNewProcTags(NP_Entry
, (IPTR
)&gui_async_op
,
100 NP_Name
, (IPTR
)"AROSTCP interface control",
102 NP_CodeType
, CODETYPE_PPC
,
106 /* TODO: Implement passing arguments to gui_async_op() */
111 case MIAMIPANELV_CallBack_Code_ShowMainGUI
:
112 /* TODO: Run configuration editor */
114 case MIAMIPANELV_CallBack_Code_HideMainGUI
:
115 /* In fact we don't have main GUI so we have nothing to hide here.
116 However many panels (MUI.MiamiPanel for example) have "Hide"
117 button and in order to make it usable we simply make it doing
118 the same as "Close panel" */
119 case MIAMIPANELV_CallBack_Code_ClosePanel
:
120 if (msg
= (struct SysLogPacket
*)GetLogMsg(&logReplyPort
)) {
121 msg
->Level
= LOG_GUIMSG
| GUICMD_CLOSE
;
122 PutMsg(logPort
, (struct Message
*)msg
);
125 case MIAMIPANELV_CallBack_Code_QuitMiami
:
126 Signal(AmiTCP_Task
, SIGBREAKF_CTRL_C
);
129 DGUI(KPrintF("Bad callback code %ld from panel\n", code
));
135 struct EmulLibEntry callback
=
137 TRAP_LIB
, 0, (void (*)(void)) callback_function
141 TEXT panel_path
[FILENAME_MAX
];
146 DGUI(long PanelVersion
;)
148 char ifname
[IFNAMSIZ
+2];
153 #if defined(__AROS__)
154 D(bug("[AROSTCP](amiga_gui.c) gui_open()\n"));
158 DGUI(KPrintF("GUI is already opened\n");)
161 if (!gui_cnf
.PanelName
) {
162 DGUI(KPrintF("GUI is disabled\n");)
165 gui_timerio
= CreateIORequest(logPort
, sizeof(struct timerequest
));
167 if (!OpenDevice("timer.device", UNIT_VBLANK
, (struct IORequest
*)gui_timerio
, 0)) {
168 // NameFromLock(GetProgramDir(), panel_path, FILENAME_MAX);
169 AddPart(panel_path
,"LIBS:", FILENAME_MAX
);
170 AddPart(panel_path
,gui_cnf
.PanelName
, FILENAME_MAX
);
171 strcat(panel_path
, ".MiamiPanel");
172 DGUI(KPrintF("Opening GUI: %s...\n", panel_path
);)
173 #if defined(__AROS__)
174 D(bug("[AROSTCP](amiga_gui.c) gui_open: Attempting to use '%s'\n", panel_path
));
176 MiamiPanelBase
= OpenLibrary(panel_path
, 0);
177 DGUI(KPrintF("Panel library opened, base = 0x%08lx\n", MiamiPanelBase
);)
178 if (MiamiPanelBase
) {
179 DGUI(PanelVersion
= MiamiPanelGetVersion();)
180 DGUI(KPrintF("Panel API version: %lu\n", PanelVersion
);)
181 MiamiPanelInhibitRefresh(TRUE
);
182 DGUI(KPrintF("Panel inhibited\n");)
186 /* Screen is always default */
187 if (MiamiPanelInit((IPTR
)&callback
, (IPTR
)&callback
, showflags
, gui_cnf
.PanelFont
, NULL
, panelx
, panely
, (IPTR
)&guimask
)) {
188 DGUI(KPrintF("Panel initialized, signals = 0x%08lx\n", guimask
);)
190 for (ifp
= ifnet
; ifp
; ifp
= ifp
->if_next
) {
191 if (!(ifp
->if_flags
& IFF_LOOPBACK
)) {
192 sprintf(ifname
, "%s%d", ifp
->if_name
, ifp
->if_unit
);
193 DGUI(KPrintF("Adding interface %s, index %lu, baud rate %lu\n", ifname
, ifp
->if_index
, ifp
->if_baudrate
);)
194 if (ifp
->if_flags
& IFF_UP
) {
195 ifstate
= MIAMIPANELV_AddInterface_State_Online
;
196 if (ifp
->if_baudrate
> 1000000)
197 sprintf(ifspeed
,"%luM", ifp
->if_baudrate
/ 1000000);
199 sprintf(ifspeed
,"%lu", ifp
->if_baudrate
);
201 ifstate
= MIAMIPANELV_AddInterface_State_Offline
;
204 MiamiPanelAddInterface(ifp
->if_index
, ifname
, ifstate
, ifp
->if_data
.ifi_aros_ontime
.tv_secs
, ifspeed
);
207 DGUI(KPrintF("Opening the panel...\n");)
208 MiamiPanelInhibitRefresh(FALSE
);
209 DGUI(KPrintF("Panel opened\n");)
210 gui_timerio
->tr_node
.io_Command
= TR_ADDREQUEST
;
211 gui_timerio
->tr_time
.tv_secs
= gui_refresh
;
212 gui_timerio
->tr_time
.tv_micro
= 0;
213 SendIO ((struct IORequest
*)gui_timerio
);
216 CloseLibrary(MiamiPanelBase
);
217 MiamiPanelBase
= NULL
;
219 CloseDevice((struct IORequest
*)gui_timerio
);
221 DeleteIORequest((struct IORequest
*)gui_timerio
);
228 #if defined(__AROS__)
229 D(bug("[AROSTCP](amiga_gui.c) gui_close()\n"));
231 DGUI(KPrintF("Closing GUI...\n");)
233 if (MiamiPanelBase
) {
235 DGUI(KPrintF("Cleaning up the panel\n");)
236 AbortIO((struct IORequest
*)gui_timerio
);
237 WaitIO((struct IORequest
*)gui_timerio
);
242 CloseLibrary(MiamiPanelBase
);
243 MiamiPanelBase
= NULL
;
244 DGUI(KPrintF("Panel library closed\n");)
246 CloseDevice((struct IORequest
*)gui_timerio
);
247 DeleteIORequest((struct IORequest
*)gui_timerio
);
254 #if defined(__AROS__)
255 D(bug("[AROSTCP](amiga_gui.c) gui_snapshot()\n"));
260 void gui_process_refresh()
266 unsigned long long q
;
273 #if defined(__AROS__)
274 D(bug("[AROSTCP](amiga_gui.c) gui_process_refresh()\n"));
278 WaitIO ((struct IORequest
*)gui_timerio
);
280 MiamiPanelInterfaceReport(-1, 0, now
.tv_secs
, 0, 0);
281 for (ifp
= ifnet
; ifp
; ifp
= ifp
->if_next
) {
282 if ((ifp
->if_flags
& (IFF_LOOPBACK
| IFF_UP
)) == IFF_UP
) {
283 total
.q
= ifp
->if_ibytes
+ ifp
->if_obytes
;
284 rate
= (total
.q
- ifp
->if_data
.ifi_aros_lasttotal
)/gui_refresh
;
285 ifp
->if_data
.ifi_aros_lasttotal
= total
.q
;
286 MiamiPanelInterfaceReport(ifp
->if_index
, rate
, now
.tv_secs
, total
.l
.hi
, total
.l
.lo
);
289 gui_timerio
->tr_node
.io_Command
= TR_ADDREQUEST
;
290 gui_timerio
->tr_time
.tv_secs
= gui_refresh
;
291 gui_timerio
->tr_time
.tv_micro
= 0;
292 SendIO ((struct IORequest
*)gui_timerio
);
296 void gui_process_msg(struct SysLogPacket
*msg
)
302 #if defined(__AROS__)
303 D(bug("[AROSTCP](amiga_gui.c) gui_process_msg()\n"));
307 switch (msg
->Level
& GUICMD_MASK
) {
308 case GUICMD_SET_INTERFACE_STATE
:
309 ifp
= (struct ifnet
*)msg
->Time
;
310 state
= (long)msg
->Tag
;
311 DGUI(KPrintF("Setting interface state for %s%u: 0x%08lx\n", ifp
->if_name
, ifp
->if_unit
, state
);)
312 MiamiPanelSetInterfaceState(ifp
->if_index
, state
, ifp
->if_data
.ifi_aros_ontime
.tv_secs
);
313 DGUI(KPrintF("Interface state set\n");)
314 if (state
& (MIAMIPANELV_AddInterface_State_Online
| MIAMIPANELV_AddInterface_State_Offline
)) {
315 if (state
== MIAMIPANELV_AddInterface_State_Online
) {
316 if (ifp
->if_baudrate
> 1000000)
317 sprintf(ifspeed
,"%luM", ifp
->if_baudrate
/ 1000000);
319 sprintf(ifspeed
,"%lu", ifp
->if_baudrate
);
322 MiamiPanelSetInterfaceSpeed(ifp
->if_index
, ifspeed
);
330 if ((msg
->Level
& GUICMD_MASK
) == GUICMD_SET_INTERFACE_STATE
) {
331 if (state
& (MIAMIPANELV_AddInterface_State_Online
| MIAMIPANELV_AddInterface_State_GoingOffline
)) {
332 if ((state
== MIAMIPANELV_AddInterface_State_Online
) && (ifp
->if_data
.ifi_aros_usedhcp
))
334 if (state
== MIAMIPANELV_AddInterface_State_GoingOffline
)
340 void gui_set_interface_state(struct ifnet
*ifp
, long state
)
342 struct SysLogPacket
*msg
;
344 #if defined(__AROS__)
345 D(bug("[AROSTCP](amiga_gui.c) gui_set_interface_state()\n"));
349 if (msg
= (struct SysLogPacket
*)GetLogMsg(&logReplyPort
)) {
350 msg
->Level
= LOG_GUIMSG
| GUICMD_SET_INTERFACE_STATE
;
351 msg
->Time
= (IPTR
)ifp
;
352 msg
->Tag
= (STRPTR
)state
;
353 PutMsg(logPort
, (struct Message
*)msg
);
358 void error_request(STRPTR Text
, ...)
360 struct EasyStruct es
= {
361 sizeof(struct EasyStruct
),
368 es
.es_TextFormat
= Text
;
369 AROS_SLOWSTACKFORMAT_PRE(Text
);
370 EasyRequestArgs(NULL
, &es
, NULL
, AROS_SLOWSTACKFORMAT_ARG(Text
));
371 AROS_SLOWSTACKFORMAT_POST(Text
);