Check if volumes are bootable by checking whether C/Shell is compatible with
[cake.git] / rom / hidd / hiddclass.c
blob6900a89d66fe83d82a9b24a57f1b280d1b8a13f4
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Main class for HIDD.
6 Lang: english
7 */
9 #include <exec/types.h>
10 #include <exec/libraries.h>
11 #include <exec/lists.h>
12 #include <exec/semaphores.h>
13 #include <exec/memory.h>
14 #include <exec/alerts.h>
16 #include <utility/tagitem.h>
17 #include <utility/hooks.h>
18 #include <oop/oop.h>
19 #include <hidd/hidd.h>
21 #include <proto/exec.h>
22 #include <proto/oop.h>
23 #include <proto/utility.h>
25 #include <aros/symbolsets.h>
27 #include "hiddclass_intern.h"
29 #include LC_LIBDEFS_FILE
31 #undef SDEBUG
32 #undef DEBUG
33 #define DEBUG 0
34 #include <aros/debug.h>
36 static const char unknown[] = "--unknown device--";
38 #define IS_HIDD_ATTR(attr, idx) ((idx = attr - HiddAttrBase) < num_Hidd_Attrs)
40 /* Implementation of root HIDD class methods. */
41 VOID HIDDCl__Root__Set(OOP_Class *cl, OOP_Object *o, struct pRoot_Set *msg);
44 /*** HIDD::New() **************************************************************/
46 OOP_Object *HIDDCl__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
48 EnterFunc(bug("HIDD::New(cl=%s)\n", cl->ClassNode.ln_Name));
49 D(bug("DoSuperMethod:%p\n", cl->DoSuperMethod));
50 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
51 if(o)
53 struct HIDDData *hd;
54 struct TagItem *list = msg->attrList;
55 struct pRoot_Set set_msg;
57 hd = OOP_INST_DATA(cl, o);
59 /* Initialise the HIDD class. These fields are publicly described
60 as not being settable at Init time, however it is the only way to
61 get proper abstraction if you ask me. Plus it does reuse code
62 in a nice way.
64 To pass these into the init code I would recommend that your
65 pass in a TagList of your tags, which is linked to the user's
66 tags by a TAG_MORE. This way you will prevent them from setting
67 these values.
70 hd->hd_Type = GetTagData(aHidd_Type, 0, list);
71 hd->hd_SubType = GetTagData(aHidd_SubType, 0, list);
72 hd->hd_Producer = GetTagData(aHidd_Producer, 0, list);
74 hd->hd_Name = (STRPTR)GetTagData(aHidd_Name, (IPTR)unknown, list);
75 hd->hd_HWName = (STRPTR)GetTagData(aHidd_HardwareName,(IPTR)unknown, list);
77 hd->hd_Status = GetTagData(aHidd_Status, vHidd_StatusUnknown, list);
78 hd->hd_Locking = GetTagData(aHidd_Locking, vHidd_LockShared, list);
79 hd->hd_ErrorCode= GetTagData(aHidd_ErrorCode, 0, list);
81 hd->hd_Active = TRUE; /* Set default, GetTagData() comes later */
83 /* Use OM_SET to set the rest */
86 set_msg.attrList = msg->attrList;
87 HIDDCl__Root__Set(cl, o, &set_msg);
90 ReturnPtr("HIDD::New", OOP_Object *, o);
94 /*** HIDD::Set() **************************************************************/
96 VOID HIDDCl__Root__Set(OOP_Class *cl, OOP_Object *o, struct pRoot_Set *msg)
99 struct TagItem *tstate = msg->attrList;
100 struct TagItem *tag;
101 struct HIDDData *hd = OOP_INST_DATA(cl, o);
103 EnterFunc(bug("HIDD::Set(cl=%s)\n", cl->ClassNode.ln_Name));
105 while((tag = NextTagItem((const struct TagItem **)&tstate)))
107 ULONG idx;
109 if (IS_HIDD_ATTR(tag->ti_Tag, idx))
111 switch(idx)
113 case aoHidd_Active:
114 hd->hd_Active = tag->ti_Data;
115 break;
121 ReturnVoid("HIDD::Set");
125 /*** HIDD::Get() **************************************************************/
127 VOID HIDDCl__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
129 struct HIDDData *hd = OOP_INST_DATA(cl, o);
130 ULONG idx;
132 EnterFunc(bug("HIDD::Get(cl=%s)\n", cl->ClassNode.ln_Name));
134 if (IS_HIDD_ATTR(msg->attrID, idx))
136 switch (idx)
138 case aoHidd_Type : *msg->storage = hd->hd_Type; break;
139 case aoHidd_SubType : *msg->storage = hd->hd_SubType; break;
140 case aoHidd_Producer : *msg->storage = hd->hd_Producer; break;
141 case aoHidd_Name : *msg->storage = (IPTR)hd->hd_Name; break;
142 case aoHidd_HardwareName: *msg->storage = (IPTR)hd->hd_HWName; break;
143 case aoHidd_Active : *msg->storage = hd->hd_Active; break;
144 case aoHidd_Status : *msg->storage = hd->hd_Status; break;
145 case aoHidd_ErrorCode : *msg->storage = hd->hd_ErrorCode; break;
146 case aoHidd_Locking : *msg->storage = hd->hd_Locking; break;
147 default : OOP_DoSuperMethod(cl, o, (OOP_Msg) msg); break;
149 } else {
150 OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
154 ReturnVoid("HIDD::Get");
158 #if 0
159 /***********************************
160 ** Unimplemented methods
166 /* switch(msg->MethodID)
168 case OM_NEW:
169 retval = OOP_DoSuperMethodA(cl, o, msg);
170 if(!retval)
171 break;
173 hd = OOP_INST_DATA(cl, retval);
175 if( hd != NULL)
177 struct TagItem *list = ((struct opSet *)msg)->ops_AttrList;
178 hd->hd_Type = GetTagData(aHidd_Type, 0, list);
179 hd->hd_SubType = GetTagData(aHidd_SubType, 0, list);
180 hd->hd_Producer = GetTagData(aHidd_Producer, 0, list);
181 hd->hd_Name = (STRPTR)GetTagData(aHidd_Name, (IPTR)unknown, list);
182 hd->hd_HWName = (STRPTR)GetTagData(aHidd_HardwareName, (IPTR)unknown, list);
183 hd->hd_Active = TRUE;
184 hd->hd_Status = GetTagData(aHidd_Status, HIDDV_StatusUnknown, list);
185 hd->hd_ErrorCode = GetTagData(aHidd_ErrorCode, 0, list);
186 hd->hd_Locking = GetTagData(aHidd_Locking, HIDDV_LockShared, list);
189 case OM_SET:
191 struct TagItem *tstate = ((struct opSet *)msg)->ops_AttrList;
192 struct TagItem *tag;
194 while((tag = NextTagItem(&tstate)))
196 switch(tag->ti_Tag)
198 case aHidd_Active:
199 hd->hd_Active = tag->ti_Data;
200 break;
203 break;
207 case OM_GET:
209 switch(((struct opGet *)msg)->opg_AttrID)
211 case aHidd_Type:
212 *((struct opGet *)msg)->opg_Storage = hd->hd_Type;
213 break;
215 case aHidd_SubType:
216 *((struct opGet *)msg)->opg_Storage = hd->hd_SubType;
217 break;
219 case aHidd_Producer:
220 *((struct opGet *)msg)->opg_Storage = hd->hd_Producer;
221 break;
223 case aHidd_Name:
224 *((struct opGet *)msg)->opg_Storage = (IPTR)hd->hd_Name;
225 break;
227 case aHidd_HardwareName:
228 *((struct opGet *)msg)->opg_Storage = (IPTR)hd->hd_HWName;
229 break;
231 case aHidd_Active:
232 *((struct opGet *)msg)->opg_Storage = hd->hd_Active;
233 break;
235 case aHidd_Status:
236 *((struct opGet *)msg)->opg_Storage = hd->hd_Status;
237 break;
239 case aHidd_ErrorCode:
240 *((struct opGet *)msg)->opg_Storage = hd->hd_ErrorCode;
241 break;
243 case aHidd_Locking:
244 *((struct opGet *)msg)->opg_Storage = hd->hd_Locking;
245 break;
252 /* These are the "hiddclass" methods. */
254 /* These two are invalid, since we don't have anything to get
255 from a class, so the superclass should handle these.
257 This is especially the case since the only place that we can
258 get the information for these methods is from an object, but
259 we don't have any objects if this method is called.
261 /* case HIDDM_Meta_Get:
262 case HIDDM_Meta_MGet:
263 retval = 0;
264 break;
266 /* Yet to determine the semantics of these so we just let
267 them return 0 for now.
269 /* case HIDDM_BeginIO:
270 case HIDDM_AbortIO:
271 retval = 0;
272 break;
274 case HIDDM_LoadConfigPlugin:
275 case HIDDM_Lock:
276 case HIDDM_Unlock:
277 retval = NULL;
278 break;
280 case HIDDM_AddHIDD:
283 Class *hc = ((hmAdd *)msg)->hma_Class;
285 if( (hc->cl_Flags & CLF_INLIST) == 0 )
288 ObtainSemaphore(&((struct HCD *)cl->cl_UserData)->listLock);
289 AddTail(
290 (struct List *)&((struct HCD *)cl->cl_UserData)->hiddList,
291 (struct Node *)hc
293 ReleaseSemaphore(&((struct HCD *)cl->cl_UserData)->listLock);
295 hc->cl_Flags |= CLF_INLIST;
296 retval = TRUE;
298 break;
301 case HIDDM_RemoveHIDD:
303 struct IClass *hc = ((hmAdd *)msg)->hma_Class;
305 if( hc->cl_Flags & CLF_INLIST )
307 ObtainSemaphore(&((struct HCD *)cl->cl_UserData)->listLock);
308 Remove((struct Node *)hc);
309 ReleaseSemaphore(&((struct HCD *)cl->cl_UserData)->listLock);
310 hc->cl_Flags &= ~CLF_INLIST;
314 case OM_DISPOSE:
316 default:
317 retval = OOP_DoSuperMethod(cl, o, msg);
320 return retval;
323 #endif
326 /*************************** Classes *****************************/
328 #undef csd
330 static int init_hiddclass(LIBBASETYPEPTR lh)
332 struct class_static_data *csd;
333 ULONG ok = 0;
335 EnterFunc(bug("HIDD::Init()\n"));
337 /* If you are not running from ROM, don't use Alert() */
339 csd = &lh->hd_csd;
341 NEWLIST(&csd->hiddList);
342 InitSemaphore(&csd->listLock);
344 HiddAttrBase = OOP_ObtainAttrBase(IID_Hidd);
345 if(HiddAttrBase)
347 D(bug("Got HiddAttrBase\n"));
348 ok = 1;
349 } /* if(HiddAttrBase) */
350 else
352 /* If you are not running from ROM, don't use Alert() */
354 Alert(AT_DeadEnd | AN_Unknown | AO_Unknown);
357 ReturnInt("HIDD::Init", ULONG, ok);
361 static int free_hiddclass(LIBBASETYPEPTR lh)
363 struct class_static_data *csd = &lh->hd_csd;
365 EnterFunc(bug("HIDD::Free()\n"));
367 if(csd->hiddAttrBase)
369 OOP_ReleaseAttrBase(IID_Hidd);
370 csd->hiddAttrBase = 0;
373 ReturnInt("HIDD::Free", ULONG, TRUE);
376 ADD2INITLIB(init_hiddclass, 0)
377 ADD2EXPUNGELIB(free_hiddclass, 0)