Skip to content

Commit

Permalink
Do not dispatch packet to Device/DeviceController (#11776)
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost authored and pull[bot] committed Dec 2, 2021
1 parent d841e0f commit 7d5817e
Show file tree
Hide file tree
Showing 17 changed files with 6 additions and 286 deletions.
1 change: 0 additions & 1 deletion examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ WiFiWidget pairingWindowLED;
class AppCallbacks : public AppDelegate
{
public:
void OnReceiveError() override { statusLED1.BlinkOnError(); }
void OnRendezvousStarted() override { bluetoothLED.Set(true); }
void OnRendezvousStopped() override
{
Expand Down
35 changes: 0 additions & 35 deletions src/app/DeviceProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,39 +104,4 @@ class DLL_EXPORT DeviceProxy
uint32_t mMrpActiveInterval = CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL;
};

/**
* This class defines an interface for an object that the user of Device
* can register as a delegate. The delegate object will be called by the
* Device when a new message or status update is received from the corresponding
* CHIP device.
*/
class DLL_EXPORT DeviceStatusDelegate
{
public:
virtual ~DeviceStatusDelegate() {}

/**
* @brief
* Called when a message is received from the device.
*
* @param[in] msg Received message buffer.
*/
virtual void OnMessage(System::PacketBufferHandle && msg) = 0;

/**
* @brief
* Called when response to OpenPairingWindow is received from the device.
*
* @param[in] status CHIP_NO_ERROR on success, or corresponding error.
*/
virtual void OnPairingWindowOpenStatus(CHIP_ERROR status){};

/**
* @brief
* Called when device status is updated.
*
*/
virtual void OnStatusChange(void){};
};

} // namespace chip
34 changes: 2 additions & 32 deletions src/app/OperationalDeviceProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,7 @@ void OperationalDeviceProxy::Clear()
{
mCASESession.Clear();

mState = State::Uninitialized;
mStatusDelegate = nullptr;
if (mInitParams.exchangeMgr)
{
// Ensure that any exchange contexts we have open get closed now,
// because we don't want them to call back in to us after this
// point.
mInitParams.exchangeMgr->CloseAllContextsForDelegate(this);
}
mState = State::Uninitialized;
mInitParams = DeviceProxyInitParams();
}

Expand All @@ -282,34 +274,12 @@ void OperationalDeviceProxy::OnConnectionExpired(SessionHandle session)
mSecureSession.ClearValue();
}

CHIP_ERROR OperationalDeviceProxy::OnMessageReceived(Messaging::ExchangeContext * exchange, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && msgBuf)
{
if (mState == State::SecureConnected)
{
if (mStatusDelegate != nullptr)
{
mStatusDelegate->OnMessage(std::move(msgBuf));
}
}
return CHIP_NO_ERROR;
}

CHIP_ERROR OperationalDeviceProxy::ShutdownSubscriptions()
{
return app::InteractionModelEngine::GetInstance()->ShutdownSubscriptions(mInitParams.fabricInfo->GetFabricIndex(),
GetDeviceId());
}

OperationalDeviceProxy::~OperationalDeviceProxy()
{
if (mInitParams.exchangeMgr)
{
// Ensure that any exchange contexts we have open get closed now,
// because we don't want them to call back in to us after this
// point.
mInitParams.exchangeMgr->CloseAllContextsForDelegate(this);
}
}
OperationalDeviceProxy::~OperationalDeviceProxy() {}

} // namespace chip
22 changes: 1 addition & 21 deletions src/app/OperationalDeviceProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@

