revert between 56095 -> 55830 in arch
[AROS.git] / workbench / tools / SysExplorer / Modules / AHCI / ahciunit_window_cl.c
blob046aecdb71cd1af7fe2812c82829350f44758e2d
1 /*
2 Copyright (C) 2018-2019, The AROS Development Team.
3 $Id$
4 */
6 #include <aros/debug.h>
8 #define MUIMASTER_YES_INLINE_STDARG
10 #include <proto/sysexp.h>
11 #include <proto/storage.h>
13 #include <proto/alib.h>
14 #include <proto/exec.h>
15 #include <proto/muimaster.h>
16 #include <proto/utility.h>
17 #include <proto/intuition.h>
19 #include <exec/memory.h>
20 #include <libraries/mui.h>
21 #include <zune/customclasses.h>
22 #include <mui/NFloattext_mcc.h>
23 #include <utility/tagitem.h>
24 #include <utility/hooks.h>
26 #include <hidd/storage.h>
27 #include <hidd/ahci.h>
29 #include "locale.h"
31 #include "ahci_classes.h"
32 #include "ahci_intern.h"
34 #include <ctype.h>
35 #include <stdio.h>
36 #include <stdlib.h>
38 extern OOP_AttrBase HiddAHCIUnitAB;
39 extern OOP_AttrBase HiddStorageUnitAB;
41 /*** Instance Data **********************************************************/
42 struct AHCIUnitWindow_DATA
44 /* Nothing to add */
47 static const char *const featNames[] =
49 "Write Cache" , "Read Ahead" , "Security Freeze Lock ",
50 NULL
53 static void DecodeBits(char *str, ULONG flags, const char *const *names)
55 unsigned char i, done;
57 for (i = 0, done = 0; *names; names++)
59 if ((IPTR)*names < 32)
61 i = (IPTR)*names;
62 continue;
64 if (flags & (1 << i))
66 strcpy(str, *names);
67 str += strlen(*names);
68 if ((done % 5) == 4)
69 *str++ = '\n';
70 else
71 *str++ = ' ';
72 done++;
74 i++;
77 *str = 0;
80 static Object *AHCIUnitWindow__OM_NEW(Class *cl, Object *self, struct opSet *msg)
82 Object *window, *ahcigroup;
83 OOP_Object *dev = (OOP_Object *)GetTagData(MUIA_PropertyWin_Object, 0, msg->ops_AttrList);
84 char feature_str[256];
85 IPTR val;
87 if (!dev)
88 return NULL;
90 /* AHCI specific attributes ... */
91 OOP_GetAttr(dev, aHidd_AHCIUnit_Features, &val);
92 DecodeBits(feature_str, val, featNames);
94 window = (Object *) DoSuperNewTags
96 cl, self, NULL,
97 Child, (IPTR)(ahcigroup = (ColGroup(2),
98 MUIA_Group_SameSize, TRUE,
99 MUIA_FrameTitle, (IPTR)"AHCI",
100 GroupFrame,
101 MUIA_Background, MUII_GroupBack,
102 Child, (IPTR)Label("Features"),
103 Child, (IPTR)(ScrollgroupObject,
104 TextFrame,
105 MUIA_Background, MUII_TextBack,
106 MUIA_Scrollgroup_Contents, (IPTR)(NFloattextObject,
107 NoFrame,
108 MUIA_Background, MUII_TextBack,
109 MUIA_CycleChain, 1,
110 MUIA_Floattext_Text, (IPTR)feature_str,
111 End),
112 End),
113 End)),
114 TAG_MORE, (IPTR) msg->ops_AttrList,
115 TAG_DONE
117 if (window)
119 IPTR unitdev;
120 OOP_GetAttr(dev, aHidd_StorageUnit_Device, &unitdev);
121 OOP_GetAttr(dev, aHidd_StorageUnit_Number, &val);
122 QueryATAStorageFeatures(ahcigroup, (char *)unitdev, val);
124 return window;
127 /*** Setup ******************************************************************/
128 BOOPSI_DISPATCHER_PROTO(IPTR, AHCIUnitWindow_Dispatcher, cl, self, msg);
129 BOOPSI_DISPATCHER(IPTR, AHCIUnitWindow_Dispatcher, cl, self, msg)
131 switch (msg->MethodID)
133 case OM_NEW:
134 return (IPTR) AHCIUnitWindow__OM_NEW(cl, self, (struct opSet *)msg);
136 default:
137 return DoSuperMethodA(cl, self, msg);
140 return (IPTR) NULL;
142 BOOPSI_DISPATCHER_END
144 int AHCIUnitWindow_Initialize(struct SysexpBase *SysexpBase)
146 struct SysexpAHCIBase *AhciBase = GetBase("AHCI.Module");
147 struct MUI_CustomClass *SUWClass;
149 D(bug("[ahci.sysexp] %s: AhciBase @ %p\n", __func__, AhciBase));
151 if (AhciBase)
153 SUWClass = GetBase("StorageUnitWindow.Class");
154 D(bug("[ahci.sysexp] %s: StorageUnitWindow.Class @ %p\n", __func__, SUWClass));
155 AhciBase->seab_AHCIUnitWindowCLASS = MUI_CreateCustomClass
157 NULL, NULL, SUWClass,
158 sizeof(struct AHCIUnitWindow_DATA), (APTR) AHCIUnitWindow_Dispatcher
160 if (AhciBase->seab_AHCIUnitWindowCLASS)
162 D(bug("[ahci.sysexp] %s: AHCIUnitWindowCLASS @ %p\n", __func__, AhciBase->seab_AHCIUnitWindowCLASS));
163 AhciBase->seab_AHCIUnitWindowCLASS->mcc_Class->cl_UserData = (IPTR)AhciBase;
166 if (!AhciBase || !AhciBase->seab_AHCIUnitWindowCLASS)
168 __showerror
169 ( (char *)
170 "Failed to create `AHCIUnitWindow' custom class.", NULL
173 return 0;
176 return 1;
179 void AHCIUnitWindow_Deinitialize(struct SysexpBase *SysexpBase)
181 struct SysexpAHCIBase *AhciBase = GetBase("AHCI.Module");
182 MUI_DeleteCustomClass(AhciBase->seab_AHCIUnitWindowCLASS);