Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / commodities / createcxobj.c
blob0ab5186e1d67d7d697b1e9f9dc28d03ea5d57409
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*****************************************************************************
11 NAME */
13 #include "cxintern.h"
14 #include <libraries/commodities.h>
15 #include <proto/exec.h>
16 #include <proto/commodities.h>
17 #include <string.h>
19 #include <aros/debug.h>
21 #define DEBUG_CREATECXOBJ(x) ;
24 VOID BrokerFunc(CxObj *, struct NewBroker *, struct Library *CxBase);
27 AROS_LH3(CxObj *, CreateCxObj,
29 /* SYNOPSIS */
31 AROS_LHA(ULONG, type, D0),
32 AROS_LHA(IPTR, arg1, A0),
33 AROS_LHA(IPTR, arg2, A1),
35 /* LOCATION */
37 struct Library *, CxBase, 5, Commodities)
39 /* FUNCTION
41 Creates a commodity object of type 'type'. This function should never
42 be called directly; instead, use the macros defined in <libraries/
43 commodties.h>. Brokers, however, should be created with the CxBroker()
44 function.
46 INPUTS
48 type - the type of the commodity object to be created. Possible
49 types are defined in <libraries/commodities.h>.
50 arg1 - depends on the value of 'type' above.
51 arg2 - depends on the value of 'type' above.
53 RESULT
55 The commodity object or NULL if it couldn't be created. Not so severe
56 problems in the creation process are recorded in an internal field
57 retrievable with CxObjError(). These errors are defined in <libraries/
58 commodities.h>
60 NOTES
62 This 'CxObj *' that is returned from this function (and from CxBroker())
63 is the reference to your commodity object. It shall be used whenever
64 dealing with your commodity objects (functions operating on commodity
65 objects and so on).
67 EXAMPLE
69 BUGS
71 SEE ALSO
73 CxObjError(), CxBroker(), cx_lib/CxSender(), cx_lib/CxSignal(),
74 cx_lib/CxFilter(), cx_lib/CxTranslate() cx_lib/CxCustom(),
75 cx_lib/CxDebug()
77 INTERNALS
79 HISTORY
81 ******************************************************************************/
84 AROS_LIBFUNC_INIT
86 CxObj *co;
88 DEBUG_CREATECXOBJ(dprintf("CreateCxObj: type %lu Arg1 0x%lx Arg2 0x%lx\n",
89 type, arg1, arg2));
91 if ((co = (CxObj *)AllocCxStructure(CX_OBJECT, type, CxBase)) == NULL)
93 return NULL; /* No memory for object */
96 D(bug("CreateCxObject: Memory for object allocated.\n"));
98 co->co_Node.ln_Type = type;
99 co->co_Flags = COF_ACTIVE;
100 co->co_Error = 0;
102 NEWLIST(&co->co_ObjList);
104 switch (type)
106 case CX_FILTER:
107 SetFilter(co, (STRPTR)arg1);
108 break;
110 case CX_TYPEFILTER:
111 /* Obsolete and undocumented */
112 break;
114 case CX_SEND:
115 co->co_Ext.co_SendExt->sext_MsgPort = (struct MsgPort *)arg1;
116 co->co_Ext.co_SendExt->sext_ID = (ULONG)arg2;
117 break;
119 case CX_SIGNAL:
120 co->co_Ext.co_SignalExt->sixt_Task = (struct Task *)arg1;
121 co->co_Ext.co_SignalExt->sixt_SigBit = (UBYTE)arg2;
122 break;
124 case CX_TRANSLATE:
125 co->co_Ext.co_IE = (struct InputEvent *)arg1;
126 break;
128 case CX_BROKER:
129 BrokerFunc(co, (struct NewBroker *)arg1, CxBase);
130 break;
132 case CX_DEBUG:
133 co->co_Ext.co_DebugID = arg1;
134 break;
136 case CX_CUSTOM:
137 co->co_Ext.co_CustomExt->cext_Action = (APTR)arg1;
138 co->co_Ext.co_CustomExt->cext_ID = arg2;
139 break;
141 default:
142 break;
145 DEBUG_CREATECXOBJ(dprintf("CreateCxObject: Leaving...\n"));
147 return co;
149 AROS_LIBFUNC_EXIT
150 } /* CxBroker */
153 VOID BrokerFunc(CxObj *co, struct NewBroker *nbrok, struct Library *CxBase)
155 strncpy(co->co_Ext.co_BExt->bext_Name, nbrok->nb_Name, CBD_NAMELEN - 1);
156 strncpy(co->co_Ext.co_BExt->bext_Title, nbrok->nb_Title, CBD_TITLELEN - 1);
157 strncpy(co->co_Ext.co_BExt->bext_Descr, nbrok->nb_Descr, CBD_DESCRLEN - 1);
159 co->co_Ext.co_BExt->bext_Task = FindTask(NULL);
161 /* Brokers are created inactive */
162 co->co_Flags &= ~COF_ACTIVE;
163 co->co_Node.ln_Pri = nbrok->nb_Pri;
165 co->co_Ext.co_BExt->bext_MsgPort = nbrok->nb_Port;
167 co->co_Flags |= (UBYTE)nbrok->nb_Flags;