2 Copyright © 1995-2012, 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 <aros/config.h>
13 #include <aros/symbolsets.h>
14 #include <exec/libraries.h>
16 #include <utility/tagitem.h>
17 #include <hidd/serial.h>
20 #include "serial_intern.h"
22 #include LC_LIBDEFS_FILE
28 #include <aros/debug.h>
30 /*** HIDDSerial::NewUnit() *********************************************************/
32 OOP_Object
*PPC4xxSer__Hidd_Serial__NewUnit(OOP_Class
*cl
, OOP_Object
*obj
, struct pHidd_Serial_NewUnit
*msg
)
34 OOP_Object
*su
= NULL
;
35 struct HIDDSerialData
* data
= OOP_INST_DATA(cl
, obj
);
38 EnterFunc(bug("HIDDSerial::NewSerial()\n"));
40 D(bug("Request for unit number %d\n",msg
->unitnum
));
42 #if (AROS_SERIAL_DEBUG > 0)
43 if (msg
->unitnum
== (AROS_SERIAL_DEBUG
-1))
44 ReturnPtr("HIDDSerial::NewSerial", Object
*, su
);
53 unitnum
= msg
->unitnum
;
54 if (0 != (data
->sd_UsedMask
& (1 << unitnum
)))
58 case -1: /* search for the next available unit */
61 while (unitnum
< SER_MAX_UNITS
)
63 if (0 == (data
->sd_UsedMask
& (1 << unitnum
)))
73 if (unitnum
>= 0 && unitnum
< SER_MAX_UNITS
)
75 struct TagItem tags
[] =
77 #define csd CSD(cl->UserData)
78 {aHidd_SerialUnit_Unit
, unitnum
},
83 su
= OOP_NewObject(NULL
, CLID_Hidd_SerialUnit
, tags
);
84 data
->sd_Unit
[unitnum
] = su
;
88 data
->sd_UsedMask
|= (1 << unitnum
);
91 ReturnPtr("HIDDSerial::NewSerial", Object
*, su
);
95 /*** HIDDSerial::DisposeUnit() ****************************************************/
97 VOID
PPC4xxSer__Hidd_Serial__DisposeUnit(OOP_Class
*cl
, OOP_Object
*obj
, struct pHidd_Serial_DisposeUnit
*msg
)
99 OOP_Object
* su
= msg
->unit
;
100 struct HIDDSerialData
* data
= OOP_INST_DATA(cl
, obj
);
101 EnterFunc(bug("HIDDSerial::DisposeUnit()\n"));
106 while (unitnum
< SER_MAX_UNITS
)
108 if (data
->sd_Unit
[unitnum
] == su
)
110 D(bug("Disposing SerialUnit!\n"));
111 OOP_DisposeObject(su
);
112 data
->sd_Unit
[unitnum
] = NULL
;
113 data
->sd_UsedMask
&= ~(1 << unitnum
);
120 ReturnVoid("HIDDSerial::DisposeUnit");
125 /*************************** Classes *****************************/
127 #define csd (&(LIBBASE->hdg_csd))
129 static int PPC4xxSer_InitAttrs(LIBBASETYPEPTR LIBBASE
)
131 EnterFunc(bug("PPC4xxSer_InitAttrs\n"));
133 __IHidd_SerialUnitAB
= OOP_ObtainAttrBase(IID_Hidd_SerialUnit
);
135 ReturnInt("PPC4xxSer_InitAttrs", ULONG
, __IHidd_SerialUnitAB
!= 0);
139 static int PPC4xxSer_ExpungeAttrs(LIBBASETYPEPTR LIBBASE
)
141 EnterFunc(bug("PPC4xxSer_ExpungeAttrs\n"));
143 OOP_ReleaseAttrBase(IID_Hidd_SerialUnit
);
145 ReturnInt("PPC4xxSer_ExpungeAttrs", int, TRUE
);
148 ADD2INITLIB(PPC4xxSer_InitAttrs
, 0)
149 ADD2EXPUNGELIB(PPC4xxSer_ExpungeAttrs
, 0)