template <typename Backing>
class OwnedVmoStore
Defined at line 57 of file ../../src/lib/vmo_store/owned_vmo_store.h
A `VmoStore` that may only be accessed through a `RegistrationAgent`.
`OwnedVmoStore` composes with `VmoStore` to provide a wrapper that only allows access to the
registered VMOs through the creation of `RegistrationAgent`s.
`Backing` is the data structure used to store the registered VMOs. It must implement
`AbstractStorage`.
Example usage:
```
using namespace vmo_store;
// Declaring our types first.
// `MyKey` is the key type that is used to register and retrieve VMOs from a VmoStore.
using MyKey = size_t;
// `MyMeta` is extra user metadata associated with every stored VMO (can be `void`).
using MyMeta = std::string;
// Declare our store alias, we're using `HashTableStorage` in this example.
// See `storage_types.h` for other Backing storage types.
using MyOwnedVmoStore = OwnedVmoStore
<HashTableStorage
<MyKey
, MyMeta>>;
MyOwnedVmoStore store(Options{...});
// Declare a registration agent for it. The agent provides a view into the store.
MyOwnedVmoStore::RegistrationAgent agent = store.CreateRegistrationAgent();
// Now let's register, retrieve, and unregister a `zx::vmo` obtained through `GetVmo()`.
// The second argument to `Register` is our user metadata.
zx::result result = agent.Register(GetVmo(), "my first VMO");
size_t key = result.take_value();
auto * my_registered_vmo = agent.GetVmo(key);
// Print metadata associated with VMO.
std::cout
<
<
"Got Vmo called "
<
<
my_registered_vmo->meta()
<
<
std::endl;
// see `stored_vmo.h` for other `StoredVmo` methods, like retrieving mapped or pinned memory.
// A different agent will not have access to the same VMO using the key.
MyVmoStore::RegistrationAgent other_agent = store.CreateRegistrationAgent();
ZX_ASSERT(other_agent.GetVmo(key) == nullptr, "no soup for other_agent");
// Finally, unregister the VMO, which will discard the VMO handle along with any mapping or
// pinning. Destroying the agent without unregistering all its VMOs will cause a crash.
agent.Unregister(key);
```
Public Methods
template <typename... StoreArgs>
void OwnedVmoStore<Backing> (StoreArgs... store_args)
Defined at line 60 of file ../../src/lib/vmo_store/owned_vmo_store.h
RegistrationAgent CreateRegistrationAgent ()
Creates a `RegistrationAgent` attached to this `OwnedVmoStore`.
The returned agent may not outlive this `OwnedVmoStore`.
Defined at line 67 of file ../../src/lib/vmo_store/owned_vmo_store.h
void OwnedVmoStore<Backing> (const OwnedVmoStore<Backing> & )
Defined at line 69 of file ../../src/lib/vmo_store/owned_vmo_store.h
void OwnedVmoStore<Backing> (OwnedVmoStore<Backing> && )
Defined at line 69 of file ../../src/lib/vmo_store/owned_vmo_store.h
OwnedVmoStore<Backing> & operator= (const OwnedVmoStore<Backing> & )
Defined at line 69 of file ../../src/lib/vmo_store/owned_vmo_store.h
OwnedVmoStore<Backing> & operator= (OwnedVmoStore<Backing> && )
Defined at line 69 of file ../../src/lib/vmo_store/owned_vmo_store.h