tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / kits / media / MediaFiles.cpp
blob2779d3534044dfb15e790f4964a980cea5492ef4
1 /*
2 * Copyright 2002-2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Marcus Overhagen
7 * Jérôme Duval
8 */
11 #include <MediaFiles.h>
13 #include <AppMisc.h>
14 #include <DataExchange.h>
15 #include <debug.h>
18 const char BMediaFiles::B_SOUNDS[] = "Sounds";
21 BMediaFiles::BMediaFiles()
23 fTypeIndex(-1),
24 fItemIndex(-1)
30 BMediaFiles::~BMediaFiles()
32 _ClearTypes();
33 _ClearItems();
37 status_t
38 BMediaFiles::RewindTypes()
40 CALLED();
42 _ClearTypes();
44 server_get_media_types_request request;
45 request.team = BPrivate::current_team();
47 server_get_media_types_reply reply;
48 status_t status = QueryServer(SERVER_GET_MEDIA_FILE_TYPES, &request,
49 sizeof(request), &reply, sizeof(reply));
50 if (status != B_OK) {
51 ERROR("BMediaFiles::RewindTypes: failed to rewind types: %s\n",
52 strerror(status));
53 return status;
56 const char* types = (const char*)reply.address;
57 for (int32 i = 0; i < reply.count; i++)
58 fTypes.AddItem(new BString(types + i * B_MEDIA_NAME_LENGTH));
60 delete_area(reply.area);
62 fTypeIndex = 0;
63 return B_OK;
67 status_t
68 BMediaFiles::GetNextType(BString* _type)
70 CALLED();
71 if (fTypeIndex < 0 || fTypeIndex >= fTypes.CountItems()) {
72 _ClearTypes();
73 fTypeIndex = -1;
74 return B_BAD_INDEX;
77 *_type = *(BString*)fTypes.ItemAt(fTypeIndex);
78 fTypeIndex++;
80 return B_OK;
84 status_t
85 BMediaFiles::RewindRefs(const char* type)
87 CALLED();
89 _ClearItems();
91 TRACE("BMediaFiles::RewindRefs: sending SERVER_GET_MEDIA_FILE_ITEMS for "
92 "type %s\n", type);
94 server_get_media_items_request request;
95 request.team = BPrivate::current_team();
96 strlcpy(request.type, type, B_MEDIA_NAME_LENGTH);
98 server_get_media_items_reply reply;
99 status_t status = QueryServer(SERVER_GET_MEDIA_FILE_ITEMS, &request,
100 sizeof(request), &reply, sizeof(reply));
101 if (status != B_OK) {
102 ERROR("BMediaFiles::RewindRefs: failed to rewind refs: %s\n",
103 strerror(status));
104 return status;
107 const char* items = (const char*)reply.address;
108 for (int32 i = 0; i < reply.count; i++) {
109 fItems.AddItem(new BString(items + i * B_MEDIA_NAME_LENGTH,
110 B_MEDIA_NAME_LENGTH));
113 delete_area(reply.area);
115 fCurrentType = type;
116 fItemIndex = 0;
117 return B_OK;
121 status_t
122 BMediaFiles::GetNextRef(BString* _type, entry_ref* _ref)
124 CALLED();
125 if (fItemIndex < 0 || fItemIndex >= fItems.CountItems()) {
126 _ClearItems();
127 fItemIndex = -1;
128 return B_BAD_INDEX;
131 *_type = *(BString*)fItems.ItemAt(fItemIndex);
132 GetRefFor(fCurrentType.String(), _type->String(), _ref);
134 fItemIndex++;
135 return B_OK;
139 status_t
140 BMediaFiles::GetRefFor(const char* type, const char* item, entry_ref* _ref)
142 CALLED();
144 if (type == NULL || item == NULL || _ref == NULL)
145 return B_BAD_VALUE;
147 server_get_ref_for_request request;
148 strlcpy(request.type, type, B_MEDIA_NAME_LENGTH);
149 strlcpy(request.item, item, B_MEDIA_NAME_LENGTH);
151 server_get_ref_for_reply reply;
152 status_t status = QueryServer(SERVER_GET_REF_FOR, &request, sizeof(request),
153 &reply, sizeof(reply));
154 if (status != B_OK) {
155 ERROR("BMediaFiles::GetRefFor: failed: %s\n", strerror(status));
156 return status;
159 *_ref = reply.ref;
160 return B_OK;
164 status_t
165 BMediaFiles::GetAudioGainFor(const char* type, const char* item, float* _gain)
167 CALLED();
169 if (type == NULL || item == NULL || _gain == NULL)
170 return B_BAD_VALUE;
172 server_get_item_audio_gain_request request;
173 strlcpy(request.type, type, B_MEDIA_NAME_LENGTH);
174 strlcpy(request.item, item, B_MEDIA_NAME_LENGTH);
176 server_get_item_audio_gain_reply reply;
177 status_t status = QueryServer(SERVER_GET_ITEM_AUDIO_GAIN, &request,
178 sizeof(request), &reply, sizeof(reply));
179 if (status != B_OK) {
180 ERROR("BMediaFiles::GetRefFor: failed: %s\n", strerror(status));
181 return status;
184 *_gain = reply.gain;
185 return B_OK;
189 status_t
190 BMediaFiles::SetRefFor(const char* type, const char* item,
191 const entry_ref& ref)
193 CALLED();
195 server_set_ref_for_request request;
196 strlcpy(request.type, type, B_MEDIA_NAME_LENGTH);
197 strlcpy(request.item, item, B_MEDIA_NAME_LENGTH);
198 request.ref = ref;
200 server_set_ref_for_reply reply;
201 status_t status = QueryServer(SERVER_SET_REF_FOR, &request, sizeof(request),
202 &reply, sizeof(reply));
203 if (status != B_OK) {
204 ERROR("BMediaFiles::SetRefFor: failed: %s\n", strerror(status));
205 return status;
208 return B_OK;
212 status_t
213 BMediaFiles::SetAudioGainFor(const char* type, const char* item, float gain)
215 CALLED();
217 server_set_item_audio_gain_request request;
218 strlcpy(request.type, type, B_MEDIA_NAME_LENGTH);
219 strlcpy(request.item, item, B_MEDIA_NAME_LENGTH);
220 request.gain = gain;
222 server_set_item_audio_gain_reply reply;
223 status_t status = QueryServer(SERVER_SET_ITEM_AUDIO_GAIN, &request,
224 sizeof(request), &reply, sizeof(reply));
225 if (status != B_OK) {
226 ERROR("BMediaFiles::SetAudioGainFor: failed: %s\n", strerror(status));
227 return status;
230 return B_OK;
234 status_t
235 BMediaFiles::RemoveRefFor(const char* type, const char* item,
236 const entry_ref &ref)
238 CALLED();
240 server_invalidate_item_request request;
241 strlcpy(request.type, type, B_MEDIA_NAME_LENGTH);
242 strlcpy(request.item, item, B_MEDIA_NAME_LENGTH);
244 server_invalidate_item_reply reply;
245 status_t status = QueryServer(SERVER_INVALIDATE_MEDIA_ITEM, &request,
246 sizeof(request), &reply, sizeof(reply));
247 if (status != B_OK) {
248 ERROR("BMediaFiles::RemoveRefFor: failed: %s\n", strerror(status));
249 return status;
252 return B_OK;
256 status_t
257 BMediaFiles::RemoveItem(const char* type, const char* item)
259 CALLED();
261 server_remove_media_item_request request;
262 strlcpy(request.type, type, B_MEDIA_NAME_LENGTH);
263 strlcpy(request.item, item, B_MEDIA_NAME_LENGTH);
265 server_remove_media_item_reply reply;
266 status_t status = QueryServer(SERVER_REMOVE_MEDIA_ITEM, &request,
267 sizeof(request), &reply, sizeof(reply));
268 if (status != B_OK) {
269 ERROR("BMediaFiles::RemoveItem: failed: %s\n", strerror(status));
270 return status;
273 return B_OK;
277 // #pragma mark - private
280 void
281 BMediaFiles::_ClearTypes()
283 for (int32 i = 0; i < fTypes.CountItems(); i++)
284 delete (BString*)fTypes.ItemAt(i);
286 fTypes.MakeEmpty();
290 void
291 BMediaFiles::_ClearItems()
293 for (int32 i = 0; i < fItems.CountItems(); i++)
294 delete (BString*)fItems.ItemAt(i);
296 fItems.MakeEmpty();
300 // #pragma mark - FBC padding
303 status_t
304 BMediaFiles::_Reserved_MediaFiles_0(void*,...)
306 // TODO: Someone didn't understand FBC
307 return B_ERROR;
311 status_t BMediaFiles::_Reserved_MediaFiles_1(void*,...) { return B_ERROR; }
312 status_t BMediaFiles::_Reserved_MediaFiles_2(void*,...) { return B_ERROR; }
313 status_t BMediaFiles::_Reserved_MediaFiles_3(void*,...) { return B_ERROR; }
314 status_t BMediaFiles::_Reserved_MediaFiles_4(void*,...) { return B_ERROR; }
315 status_t BMediaFiles::_Reserved_MediaFiles_5(void*,...) { return B_ERROR; }
316 status_t BMediaFiles::_Reserved_MediaFiles_6(void*,...) { return B_ERROR; }
317 status_t BMediaFiles::_Reserved_MediaFiles_7(void*,...) { return B_ERROR; }