[Fabric-Bridge] Refactor platform independent files out of linux folder (#34327)

* Refactor platform independent files out of linux folder

* Address review comment
diff --git a/examples/fabric-bridge-app/fabric-bridge-common/BUILD.gn b/examples/fabric-bridge-app/fabric-bridge-common/BUILD.gn
index 70d9586..3bc4c23 100644
--- a/examples/fabric-bridge-app/fabric-bridge-common/BUILD.gn
+++ b/examples/fabric-bridge-app/fabric-bridge-common/BUILD.gn
@@ -13,13 +13,32 @@
 # limitations under the License.
 
 import("//build_overrides/chip.gni")
-
 import("${chip_root}/src/app/chip_data_model.gni")
 
+config("config") {
+  include_dirs = [ "include" ]
+}
+
 chip_data_model("fabric-bridge-common") {
   zap_file = "fabric-bridge-app.zap"
-
   is_server = true
-
   cflags = [ "-DDYNAMIC_ENDPOINT_COUNT=16" ]
 }
+
+source_set("fabric-bridge-lib") {
+  public_configs = [ ":config" ]
+
+  sources = [
+    "include/CHIPProjectAppConfig.h",
+    "include/Device.h",
+    "include/DeviceManager.h",
+    "src/Device.cpp",
+    "src/DeviceManager.cpp",
+    "src/ZCLCallbacks.cpp",
+  ]
+
+  deps = [
+    "${chip_root}/examples/fabric-bridge-app/fabric-bridge-common",
+    "${chip_root}/src/lib",
+  ]
+}
diff --git a/examples/fabric-bridge-app/linux/include/Device.h b/examples/fabric-bridge-app/fabric-bridge-common/include/Device.h
similarity index 100%
rename from examples/fabric-bridge-app/linux/include/Device.h
rename to examples/fabric-bridge-app/fabric-bridge-common/include/Device.h
diff --git a/examples/fabric-bridge-app/linux/include/DeviceManager.h b/examples/fabric-bridge-app/fabric-bridge-common/include/DeviceManager.h
similarity index 100%
rename from examples/fabric-bridge-app/linux/include/DeviceManager.h
rename to examples/fabric-bridge-app/fabric-bridge-common/include/DeviceManager.h
diff --git a/examples/fabric-bridge-app/linux/Device.cpp b/examples/fabric-bridge-app/fabric-bridge-common/src/Device.cpp
similarity index 100%
rename from examples/fabric-bridge-app/linux/Device.cpp
rename to examples/fabric-bridge-app/fabric-bridge-common/src/Device.cpp
diff --git a/examples/fabric-bridge-app/linux/DeviceManager.cpp b/examples/fabric-bridge-app/fabric-bridge-common/src/DeviceManager.cpp
similarity index 100%
rename from examples/fabric-bridge-app/linux/DeviceManager.cpp
rename to examples/fabric-bridge-app/fabric-bridge-common/src/DeviceManager.cpp
diff --git a/examples/fabric-bridge-app/fabric-bridge-common/src/ZCLCallbacks.cpp b/examples/fabric-bridge-app/fabric-bridge-common/src/ZCLCallbacks.cpp
new file mode 100644
index 0000000..7a9521f
--- /dev/null
+++ b/examples/fabric-bridge-app/fabric-bridge-common/src/ZCLCallbacks.cpp
@@ -0,0 +1,92 @@
+/*
+ *
+ *    Copyright (c) 2024 Project CHIP Authors
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include "DeviceManager.h"
+
+#include <app-common/zap-generated/cluster-objects.h>
+#include <app-common/zap-generated/ids/Attributes.h>
+#include <app-common/zap-generated/ids/Clusters.h>
+#include <lib/support/ZclString.h>
+
+using namespace ::chip;
+using namespace ::chip::app::Clusters;
+
+#define ZCL_DESCRIPTOR_CLUSTER_REVISION (1u)
+#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION (2u)
+#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_FEATURE_MAP (0u)
+
+// External attribute read callback function
+Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(EndpointId endpoint, ClusterId clusterId,
+                                                                         const EmberAfAttributeMetadata * attributeMetadata,
+                                                                         uint8_t * buffer, uint16_t maxReadLength)
+{
+    uint16_t endpointIndex  = emberAfGetDynamicIndexFromEndpoint(endpoint);
+    AttributeId attributeId = attributeMetadata->attributeId;
+
+    Device * dev = DeviceMgr().GetDevice(endpointIndex);
+    if (dev != nullptr && clusterId == app::Clusters::BridgedDeviceBasicInformation::Id)
+    {
+        using namespace app::Clusters::BridgedDeviceBasicInformation::Attributes;
+        ChipLogProgress(NotSpecified, "HandleReadBridgedDeviceBasicAttribute: attrId=%d, maxReadLength=%d", attributeId,
+                        maxReadLength);
+
+        if ((attributeId == Reachable::Id) && (maxReadLength == 1))
+        {
+            *buffer = dev->IsReachable() ? 1 : 0;
+        }
+        else if ((attributeId == NodeLabel::Id) && (maxReadLength == 32))
+        {
+            MutableByteSpan zclNameSpan(buffer, maxReadLength);
+            MakeZclCharString(zclNameSpan, dev->GetName());
+        }
+        else if ((attributeId == ClusterRevision::Id) && (maxReadLength == 2))
+        {
+            uint16_t rev = ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION;
+            memcpy(buffer, &rev, sizeof(rev));
+        }
+        else if ((attributeId == FeatureMap::Id) && (maxReadLength == 4))
+        {
+            uint32_t featureMap = ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_FEATURE_MAP;
+            memcpy(buffer, &featureMap, sizeof(featureMap));
+        }
+        else
+        {
+            return Protocols::InteractionModel::Status::Failure;
+        }
+        return Protocols::InteractionModel::Status::Success;
+    }
+
+    return Protocols::InteractionModel::Status::Failure;
+}
+
+// External attribute write callback function
+Protocols::InteractionModel::Status emberAfExternalAttributeWriteCallback(EndpointId endpoint, ClusterId clusterId,
+                                                                          const EmberAfAttributeMetadata * attributeMetadata,
+                                                                          uint8_t * buffer)
+{
+    uint16_t endpointIndex                  = emberAfGetDynamicIndexFromEndpoint(endpoint);
+    Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Failure;
+
+    Device * dev = DeviceMgr().GetDevice(endpointIndex);
+    if (dev != nullptr && dev->IsReachable())
+    {
+        ChipLogProgress(NotSpecified, "emberAfExternalAttributeWriteCallback: ep=%d, clusterId=%d", endpoint, clusterId);
+        ret = Protocols::InteractionModel::Status::Success;
+    }
+
+    return ret;
+}
diff --git a/examples/fabric-bridge-app/linux/BUILD.gn b/examples/fabric-bridge-app/linux/BUILD.gn
index 2b408d5..d0f60f3 100644
--- a/examples/fabric-bridge-app/linux/BUILD.gn
+++ b/examples/fabric-bridge-app/linux/BUILD.gn
@@ -33,15 +33,12 @@
 executable("fabric-bridge-app") {
   sources = [
     "${chip_root}/examples/fabric-bridge-app/fabric-bridge-common/include/CHIPProjectAppConfig.h",
-    "Device.cpp",
-    "DeviceManager.cpp",
-    "include/Device.h",
-    "include/DeviceManager.h",
     "main.cpp",
   ]
 
   deps = [
     "${chip_root}/examples/fabric-bridge-app/fabric-bridge-common",
+    "${chip_root}/examples/fabric-bridge-app/fabric-bridge-common:fabric-bridge-lib",
     "${chip_root}/examples/platform/linux:app-main",
     "${chip_root}/src/lib",
   ]
diff --git a/examples/fabric-bridge-app/linux/main.cpp b/examples/fabric-bridge-app/linux/main.cpp
index 2047e15..0aa22b8 100644
--- a/examples/fabric-bridge-app/linux/main.cpp
+++ b/examples/fabric-bridge-app/linux/main.cpp
@@ -23,7 +23,6 @@
 #include "DeviceManager.h"
 
 #include <app/AttributeAccessInterfaceRegistry.h>
-#include <lib/support/ZclString.h>
 
 #if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
 #include "RpcClient.h"
@@ -40,10 +39,6 @@
 using namespace chip::app::Clusters;
 using namespace chip::app::Clusters::AdministratorCommissioning;
 
-#define ZCL_DESCRIPTOR_CLUSTER_REVISION (1u)
-#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION (2u)
-#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_FEATURE_MAP (0u)
-
 namespace {
 
 constexpr uint16_t kPollIntervalMs = 100;
@@ -158,6 +153,8 @@
 
 void ApplicationInit()
 {
+    ChipLogDetail(NotSpecified, "Fabric-Bridge: ApplicationInit()");
+
     InteractionModelEngine::GetInstance()->RegisterCommandHandler(&gAdministratorCommissioningCommandHandler);
 
 #if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
@@ -172,7 +169,10 @@
     DeviceMgr().Init();
 }
 
-void ApplicationShutdown() {}
+void ApplicationShutdown()
+{
+    ChipLogDetail(NotSpecified, "Fabric-Bridge: ApplicationShutdown()");
+}
 
 int main(int argc, char * argv[])
 {
@@ -185,65 +185,3 @@
 
     return 0;
 }
-
-// External attribute read callback function
-Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(EndpointId endpoint, ClusterId clusterId,
-                                                                         const EmberAfAttributeMetadata * attributeMetadata,
-                                                                         uint8_t * buffer, uint16_t maxReadLength)
-{
-    uint16_t endpointIndex  = emberAfGetDynamicIndexFromEndpoint(endpoint);
-    AttributeId attributeId = attributeMetadata->attributeId;
-
-    Device * dev = DeviceMgr().GetDevice(endpointIndex);
-    if (dev != nullptr && clusterId == app::Clusters::BridgedDeviceBasicInformation::Id)
-    {
-        using namespace app::Clusters::BridgedDeviceBasicInformation::Attributes;
-        ChipLogProgress(NotSpecified, "HandleReadBridgedDeviceBasicAttribute: attrId=%d, maxReadLength=%d", attributeId,
-                        maxReadLength);
-
-        if ((attributeId == Reachable::Id) && (maxReadLength == 1))
-        {
-            *buffer = dev->IsReachable() ? 1 : 0;
-        }
-        else if ((attributeId == NodeLabel::Id) && (maxReadLength == 32))
-        {
-            MutableByteSpan zclNameSpan(buffer, maxReadLength);
-            MakeZclCharString(zclNameSpan, dev->GetName());
-        }
-        else if ((attributeId == ClusterRevision::Id) && (maxReadLength == 2))
-        {
-            uint16_t rev = ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION;
-            memcpy(buffer, &rev, sizeof(rev));
-        }
-        else if ((attributeId == FeatureMap::Id) && (maxReadLength == 4))
-        {
-            uint32_t featureMap = ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_FEATURE_MAP;
-            memcpy(buffer, &featureMap, sizeof(featureMap));
-        }
-        else
-        {
-            return Protocols::InteractionModel::Status::Failure;
-        }
-        return Protocols::InteractionModel::Status::Success;
-    }
-
-    return Protocols::InteractionModel::Status::Failure;
-}
-
-// External attribute write callback function
-Protocols::InteractionModel::Status emberAfExternalAttributeWriteCallback(EndpointId endpoint, ClusterId clusterId,
-                                                                          const EmberAfAttributeMetadata * attributeMetadata,
-                                                                          uint8_t * buffer)
-{
-    uint16_t endpointIndex                  = emberAfGetDynamicIndexFromEndpoint(endpoint);
-    Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Failure;
-
-    Device * dev = DeviceMgr().GetDevice(endpointIndex);
-    if (dev != nullptr && dev->IsReachable())
-    {
-        ChipLogProgress(NotSpecified, "emberAfExternalAttributeWriteCallback: ep=%d, clusterId=%d", endpoint, clusterId);
-        ret = Protocols::InteractionModel::Status::Success;
-    }
-
-    return ret;
-}