2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
6 #include "datatypes_intern.h"
7 #include <proto/exec.h>
9 #include <proto/iffparse.h>
10 #include <proto/utility.h>
11 #include <utility/tagitem.h>
13 #include <datatypes/datatypesclass.h>
14 #include <libraries/iffparse.h>
16 #include <aros/debug.h>
18 /*****************************************************************************
22 AROS_LH3(struct DataType
*, ObtainDataTypeA
,
25 AROS_LHA(ULONG
, type
, D0
),
26 AROS_LHA(APTR
, handle
, A0
),
27 AROS_LHA(struct TagItem
*, attrs
, A1
),
30 struct Library
*, DataTypesBase
, 6, DataTypes
)
34 Examine the data pointed to by 'handle'.
38 type -- type of 'handle'
39 handle -- handle to examine (if 'type' is DTST_FILE, 'handle' should be
40 a BPTR lock; if it's DTST_CLIPBOARD, 'handle' should be a
42 attrs -- additional attributes (currently none defined).
46 A pointer to a DataType or NULL if failure. IoErr() gives more information
49 ERROR_NO_FREE_STORE -- Not enough memory available
50 ERROR_OBJECT_NOT_FOUND -- Unable to open the data type object
51 ERROR_NOT_IMPLEMENTED -- Unknown handle type
67 *****************************************************************************/
71 struct CompoundDataType
*cdt
= NULL
;
73 D(bug("datatypes.library/ObtainDataType - sem = %p\n", &(GPB(DataTypesBase
)->dtb_DTList
->dtl_Lock
)));
74 ObtainSemaphoreShared(&(GPB(DataTypesBase
)->dtb_DTList
->dtl_Lock
));
80 struct FileInfoBlock
*fib
;
82 D(bug("datatypes.library/ObtainDataType: SourceType = DTST_FILE\n"));
84 if((fib
= AllocDosObject(DOS_FIB
, TAG_DONE
)) != NULL
)
87 D(bug("datatypes.library/ObtainDataType: alloced DOS_FIB. Now calling ExamineLock\n"));
89 cdt
= ExamineLock((BPTR
)handle
, fib
, DataTypesBase
);
91 D(bug("datatypes.library/ObtainDataType: DTST_FILE. ExamineLock call returned\n"));
93 FreeDosObject(DOS_FIB
, fib
);
99 struct ClipboardHandle
*cbh
;
100 UBYTE CheckArray
[64];
102 D(bug("datatypes.library/ObtainDataType: SourceType = DTST_CLIPBOARD\n"));
104 cbh
= (struct ClipboardHandle
*)((struct IFFHandle
*)handle
)->iff_Stream
;
106 /* cbh->cbh_Req.io_ClipID = 0; NONONONONO!!!! io_ClipID was set up by reads in OpenIFF!! */
107 cbh
->cbh_Req
.io_Error
= 0;
108 cbh
->cbh_Req
.io_Offset
= 0;
109 cbh
->cbh_Req
.io_Command
= CMD_READ
;
110 cbh
->cbh_Req
.io_Data
= CheckArray
;
111 cbh
->cbh_Req
.io_Length
= sizeof(CheckArray
);
113 if(DoIO((struct IORequest
*)&cbh
->cbh_Req
))
115 SetIoErr(ERROR_OBJECT_NOT_FOUND
);
119 cbh
->cbh_Req
.io_Error
= 0;
120 cbh
->cbh_Req
.io_Offset
= 0;
122 if(cbh
->cbh_Req
.io_Actual
< 12)
123 SetIoErr(ERROR_OBJECT_NOT_FOUND
);
126 struct DTHookContext dthc
;
128 dthc
.dthc_SysBase
= (struct Library
*)SysBase
;
129 dthc
.dthc_DOSBase
= (struct Library
*)DOSBase
;
130 dthc
.dthc_IFFParseBase
= IFFParseBase
;
131 dthc
.dthc_UtilityBase
= (struct Library
*)UtilityBase
;
132 dthc
.dthc_Lock
= BNULL
;
133 dthc
.dthc_FIB
= NULL
;
134 dthc
.dthc_FileHandle
= BNULL
;
135 dthc
.dthc_IFF
= (struct IFFHandle
*)handle
;
136 dthc
.dthc_Buffer
= CheckArray
;
137 dthc
.dthc_BufferLength
= cbh
->cbh_Req
.io_Actual
;
139 D(bug("datatypes.library/ObtainDataType: DTST_CLIPBOARD: Calling ExamineData\n"));
141 cdt
= ExamineData(DataTypesBase
,
144 (UWORD
)cbh
->cbh_Req
.io_Actual
,
148 D(bug("datatypes.library/ObtainDataType: DTST_CLIPBOARD: ExamineData call returned\n"));
156 SetIoErr(ERROR_NOT_IMPLEMENTED
);
163 ReleaseSemaphore(&(GPB(DataTypesBase
)->dtb_DTList
->dtl_Lock
));
165 if(IoErr() == ERROR_OBJECT_NOT_FOUND
)
166 SetIoErr(DTERROR_COULDNT_OPEN
);
168 D(bug("datatypes.library/ObtainDataType: Done. Returning %x\n", cdt
));
170 return (struct DataType
*)cdt
;
173 } /* ObtainDataTypeA */