template <typename FidlType>

class MetadataServer

Defined at line 190 of file ../../src/lib/ddktl/include/ddktl/metadata_server.h

When converting a driver from DFv1 to DFv2, replace usages of the `ddk::MetadataServer` class

with the `fdf_metadata::MetadataServer` class found in the //sdk/lib/driver/metadata/cpp library.

Serves metadata that can be retrieved using `ddk::GetMetadata

<

|FidlType|>()`. `FidlType` must be

annotated with `

`.

As an example, lets say there exists a FIDl type `fuchsia.hardware.test/Metadata` to be sent from

a driver to its child driver:

library fuchsia.hardware.test;

// Make sure to annotate with `

`.

type Metadata = table {

1: test_property string:MAX;

};

The parent driver can define a `MetadataServer

<fuchsia

_hardware_test::Metadata>` server

instance as one its members:

class ParentDriver : public fdf::DriverBase {

private:

using MetadataServer = ddk::MetadataServer

<fuchsia

_hardware_test::Metadata>

MetadataServer metadata_server_;

}

When the parent driver creates a child device, it can offer the metadata server's service to the

child device by adding the metadata server's offers to the device-add arguments:

std::array offers = {MetadataServer::kFidlServiceName};

ddk::DeviceAddArgs args{"child"};

args.set_fidl_service_offers(offers))

The parent driver should also declare the metadata server's capability and offer it in the

driver's component manifest:

capabilities: [

{ service: "fuchsia.hardware.test.Metadata" },

],

expose: [

{

service: "fuchsia.hardware.test.Metadata",

from: "self",

},

],

Public Members

static const char * kFidlServiceName

Public Methods

void MetadataServer<FidlType> (std::string instance_name)

Defined at line 195 of file ../../src/lib/ddktl/include/ddktl/metadata_server.h

zx_status_t SetMetadata (const FidlType & metadata)

Set the metadata to be served to |metadata|.

Defined at line 200 of file ../../src/lib/ddktl/include/ddktl/metadata_server.h

zx_status_t ForwardMetadata (zx_device_t * device, const char * instance_name)

Sets the metadata to be served to the metadata found in the incoming namespace of |device|.

If the metadata found in |incoming| changes after this function is called then those changes

will not be reflected in the metadata to be served. Make sure that the component

manifest specifies that is uses the `FidlType::kSerializableName` service

Defined at line 219 of file ../../src/lib/ddktl/include/ddktl/metadata_server.h

zx::result<bool> ForwardMetadataIfExists (zx_device_t * device, const char * instance_name)

Similar to `ForwardMetadata()` except that it will return false if it fails to connect to the

incoming metadata server or if the incoming metadata server does not have metadata to provide.

Returns true otherwise.

Defined at line 253 of file ../../src/lib/ddktl/include/ddktl/metadata_server.h

zx_status_t Serve (fdf::OutgoingDirectory & outgoing, async_dispatcher_t * dispatcher)

Serves the fuchsia.driver.metadata/Service service to |outgoing| under the service name

`ddk::MetadataServer::kFidlServiceName` and instance name

`ddk::MetadataServer::instance_name_`.

Defined at line 294 of file ../../src/lib/ddktl/include/ddktl/metadata_server.h

zx_status_t Serve (component::OutgoingDirectory & outgoing, async_dispatcher_t * dispatcher)

Serves the fuchsia.driver.metadata/Service service to |outgoing| under the service name

`ddk::MetadataServer::kFidlServiceName` and instance name

`ddk::MetadataServer::instance_name_`.

Defined at line 301 of file ../../src/lib/ddktl/include/ddktl/metadata_server.h