Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / network / stacks / AROSTCP / MUI.MiamiPanel / Classes / muimiamipanel_class_traffic.c
blob751c593ecd6718e2f12de158eb4ddc319190ff63
2 #include <proto/intuition.h>
3 #include <proto/muimaster.h>
4 #include <proto/utility.h>
6 #include <libraries/mui.h>
7 #include <libraries/gadtools.h>
9 #include <stdio.h>
10 #include <string.h>
12 #include "muimiamipanel_intern.h"
13 #include "muimiamipanel_locale.h"
14 #include "muimiamipanel_misc.h"
16 /***********************************************************************/
18 static UBYTE *Kbs, *Mbs;
20 struct MiamiPanelTrafficClass_DATA
22 UQUAD traffic;
23 ULONG flags;
26 enum
28 FLG_Short = 1<<0,
29 FLG_NoGrouping = 1<<1,
32 /***********************************************************************/
34 static struct MiamiPanelBase_intern *MiamiPanelBaseIntern;
36 static ULONG
37 MUIPC_Traffic__OM_NEW(struct IClass *CLASS,Object *self,struct opSet *message)
39 register struct TagItem *attrs = message->ops_AttrList;
41 if (self = (Object *)DoSuperNewTags(CLASS, self, NULL, MUIA_Text_Contents, "0", TAG_MORE, attrs))
43 message->MethodID = OM_SET;
44 DoMethodA(self,(Msg)message);
45 message->MethodID = OM_NEW;
48 return (ULONG)self;
51 /***********************************************************************/
53 static ULONG
54 MUIPC_Traffic__OM_SET(struct IClass *CLASS,Object *self,struct opSet *message)
56 register struct MiamiPanelTrafficClass_DATA *data = INST_DATA(CLASS,self);
57 register struct TagItem *tag;
58 struct TagItem *tstate;
59 register ULONG redraw;
61 for (redraw = FALSE, tstate = message->ops_AttrList; tag = NextTagItem(&tstate); )
63 register ULONG tidata = tag->ti_Data;
65 switch(tag->ti_Tag)
67 case MPA_Prefs:
68 if (!BOOLSAME(PREFS(tidata)->flags & MPV_Flags_TrafficShort,data->flags & FLG_Short) ||
69 !BOOLSAME(PREFS(tidata)->flags & MPV_Flags_TrafficNoGrouping,data->flags & FLG_NoGrouping))
71 if (PREFS(tidata)->flags & MPV_Flags_TrafficShort) data->flags |= FLG_Short;
72 else data->flags &= ~FLG_Short;
74 if (PREFS(tidata)->flags & MPV_Flags_TrafficNoGrouping) data->flags |= FLG_NoGrouping;
75 else data->flags &= ~FLG_NoGrouping;
77 redraw = TRUE;
79 break;
81 case MPA_Value:
83 bigint *bi = (bigint *)tidata;
84 UQUAD traffic;
86 traffic = ((UQUAD)bi->hi << 32) | bi->lo;
88 if (data->traffic!=traffic)
90 data->traffic = traffic;
91 redraw = TRUE;
97 if (redraw)
99 UBYTE cont[64];
100 UQUAD tot = data->traffic;
102 if (data->flags & FLG_Short)
104 UBYTE *dp = MiamiPanelBaseIntern->mpb_decPoint;
106 if (tot>>32) /* big int */
108 UBYTE buf1[64], buf2[64];
109 UQUAD q, r, qd, rd;
111 q = tot/1000000ULL;
112 r = tot%1000000ULL;
113 sprintf(buf1,"%Ld",q);
114 if (!(data->flags & FLG_NoGrouping)) grouping(buf1, MiamiPanelBaseIntern);
116 qd = r/1000ULL;
117 rd = r%1000ULL;
118 sprintf(buf1,"%Ld",qd);
120 sprintf(cont,"%s%s%3.3s %s",buf1,dp,buf2,Mbs);
122 else /* small int */
124 UBYTE buf[32];
125 ULONG q, r;
127 if (tot>=1000000) /* Mb */
129 q = tot/1000000;
130 r = tot%1000000;
131 sprintf(buf, "%u", q);
132 r = r/1000;
133 if (!(data->flags & FLG_NoGrouping)) grouping(buf, MiamiPanelBaseIntern);
134 sprintf(cont,"%s%s%3.3lu %s",buf,dp,r,Mbs);
136 else /* Kb */
138 q = tot/1000;
139 r = tot%1000;
140 sprintf(buf, "%u", q);
141 if (!(data->flags & FLG_NoGrouping)) grouping(buf, MiamiPanelBaseIntern);
142 sprintf(cont,"%s%s%1.1lu %s",buf,dp,(r<100) ? 0 : r,Kbs);
146 else
148 sprintf(cont,"%Ld",tot);
150 if (!(data->flags & FLG_NoGrouping)) grouping(cont, MiamiPanelBaseIntern);
153 SetSuperAttrs(CLASS, self, MUIA_Text_Contents, cont, TAG_DONE);
156 return DoSuperMethodA(CLASS,self,(Msg)message);
159 /***********************************************************************/
161 BOOPSI_DISPATCHER(IPTR, MUIPC_Traffic_Dispatcher, CLASS, self, message)
163 switch (message->MethodID)
165 case OM_SET: return MUIPC_Traffic__OM_SET(CLASS,self,(APTR)message);
166 case OM_NEW: return MUIPC_Traffic__OM_NEW(CLASS,self,(APTR)message);
167 default: return DoSuperMethodA(CLASS,self,message);
169 return 0;
171 BOOPSI_DISPATCHER_END
173 /***********************************************************************/
175 ULONG
176 MUIPC_Traffic_ClassInit(struct MiamiPanelBase_intern *MiamiPanelBase)
178 MiamiPanelBaseIntern = MiamiPanelBase;
179 if (MiamiPanelBaseIntern->mpb_trafficClass = MUI_CreateCustomClass(NULL, MUIC_Text, NULL, sizeof(struct MiamiPanelTrafficClass_DATA), MUIPC_Traffic_Dispatcher))
181 Kbs = __(MSG_Traffic_KB);
182 Mbs = __(MSG_Traffic_MB);
184 return TRUE;
187 return FALSE;
190 /***********************************************************************/