xref: /haiku/src/add-ons/media/media-add-ons/AbstractFileInterfaceAddOn.cpp (revision 5412911f7f8ca41340b0f5cb928ed9726322ab44)
1 // AbstractFileInterfaceAddOn.cpp
2 //
3 // Andrew Bachmann, 2002
4 //
5 // AbstractFileInterfaceAddOn is an add-on
6 // that can make instances of AbstractFileInterfaceNode
7 //
8 // AbstractFileInterfaceNode handles a file and a multistream
9 
10 
11 #include <MediaDefs.h>
12 #include <MediaAddOn.h>
13 #include <Errors.h>
14 #include <Node.h>
15 #include <Mime.h>
16 #include <StorageDefs.h>
17 
18 #include "AbstractFileInterfaceNode.h"
19 #include "AbstractFileInterfaceAddOn.h"
20 
21 #include <limits.h>
22 #include <stdio.h>
23 #include <string.h>
24 
25 // instantiation function
26 extern "C" _EXPORT BMediaAddOn * make_media_addon(image_id image);
27 // {
28 //	return new AbstractFileInterfaceAddOn(image);
29 // }
30 
31 // -------------------------------------------------------- //
32 // ctor/dtor
33 // -------------------------------------------------------- //
34 
35 AbstractFileInterfaceAddOn::~AbstractFileInterfaceAddOn()
36 {
37 }
38 
39 AbstractFileInterfaceAddOn::AbstractFileInterfaceAddOn(image_id image) :
40 	BMediaAddOn(image)
41 {
42 	fprintf(stderr,"AbstractFileInterfaceAddOn::AbstractFileInterfaceAddOn\n");
43 	refCount = 0;
44 }
45 
46 // -------------------------------------------------------- //
47 // BMediaAddOn impl
48 // -------------------------------------------------------- //
49 
50 status_t AbstractFileInterfaceAddOn::InitCheck(
51 	const char ** out_failure_text)
52 {
53 	fprintf(stderr,"AbstractFileInterfaceAddOn::InitCheck\n");
54 	return B_OK;
55 }
56 
57 int32 AbstractFileInterfaceAddOn::CountFlavors()
58 {
59 	fprintf(stderr,"AbstractFileInterfaceAddOn::CountFlavors\n");
60 	return 1;
61 }
62 
63 status_t AbstractFileInterfaceAddOn::GetFlavorAt(
64 	int32 n,
65 	const flavor_info ** out_info)
66 {
67 	fprintf(stderr,"AbstractFileInterfaceAddOn::GetFlavorAt\n");
68 	if (out_info == 0) {
69 		fprintf(stderr,"<- B_BAD_VALUE\n");
70 		return B_BAD_VALUE; // we refuse to crash because you were stupid
71 	}
72 	if (n != 0) {
73 		fprintf(stderr,"<- B_BAD_INDEX\n");
74 		return B_BAD_INDEX;
75 	}
76 	flavor_info * infos = new flavor_info[1];
77 	AbstractFileInterfaceNode::GetFlavor(&infos[0],n);
78 	(*out_info) = infos;
79 	return B_OK;
80 }
81 
82 status_t AbstractFileInterfaceAddOn::GetConfigurationFor(
83 				BMediaNode * your_node,
84 				BMessage * into_message)
85 {
86 	fprintf(stderr,"AbstractFileInterfaceAddOn::GetConfigurationFor\n");
87 	if (into_message == 0) {
88 		fprintf(stderr,"<- B_BAD_VALUE\n");
89 		return B_BAD_VALUE; // we refuse to crash because you were stupid
90 	}
91 	AbstractFileInterfaceNode * node
92 		= dynamic_cast<AbstractFileInterfaceNode*>(your_node);
93 	if (node == 0) {
94 		fprintf(stderr,"<- B_BAD_TYPE\n");
95 		return B_BAD_TYPE;
96 	}
97 	return node->GetConfigurationFor(into_message);
98 }
99 
100 bool AbstractFileInterfaceAddOn::WantsAutoStart()
101 {
102 	fprintf(stderr,"AbstractFileInterfaceAddOn::WantsAutoStart\n");
103 	return false;
104 }
105 
106 status_t AbstractFileInterfaceAddOn::AutoStart(
107 				int in_count,
108 				BMediaNode ** out_node,
109 				int32 * out_internal_id,
110 				bool * out_has_more)
111 {
112 	fprintf(stderr,"AbstractFileInterfaceAddOn::AutoStart\n");
113 	return B_OK;
114 }
115 
116 // -------------------------------------------------------- //
117 // BMediaAddOn impl for B_FILE_INTERFACE nodes
118 // -------------------------------------------------------- //
119 
120 status_t AbstractFileInterfaceAddOn::SniffRef(
121 				const entry_ref & file,
122 				BMimeType * io_mime_type,
123 				float * out_quality,
124 				int32 * out_internal_id)
125 {
126 	fprintf(stderr,"AbstractFileInterfaceAddOn::SniffRef\n");
127 	if ((io_mime_type == 0) || (out_quality == 0) || (out_internal_id == 0)) {
128 		fprintf(stderr,"<- B_BAD_VALUE\n");
129 		return B_BAD_VALUE; // we refuse to crash because you were stupid
130 	}
131 	*out_internal_id = 0; // only one flavor
132 	char mime_string[B_MIME_TYPE_LENGTH+1];
133 	status_t status =  AbstractFileInterfaceNode::StaticSniffRef(file,mime_string,out_quality);
134 	io_mime_type->SetTo(mime_string);
135 	return status;
136 }
137 
138 // even though I implemented SniffTypeKind below and this shouldn't get called,
139 // I am going to implement it anyway.  I'll use it later anyhow.
140 status_t AbstractFileInterfaceAddOn::SniffType(
141 				const BMimeType & type,
142 				float * out_quality,
143 				int32 * out_internal_id)
144 {
145 	fprintf(stderr,"AbstractFileInterfaceAddOn::SniffType\n");
146 	if ((out_quality == 0) || (out_internal_id == 0)) {
147 		fprintf(stderr,"<- B_BAD_VALUE\n");
148 		return B_BAD_VALUE; // we refuse to crash because you were stupid
149 	}
150 	*out_quality = 1.0;
151 	*out_internal_id = 0;
152 	return B_OK;
153 }
154 
155 // This function treats null pointers slightly differently than the others.
156 // This is because a program could reasonably call this function with just
157 // about any junk, get the out_read_items or out_write_items and then use
158 // that to create an array of sufficient size to hold the result, and then
159 // call us again.  So we won't punish them if they supply us with null
160 // pointers the first time around.
161 status_t AbstractFileInterfaceAddOn::GetFileFormatList(
162 				int32 flavor_id,
163 				media_file_format * out_writable_formats,
164 				int32 in_write_items,
165 				int32 * out_write_items,
166 				media_file_format * out_readable_formats,
167 				int32 in_read_items,
168 				int32 * out_read_items,
169 				void * _reserved)
170 {
171 	fprintf(stderr,"AbstractFileInterfaceAddOn::GetFileFormatList\n");
172 	if (flavor_id != 0) {
173 		// this is a sanity check for now
174 		fprintf(stderr,"<- B_BAD_INDEX\n");
175 		return B_BAD_INDEX;
176 	}
177 	// see null check comment above
178 	if (out_write_items != 0) {
179 		*out_write_items = 0;
180 	}
181 	// see null check comment above
182 	if (out_read_items != 0) {
183 		*out_read_items = 0;
184 	}
185 	return B_OK;
186 }
187 
188 status_t AbstractFileInterfaceAddOn::SniffTypeKind(
189 				const BMimeType & type,
190 				uint64 in_kinds,
191 				uint64 io_kind,
192 				float * out_quality,
193 				int32 * out_internal_id,
194 				void * _reserved)
195 {
196 	fprintf(stderr,"AbstractFileInterfaceAddOn::SniffTypeKind\n");
197 	if ((out_quality == 0) || (out_internal_id == 0)) {
198 		fprintf(stderr,"<- B_BAD_VALUE\n");
199 		return B_BAD_VALUE; // we refuse to crash because you were stupid
200 	}
201 	if (in_kinds & (io_kind | B_FILE_INTERFACE | B_CONTROLLABLE)) {
202 		return SniffType(type,out_quality,out_internal_id);
203 	} else {
204 		// They asked for some kind we don't supply.  We set the output
205 		// just in case they try to do something with it anyway (!)
206 		*out_quality = 0;
207 		*out_internal_id = -1;
208 		fprintf(stderr,"<- B_BAD_TYPE\n");
209 		return B_BAD_TYPE;
210 	}
211 }
212 
213 // -------------------------------------------------------- //
214 // main
215 // -------------------------------------------------------- //
216 
217 // int main(int argc, char *argv[])
218 //{
219 //}
220 
221 // -------------------------------------------------------- //
222 // stuffing
223 // -------------------------------------------------------- //
224 
225 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_0(void *) {};
226 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_1(void *) {};
227 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_2(void *) {};
228 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_3(void *) {};
229 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_4(void *) {};
230 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_5(void *) {};
231 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_6(void *) {};
232 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_7(void *) {};
233 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_8(void *) {};
234 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_9(void *) {};
235 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_10(void *) {};
236 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_11(void *) {};
237 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_12(void *) {};
238 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_13(void *) {};
239 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_14(void *) {};
240 status_t AbstractFileInterfaceAddOn::_Reserved_AbstractFileInterfaceAddOn_15(void *) {};
241