xref: /haiku/src/kits/media/FileInterface.cpp (revision b84955d416f92e89c9d73999f545a2dec353d988)
1 /***********************************************************************
2  * AUTHOR: Marcus Overhagen
3  *   FILE: FileInterface.cpp
4  *  DESCR:
5  ***********************************************************************/
6 /*
7  * Copyright 2008 Maurice Kalinowski, haiku@kaldience.com
8  *
9  * All rights reserved. Distributed under the terms of the MIT License.
10  *
11  */
12 
13 #include "MediaDebug.h"
14 #include "DataExchange.h"
15 #include <string.h>
16 #include <FileInterface.h>
17 #include <MimeType.h>
18 
19 
20 /*************************************************************
21  * protected BFileInterface
22  *************************************************************/
23 
~BFileInterface()24 BFileInterface::~BFileInterface()
25 {
26 }
27 
28 /*************************************************************
29  * public BFileInterface
30  *************************************************************/
31 
32 /* nothing */
33 
34 /*************************************************************
35  * protected BFileInterface
36  *************************************************************/
37 
BFileInterface()38 BFileInterface::BFileInterface()
39 	: BMediaNode("called by FileInterface")
40 {
41 	CALLED();
42 
43 	AddNodeKind(B_FILE_INTERFACE);
44 }
45 
46 
47 status_t
HandleMessage(int32 message,const void * data,size_t size)48 BFileInterface::HandleMessage(int32 message,
49 							  const void *data,
50 							  size_t size)
51 {
52 	CALLED();
53 
54 	status_t rv;
55 
56 	switch(message) {
57 		case FILEINTERFACE_SET_REF:
58 		{
59 			const fileinterface_set_ref_request *request =
60 					(const fileinterface_set_ref_request*) data;
61 			fileinterface_set_ref_reply reply;
62 			entry_ref ref(request->device, request->directory,
63 								request->name);
64 			reply.duration = request->duration;
65 
66 			rv = SetRef(ref, request->create, &reply.duration);
67 
68 			request->SendReply(rv, &reply, sizeof(reply));
69 			return B_OK;
70 		}
71 		case FILEINTERFACE_GET_REF:
72 		{
73 			const fileinterface_get_ref_request *request =
74 					(const fileinterface_get_ref_request*) data;
75 			fileinterface_get_ref_reply reply;
76 			entry_ref resultRef;
77 			rv = GetRef(&resultRef, reply.mimetype);
78 			if (rv == B_OK) {
79 				reply.device = resultRef.device;
80 				reply.directory = resultRef.directory;
81 				strcpy(reply.name, resultRef.name);
82 			}
83 			request->SendReply(rv, &reply, sizeof(reply));
84 			return B_OK;
85 		}
86 		case FILEINTERFACE_SNIFF_REF:
87 		{
88 			const fileinterface_sniff_ref_request *request =
89 					(const fileinterface_sniff_ref_request*) data;
90 			fileinterface_sniff_ref_reply reply;
91 
92 			entry_ref ref(request->device, request->directory,
93 						  request->name);
94 
95 			rv = SniffRef(ref, reply.mimetype, &reply.capability);
96 			request->SendReply(rv, &reply, sizeof(reply));
97 
98 			return B_OK;
99 		}
100 		case FILEINTERFACE_GET_FORMATS:
101 		{
102 			const fileinterface_get_formats_request *request =
103 					(const fileinterface_get_formats_request*) data;
104 			fileinterface_get_formats_reply reply;
105 
106 			media_file_format* formats;
107 			area_id area = clone_area("client formats area",
108 				(void**)&formats, B_ANY_ADDRESS, B_WRITE_AREA,
109 				request->data_area);
110 
111 			if (area < 0) {
112 				ERROR("BBufferConsumer::FILEINTERFACE_GET_FORMATS:"
113 					" can't clone area\n");
114 				break;
115 			}
116 
117 			int32 cookie = 0;
118 			while (GetNextFileFormat(&cookie, formats) == B_OK) {
119 				if (cookie >= request->num_formats)
120 					break;
121 				formats += sizeof(media_format);
122 			}
123 			reply.filled_slots = cookie;
124 			request->SendReply(B_OK, &reply, sizeof(reply));
125 
126 			delete_area(area);
127 			return B_OK;
128 		}
129 		default:
130 			return B_ERROR;
131 	}
132 	return B_ERROR;
133 }
134 
135 /*************************************************************
136  * private BFileInterface
137  *************************************************************/
138 
139 /*
140 private unimplemented
141 BFileInterface::BFileInterface(const BFileInterface &clone)
142 FileInterface & BFileInterface::operator=(const BFileInterface &clone)
143 */
144 
_Reserved_FileInterface_0(void *)145 status_t BFileInterface::_Reserved_FileInterface_0(void *) { return B_ERROR; }
_Reserved_FileInterface_1(void *)146 status_t BFileInterface::_Reserved_FileInterface_1(void *) { return B_ERROR; }
_Reserved_FileInterface_2(void *)147 status_t BFileInterface::_Reserved_FileInterface_2(void *) { return B_ERROR; }
_Reserved_FileInterface_3(void *)148 status_t BFileInterface::_Reserved_FileInterface_3(void *) { return B_ERROR; }
_Reserved_FileInterface_4(void *)149 status_t BFileInterface::_Reserved_FileInterface_4(void *) { return B_ERROR; }
_Reserved_FileInterface_5(void *)150 status_t BFileInterface::_Reserved_FileInterface_5(void *) { return B_ERROR; }
_Reserved_FileInterface_6(void *)151 status_t BFileInterface::_Reserved_FileInterface_6(void *) { return B_ERROR; }
_Reserved_FileInterface_7(void *)152 status_t BFileInterface::_Reserved_FileInterface_7(void *) { return B_ERROR; }
_Reserved_FileInterface_8(void *)153 status_t BFileInterface::_Reserved_FileInterface_8(void *) { return B_ERROR; }
_Reserved_FileInterface_9(void *)154 status_t BFileInterface::_Reserved_FileInterface_9(void *) { return B_ERROR; }
_Reserved_FileInterface_10(void *)155 status_t BFileInterface::_Reserved_FileInterface_10(void *) { return B_ERROR; }
_Reserved_FileInterface_11(void *)156 status_t BFileInterface::_Reserved_FileInterface_11(void *) { return B_ERROR; }
_Reserved_FileInterface_12(void *)157 status_t BFileInterface::_Reserved_FileInterface_12(void *) { return B_ERROR; }
_Reserved_FileInterface_13(void *)158 status_t BFileInterface::_Reserved_FileInterface_13(void *) { return B_ERROR; }
_Reserved_FileInterface_14(void *)159 status_t BFileInterface::_Reserved_FileInterface_14(void *) { return B_ERROR; }
_Reserved_FileInterface_15(void *)160 status_t BFileInterface::_Reserved_FileInterface_15(void *) { return B_ERROR; }
161 
162