nl:: Weave:: Profiles:: DataManagement_Current:: CommandSender
#include <src/lib/profiles/data-management/Current/CommandSender.h>
摘要
注意:這個類別會封裝傳送指令的通訊協定詳細資料,簡化與應用程式有關的機制。應用程式會提供包含指令酬載的 PacketBuffer,以及一組選用的引數,以修改指令標頭的內容及指令的行為。此包裝函式在指令處理的效用有限,主要是因為安全性驗證和資料序列化/去序列化作業的複雜性/彈性所致。
指令驗證的詳細資料仍待定
此類別也有助於應用程式推論相關 TraitDataSink 內的資料,是否達到通訊的副作用 (根據指令回應中提供的版本)。應用程式負責管理該物件的儲存空間。
編織繫結
這個類別的物件可以使用 Weave 繫結進行初始化,做為傳送指令的預設繫結。使用者也可以為每次 SendCommand() 呼叫提供 Binding,藉此覆寫預設的 Binding。您不需要提供預設的 Binding,但提供給 CommandSender 的任何繫結都必須先初始化。
EventCallback
如果使用者希望收到指令傳送後所發生事件的最新消息,就必須定義此類型的函式 (請參閱下方的「API 事件」)。如果使用者不關心在指令傳送後發生什麼事,這個空值可能會是 NULL。
API 事件
傳送 Command 後可能會發生下列事件:
CommunicationError
形成或傳送 Command,或是等待回應時發生錯誤。等待回應時可能發生的錯誤,例如關鍵錯誤或非預期的連線關閉。錯誤原因會包含在 EventCallback 處理常式的 InEventParam 引數中。
InProgressReceived
收件者可以傳送「處理中」訊息,表示已接收「指令」,但尚未完成。完成後,接收者會傳送「Response」或「StatusReport」。無須傳送「進行中」訊息。
StatusReportReceived
接收 StatusReport 表示處理 Command 時發生錯誤。您可以透過 InEventParam 存取 StatusReport。
ResponseReceived
接收回應表示 Command 收件者已成功處理 Command。「回應」可能包含酬載,也可能沒有。如果想要保留封包緩衝區,可能會呼叫 ExchangeContext::AddRef() 來增加參照數量。
公開類型 |
|
---|---|
EventCallback)(void *const aAppState, EventType aEvent, const InEventParam &aInParam, OutEventParam &aOutEventParam)
|
typedefvoid(*
|
EventType
|
列舉 |
公開屬性 |
|
---|---|
mAppState = NULL
|
void *
|
mSyncronizedTraitState = NULL
|
公開的靜態函式 |
|
---|---|
DefaultEventHandler(void *aAppState, EventType aEvent, const InEventParam & aInParam, OutEventParam & aOutParam)
|
void
|
公用函式 |
|
---|---|
Close(bool aAbortNow)
|
void
|
Init(nl::Weave::Binding *aBinding, const EventCallback aEventCallback, void *const aAppState)
|
|
SendCommand(nl::Weave::PacketBuffer *aPayload, nl::Weave::Binding *aBinding, ResourceIdentifier & aResourceId, uint32_t aProfileId, uint32_t aCommandType)
|
|
SendCommand(nl::Weave::PacketBuffer *aPayload, nl::Weave::Binding *aBinding, SendParams & aSendParams)
|
|
SetSynchronizedTraitState(SynchronizedTraitState *aTraitState)
|
void
|
結構 |
|
---|---|
nl:: |
接收自訂指令的接收者傳回給寄件者的資料。 |
nl:: |
資料從 EventCallback 函式傳回 CommandSender 物件。 |
nl:: |
封裝要傳遞至 SendCommand() 的引數。 |
nl:: |
公開類型
EventCallback
void(* EventCallback)(void *const aAppState, EventType aEvent, const InEventParam &aInParam, OutEventParam &aOutEventParam)
EventType
EventType
公開屬性
mAppState
void * mAppState = NULL
mSyncronizedTraitState
SynchronizedTraitState * mSyncronizedTraitState = NULL
公開的靜態函式
DefaultEventHandler
void DefaultEventHandler( void *aAppState, EventType aEvent, const InEventParam & aInParam, OutEventParam & aOutParam )
公用函式
關閉
void Close( bool aAbortNow )
Init
WEAVE_ERROR Init( nl::Weave::Binding *aBinding, const EventCallback aEventCallback, void *const aAppState )
SendCommand
WEAVE_ERROR SendCommand( nl::Weave::PacketBuffer *aPayload, nl::Weave::Binding *aBinding, ResourceIdentifier & aResourceId, uint32_t aProfileId, uint32_t aCommandType )
SendCommand
WEAVE_ERROR SendCommand( nl::Weave::PacketBuffer *aPayload, nl::Weave::Binding *aBinding, SendParams & aSendParams )