[FabricAdmin] Refactor FS specific attribute handlings out of general HandleAttributeData function (#35080)

* [FabricAdmin] Refactor attribute Data handling

* Use reference to pass chip::TLV::TLVReader

* Update examples/fabric-admin/device_manager/DeviceManager.h

Co-authored-by: Terence Hampson <thampson@google.com>

* Update function name

---------

Co-authored-by: Terence Hampson <thampson@google.com>
diff --git a/examples/fabric-admin/commands/clusters/ClusterCommand.h b/examples/fabric-admin/commands/clusters/ClusterCommand.h
index ab2a535..edf2302 100644
--- a/examples/fabric-admin/commands/clusters/ClusterCommand.h
+++ b/examples/fabric-admin/commands/clusters/ClusterCommand.h
@@ -84,7 +84,7 @@
         if (data != nullptr)
         {
             LogErrorOnFailure(RemoteDataModelLogger::LogCommandAsJSON(path, data));
-            DeviceMgr().HandleCommandResponse(path, data);
+            DeviceMgr().HandleCommandResponse(path, *data);
         }
     }
 
diff --git a/examples/fabric-admin/commands/clusters/ReportCommand.cpp b/examples/fabric-admin/commands/clusters/ReportCommand.cpp
index ff52a30..2fdb965 100644
--- a/examples/fabric-admin/commands/clusters/ReportCommand.cpp
+++ b/examples/fabric-admin/commands/clusters/ReportCommand.cpp
@@ -46,7 +46,7 @@
 
     LogErrorOnFailure(RemoteDataModelLogger::LogAttributeAsJSON(path, data));
 
-    DeviceMgr().HandleAttributeData(path, data);
+    DeviceMgr().HandleAttributeData(path, *data);
 }
 
 void ReportCommand::OnEventData(const app::EventHeader & eventHeader, TLV::TLVReader * data, const app::StatusIB * status)
@@ -73,5 +73,5 @@
 
     LogErrorOnFailure(RemoteDataModelLogger::LogEventAsJSON(eventHeader, data));
 
-    DeviceMgr().HandleEventData(eventHeader, data);
+    DeviceMgr().HandleEventData(eventHeader, *data);
 }
diff --git a/examples/fabric-admin/device_manager/DeviceManager.cpp b/examples/fabric-admin/device_manager/DeviceManager.cpp
index 849d557..ad8def6 100644
--- a/examples/fabric-admin/device_manager/DeviceManager.cpp
+++ b/examples/fabric-admin/device_manager/DeviceManager.cpp
@@ -237,6 +237,25 @@
     PushCommand(commandBuilder.c_str());
 }
 