namespace chip {

class DeviceStatusDelegate;

struct DeviceProxyInitParams
{
SessionManager * sessionManager = nullptr;
Expand All @@ -59,7 +57,7 @@ class OperationalDeviceProxy;
typedef void (*OnDeviceConnected)(void * context, DeviceProxy * device);
typedef void (*OnDeviceConnectionFailure)(void * context, NodeId deviceId, CHIP_ERROR error);

class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy, Messaging::ExchangeDelegate, public SessionEstablishmentDelegate
class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy, public SessionEstablishmentDelegate
{
public:
virtual ~OperationalDeviceProxy();
Expand Down Expand Up @@ -128,16 +126,6 @@ class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy, Messaging::Exchang
onFailureCallback, app::TLVDataFilter tlvDataFilter = nullptr) override; void CancelIMResponseHandler(void * commandObj)
override;
*/
/**
* @brief
* This function is called when a message is received from the corresponding
* device. The message ownership is transferred to the function, and it is expected
* to release the message buffer before returning.
*/
CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * exchange, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && msgBuf) override;

void OnResponseTimeout(Messaging::ExchangeContext * ec) override {}

/**
* Update data of the device.
Expand All @@ -147,13 +135,6 @@ class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy, Messaging::Exchang
*/
CHIP_ERROR UpdateDeviceData(const Transport::PeerAddress & addr, uint32_t mrpIdleInterval, uint32_t mrpActiveInterval);

/**
* Set the delegate object which will be called when a message is received.
* The user of this Device object must reset the delegate (by calling
* SetDelegate(nullptr)) before releasing their delegate object.
*/
void SetDelegate(DeviceStatusDelegate * delegate) { mStatusDelegate = delegate; }

PeerId GetPeerId() const { return mPeerId; }

bool MatchesSession(SessionHandle session) const { return mSecureSession.HasValue() && mSecureSession.Value() == session; }
Expand Down Expand Up @@ -196,7 +177,6 @@ class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy, Messaging::Exchang

State mState = State::Uninitialized;

DeviceStatusDelegate * mStatusDelegate = nullptr;
Optional<SessionHandle> mSecureSession = Optional<SessionHandle>::Missing();

uint8_t mSequenceNumber = 0;
Expand Down
1 change: 0 additions & 1 deletion src/app/server/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class AppDelegate
{
public:
virtual ~AppDelegate() {}
virtual void OnReceiveError() {}
virtual void OnRendezvousStarted() {}
virtual void OnRendezvousStopped() {}
virtual void OnPairingWindowOpened() {}
Expand Down
26 changes: 0 additions & 26 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ Server Server::sServer;

CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint16_t unsecureServicePort)
{
mAppDelegate = delegate;
mSecuredServicePort = secureServicePort;
mUnsecuredServicePort = unsecureServicePort;

Expand Down Expand Up @@ -162,11 +161,6 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint
app::DnssdServer::Instance().StartServer();
#endif

// TODO @pan-apple Use IM protocol ID.
// Register to receive unsolicited legacy ZCL messages from the exchange manager.
err = mExchangeMgr.RegisterUnsolicitedMessageHandlerForProtocol(Protocols::TempZCL::Id, this);
SuccessOrExit(err);

err = mCASEServer.ListenForSessionEstablishment(&mExchangeMgr, &mTransports, chip::DeviceLayer::ConnectivityMgr().GetBleLayer(),
&mSessions, &mFabrics, &mSessionIDAllocator);
SuccessOrExit(err);
Expand Down Expand Up @@ -259,24 +253,4 @@ CHIP_ERROR Server::AddTestCommissioning()
return err;
}

CHIP_ERROR Server::OnMessageReceived(Messaging::ExchangeContext * exchangeContext, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && buffer)
{
CHIP_ERROR err = CHIP_NO_ERROR;
VerifyOrReturnError(!buffer.IsNull(), err = CHIP_ERROR_INVALID_ARGUMENT);
// TODO: BDX messages will also be possible in the future.
HandleDataModelMessage(exchangeContext, std::move(buffer));

return err;
}

void Server::OnResponseTimeout(Messaging::ExchangeContext * ec)
{
ChipLogProgress(AppServer, "Failed to receive response");
if (mAppDelegate != nullptr)
{
mAppDelegate->OnReceiveError();
}
}

} // namespace chip
9 changes: 1 addition & 8 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ using ServerTransportMgr = chip::TransportMgr<chip::Transport::UDP
#endif
>;

class Server : public Messaging::ExchangeDelegate
class Server
{
public:
CHIP_ERROR Init(AppDelegate * delegate = nullptr, uint16_t secureServicePort = CHIP_PORT,
Expand Down Expand Up @@ -130,13 +130,6 @@ class Server : public Messaging::ExchangeDelegate
CHIP_ERROR SyncDelete(FabricIndex fabricIndex, const char * key) override { return SyncDeleteKeyValue(key); };
};

// Messaging::ExchangeDelegate
CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * exchangeContext, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && buffer) override;
void OnResponseTimeout(Messaging::ExchangeContext * ec) override;

AppDelegate * mAppDelegate = nullptr;

#if CONFIG_NETWORK_LAYER_BLE
Ble::BleLayer * mBleLayer = nullptr;
#endif
Expand Down
1 change: 0 additions & 1 deletion src/app/tests/TestCommissionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ using chip::Server;

// Mock function for linking
void InitDataModelHandler(chip::Messaging::ExchangeManager * exchangeMgr) {}
void HandleDataModelMessage(chip::Messaging::ExchangeContext * exchange, chip::System::PacketBufferHandle && buffer) {}

namespace {

Expand Down
34 changes: 0 additions & 34 deletions src/app/util/DataModelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,3 @@ void InitDataModelHandler(chip::Messaging::ExchangeManager * exchangeManager)
#endif
#endif
}

