fixed some warnings

code style of MMediaFilesManager.* 


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20703 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2007-04-15 13:59:59 +00:00
parent 309289eb87
commit 88ec4b1dbe
4 changed files with 160 additions and 159 deletions

View File

@ -11,6 +11,7 @@ namespace BPrivate { namespace media {
class ChunkProvider { class ChunkProvider {
public: public:
virtual ~ChunkProvider() {};
virtual status_t GetNextChunk(const void **chunkBuffer, size_t *chunkSize, virtual status_t GetNextChunk(const void **chunkBuffer, size_t *chunkSize,
media_header *mediaHeader) = 0; media_header *mediaHeader) = 0;
}; };

View File

@ -143,7 +143,7 @@ PluginManager::~PluginManager()
{ {
CALLED(); CALLED();
while (!fPluginList->IsEmpty()) { while (!fPluginList->IsEmpty()) {
plugin_info *info; plugin_info *info = NULL;
fPluginList->Get(fPluginList->CountItems() - 1, &info); fPluginList->Get(fPluginList->CountItems() - 1, &info);
printf("PluginManager: Error, unloading PlugIn %s with usecount %d\n", info->name, info->usecount); printf("PluginManager: Error, unloading PlugIn %s with usecount %d\n", info->name, info->usecount);
delete info->plugin; delete info->plugin;

View File

@ -1,4 +1,4 @@
/* /*
* Copyright 2003, Jérôme Duval. All rights reserved. * Copyright 2003, Jérôme Duval. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@ -12,7 +12,7 @@
MMediaFilesManager::MMediaFilesManager() MMediaFilesManager::MMediaFilesManager()
: fLocker(new BLocker("media files manager locker")), : fLocker(new BLocker("media files manager locker")),
fRegistryMap(new Map<BString, Map<BString, entry_ref> >), fRegistryMap(new Map<BString, Map<BString, entry_ref> >),
fRunner(NULL) fRunner(NULL)
{ {
@ -32,38 +32,38 @@ MMediaFilesManager::~MMediaFilesManager()
} }
int32 int32
MMediaFilesManager::ReadPascalString(BFile &file, char **str) MMediaFilesManager::ReadPascalString(BFile &file, char **str)
{ {
uint32 len; uint32 len;
*str=NULL; *str = NULL;
if (file.Read(&len, 4) < 4) if (file.Read(&len, 4) < 4)
return -1; return -1;
if (len == 0) if (len == 0)
return 0; return 0;
*str = (char *)malloc(len); *str = (char *)malloc(len);
if (file.Read(*str, len) < (int32)len) { if (file.Read(*str, len) < (int32)len) {
free(*str); free(*str);
*str = NULL; *str = NULL;
return -1; return -1;
} }
return (int32)len; return (int32)len;
} }
int32 int32
MMediaFilesManager::WritePascalString(BFile &file, const char *str) MMediaFilesManager::WritePascalString(BFile &file, const char *str)
{ {
if(str == NULL) if (str == NULL)
return -1; return -1;
uint32 len = strlen(str) + 1; uint32 len = strlen(str) + 1;
if (file.Write(&len, 4) < 4) if (file.Write(&len, 4) < 4)
return -1; return -1;
if (len == 0) if (len == 0)
return 0; return 0;
if (file.Write(str, len) < (int32)len) { if (file.Write(str, len) < (int32)len) {
return -1; return -1;
} }
return (int32)len; return (int32)len;
} }
@ -76,16 +76,16 @@ MMediaFilesManager::LoadState()
CALLED(); CALLED();
status_t err = B_OK; status_t err = B_OK;
BPath path; BPath path;
if((err = find_directory(B_USER_SETTINGS_DIRECTORY, &path))!=B_OK) if ((err = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK)
return err; return err;
path.Append("Media/MMediaFilesManager"); path.Append("Media/MMediaFilesManager");
BFile file(path.Path(), B_READ_ONLY); BFile file(path.Path(), B_READ_ONLY);
uint32 category_count; uint32 category_count;
if (file.Read(header, sizeof(uint32)*3) < (int32)sizeof(uint32)*3) { if (file.Read(header, sizeof(uint32)*3) < (int32)sizeof(uint32)*3) {
header[0] = 0xac00150c; header[0] = 0xac00150c;
header[1] = 0x18723462; header[1] = 0x18723462;
header[2] = 0x00000001; header[2] = 0x00000001;
return B_ERROR; return B_ERROR;
@ -106,35 +106,35 @@ MMediaFilesManager::LoadState()
break; break;
TRACE("%s {\n", str); TRACE("%s {\n", str);
do { do {
len = ReadPascalString(file, &key); len = ReadPascalString(file, &key);
if (len < 0) if (len < 0)
return B_ERROR; return B_ERROR;
if (len == 0) if (len == 0)
break; break;
len = ReadPascalString(file, &val); len = ReadPascalString(file, &val);
if (len == 1) { if (len == 1) {
free(val); free(val);
val = strdup("(null)"); val = strdup("(null)");
} }
/*if (file.Read(&vol, sizeof(uint32)) < (int32)sizeof(uint32)) /*if (file.Read(&vol, sizeof(uint32)) < (int32)sizeof(uint32))
return B_ERROR;*/ return B_ERROR;*/
//TRACE(" %s: %s, volume: %f\n", key, val, *(float *)&vol); //TRACE(" %s: %s, volume: %f\n", key, val, *(float *)&vol);
entry_ref ref; entry_ref ref;
if(len>1) { if (len > 1) {
BEntry entry(val); BEntry entry(val);
if(entry.Exists()) if (entry.Exists())
entry.GetRef(&ref); entry.GetRef(&ref);
} }
SetRefFor(str, key, ref, false); SetRefFor(str, key, ref, false);
free(key); free(key);
free(val); free(val);
} while (true); } while (true);
TRACE("}\n"); TRACE("}\n");
free(str); free(str);
} }
return B_OK; return B_OK;
} }
@ -145,42 +145,42 @@ MMediaFilesManager::SaveState()
CALLED(); CALLED();
status_t err = B_OK; status_t err = B_OK;
BPath path; BPath path;
if((err = find_directory(B_USER_SETTINGS_DIRECTORY, &path))!=B_OK) if ((err = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK)
return err; return err;
path.Append("Media/MMediaFilesManager"); path.Append("Media/MMediaFilesManager");
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE); BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
uint32 zero = 0; uint32 zero = 0;
if (file.Write(header, sizeof(uint32)*3) < (int32)sizeof(uint32)*3) if (file.Write(header, sizeof(uint32)*3) < (int32)sizeof(uint32)*3)
return B_ERROR; return B_ERROR;
uint32 category_count = fRegistryMap->CountItems(); uint32 category_count = fRegistryMap->CountItems();
if (file.Write(&category_count, sizeof(uint32)) < (int32)sizeof(uint32)) if (file.Write(&category_count, sizeof(uint32)) < (int32)sizeof(uint32))
return B_ERROR; return B_ERROR;
BString *type; BString *type = NULL;
Map<BString, entry_ref> *map; Map<BString, entry_ref> *map;
BString *item; BString *item = NULL;
entry_ref *ref; entry_ref *ref;
for (fRegistryMap->Rewind(); fRegistryMap->GetNext(&map); ) { for (fRegistryMap->Rewind(); fRegistryMap->GetNext(&map);) {
fRegistryMap->GetCurrentKey(&type); fRegistryMap->GetCurrentKey(&type);
WritePascalString(file, type->String()); WritePascalString(file, type->String());
for (map->Rewind(); map->GetNext(&ref);) { for (map->Rewind(); map->GetNext(&ref);) {
map->GetCurrentKey(&item); map->GetCurrentKey(&item);
BPath path(ref); BPath path(ref);
WritePascalString(file, item->String()); WritePascalString(file, item->String());
WritePascalString(file, path.Path() ? path.Path() : ""); WritePascalString(file, path.Path() ? path.Path() : "");
} }
file.Write(&zero, sizeof(uint32)); file.Write(&zero, sizeof(uint32));
} }
file.Write(&zero, sizeof(uint32)); file.Write(&zero, sizeof(uint32));
return B_OK; return B_OK;
} }
@ -190,22 +190,22 @@ MMediaFilesManager::Dump()
{ {
BAutolock lock(fLocker); BAutolock lock(fLocker);
printf("\n"); printf("\n");
/* for each type, the registry map contains a map of item/entry_ref /* for each type, the registry map contains a map of item/entry_ref
*/ */
printf("MMediaFilesManager: registry map follows\n"); printf("MMediaFilesManager: registry map follows\n");
BString *type; BString *type = NULL;
Map<BString, entry_ref> *map; Map<BString, entry_ref> *map;
BString *item; BString *item = NULL;
entry_ref *ref; entry_ref *ref;
for (fRegistryMap->Rewind(); fRegistryMap->GetNext(&map); ) { for (fRegistryMap->Rewind(); fRegistryMap->GetNext(&map);) {
fRegistryMap->GetCurrentKey(&type); fRegistryMap->GetCurrentKey(&type);
for (map->Rewind(); map->GetNext(&ref);) { for (map->Rewind(); map->GetNext(&ref);) {
map->GetCurrentKey(&item); map->GetCurrentKey(&item);
BPath path(ref); BPath path(ref);
printf(" type \"%s\", item \"%s\", path \"%s\"\n", printf(" type \"%s\", item \"%s\", path \"%s\"\n",
type->String(), item->String(), (path.InitCheck() == B_OK) ? path.Path() : "INVALID"); type->String(), item->String(), (path.InitCheck() == B_OK) ? path.Path() : "INVALID");
} }
} }
printf("MMediaFilesManager: list end\n"); printf("MMediaFilesManager: list end\n");
@ -218,21 +218,21 @@ status_t
MMediaFilesManager::RewindTypes(BString ***types, int32 *count) MMediaFilesManager::RewindTypes(BString ***types, int32 *count)
{ {
CALLED(); CALLED();
if(types==NULL || count == NULL) if (types == NULL || count == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
Map<BString, entry_ref> *map; Map<BString, entry_ref> *map;
BString *type; BString *type = NULL;
*count = fRegistryMap->CountItems(); *count = fRegistryMap->CountItems();
*types = new BString*[*count]; *types = new BString*[*count];
int32 i=0; int32 i = 0;
for (fRegistryMap->Rewind(); i<*count && fRegistryMap->GetNext(&map); i++) { for (fRegistryMap->Rewind(); i < *count && fRegistryMap->GetNext(&map); i++) {
fRegistryMap->GetCurrentKey(&type); fRegistryMap->GetCurrentKey(&type);
(*types)[i] = type; (*types)[i] = type;
} }
return B_OK; return B_OK;
} }
@ -241,87 +241,87 @@ status_t
MMediaFilesManager::RewindRefs(const char* type, BString ***items, int32 *count) MMediaFilesManager::RewindRefs(const char* type, BString ***items, int32 *count)
{ {
CALLED(); CALLED();
if(type == NULL || items==NULL || count == NULL) if (type == NULL || items == NULL || count == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
Map<BString, entry_ref> *map; Map<BString, entry_ref> *map = NULL;
entry_ref *ref; entry_ref *ref;
BString *item; BString *item = NULL;
*count = 0; *count = 0;
*items = NULL; *items = NULL;
if (!fRegistryMap->Get(BString(type), &map)) if (!fRegistryMap->Get(BString(type), &map))
return B_OK; return B_OK;
*count = map->CountItems(); *count = map->CountItems();
*items = new BString*[*count]; *items = new BString*[*count];
int32 i=0; int32 i = 0;
for (map->Rewind(); i<*count && map->GetNext(&ref); i++) { for (map->Rewind(); i < *count && map->GetNext(&ref); i++) {
map->GetCurrentKey(&item); map->GetCurrentKey(&item);
(*items)[i] = item; (*items)[i] = item;
} }
return B_OK; return B_OK;
} }
status_t status_t
MMediaFilesManager::GetRefFor(const char *type, MMediaFilesManager::GetRefFor(const char *type,
const char *item, const char *item,
entry_ref **out_ref) entry_ref **out_ref)
{ {
CALLED(); CALLED();
Map <BString, entry_ref> *map; Map <BString, entry_ref> *map = NULL;
if(!fRegistryMap->Get(BString(type), &map)) if (!fRegistryMap->Get(BString(type), &map))
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
if(!map->Get(BString(item), out_ref)) if (!map->Get(BString(item), out_ref))
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
return B_OK; return B_OK;
} }
status_t status_t
MMediaFilesManager::SetRefFor(const char *type, MMediaFilesManager::SetRefFor(const char *type,
const char *item, const char *item,
const entry_ref &ref, bool save) const entry_ref &ref, bool save)
{ {
CALLED(); CALLED();
TRACE("MMediaFilesManager::SetRefFor %s %s\n", type, item); TRACE("MMediaFilesManager::SetRefFor %s %s\n", type, item);
BString itemString(item); BString itemString(item);
itemString.Truncate(B_MEDIA_NAME_LENGTH); itemString.Truncate(B_MEDIA_NAME_LENGTH);
BString typeString(type); BString typeString(type);
Map <BString, entry_ref> *map; Map <BString, entry_ref> *map;
if(!fRegistryMap->Get(typeString, &map)) { if (!fRegistryMap->Get(typeString, &map)) {
map = new Map<BString, entry_ref>; map = new Map<BString, entry_ref>;
fRegistryMap->Insert(typeString, *map); fRegistryMap->Insert(typeString, *map);
fRegistryMap->Get(typeString, &map); fRegistryMap->Get(typeString, &map);
} }
if(map->Has(itemString)) if (map->Has(itemString))
map->Remove(itemString); map->Remove(itemString);
map->Insert(itemString, ref); map->Insert(itemString, ref);
if(save) if (save)
LaunchTimer(); LaunchTimer();
return B_OK; return B_OK;
} }
status_t status_t
MMediaFilesManager::RemoveRefFor(const char *type, MMediaFilesManager::RemoveRefFor(const char *type,
const char *item, const char *item,
const entry_ref &ref) const entry_ref &ref)
{ {
CALLED(); CALLED();
BString itemString(item); BString itemString(item);
BString typeString(type); BString typeString(type);
Map <BString, entry_ref> *map; Map <BString, entry_ref> *map;
if(fRegistryMap->Get(typeString, &map)) { if (fRegistryMap->Get(typeString, &map)) {
map->Remove(itemString); map->Remove(itemString);
map->Insert(itemString, *(new entry_ref)); map->Insert(itemString, *(new entry_ref));
LaunchTimer(); LaunchTimer();
@ -332,13 +332,13 @@ MMediaFilesManager::RemoveRefFor(const char *type,
status_t status_t
MMediaFilesManager::RemoveItem(const char *type, MMediaFilesManager::RemoveItem(const char *type,
const char *item) const char *item)
{ {
CALLED(); CALLED();
BString itemString(item); BString itemString(item);
BString typeString(type); BString typeString(type);
Map <BString, entry_ref> *map; Map <BString, entry_ref> *map;
if(fRegistryMap->Get(typeString, &map)) { if (fRegistryMap->Get(typeString, &map)) {
map->Remove(itemString); map->Remove(itemString);
LaunchTimer(); LaunchTimer();
} }
@ -349,9 +349,9 @@ MMediaFilesManager::RemoveItem(const char *type,
void void
MMediaFilesManager::LaunchTimer() MMediaFilesManager::LaunchTimer()
{ {
if(!fRunner) if (!fRunner)
fRunner = new BMessageRunner(be_app, fRunner = new BMessageRunner(be_app,
new BMessage(MMEDIAFILESMANAGER_SAVE_TIMER), 3 * 1000000, 1); new BMessage(MMEDIAFILESMANAGER_SAVE_TIMER), 3 * 1000000LL, 1);
} }
@ -360,6 +360,6 @@ MMediaFilesManager::TimerMessage()
{ {
SaveState(); SaveState();
delete fRunner; delete fRunner;
fRunner = NULL; fRunner = NULL;
} }

View File

@ -1,4 +1,4 @@
/* /*
* Copyright 2003, Jérôme Duval. All rights reserved. * Copyright 2003, Jérôme Duval. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@ -15,52 +15,52 @@
class MMediaFilesManager class MMediaFilesManager
{ {
public: public:
MMediaFilesManager(); MMediaFilesManager();
~MMediaFilesManager(); ~MMediaFilesManager();
status_t LoadState(); status_t LoadState();
status_t SaveState(); status_t SaveState();
void Dump(); void Dump();
status_t RewindTypes(
BString ***types,
int32 *count);
status_t RewindRefs(
const char * type,
BString ***items,
int32 *count);
status_t GetRefFor(
const char * type,
const char * item,
entry_ref ** out_ref);
status_t SetRefFor(
const char * type,
const char * item,
const entry_ref & ref,
bool save = true);
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);
status_t RemoveItem( // new in 4.1, removes the whole item. status_t RewindTypes(
const char * type, BString ***types,
const char * item); int32 *count);
status_t RewindRefs(
const char * type,
BString ***items,
int32 *count);
status_t GetRefFor(
const char * type,
const char * item,
entry_ref ** out_ref);
status_t SetRefFor(
const char * type,
const char * item,
const entry_ref & ref,
bool save = true);
status_t RemoveRefFor(
const char * type,
const char * item,
const entry_ref & ref);
void TimerMessage(); status_t RemoveItem(
const char * type,
const char * item);
private: void TimerMessage();
static int32 ReadPascalString(BFile &file, char **str);
static int32 WritePascalString(BFile &file, const char *str); private:
void LaunchTimer(); static int32 ReadPascalString(BFile &file, char **str);
private: static int32 WritePascalString(BFile &file, const char *str);
BLocker *fLocker; void LaunchTimer();
private:
Map<BString, Map<BString, entry_ref> > * fRegistryMap; BLocker *fLocker;
uint32 header[3]; Map<BString, Map<BString, entry_ref> > * fRegistryMap;
BMessageRunner *fRunner; uint32 header[3];
BMessageRunner *fRunner;
}; };