revert between 56095 -> 55830 in arch
[AROS.git] / arch / i386-pc / drivers / serial.hidd / SerialClass.c
bloba7bf8d3c584ddb3fa581d70910631663332d83cd
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Serial hidd class implementation.
6 Lang: english
7 */
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
24 #undef SDEBUG
25 #undef DEBUG
26 #define SDEBUG 0
27 #define DEBUG 0
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);
37 ULONG unitnum = -1;
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);
46 #endif
48 switch (msg->unitnum)
50 case 0:
51 case 1:
52 case 2:
53 case 3:
54 unitnum = msg->unitnum;
55 if (0 != (data->usedunits & (1 << unitnum)))
56 unitnum = -1;
57 break;
59 case -1: /* search for the next available unit */
61 unitnum = 0;
62 while (unitnum < SER_MAX_UNITS)
64 if (0 == (data->usedunits & (1 << unitnum)))
65 break;
66 unitnum++;
69 break;
74 if (unitnum >= 0 && unitnum < SER_MAX_UNITS)
76 struct TagItem tags[] =
78 #define csd CSD(cl->UserData)
79 {aHidd_SerialUnit_Unit, unitnum},
80 #undef csd
81 {TAG_DONE }
84 su = OOP_NewObject(NULL, CLID_Hidd_SerialUnit, tags);
85 data->SerialUnits[unitnum] = su;
87 ** Mark it as used
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"));
104 if(su)
106 ULONG unitnum = 0;
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);
115 break;
117 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)