From 88ec4b1dbe66575e225e60b230f99c6cbd0005de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sun, 15 Apr 2007 13:59:59 +0000 Subject: [PATCH] fixed some warnings code style of MMediaFilesManager.* git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20703 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/media/DecoderPlugin.h | 1 + src/kits/media/PluginManager.cpp | 2 +- src/servers/media/MMediaFilesManager.cpp | 228 +++++++++++------------ src/servers/media/MMediaFilesManager.h | 88 ++++----- 4 files changed, 160 insertions(+), 159 deletions(-) diff --git a/headers/private/media/DecoderPlugin.h b/headers/private/media/DecoderPlugin.h index 6aed9b1079..ec13c99422 100644 --- a/headers/private/media/DecoderPlugin.h +++ b/headers/private/media/DecoderPlugin.h @@ -11,6 +11,7 @@ namespace BPrivate { namespace media { class ChunkProvider { public: + virtual ~ChunkProvider() {}; virtual status_t GetNextChunk(const void **chunkBuffer, size_t *chunkSize, media_header *mediaHeader) = 0; }; diff --git a/src/kits/media/PluginManager.cpp b/src/kits/media/PluginManager.cpp index 9237b8cbdf..5c4d77a8ba 100644 --- a/src/kits/media/PluginManager.cpp +++ b/src/kits/media/PluginManager.cpp @@ -143,7 +143,7 @@ PluginManager::~PluginManager() { CALLED(); while (!fPluginList->IsEmpty()) { - plugin_info *info; + plugin_info *info = NULL; fPluginList->Get(fPluginList->CountItems() - 1, &info); printf("PluginManager: Error, unloading PlugIn %s with usecount %d\n", info->name, info->usecount); delete info->plugin; diff --git a/src/servers/media/MMediaFilesManager.cpp b/src/servers/media/MMediaFilesManager.cpp index e5a9d3c267..5ca16f30fb 100644 --- a/src/servers/media/MMediaFilesManager.cpp +++ b/src/servers/media/MMediaFilesManager.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright 2003, Jérôme Duval. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -12,7 +12,7 @@ MMediaFilesManager::MMediaFilesManager() - : fLocker(new BLocker("media files manager locker")), + : fLocker(new BLocker("media files manager locker")), fRegistryMap(new Map >), fRunner(NULL) { @@ -32,38 +32,38 @@ MMediaFilesManager::~MMediaFilesManager() } -int32 +int32 MMediaFilesManager::ReadPascalString(BFile &file, char **str) { uint32 len; - *str=NULL; + *str = NULL; if (file.Read(&len, 4) < 4) - return -1; + return -1; if (len == 0) - return 0; + return 0; *str = (char *)malloc(len); if (file.Read(*str, len) < (int32)len) { - free(*str); - *str = NULL; - return -1; + free(*str); + *str = NULL; + return -1; } return (int32)len; } -int32 +int32 MMediaFilesManager::WritePascalString(BFile &file, const char *str) { - - if(str == NULL) - return -1; + + if (str == NULL) + return -1; uint32 len = strlen(str) + 1; if (file.Write(&len, 4) < 4) - return -1; + return -1; if (len == 0) - return 0; + return 0; if (file.Write(str, len) < (int32)len) { - return -1; + return -1; } return (int32)len; } @@ -76,16 +76,16 @@ MMediaFilesManager::LoadState() CALLED(); status_t err = B_OK; 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; - + path.Append("Media/MMediaFilesManager"); - + BFile file(path.Path(), B_READ_ONLY); - + uint32 category_count; - if (file.Read(header, sizeof(uint32)*3) < (int32)sizeof(uint32)*3) { - header[0] = 0xac00150c; + if (file.Read(header, sizeof(uint32)*3) < (int32)sizeof(uint32)*3) { + header[0] = 0xac00150c; header[1] = 0x18723462; header[2] = 0x00000001; return B_ERROR; @@ -106,35 +106,35 @@ MMediaFilesManager::LoadState() break; TRACE("%s {\n", str); do { - len = ReadPascalString(file, &key); - if (len < 0) - return B_ERROR; - if (len == 0) - break; - len = ReadPascalString(file, &val); - if (len == 1) { - free(val); - val = strdup("(null)"); - } - /*if (file.Read(&vol, sizeof(uint32)) < (int32)sizeof(uint32)) - return B_ERROR;*/ - //TRACE(" %s: %s, volume: %f\n", key, val, *(float *)&vol); - - entry_ref ref; - if(len>1) { - BEntry entry(val); - if(entry.Exists()) - entry.GetRef(&ref); - } - SetRefFor(str, key, ref, false); - - free(key); - free(val); + len = ReadPascalString(file, &key); + if (len < 0) + return B_ERROR; + if (len == 0) + break; + len = ReadPascalString(file, &val); + if (len == 1) { + free(val); + val = strdup("(null)"); + } + /*if (file.Read(&vol, sizeof(uint32)) < (int32)sizeof(uint32)) + return B_ERROR;*/ + //TRACE(" %s: %s, volume: %f\n", key, val, *(float *)&vol); + + entry_ref ref; + if (len > 1) { + BEntry entry(val); + if (entry.Exists()) + entry.GetRef(&ref); + } + SetRefFor(str, key, ref, false); + + free(key); + free(val); } while (true); TRACE("}\n"); free(str); } - + return B_OK; } @@ -145,42 +145,42 @@ MMediaFilesManager::SaveState() CALLED(); status_t err = B_OK; 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; - + path.Append("Media/MMediaFilesManager"); - + BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE); uint32 zero = 0; - + if (file.Write(header, sizeof(uint32)*3) < (int32)sizeof(uint32)*3) return B_ERROR; 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; - - BString *type; + + BString *type = NULL; Map *map; - BString *item; + BString *item = NULL; entry_ref *ref; - for (fRegistryMap->Rewind(); fRegistryMap->GetNext(&map); ) { + for (fRegistryMap->Rewind(); fRegistryMap->GetNext(&map);) { fRegistryMap->GetCurrentKey(&type); - + WritePascalString(file, type->String()); - + for (map->Rewind(); map->GetNext(&ref);) { map->GetCurrentKey(&item); BPath path(ref); - + WritePascalString(file, item->String()); WritePascalString(file, path.Path() ? path.Path() : ""); - + } - + file.Write(&zero, sizeof(uint32)); } file.Write(&zero, sizeof(uint32)); - + return B_OK; } @@ -190,22 +190,22 @@ MMediaFilesManager::Dump() { BAutolock lock(fLocker); printf("\n"); - + /* for each type, the registry map contains a map of item/entry_ref */ printf("MMediaFilesManager: registry map follows\n"); - BString *type; + BString *type = NULL; Map *map; - BString *item; + BString *item = NULL; entry_ref *ref; - for (fRegistryMap->Rewind(); fRegistryMap->GetNext(&map); ) { + for (fRegistryMap->Rewind(); fRegistryMap->GetNext(&map);) { fRegistryMap->GetCurrentKey(&type); - + for (map->Rewind(); map->GetNext(&ref);) { map->GetCurrentKey(&item); BPath path(ref); - printf(" type \"%s\", item \"%s\", path \"%s\"\n", - type->String(), item->String(), (path.InitCheck() == B_OK) ? path.Path() : "INVALID"); + printf(" type \"%s\", item \"%s\", path \"%s\"\n", + type->String(), item->String(), (path.InitCheck() == B_OK) ? path.Path() : "INVALID"); } } printf("MMediaFilesManager: list end\n"); @@ -218,21 +218,21 @@ status_t MMediaFilesManager::RewindTypes(BString ***types, int32 *count) { CALLED(); - if(types==NULL || count == NULL) + if (types == NULL || count == NULL) return B_BAD_VALUE; - + Map *map; - BString *type; - + BString *type = NULL; + *count = fRegistryMap->CountItems(); *types = new BString*[*count]; - int32 i=0; - - for (fRegistryMap->Rewind(); i<*count && fRegistryMap->GetNext(&map); i++) { + int32 i = 0; + + for (fRegistryMap->Rewind(); i < *count && fRegistryMap->GetNext(&map); i++) { fRegistryMap->GetCurrentKey(&type); - (*types)[i] = type; + (*types)[i] = type; } - + return B_OK; } @@ -241,87 +241,87 @@ status_t MMediaFilesManager::RewindRefs(const char* type, BString ***items, int32 *count) { CALLED(); - if(type == NULL || items==NULL || count == NULL) + if (type == NULL || items == NULL || count == NULL) return B_BAD_VALUE; - - Map *map; + + Map *map = NULL; entry_ref *ref; - BString *item; - + BString *item = NULL; + *count = 0; *items = NULL; - + if (!fRegistryMap->Get(BString(type), &map)) return B_OK; - + *count = map->CountItems(); *items = new BString*[*count]; - int32 i=0; - - for (map->Rewind(); i<*count && map->GetNext(&ref); i++) { + int32 i = 0; + + for (map->Rewind(); i < *count && map->GetNext(&ref); i++) { map->GetCurrentKey(&item); - (*items)[i] = item; + (*items)[i] = item; } - + return B_OK; } status_t MMediaFilesManager::GetRefFor(const char *type, - const char *item, - entry_ref **out_ref) + const char *item, + entry_ref **out_ref) { CALLED(); - Map *map; - if(!fRegistryMap->Get(BString(type), &map)) + Map *map = NULL; + if (!fRegistryMap->Get(BString(type), &map)) 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_OK; } status_t MMediaFilesManager::SetRefFor(const char *type, - const char *item, - const entry_ref &ref, bool save) + const char *item, + const entry_ref &ref, bool save) { CALLED(); TRACE("MMediaFilesManager::SetRefFor %s %s\n", type, item); - + BString itemString(item); itemString.Truncate(B_MEDIA_NAME_LENGTH); BString typeString(type); Map *map; - if(!fRegistryMap->Get(typeString, &map)) { + if (!fRegistryMap->Get(typeString, &map)) { map = new 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->Insert(itemString, ref); - if(save) + if (save) LaunchTimer(); - + return B_OK; } status_t MMediaFilesManager::RemoveRefFor(const char *type, - const char *item, - const entry_ref &ref) + const char *item, + const entry_ref &ref) { CALLED(); BString itemString(item); BString typeString(type); Map *map; - if(fRegistryMap->Get(typeString, &map)) { + if (fRegistryMap->Get(typeString, &map)) { map->Remove(itemString); map->Insert(itemString, *(new entry_ref)); LaunchTimer(); @@ -332,13 +332,13 @@ MMediaFilesManager::RemoveRefFor(const char *type, status_t MMediaFilesManager::RemoveItem(const char *type, - const char *item) + const char *item) { CALLED(); BString itemString(item); BString typeString(type); Map *map; - if(fRegistryMap->Get(typeString, &map)) { + if (fRegistryMap->Get(typeString, &map)) { map->Remove(itemString); LaunchTimer(); } @@ -349,9 +349,9 @@ MMediaFilesManager::RemoveItem(const char *type, void MMediaFilesManager::LaunchTimer() { - if(!fRunner) - fRunner = new BMessageRunner(be_app, - new BMessage(MMEDIAFILESMANAGER_SAVE_TIMER), 3 * 1000000, 1); + if (!fRunner) + fRunner = new BMessageRunner(be_app, + new BMessage(MMEDIAFILESMANAGER_SAVE_TIMER), 3 * 1000000LL, 1); } @@ -360,6 +360,6 @@ MMediaFilesManager::TimerMessage() { SaveState(); delete fRunner; - fRunner = NULL; + fRunner = NULL; } diff --git a/src/servers/media/MMediaFilesManager.h b/src/servers/media/MMediaFilesManager.h index 90f9683f81..3fa294fc5b 100644 --- a/src/servers/media/MMediaFilesManager.h +++ b/src/servers/media/MMediaFilesManager.h @@ -1,4 +1,4 @@ -/* +/* * Copyright 2003, Jérôme Duval. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -15,52 +15,52 @@ class MMediaFilesManager { -public: - MMediaFilesManager(); - ~MMediaFilesManager(); + public: + MMediaFilesManager(); + ~MMediaFilesManager(); - status_t LoadState(); - status_t SaveState(); + status_t LoadState(); + status_t SaveState(); - 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); + void Dump(); - status_t RemoveItem( // new in 4.1, removes the whole item. - const char * type, - const char * item); + 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( + const char * type, + const char * item, + const entry_ref & ref); - void TimerMessage(); + status_t RemoveItem( + const char * type, + const char * item); -private: - static int32 ReadPascalString(BFile &file, char **str); - static int32 WritePascalString(BFile &file, const char *str); - void LaunchTimer(); -private: - BLocker *fLocker; - - Map > * fRegistryMap; - - uint32 header[3]; - - BMessageRunner *fRunner; + void TimerMessage(); + + private: + static int32 ReadPascalString(BFile &file, char **str); + static int32 WritePascalString(BFile &file, const char *str); + void LaunchTimer(); + private: + BLocker *fLocker; + + Map > * fRegistryMap; + + uint32 header[3]; + + BMessageRunner *fRunner; };