2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Serial hidd class implementation.
9 #include <proto/exec.h>
10 #include <proto/utility.h>
11 #include <proto/oop.h>
12 #include <exec/libraries.h>
14 #include <utility/tagitem.h>
15 #include <hidd/serial.h>
18 #include "serial_intern.h"
24 #include <aros/debug.h>
27 /*static AttrBase HiddGCAttrBase;*/
29 /*** HIDDSerial::NewUnit() *********************************************************/
31 static OOP_Object
*hiddserial_newunit(OOP_Class
*cl
, OOP_Object
*obj
, struct pHidd_Serial_NewUnit
*msg
)
33 OOP_Object
*su
= NULL
;
34 struct HIDDSerialData
* data
= OOP_INST_DATA(cl
, obj
);
37 EnterFunc(bug("HIDDSerial::NewSerial()\n"));
39 D(bug("Request for unit number %d\n",msg
->unitnum
));
41 switch (msg
->unitnum
) {
44 unitnum
= msg
->unitnum
;
45 if (0 != (data
->usedunits
& (1 << unitnum
)))
49 case -1: /* search for the next available unit */
52 while (unitnum
< SER_MAX_UNITS
)
54 if (0 == (data
->usedunits
& (1 << unitnum
)))
64 if (unitnum
>= 0 && unitnum
< SER_MAX_UNITS
) {
65 struct TagItem tags
[] =
67 #define csd CSD(cl->UserData)
68 {aHidd_SerialUnit_Unit
, unitnum
},
73 su
= OOP_NewObject(NULL
, CLID_Hidd_SerialUnit
, tags
);
74 data
->SerialUnits
[unitnum
] = su
;
78 data
->usedunits
|= (1 << unitnum
);
81 ReturnPtr("HIDDSerial::NewSerial", Object
*, su
);
85 /*** HIDDSerial::DisposeUnit() ****************************************************/
87 static VOID
hiddserial_disposeunit(OOP_Class
*cl
, OOP_Object
*obj
, struct pHidd_Serial_DisposeUnit
*msg
)
89 OOP_Object
* su
= msg
->unit
;
90 struct HIDDSerialData
* data
= OOP_INST_DATA(cl
, obj
);
91 EnterFunc(bug("HIDDSerial::DisposeUnit()\n"));
95 while (unitnum
< SER_MAX_UNITS
) {
96 if (data
->SerialUnits
[unitnum
] == su
) {
97 D(bug("Disposing SerialUnit!\n"));
98 OOP_DisposeObject(su
);
99 data
->SerialUnits
[unitnum
] = NULL
;
100 data
->usedunits
&= ~(1 << unitnum
);
107 ReturnVoid("HIDDSerial::DisposeUnit");
112 /*************************** Classes *****************************/
118 #define SysBase (csd->sysbase)
119 #define OOPBase (csd->oopbase)
120 #define UtilityBase (csd->utilitybase)
122 #define NUM_SERIALHIDD_METHODS moHidd_Serial_NumMethods
124 OOP_Class
*init_serialhiddclass (struct class_static_data
*csd
)
126 OOP_Class
*cl
= NULL
;
129 struct OOP_MethodDescr serialhidd_descr
[NUM_SERIALHIDD_METHODS
+ 1] =
131 {(IPTR (*)())hiddserial_newunit
, moHidd_Serial_NewUnit
},
132 {(IPTR (*)())hiddserial_disposeunit
, moHidd_Serial_DisposeUnit
},
137 struct OOP_InterfaceDescr ifdescr
[] =
139 {serialhidd_descr
, IID_Hidd_Serial
, NUM_SERIALHIDD_METHODS
},
143 OOP_AttrBase MetaAttrBase
= OOP_GetAttrBase(IID_Meta
);
145 struct TagItem tags
[] =
147 { aMeta_SuperID
, (IPTR
)CLID_Root
},
148 { aMeta_InterfaceDescr
,(IPTR
)ifdescr
},
149 { aMeta_ID
, (IPTR
)CLID_Hidd_Serial
},
150 { aMeta_InstSize
, (IPTR
)sizeof (struct HIDDSerialData
) },
155 EnterFunc(bug(" init_serialhiddclass(csd=%p)\n", csd
));
157 cl
= OOP_NewObject(NULL
, CLID_HiddMeta
, tags
);
158 D(bug("Class=%p\n", cl
));
160 D(bug("SerialHiddClass ok\n"));
161 cl
->UserData
= (APTR
)csd
;
163 csd
->serialunitclass
= init_serialunitclass(csd
);
164 D(bug("serialunitclass: %p\n", csd
->serialunitclass
));
166 if(csd
->serialunitclass
) {
167 __IHidd_SerialUnitAB
= OOP_ObtainAttrBase(IID_Hidd_SerialUnit
);
168 if (NULL
!= __IHidd_SerialUnitAB
) {
169 D(bug("SerialUnitClass ok\n"));
177 free_serialhiddclass(csd
);
183 ReturnPtr("init_serialhiddclass", OOP_Class
*, cl
);
187 void free_serialhiddclass(struct class_static_data
*csd
)
189 EnterFunc(bug("free_serialhiddclass(csd=%p)\n", csd
));
192 OOP_RemoveClass(csd
->serialhiddclass
);
194 free_serialunitclass(csd
);
196 if(csd
->serialhiddclass
) OOP_DisposeObject((OOP_Object
*) csd
->serialhiddclass
);
197 csd
->serialhiddclass
= NULL
;
200 ReturnVoid("free_serialhiddclass");