2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
5 Desc: Main class for HIDD.
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>
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
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
);
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
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
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
;
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
)))
109 if (IS_HIDD_ATTR(tag
->ti_Tag
, idx
))
114 hd
->hd_Active
= tag
->ti_Data
;
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
);
132 EnterFunc(bug("HIDD::Get(cl=%s)\n", cl
->ClassNode
.ln_Name
));
134 if (IS_HIDD_ATTR(msg
->attrID
, 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;
150 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
);
154 ReturnVoid("HIDD::Get");
159 /***********************************
160 ** Unimplemented methods
166 /* switch(msg->MethodID)
169 retval = OOP_DoSuperMethodA(cl, o, msg);
173 hd = OOP_INST_DATA(cl, retval);
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);
191 struct TagItem *tstate = ((struct opSet *)msg)->ops_AttrList;
194 while((tag = NextTagItem(&tstate)))
199 hd->hd_Active = tag->ti_Data;
209 switch(((struct opGet *)msg)->opg_AttrID)
212 *((struct opGet *)msg)->opg_Storage = hd->hd_Type;
216 *((struct opGet *)msg)->opg_Storage = hd->hd_SubType;
220 *((struct opGet *)msg)->opg_Storage = hd->hd_Producer;
224 *((struct opGet *)msg)->opg_Storage = (IPTR)hd->hd_Name;
227 case aHidd_HardwareName:
228 *((struct opGet *)msg)->opg_Storage = (IPTR)hd->hd_HWName;
232 *((struct opGet *)msg)->opg_Storage = hd->hd_Active;
236 *((struct opGet *)msg)->opg_Storage = hd->hd_Status;
239 case aHidd_ErrorCode:
240 *((struct opGet *)msg)->opg_Storage = hd->hd_ErrorCode;
244 *((struct opGet *)msg)->opg_Storage = hd->hd_Locking;
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:
266 /* Yet to determine the semantics of these so we just let
267 them return 0 for now.
269 /* case HIDDM_BeginIO:
274 case HIDDM_LoadConfigPlugin:
283 Class *hc = ((hmAdd *)msg)->hma_Class;
285 if( (hc->cl_Flags & CLF_INLIST) == 0 )
288 ObtainSemaphore(&((struct HCD *)cl->cl_UserData)->listLock);
290 (struct List *)&((struct HCD *)cl->cl_UserData)->hiddList,
293 ReleaseSemaphore(&((struct HCD *)cl->cl_UserData)->listLock);
295 hc->cl_Flags |= CLF_INLIST;
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;
317 retval = OOP_DoSuperMethod(cl, o, msg);
326 /*************************** Classes *****************************/
330 static int init_hiddclass(LIBBASETYPEPTR lh
)
332 struct class_static_data
*csd
;
335 EnterFunc(bug("HIDD::Init()\n"));
337 /* If you are not running from ROM, don't use Alert() */
341 NEWLIST(&csd
->hiddList
);
342 InitSemaphore(&csd
->listLock
);
344 HiddAttrBase
= OOP_ObtainAttrBase(IID_Hidd
);
347 D(bug("Got HiddAttrBase\n"));
349 } /* if(HiddAttrBase) */
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)