* Rewrote header
* Some coding style fixes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32782 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
e09d819b6c
commit
6abeda1091
@ -1,77 +1,70 @@
|
||||
/* MediaFiles.h */
|
||||
/* Copyright 1998 Be Incorporated. All rights reserved. */
|
||||
|
||||
#if !defined(_MEDIA_FILES_H)
|
||||
/*
|
||||
* Copyright 2009, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _MEDIA_FILES_H
|
||||
#define _MEDIA_FILES_H
|
||||
|
||||
|
||||
#include <MediaDefs.h>
|
||||
#include <List.h>
|
||||
#include <String.h>
|
||||
|
||||
struct entry_ref;
|
||||
|
||||
#include <String.h>
|
||||
|
||||
class BMediaFiles {
|
||||
public:
|
||||
|
||||
BMediaFiles();
|
||||
virtual ~BMediaFiles();
|
||||
BMediaFiles();
|
||||
virtual ~BMediaFiles();
|
||||
|
||||
virtual status_t RewindTypes();
|
||||
virtual status_t GetNextType(
|
||||
BString * out_type);
|
||||
virtual status_t RewindTypes();
|
||||
virtual status_t GetNextType(BString* _type);
|
||||
|
||||
virtual status_t RewindRefs(
|
||||
const char * type);
|
||||
virtual status_t GetNextRef(
|
||||
BString * out_type,
|
||||
entry_ref * out_ref = NULL);
|
||||
virtual status_t RewindRefs(const char* type);
|
||||
virtual status_t GetNextRef(BString* _type,
|
||||
entry_ref* _ref = NULL);
|
||||
|
||||
virtual status_t GetRefFor(
|
||||
const char * type,
|
||||
const char * item,
|
||||
entry_ref * out_ref);
|
||||
status_t GetAudioGainFor(
|
||||
const char * type,
|
||||
const char * item,
|
||||
float * out_audio_gain);
|
||||
virtual status_t SetRefFor(
|
||||
const char * type,
|
||||
const char * item,
|
||||
const entry_ref & ref);
|
||||
status_t SetAudioGainFor(
|
||||
const char * type,
|
||||
const char * item,
|
||||
float audio_gain);
|
||||
virtual status_t RemoveRefFor( // This might better be called "ClearRefFor"
|
||||
const char * type, // but it's too late now...
|
||||
const char * item,
|
||||
const entry_ref & ref);
|
||||
virtual status_t GetRefFor(const char* type, const char* item,
|
||||
entry_ref* _ref);
|
||||
virtual status_t SetRefFor(const char* type, const char* item,
|
||||
const entry_ref& ref);
|
||||
|
||||
static const char B_SOUNDS[]; /* for "types" */
|
||||
status_t GetAudioGainFor(const char* type,
|
||||
const char* item, float* _gain);
|
||||
status_t SetAudioGainFor(const char* type,
|
||||
const char* item, float gain);
|
||||
|
||||
virtual status_t RemoveItem( // new in 4.1, removes the whole item.
|
||||
const char * type,
|
||||
const char * item);
|
||||
// TODO: Rename this to "ClearRefFor" when breaking BC.
|
||||
virtual status_t RemoveRefFor(const char* type,
|
||||
const char* item, const entry_ref& ref);
|
||||
|
||||
static const char B_SOUNDS[];
|
||||
|
||||
virtual status_t RemoveItem(const char* type, const char* item);
|
||||
|
||||
// TODO: Needs Perform() for FBC reasons!
|
||||
|
||||
private:
|
||||
// FBC padding
|
||||
|
||||
status_t _Reserved_MediaFiles_0(void *, ...);
|
||||
virtual status_t _Reserved_MediaFiles_1(void *, ...);
|
||||
virtual status_t _Reserved_MediaFiles_2(void *, ...);
|
||||
virtual status_t _Reserved_MediaFiles_3(void *, ...);
|
||||
virtual status_t _Reserved_MediaFiles_4(void *, ...);
|
||||
virtual status_t _Reserved_MediaFiles_5(void *, ...);
|
||||
virtual status_t _Reserved_MediaFiles_6(void *, ...);
|
||||
virtual status_t _Reserved_MediaFiles_7(void *, ...);
|
||||
status_t _Reserved_MediaFiles_0(void*, ...);
|
||||
virtual status_t _Reserved_MediaFiles_1(void*, ...);
|
||||
virtual status_t _Reserved_MediaFiles_2(void*, ...);
|
||||
virtual status_t _Reserved_MediaFiles_3(void*, ...);
|
||||
virtual status_t _Reserved_MediaFiles_4(void*, ...);
|
||||
virtual status_t _Reserved_MediaFiles_5(void*, ...);
|
||||
virtual status_t _Reserved_MediaFiles_6(void*, ...);
|
||||
virtual status_t _Reserved_MediaFiles_7(void*, ...);
|
||||
|
||||
BList m_types;
|
||||
int m_type_index;
|
||||
BString m_cur_type;
|
||||
BList m_items;
|
||||
int m_item_index;
|
||||
private:
|
||||
BList fTypes;
|
||||
int fTypeIndex;
|
||||
BString fCurrentType;
|
||||
BList fItems;
|
||||
int fItemIndex;
|
||||
};
|
||||
|
||||
#endif /* _MEDIA_FILES_H */
|
||||
#endif // _MEDIA_FILES_H
|
||||
|
||||
|
@ -1,181 +1,191 @@
|
||||
/***********************************************************************
|
||||
* AUTHOR: Marcus Overhagen, Jérôme Duval
|
||||
* FILE: MediaFiles.cpp
|
||||
* DESCR:
|
||||
***********************************************************************/
|
||||
/*
|
||||
* Copyright 2002-2008, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Marcus Overhagen
|
||||
* Jérôme Duval
|
||||
*/
|
||||
|
||||
|
||||
#include <MediaFiles.h>
|
||||
#include "DataExchange.h"
|
||||
#include "debug.h"
|
||||
|
||||
/*************************************************************
|
||||
* public BMediaFiles
|
||||
*************************************************************/
|
||||
|
||||
const char BMediaFiles::B_SOUNDS[] = "Sounds"; /* for "types" */
|
||||
const char BMediaFiles::B_SOUNDS[] = "Sounds";
|
||||
|
||||
|
||||
BMediaFiles::BMediaFiles()
|
||||
: m_type_index(-1),
|
||||
m_cur_type(""),
|
||||
m_item_index(-1)
|
||||
:
|
||||
fTypeIndex(-1),
|
||||
fCurrentType(""),
|
||||
fItemIndex(-1)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* virtual */
|
||||
BMediaFiles::~BMediaFiles()
|
||||
{
|
||||
|
||||
// TODO: Cleanup!
|
||||
}
|
||||
|
||||
|
||||
/* virtual */ status_t
|
||||
status_t
|
||||
BMediaFiles::RewindTypes()
|
||||
{
|
||||
CALLED();
|
||||
status_t rv;
|
||||
server_rewindtypes_request request;
|
||||
server_rewindtypes_reply reply;
|
||||
|
||||
for (int32 i = 0; i < m_types.CountItems(); i++)
|
||||
delete (BString*)m_types.ItemAt(i);
|
||||
|
||||
m_types.MakeEmpty();
|
||||
|
||||
for (int32 i = 0; i < fTypes.CountItems(); i++)
|
||||
delete (BString*)fTypes.ItemAt(i);
|
||||
|
||||
fTypes.MakeEmpty();
|
||||
|
||||
TRACE("BMediaFiles::RewindTypes: sending SERVER_REWINDTYPES\n");
|
||||
|
||||
rv = QueryServer(SERVER_REWINDTYPES, &request, sizeof(request), &reply, sizeof(reply));
|
||||
|
||||
rv = QueryServer(SERVER_REWINDTYPES, &request, sizeof(request), &reply,
|
||||
sizeof(reply));
|
||||
if (rv != B_OK) {
|
||||
ERROR("BMediaFiles::RewindTypes: failed to rewindtypes (error %#lx)\n", rv);
|
||||
ERROR("BMediaFiles::RewindTypes: failed to rewindtypes "
|
||||
"(error %#lx)\n", rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
char *types;
|
||||
area_id clone;
|
||||
|
||||
clone = clone_area("rewind types clone", reinterpret_cast<void **>(&types), B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, reply.area);
|
||||
clone = clone_area("rewind types clone", reinterpret_cast<void **>(&types),
|
||||
B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, reply.area);
|
||||
if (clone < B_OK) {
|
||||
ERROR("BMediaFiles::RewindTypes failed to clone area, %#lx\n", clone);
|
||||
delete_area(reply.area);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
for (int32 i = 0; i < reply.count; i++) {
|
||||
m_types.AddItem(new BString(types + i * B_MEDIA_NAME_LENGTH));
|
||||
}
|
||||
for (int32 i = 0; i < reply.count; i++)
|
||||
fTypes.AddItem(new BString(types + i * B_MEDIA_NAME_LENGTH));
|
||||
|
||||
delete_area(clone);
|
||||
delete_area(reply.area);
|
||||
|
||||
m_type_index = 0;
|
||||
|
||||
fTypeIndex = 0;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/* virtual */ status_t
|
||||
status_t
|
||||
BMediaFiles::GetNextType(BString *out_type)
|
||||
{
|
||||
CALLED();
|
||||
if (m_type_index < 0 || m_type_index >= m_types.CountItems()) {
|
||||
m_type_index = -1;
|
||||
if (fTypeIndex < 0 || fTypeIndex >= fTypes.CountItems()) {
|
||||
fTypeIndex = -1;
|
||||
return B_BAD_INDEX;
|
||||
}
|
||||
|
||||
*out_type = *(BString*)m_types.ItemAt(m_type_index);
|
||||
m_type_index++;
|
||||
|
||||
*out_type = *(BString*)fTypes.ItemAt(fTypeIndex);
|
||||
fTypeIndex++;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/* virtual */ status_t
|
||||
status_t
|
||||
BMediaFiles::RewindRefs(const char *type)
|
||||
{
|
||||
CALLED();
|
||||
status_t rv;
|
||||
server_rewindrefs_request request;
|
||||
server_rewindrefs_reply reply;
|
||||
|
||||
for (int32 i = 0; i < m_items.CountItems(); i++)
|
||||
delete (BString*)m_items.ItemAt(i);
|
||||
|
||||
m_items.MakeEmpty();
|
||||
|
||||
TRACE("BMediaFiles::RewindRefs: sending SERVER_REWINDREFS for type %s\n", type);
|
||||
for (int32 i = 0; i < fItems.CountItems(); i++)
|
||||
delete (BString*)fItems.ItemAt(i);
|
||||
|
||||
fItems.MakeEmpty();
|
||||
|
||||
TRACE("BMediaFiles::RewindRefs: sending SERVER_REWINDREFS for type %s\n",
|
||||
type);
|
||||
strncpy(request.type, type, B_MEDIA_NAME_LENGTH);
|
||||
|
||||
rv = QueryServer(SERVER_REWINDREFS, &request, sizeof(request), &reply, sizeof(reply));
|
||||
|
||||
rv = QueryServer(SERVER_REWINDREFS, &request, sizeof(request), &reply,
|
||||
sizeof(reply));
|
||||
if (rv != B_OK) {
|
||||
ERROR("BMediaFiles::RewindRefs: failed to rewindrefs (error %#lx)\n", rv);
|
||||
ERROR("BMediaFiles::RewindRefs: failed to rewindrefs (error %#lx)\n",
|
||||
rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (reply.count>0) {
|
||||
char *items;
|
||||
area_id clone;
|
||||
|
||||
clone = clone_area("rewind refs clone", reinterpret_cast<void **>(&items), B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, reply.area);
|
||||
|
||||
clone = clone_area("rewind refs clone",
|
||||
reinterpret_cast<void **>(&items), B_ANY_ADDRESS, B_READ_AREA
|
||||
| B_WRITE_AREA, reply.area);
|
||||
if (clone < B_OK) {
|
||||
ERROR("BMediaFiles::RewindRefs failed to clone area, %#lx\n", clone);
|
||||
ERROR("BMediaFiles::RewindRefs failed to clone area, %#lx\n",
|
||||
clone);
|
||||
delete_area(reply.area);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
for (int32 i = 0; i < reply.count; i++) {
|
||||
m_items.AddItem(new BString(items + i * B_MEDIA_NAME_LENGTH));
|
||||
fItems.AddItem(new BString(items + i * B_MEDIA_NAME_LENGTH));
|
||||
}
|
||||
|
||||
|
||||
delete_area(clone);
|
||||
delete_area(reply.area);
|
||||
}
|
||||
|
||||
m_cur_type = BString(type);
|
||||
m_item_index = 0;
|
||||
|
||||
fCurrentType = BString(type);
|
||||
fItemIndex = 0;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/* virtual */ status_t
|
||||
BMediaFiles::GetNextRef(BString *out_type,
|
||||
entry_ref *out_ref)
|
||||
status_t
|
||||
BMediaFiles::GetNextRef(BString *out_type, entry_ref *out_ref)
|
||||
{
|
||||
CALLED();
|
||||
if (m_item_index < 0 || m_item_index >= m_items.CountItems()) {
|
||||
m_item_index = -1;
|
||||
if (fItemIndex < 0 || fItemIndex >= fItems.CountItems()) {
|
||||
fItemIndex = -1;
|
||||
return B_BAD_INDEX;
|
||||
}
|
||||
|
||||
*out_type = *(BString*)m_items.ItemAt(m_item_index);
|
||||
m_item_index++;
|
||||
|
||||
GetRefFor(m_cur_type.String(), out_type->String(), out_ref);
|
||||
|
||||
*out_type = *(BString*)fItems.ItemAt(fItemIndex);
|
||||
fItemIndex++;
|
||||
|
||||
GetRefFor(fCurrentType.String(), out_type->String(), out_ref);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/* virtual */ status_t
|
||||
BMediaFiles::GetRefFor(const char *type,
|
||||
const char *item,
|
||||
entry_ref *out_ref)
|
||||
status_t
|
||||
BMediaFiles::GetRefFor(const char *type, const char *item, entry_ref *out_ref)
|
||||
{
|
||||
CALLED();
|
||||
status_t rv;
|
||||
server_getreffor_request request;
|
||||
server_getreffor_reply reply;
|
||||
|
||||
|
||||
strncpy(request.type, type, B_MEDIA_NAME_LENGTH);
|
||||
strncpy(request.item, item, B_MEDIA_NAME_LENGTH);
|
||||
|
||||
|
||||
TRACE("BMediaFiles::GetRefFor: sending SERVER_GETREFFOR\n");
|
||||
|
||||
rv = QueryServer(SERVER_GETREFFOR, &request, sizeof(request), &reply, sizeof(reply));
|
||||
|
||||
rv = QueryServer(SERVER_GETREFFOR, &request, sizeof(request), &reply,
|
||||
sizeof(reply));
|
||||
if (rv != B_OK) {
|
||||
entry_ref ref;
|
||||
*out_ref = ref;
|
||||
ERROR("BMediaFiles::GetRefFor: failed to getreffor (error %#lx)\n", rv);
|
||||
ERROR("BMediaFiles::GetRefFor: failed to getreffor (error %#lx)\n",
|
||||
rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -186,9 +196,8 @@ BMediaFiles::GetRefFor(const char *type,
|
||||
|
||||
|
||||
status_t
|
||||
BMediaFiles::GetAudioGainFor(const char * type,
|
||||
const char * item,
|
||||
float * out_audio_gain)
|
||||
BMediaFiles::GetAudioGainFor(const char * type, const char * item,
|
||||
float * out_audio_gain)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
*out_audio_gain = 1.0f;
|
||||
@ -196,25 +205,26 @@ BMediaFiles::GetAudioGainFor(const char * type,
|
||||
}
|
||||
|
||||
|
||||
/* virtual */ status_t
|
||||
BMediaFiles::SetRefFor(const char *type,
|
||||
const char *item,
|
||||
const entry_ref &ref)
|
||||
status_t
|
||||
BMediaFiles::SetRefFor(const char *type, const char *item,
|
||||
const entry_ref &ref)
|
||||
{
|
||||
CALLED();
|
||||
status_t rv;
|
||||
server_setreffor_request request;
|
||||
server_setreffor_reply reply;
|
||||
|
||||
|
||||
strncpy(request.type, type, B_MEDIA_NAME_LENGTH);
|
||||
strncpy(request.item, item, B_MEDIA_NAME_LENGTH);
|
||||
request.ref = ref;
|
||||
|
||||
|
||||
TRACE("BMediaFiles::SetRefFor: sending SERVER_SETREFFOR\n");
|
||||
|
||||
rv = QueryServer(SERVER_SETREFFOR, &request, sizeof(request), &reply, sizeof(reply));
|
||||
|
||||
rv = QueryServer(SERVER_SETREFFOR, &request, sizeof(request), &reply,
|
||||
sizeof(reply));
|
||||
if (rv != B_OK) {
|
||||
ERROR("BMediaFiles::SetRefFor: failed to setreffor (error %#lx)\n", rv);
|
||||
ERROR("BMediaFiles::SetRefFor: failed to setreffor (error %#lx)\n",
|
||||
rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -223,33 +233,33 @@ BMediaFiles::SetRefFor(const char *type,
|
||||
|
||||
|
||||
status_t
|
||||
BMediaFiles::SetAudioGainFor(const char * type,
|
||||
const char * item,
|
||||
float audio_gain)
|
||||
BMediaFiles::SetAudioGainFor(const char * type, const char * item,
|
||||
float audio_gain)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/* virtual */ status_t
|
||||
BMediaFiles::RemoveRefFor(const char *type,
|
||||
const char *item,
|
||||
const entry_ref &ref)
|
||||
status_t
|
||||
BMediaFiles::RemoveRefFor(const char *type, const char *item,
|
||||
const entry_ref &ref)
|
||||
{
|
||||
status_t rv;
|
||||
server_removereffor_request request;
|
||||
server_removereffor_reply reply;
|
||||
|
||||
|
||||
strncpy(request.type, type, B_MEDIA_NAME_LENGTH);
|
||||
strncpy(request.item, item, B_MEDIA_NAME_LENGTH);
|
||||
request.ref = ref;
|
||||
|
||||
|
||||
TRACE("BMediaFiles::RemoveRefFor: sending SERVER_REMOVEREFFOR\n");
|
||||
|
||||
rv = QueryServer(SERVER_REMOVEREFFOR, &request, sizeof(request), &reply, sizeof(reply));
|
||||
|
||||
rv = QueryServer(SERVER_REMOVEREFFOR, &request, sizeof(request), &reply,
|
||||
sizeof(reply));
|
||||
if (rv != B_OK) {
|
||||
ERROR("BMediaFiles::RemoveRefFor: failed to removereffor (error %#lx)\n", rv);
|
||||
ERROR("BMediaFiles::RemoveRefFor: failed to removereffor "
|
||||
"(error %#lx)\n", rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -257,33 +267,38 @@ BMediaFiles::RemoveRefFor(const char *type,
|
||||
}
|
||||
|
||||
|
||||
/* virtual */ status_t
|
||||
BMediaFiles::RemoveItem(const char *type,
|
||||
const char *item)
|
||||
status_t
|
||||
BMediaFiles::RemoveItem(const char *type, const char *item)
|
||||
{
|
||||
status_t rv;
|
||||
server_removeitem_request request;
|
||||
server_removeitem_reply reply;
|
||||
|
||||
|
||||
strncpy(request.type, type, B_MEDIA_NAME_LENGTH);
|
||||
strncpy(request.item, item, B_MEDIA_NAME_LENGTH);
|
||||
|
||||
|
||||
TRACE("BMediaFiles::RemoveItem: sending SERVER_REMOVEITEM\n");
|
||||
|
||||
rv = QueryServer(SERVER_REMOVEITEM, &request, sizeof(request), &reply, sizeof(reply));
|
||||
|
||||
rv = QueryServer(SERVER_REMOVEITEM, &request, sizeof(request), &reply,
|
||||
sizeof(reply));
|
||||
if (rv != B_OK) {
|
||||
ERROR("BMediaFiles::RemoveItem: failed to removeitem (error %#lx)\n", rv);
|
||||
ERROR("BMediaFiles::RemoveItem: failed to removeitem (error %#lx)\n",
|
||||
rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* private BMediaFiles
|
||||
*************************************************************/
|
||||
|
||||
status_t BMediaFiles::_Reserved_MediaFiles_0(void *,...) { return B_ERROR; }
|
||||
// #pragma mark - FBC padding
|
||||
|
||||
status_t BMediaFiles::_Reserved_MediaFiles_0(void *,...)
|
||||
{
|
||||
// TODO: Someone didn't understand FBC
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t BMediaFiles::_Reserved_MediaFiles_1(void *,...) { return B_ERROR; }
|
||||
status_t BMediaFiles::_Reserved_MediaFiles_2(void *,...) { return B_ERROR; }
|
||||
status_t BMediaFiles::_Reserved_MediaFiles_3(void *,...) { return B_ERROR; }
|
||||
|
Loading…
Reference in New Issue
Block a user