+void DeviceManager::HandleReadSupportedDeviceCategories(chip::TLV::TLVReader & data)
+{
+    ChipLogProgress(NotSpecified, "Attribute SupportedDeviceCategories detected.");
+
+    BitMask<CommissionerControl::SupportedDeviceCategoryBitmap> value;
+    CHIP_ERROR error = app::DataModel::Decode(data, value);
+    if (error != CHIP_NO_ERROR)
+    {
+        ChipLogError(NotSpecified, "Failed to decode attribute value. Error: %" CHIP_ERROR_FORMAT, error.Format());
+        return;
+    }
+
+    if (value.Has(CommissionerControl::SupportedDeviceCategoryBitmap::kFabricSynchronization))
+    {
+        ChipLogProgress(NotSpecified, "Remote Fabric-Bridge supports Fabric Synchronization, start reverse commissioning.");
+        RequestCommissioningApproval();
+    }
+}
+
 void DeviceManager::RequestCommissioningApproval()
 {
     ChipLogProgress(NotSpecified, "Starting reverse commissioning for bridge device: NodeId: " ChipLogFormatX64,
@@ -254,12 +273,12 @@
     PushCommand(commandBuilder.c_str());
 }
 
-void DeviceManager::HandleCommissioningRequestResult(TLV::TLVReader * data)
+void DeviceManager::HandleCommissioningRequestResult(TLV::TLVReader & data)
 {
     ChipLogProgress(NotSpecified, "CommissioningRequestResult event received.");
 
     CommissionerControl::Events::CommissioningRequestResult::DecodableType value;
-    CHIP_ERROR error = app::DataModel::Decode(*data, value);
+    CHIP_ERROR error = app::DataModel::Decode(data, value);
     if (error != CHIP_NO_ERROR)
     {
         ChipLogError(NotSpecified, "Failed to decode event value. Error: %" CHIP_ERROR_FORMAT, error.Format());
@@ -283,82 +302,12 @@
     SendCommissionNodeRequest(value.requestId, kResponseTimeoutSeconds);
 }
 
-void DeviceManager::SendCommissionNodeRequest(uint64_t requestId, uint16_t responseTimeoutSeconds)
+void DeviceManager::HandleAttributePartsListUpdate(chip::TLV::TLVReader & data)
 {
-    ChipLogProgress(NotSpecified, "Request the Commissioner Control Server to begin commissioning a previously approved request.");
-
-    StringBuilder<kMaxCommandSize> commandBuilder;
-    commandBuilder.Add("commissionercontrol commission-node ");
-    commandBuilder.AddFormat("%lu %u %lu %d", requestId, responseTimeoutSeconds, mRemoteBridgeNodeId, kRootEndpointId);
-
-    PushCommand(commandBuilder.c_str());
-}
-
-void DeviceManager::HandleReverseOpenCommissioningWindow(TLV::TLVReader * data)
-{
-    CommissionerControl::Commands::ReverseOpenCommissioningWindow::DecodableType value;
-    CHIP_ERROR error = app::DataModel::Decode(*data, value);
-    if (error != CHIP_NO_ERROR)
-    {
-        ChipLogError(NotSpecified, "Failed to decode command response value. Error: %" CHIP_ERROR_FORMAT, error.Format());
-        return;
-    }
-
-    // Log all fields
-    ChipLogProgress(NotSpecified, "DecodableType fields:");
-    ChipLogProgress(NotSpecified, "  commissioningTimeout: %u", value.commissioningTimeout);
-    ChipLogProgress(NotSpecified, "  discriminator: %u", value.discriminator);
-    ChipLogProgress(NotSpecified, "  iterations: %u", value.iterations);
-
-    char verifierHex[Crypto::kSpake2p_VerifierSerialized_Length * 2 + 1];
-    Encoding::BytesToHex(value.PAKEPasscodeVerifier.data(), value.PAKEPasscodeVerifier.size(), verifierHex, sizeof(verifierHex),
-                         Encoding::HexFlags::kNullTerminate);
-    ChipLogProgress(NotSpecified, "  PAKEPasscodeVerifier: %s", verifierHex);
-
-    char saltHex[Crypto::kSpake2p_Max_PBKDF_Salt_Length * 2 + 1];
-    Encoding::BytesToHex(value.salt.data(), value.salt.size(), saltHex, sizeof(saltHex), Encoding::HexFlags::kNullTerminate);
-    ChipLogProgress(NotSpecified, "  salt: %s", saltHex);
-
-    OpenDeviceCommissioningWindow(mLocalBridgeNodeId, value.commissioningTimeout, value.iterations, value.discriminator, saltHex,
-                                  verifierHex);
-}
-
-void DeviceManager::HandleAttributeData(const app::ConcreteDataAttributePath & path, TLV::TLVReader * data)
-{
-    if (path.mClusterId == CommissionerControl::Id &&
-        path.mAttributeId == CommissionerControl::Attributes::SupportedDeviceCategories::Id)
-    {
-        ChipLogProgress(NotSpecified, "Attribute SupportedDeviceCategories detected.");
-
-        BitMask<CommissionerControl::SupportedDeviceCategoryBitmap> value;
-        CHIP_ERROR error = app::DataModel::Decode(*data, value);
-        if (error != CHIP_NO_ERROR)
-        {
-            ChipLogError(NotSpecified, "Failed to decode attribute value. Error: %" CHIP_ERROR_FORMAT, error.Format());
-            return;
-        }
-
-        if (value.Has(CommissionerControl::SupportedDeviceCategoryBitmap::kFabricSynchronization))
-        {
-            ChipLogProgress(NotSpecified, "Remote Fabric-Bridge supports Fabric Synchronization, start reverse commissioning.");
-            RequestCommissioningApproval();
-        }
-
-        return;
-    }
-
-    if (path.mClusterId != Descriptor::Id || path.mAttributeId != Descriptor::Attributes::PartsList::Id)
-    {
-        return;
-    }
-
-    ChipLogProgress(NotSpecified, "Attribute change detected:");
-    ChipLogProgress(
-        NotSpecified, "Endpoint: %u, Cluster: " ChipLogFormatMEI ", Attribute: " ChipLogFormatMEI ", DataVersion: %" PRIu32,
-        path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId), path.mDataVersion.ValueOr(0));
+    ChipLogProgress(NotSpecified, "Attribute PartsList change detected:");
 
     app::DataModel::DecodableList<EndpointId> value;
-    CHIP_ERROR error = app::DataModel::Decode(*data, value);
+    CHIP_ERROR error = app::DataModel::Decode(data, value);
     if (error != CHIP_NO_ERROR)
     {
         ChipLogError(NotSpecified, "Failed to decode attribute value. Error: %" CHIP_ERROR_FORMAT, error.Format());
@@ -456,7 +405,63 @@
     }
 }
 
-void DeviceManager::HandleEventData(const app::EventHeader & header, TLV::TLVReader * data)
+void DeviceManager::SendCommissionNodeRequest(uint64_t requestId, uint16_t responseTimeoutSeconds)
+{
+    ChipLogProgress(NotSpecified, "Request the Commissioner Control Server to begin commissioning a previously approved request.");
+
+    StringBuilder<kMaxCommandSize> commandBuilder;
+    commandBuilder.Add("commissionercontrol commission-node ");
+    commandBuilder.AddFormat("%lu %u %lu %d", requestId, responseTimeoutSeconds, mRemoteBridgeNodeId, kRootEndpointId);
+
+    PushCommand(commandBuilder.c_str());
+}
+
+void DeviceManager::HandleReverseOpenCommissioningWindow(TLV::TLVReader & data)
+{
+    CommissionerControl::Commands::ReverseOpenCommissioningWindow::DecodableType value;
+    CHIP_ERROR error = app::DataModel::Decode(data, value);
+    if (error != CHIP_NO_ERROR)
+    {
+        ChipLogError(NotSpecified, "Failed to decode command response value. Error: %" CHIP_ERROR_FORMAT, error.Format());
+        return;
+    }
+
+    // Log all fields
+    ChipLogProgress(NotSpecified, "DecodableType fields:");
+    ChipLogProgress(NotSpecified, "  commissioningTimeout: %u", value.commissioningTimeout);
+    ChipLogProgress(NotSpecified, "  discriminator: %u", value.discriminator);
+    ChipLogProgress(NotSpecified, "  iterations: %u", value.iterations);
+
+    char verifierHex[Crypto::kSpake2p_VerifierSerialized_Length * 2 + 1];
+    Encoding::BytesToHex(value.PAKEPasscodeVerifier.data(), value.PAKEPasscodeVerifier.size(), verifierHex, sizeof(verifierHex),
+                         Encoding::HexFlags::kNullTerminate);
+    ChipLogProgress(NotSpecified, "  PAKEPasscodeVerifier: %s", verifierHex);
+
+    char saltHex[Crypto::kSpake2p_Max_PBKDF_Salt_Length * 2 + 1];
+    Encoding::BytesToHex(value.salt.data(), value.salt.size(), saltHex, sizeof(saltHex), Encoding::HexFlags::kNullTerminate);
+    ChipLogProgress(NotSpecified, "  salt: %s", saltHex);
+
+    OpenDeviceCommissioningWindow(mLocalBridgeNodeId, value.commissioningTimeout, value.iterations, value.discriminator, saltHex,
+                                  verifierHex);
+}
+
+void DeviceManager::HandleAttributeData(const app::ConcreteDataAttributePath & path, TLV::TLVReader & data)
+{
+    if (path.mClusterId == CommissionerControl::Id &&
+        path.mAttributeId == CommissionerControl::Attributes::SupportedDeviceCategories::Id)
+    {
+        HandleReadSupportedDeviceCategories(data);
+        return;
+    }
+
+    if (path.mClusterId == Descriptor::Id && path.mAttributeId == Descriptor::Attributes::PartsList::Id)
+    {
+        HandleAttributePartsListUpdate(data);
+        return;
+    }
+}
+
+void DeviceManager::HandleEventData(const app::EventHeader & header, TLV::TLVReader & data)
 {
     if (header.mPath.mClusterId == CommissionerControl::Id &&
         header.mPath.mEventId == CommissionerControl::Events::CommissioningRequestResult::Id)
@@ -465,7 +470,7 @@
     }
 }
 
