xref: /haiku/src/kits/media/FileInterface.cpp (revision 0d452c8f34013b611a54c746a71c05e28796eae2)
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 <string.h>
16 #include <FileInterface.h>
17 #include <MimeType.h>
18 
19 
20 /*************************************************************
21  * protected BFileInterface
22  *************************************************************/
23 
24 BFileInterface::~BFileInterface()
25 {
26 }
27 
28 /*************************************************************
29  * public BFileInterface
30  *************************************************************/
31 
32 /* nothing */
33 
34 /*************************************************************
35  * protected BFileInterface
36  *************************************************************/
37 
38 BFileInterface::BFileInterface()
39 	: BMediaNode("called by FileInterface")
40 {
41 	CALLED();
42 
43 	AddNodeKind(B_FILE_INTERFACE);
44 }
45 
46 
47 status_t
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 		default:
101 			return B_ERROR;
102 	}
103 	return B_ERROR;
104 }
105 
106 /*************************************************************
107  * private BFileInterface
108  *************************************************************/
109 
110 /*
111 private unimplemented
112 BFileInterface::BFileInterface(const BFileInterface &clone)
113 FileInterface & BFileInterface::operator=(const BFileInterface &clone)
114 */
115 
116 status_t BFileInterface::_Reserved_FileInterface_0(void *) { return B_ERROR; }
117 status_t BFileInterface::_Reserved_FileInterface_1(void *) { return B_ERROR; }
118 status_t BFileInterface::_Reserved_FileInterface_2(void *) { return B_ERROR; }
119 status_t BFileInterface::_Reserved_FileInterface_3(void *) { return B_ERROR; }
120 status_t BFileInterface::_Reserved_FileInterface_4(void *) { return B_ERROR; }
121 status_t BFileInterface::_Reserved_FileInterface_5(void *) { return B_ERROR; }
122 status_t BFileInterface::_Reserved_FileInterface_6(void *) { return B_ERROR; }
123 status_t BFileInterface::_Reserved_FileInterface_7(void *) { return B_ERROR; }
124 status_t BFileInterface::_Reserved_FileInterface_8(void *) { return B_ERROR; }
125 status_t BFileInterface::_Reserved_FileInterface_9(void *) { return B_ERROR; }
126 status_t BFileInterface::_Reserved_FileInterface_10(void *) { return B_ERROR; }
127 status_t BFileInterface::_Reserved_FileInterface_11(void *) { return B_ERROR; }
128 status_t BFileInterface::_Reserved_FileInterface_12(void *) { return B_ERROR; }
129 status_t BFileInterface::_Reserved_FileInterface_13(void *) { return B_ERROR; }
130 status_t BFileInterface::_Reserved_FileInterface_14(void *) { return B_ERROR; }
131 status_t BFileInterface::_Reserved_FileInterface_15(void *) { return B_ERROR; }
132 
133