copy more of the Mason prefs icons
[AROS.git] / rom / hidds / hidd / hiddclass.c
blobc5ccdd51cedba949fc905bd7a12a0e709bfb2af3
1 /*
2 Copyright © 1995-2013, 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/alib.h>
22 #include <proto/exec.h>
23 #include <proto/oop.h>
24 #include <proto/utility.h>
26 #include <aros/symbolsets.h>
28 #include <string.h>
30 #include "hiddclass_intern.h"
32 #undef SDEBUG
33 #undef DEBUG
34 #define DEBUG 0
35 #include <aros/debug.h>
37 /*****************************************************************************************
39 NAME
40 --background_hiddclass--
42 LOCATION
43 hiddclass
45 NOTES
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 /*****************************************************************************************
62 NAME
63 aoHidd_Producer
65 SYNOPSIS
66 [I.G], ULONG
68 LOCATION
69 hiddclass
71 FUNCTION
72 Query hardware manufacturer's numeric ID. This ID may come for example from PCI
73 or Zorro bus configuration data.
75 NOTES
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.
81 EXAMPLE
83 BUGS
85 SEE ALSO
86 aoHidd_Product
88 INTERNALS
90 *****************************************************************************************/
92 /*****************************************************************************************
94 NAME
95 aoHidd_Name
97 SYNOPSIS
98 [I.G], STRPTR
100 LOCATION
101 hiddclass
103 FUNCTION
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.
115 NOTES
116 Initial value for this attribute is usually supplied by driver class in its
117 moRoot_New implementation.
119 EXAMPLE
121 BUGS
123 SEE ALSO
124 aoHidd_HardwareName
126 INTERNALS
128 *****************************************************************************************/
130 /*****************************************************************************************
132 NAME
133 aoHidd_HardwareName
135 SYNOPSIS
136 [I.G], STRPTR
138 LOCATION
139 hiddclass
141 FUNCTION
142 Query hardware name string.
144 NOTES
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!
150 EXAMPLE
152 BUGS
154 SEE ALSO
155 aoHidd_Name
157 INTERNALS
159 *****************************************************************************************/
161 /*****************************************************************************************
163 NAME
164 aoHidd_Product
166 SYNOPSIS
167 [I.G], ULONG
169 LOCATION
170 hiddclass
172 FUNCTION
173 Query hardware's numeric produce ID. This ID may come for example from PCI
174 or Zorro bus configuration data.
176 NOTES
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.
182 EXAMPLE
184 BUGS
186 SEE ALSO
187 aoHidd_Producer
189 INTERNALS
191 *****************************************************************************************/
193 /*****************************************************************************************
195 NAME
196 aoHidd_ProducerName
198 SYNOPSIS
199 [I.G], STRPTR
201 LOCATION
202 hiddclass
204 FUNCTION
205 Query hardware manufacturer string. NULL is a valid value for this attribute
206 meaning that the information is not specified.
208 NOTES
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!
214 EXAMPLE
216 BUGS
218 SEE ALSO
219 aoHidd_HardwareName
221 INTERNALS
223 *****************************************************************************************/
225 /*****************************************************************************************
227 NAME
228 aoHidd_DriverData
230 SYNOPSIS
231 [I..], APTR
233 LOCATION
234 hiddclass
236 FUNCTION
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.
245 NOTES
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.
253 EXAMPLE
255 BUGS
257 SEE ALSO
258 aoHidd_Producer
260 INTERNALS
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);
275 if(o)
277 struct HIDDData *hd = OOP_INST_DATA(cl, o);
278 struct TagItem *list = msg->attrList;
279 struct TagItem *tag;
281 /* Set defaults */
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
291 * in a nice way.
293 while ((tag = NextTagItem(&list)))
295 ULONG idx;
297 Hidd_Switch(tag->ti_Tag, idx)
299 case aoHidd_Name:
300 if (tag->ti_Data)
301 hd->hd_Name = StrDup((STRPTR)tag->ti_Data);
302 break;
304 case aoHidd_Type:
305 hd->hd_Type = tag->ti_Data;
306 break;
308 case aoHidd_SubType:
309 hd->hd_SubType = tag->ti_Data;
310 break;
312 case aoHidd_Producer:
313 hd->hd_Producer = tag->ti_Data;
314 break;
316 case aoHidd_Product:
317 hd->hd_Product = tag->ti_Data;
318 break;
320 case aoHidd_HardwareName:
321 hd->hd_HWName = (STRPTR)tag->ti_Data;
322 break;
324 case aoHidd_ProducerName:
325 hd->hd_ProducerName = (STRPTR)tag->ti_Data;
326 break;
328 case aoHidd_Status:
329 hd->hd_Status = tag->ti_Data;
330 break;
332 case aoHidd_Locking:
333 hd->hd_Locking = tag->ti_Data;
334 break;
336 case aoHidd_ErrorCode:
337 hd->hd_ErrorCode = tag->ti_Data;
338 break;
340 case aoHidd_Active:
341 hd->hd_Active = tag->ti_Data;
342 break;
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;
367 struct TagItem *tag;
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)))
374 ULONG idx;
376 if (IS_HIDD_ATTR(tag->ti_Tag, idx))
378 switch(idx)
380 case aoHidd_Active:
381 hd->hd_Active = tag->ti_Data;
382 break;
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);
397 ULONG idx;
399 EnterFunc(bug("HIDD::Get(cl=%s)\n", cl->ClassNode.ln_Name));
401 if (IS_HIDD_ATTR(msg->attrID, idx))
403 switch (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;
414 case aoHidd_Product:
415 *msg->storage = hd->hd_Product;
416 break;
417 case aoHidd_ProducerName:
418 *msg->storage = (IPTR)hd->hd_ProducerName;
419 break;
420 default : OOP_DoSuperMethod(cl, o, (OOP_Msg) msg); break;
422 } else {
423 OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
427 ReturnVoid("HIDD::Get");
431 #if 0
432 /***********************************
433 ** Unimplemented methods
439 /* switch(msg->MethodID)
441 case OM_NEW:
442 retval = OOP_DoSuperMethodA(cl, o, msg);
443 if(!retval)
444 break;
446 hd = OOP_INST_DATA(cl, retval);
448 if( hd != NULL)
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);
462 case OM_SET:
464 struct TagItem *tstate = ((struct opSet *)msg)->ops_AttrList;
465 struct TagItem *tag;
467 while((tag = NextTagItem(&tstate)))
469 switch(tag->ti_Tag)
471 case aHidd_Active:
472 hd->hd_Active = tag->ti_Data;
473 break;
476 break;
480 case OM_GET:
482 switch(((struct opGet *)msg)->opg_AttrID)
484 case aHidd_Type:
485 *((struct opGet *)msg)->opg_Storage = hd->hd_Type;
486 break;
488 case aHidd_SubType:
489 *((struct opGet *)msg)->opg_Storage = hd->hd_SubType;
490 break;
492 case aHidd_Producer:
493 *((struct opGet *)msg)->opg_Storage = hd->hd_Producer;
494 break;
496 case aHidd_Name:
497 *((struct opGet *)msg)->opg_Storage = (IPTR)hd->hd_Name;
498 break;
500 case aHidd_HardwareName:
501 *((struct opGet *)msg)->opg_Storage = (IPTR)hd->hd_HWName;
502 break;
504 case aHidd_Active:
505 *((struct opGet *)msg)->opg_Storage = hd->hd_Active;
506 break;
508 case aHidd_Status:
509 *((struct opGet *)msg)->opg_Storage = hd->hd_Status;
510 break;
512 case aHidd_ErrorCode:
513 *((struct opGet *)msg)->opg_Storage = hd->hd_ErrorCode;
514 break;
516 case aHidd_Locking:
517 *((struct opGet *)msg)->opg_Storage = hd->hd_Locking;
518 break;
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:
536 retval = 0;
537 break;
539 /* Yet to determine the semantics of these so we just let
540 them return 0 for now.
542 /* case HIDDM_BeginIO:
543 case HIDDM_AbortIO:
544 retval = 0;
545 break;
547 case HIDDM_LoadConfigPlugin:
548 case HIDDM_Lock:
549 case HIDDM_Unlock:
550 retval = NULL;
551 break;
553 case HIDDM_AddHIDD:
556 Class *hc = ((hmAdd *)msg)->hma_Class;
558 if( (hc->cl_Flags & CLF_INLIST) == 0 )
561 ObtainSemaphore(&((struct HCD *)cl->cl_UserData)->listLock);
562 AddTail(
563 (struct List *)&((struct HCD *)cl->cl_UserData)->hiddList,
564 (struct Node *)hc
566 ReleaseSemaphore(&((struct HCD *)cl->cl_UserData)->listLock);
568 hc->cl_Flags |= CLF_INLIST;
569 retval = TRUE;
571 break;
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;
587 case OM_DISPOSE:
589 default:
590 retval = OOP_DoSuperMethod(cl, o, msg);
593 return retval;
596 #endif