-void DeviceManager::HandleCommandResponse(const app::ConcreteCommandPath & path, TLV::TLVReader * data)
+void DeviceManager::HandleCommandResponse(const app::ConcreteCommandPath & path, TLV::TLVReader & data)
 {
     ChipLogProgress(NotSpecified, "Command Response received.");
 
diff --git a/examples/fabric-admin/device_manager/DeviceManager.h b/examples/fabric-admin/device_manager/DeviceManager.h
index b6c7dc0..d3b47c4 100644
--- a/examples/fabric-admin/device_manager/DeviceManager.h
+++ b/examples/fabric-admin/device_manager/DeviceManager.h
@@ -150,11 +150,11 @@
 
     void ReadSupportedDeviceCategories();
 
-    void HandleAttributeData(const chip::app::ConcreteDataAttributePath & path, chip::TLV::TLVReader * data);
+    void HandleAttributeData(const chip::app::ConcreteDataAttributePath & path, chip::TLV::TLVReader & data);
 
-    void HandleEventData(const chip::app::EventHeader & header, chip::TLV::TLVReader * data);
+    void HandleEventData(const chip::app::EventHeader & header, chip::TLV::TLVReader & data);
 
-    void HandleCommandResponse(const chip::app::ConcreteCommandPath & path, chip::TLV::TLVReader * data);
+    void HandleCommandResponse(const chip::app::ConcreteCommandPath & path, chip::TLV::TLVReader & data);
 
     void OnDeviceRemoved(chip::NodeId deviceId, CHIP_ERROR err) override;
 
@@ -163,11 +163,15 @@
 
     void RequestCommissioningApproval();
 
-    void HandleCommissioningRequestResult(chip::TLV::TLVReader * data);
+    void HandleReadSupportedDeviceCategories(chip::TLV::TLVReader & data);
+
+    void HandleCommissioningRequestResult(chip::TLV::TLVReader & data);
+
+    void HandleAttributePartsListUpdate(chip::TLV::TLVReader & data);
 
     void SendCommissionNodeRequest(uint64_t requestId, uint16_t responseTimeoutSeconds);
 
-    void HandleReverseOpenCommissioningWindow(chip::TLV::TLVReader * data);
+    void HandleReverseOpenCommissioningWindow(chip::TLV::TLVReader & data);
 
     static DeviceManager sInstance;