2 Copyright © 1995-2013, 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/alib.h>
22 #include <proto/exec.h>
23 #include <proto/oop.h>
24 #include <proto/utility.h>
26 #include <aros/symbolsets.h>
30 #include "hiddclass_intern.h"
35 #include <aros/debug.h>
37 /*****************************************************************************************
40 --background_hiddclass--
46 This class is a base class for all object-oriented hardware drivers in AROS. Its
47 main purpose is to provide some information about the driver itself.
49 At the moment this class is just a primary design. Many defined attributes and
50 methods are drafts and reserved. This documentation includes only already
51 estabilished definitions. Do not use any other methods and attributes, their
52 definitions may change at any moment.
54 *****************************************************************************************/
56 static const char unknown
[] = "--unknown device--";
58 #define IS_HIDD_ATTR(attr, idx) ((idx = attr - HiddAttrBase) < num_Hidd_Attrs)
60 /*****************************************************************************************
72 Query hardware manufacturer's numeric ID. This ID may come for example from PCI
73 or Zorro bus configuration data.
76 It is valid to return 0 if your hardware doesn't provide any ID number.
78 Initial value for this attribute is usually supplied by driver class in its
79 moRoot_New implementation.
90 *****************************************************************************************/
92 /*****************************************************************************************
104 Name of the driver instance under which it is known to the OS. This name is
105 provided to OS components that use the driver. For example Intuition's MONITORCLASS
106 expects to find something like "ati_dvi1.monitor", "ati_vga1.monitor" or
107 "pcvga.monitor" here.
109 Note that is is instance name, not class name. Different instances of the driver may
110 need to provide different names for different objects (like in ATI example) in order
111 to let the OS to distinguish between them.
113 The supplied string is internally copied, you may destroy it after object creation.
116 Initial value for this attribute is usually supplied by driver class in its
117 moRoot_New implementation.
128 *****************************************************************************************/
130 /*****************************************************************************************
142 Query hardware name string.
145 Initial value for this attribute is usually supplied by driver class in its
146 moRoot_New implementation.
148 The supplied string is not copied!
159 *****************************************************************************************/
161 /*****************************************************************************************
173 Query hardware's numeric produce ID. This ID may come for example from PCI
174 or Zorro bus configuration data.
177 It is valid to return 0 if your hardware doesn't provide any ID number.
179 Initial value for this attribute is usually supplied by driver class in its
180 moRoot_New implementation.
191 *****************************************************************************************/
193 /*****************************************************************************************
205 Query hardware manufacturer string. NULL is a valid value for this attribute
206 meaning that the information is not specified.
209 Initial value for this attribute is usually supplied by driver class in its
210 moRoot_New implementation.
212 The supplied string is not copied!
223 *****************************************************************************************/
225 /*****************************************************************************************
237 Provide private data for driver creation.
239 This attribute is actually reserved for private use by device drivers.
240 Many driver classes will scan the system and instantiate one or more
241 objects of own class to control the discovered hardware. This attribute
242 is intended to specify details of the actual device. For example for
243 PCI device drivers this can be a pointer to PCI device objects.
246 Be careful and do not use this attribute if you implement a public reusable
247 class which is meant to be subclassed. In this case this attribute can be
248 used by subclasses, and your own use will make a conflict.
250 This attribute actually exists only in order to free the developer from need
251 to create own private interface just for one attribute.
262 *****************************************************************************************/
264 /* Implementation of root HIDD class methods. */
265 VOID
HIDDCl__Root__Set(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Set
*msg
);
267 /*** HIDD::New() **************************************************************/
269 OOP_Object
*HIDDCl__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
271 struct Library
*UtilityBase
= CSD(cl
)->cs_UtilityBase
;
272 EnterFunc(bug("HIDD::New(cl=%s)\n", cl
->ClassNode
.ln_Name
));
273 D(bug("DoSuperMethod:%p\n", cl
->cl_DoSuperMethod
));
274 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
277 struct HIDDData
*hd
= OOP_INST_DATA(cl
, o
);
278 struct TagItem
*list
= msg
->attrList
;
282 hd
->hd_Name
= (STRPTR
)unknown
;
283 hd
->hd_HWName
= (STRPTR
)unknown
;
284 hd
->hd_Status
= vHidd_StatusUnknown
;
285 hd
->hd_Locking
= vHidd_LockShared
;
286 hd
->hd_Active
= TRUE
;
288 * Initialise the HIDD class. These fields are publicly described
289 * as not being settable at Init time, however it is the only way to
290 * get proper abstraction if you ask me. Plus it does reuse code
293 while ((tag
= NextTagItem(&list
)))
297 Hidd_Switch(tag
->ti_Tag
, idx
)
301 hd
->hd_Name
= StrDup((STRPTR
)tag
->ti_Data
);
305 hd
->hd_Type
= tag
->ti_Data
;
309 hd
->hd_SubType
= tag
->ti_Data
;
312 case aoHidd_Producer
:
313 hd
->hd_Producer
= tag
->ti_Data
;
317 hd
->hd_Product
= tag
->ti_Data
;
320 case aoHidd_HardwareName
:
321 hd
->hd_HWName
= (STRPTR
)tag
->ti_Data
;
324 case aoHidd_ProducerName
:
325 hd
->hd_ProducerName
= (STRPTR
)tag
->ti_Data
;
329 hd
->hd_Status
= tag
->ti_Data
;
333 hd
->hd_Locking
= tag
->ti_Data
;
336 case aoHidd_ErrorCode
:
337 hd
->hd_ErrorCode
= tag
->ti_Data
;
341 hd
->hd_Active
= tag
->ti_Data
;
347 ReturnPtr("HIDD::New", OOP_Object
*, o
);
350 /*** HIDD::Dispose() **********************************************************/
351 VOID
HIDDCl__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
353 struct HIDDData
*hd
= OOP_INST_DATA(cl
, o
);
355 if (hd
->hd_Name
!= (STRPTR
)unknown
)
356 FreeVec(hd
->hd_Name
);
358 OOP_DoSuperMethod(cl
, o
, msg
);
361 /*** HIDD::Set() **************************************************************/
363 VOID
HIDDCl__Root__Set(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Set
*msg
)
365 struct Library
*UtilityBase
= CSD(cl
)->cs_UtilityBase
;
366 struct TagItem
*tstate
= msg
->attrList
;
368 struct HIDDData
*hd
= OOP_INST_DATA(cl
, o
);
370 EnterFunc(bug("HIDD::Set(cl=%s)\n", cl
->ClassNode
.ln_Name
));
372 while((tag
= NextTagItem(&tstate
)))
376 if (IS_HIDD_ATTR(tag
->ti_Tag
, idx
))
381 hd
->hd_Active
= tag
->ti_Data
;
388 ReturnVoid("HIDD::Set");
392 /*** HIDD::Get() **************************************************************/
394 VOID
HIDDCl__Root__Get(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Get
*msg
)
396 struct HIDDData
*hd
= OOP_INST_DATA(cl
, o
);
399 EnterFunc(bug("HIDD::Get(cl=%s)\n", cl
->ClassNode
.ln_Name
));
401 if (IS_HIDD_ATTR(msg
->attrID
, idx
))
405 case aoHidd_Type
: *msg
->storage
= hd
->hd_Type
; break;
406 case aoHidd_SubType
: *msg
->storage
= hd
->hd_SubType
; break;
407 case aoHidd_Producer
: *msg
->storage
= hd
->hd_Producer
; break;
408 case aoHidd_Name
: *msg
->storage
= (IPTR
)hd
->hd_Name
; break;
409 case aoHidd_HardwareName
: *msg
->storage
= (IPTR
)hd
->hd_HWName
; break;
410 case aoHidd_Active
: *msg
->storage
= hd
->hd_Active
; break;
411 case aoHidd_Status
: *msg
->storage
= hd
->hd_Status
; break;
412 case aoHidd_ErrorCode
: *msg
->storage
= hd
->hd_ErrorCode
; break;
413 case aoHidd_Locking
: *msg
->storage
= hd
->hd_Locking
; break;
415 *msg
->storage
= hd
->hd_Product
;
417 case aoHidd_ProducerName
:
418 *msg
->storage
= (IPTR
)hd
->hd_ProducerName
;
420 default : OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
); break;
423 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
);
427 ReturnVoid("HIDD::Get");
432 /***********************************
433 ** Unimplemented methods
439 /* switch(msg->MethodID)
442 retval = OOP_DoSuperMethodA(cl, o, msg);
446 hd = OOP_INST_DATA(cl, retval);
450 struct TagItem *list = ((struct opSet *)msg)->ops_AttrList;
451 hd->hd_Type = GetTagData(aHidd_Type, 0, list);
452 hd->hd_SubType = GetTagData(aHidd_SubType, 0, list);
453 hd->hd_Producer = GetTagData(aHidd_Producer, 0, list);
454 hd->hd_Name = (STRPTR)GetTagData(aHidd_Name, (IPTR)unknown, list);
455 hd->hd_HWName = (STRPTR)GetTagData(aHidd_HardwareName, (IPTR)unknown, list);
456 hd->hd_Active = TRUE;
457 hd->hd_Status = GetTagData(aHidd_Status, HIDDV_StatusUnknown, list);
458 hd->hd_ErrorCode = GetTagData(aHidd_ErrorCode, 0, list);
459 hd->hd_Locking = GetTagData(aHidd_Locking, HIDDV_LockShared, list);
464 struct TagItem *tstate = ((struct opSet *)msg)->ops_AttrList;
467 while((tag = NextTagItem(&tstate)))
472 hd->hd_Active = tag->ti_Data;
482 switch(((struct opGet *)msg)->opg_AttrID)
485 *((struct opGet *)msg)->opg_Storage = hd->hd_Type;
489 *((struct opGet *)msg)->opg_Storage = hd->hd_SubType;
493 *((struct opGet *)msg)->opg_Storage = hd->hd_Producer;
497 *((struct opGet *)msg)->opg_Storage = (IPTR)hd->hd_Name;
500 case aHidd_HardwareName:
501 *((struct opGet *)msg)->opg_Storage = (IPTR)hd->hd_HWName;
505 *((struct opGet *)msg)->opg_Storage = hd->hd_Active;
509 *((struct opGet *)msg)->opg_Storage = hd->hd_Status;
512 case aHidd_ErrorCode:
513 *((struct opGet *)msg)->opg_Storage = hd->hd_ErrorCode;
517 *((struct opGet *)msg)->opg_Storage = hd->hd_Locking;
525 /* These are the "hiddclass" methods. */
527 /* These two are invalid, since we don't have anything to get
528 from a class, so the superclass should handle these.
530 This is especially the case since the only place that we can
531 get the information for these methods is from an object, but
532 we don't have any objects if this method is called.
534 /* case HIDDM_Meta_Get:
535 case HIDDM_Meta_MGet:
539 /* Yet to determine the semantics of these so we just let
540 them return 0 for now.
542 /* case HIDDM_BeginIO:
547 case HIDDM_LoadConfigPlugin:
556 Class *hc = ((hmAdd *)msg)->hma_Class;
558 if( (hc->cl_Flags & CLF_INLIST) == 0 )
561 ObtainSemaphore(&((struct HCD *)cl->cl_UserData)->listLock);
563 (struct List *)&((struct HCD *)cl->cl_UserData)->hiddList,
566 ReleaseSemaphore(&((struct HCD *)cl->cl_UserData)->listLock);
568 hc->cl_Flags |= CLF_INLIST;
574 case HIDDM_RemoveHIDD:
576 struct IClass *hc = ((hmAdd *)msg)->hma_Class;
578 if( hc->cl_Flags & CLF_INLIST )
580 ObtainSemaphore(&((struct HCD *)cl->cl_UserData)->listLock);
581 Remove((struct Node *)hc);
582 ReleaseSemaphore(&((struct HCD *)cl->cl_UserData)->listLock);
583 hc->cl_Flags &= ~CLF_INLIST;
590 retval = OOP_DoSuperMethod(cl, o, msg);