added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / .unmaintained / generic / hidd / serial / SerialClass.c
blobc83862c6447c23eb4766325faa26efe2e75f206e
1 /*
2 Copyright © 1995-2001, 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 <exec/libraries.h>
14 #include <utility/tagitem.h>
15 #include <hidd/serial.h>
18 #include "serial_intern.h"
20 #undef SDEBUG
21 #undef DEBUG
22 #define SDEBUG 0
23 #define DEBUG 0
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);
35 ULONG unitnum = -1;
37 EnterFunc(bug("HIDDSerial::NewSerial()\n"));
39 D(bug("Request for unit number %d\n",msg->unitnum));
41 switch (msg->unitnum) {
42 case 0:
43 case 1:
44 unitnum = msg->unitnum;
45 if (0 != (data->usedunits & (1 << unitnum)))
46 unitnum = -1;
47 break;
49 case -1: /* search for the next available unit */
51 unitnum = 0;
52 while (unitnum < SER_MAX_UNITS)
54 if (0 == (data->usedunits & (1 << unitnum)))
55 break;
56 unitnum++;
59 break;
64 if (unitnum >= 0 && unitnum < SER_MAX_UNITS) {
65 struct TagItem tags[] =
67 #define csd CSD(cl->UserData)
68 {aHidd_SerialUnit_Unit, unitnum},
69 #undef csd
70 {TAG_DONE }
73 su = OOP_NewObject(NULL, CLID_Hidd_SerialUnit, tags);
74 data->SerialUnits[unitnum] = su;
76 ** Mark it as used
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"));
93 if(su) {
94 ULONG unitnum = 0;
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);
101 break;
103 unitnum++;
107 ReturnVoid("HIDDSerial::DisposeUnit");
112 /*************************** Classes *****************************/
114 #undef OOPBase
115 #undef SysBase
116 #undef UtilityBase
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;
127 BOOL ok = FALSE;
129 struct OOP_MethodDescr serialhidd_descr[NUM_SERIALHIDD_METHODS + 1] =
131 {(IPTR (*)())hiddserial_newunit, moHidd_Serial_NewUnit},
132 {(IPTR (*)())hiddserial_disposeunit, moHidd_Serial_DisposeUnit},
133 {NULL, 0UL}
137 struct OOP_InterfaceDescr ifdescr[] =
139 {serialhidd_descr, IID_Hidd_Serial, NUM_SERIALHIDD_METHODS},
140 {NULL, NULL, 0}
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) },
151 {TAG_DONE, 0UL}
155 EnterFunc(bug(" init_serialhiddclass(csd=%p)\n", csd));
157 cl = OOP_NewObject(NULL, CLID_HiddMeta, tags);
158 D(bug("Class=%p\n", cl));
159 if(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"));
171 ok = TRUE;
176 if(ok == FALSE) {
177 free_serialhiddclass(csd);
178 cl = NULL;
179 } else {
180 OOP_AddClass(cl);
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));
191 if(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");