Refactor mjVFS and resource management.
Resource operations (e.g. mju_openResource, mju_readResource, and mju_closeResource, etc.) are now all handled by a VFS instance. It is now up to the VFS to determine which provider to use in order to handle those operations. This allows us to dynamically add/remove (aka "mount") providers to a VFS to handle special requests. mj_addFileVFS and mj_addBufferVFS have been reimplemented as two such use-cases. Moreover, we expose the mounting behaviour with two new functions: mj_mountVFS and mj_unmountVFS. PiperOrigin-RevId: 861550939 Change-Id: I070eb4bcc2982466c8f368f7918005538baa5185
This commit is contained in:
committed by
Copybara-Service
parent
e977b0d660
commit
0ddbb46fa1
@@ -1357,6 +1357,25 @@ The VFS must first be allocated using :ref:`mj_defaultVFS` and must be freed wit
|
||||
|
||||
Initialize an empty VFS, :ref:`mj_deleteVFS` must be called to deallocate the VFS.
|
||||
|
||||
.. _mj_mountVFS:
|
||||
|
||||
`mj_mountVFS <#mj_mountVFS>`__
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. mujoco-include:: mj_mountVFS
|
||||
|
||||
Mount a ResourceProvider to handle file operations under the given path; return 0: success,
|
||||
2: repeated name, -1: invalid resource provider.
|
||||
|
||||
.. _mj_unmountVFS:
|
||||
|
||||
`mj_unmountVFS <#mj_unmountVFS>`__
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. mujoco-include:: mj_unmountVFS
|
||||
|
||||
Unmount a previously mounted ResourceProvider; return 0: success, -1: not found in VFS.
|
||||
|
||||
.. _mj_addFileVFS:
|
||||
|
||||
`mj_addFileVFS <#mj_addFileVFS>`__
|
||||
|
||||
@@ -54,6 +54,8 @@ General
|
||||
See :ref:`rangefinder<sensor-rangefinder>` for details.
|
||||
- Cameras now have an :ref:`output<body-camera-output>` attribute, parsed into the ``mjModel.cam_output`` bitfield.
|
||||
Unused by the renderer, it serves as a convenient location to store a camera's supported output types.
|
||||
- Added :ref:`mj_mountVFS` and :ref:`mj_unmountVFS` functions for mounting a custom VFS provider. Mounting Allows
|
||||
providers to be used to open/read/close resources dynamically at arbitrary paths.
|
||||
- Non-breaking ABI changes:
|
||||
|
||||
- The type of the ``sig`` (signature) argument of :ref:`mj_stateSize` and related functions has been changed from
|
||||
|
||||
@@ -1629,6 +1629,7 @@ typedef struct mjModel_ mjModel;
|
||||
struct mjResource_ {
|
||||
char* name; // name of resource (filename, etc)
|
||||
void* data; // opaque data pointer
|
||||
mjVFS* vfs; // pointer to the VFS
|
||||
char timestamp[512]; // timestamp of the resource
|
||||
const struct mjpResourceProvider* provider; // pointer to the provider
|
||||
};
|
||||
@@ -1638,6 +1639,8 @@ struct mjpResourceProvider {
|
||||
mjfOpenResource open; // opening callback
|
||||
mjfReadResource read; // reading callback
|
||||
mjfCloseResource close; // closing callback
|
||||
mjfMountResource mount; // mounting callback (optional)
|
||||
mjfUnmountResource unmount; // unmounting callback (optional)
|
||||
mjfResourceModified modified; // resource modified callback (optional)
|
||||
void* data; // opaque data pointer (resource invariant)
|
||||
};
|
||||
@@ -3095,6 +3098,8 @@ typedef struct mjvFigure_ mjvFigure;
|
||||
|
||||
//----------------------------- MJAPI FUNCTIONS --------------------------------
|
||||
void mj_defaultVFS(mjVFS* vfs);
|
||||
int mj_mountVFS(mjVFS* vfs, const char* filepath, const mjpResourceProvider* provider);
|
||||
int mj_unmountVFS(mjVFS* vfs, const char* filename);
|
||||
int mj_addFileVFS(mjVFS* vfs, const char* directory, const char* filename);
|
||||
int mj_addBufferVFS(mjVFS* vfs, const char* name, const void* buffer, int nbuffer);
|
||||
int mj_deleteFileVFS(mjVFS* vfs, const char* filename);
|
||||
|
||||
Reference in New Issue
Block a user