xref: /haiku/src/kits/media/FileInterface.cpp (revision 4b3b81da9e459443d75329cfd08bc9a57ad02653)
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 "debug.h"
14 #include "DataExchange.h"
15 #include <FileInterface.h>
16 #include <MimeType.h>
17 
18 
19 /*************************************************************
20  * protected BFileInterface
21  *************************************************************/
22 
23 BFileInterface::~BFileInterface()
24 {
25 }
26 
27 /*************************************************************
28  * public BFileInterface
29  *************************************************************/
30 
31 /* nothing */
32 
33 /*************************************************************
34  * protected BFileInterface
35  *************************************************************/
36 
37 BFileInterface::BFileInterface()
38 	: BMediaNode("called by FileInterface")
39 {
40 	CALLED();
41 
42 	AddNodeKind(B_FILE_INTERFACE);
43 }
44 
45 
46 status_t
47 BFileInterface::HandleMessage(int32 message,
48 							  const void *data,
49 							  size_t size)
50 {
51 	CALLED();
52 
53 	status_t rv;
54 
55 	switch(message) {
56 		case FILEINTERFACE_SET_REF:
57 		{
58 			const fileinterface_set_ref_request *request =
59 					(const fileinterface_set_ref_request*) data;
60 			fileinterface_set_ref_reply reply;
61 			entry_ref ref(request->device, request->directory,
62 								request->name);
63 			reply.duration = request->duration;
64 
65 			rv = SetRef(ref, request->create, &reply.duration);
66 
67 			request->SendReply(rv, &reply, sizeof(reply));
68 			return B_OK;
69 		}
70 		case FILEINTERFACE_GET_REF:
71 		{
72 			const fileinterface_get_ref_request *request =
73 					(const fileinterface_get_ref_request*) data;
74 			fileinterface_get_ref_reply reply;
75 			entry_ref resultRef;
76 			rv = GetRef(&resultRef, reply.mimetype);
77 			if (rv == B_OK) {
78 				reply.device = resultRef.device;
79 				reply.directory = resultRef.directory;
80 				strcpy(reply.name, resultRef.name);
81 			}
82 			request->SendReply(rv, &reply, sizeof(reply));
83 			return B_OK;
84 		}
85 		case FILEINTERFACE_SNIFF_REF:
86 		{
87 			const fileinterface_sniff_ref_request *request =
88 					(const fileinterface_sniff_ref_request*) data;
89 			fileinterface_sniff_ref_reply reply;
90 
91 			entry_ref ref(request->device, request->directory,
92 						  request->name);
93 
94 			rv = SniffRef(ref, reply.mimetype, &reply.capability);
95 			request->SendReply(rv, &reply, sizeof(reply));
96 
97 			return B_OK;
98 		}
99 		default:
100 			return B_ERROR;
101 	}
102 	return B_ERROR;
103 }
104 
105 /*************************************************************
106  * private BFileInterface
107  *************************************************************/
108 
109 /*
110 private unimplemented
111 BFileInterface::BFileInterface(const BFileInterface &clone)
112 FileInterface & BFileInterface::operator=(const BFileInterface &clone)
113 */
114 
115 status_t BFileInterface::_Reserved_FileInterface_0(void *) { return B_ERROR; }
116 status_t BFileInterface::_Reserved_FileInterface_1(void *) { return B_ERROR; }
117 status_t BFileInterface::_Reserved_FileInterface_2(void *) { return B_ERROR; }
118 status_t BFileInterface::_Reserved_FileInterface_3(void *) { return B_ERROR; }
119 status_t BFileInterface::_Reserved_FileInterface_4(void *) { return B_ERROR; }
120 status_t BFileInterface::_Reserved_FileInterface_5(void *) { return B_ERROR; }
121 status_t BFileInterface::_Reserved_FileInterface_6(void *) { return B_ERROR; }
122 status_t BFileInterface::_Reserved_FileInterface_7(void *) { return B_ERROR; }
123 status_t BFileInterface::_Reserved_FileInterface_8(void *) { return B_ERROR; }
124 status_t BFileInterface::_Reserved_FileInterface_9(void *) { return B_ERROR; }
125 status_t BFileInterface::_Reserved_FileInterface_10(void *) { return B_ERROR; }
126 status_t BFileInterface::_Reserved_FileInterface_11(void *) { return B_ERROR; }
127 status_t BFileInterface::_Reserved_FileInterface_12(void *) { return B_ERROR; }
128 status_t BFileInterface::_Reserved_FileInterface_13(void *) { return B_ERROR; }
129 status_t BFileInterface::_Reserved_FileInterface_14(void *) { return B_ERROR; }
130 status_t BFileInterface::_Reserved_FileInterface_15(void *) { return B_ERROR; }
131 
132