2 * Copyright 2002-2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
11 #include <MediaFiles.h>
14 #include <DataExchange.h>
18 const char BMediaFiles::B_SOUNDS
[] = "Sounds";
21 BMediaFiles::BMediaFiles()
30 BMediaFiles::~BMediaFiles()
38 BMediaFiles::RewindTypes()
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
));
51 ERROR("BMediaFiles::RewindTypes: failed to rewind types: %s\n",
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
);
68 BMediaFiles::GetNextType(BString
* _type
)
71 if (fTypeIndex
< 0 || fTypeIndex
>= fTypes
.CountItems()) {
77 *_type
= *(BString
*)fTypes
.ItemAt(fTypeIndex
);
85 BMediaFiles::RewindRefs(const char* type
)
91 TRACE("BMediaFiles::RewindRefs: sending SERVER_GET_MEDIA_FILE_ITEMS for "
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",
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
);
122 BMediaFiles::GetNextRef(BString
* _type
, entry_ref
* _ref
)
125 if (fItemIndex
< 0 || fItemIndex
>= fItems
.CountItems()) {
131 *_type
= *(BString
*)fItems
.ItemAt(fItemIndex
);
132 GetRefFor(fCurrentType
.String(), _type
->String(), _ref
);
140 BMediaFiles::GetRefFor(const char* type
, const char* item
, entry_ref
* _ref
)
144 if (type
== NULL
|| item
== NULL
|| _ref
== NULL
)
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
));
165 BMediaFiles::GetAudioGainFor(const char* type
, const char* item
, float* _gain
)
169 if (type
== NULL
|| item
== NULL
|| _gain
== NULL
)
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
));
190 BMediaFiles::SetRefFor(const char* type
, const char* item
,
191 const entry_ref
& ref
)
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
);
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
));
213 BMediaFiles::SetAudioGainFor(const char* type
, const char* item
, float gain
)
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
);
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
));
235 BMediaFiles::RemoveRefFor(const char* type
, const char* item
,
236 const entry_ref
&ref
)
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
));
257 BMediaFiles::RemoveItem(const char* type
, const char* item
)
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
));
277 // #pragma mark - private
281 BMediaFiles::_ClearTypes()
283 for (int32 i
= 0; i
< fTypes
.CountItems(); i
++)
284 delete (BString
*)fTypes
.ItemAt(i
);
291 BMediaFiles::_ClearItems()
293 for (int32 i
= 0; i
< fItems
.CountItems(); i
++)
294 delete (BString
*)fItems
.ItemAt(i
);
300 // #pragma mark - FBC padding
304 BMediaFiles::_Reserved_MediaFiles_0(void*,...)
306 // TODO: Someone didn't understand FBC
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
; }