2 Copyright © 1995-2006, 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>
31 /*** HIDDSerial::NewUnit() *********************************************************/
33 OOP_Object
*PCSer__Hidd_Serial__NewUnit(OOP_Class
*cl
, OOP_Object
*obj
, struct pHidd_Serial_NewUnit
*msg
)
35 OOP_Object
*su
= NULL
;
36 struct HIDDSerialData
* data
= OOP_INST_DATA(cl
, obj
);
39 EnterFunc(bug("HIDDSerial::NewSerial()\n"));
41 D(bug("Request for unit number %d\n",msg
->unitnum
));
43 #if (AROS_SERIAL_DEBUG > 0)
44 if (msg
->unitnum
== (AROS_SERIAL_DEBUG
-1))
45 ReturnPtr("HIDDSerial::NewSerial", Object
*, su
);
54 unitnum
= msg
->unitnum
;
55 if (0 != (data
->usedunits
& (1 << unitnum
)))
59 case -1: /* search for the next available unit */
62 while (unitnum
< SER_MAX_UNITS
)
64 if (0 == (data
->usedunits
& (1 << unitnum
)))
74 if (unitnum
>= 0 && unitnum
< SER_MAX_UNITS
)
76 struct TagItem tags
[] =
78 #define csd CSD(cl->UserData)
79 {aHidd_SerialUnit_Unit
, unitnum
},
84 su
= OOP_NewObject(NULL
, CLID_Hidd_SerialUnit
, tags
);
85 data
->SerialUnits
[unitnum
] = su
;
89 data
->usedunits
|= (1 << unitnum
);
92 ReturnPtr("HIDDSerial::NewSerial", Object
*, su
);
96 /*** HIDDSerial::DisposeUnit() ****************************************************/
98 VOID
PCSer__Hidd_Serial__DisposeUnit(OOP_Class
*cl
, OOP_Object
*obj
, struct pHidd_Serial_DisposeUnit
*msg
)
100 OOP_Object
* su
= msg
->unit
;
101 struct HIDDSerialData
* data
= OOP_INST_DATA(cl
, obj
);
102 EnterFunc(bug("HIDDSerial::DisposeUnit()\n"));
107 while (unitnum
< SER_MAX_UNITS
)
109 if (data
->SerialUnits
[unitnum
] == su
)
111 D(bug("Disposing SerialUnit!\n"));
112 OOP_DisposeObject(su
);
113 data
->SerialUnits
[unitnum
] = NULL
;
114 data
->usedunits
&= ~(1 << unitnum
);
121 ReturnVoid("HIDDSerial::DisposeUnit");
126 /*************************** Classes *****************************/
128 #define csd (&(LIBBASE->hdg_csd))
130 static int PCSer_InitAttrs(LIBBASETYPEPTR LIBBASE
)
132 EnterFunc(bug("PCSer_InitAttrs\n"));
134 __IHidd_SerialUnitAB
= OOP_ObtainAttrBase(IID_Hidd_SerialUnit
);
136 ReturnInt("PCSer_InitAttrs", ULONG
, __IHidd_SerialUnitAB
!= 0);
140 static int PCSer_ExpungeAttrs(LIBBASETYPEPTR LIBBASE
)
142 EnterFunc(bug("PCSer_ExpungeAttrs\n"));
144 OOP_ReleaseAttrBase(IID_Hidd_SerialUnit
);
146 ReturnInt("PCSer_ExpungeAttrs", int, TRUE
);
149 ADD2INITLIB(PCSer_InitAttrs
, 0)
150 ADD2EXPUNGELIB(PCSer_ExpungeAttrs
, 0)