アクセスいただきありがとうございます。こちらのページは現在英語のみのご用意となっております。順次日本語化を進めてまいりますので、ご理解のほどよろしくお願いいたします。

MRM WHA Class

The WHA class implements device-independent behavior such as time synchronization, and fetching and distributing audio content. When instantiated, it is to be used as a singleton.

Functions that begin with post are asynchronous and return immediately to the caller. Each call is enqueued and handled in order by the MRM SDK. When it is time to process a post function, the MRM SDK calls corresponding functions for DeviceInfoDelegate and/or CloudDelegate to update related attributes.

WHA Class Declaration

This is a sample declaration of the WHA class:

class WHA {
public:
    WHA(CloudDelegate *cloudDelegate,
        DeviceInfoDelegate *deviceInfoDelegate,
        PlaybackDelegate *playbackDelegate,
        TimeDelegate *timeDelegate,
        LoggingDelegate *loggingDelegate);
    ~WHA();

    void run();
    void stop();

    bool isAcceptedNamespace(const char *nameSpace);
    void handleDirective(const char *nameSpace, const char *name,
    const char *messageId, const char *payload);

    void postAlexaConnectivityChanged();
    void postDeviceIdleChanged();
    void postDeviceMainVolumeChanged();
    void postNetworkConnectionChanged();
    void postRegistrationChanged();
};

An Example of Typical Usage

This sample illustrates typical usage of the WHA class:

// instantiate delegates
MyCloudDelegate cloudDelegate;
MyDeviceInfo deviceInfo;
MyTimeDelegate timeDelegate;
LoggingDelegate logger;

// instantiate WHA instance
wha::WHA wha(&cloudDelegate, &deviceInfo, &timeDelegate, &logger);

// run WHA event loop; the function will exit once WHA::stop() is called
wha.run();

// stop WHA event loop (from another thread)
wha.stop();

run()

This function starts the WHA instance.

void run();

stop()

This function shuts down the WHA instance.

void stop();

isAcceptedNamespace()

This function returns a boolean value to inform the client if the nameSpace provided is related to MRM.

bool isAcceptedNamespace(const char *nameSpace);
Parameter Description
const char *nameSpace The namespace to evaluate.

handleDirective()

This function instructs the WHA instance to handle an MRM Directive received via the AVS connection.

The parameters passed to this function must be extracted from the directive. The MRM SDK makes a copy for asynchronous handling.

This function returns 0 if the parameters are valid and -1 otherwise (which suggests the namespace is invalid or a parameter is null).

int handleDirective(const char *nameSpace, const char *name,
    const char *messageId, const char *payload);
Parameter Description
const char *nameSpace Message namespace.
const char *name Message name.
const char *messageId Message ID.
const char *payload Stringified JSON payload.

postAlexaConnectivityChanged()

This function informs the MRM SDK of a connectivity change between Alexa and the device. It should be invoked when there is an Alexa connection state change on the device. This triggers the MRM SDK to call CloudDelegate::hasAlexaConnection() to acquire connection state.

void postAlexaConnectivityChanged();

postDeviceIdleChanged()

This function notifies the MRM SDK that the AVS client has sent a System.UserInactivityReport.

A user activity is defined as an action that confirms a user is in the presence of the device, such as interacting with on-device buttons, speaking with Alexa, or using a GUI affordance.

void postDeviceIdleChanged();

postDeviceMainVolumeChanged()

This function informs the MRM SDK of a local change to the device's volume for media playback. This includes muting/unmuting audio.

The MRM SDK calls DeviceInfoDelegate::getDeviceMainVolume() to update cached volume when it is time to process this post event.

void postDeviceMainVolumeChanged();

postNetworkConnectionChanged()

This function informs the MRM SDK of a change to network connectivity state. It must be invoked when the network connection is established or goes down, and when the device's IP address changes.

The MRM SDK queries the latest network information such as IP address through DeviceInfoDelegate. Use this to notify the MRM SDK of a valid network connection at initialization.

void postNetworkConnectionChanged();

postRegistrationChanged()

This function informs the MRM SDK that the user triggered a registration activity, such as registering or deregistering an Alexa account from the Amazon Alexa App or your companion app.

postRegistrationChanged() must be called when there is a registration state change on the device. The MRM SDK will call DeviceInfoDelegate::getRegistrationState() to determine the current state.

If the connection to Alexa or the network is lost, the AVS client must check registration state. If registration state has changed, then the AVS client must call postRegistrationChanged().

If the device comes back from a lost connection and the device is deregistered by a user while the device is disconnected, the AVS client must call postNetworkConnectionChanged(), postRegistrationChanged() and postAlexaConnectivityChanged().

void postRegistrationChanged();