void HandleDataModelMessage(Messaging::ExchangeContext * exchange, System::PacketBufferHandle && buffer)
{
#ifdef USE_ZAP_CONFIG
EmberApsFrame frame;
bool ok = extractApsFrame(buffer->Start(), buffer->DataLength(), &frame) > 0;
if (ok)
{
ChipLogDetail(Zcl, "APS frame processing success!");
}
else
{
ChipLogDetail(Zcl, "APS frame processing failure!");
return;
}

uint8_t * message;
uint16_t messageLen = extractMessage(buffer->Start(), buffer->DataLength(), &message);
ok = emberAfProcessMessage(&frame,
0, // type
message, messageLen,
exchange, // source identifier
NULL);

if (ok)
{
ChipLogDetail(Zcl, "Data model processing success!");
}
else
{
ChipLogDetail(Zcl, "Data model processing failure!");
}
#endif
}
11 changes: 0 additions & 11 deletions src/app/util/DataModelHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,3 @@
*
*/
void InitDataModelHandler(chip::Messaging::ExchangeManager * exchangeMgr);

/**
* Handle a message that should be processed via our data model processing
* codepath.
*
* @param [in] exchange The exchange on which the message was received.
* @param [in] buffer The buffer holding the message. This function guarantees
* that it will free the buffer before returning.
*
*/
void HandleDataModelMessage(chip::Messaging::ExchangeContext * exchange, chip::System::PacketBufferHandle && buffer);
25 changes: 0 additions & 25 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ CHIP_ERROR DeviceController::Init(ControllerInitParams params)

// TODO Exchange Mgr needs to be able to track multiple delegates. Delegate API should be able to query for the right delegate
// to handle events.
ReturnErrorOnFailure(
params.systemState->ExchangeMgr()->RegisterUnsolicitedMessageHandlerForProtocol(Protocols::TempZCL::Id, this));
params.systemState->ExchangeMgr()->SetDelegate(this);

#if CHIP_DEVICE_CONFIG_ENABLE_DNSSD
Expand Down Expand Up @@ -303,29 +301,6 @@ CHIP_ERROR DeviceController::UpdateDevice(NodeId deviceId)
#endif // CHIP_DEVICE_CONFIG_ENABLE_DNSSD
}

CHIP_ERROR DeviceController::OnMessageReceived(Messaging::ExchangeContext * ec, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && msgBuf)
{
OperationalDeviceProxy * device = nullptr;

VerifyOrExit(mState == State::Initialized, ChipLogError(Controller, "OnMessageReceived was called in incorrect state"));
VerifyOrExit(ec != nullptr, ChipLogError(Controller, "OnMessageReceived was called with null exchange"));

device = FindOperationalDevice(ec->GetSessionHandle());
VerifyOrExit(device != nullptr, ChipLogError(Controller, "OnMessageReceived was called for unknown device object"));

device->OnMessageReceived(ec, payloadHeader, std::move(msgBuf));

exit:
return CHIP_NO_ERROR;
}

void DeviceController::OnResponseTimeout(Messaging::ExchangeContext * ec)
{
ChipLogProgress(Controller, "Time out! failed to receive response from Exchange: " ChipLogFormatExchange,
ChipLogValueExchange(ec));
}

void DeviceController::OnNewConnection(SessionHandle session, Messaging::ExchangeManager * mgr) {}

void DeviceController::OnConnectionExpired(SessionHandle session, Messaging::ExchangeManager * mgr)
Expand Down
8 changes: 1 addition & 7 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ typedef void (*OnOpenCommissioningWindow)(void * context, NodeId deviceId, CHIP_
* and device pairing information for individual devices). Alternatively, this class can retrieve the
* relevant information when the application tries to communicate with the device
*/
class DLL_EXPORT DeviceController : public Messaging::ExchangeDelegate,
public Messaging::ExchangeMgrDelegate,
class DLL_EXPORT DeviceController : public Messaging::ExchangeMgrDelegate,
#if CHIP_DEVICE_CONFIG_ENABLE_DNSSD
public AbstractDnssdDiscoveryController,
#endif
Expand Down Expand Up @@ -402,11 +401,6 @@ class DLL_EXPORT DeviceController : public Messaging::ExchangeDelegate,
#endif // CHIP_DEVICE_CONFIG_ENABLE_DNSSD

private:
//////////// ExchangeDelegate Implementation ///////////////
CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && msgBuf) override;
void OnResponseTimeout(Messaging::ExchangeContext * ec) override;

OperationalDeviceProxy * FindOperationalDevice(SessionHandle session);
OperationalDeviceProxy * FindOperationalDevice(NodeId id);
void ReleaseOperationalDevice(OperationalDeviceProxy * device);
Expand Down
Loading

0 comments on commit 7d5817e

Please sign in to comment.