Added a 3 seconds delayed save to disk
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5349 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
|
#include <Application.h>
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <storage/FindDirectory.h>
|
#include <storage/FindDirectory.h>
|
||||||
@@ -12,7 +13,8 @@
|
|||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
LoadState();
|
LoadState();
|
||||||
@@ -24,6 +26,7 @@ MMediaFilesManager::MMediaFilesManager()
|
|||||||
MMediaFilesManager::~MMediaFilesManager()
|
MMediaFilesManager::~MMediaFilesManager()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
delete fRunner;
|
||||||
SaveState();
|
SaveState();
|
||||||
delete fRegistryMap;
|
delete fRegistryMap;
|
||||||
delete fLocker;
|
delete fLocker;
|
||||||
@@ -120,7 +123,7 @@ MMediaFilesManager::LoadState()
|
|||||||
BEntry entry(val);
|
BEntry entry(val);
|
||||||
entry.GetRef(&ref);
|
entry.GetRef(&ref);
|
||||||
}
|
}
|
||||||
SetRefFor(str, key, ref);
|
SetRefFor(str, key, ref, false);
|
||||||
|
|
||||||
free(key);
|
free(key);
|
||||||
free(val);
|
free(val);
|
||||||
@@ -276,7 +279,7 @@ MMediaFilesManager::GetRefFor(const char *type,
|
|||||||
status_t
|
status_t
|
||||||
MMediaFilesManager::SetRefFor(const char *type,
|
MMediaFilesManager::SetRefFor(const char *type,
|
||||||
const char *item,
|
const char *item,
|
||||||
const entry_ref &ref)
|
const entry_ref &ref, bool save)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
TRACE("MMediaFilesManager::SetRefFor %s %s\n", type, item);
|
TRACE("MMediaFilesManager::SetRefFor %s %s\n", type, item);
|
||||||
@@ -294,6 +297,8 @@ MMediaFilesManager::SetRefFor(const char *type,
|
|||||||
if(map->Has(itemString))
|
if(map->Has(itemString))
|
||||||
map->Remove(itemString);
|
map->Remove(itemString);
|
||||||
map->Insert(itemString, ref);
|
map->Insert(itemString, ref);
|
||||||
|
if(save)
|
||||||
|
LaunchTimer();
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -308,12 +313,11 @@ MMediaFilesManager::RemoveRefFor(const char *type,
|
|||||||
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)) {
|
||||||
return B_OK;
|
map->Remove(itemString);
|
||||||
|
map->Insert(itemString, *(new entry_ref));
|
||||||
map->Remove(itemString);
|
LaunchTimer();
|
||||||
map->Insert(itemString, *(new entry_ref));
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,11 +330,25 @@ MMediaFilesManager::RemoveItem(const char *type,
|
|||||||
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)) {
|
||||||
return B_OK;
|
map->Remove(itemString);
|
||||||
|
LaunchTimer();
|
||||||
map->Remove(itemString);
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MMediaFilesManager::LaunchTimer()
|
||||||
|
{
|
||||||
|
if(!fRunner)
|
||||||
|
fRunner = new BMessageRunner(be_app,
|
||||||
|
new BMessage(MMEDIAFILESMANAGER_SAVE_TIMER), 3 * 1000000, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MMediaFilesManager::TimerMessage()
|
||||||
|
{
|
||||||
|
SaveState();
|
||||||
|
delete fRunner;
|
||||||
|
fRunner = NULL;
|
||||||
|
}
|
||||||
@@ -6,10 +6,13 @@
|
|||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
|
#include <MessageRunner.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include "TMap.h"
|
#include "TMap.h"
|
||||||
#include "DataExchange.h"
|
#include "DataExchange.h"
|
||||||
|
|
||||||
|
#define MMEDIAFILESMANAGER_SAVE_TIMER 'mmst'
|
||||||
|
|
||||||
class MMediaFilesManager
|
class MMediaFilesManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -35,7 +38,8 @@ public:
|
|||||||
status_t SetRefFor(
|
status_t SetRefFor(
|
||||||
const char * type,
|
const char * type,
|
||||||
const char * item,
|
const char * item,
|
||||||
const entry_ref & ref);
|
const entry_ref & ref,
|
||||||
|
bool save = true);
|
||||||
status_t RemoveRefFor( // This might better be called "ClearRefFor"
|
status_t RemoveRefFor( // This might better be called "ClearRefFor"
|
||||||
const char * type, // but it's too late now...
|
const char * type, // but it's too late now...
|
||||||
const char * item,
|
const char * item,
|
||||||
@@ -45,15 +49,18 @@ public:
|
|||||||
const char * type,
|
const char * type,
|
||||||
const char * item);
|
const char * item);
|
||||||
|
|
||||||
|
void TimerMessage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int32 ReadPascalString(BFile &file, char **str);
|
static int32 ReadPascalString(BFile &file, char **str);
|
||||||
static int32 WritePascalString(BFile &file, const char *str);
|
static int32 WritePascalString(BFile &file, const char *str);
|
||||||
|
void LaunchTimer();
|
||||||
private:
|
private:
|
||||||
BLocker *fLocker;
|
BLocker *fLocker;
|
||||||
|
|
||||||
Map<BString, Map<BString, entry_ref> > * fRegistryMap;
|
Map<BString, Map<BString, entry_ref> > * fRegistryMap;
|
||||||
|
|
||||||
uint32 header[3];
|
uint32 header[3];
|
||||||
|
|
||||||
|
BMessageRunner *fRunner;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -698,6 +698,7 @@ void ServerApp::MessageReceived(BMessage *msg)
|
|||||||
case MEDIA_SERVER_REQUEST_NOTIFICATIONS: gNotificationManager->EnqueueMessage(msg); break;
|
case MEDIA_SERVER_REQUEST_NOTIFICATIONS: gNotificationManager->EnqueueMessage(msg); break;
|
||||||
case MEDIA_SERVER_CANCEL_NOTIFICATIONS: gNotificationManager->EnqueueMessage(msg); break;
|
case MEDIA_SERVER_CANCEL_NOTIFICATIONS: gNotificationManager->EnqueueMessage(msg); break;
|
||||||
case MEDIA_SERVER_SEND_NOTIFICATIONS: gNotificationManager->EnqueueMessage(msg); break;
|
case MEDIA_SERVER_SEND_NOTIFICATIONS: gNotificationManager->EnqueueMessage(msg); break;
|
||||||
|
case MMEDIAFILESMANAGER_SAVE_TIMER: gMMediaFilesManager->TimerMessage(); break;
|
||||||
default:
|
default:
|
||||||
printf("\nnew media server: unknown message received\n");
|
printf("\nnew media server: unknown message received\n");
|
||||||
msg->PrintToStream();
|
msg->PrintToStream();
|
||||||
|
|||||||
Reference in New Issue
Block a user