2007-01-26 19:36:29 +03:00
|
|
|
/*
|
2010-07-08 18:54:25 +04:00
|
|
|
* Copyright 2001-2010, Haiku, Inc. All Rights Reserved.
|
2007-01-26 19:36:29 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-07-09 16:24:59 +04:00
|
|
|
#ifndef _ARCHIVABLE_H
|
|
|
|
#define _ARCHIVABLE_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <image.h>
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
|
|
|
|
|
|
|
class BMessage;
|
|
|
|
|
2010-07-08 18:54:25 +04:00
|
|
|
namespace BPrivate {
|
|
|
|
namespace Archiving {
|
|
|
|
class BArchiveManager;
|
|
|
|
class BUnarchiveManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
using BPrivate::Archiving::BArchiveManager;
|
|
|
|
using BPrivate::Archiving::BUnarchiveManager;
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2007-01-26 19:36:29 +03:00
|
|
|
class BArchivable {
|
2010-07-08 18:54:25 +04:00
|
|
|
public:
|
2010-07-08 19:04:38 +04:00
|
|
|
BArchivable(BMessage* from);
|
|
|
|
BArchivable();
|
|
|
|
virtual ~BArchivable();
|
2010-07-08 18:54:25 +04:00
|
|
|
|
2010-07-08 19:04:38 +04:00
|
|
|
virtual status_t Archive(BMessage* into, bool deep = true) const;
|
|
|
|
static BArchivable* Instantiate(BMessage* archive);
|
2010-07-08 18:54:25 +04:00
|
|
|
|
2010-07-08 19:04:38 +04:00
|
|
|
virtual status_t Perform(perform_code d, void* arg);
|
2010-07-08 18:54:25 +04:00
|
|
|
|
2010-07-08 19:04:38 +04:00
|
|
|
virtual status_t AllUnarchived(const BMessage* archive);
|
|
|
|
virtual status_t AllArchived(BMessage* archive) const;
|
2010-07-08 18:54:25 +04:00
|
|
|
|
|
|
|
private:
|
2010-07-08 19:04:38 +04:00
|
|
|
virtual void _ReservedArchivable3();
|
2010-07-08 18:54:25 +04:00
|
|
|
|
2010-07-08 19:04:38 +04:00
|
|
|
uint32 _reserved[2];
|
2010-07-08 18:54:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BArchiver {
|
|
|
|
public:
|
2010-07-08 19:04:38 +04:00
|
|
|
BArchiver(BMessage* archive);
|
|
|
|
~BArchiver();
|
2010-07-08 18:54:25 +04:00
|
|
|
|
2010-07-08 19:04:38 +04:00
|
|
|
status_t AddArchivable(const char* name,
|
|
|
|
BArchivable* archivable, bool deep = true);
|
2010-07-08 18:54:25 +04:00
|
|
|
|
2010-07-08 19:04:38 +04:00
|
|
|
status_t GetTokenForArchivable(BArchivable* archivable,
|
|
|
|
int32& _token, bool deep = true);
|
2010-07-08 18:54:25 +04:00
|
|
|
|
2010-07-08 19:04:38 +04:00
|
|
|
bool IsArchived(BArchivable* archivable);
|
|
|
|
status_t Finish();
|
|
|
|
BMessage* ArchiveMessage() const;
|
2010-07-08 18:54:25 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class BArchivable;
|
|
|
|
|
2010-07-08 19:04:38 +04:00
|
|
|
BArchiver(); // not defined
|
|
|
|
BArchiver(const BArchiver&); // not defined
|
2010-07-08 18:54:25 +04:00
|
|
|
|
2010-07-08 19:04:38 +04:00
|
|
|
void RegisterArchivable(
|
|
|
|
const BArchivable* archivable);
|
2010-07-08 18:54:25 +04:00
|
|
|
|
2010-07-08 19:04:38 +04:00
|
|
|
BArchiveManager* fManager;
|
|
|
|
BMessage* fArchive;
|
|
|
|
bool fFinished;
|
2010-07-08 18:54:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BUnarchiver {
|
|
|
|
public:
|
|
|
|
BUnarchiver(const BMessage* archive);
|
|
|
|
~BUnarchiver();
|
|
|
|
|
|
|
|
status_t GetArchivable(int32 token,
|
|
|
|
BArchivable** archivable);
|
|
|
|
|
|
|
|
status_t FindArchivable(const char* name,
|
|
|
|
BArchivable** archivable);
|
|
|
|
|
|
|
|
status_t FindArchivable(const char* name, int32 index,
|
|
|
|
BArchivable** archivable);
|
|
|
|
|
|
|
|
status_t EnsureUnarchived(const char* name,
|
|
|
|
int32 index = 0);
|
|
|
|
status_t EnsureUnarchived(int32 token);
|
|
|
|
|
|
|
|
bool IsInstantiated(int32 token);
|
|
|
|
bool IsInstantiated(const char* name,
|
|
|
|
int32 index = 0);
|
|
|
|
|
|
|
|
status_t Finish();
|
|
|
|
const BMessage* ArchiveMessage() const;
|
|
|
|
|
|
|
|
static bool IsArchiveManaged(BMessage* archive);
|
|
|
|
static BMessage* PrepareArchive(BMessage*& archive);
|
2010-07-08 19:04:38 +04:00
|
|
|
|
2010-07-08 18:54:25 +04:00
|
|
|
private:
|
|
|
|
friend class BArchivable;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2010-07-08 18:54:25 +04:00
|
|
|
BUnarchiver(); // not defined
|
|
|
|
BUnarchiver(const BUnarchiver&); // not defined
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2010-07-08 18:54:25 +04:00
|
|
|
void RegisterArchivable(BArchivable* archivable);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2010-07-08 18:54:25 +04:00
|
|
|
void _CallDebuggerIfManagerNull();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2010-07-08 18:54:25 +04:00
|
|
|
BUnarchiveManager* fManager;
|
|
|
|
const BMessage* fArchive;
|
|
|
|
bool fFinished;
|
2002-07-09 16:24:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-01-26 19:36:29 +03:00
|
|
|
// global functions
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2007-01-26 19:36:29 +03:00
|
|
|
typedef BArchivable* (*instantiation_func)(BMessage*);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2010-07-08 18:54:25 +04:00
|
|
|
BArchivable* instantiate_object(BMessage* from, image_id* id);
|
|
|
|
BArchivable* instantiate_object(BMessage* from);
|
2007-01-26 19:36:29 +03:00
|
|
|
bool validate_instantiation(BMessage* from, const char* className);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2007-01-26 19:36:29 +03:00
|
|
|
instantiation_func find_instantiation_func(const char* className,
|
|
|
|
const char* signature);
|
|
|
|
instantiation_func find_instantiation_func(const char* className);
|
|
|
|
instantiation_func find_instantiation_func(BMessage* archive);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
#endif // _ARCHIVABLE_H
|