RamDiskInterface Class Reference

#include <ramdisk.h>

Inheritance diagram for RamDiskInterface:

Detailed Description

A RamDisk provides a complete in-memory file system. It supports a Clone method to efficiently duplicate a whole file system.

Public Types

using ContentCreator = Delegate< Result< IoMemoryRef >()>
 
using PermissionChecker = Delegate< Result< void >(const Url &url)>
 

Public Member Functions

MAXON_METHOD Result< UrlGetRoot ()
 
MAXON_METHOD Result< FileUtilities::ReadDirectoryTreeReceiverMount (const Block< const String > &mountPoint, const Url &source, const Url &cache)
 
MAXON_METHOD Result< UrlCreateLazyFile (const Block< const String > &path, ContentCreator &&creator)
 
MAXON_METHOD Result< void > SetPermissions (PermissionChecker &&permissions)
 
 MAXON_OBSERVABLE (void, ObservableLoadIntoCacheChange,(const RamDiskRef &ramDisk, Bool finished), ObservableCombinerRunAllComponent)
 
MAXON_METHOD Result< void > ChangeMirrorPath (const Url &oldBase, const Url &newBase)
 
MAXON_METHOD Result< FileUtilities::ReadDirectoryTreeReceiverUpdateMount (const Block< const String > &mountPoint, const Url &source, const Url &cache)
 

Static Public Member Functions

static MAXON_METHOD Result< Tuple< Bool, Url > > IsInCache (const Url &url)
 
static MAXON_METHOD Result< void > LoadIntoCache (const Url &url, const IoProgressDelegate &progress)
 
static MAXON_METHOD Result< void > RemoveFromCache (const Url &url)
 
static MAXON_METHOD Result< RamDiskRef > Create ()
 
static MAXON_METHOD Result< RamDiskRef > Create (const String &ramdiskId)
 
static MAXON_METHOD Result< void > ChangeRamDiskMirrorPath (const Url &oldBase, const Url &newBase)
 
static MAXON_METHOD RamDiskRef FindExisting (const String &ramdiskId)
 

Private Member Functions

 MAXON_INTERFACE (RamDiskInterface, MAXON_REFERENCE_NORMAL, "net.maxon.misc.interface.ramdisk")
 

Member Typedef Documentation

◆ ContentCreator

using ContentCreator = Delegate<Result<IoMemoryRef>()>

◆ PermissionChecker

using PermissionChecker = Delegate<Result<void>(const Url& url)>

Member Function Documentation

◆ MAXON_INTERFACE()

MAXON_INTERFACE ( RamDiskInterface  ,
MAXON_REFERENCE_NORMAL  ,
"net.maxon.misc.interface.ramdisk"   
)
private

◆ GetRoot()

MAXON_METHOD Result<Url> GetRoot ( )

Returns the Url of the root directory of this RAM disk. The Url has the ramdisk scheme and uses the unique identifier of the RAM disk as authority. Also the returned Url contains a strong reference on this RAM disk, so it suffices to keep the Url alive to keep this RAM disk alive. Likewise all Urls which are derived from the returned Url will contain a strong reference on this RAM disk.

Returns
The Url of this RAM disk's root directory.

◆ Mount()

MAXON_METHOD Result<FileUtilities::ReadDirectoryTreeReceiver> Mount ( const Block< const String > &  mountPoint,
const Url source,
const Url cache 
)

Mounts the external directory source at the path given by mountPoint. This makes the Url hierarchy of source accessible (including browsing) via this RAM disk. But you have to tell the RAM disk which Urls exist under source by subsequent invocations of the returned ReadDirectoryTreeReceiver. This allows to convert non-browsable Urls such as https to browsable Urls if you can provide the list of nested Urls which shall be accessible.

In addition, you can also set a cache path which will be used to cache content loaded from source. This could be a Url for a local directory to cache files downloaded from a https source.

This mount function will return an error if a file which would be mounted already exists, use UpdateMount below in order to update the mount with new files and keep existing files.

Parameters
[in]mountPointThe path where the source directory shall be mounted. Children of the source directory will be children of this path.
[in]sourceThe source directory.
[in]cacheAn optional directory to use for caching files downloaded from source.
Returns
A ReadDirectoryTreeReceiver which you have to provide with the list of files (within the hierarchy of source) you want to mount.

◆ CreateLazyFile()

MAXON_METHOD Result<Url> CreateLazyFile ( const Block< const String > &  path,
ContentCreator &&  creator 
)

Creates a Url for a file whose content is created lazily by the creator Delegate.

Parameters
[in]pathThe path of the file to be created. The file mustn't exist yet.
[in]creatorThe delegate which will create the file's content on first access.
Returns
The Url for the file.

◆ SetPermissions()

MAXON_METHOD Result<void> SetPermissions ( PermissionChecker &&  permissions)

Sets the permission checker for this RAM disk.

Parameters
[in]permissionsDelegate which gets called to check for valid permissions whenever a stream is opened.

◆ MAXON_OBSERVABLE()

MAXON_OBSERVABLE ( void  ,
ObservableLoadIntoCacheChange  ,
(const RamDiskRef &ramDisk, Bool finished)  ,
ObservableCombinerRunAllComponent   
)

◆ IsInCache()

static MAXON_METHOD Result<Tuple<Bool, Url> > IsInCache ( const Url url)
static

IsInCache allows to detect if the url is cached.

Parameters
[in]urlUrl to detect.
Returns
Returns the url of the cache if the file cached. If empty no cache exists.

◆ LoadIntoCache()

static MAXON_METHOD Result<void> LoadIntoCache ( const Url url,
const IoProgressDelegate progress 
)
static

◆ RemoveFromCache()

static MAXON_METHOD Result<void> RemoveFromCache ( const Url url)
static

◆ Create() [1/2]

static MAXON_METHOD Result<RamDiskRef> Create ( )
static

◆ Create() [2/2]

static MAXON_METHOD Result<RamDiskRef> Create ( const String ramdiskId)
static

◆ ChangeMirrorPath()

MAXON_METHOD Result<void> ChangeMirrorPath ( const Url oldBase,
const Url newBase 
)

◆ ChangeRamDiskMirrorPath()

static MAXON_METHOD Result<void> ChangeRamDiskMirrorPath ( const Url oldBase,
const Url newBase 
)
static

◆ FindExisting()

static MAXON_METHOD RamDiskRef FindExisting ( const String ramdiskId)
static

FindExisting returns an existing ram disk.

Parameters
[in]ramdiskIdId to find.
Returns
RamDiskRef on success. Otherwise nullptr.

◆ UpdateMount()

MAXON_METHOD Result<FileUtilities::ReadDirectoryTreeReceiver> UpdateMount ( const Block< const String > &  mountPoint,
const Url source,
const Url cache 
)

Mounts the external directory source at the path given by mountPoint, or updates an existing mount. This does the same as Mount, but will not return an error in case of hitting existing files. This allows to update an existing mount with new files while keeping existing files.

Parameters
[in]mountPointThe path where the source directory shall be mounted. Children of the source directory will be children of this path.
[in]sourceThe source directory.
[in]cacheAn optional directory to use for caching files downloaded from source.
Returns
A ReadDirectoryTreeReceiver which you have to provide with the list of files (within the hierarchy of source) you want to mount.