OSDN Git Service

Split L2CAP Classic and LE stacks into separate modules
authorJack He <siyuanh@google.com>
Fri, 4 Oct 2019 00:11:07 +0000 (17:11 -0700)
committerJack He <siyuanh@google.com>
Fri, 4 Oct 2019 01:42:47 +0000 (18:42 -0700)
* Although L2CAP LE and Classic stacks look similar, they are actually very different when diving into details
* Splitting them into two separate modules will benefit in the following ways:
 * One can start a LE only stack
 * One can turn off Classic stack entirely when not needed
 * Dependencies are more obvious, e.g. LE-CoC only depends on LE L2CAP and A2DP only depends on Classic L2CAP
* Changed test names as GTEST does not allow test name collisions
* New directory structure after the change:
  - l2cap: common headers that should be exposed to public
    - internal: common internal libraries shared between LE and classic
    - classic: classic headers that should be exposed to public
      - internal: internal libraries for classic
      - cert: certification stack for classic
   - le: LE headers that should be exposed to public
      - internal: internal libraries for LE
      - cert: certification stack for LE

Using Bash
 for file in classic_*; do git mv "$file" "classic/${file/classic_/}"; done
 for file in le_*; do git mv "$file" "le/${file/le_/}"; done
 for file in internal/le_*; do git mv "$file" "le/${file/le_/}"; done
 for file in internal/classic_*; do git mv "$file" "classic/${file/classic_/}"; done
 for file in classic/*; do if [ -f "$file" ]; then sed -i -e 's/Classic//g' "$file"; fi; done
 for file in classic/internal/*; do if [ -f "$file" ]; then sed -i -e 's/Classic//g' "$file"; fi; done
 for file in le/*; do if [ -f "$file" ]; then sed -i -e 's/Le//g' "$file"; fi; done
 for file in le/internal/*; do if [ -f "$file" ]; then sed -i -e 's/Le//g' "$file"; fi; done

Using IDE:
 replace "namespace l2cap {" with "namespace l2cap { namespace classic {" in classic/
 replace "}  // namespace l2cap" with "} }" in classic/
 replace "namespace l2cap {" with "namespace l2cap { namespace le {" in le/
 replace "}  // namespace l2cap" with "} }" in le/
 replace "l2cap/classic_" with "l2cap/classic/" in classic/
 replace "l2cap/internal/classic_" with "l2cap/classic/internal/" in classic/
 replace "l2cap/le_" with "l2cap/le/" in le/
 replace "l2cap/internal/le_" with "l2cap/le/internal/" in le/

Bug: 140938432
Test: bluetooth_test_gd
Change-Id: I29eafefc5b6be4033e5db811776230d28ca312b2

81 files changed:
gd/Android.bp
gd/cert/gd_cert_device.py
gd/cert/gd_device.py
gd/cert/grpc_root_server.cc
gd/facade/grpc_root_server.cc
gd/l2cap/Android.bp
gd/l2cap/classic/cert/api.proto [moved from gd/l2cap/cert/api.proto with 95% similarity]
gd/l2cap/classic/cert/cert.cc [moved from gd/l2cap/cert/cert.cc with 91% similarity]
gd/l2cap/classic/cert/cert.h [moved from gd/l2cap/cert/cert.h with 88% similarity]
gd/l2cap/classic/cert/simple_l2cap_test.py [moved from gd/l2cap/cert/simple_l2cap_test.py with 98% similarity]
gd/l2cap/classic/dynamic_channel.cc [moved from gd/l2cap/le_fixed_channel.cc with 61% similarity]
gd/l2cap/classic/dynamic_channel.h [moved from gd/l2cap/classic_dynamic_channel.h with 88% similarity]
gd/l2cap/classic/dynamic_channel_manager.cc [moved from gd/l2cap/classic_dynamic_channel_manager.cc with 52% similarity]
gd/l2cap/classic/dynamic_channel_manager.h [moved from gd/l2cap/classic_dynamic_channel_manager.h with 82% similarity]
gd/l2cap/classic/dynamic_channel_service.cc [moved from gd/l2cap/classic_dynamic_channel_service.cc with 71% similarity]
gd/l2cap/classic/dynamic_channel_service.h [moved from gd/l2cap/classic_dynamic_channel_service.h with 76% similarity]
gd/l2cap/classic/facade.cc [moved from gd/l2cap/facade.cc with 83% similarity]
gd/l2cap/classic/facade.h [moved from gd/l2cap/facade.h with 94% similarity]
gd/l2cap/classic/facade.proto [moved from gd/l2cap/facade.proto with 98% similarity]
gd/l2cap/classic/fixed_channel.cc [moved from gd/l2cap/classic_fixed_channel.cc with 50% similarity]
gd/l2cap/classic/fixed_channel.h [moved from gd/l2cap/classic_fixed_channel.h with 86% similarity]
gd/l2cap/classic/fixed_channel_manager.cc [moved from gd/l2cap/classic_fixed_channel_manager.cc with 54% similarity]
gd/l2cap/classic/fixed_channel_manager.h [moved from gd/l2cap/classic_fixed_channel_manager.h with 80% similarity]
gd/l2cap/classic/fixed_channel_service.cc [moved from gd/l2cap/classic_fixed_channel_service.cc with 69% similarity]
gd/l2cap/classic/fixed_channel_service.h [moved from gd/l2cap/classic_fixed_channel_service.h with 76% similarity]
gd/l2cap/classic/internal/dynamic_channel_allocator.cc [moved from gd/l2cap/internal/classic_dynamic_channel_allocator.cc with 73% similarity]
gd/l2cap/classic/internal/dynamic_channel_allocator.h [moved from gd/l2cap/internal/classic_dynamic_channel_allocator.h with 70% similarity]
gd/l2cap/classic/internal/dynamic_channel_allocator_test.cc [moved from gd/l2cap/internal/classic_dynamic_channel_allocator_test.cc with 81% similarity]
gd/l2cap/classic/internal/dynamic_channel_impl.cc [moved from gd/l2cap/internal/classic_dynamic_channel_impl.cc with 76% similarity]
gd/l2cap/classic/internal/dynamic_channel_impl.h [moved from gd/l2cap/internal/classic_dynamic_channel_impl.h with 80% similarity]
gd/l2cap/classic/internal/dynamic_channel_impl_test.cc [moved from gd/l2cap/internal/classic_dynamic_channel_impl_test.cc with 78% similarity]
gd/l2cap/classic/internal/dynamic_channel_service_impl.h [moved from gd/l2cap/internal/le_fixed_channel_service_impl.h with 64% similarity]
gd/l2cap/classic/internal/dynamic_channel_service_manager_impl.cc [moved from gd/l2cap/internal/le_fixed_channel_service_manager_impl.cc with 53% similarity]
gd/l2cap/classic/internal/dynamic_channel_service_manager_impl.h [moved from gd/l2cap/internal/le_fixed_channel_service_manager_impl.h with 60% similarity]
gd/l2cap/classic/internal/dynamic_channel_service_manager_test.cc [moved from gd/l2cap/internal/classic_dynamic_channel_service_manager_test.cc with 80% similarity]
gd/l2cap/classic/internal/fixed_channel_impl.cc [moved from gd/l2cap/internal/classic_fixed_channel_impl.cc with 83% similarity]
gd/l2cap/classic/internal/fixed_channel_impl.h [moved from gd/l2cap/internal/classic_fixed_channel_impl.h with 83% similarity]
gd/l2cap/classic/internal/fixed_channel_impl_mock.h [moved from gd/l2cap/internal/classic_fixed_channel_impl_mock.h with 73% similarity]
gd/l2cap/classic/internal/fixed_channel_impl_test.cc [moved from gd/l2cap/internal/classic_fixed_channel_impl_test.cc with 82% similarity]
gd/l2cap/classic/internal/fixed_channel_service_impl.h [moved from gd/l2cap/internal/classic_fixed_channel_service_impl.h with 58% similarity]
gd/l2cap/classic/internal/fixed_channel_service_impl_mock.h [moved from gd/l2cap/internal/classic_fixed_channel_service_impl_mock.h with 64% similarity]
gd/l2cap/classic/internal/fixed_channel_service_manager_impl.cc [new file with mode: 0644]
gd/l2cap/classic/internal/fixed_channel_service_manager_impl.h [moved from gd/l2cap/internal/classic_fixed_channel_service_manager_impl.h with 58% similarity]
gd/l2cap/classic/internal/fixed_channel_service_manager_impl_mock.h [moved from gd/l2cap/internal/classic_fixed_channel_service_manager_impl_mock.h with 54% similarity]
gd/l2cap/classic/internal/fixed_channel_service_manager_test.cc [moved from gd/l2cap/internal/classic_fixed_channel_service_manager_test.cc with 65% similarity]
gd/l2cap/classic/internal/link.cc [moved from gd/l2cap/internal/classic_link.cc with 67% similarity]
gd/l2cap/classic/internal/link.h [moved from gd/l2cap/internal/classic_link.h with 61% similarity]
gd/l2cap/classic/internal/link_manager.cc [moved from gd/l2cap/internal/classic_link_manager.cc with 71% similarity]
gd/l2cap/classic/internal/link_manager.h [moved from gd/l2cap/internal/classic_link_manager.h with 67% similarity]
gd/l2cap/classic/internal/link_manager_test.cc [moved from gd/l2cap/internal/classic_link_manager_test.cc with 73% similarity]
gd/l2cap/classic/internal/link_mock.h [moved from gd/l2cap/internal/le_link_mock.h with 72% similarity]
gd/l2cap/classic/l2cap_classic_module.cc [new file with mode: 0644]
gd/l2cap/classic/l2cap_classic_module.h [moved from gd/l2cap/l2cap_layer.h with 68% similarity]
gd/l2cap/internal/classic_dynamic_channel_service_manager_impl.cc [deleted file]
gd/l2cap/internal/classic_fixed_channel_service_manager_impl.cc [deleted file]
gd/l2cap/internal/fixed_channel_allocator_test.cc
gd/l2cap/l2cap_layer.cc [deleted file]
gd/l2cap/le/fixed_channel.cc [moved from gd/l2cap/classic_dynamic_channel.cc with 52% similarity]
gd/l2cap/le/fixed_channel.h [moved from gd/l2cap/le_fixed_channel.h with 88% similarity]
gd/l2cap/le/fixed_channel_manager.cc [moved from gd/l2cap/le_fixed_channel_manager.cc with 55% similarity]
gd/l2cap/le/fixed_channel_manager.h [moved from gd/l2cap/le_fixed_channel_manager.h with 82% similarity]
gd/l2cap/le/fixed_channel_service.cc [moved from gd/l2cap/le_fixed_channel_service.cc with 70% similarity]
gd/l2cap/le/fixed_channel_service.h [moved from gd/l2cap/le_fixed_channel_service.h with 77% similarity]
gd/l2cap/le/internal/fixed_channel_impl.cc [moved from gd/l2cap/internal/le_fixed_channel_impl.cc with 84% similarity]
gd/l2cap/le/internal/fixed_channel_impl.h [moved from gd/l2cap/internal/le_fixed_channel_impl.h with 85% similarity]
gd/l2cap/le/internal/fixed_channel_impl_mock.h [moved from gd/l2cap/internal/le_fixed_channel_impl_mock.h with 80% similarity]
gd/l2cap/le/internal/fixed_channel_impl_test.cc [moved from gd/l2cap/internal/le_fixed_channel_impl_test.cc with 84% similarity]
gd/l2cap/le/internal/fixed_channel_service_impl.h [moved from gd/l2cap/internal/classic_dynamic_channel_service_impl.h with 57% similarity]
gd/l2cap/le/internal/fixed_channel_service_impl_mock.h [moved from gd/l2cap/internal/le_fixed_channel_service_impl_mock.h with 64% similarity]
gd/l2cap/le/internal/fixed_channel_service_manager_impl.cc [new file with mode: 0644]
gd/l2cap/le/internal/fixed_channel_service_manager_impl.h [moved from gd/l2cap/internal/classic_dynamic_channel_service_manager_impl.h with 52% similarity]
gd/l2cap/le/internal/fixed_channel_service_manager_impl_mock.h [moved from gd/l2cap/internal/le_fixed_channel_service_manager_impl_mock.h with 55% similarity]
gd/l2cap/le/internal/fixed_channel_service_manager_test.cc [moved from gd/l2cap/internal/le_fixed_channel_service_manager_test.cc with 66% similarity]
gd/l2cap/le/internal/link.h [moved from gd/l2cap/internal/le_link.h with 75% similarity]
gd/l2cap/le/internal/link_manager.cc [moved from gd/l2cap/internal/le_link_manager.cc with 75% similarity]
gd/l2cap/le/internal/link_manager.h [moved from gd/l2cap/internal/le_link_manager.h with 72% similarity]
gd/l2cap/le/internal/link_manager_test.cc [moved from gd/l2cap/internal/le_link_manager_test.cc with 78% similarity]
gd/l2cap/le/internal/link_mock.h [moved from gd/l2cap/internal/classic_link_mock.h with 72% similarity]
gd/l2cap/le/l2cap_le_module.cc [new file with mode: 0644]
gd/l2cap/le/l2cap_le_module.h [new file with mode: 0644]
gd/shim/stack.cc

index 98a6009..67394ed 100644 (file)
@@ -326,7 +326,7 @@ filegroup {
         "facade/rootservice.proto",
         "hal/facade.proto",
         "hci/facade.proto",
-        "l2cap/facade.proto",
+        "l2cap/classic/facade.proto",
     ],
 }
 
@@ -349,8 +349,8 @@ genrule {
         "hal/facade.pb.h",
         "hci/facade.grpc.pb.h",
         "hci/facade.pb.h",
-        "l2cap/facade.grpc.pb.h",
-        "l2cap/facade.pb.h",
+        "l2cap/classic/facade.grpc.pb.h",
+        "l2cap/classic/facade.pb.h",
     ],
 }
 
@@ -373,8 +373,8 @@ genrule {
         "hal/facade.pb.cc",
         "hci/facade.grpc.pb.cc",
         "hci/facade.pb.cc",
-        "l2cap/facade.grpc.pb.cc",
-        "l2cap/facade.pb.cc",
+        "l2cap/classic/facade.grpc.pb.cc",
+        "l2cap/classic/facade.pb.cc",
     ],
 }
 
@@ -390,8 +390,8 @@ genrule {
         "touch $(genDir)/hal/cert/__init__.py; " +
         "touch $(genDir)/hci/__init__.py; " +
         "touch $(genDir)/hci/cert/__init__.py; " +
-        "touch $(genDir)/l2cap/__init__.py; " +
-        "touch $(genDir)/l2cap/cert/__init__.py; ",
+        "touch $(genDir)/l2cap/classic/__init__.py; " +
+        "touch $(genDir)/l2cap/classic/cert/__init__.py; ",
     srcs: [
         ":BluetoothFacadeProto",
         ":BluetoothCertStackProto",
@@ -410,18 +410,18 @@ genrule {
         "hci/__init__.py",
         "hci/facade_pb2_grpc.py",
         "hci/facade_pb2.py",
-        "l2cap/__init__.py",
-        "l2cap/facade_pb2_grpc.py",
-        "l2cap/facade_pb2.py",
+        "l2cap/classic/__init__.py",
+        "l2cap/classic/facade_pb2_grpc.py",
+        "l2cap/classic/facade_pb2.py",
         "hal/cert/__init__.py",
         "hal/cert/api_pb2_grpc.py",
         "hal/cert/api_pb2.py",
         "hci/cert/__init__.py",
         "hci/cert/api_pb2_grpc.py",
         "hci/cert/api_pb2.py",
-        "l2cap/cert/__init__.py",
-        "l2cap/cert/api_pb2_grpc.py",
-        "l2cap/cert/api_pb2.py",
+        "l2cap/classic/cert/__init__.py",
+        "l2cap/classic/cert/api_pb2_grpc.py",
+        "l2cap/classic/cert/api_pb2.py",
     ],
 }
 
@@ -431,7 +431,7 @@ filegroup {
         "cert/rootservice.proto",
         "hal/cert/api.proto",
         "hci/cert/api.proto",
-        "l2cap/cert/api.proto",
+        "l2cap/classic/cert/api.proto",
     ],
 }
 
@@ -455,8 +455,8 @@ genrule {
         "hal/cert/api.pb.h",
         "hci/cert/api.grpc.pb.h",
         "hci/cert/api.pb.h",
-        "l2cap/cert/api.grpc.pb.h",
-        "l2cap/cert/api.pb.h",
+        "l2cap/classic/cert/api.grpc.pb.h",
+        "l2cap/classic/cert/api.pb.h",
     ],
 }
 
@@ -480,7 +480,7 @@ genrule {
         "hal/cert/api.pb.cc",
         "hci/cert/api.grpc.pb.cc",
         "hci/cert/api.pb.cc",
-        "l2cap/cert/api.grpc.pb.cc",
-        "l2cap/cert/api.pb.cc",
+        "l2cap/classic/cert/api.grpc.pb.cc",
+        "l2cap/classic/cert/api.pb.cc",
     ],
 }
index 5adb0c5..1cdd57d 100644 (file)
@@ -21,7 +21,7 @@ from cert.event_stream import EventStream
 from cert import rootservice_pb2_grpc as cert_rootservice_pb2_grpc
 from hal.cert import api_pb2_grpc as hal_cert_pb2_grpc
 from hci.cert import api_pb2_grpc as hci_cert_pb2_grpc
-from l2cap.cert import api_pb2_grpc as l2cap_cert_pb2_grpc
+from l2cap.classic.cert import api_pb2_grpc as l2cap_cert_pb2_grpc
 
 ACTS_CONTROLLER_CONFIG_NAME = "GdCertDevice"
 ACTS_CONTROLLER_REFERENCE_NAME = "gd_cert_devices"
index 69a1936..2cd49b7 100644 (file)
@@ -21,7 +21,7 @@ from cert.event_stream import EventStream
 from facade import rootservice_pb2_grpc as facade_rootservice_pb2_grpc
 from hal import facade_pb2_grpc as hal_facade_pb2_grpc
 from hci import facade_pb2_grpc as hci_facade_pb2_grpc
-from l2cap import facade_pb2_grpc as l2cap_facade_pb2_grpc
+from l2cap.classic import facade_pb2_grpc as l2cap_facade_pb2_grpc
 
 ACTS_CONTROLLER_CONFIG_NAME = "GdDevice"
 ACTS_CONTROLLER_REFERENCE_NAME = "gd_devices"
index 7c32ff2..acbae32 100644 (file)
@@ -23,7 +23,7 @@
 #include "grpc/grpc_module.h"
 #include "hal/cert/cert.h"
 #include "hci/cert/cert.h"
-#include "l2cap/cert/cert.h"
+#include "l2cap/classic/cert/cert.h"
 #include "os/log.h"
 #include "os/thread.h"
 #include "stack_manager.h"
@@ -59,7 +59,7 @@ class RootCertService : public ::bluetooth::cert::RootCert::Service {
         break;
       case BluetoothModule::L2CAP:
         modules.add<::bluetooth::cert::ReadOnlyPropertyServerModule>();
-        modules.add<::bluetooth::l2cap::cert::L2capModuleCertModule>();
+        modules.add<::bluetooth::l2cap::classic::cert::L2capModuleCertModule>();
         break;
       default:
         return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "invalid module under test");
index 8857ea0..3376004 100644 (file)
@@ -23,7 +23,7 @@
 #include "grpc/grpc_module.h"
 #include "hal/facade.h"
 #include "hci/facade.h"
-#include "l2cap/facade.h"
+#include "l2cap/classic/facade.h"
 #include "os/log.h"
 #include "os/thread.h"
 #include "stack_manager.h"
@@ -60,7 +60,7 @@ class RootFacadeService : public ::bluetooth::facade::RootFacade::Service {
         break;
       case BluetoothModule::L2CAP:
         modules.add<::bluetooth::facade::ReadOnlyPropertyServerModule>();
-        modules.add<::bluetooth::l2cap::L2capModuleFacadeModule>();
+        modules.add<::bluetooth::l2cap::classic::L2capModuleFacadeModule>();
         break;
       default:
         return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "invalid module under test");
index 1067cdd..af12aa2 100644 (file)
@@ -2,45 +2,46 @@ filegroup {
     name: "BluetoothL2capSources",
     srcs: [
         "fcs.cc",
-        "l2cap_layer.cc",
-        "classic_dynamic_channel.cc",
-        "classic_dynamic_channel_manager.cc",
-        "classic_dynamic_channel_service.cc",
-        "classic_fixed_channel.cc",
-        "classic_fixed_channel_manager.cc",
-        "classic_fixed_channel_service.cc",
-        "internal/classic_dynamic_channel_allocator.cc",
-        "internal/classic_dynamic_channel_impl.cc",
-        "internal/classic_dynamic_channel_service_manager_impl.cc",
-        "internal/classic_fixed_channel_impl.cc",
-        "internal/classic_fixed_channel_service_manager_impl.cc",
-        "internal/classic_link.cc",
-        "internal/classic_link_manager.cc",
-        "internal/le_fixed_channel_impl.cc",
-        "internal/le_fixed_channel_service_manager_impl.cc",
-        "internal/le_link_manager.cc",
+        "classic/dynamic_channel.cc",
+        "classic/dynamic_channel_manager.cc",
+        "classic/dynamic_channel_service.cc",
+        "classic/fixed_channel.cc",
+        "classic/fixed_channel_manager.cc",
+        "classic/fixed_channel_service.cc",
+        "classic/internal/dynamic_channel_allocator.cc",
+        "classic/internal/dynamic_channel_impl.cc",
+        "classic/internal/dynamic_channel_service_manager_impl.cc",
+        "classic/internal/fixed_channel_impl.cc",
+        "classic/internal/fixed_channel_service_manager_impl.cc",
+        "classic/internal/link.cc",
+        "classic/internal/link_manager.cc",
+        "classic/l2cap_classic_module.cc",
         "internal/scheduler_fifo.cc",
-        "le_fixed_channel.cc",
-        "le_fixed_channel_manager.cc",
-        "le_fixed_channel_service.cc",
+        "le/internal/fixed_channel_impl.cc",
+        "le/internal/fixed_channel_service_manager_impl.cc",
+        "le/internal/link_manager.cc",
+        "le/fixed_channel.cc",
+        "le/fixed_channel_manager.cc",
+        "le/fixed_channel_service.cc",
+        "le/l2cap_le_module.cc",
     ],
 }
 
 filegroup {
     name: "BluetoothL2capTestSources",
     srcs: [
-        "l2cap_packet_test.cc",
-        "internal/classic_dynamic_channel_allocator_test.cc",
-        "internal/classic_dynamic_channel_impl_test.cc",
-        "internal/classic_dynamic_channel_service_manager_test.cc",
-        "internal/classic_fixed_channel_impl_test.cc",
-        "internal/classic_fixed_channel_service_manager_test.cc",
-        "internal/classic_link_manager_test.cc",
+        "classic/internal/dynamic_channel_allocator_test.cc",
+        "classic/internal/dynamic_channel_impl_test.cc",
+        "classic/internal/dynamic_channel_service_manager_test.cc",
+        "classic/internal/fixed_channel_impl_test.cc",
+        "classic/internal/fixed_channel_service_manager_test.cc",
+        "classic/internal/link_manager_test.cc",
         "internal/fixed_channel_allocator_test.cc",
-        "internal/le_fixed_channel_impl_test.cc",
-        "internal/le_fixed_channel_service_manager_test.cc",
-        "internal/le_link_manager_test.cc",
         "internal/scheduler_fifo_test.cc",
+        "l2cap_packet_test.cc",
+        "le/internal/fixed_channel_impl_test.cc",
+        "le/internal/fixed_channel_service_manager_test.cc",
+        "le/internal/link_manager_test.cc",
         "signal_id_test.cc",
     ],
 }
@@ -48,13 +49,13 @@ filegroup {
 filegroup {
     name: "BluetoothFacade_l2cap_layer",
     srcs: [
-        "facade.cc",
+        "classic/facade.cc",
     ],
 }
 
 filegroup {
     name: "BluetoothCertSource_l2cap_layer",
     srcs: [
-        "cert/cert.cc",
+        "classic/cert/cert.cc",
     ],
 }
similarity index 95%
rename from gd/l2cap/cert/api.proto
rename to gd/l2cap/classic/cert/api.proto
index dde5723..e5ba697 100644 (file)
@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package bluetooth.l2cap.cert;
+package bluetooth.l2cap.classic.cert;
 
 import "google/protobuf/empty.proto";
 import "facade/common.proto";
similarity index 91%
rename from gd/l2cap/cert/cert.cc
rename to gd/l2cap/classic/cert/cert.cc
index c2dd8b5..eda0c4f 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "l2cap/cert/cert.h"
+#include "l2cap/classic/cert/cert.h"
 
 #include <cstdint>
 #include <memory>
@@ -26,8 +26,8 @@
 #include "grpc/grpc_event_stream.h"
 #include "hci/acl_manager.h"
 #include "hci/cert/cert.h"
-#include "l2cap/cert/api.grpc.pb.h"
-#include "l2cap/l2cap_layer.h"
+#include "l2cap/classic/cert/api.grpc.pb.h"
+#include "l2cap/classic/l2cap_classic_module.h"
 #include "l2cap/l2cap_packets.h"
 #include "os/log.h"
 #include "packet/raw_builder.h"
@@ -39,8 +39,12 @@ using ::grpc::ServerContext;
 using ::bluetooth::facade::EventStreamRequest;
 using ::bluetooth::packet::RawBuilder;
 
+using ::bluetooth::l2cap::classic::cert::ConnectionCompleteEvent;
+using ::bluetooth::l2cap::classic::cert::L2capPacket;
+
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace cert {
 
 using namespace facade;
@@ -64,13 +68,13 @@ class L2capModuleCertService : public L2capModuleCert::Service {
   ::bluetooth::grpc::GrpcEventStream<ConnectionCompleteEvent, ConnectionCompleteEvent> connection_complete_stream_{
       &connection_complete_callback_};
 
-  ::grpc::Status FetchConnectionComplete(
-      ::grpc::ServerContext* context, const ::bluetooth::facade::EventStreamRequest* request,
-      ::grpc::ServerWriter<::bluetooth::l2cap::cert::ConnectionCompleteEvent>* writer) override {
+  ::grpc::Status FetchConnectionComplete(::grpc::ServerContext* context,
+                                         const ::bluetooth::facade::EventStreamRequest* request,
+                                         ::grpc::ServerWriter<ConnectionCompleteEvent>* writer) override {
     return connection_complete_stream_.HandleRequest(context, request, writer);
   }
 
-  ::grpc::Status SendL2capPacket(::grpc::ServerContext* context, const ::bluetooth::l2cap::cert::L2capPacket* request,
+  ::grpc::Status SendL2capPacket(::grpc::ServerContext* context, const L2capPacket* request,
                                  ::google::protobuf::Empty* response) override {
     std::unique_ptr<RawBuilder> packet = std::make_unique<RawBuilder>();
     auto req_string = request->payload();
@@ -173,5 +177,6 @@ const ModuleFactory L2capModuleCertModule::Factory =
     ::bluetooth::ModuleFactory([]() { return new L2capModuleCertModule(); });
 
 }  // namespace cert
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 88%
rename from gd/l2cap/cert/cert.h
rename to gd/l2cap/classic/cert/cert.h
index 07b78d5..c8015d6 100644 (file)
@@ -3,10 +3,10 @@
 #include <grpc++/grpc++.h>
 
 #include "grpc/grpc_module.h"
-#include "l2cap/l2cap_layer.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace cert {
 
 class L2capModuleCertService;
@@ -26,5 +26,6 @@ class L2capModuleCertModule : public ::bluetooth::grpc::GrpcFacadeModule {
 };
 
 }  // namespace cert
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
similarity index 98%
rename from gd/l2cap/cert/simple_l2cap_test.py
rename to gd/l2cap/classic/cert/simple_l2cap_test.py
index 0b85444..c1a841c 100644 (file)
@@ -24,7 +24,7 @@ from cert import rootservice_pb2 as cert_rootservice_pb2
 from facade import common_pb2
 from facade import rootservice_pb2 as facade_rootservice_pb2
 from google.protobuf import empty_pb2
-from l2cap import facade_pb2 as l2cap_facade_pb2
+from l2cap.classic import facade_pb2 as l2cap_facade_pb2
 
 class SimpleL2capTest(GdBaseTestClass):
     def setup_test(self):
similarity index 61%
rename from gd/l2cap/le_fixed_channel.cc
rename to gd/l2cap/classic/dynamic_channel.cc
index b4952d9..b888b91 100644 (file)
  * limitations under the License.
  */
 
-#include "l2cap/le_fixed_channel.h"
+#include "l2cap/classic/dynamic_channel.h"
 #include "common/bind.h"
-#include "l2cap/internal/le_fixed_channel_impl.h"
+#include "l2cap/classic/internal/dynamic_channel_impl.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
-hci::Address LeFixedChannel::GetDevice() const {
+hci::Address DynamicChannel::GetDevice() const {
   return impl_->GetDevice();
 }
 
-void LeFixedChannel::RegisterOnCloseCallback(os::Handler* user_handler,
-                                             LeFixedChannel::OnCloseCallback on_close_callback) {
-  l2cap_handler_->Post(common::BindOnce(&internal::LeFixedChannelImpl::RegisterOnCloseCallback, impl_, user_handler,
+void DynamicChannel::RegisterOnCloseCallback(os::Handler* user_handler,
+                                             DynamicChannel::OnCloseCallback on_close_callback) {
+  l2cap_handler_->Post(common::BindOnce(&internal::DynamicChannelImpl::RegisterOnCloseCallback, impl_, user_handler,
                                         std::move(on_close_callback)));
 }
 
-void LeFixedChannel::Acquire() {
-  l2cap_handler_->Post(common::BindOnce(&internal::LeFixedChannelImpl::Acquire, impl_));
-}
-
-void LeFixedChannel::Release() {
-  l2cap_handler_->Post(common::BindOnce(&internal::LeFixedChannelImpl::Release, impl_));
+void DynamicChannel::Close() {
+  l2cap_handler_->Post(common::BindOnce(&internal::DynamicChannelImpl::Close, impl_));
 }
 
 common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>*
-LeFixedChannel::GetQueueUpEnd() const {
+DynamicChannel::GetQueueUpEnd() const {
   return impl_->GetQueueUpEnd();
 }
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
similarity index 88%
rename from gd/l2cap/classic_dynamic_channel.h
rename to gd/l2cap/classic/dynamic_channel.h
index 3e84f98..eb52c16 100644 (file)
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
 namespace internal {
-class ClassicDynamicChannelImpl;
+class DynamicChannelImpl;
 }  // namespace internal
 
 /**
  * L2CAP Dynamic channel object. User needs to call Close() when user no longer wants to use it. Otherwise the link
  * won't be disconnected.
  */
-class ClassicDynamicChannel {
+class DynamicChannel {
  public:
-  // Should only be constructed by modules that have access to ClassicLinkManager
-  ClassicDynamicChannel(std::shared_ptr<internal::ClassicDynamicChannelImpl> impl, os::Handler* l2cap_handler)
+  // Should only be constructed by modules that have access to LinkManager
+  DynamicChannel(std::shared_ptr<internal::DynamicChannelImpl> impl, os::Handler* l2cap_handler)
       : impl_(std::move(impl)), l2cap_handler_(l2cap_handler) {
     ASSERT(impl_ != nullptr);
     ASSERT(l2cap_handler_ != nullptr);
@@ -71,9 +72,10 @@ class ClassicDynamicChannel {
   common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>* GetQueueUpEnd() const;
 
  private:
-  std::shared_ptr<internal::ClassicDynamicChannelImpl> impl_;
+  std::shared_ptr<internal::DynamicChannelImpl> impl_;
   os::Handler* l2cap_handler_;
 };
 
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 52%
rename from gd/l2cap/classic_dynamic_channel_manager.cc
rename to gd/l2cap/classic/dynamic_channel_manager.cc
index a57056d..923e06f 100644 (file)
  * limitations under the License.
  */
 
-#include "l2cap/classic_dynamic_channel_manager.h"
-#include "l2cap/internal/classic_dynamic_channel_service_impl.h"
-#include "l2cap/internal/classic_dynamic_channel_service_manager_impl.h"
-#include "l2cap/internal/classic_link_manager.h"
+#include "l2cap/classic/dynamic_channel_manager.h"
+#include "l2cap/classic/internal/dynamic_channel_service_impl.h"
+#include "l2cap/classic/internal/dynamic_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/link_manager.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
-bool ClassicDynamicChannelManager::ConnectChannel(hci::Address device, Psm psm,
-                                                  OnConnectionOpenCallback on_connection_open,
-                                                  OnConnectionFailureCallback on_fail_callback, os::Handler* handler) {
+bool DynamicChannelManager::ConnectChannel(hci::Address device, Psm psm, OnConnectionOpenCallback on_connection_open,
+                                           OnConnectionFailureCallback on_fail_callback, os::Handler* handler) {
   // TODO impl me when there is no link, and when there is link
   return false;
 }
 
-bool ClassicDynamicChannelManager::RegisterService(Psm psm, const SecurityPolicy& security_policy,
-                                                   OnRegistrationCompleteCallback on_registration_complete,
-                                                   OnConnectionOpenCallback on_connection_open, os::Handler* handler) {
-  internal::ClassicDynamicChannelServiceImpl::PendingRegistration pending_registration{
+bool DynamicChannelManager::RegisterService(Psm psm, const SecurityPolicy& security_policy,
+                                            OnRegistrationCompleteCallback on_registration_complete,
+                                            OnConnectionOpenCallback on_connection_open, os::Handler* handler) {
+  internal::DynamicChannelServiceImpl::PendingRegistration pending_registration{
       .user_handler_ = handler,
       .on_registration_complete_callback_ = std::move(on_registration_complete),
       .on_connection_open_callback_ = std::move(on_connection_open)};
-  l2cap_layer_handler_->Post(common::BindOnce(&internal::ClassicDynamicChannelServiceManagerImpl::Register,
+  l2cap_layer_handler_->Post(common::BindOnce(&internal::DynamicChannelServiceManagerImpl::Register,
                                               common::Unretained(service_manager_), psm,
                                               std::move(pending_registration)));
 
   return true;
 }
 
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 82%
rename from gd/l2cap/classic_dynamic_channel_manager.h
rename to gd/l2cap/classic/dynamic_channel_manager.h
index 05a6b78..b6c0518 100644 (file)
@@ -19,8 +19,8 @@
 
 #include "hci/acl_manager.h"
 #include "hci/address.h"
-#include "l2cap/classic_dynamic_channel.h"
-#include "l2cap/classic_dynamic_channel_service.h"
+#include "l2cap/classic/dynamic_channel.h"
+#include "l2cap/classic/dynamic_channel_service.h"
 #include "l2cap/l2cap_packets.h"
 #include "l2cap/psm.h"
 #include "l2cap/security_policy.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
-class L2capLayer;
+class L2capClassicModule;
 
 namespace internal {
-class ClassicLinkManager;
-class ClassicDynamicChannelServiceManagerImpl;
+class LinkManager;
+class DynamicChannelServiceManagerImpl;
 }  // namespace internal
 
-class ClassicDynamicChannelManager {
+class DynamicChannelManager {
  public:
   enum class ConnectionResultCode {
     SUCCESS = 0,
@@ -56,9 +57,9 @@ class ClassicDynamicChannelManager {
   using OnConnectionFailureCallback = common::OnceCallback<void(ConnectionResult result)>;
 
   /**
-   * OnConnectionOpenCallback(ClassicDynamicChannel channel);
+   * OnConnectionOpenCallback(DynamicChannel channel);
    */
-  using OnConnectionOpenCallback = common::Callback<void(std::unique_ptr<ClassicDynamicChannel>)>;
+  using OnConnectionOpenCallback = common::Callback<void(std::unique_ptr<DynamicChannel>)>;
 
   enum class RegistrationResult {
     SUCCESS = 0,
@@ -67,10 +68,10 @@ class ClassicDynamicChannelManager {
   };
 
   /**
-   * OnRegistrationFailureCallback(RegistrationResult result, ClassicDynamicChannelService service);
+   * OnRegistrationFailureCallback(RegistrationResult result, DynamicChannelService service);
    */
   using OnRegistrationCompleteCallback =
-      common::OnceCallback<void(RegistrationResult, std::unique_ptr<ClassicDynamicChannelService>)>;
+      common::OnceCallback<void(RegistrationResult, std::unique_ptr<DynamicChannelService>)>;
 
   /**
    * Connect to a Dynamic channel on a remote device
@@ -100,10 +101,10 @@ class ClassicDynamicChannelManager {
    * - This method is asynchronous.
    * - When false is returned, the registration fails immediately.
    * - When true is returned, method caller should wait for on_service_registered callback that contains a
-   *   ClassicDynamicChannelService object. The registered service can be managed from that object.
+   *   DynamicChannelService object. The registered service can be managed from that object.
    * - If a PSM is already registered or some other error happens, on_registration_complete will be triggered with a
    *   non-SUCCESS value
-   * - After a service is registered, a ClassicDynamicChannel is delivered through on_open_callback when the remote
+   * - After a service is registered, a DynamicChannel is delivered through on_open_callback when the remote
    *   initiates a channel open and channel is opened successfully
    * - on_open_callback, will only be triggered after on_service_registered callback
    *
@@ -118,22 +119,23 @@ class ClassicDynamicChannelManager {
                        OnRegistrationCompleteCallback on_registration_complete,
                        OnConnectionOpenCallback on_connection_open, os::Handler* handler);
 
-  friend class L2capLayer;
+  friend class L2capClassicModule;
 
  private:
   // The constructor is not to be used by user code
-  ClassicDynamicChannelManager(internal::ClassicDynamicChannelServiceManagerImpl* service_manager,
-                               internal::ClassicLinkManager* link_manager, os::Handler* l2cap_layer_handler)
+  DynamicChannelManager(internal::DynamicChannelServiceManagerImpl* service_manager,
+                        internal::LinkManager* link_manager, os::Handler* l2cap_layer_handler)
       : service_manager_(service_manager), link_manager_(link_manager), l2cap_layer_handler_(l2cap_layer_handler) {
     ASSERT(service_manager_ != nullptr);
     ASSERT(link_manager_ != nullptr);
     ASSERT(l2cap_layer_handler_ != nullptr);
   }
-  internal::ClassicDynamicChannelServiceManagerImpl* service_manager_ = nullptr;
-  internal::ClassicLinkManager* link_manager_ = nullptr;
+  internal::DynamicChannelServiceManagerImpl* service_manager_ = nullptr;
+  internal::LinkManager* link_manager_ = nullptr;
   os::Handler* l2cap_layer_handler_ = nullptr;
-  DISALLOW_COPY_AND_ASSIGN(ClassicDynamicChannelManager);
+  DISALLOW_COPY_AND_ASSIGN(DynamicChannelManager);
 };
 
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 71%
rename from gd/l2cap/classic_dynamic_channel_service.cc
rename to gd/l2cap/classic/dynamic_channel_service.cc
index 57039fa..16a9675 100644 (file)
  * limitations under the License.
  */
 
-#include "l2cap/classic_dynamic_channel_service.h"
+#include "l2cap/classic/dynamic_channel_service.h"
 #include "common/bind.h"
-#include "l2cap/internal/classic_dynamic_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/dynamic_channel_service_manager_impl.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
-void ClassicDynamicChannelService::Unregister(OnUnregisteredCallback on_unregistered,
-                                              os::Handler* on_unregistered_handler) {
+void DynamicChannelService::Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler) {
   ASSERT_LOG(manager_ != nullptr, "this service is invalid");
-  l2cap_layer_handler_->Post(common::BindOnce(&internal::ClassicDynamicChannelServiceManagerImpl::Unregister,
+  l2cap_layer_handler_->Post(common::BindOnce(&internal::DynamicChannelServiceManagerImpl::Unregister,
                                               common::Unretained(manager_), psm_, std::move(on_unregistered),
                                               on_unregistered_handler));
 }
 
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 76%
rename from gd/l2cap/classic_dynamic_channel_service.h
rename to gd/l2cap/classic/dynamic_channel_service.h
index 38a490e..8540087 100644 (file)
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
 namespace internal {
-class ClassicDynamicChannelServiceManagerImpl;
+class DynamicChannelServiceManagerImpl;
 }
 
-class ClassicDynamicChannelService {
+class DynamicChannelService {
  public:
-  ClassicDynamicChannelService() = default;
+  DynamicChannelService() = default;
 
   using OnUnregisteredCallback = common::OnceCallback<void()>;
 
@@ -42,21 +43,21 @@ class ClassicDynamicChannelService {
    */
   void Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler);
 
-  friend internal::ClassicDynamicChannelServiceManagerImpl;
+  friend internal::DynamicChannelServiceManagerImpl;
 
  private:
-  ClassicDynamicChannelService(Psm psm, internal::ClassicDynamicChannelServiceManagerImpl* manager,
-                               os::Handler* handler)
+  DynamicChannelService(Psm psm, internal::DynamicChannelServiceManagerImpl* manager, os::Handler* handler)
       : psm_(psm), manager_(manager), l2cap_layer_handler_(handler) {
     ASSERT(IsPsmValid(psm));
     ASSERT(manager_ != nullptr);
     ASSERT(l2cap_layer_handler_ != nullptr);
   }
   Psm psm_ = kDefaultPsm;
-  internal::ClassicDynamicChannelServiceManagerImpl* manager_ = nullptr;
+  internal::DynamicChannelServiceManagerImpl* manager_ = nullptr;
   os::Handler* l2cap_layer_handler_;
-  DISALLOW_COPY_AND_ASSIGN(ClassicDynamicChannelService);
+  DISALLOW_COPY_AND_ASSIGN(DynamicChannelService);
 };
 
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 83%
rename from gd/l2cap/facade.cc
rename to gd/l2cap/classic/facade.cc
index 32e3ea2..9072db0 100644 (file)
@@ -21,9 +21,9 @@
 #include "grpc/grpc_event_stream.h"
 #include "hci/address.h"
 #include "hci/facade.h"
-#include "l2cap/facade.grpc.pb.h"
-#include "l2cap/facade.h"
-#include "l2cap/l2cap_layer.h"
+#include "l2cap/classic/facade.grpc.pb.h"
+#include "l2cap/classic/facade.h"
+#include "l2cap/classic/l2cap_classic_module.h"
 #include "l2cap/l2cap_packets.h"
 #include "os/log.h"
 #include "packet/raw_builder.h"
@@ -37,10 +37,11 @@ using ::bluetooth::packet::RawBuilder;
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
 class L2capModuleFacadeService : public L2capModuleFacade::Service {
  public:
-  L2capModuleFacadeService(L2capLayer* l2cap_layer, os::Handler* facade_handler)
+  L2capModuleFacadeService(L2capClassicModule* l2cap_layer, os::Handler* facade_handler)
       : l2cap_layer_(l2cap_layer), facade_handler_(facade_handler) {
     ASSERT(l2cap_layer_ != nullptr);
     ASSERT(facade_handler_ != nullptr);
@@ -59,38 +60,39 @@ class L2capModuleFacadeService : public L2capModuleFacade::Service {
 
   ::grpc::Status FetchConnectionComplete(
       ::grpc::ServerContext* context, const ::bluetooth::facade::EventStreamRequest* request,
-      ::grpc::ServerWriter<::bluetooth::l2cap::ConnectionCompleteEvent>* writer) override {
+      ::grpc::ServerWriter<::bluetooth::l2cap::classic::ConnectionCompleteEvent>* writer) override {
     return connection_complete_stream_.HandleRequest(context, request, writer);
   }
 
   ::grpc::Status Connect(::grpc::ServerContext* context, const facade::BluetoothAddress* request,
                          ::google::protobuf::Empty* response) override {
-    auto fixed_channel_manager = l2cap_layer_->GetClassicFixedChannelManager();
+    auto fixed_channel_manager = l2cap_layer_->GetFixedChannelManager();
     hci::Address peer;
     ASSERT(hci::Address::FromString(request->address(), peer));
-    fixed_channel_manager->ConnectServices(peer, common::BindOnce([](ClassicFixedChannelManager::ConnectionResult) {}),
+    fixed_channel_manager->ConnectServices(peer, common::BindOnce([](FixedChannelManager::ConnectionResult) {}),
                                            facade_handler_);
     return ::grpc::Status::OK;
   }
 
-  ::grpc::Status SendL2capPacket(::grpc::ServerContext* context, const ::bluetooth::l2cap::L2capPacket* request,
-                                 SendL2capPacketResult* response) override {
+  ::grpc::Status SendL2capPacket(::grpc::ServerContext* context,
+                                 const ::bluetooth::l2cap::classic::L2capPacket* request,
+                                 ::bluetooth::l2cap::classic::SendL2capPacketResult* response) override {
     if (connection_less_channel_helper_map_.find(request->channel()) == connection_less_channel_helper_map_.end()) {
       return ::grpc::Status(::grpc::StatusCode::FAILED_PRECONDITION, "Channel not registered");
     }
     std::vector<uint8_t> packet(request->payload().begin(), request->payload().end());
     connection_less_channel_helper_map_[request->channel()]->SendPacket(packet);
-    response->set_result_type(SendL2capPacketResultType::OK);
+    response->set_result_type(::bluetooth::l2cap::classic::SendL2capPacketResultType::OK);
     return ::grpc::Status::OK;
   }
 
   ::grpc::Status FetchL2capData(::grpc::ServerContext* context, const ::bluetooth::facade::EventStreamRequest* request,
-                                ::grpc::ServerWriter<::bluetooth::l2cap::L2capPacket>* writer) override {
+                                ::grpc::ServerWriter<::bluetooth::l2cap::classic::L2capPacket>* writer) override {
     return l2cap_stream_.HandleRequest(context, request, writer);
   }
 
   ::grpc::Status RegisterChannel(::grpc::ServerContext* context,
-                                 const ::bluetooth::l2cap::RegisterChannelRequest* request,
+                                 const ::bluetooth::l2cap::classic::RegisterChannelRequest* request,
                                  ::google::protobuf::Empty* response) override {
     if (connection_less_channel_helper_map_.find(request->channel()) != connection_less_channel_helper_map_.end()) {
       return ::grpc::Status(::grpc::StatusCode::FAILED_PRECONDITION, "Already registered");
@@ -104,21 +106,22 @@ class L2capModuleFacadeService : public L2capModuleFacade::Service {
 
   class L2capFixedChannelHelper {
    public:
-    L2capFixedChannelHelper(L2capModuleFacadeService* service, L2capLayer* l2cap_layer, os::Handler* handler, Cid cid)
+    L2capFixedChannelHelper(L2capModuleFacadeService* service, L2capClassicModule* l2cap_layer, os::Handler* handler,
+                            Cid cid)
         : facade_service_(service), l2cap_layer_(l2cap_layer), handler_(handler), cid_(cid) {
-      fixed_channel_manager_ = l2cap_layer_->GetClassicFixedChannelManager();
+      fixed_channel_manager_ = l2cap_layer_->GetFixedChannelManager();
       fixed_channel_manager_->RegisterService(
           cid, {},
           common::BindOnce(&L2capFixedChannelHelper::on_l2cap_service_registration_complete, common::Unretained(this)),
           common::Bind(&L2capFixedChannelHelper::on_connection_open, common::Unretained(this)), handler_);
     }
 
-    void on_l2cap_service_registration_complete(ClassicFixedChannelManager::RegistrationResult registration_result,
-                                                std::unique_ptr<ClassicFixedChannelService> service) {
+    void on_l2cap_service_registration_complete(FixedChannelManager::RegistrationResult registration_result,
+                                                std::unique_ptr<FixedChannelService> service) {
       service_ = std::move(service);
     }
 
-    void on_connection_open(std::unique_ptr<ClassicFixedChannel> channel) {
+    void on_connection_open(std::unique_ptr<FixedChannel> channel) {
       ConnectionCompleteEvent event;
       event.mutable_remote()->set_address(channel->GetDevice().ToString());
       facade_service_->connection_complete_stream_.OnIncomingEvent(event);
@@ -151,15 +154,15 @@ class L2capModuleFacadeService : public L2capModuleFacade::Service {
     };
 
     L2capModuleFacadeService* facade_service_;
-    L2capLayer* l2cap_layer_;
+    L2capClassicModule* l2cap_layer_;
     os::Handler* handler_;
-    std::unique_ptr<ClassicFixedChannelManager> fixed_channel_manager_;
-    std::unique_ptr<ClassicFixedChannelService> service_;
-    std::unique_ptr<ClassicFixedChannel> channel_ = nullptr;
+    std::unique_ptr<FixedChannelManager> fixed_channel_manager_;
+    std::unique_ptr<FixedChannelService> service_;
+    std::unique_ptr<FixedChannel> channel_ = nullptr;
     Cid cid_;
   };
 
-  l2cap::L2capLayer* l2cap_layer_;
+  l2cap::classic::L2capClassicModule* l2cap_layer_;
   ::bluetooth::os::Handler* facade_handler_;
   std::map<Cid, std::unique_ptr<L2capFixedChannelHelper>> connection_less_channel_helper_map_;
 
@@ -211,7 +214,7 @@ class L2capModuleFacadeService : public L2capModuleFacade::Service {
 
 void L2capModuleFacadeModule::ListDependencies(ModuleList* list) {
   ::bluetooth::grpc::GrpcFacadeModule::ListDependencies(list);
-  list->add<l2cap::L2capLayer>();
+  list->add<l2cap::classic::L2capClassicModule>();
   list->add<hci::HciLayer>();
 }
 
@@ -219,7 +222,7 @@ void L2capModuleFacadeModule::Start() {
   ::bluetooth::grpc::GrpcFacadeModule::Start();
   GetDependency<hci::HciLayer>()->EnqueueCommand(hci::WriteScanEnableBuilder::Create(hci::ScanEnable::PAGE_SCAN_ONLY),
                                                  common::BindOnce([](hci::CommandCompleteView) {}), GetHandler());
-  service_ = new L2capModuleFacadeService(GetDependency<l2cap::L2capLayer>(), GetHandler());
+  service_ = new L2capModuleFacadeService(GetDependency<l2cap::classic::L2capClassicModule>(), GetHandler());
 }
 
 void L2capModuleFacadeModule::Stop() {
@@ -234,5 +237,6 @@ void L2capModuleFacadeModule::Stop() {
 const ModuleFactory L2capModuleFacadeModule::Factory =
     ::bluetooth::ModuleFactory([]() { return new L2capModuleFacadeModule(); });
 
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 94%
rename from gd/l2cap/facade.h
rename to gd/l2cap/classic/facade.h
index 734d261..425940a 100644 (file)
@@ -20,6 +20,7 @@
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
 class L2capModuleFacadeService;
 
@@ -37,5 +38,6 @@ class L2capModuleFacadeModule : public ::bluetooth::grpc::GrpcFacadeModule {
   L2capModuleFacadeService* service_;
 };
 
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
similarity index 98%
rename from gd/l2cap/facade.proto
rename to gd/l2cap/classic/facade.proto
index 65dd55f..2e3f6f3 100644 (file)
@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package bluetooth.l2cap;
+package bluetooth.l2cap.classic;
 
 import "google/protobuf/empty.proto";
 import "facade/common.proto";
similarity index 50%
rename from gd/l2cap/classic_fixed_channel.cc
rename to gd/l2cap/classic/fixed_channel.cc
index 99eb593..a90d119 100644 (file)
  * limitations under the License.
  */
 
-#include "l2cap/classic_fixed_channel.h"
+#include "l2cap/classic/fixed_channel.h"
 #include "common/bind.h"
-#include "l2cap/internal/classic_fixed_channel_impl.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
-hci::Address ClassicFixedChannel::GetDevice() const {
+hci::Address FixedChannel::GetDevice() const {
   return impl_->GetDevice();
 }
 
-void ClassicFixedChannel::RegisterOnCloseCallback(os::Handler* user_handler,
-                                                  ClassicFixedChannel::OnCloseCallback on_close_callback) {
-  l2cap_handler_->Post(common::BindOnce(&internal::ClassicFixedChannelImpl::RegisterOnCloseCallback, impl_,
-                                        user_handler, std::move(on_close_callback)));
+void FixedChannel::RegisterOnCloseCallback(os::Handler* user_handler, FixedChannel::OnCloseCallback on_close_callback) {
+  l2cap_handler_->Post(common::BindOnce(&internal::FixedChannelImpl::RegisterOnCloseCallback, impl_, user_handler,
+                                        std::move(on_close_callback)));
 }
 
-void ClassicFixedChannel::Acquire() {
-  l2cap_handler_->Post(common::BindOnce(&internal::ClassicFixedChannelImpl::Acquire, impl_));
+void FixedChannel::Acquire() {
+  l2cap_handler_->Post(common::BindOnce(&internal::FixedChannelImpl::Acquire, impl_));
 }
 
-void ClassicFixedChannel::Release() {
-  l2cap_handler_->Post(common::BindOnce(&internal::ClassicFixedChannelImpl::Release, impl_));
+void FixedChannel::Release() {
+  l2cap_handler_->Post(common::BindOnce(&internal::FixedChannelImpl::Release, impl_));
 }
 
 common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>*
-ClassicFixedChannel::GetQueueUpEnd() const {
+FixedChannel::GetQueueUpEnd() const {
   return impl_->GetQueueUpEnd();
 }
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
similarity index 86%
rename from gd/l2cap/classic_fixed_channel.h
rename to gd/l2cap/classic/fixed_channel.h
index dadd39d..bf88e3d 100644 (file)
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
 namespace internal {
-class ClassicFixedChannelImpl;
+class FixedChannelImpl;
 }  // namespace internal
 
 /**
@@ -36,10 +37,10 @@ class ClassicFixedChannelImpl;
  * Otherwise, {@link FixedChannel#Release()} will be called automatically.
  *
  */
-class ClassicFixedChannel {
+class FixedChannel {
  public:
-  // Should only be constructed by modules that have access to ClassicLinkManager
-  ClassicFixedChannel(std::shared_ptr<internal::ClassicFixedChannelImpl> impl, os::Handler* l2cap_handler)
+  // Should only be constructed by modules that have access to LinkManager
+  FixedChannel(std::shared_ptr<internal::FixedChannelImpl> impl, os::Handler* l2cap_handler)
       : impl_(std::move(impl)), l2cap_handler_(l2cap_handler) {
     ASSERT(impl_ != nullptr);
     ASSERT(l2cap_handler_ != nullptr);
@@ -65,7 +66,7 @@ class ClassicFixedChannel {
 
   /**
    * Indicate that this Fixed Channel is no longer being used. ACL connection will be disconnected after
-   * kClassicLinkIdleDisconnectTimeout if no other DynamicChannel is connected or no other Fixed Channel is  using this
+   * kLinkIdleDisconnectTimeout if no other DynamicChannel is connected or no other Fixed Channel is  using this
    * ACL connection. However a module can still receive data on this channel as long as it remains open.
    */
   void Release();
@@ -80,9 +81,10 @@ class ClassicFixedChannel {
   common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>* GetQueueUpEnd() const;
 
  private:
-  std::shared_ptr<internal::ClassicFixedChannelImpl> impl_;
+  std::shared_ptr<internal::FixedChannelImpl> impl_;
   os::Handler* l2cap_handler_;
 };
 
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 54%
rename from gd/l2cap/classic_fixed_channel_manager.cc
rename to gd/l2cap/classic/fixed_channel_manager.cc
index af44435..3334804 100644 (file)
  * limitations under the License.
  */
 
-#include "l2cap/classic_fixed_channel_manager.h"
-#include "l2cap/internal/classic_fixed_channel_service_impl.h"
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
-#include "l2cap/internal/classic_link_manager.h"
+#include "l2cap/classic/fixed_channel_manager.h"
+#include "l2cap/classic/internal/fixed_channel_service_impl.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/link_manager.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
-bool ClassicFixedChannelManager::ConnectServices(hci::Address device, OnConnectionFailureCallback on_fail_callback,
-                                                 os::Handler* handler) {
-  internal::ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+bool FixedChannelManager::ConnectServices(hci::Address device, OnConnectionFailureCallback on_fail_callback,
+                                          os::Handler* handler) {
+  internal::LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
       .on_fail_callback_ = std::move(on_fail_callback), .handler_ = handler};
-  l2cap_layer_handler_->Post(common::BindOnce(&internal::ClassicLinkManager::ConnectFixedChannelServices,
+  l2cap_layer_handler_->Post(common::BindOnce(&internal::LinkManager::ConnectFixedChannelServices,
                                               common::Unretained(link_manager_), device,
                                               std::move(pending_fixed_channel_connection)));
   return true;
 }
 
-bool ClassicFixedChannelManager::RegisterService(Cid cid, const SecurityPolicy& security_policy,
-                                                 OnRegistrationCompleteCallback on_registration_complete,
-                                                 OnConnectionOpenCallback on_connection_open, os::Handler* handler) {
-  internal::ClassicFixedChannelServiceImpl::PendingRegistration pending_registration{
+bool FixedChannelManager::RegisterService(Cid cid, const SecurityPolicy& security_policy,
+                                          OnRegistrationCompleteCallback on_registration_complete,
+                                          OnConnectionOpenCallback on_connection_open, os::Handler* handler) {
+  internal::FixedChannelServiceImpl::PendingRegistration pending_registration{
       .user_handler_ = handler,
       .on_registration_complete_callback_ = std::move(on_registration_complete),
       .on_connection_open_callback_ = std::move(on_connection_open)};
-  l2cap_layer_handler_->Post(common::BindOnce(&internal::ClassicFixedChannelServiceManagerImpl::Register,
+  l2cap_layer_handler_->Post(common::BindOnce(&internal::FixedChannelServiceManagerImpl::Register,
                                               common::Unretained(service_manager_), cid,
                                               std::move(pending_registration)));
   return true;
 }
 
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 80%
rename from gd/l2cap/classic_fixed_channel_manager.h
rename to gd/l2cap/classic/fixed_channel_manager.h
index 88691f8..69812df 100644 (file)
 #include "hci/acl_manager.h"
 #include "hci/address.h"
 #include "l2cap/cid.h"
-#include "l2cap/classic_fixed_channel.h"
-#include "l2cap/classic_fixed_channel_service.h"
+#include "l2cap/classic/fixed_channel.h"
+#include "l2cap/classic/fixed_channel_service.h"
 #include "l2cap/security_policy.h"
 #include "os/handler.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
-class L2capLayer;
+class L2capClassicModule;
 
 namespace internal {
-class ClassicLinkManager;
-class ClassicFixedChannelServiceManagerImpl;
+class LinkManager;
+class FixedChannelServiceManagerImpl;
 }  // namespace internal
 
-class ClassicFixedChannelManager {
+class FixedChannelManager {
  public:
   enum class ConnectionResultCode {
     SUCCESS = 0,
@@ -54,9 +55,9 @@ class ClassicFixedChannelManager {
   using OnConnectionFailureCallback = common::OnceCallback<void(ConnectionResult result)>;
 
   /**
-   * OnConnectionOpenCallback(ClassicFixedChannel channel);
+   * OnConnectionOpenCallback(FixedChannel channel);
    */
-  using OnConnectionOpenCallback = common::Callback<void(std::unique_ptr<ClassicFixedChannel>)>;
+  using OnConnectionOpenCallback = common::Callback<void(std::unique_ptr<FixedChannel>)>;
 
   enum class RegistrationResult {
     SUCCESS = 0,
@@ -65,10 +66,10 @@ class ClassicFixedChannelManager {
   };
 
   /**
-   * OnRegistrationFailureCallback(RegistrationResult result, ClassicFixedChannelService service);
+   * OnRegistrationFailureCallback(RegistrationResult result, FixedChannelService service);
    */
   using OnRegistrationCompleteCallback =
-      common::OnceCallback<void(RegistrationResult, std::unique_ptr<ClassicFixedChannelService>)>;
+      common::OnceCallback<void(RegistrationResult, std::unique_ptr<FixedChannelService>)>;
 
   /**
    * Connect to ALL fixed channels on a remote device
@@ -78,10 +79,10 @@ class ClassicFixedChannelManager {
    * - When true is returned, method caller should wait for on_fail_callback or on_open_callback registered through
    *   RegisterService() API.
    * - If an ACL connection does not exist, this method will create an ACL connection. As a result, on_open_callback
-   *   supplied through RegisterService() will be triggered to provide the actual ClassicFixedChannel objects
+   *   supplied through RegisterService() will be triggered to provide the actual FixedChannel objects
    * - If HCI connection failed, on_fail_callback will be triggered with FAIL_HCI_ERROR
    * - If fixed channel on a remote device is already reported as connected via on_open_callback and has been acquired
-   *   via ClassicFixedChannel#Acquire() API, it won't be reported again
+   *   via FixedChannel#Acquire() API, it won't be reported again
    * - If no service is registered, on_fail_callback will be triggered with FAIL_NO_SERVICE_REGISTERED
    * - If there is an ACL connection and channels for each service is allocated, on_fail_callback will be triggered with
    *   FAIL_ALL_SERVICES_HAVE_CHANNEL
@@ -90,7 +91,7 @@ class ClassicFixedChannelManager {
    * This call will initiate an effort to connect all fixed channel services on a remote device.
    * Due to the connectionless nature of fixed channels, all fixed channels will be connected together.
    * If a fixed channel service does not need a particular fixed channel. It should release the received
-   * channel immediately after receiving on_open_callback via ClassicFixedChannel#Release()
+   * channel immediately after receiving on_open_callback via FixedChannel#Release()
    *
    * A module calling ConnectServices() must have called RegisterService() before.
    * The callback will come back from on_open_callback in the service that is registered
@@ -109,14 +110,14 @@ class ClassicFixedChannelManager {
    * - This method is asynchronous.
    * - When false is returned, the registration fails immediately.
    * - When true is returned, method caller should wait for on_service_registered callback that contains a
-   *   ClassicFixedChannelService object. The registered service can be managed from that object.
+   *   FixedChannelService object. The registered service can be managed from that object.
    * - If a CID is already registered or some other error happens, on_registration_complete will be triggered with a
    *   non-SUCCESS value
-   * - After a service is registered, any classic ACL connection will create a ClassicFixedChannel object that is
+   * - After a service is registered, any classic ACL connection will create a FixedChannel object that is
    *   delivered through on_open_callback
    * - on_open_callback, will only be triggered after on_service_registered callback
    *
-   * @param cid: Classic cid used to receive incoming connections
+   * @param cid:  cid used to receive incoming connections
    * @param security_policy: The security policy used for the connection.
    * @param on_registration_complete: A callback to indicate the service setup has completed. If the return status is
    *        not SUCCESS, it means service is not registered due to reasons like CID already take
@@ -127,18 +128,19 @@ class ClassicFixedChannelManager {
                        OnRegistrationCompleteCallback on_registration_complete,
                        OnConnectionOpenCallback on_connection_open, os::Handler* handler);
 
-  friend class L2capLayer;
+  friend class L2capClassicModule;
 
  private:
   // The constructor is not to be used by user code
-  ClassicFixedChannelManager(internal::ClassicFixedChannelServiceManagerImpl* service_manager,
-                             internal::ClassicLinkManager* link_manager, os::Handler* l2cap_layer_handler)
+  FixedChannelManager(internal::FixedChannelServiceManagerImpl* service_manager, internal::LinkManager* link_manager,
+                      os::Handler* l2cap_layer_handler)
       : service_manager_(service_manager), link_manager_(link_manager), l2cap_layer_handler_(l2cap_layer_handler) {}
-  internal::ClassicFixedChannelServiceManagerImpl* service_manager_ = nullptr;
-  internal::ClassicLinkManager* link_manager_ = nullptr;
+  internal::FixedChannelServiceManagerImpl* service_manager_ = nullptr;
+  internal::LinkManager* link_manager_ = nullptr;
   os::Handler* l2cap_layer_handler_ = nullptr;
-  DISALLOW_COPY_AND_ASSIGN(ClassicFixedChannelManager);
+  DISALLOW_COPY_AND_ASSIGN(FixedChannelManager);
 };
 
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 69%
rename from gd/l2cap/classic_fixed_channel_service.cc
rename to gd/l2cap/classic/fixed_channel_service.cc
index 5199126..49a977d 100644 (file)
  * limitations under the License.
  */
 
-#include "l2cap/classic_fixed_channel_service.h"
+#include "l2cap/classic/fixed_channel_service.h"
 #include "common/bind.h"
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
-void ClassicFixedChannelService::Unregister(OnUnregisteredCallback on_unregistered,
-                                            os::Handler* on_unregistered_handler) {
+void FixedChannelService::Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler) {
   ASSERT_LOG(manager_ != nullptr, "this service is invalid");
-  l2cap_layer_handler_->Post(common::BindOnce(&internal::ClassicFixedChannelServiceManagerImpl::Unregister,
+  l2cap_layer_handler_->Post(common::BindOnce(&internal::FixedChannelServiceManagerImpl::Unregister,
                                               common::Unretained(manager_), cid_, std::move(on_unregistered),
                                               on_unregistered_handler));
 }
 
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
similarity index 76%
rename from gd/l2cap/classic_fixed_channel_service.h
rename to gd/l2cap/classic/fixed_channel_service.h
index 05abaed..d5d213b 100644 (file)
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
 namespace internal {
-class ClassicFixedChannelServiceManagerImpl;
+class FixedChannelServiceManagerImpl;
 }  // namespace internal
 
-class ClassicFixedChannelService {
+class FixedChannelService {
  public:
-  ClassicFixedChannelService() = default;
+  FixedChannelService() = default;
 
   using OnUnregisteredCallback = common::OnceCallback<void()>;
 
@@ -42,16 +43,17 @@ class ClassicFixedChannelService {
    */
   void Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler);
 
-  friend internal::ClassicFixedChannelServiceManagerImpl;
+  friend internal::FixedChannelServiceManagerImpl;
 
  private:
-  ClassicFixedChannelService(Cid cid, internal::ClassicFixedChannelServiceManagerImpl* manager, os::Handler* handler)
+  FixedChannelService(Cid cid, internal::FixedChannelServiceManagerImpl* manager, os::Handler* handler)
       : cid_(cid), manager_(manager), l2cap_layer_handler_(handler) {}
   Cid cid_ = kInvalidCid;
-  internal::ClassicFixedChannelServiceManagerImpl* manager_ = nullptr;
+  internal::FixedChannelServiceManagerImpl* manager_ = nullptr;
   os::Handler* l2cap_layer_handler_;
-  DISALLOW_COPY_AND_ASSIGN(ClassicFixedChannelService);
+  DISALLOW_COPY_AND_ASSIGN(FixedChannelService);
 };
 
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
 
 #include <unordered_map>
 
-#include "classic_dynamic_channel_allocator.h"
 #include "l2cap/cid.h"
-#include "l2cap/internal/classic_dynamic_channel_allocator.h"
-#include "l2cap/internal/classic_link.h"
+#include "l2cap/classic/internal/dynamic_channel_allocator.h"
+#include "l2cap/classic/internal/link.h"
 #include "l2cap/security_policy.h"
 #include "os/handler.h"
 #include "os/log.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-std::shared_ptr<ClassicDynamicChannelImpl> ClassicDynamicChannelAllocator::AllocateChannel(
-    Psm psm, Cid remote_cid, SecurityPolicy security_policy) {
+std::shared_ptr<DynamicChannelImpl> DynamicChannelAllocator::AllocateChannel(Psm psm, Cid remote_cid,
+                                                                             SecurityPolicy security_policy) {
   if (IsChannelAllocated((psm))) {
     LOG_INFO("Psm 0x%x for device %s is already in use", psm, link_->GetDevice().ToString().c_str());
     return nullptr;
@@ -51,8 +51,8 @@ std::shared_ptr<ClassicDynamicChannelImpl> ClassicDynamicChannelAllocator::Alloc
     LOG_WARN("All cid are used");
     return nullptr;
   }
-  auto elem = channels_.try_emplace(
-      psm, std::make_shared<ClassicDynamicChannelImpl>(psm, cid, remote_cid, link_, l2cap_handler_));
+  auto elem =
+      channels_.try_emplace(psm, std::make_shared<DynamicChannelImpl>(psm, cid, remote_cid, link_, l2cap_handler_));
   ASSERT_LOG(elem.second, "Failed to create channel for psm 0x%x device %s", psm,
              link_->GetDevice().ToString().c_str());
   ASSERT(elem.first->second != nullptr);
@@ -61,32 +61,33 @@ std::shared_ptr<ClassicDynamicChannelImpl> ClassicDynamicChannelAllocator::Alloc
   return elem.first->second;
 }
 
-void ClassicDynamicChannelAllocator::FreeChannel(Psm psm) {
+void DynamicChannelAllocator::FreeChannel(Psm psm) {
   ASSERT_LOG(IsChannelAllocated(psm), "Channel is not in use: psm %d, device %s", psm,
              link_->GetDevice().ToString().c_str());
   channels_.erase(psm);
 }
 
-bool ClassicDynamicChannelAllocator::IsChannelAllocated(Psm psm) const {
+bool DynamicChannelAllocator::IsChannelAllocated(Psm psm) const {
   return channels_.find(psm) != channels_.end();
 }
 
-std::shared_ptr<ClassicDynamicChannelImpl> ClassicDynamicChannelAllocator::FindChannel(Psm psm) {
+std::shared_ptr<DynamicChannelImpl> DynamicChannelAllocator::FindChannel(Psm psm) {
   ASSERT_LOG(IsChannelAllocated(psm), "Channel is not in use: psm %d, device %s", psm,
              link_->GetDevice().ToString().c_str());
   return channels_.find(psm)->second;
 }
 
-size_t ClassicDynamicChannelAllocator::NumberOfChannels() const {
+size_t DynamicChannelAllocator::NumberOfChannels() const {
   return channels_.size();
 }
 
-void ClassicDynamicChannelAllocator::OnAclDisconnected(hci::ErrorCode reason) {
+void DynamicChannelAllocator::OnAclDisconnected(hci::ErrorCode reason) {
   for (auto& elem : channels_) {
     elem.second->OnClosed(reason);
   }
 }
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
@@ -20,7 +20,7 @@
 #include <unordered_map>
 
 #include "l2cap/cid.h"
-#include "l2cap/internal/classic_dynamic_channel_impl.h"
+#include "l2cap/classic/internal/dynamic_channel_impl.h"
 #include "l2cap/psm.h"
 #include "l2cap/security_policy.h"
 #include "os/handler.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-class ClassicLink;
+class Link;
 
 // Helper class for keeping channels in a Link. It allocates and frees Channel object, and supports querying whether a
 // channel is in use
-class ClassicDynamicChannelAllocator {
+class DynamicChannelAllocator {
  public:
-  ClassicDynamicChannelAllocator(ClassicLink* link, os::Handler* l2cap_handler)
-      : link_(link), l2cap_handler_(l2cap_handler) {
+  DynamicChannelAllocator(Link* link, os::Handler* l2cap_handler) : link_(link), l2cap_handler_(l2cap_handler) {
     ASSERT(link_ != nullptr);
     ASSERT(l2cap_handler_ != nullptr);
   }
 
   // Allocates a channel. If psm is used, OR the remote cid already exists, return nullptr.
-  // NOTE: The returned ClassicDynamicChannelImpl object is still owned by the channel allocator, NOT the client.
-  std::shared_ptr<ClassicDynamicChannelImpl> AllocateChannel(Psm psm, Cid remote_cid, SecurityPolicy security_policy);
+  // NOTE: The returned DynamicChannelImpl object is still owned by the channel allocator, NOT the client.
+  std::shared_ptr<DynamicChannelImpl> AllocateChannel(Psm psm, Cid remote_cid, SecurityPolicy security_policy);
 
   // Frees a channel. If psm doesn't exist, it will crash
   void FreeChannel(Psm psm);
 
   bool IsChannelAllocated(Psm psm) const;
 
-  std::shared_ptr<ClassicDynamicChannelImpl> FindChannel(Psm psm);
+  std::shared_ptr<DynamicChannelImpl> FindChannel(Psm psm);
 
   size_t NumberOfChannels() const;
 
   void OnAclDisconnected(hci::ErrorCode hci_status);
 
  private:
-  ClassicLink* link_;
+  Link* link_;
   os::Handler* l2cap_handler_;
-  std::unordered_map<Psm, std::shared_ptr<ClassicDynamicChannelImpl>> channels_;
+  std::unordered_map<Psm, std::shared_ptr<DynamicChannelImpl>> channels_;
   std::set<Cid> used_cid_;
   std::set<Cid> used_remote_cid_;
 };
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#include "l2cap/internal/classic_dynamic_channel_allocator.h"
-#include "l2cap/internal/classic_link_mock.h"
+#include "l2cap/classic/internal/dynamic_channel_allocator.h"
+#include "l2cap/classic/internal/link_mock.h"
 #include "l2cap/internal/parameter_provider_mock.h"
 
 #include <gmock/gmock.h>
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-using testing::MockClassicLink;
-using testing::MockParameterProvider;
+using l2cap::internal::testing::MockParameterProvider;
+using testing::MockLink;
 using ::testing::Return;
 
 const hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
@@ -37,9 +38,9 @@ class L2capClassicDynamicChannelAllocatorTest : public ::testing::Test {
     thread_ = new os::Thread("test_thread", os::Thread::Priority::NORMAL);
     handler_ = new os::Handler(thread_);
     mock_parameter_provider_ = new MockParameterProvider();
-    mock_classic_link_ = new MockClassicLink(handler_, mock_parameter_provider_);
+    mock_classic_link_ = new MockLink(handler_, mock_parameter_provider_);
     EXPECT_CALL(*mock_classic_link_, GetDevice()).WillRepeatedly(Return(device));
-    channel_allocator_ = std::make_unique<ClassicDynamicChannelAllocator>(mock_classic_link_, handler_);
+    channel_allocator_ = std::make_unique<DynamicChannelAllocator>(mock_classic_link_, handler_);
   }
 
   void TearDown() override {
@@ -54,8 +55,8 @@ class L2capClassicDynamicChannelAllocatorTest : public ::testing::Test {
   os::Thread* thread_{nullptr};
   os::Handler* handler_{nullptr};
   MockParameterProvider* mock_parameter_provider_{nullptr};
-  MockClassicLink* mock_classic_link_{nullptr};
-  std::unique_ptr<ClassicDynamicChannelAllocator> channel_allocator_;
+  MockLink* mock_classic_link_{nullptr};
+  std::unique_ptr<DynamicChannelAllocator> channel_allocator_;
 };
 
 TEST_F(L2capClassicDynamicChannelAllocatorTest, precondition) {
@@ -74,5 +75,6 @@ TEST_F(L2capClassicDynamicChannelAllocatorTest, allocate_and_free_channel) {
 }
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
@@ -17,8 +17,8 @@
 #include <unordered_map>
 
 #include "l2cap/cid.h"
-#include "l2cap/internal/classic_dynamic_channel_impl.h"
-#include "l2cap/internal/classic_link.h"
+#include "l2cap/classic/internal/dynamic_channel_impl.h"
+#include "l2cap/classic/internal/link.h"
 #include "l2cap/psm.h"
 #include "l2cap/security_policy.h"
 #include "os/handler.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-ClassicDynamicChannelImpl::ClassicDynamicChannelImpl(Psm psm, Cid cid, Cid remote_cid, ClassicLink* link,
-                                                     os::Handler* l2cap_handler)
+DynamicChannelImpl::DynamicChannelImpl(Psm psm, Cid cid, Cid remote_cid, Link* link, os::Handler* l2cap_handler)
     : psm_(psm), cid_(cid), remote_cid_(remote_cid), link_(link), l2cap_handler_(l2cap_handler),
       device_(link->GetDevice()) {
   ASSERT(IsPsmValid(psm_));
@@ -39,12 +39,12 @@ ClassicDynamicChannelImpl::ClassicDynamicChannelImpl(Psm psm, Cid cid, Cid remot
   ASSERT(l2cap_handler_ != nullptr);
 }
 
-hci::Address ClassicDynamicChannelImpl::GetDevice() const {
+hci::Address DynamicChannelImpl::GetDevice() const {
   return device_;
 }
 
-void ClassicDynamicChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler,
-                                                        ClassicDynamicChannel::OnCloseCallback on_close_callback) {
+void DynamicChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler,
+                                                 DynamicChannel::OnCloseCallback on_close_callback) {
   ASSERT_LOG(user_handler_ == nullptr, "OnCloseCallback can only be registered once");
   // If channel is already closed, call the callback immediately without saving it
   if (closed_) {
@@ -55,11 +55,11 @@ void ClassicDynamicChannelImpl::RegisterOnCloseCallback(os::Handler* user_handle
   on_close_callback_ = std::move(on_close_callback);
 }
 
-void ClassicDynamicChannelImpl::Close() {
+void DynamicChannelImpl::Close() {
   // TODO: Implement it by sending signalling packet
 }
 
-void ClassicDynamicChannelImpl::OnClosed(hci::ErrorCode status) {
+void DynamicChannelImpl::OnClosed(hci::ErrorCode status) {
   ASSERT_LOG(!closed_, "Device %s Cid 0x%x closed twice, old status 0x%x, new status 0x%x", device_.ToString().c_str(),
              cid_, static_cast<int>(close_reason_), static_cast<int>(status));
   closed_ = true;
@@ -75,12 +75,13 @@ void ClassicDynamicChannelImpl::OnClosed(hci::ErrorCode status) {
   on_close_callback_.Reset();
 }
 
-std::string ClassicDynamicChannelImpl::ToString() {
+std::string DynamicChannelImpl::ToString() {
   std::ostringstream ss;
   ss << "Device " << device_.ToString() << "Psm 0x" << std::hex << psm_ << " Cid 0x" << std::hex << cid_;
   return ss.str();
 }
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
 #include "common/bidi_queue.h"
 #include "hci/address.h"
 #include "l2cap/cid.h"
-#include "l2cap/classic_dynamic_channel.h"
+#include "l2cap/classic/dynamic_channel.h"
 #include "l2cap/psm.h"
 #include "os/handler.h"
 #include "os/log.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-class ClassicLink;
+class Link;
 
-class ClassicDynamicChannelImpl {
+class DynamicChannelImpl {
  public:
-  ClassicDynamicChannelImpl(Psm psm, Cid cid, Cid remote_cid, ClassicLink* link, os::Handler* l2cap_handler);
+  DynamicChannelImpl(Psm psm, Cid cid, Cid remote_cid, Link* link, os::Handler* l2cap_handler);
 
-  virtual ~ClassicDynamicChannelImpl() = default;
+  virtual ~DynamicChannelImpl() = default;
 
   hci::Address GetDevice() const;
 
-  virtual void RegisterOnCloseCallback(os::Handler* user_handler,
-                                       ClassicDynamicChannel::OnCloseCallback on_close_callback);
+  virtual void RegisterOnCloseCallback(os::Handler* user_handler, DynamicChannel::OnCloseCallback on_close_callback);
 
   virtual void Close();
   virtual void OnClosed(hci::ErrorCode status);
@@ -61,13 +61,13 @@ class ClassicDynamicChannelImpl {
   const Psm psm_;
   const Cid cid_;
   const Cid remote_cid_;
-  ClassicLink* link_;
+  Link* link_;
   os::Handler* l2cap_handler_;
   const hci::Address device_;
 
   // User supported states
   os::Handler* user_handler_ = nullptr;
-  ClassicDynamicChannel::OnCloseCallback on_close_callback_{};
+  DynamicChannel::OnCloseCallback on_close_callback_{};
 
   // Internal states
   bool closed_ = false;
@@ -76,9 +76,10 @@ class ClassicDynamicChannelImpl {
   common::BidiQueue<packet::PacketView<packet::kLittleEndian>, packet::BasePacketBuilder> channel_queue_{
       kChannelQueueSize};
 
-  DISALLOW_COPY_AND_ASSIGN(ClassicDynamicChannelImpl);
+  DISALLOW_COPY_AND_ASSIGN(DynamicChannelImpl);
 };
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "l2cap/internal/classic_dynamic_channel_impl.h"
+#include "l2cap/classic/internal/dynamic_channel_impl.h"
 
 #include "common/testing/bind_test_util.h"
 #include "l2cap/cid.h"
-#include "l2cap/internal/classic_link_mock.h"
+#include "l2cap/classic/internal/link_mock.h"
 #include "l2cap/internal/parameter_provider_mock.h"
 #include "os/handler.h"
 
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-using testing::MockClassicLink;
-using testing::MockParameterProvider;
+using l2cap::internal::testing::MockParameterProvider;
+using testing::MockLink;
 using ::testing::Return;
 
 class L2capClassicDynamicChannelImplTest : public ::testing::Test {
@@ -59,21 +60,21 @@ class L2capClassicDynamicChannelImplTest : public ::testing::Test {
 
 TEST_F(L2capClassicDynamicChannelImplTest, get_device) {
   MockParameterProvider mock_parameter_provider;
-  MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
-  ClassicDynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
-                                                 l2cap_handler_);
+  DynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
+                                          l2cap_handler_);
   EXPECT_EQ(device, dynamic_channel_impl.GetDevice());
 }
 
 TEST_F(L2capClassicDynamicChannelImplTest, close_triggers_callback) {
   MockParameterProvider mock_parameter_provider;
-  MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
-  ClassicDynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
-                                                 l2cap_handler_);
+  DynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
+                                          l2cap_handler_);
 
   // Register on close callback
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -91,11 +92,11 @@ TEST_F(L2capClassicDynamicChannelImplTest, close_triggers_callback) {
 
 TEST_F(L2capClassicDynamicChannelImplTest, register_callback_after_close_should_call_immediately) {
   MockParameterProvider mock_parameter_provider;
-  MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
-  ClassicDynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
-                                                 l2cap_handler_);
+  DynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
+                                          l2cap_handler_);
 
   // Channel closure should do nothing
   dynamic_channel_impl.OnClosed(hci::ErrorCode::REMOTE_USER_TERMINATED_CONNECTION);
@@ -113,11 +114,11 @@ TEST_F(L2capClassicDynamicChannelImplTest, register_callback_after_close_should_
 
 TEST_F(L2capClassicDynamicChannelImplTest, close_twice_should_fail) {
   MockParameterProvider mock_parameter_provider;
-  MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
-  ClassicDynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
-                                                 l2cap_handler_);
+  DynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
+                                          l2cap_handler_);
 
   // Register on close callback
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -138,11 +139,11 @@ TEST_F(L2capClassicDynamicChannelImplTest, close_twice_should_fail) {
 
 TEST_F(L2capClassicDynamicChannelImplTest, multiple_registeration_should_fail) {
   MockParameterProvider mock_parameter_provider;
-  MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
-  ClassicDynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
-                                                 l2cap_handler_);
+  DynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
+                                          l2cap_handler_);
 
   // Register on close callback
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -158,5 +159,6 @@ TEST_F(L2capClassicDynamicChannelImplTest, multiple_registeration_should_fail) {
 }
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
 
 #pragma once
 
-#include "l2cap/le_fixed_channel.h"
-#include "l2cap/le_fixed_channel_manager.h"
-#include "l2cap/le_fixed_channel_service.h"
+#include "common/bind.h"
+
+#include "l2cap/classic/dynamic_channel.h"
+#include "l2cap/classic/dynamic_channel_manager.h"
+#include "l2cap/classic/dynamic_channel_service.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
-
-class LeFixedChannelServiceImpl {
+class DynamicChannelServiceImpl {
  public:
-  virtual ~LeFixedChannelServiceImpl() = default;
+  virtual ~DynamicChannelServiceImpl() = default;
 
   struct PendingRegistration {
     os::Handler* user_handler_ = nullptr;
-    LeFixedChannelManager::OnRegistrationCompleteCallback on_registration_complete_callback_;
-    LeFixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
+    DynamicChannelManager::OnRegistrationCompleteCallback on_registration_complete_callback_;
+    DynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
   };
 
-  virtual void NotifyChannelCreation(std::unique_ptr<LeFixedChannel> channel) {
+  virtual void NotifyChannelCreation(std::unique_ptr<DynamicChannel> channel) {
     user_handler_->Post(common::BindOnce(on_connection_open_callback_, std::move(channel)));
   }
 
-  friend class LeFixedChannelServiceManagerImpl;
+  friend class DynamicChannelServiceManagerImpl;
 
  protected:
   // protected access for mocking
-  LeFixedChannelServiceImpl(os::Handler* user_handler,
-                            LeFixedChannelManager::OnConnectionOpenCallback on_connection_open_callback)
+  DynamicChannelServiceImpl(os::Handler* user_handler,
+                            DynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback)
       : user_handler_(user_handler), on_connection_open_callback_(std::move(on_connection_open_callback)) {}
 
  private:
   os::Handler* user_handler_ = nullptr;
-  LeFixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
+  DynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
 };
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
  * limitations under the License.
  */
 
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
-
+#include "l2cap/classic/internal/dynamic_channel_service_manager_impl.h"
 #include "common/bind.h"
-#include "l2cap/cid.h"
-#include "l2cap/internal/le_fixed_channel_service_impl.h"
+#include "l2cap/classic/internal/dynamic_channel_service_impl.h"
+#include "l2cap/psm.h"
 #include "os/log.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-void LeFixedChannelServiceManagerImpl::Register(Cid cid,
-                                                LeFixedChannelServiceImpl::PendingRegistration pending_registration) {
-  if (cid < kFirstFixedChannel || cid > kLastFixedChannel || cid == kLeSignallingCid) {
-    std::unique_ptr<LeFixedChannelService> invalid_service(new LeFixedChannelService());
+void DynamicChannelServiceManagerImpl::Register(Psm psm,
+                                                DynamicChannelServiceImpl::PendingRegistration pending_registration) {
+  if (!IsPsmValid(psm)) {
+    std::unique_ptr<DynamicChannelService> invalid_service(new DynamicChannelService());
     pending_registration.user_handler_->Post(
         common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
-                         LeFixedChannelManager::RegistrationResult::FAIL_INVALID_SERVICE, std::move(invalid_service)));
-  } else if (IsServiceRegistered(cid)) {
-    std::unique_ptr<LeFixedChannelService> invalid_service(new LeFixedChannelService());
+                         DynamicChannelManager::RegistrationResult::FAIL_INVALID_SERVICE, std::move(invalid_service)));
+  } else if (IsServiceRegistered(psm)) {
+    std::unique_ptr<DynamicChannelService> invalid_service(new DynamicChannelService());
     pending_registration.user_handler_->Post(common::BindOnce(
         std::move(pending_registration.on_registration_complete_callback_),
-        LeFixedChannelManager::RegistrationResult::FAIL_DUPLICATE_SERVICE, std::move(invalid_service)));
+        DynamicChannelManager::RegistrationResult::FAIL_DUPLICATE_SERVICE, std::move(invalid_service)));
   } else {
-    service_map_.try_emplace(cid,
-                             LeFixedChannelServiceImpl(pending_registration.user_handler_,
+    service_map_.try_emplace(psm,
+                             DynamicChannelServiceImpl(pending_registration.user_handler_,
                                                        std::move(pending_registration.on_connection_open_callback_)));
-    std::unique_ptr<LeFixedChannelService> user_service(new LeFixedChannelService(cid, this, l2cap_layer_handler_));
+    std::unique_ptr<DynamicChannelService> user_service(new DynamicChannelService(psm, this, l2cap_layer_handler_));
     pending_registration.user_handler_->Post(
         common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
-                         LeFixedChannelManager::RegistrationResult::SUCCESS, std::move(user_service)));
+                         DynamicChannelManager::RegistrationResult::SUCCESS, std::move(user_service)));
   }
 }
 
-void LeFixedChannelServiceManagerImpl::Unregister(Cid cid, LeFixedChannelService::OnUnregisteredCallback callback,
+void DynamicChannelServiceManagerImpl::Unregister(Psm psm, DynamicChannelService::OnUnregisteredCallback callback,
                                                   os::Handler* handler) {
-  if (IsServiceRegistered(cid)) {
-    service_map_.erase(cid);
+  if (IsServiceRegistered(psm)) {
+    service_map_.erase(psm);
     handler->Post(std::move(callback));
   } else {
-    LOG_ERROR("service not registered cid:%d", cid);
+    LOG_ERROR("service not registered psm:%d", psm);
   }
 }
 
-bool LeFixedChannelServiceManagerImpl::IsServiceRegistered(Cid cid) const {
-  return service_map_.find(cid) != service_map_.end();
+bool DynamicChannelServiceManagerImpl::IsServiceRegistered(Psm psm) const {
+  return service_map_.find(psm) != service_map_.end();
 }
 
-LeFixedChannelServiceImpl* LeFixedChannelServiceManagerImpl::GetService(Cid cid) {
-  ASSERT(IsServiceRegistered(cid));
-  return &service_map_.find(cid)->second;
+DynamicChannelServiceImpl* DynamicChannelServiceManagerImpl::GetService(Psm psm) {
+  ASSERT(IsServiceRegistered(psm));
+  return &service_map_.find(psm)->second;
 }
 
-std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> LeFixedChannelServiceManagerImpl::GetRegisteredServices() {
-  std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> results;
+std::vector<std::pair<Psm, DynamicChannelServiceImpl*>> DynamicChannelServiceManagerImpl::GetRegisteredServices() {
+  std::vector<std::pair<Psm, DynamicChannelServiceImpl*>> results;
   for (auto& elem : service_map_) {
     results.emplace_back(elem.first, &elem.second);
   }
@@ -76,5 +76,6 @@ std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> LeFixedChannelServiceMan
 }
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
 
 #include <unordered_map>
 
-#include "l2cap/cid.h"
-#include "l2cap/internal/le_fixed_channel_service_impl.h"
-#include "l2cap/le_fixed_channel_service.h"
+#include "l2cap/classic/dynamic_channel_service.h"
+#include "l2cap/classic/internal/dynamic_channel_service_impl.h"
+#include "l2cap/psm.h"
 #include "os/handler.h"
+#include "os/log.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-class LeFixedChannelServiceManagerImpl {
+class DynamicChannelServiceManagerImpl {
  public:
-  explicit LeFixedChannelServiceManagerImpl(os::Handler* l2cap_layer_handler)
+  explicit DynamicChannelServiceManagerImpl(os::Handler* l2cap_layer_handler)
       : l2cap_layer_handler_(l2cap_layer_handler) {}
-  virtual ~LeFixedChannelServiceManagerImpl() = default;
 
+  virtual ~DynamicChannelServiceManagerImpl() = default;
+  //
   // All APIs must be invoked in L2CAP layer handler
-
-  virtual void Register(Cid cid, LeFixedChannelServiceImpl::PendingRegistration pending_registration);
-  virtual void Unregister(Cid cid, LeFixedChannelService::OnUnregisteredCallback callback, os::Handler* handler);
-  virtual bool IsServiceRegistered(Cid cid) const;
-  virtual LeFixedChannelServiceImpl* GetService(Cid cid);
-  virtual std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> GetRegisteredServices();
-
+  //
+  virtual void Register(Psm psm, DynamicChannelServiceImpl::PendingRegistration pending_registration);
+  virtual void Unregister(Psm psm, DynamicChannelService::OnUnregisteredCallback callback, os::Handler* handler);
+  virtual bool IsServiceRegistered(Psm psm) const;
+  virtual DynamicChannelServiceImpl* GetService(Psm psm);
+
+  virtual std::vector<std::pair<Psm, DynamicChannelServiceImpl*>> GetRegisteredServices();
+  //
  private:
   os::Handler* l2cap_layer_handler_ = nullptr;
-  std::unordered_map<Cid, LeFixedChannelServiceImpl> service_map_;
+  std::unordered_map<Psm, DynamicChannelServiceImpl> service_map_;
 };
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
  * limitations under the License.
  */
 
-#include "l2cap/internal/classic_dynamic_channel_service_manager_impl.h"
-
 #include <future>
 
+#include <gtest/gtest.h>
+
 #include "common/bind.h"
 #include "l2cap/cid.h"
-#include "l2cap/classic_dynamic_channel_manager.h"
-#include "l2cap/classic_dynamic_channel_service.h"
+#include "l2cap/classic/dynamic_channel_manager.h"
+#include "l2cap/classic/dynamic_channel_service.h"
+#include "l2cap/classic/internal/dynamic_channel_service_manager_impl.h"
 #include "os/handler.h"
 #include "os/thread.h"
 
-#include <gtest/gtest.h>
-
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
 class L2capDynamicServiceManagerTest : public ::testing::Test {
  public:
   ~L2capDynamicServiceManagerTest() override = default;
 
-  void OnServiceRegistered(bool expect_success, ClassicDynamicChannelManager::RegistrationResult result,
-                           std::unique_ptr<ClassicDynamicChannelService> user_service) {
-    EXPECT_EQ(result == ClassicDynamicChannelManager::RegistrationResult::SUCCESS, expect_success);
+  void OnServiceRegistered(bool expect_success, DynamicChannelManager::RegistrationResult result,
+                           std::unique_ptr<DynamicChannelService> user_service) {
+    EXPECT_EQ(result == DynamicChannelManager::RegistrationResult::SUCCESS, expect_success);
     service_registered_ = expect_success;
   }
 
@@ -46,7 +46,7 @@ class L2capDynamicServiceManagerTest : public ::testing::Test {
     thread_ = new os::Thread("test_thread", os::Thread::Priority::NORMAL);
     user_handler_ = new os::Handler(thread_);
     l2cap_handler_ = new os::Handler(thread_);
-    manager_ = new ClassicDynamicChannelServiceManagerImpl{l2cap_handler_};
+    manager_ = new DynamicChannelServiceManagerImpl{l2cap_handler_};
   }
 
   void TearDown() override {
@@ -65,7 +65,7 @@ class L2capDynamicServiceManagerTest : public ::testing::Test {
     future.wait_for(std::chrono::milliseconds(3));
   }
 
-  ClassicDynamicChannelServiceManagerImpl* manager_ = nullptr;
+  DynamicChannelServiceManagerImpl* manager_ = nullptr;
   os::Thread* thread_ = nullptr;
   os::Handler* user_handler_ = nullptr;
   os::Handler* l2cap_handler_ = nullptr;
@@ -74,7 +74,7 @@ class L2capDynamicServiceManagerTest : public ::testing::Test {
 };
 
 TEST_F(L2capDynamicServiceManagerTest, register_and_unregister_classic_dynamic_channel) {
-  ClassicDynamicChannelServiceImpl::PendingRegistration pending_registration{
+  DynamicChannelServiceImpl::PendingRegistration pending_registration{
       .user_handler_ = user_handler_,
       .on_registration_complete_callback_ =
           common::BindOnce(&L2capDynamicServiceManagerTest::OnServiceRegistered, common::Unretained(this), true)};
@@ -89,7 +89,7 @@ TEST_F(L2capDynamicServiceManagerTest, register_and_unregister_classic_dynamic_c
 }
 
 TEST_F(L2capDynamicServiceManagerTest, register_classic_dynamic_channel_bad_cid) {
-  ClassicDynamicChannelServiceImpl::PendingRegistration pending_registration{
+  DynamicChannelServiceImpl::PendingRegistration pending_registration{
       .user_handler_ = user_handler_,
       .on_registration_complete_callback_ =
           common::BindOnce(&L2capDynamicServiceManagerTest::OnServiceRegistered, common::Unretained(this), false)};
@@ -102,5 +102,6 @@ TEST_F(L2capDynamicServiceManagerTest, register_classic_dynamic_channel_bad_cid)
 }
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
 #include <unordered_map>
 
 #include "l2cap/cid.h"
-#include "l2cap/internal/classic_fixed_channel_impl.h"
-#include "l2cap/internal/classic_link.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
+#include "l2cap/classic/internal/link.h"
 #include "l2cap/security_policy.h"
 #include "os/handler.h"
 #include "os/log.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-ClassicFixedChannelImpl::ClassicFixedChannelImpl(Cid cid, ClassicLink* link, os::Handler* l2cap_handler)
+FixedChannelImpl::FixedChannelImpl(Cid cid, Link* link, os::Handler* l2cap_handler)
     : cid_(cid), device_(link->GetDevice()), link_(link), l2cap_handler_(l2cap_handler) {
   ASSERT_LOG(cid_ >= kFirstFixedChannel && cid_ <= kLastFixedChannel, "Invalid cid: %d", cid_);
   ASSERT(!device_.IsEmpty());
@@ -35,8 +36,8 @@ ClassicFixedChannelImpl::ClassicFixedChannelImpl(Cid cid, ClassicLink* link, os:
   ASSERT(l2cap_handler_ != nullptr);
 }
 
-void ClassicFixedChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler,
-                                                      ClassicFixedChannel::OnCloseCallback on_close_callback) {
+void FixedChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler,
+                                               FixedChannel::OnCloseCallback on_close_callback) {
   ASSERT_LOG(user_handler_ == nullptr, "OnCloseCallback can only be registered once");
   // If channel is already closed, call the callback immediately without saving it
   if (closed_) {
@@ -47,7 +48,7 @@ void ClassicFixedChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler,
   on_close_callback_ = std::move(on_close_callback);
 }
 
-void ClassicFixedChannelImpl::OnClosed(hci::ErrorCode status) {
+void FixedChannelImpl::OnClosed(hci::ErrorCode status) {
   ASSERT_LOG(!closed_, "Device %s Cid 0x%x closed twice, old status 0x%x, new status 0x%x", device_.ToString().c_str(),
              cid_, static_cast<int>(close_reason_), static_cast<int>(status));
   closed_ = true;
@@ -64,7 +65,7 @@ void ClassicFixedChannelImpl::OnClosed(hci::ErrorCode status) {
   on_close_callback_.Reset();
 }
 
-void ClassicFixedChannelImpl::Acquire() {
+void FixedChannelImpl::Acquire() {
   ASSERT_LOG(user_handler_ != nullptr, "Must register OnCloseCallback before calling any methods");
   if (closed_) {
     LOG_WARN("%s is already closed", ToString().c_str());
@@ -79,7 +80,7 @@ void ClassicFixedChannelImpl::Acquire() {
   link_->RefreshRefCount();
 }
 
-void ClassicFixedChannelImpl::Release() {
+void FixedChannelImpl::Release() {
   ASSERT_LOG(user_handler_ != nullptr, "Must register OnCloseCallback before calling any methods");
   if (closed_) {
     LOG_WARN("%s is already closed", ToString().c_str());
@@ -95,5 +96,6 @@ void ClassicFixedChannelImpl::Release() {
 }
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
 
 #include "common/bidi_queue.h"
 #include "l2cap/cid.h"
-#include "l2cap/classic_fixed_channel.h"
+#include "l2cap/classic/fixed_channel.h"
 #include "os/handler.h"
 #include "os/log.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-class ClassicLink;
+class Link;
 
-class ClassicFixedChannelImpl {
+class FixedChannelImpl {
  public:
-  ClassicFixedChannelImpl(Cid cid, ClassicLink* link, os::Handler* l2cap_handler);
+  FixedChannelImpl(Cid cid, Link* link, os::Handler* l2cap_handler);
 
-  virtual ~ClassicFixedChannelImpl() = default;
+  virtual ~FixedChannelImpl() = default;
 
   hci::Address GetDevice() const {
     return device_;
   }
 
-  virtual void RegisterOnCloseCallback(os::Handler* user_handler,
-                                       ClassicFixedChannel::OnCloseCallback on_close_callback);
+  virtual void RegisterOnCloseCallback(os::Handler* user_handler, FixedChannel::OnCloseCallback on_close_callback);
 
   virtual void Acquire();
 
@@ -72,12 +72,12 @@ class ClassicFixedChannelImpl {
   // For logging purpose only
   const hci::Address device_;
   // Needed to handle Acquire() and Release()
-  ClassicLink* link_;
+  Link* link_;
   os::Handler* l2cap_handler_;
 
   // User supported states
   os::Handler* user_handler_ = nullptr;
-  ClassicFixedChannel::OnCloseCallback on_close_callback_{};
+  FixedChannel::OnCloseCallback on_close_callback_{};
 
   // Internal states
   bool acquired_ = false;
@@ -87,9 +87,10 @@ class ClassicFixedChannelImpl {
   common::BidiQueue<packet::PacketView<packet::kLittleEndian>, packet::BasePacketBuilder> channel_queue_{
       kChannelQueueSize};
 
-  DISALLOW_COPY_AND_ASSIGN(ClassicFixedChannelImpl);
+  DISALLOW_COPY_AND_ASSIGN(FixedChannelImpl);
 };
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
  */
 #pragma once
 
-#include "l2cap/internal/classic_fixed_channel_impl.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
 
 #include <gmock/gmock.h>
 
 // Unit test interfaces
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 namespace testing {
 
-class MockClassicFixedChannelImpl : public ClassicFixedChannelImpl {
+class MockFixedChannelImpl : public FixedChannelImpl {
  public:
-  MockClassicFixedChannelImpl(Cid cid, ClassicLink* link, os::Handler* l2cap_handler)
-      : ClassicFixedChannelImpl(cid, link, l2cap_handler) {}
+  MockFixedChannelImpl(Cid cid, Link* link, os::Handler* l2cap_handler) : FixedChannelImpl(cid, link, l2cap_handler) {}
   MOCK_METHOD(void, RegisterOnCloseCallback,
-              (os::Handler * user_handler, ClassicFixedChannel::OnCloseCallback on_close_callback), (override));
+              (os::Handler * user_handler, FixedChannel::OnCloseCallback on_close_callback), (override));
   MOCK_METHOD(void, Acquire, (), (override));
   MOCK_METHOD(void, Release, (), (override));
   MOCK_METHOD(bool, IsAcquired, (), (override, const));
@@ -39,5 +39,6 @@ class MockClassicFixedChannelImpl : public ClassicFixedChannelImpl {
 
 }  // namespace testing
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "l2cap/internal/classic_fixed_channel_impl.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
 
 #include "common/testing/bind_test_util.h"
 #include "l2cap/cid.h"
-#include "l2cap/internal/classic_link_mock.h"
+#include "l2cap/classic/internal/link_mock.h"
 #include "l2cap/internal/parameter_provider_mock.h"
 #include "os/handler.h"
 
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-using testing::MockClassicLink;
-using testing::MockParameterProvider;
+using l2cap::internal::testing::MockParameterProvider;
+using testing::MockLink;
 using ::testing::Return;
 
 class L2capClassicFixedChannelImplTest : public ::testing::Test {
@@ -59,19 +60,19 @@ class L2capClassicFixedChannelImplTest : public ::testing::Test {
 
 TEST_F(L2capClassicFixedChannelImplTest, get_device) {
   MockParameterProvider mock_parameter_provider;
-  MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
-  ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
   EXPECT_EQ(device, fixed_channel_impl.GetDevice());
 }
 
 TEST_F(L2capClassicFixedChannelImplTest, close_triggers_callback) {
   MockParameterProvider mock_parameter_provider;
-  MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
-  ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
 
   // Register on close callback
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -89,10 +90,10 @@ TEST_F(L2capClassicFixedChannelImplTest, close_triggers_callback) {
 
 TEST_F(L2capClassicFixedChannelImplTest, register_callback_after_close_should_call_immediately) {
   MockParameterProvider mock_parameter_provider;
-  MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
-  ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
 
   // Channel closure should do nothing
   fixed_channel_impl.OnClosed(hci::ErrorCode::REMOTE_USER_TERMINATED_CONNECTION);
@@ -110,10 +111,10 @@ TEST_F(L2capClassicFixedChannelImplTest, register_callback_after_close_should_ca
 
 TEST_F(L2capClassicFixedChannelImplTest, close_twice_should_fail) {
   MockParameterProvider mock_parameter_provider;
-  MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
-  ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
 
   // Register on close callback
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -134,10 +135,10 @@ TEST_F(L2capClassicFixedChannelImplTest, close_twice_should_fail) {
 
 TEST_F(L2capClassicFixedChannelImplTest, multiple_registeration_should_fail) {
   MockParameterProvider mock_parameter_provider;
-  MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
-  ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
 
   // Register on close callback
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -154,28 +155,28 @@ TEST_F(L2capClassicFixedChannelImplTest, multiple_registeration_should_fail) {
 
 TEST_F(L2capClassicFixedChannelImplTest, call_acquire_before_registeration_should_fail) {
   MockParameterProvider mock_parameter_provider;
-  MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
-  ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
   EXPECT_DEATH(fixed_channel_impl.Acquire(), ".*Acquire.*");
 }
 
 TEST_F(L2capClassicFixedChannelImplTest, call_release_before_registeration_should_fail) {
   MockParameterProvider mock_parameter_provider;
-  MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
-  ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
   EXPECT_DEATH(fixed_channel_impl.Release(), ".*Release.*");
 }
 
 TEST_F(L2capClassicFixedChannelImplTest, test_acquire_release_channel) {
   MockParameterProvider mock_parameter_provider;
-  MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
-  ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
 
   // Register on close callback
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -200,10 +201,10 @@ TEST_F(L2capClassicFixedChannelImplTest, test_acquire_release_channel) {
 
 TEST_F(L2capClassicFixedChannelImplTest, test_acquire_after_close) {
   MockParameterProvider mock_parameter_provider;
-  MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
-  ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
 
   // Register on close callback
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -225,5 +226,6 @@ TEST_F(L2capClassicFixedChannelImplTest, test_acquire_after_close) {
 }
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
 
 #pragma once
 
-#include "l2cap/classic_fixed_channel.h"
-#include "l2cap/classic_fixed_channel_manager.h"
-#include "l2cap/classic_fixed_channel_service.h"
+#include "l2cap/classic/fixed_channel.h"
+#include "l2cap/classic/fixed_channel_manager.h"
+#include "l2cap/classic/fixed_channel_service.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-class ClassicFixedChannelServiceImpl {
+class FixedChannelServiceImpl {
  public:
-  virtual ~ClassicFixedChannelServiceImpl() = default;
+  virtual ~FixedChannelServiceImpl() = default;
 
   struct PendingRegistration {
     os::Handler* user_handler_ = nullptr;
-    ClassicFixedChannelManager::OnRegistrationCompleteCallback on_registration_complete_callback_;
-    ClassicFixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
+    FixedChannelManager::OnRegistrationCompleteCallback on_registration_complete_callback_;
+    FixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
   };
 
-  virtual void NotifyChannelCreation(std::unique_ptr<ClassicFixedChannel> channel) {
+  virtual void NotifyChannelCreation(std::unique_ptr<FixedChannel> channel) {
     user_handler_->Post(common::BindOnce(on_connection_open_callback_, std::move(channel)));
   }
 
-  friend class ClassicFixedChannelServiceManagerImpl;
+  friend class FixedChannelServiceManagerImpl;
 
  protected:
   // protected access for mocking
-  ClassicFixedChannelServiceImpl(os::Handler* user_handler,
-                                 ClassicFixedChannelManager::OnConnectionOpenCallback on_connection_open_callback)
+  FixedChannelServiceImpl(os::Handler* user_handler,
+                          FixedChannelManager::OnConnectionOpenCallback on_connection_open_callback)
       : user_handler_(user_handler), on_connection_open_callback_(std::move(on_connection_open_callback)) {}
 
  private:
   os::Handler* user_handler_ = nullptr;
-  ClassicFixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
+  FixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
 };
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
  */
 #pragma once
 
-#include "l2cap/internal/classic_fixed_channel_impl.h"
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
 
 #include <gmock/gmock.h>
 
 // Unit test interfaces
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 namespace testing {
 
-class MockClassicFixedChannelServiceImpl : public ClassicFixedChannelServiceImpl {
+class MockFixedChannelServiceImpl : public FixedChannelServiceImpl {
  public:
-  MockClassicFixedChannelServiceImpl()
-      : ClassicFixedChannelServiceImpl(nullptr, ClassicFixedChannelManager::OnConnectionOpenCallback()) {}
-  MOCK_METHOD(void, NotifyChannelCreation, (std::unique_ptr<ClassicFixedChannel> channel), (override));
+  MockFixedChannelServiceImpl() : FixedChannelServiceImpl(nullptr, FixedChannelManager::OnConnectionOpenCallback()) {}
+  MOCK_METHOD(void, NotifyChannelCreation, (std::unique_ptr<FixedChannel> channel), (override));
 };
 
 }  // namespace testing
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
diff --git a/gd/l2cap/classic/internal/fixed_channel_service_manager_impl.cc b/gd/l2cap/classic/internal/fixed_channel_service_manager_impl.cc
new file mode 100644 (file)
index 0000000..206c0e4
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2019 The Android Open Source Project
+ *
+ * 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 "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
+
+#include "common/bind.h"
+#include "l2cap/cid.h"
+#include "l2cap/classic/internal/fixed_channel_service_impl.h"
+#include "os/log.h"
+
+namespace bluetooth {
+namespace l2cap {
+namespace classic {
+namespace internal {
+
+void FixedChannelServiceManagerImpl::Register(Cid cid,
+                                              FixedChannelServiceImpl::PendingRegistration pending_registration) {
+  if (cid < kFirstFixedChannel || cid > kLastFixedChannel || cid == kClassicSignallingCid) {
+    std::unique_ptr<FixedChannelService> invalid_service(new FixedChannelService());
+    pending_registration.user_handler_->Post(
+        common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
+                         FixedChannelManager::RegistrationResult::FAIL_INVALID_SERVICE, std::move(invalid_service)));
+  } else if (IsServiceRegistered(cid)) {
+    std::unique_ptr<FixedChannelService> invalid_service(new FixedChannelService());
+    pending_registration.user_handler_->Post(
+        common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
+                         FixedChannelManager::RegistrationResult::FAIL_DUPLICATE_SERVICE, std::move(invalid_service)));
+  } else {
+    service_map_.try_emplace(cid,
+                             FixedChannelServiceImpl(pending_registration.user_handler_,
+                                                     std::move(pending_registration.on_connection_open_callback_)));
+    std::unique_ptr<FixedChannelService> user_service(new FixedChannelService(cid, this, l2cap_layer_handler_));
+    pending_registration.user_handler_->Post(
+        common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
+                         FixedChannelManager::RegistrationResult::SUCCESS, std::move(user_service)));
+  }
+}
+
+void FixedChannelServiceManagerImpl::Unregister(Cid cid, FixedChannelService::OnUnregisteredCallback callback,
+                                                os::Handler* handler) {
+  if (IsServiceRegistered(cid)) {
+    service_map_.erase(cid);
+    handler->Post(std::move(callback));
+  } else {
+    LOG_ERROR("service not registered cid:%d", cid);
+  }
+}
+
+bool FixedChannelServiceManagerImpl::IsServiceRegistered(Cid cid) const {
+  return service_map_.find(cid) != service_map_.end();
+}
+
+FixedChannelServiceImpl* FixedChannelServiceManagerImpl::GetService(Cid cid) {
+  ASSERT(IsServiceRegistered(cid));
+  return &service_map_.find(cid)->second;
+}
+
+std::vector<std::pair<Cid, FixedChannelServiceImpl*>> FixedChannelServiceManagerImpl::GetRegisteredServices() {
+  std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
+  for (auto& elem : service_map_) {
+    results.emplace_back(elem.first, &elem.second);
+  }
+  return results;
+}
+
+}  // namespace internal
+}  // namespace classic
+}  // namespace l2cap
+}  // namespace bluetooth
 #include <unordered_map>
 
 #include "l2cap/cid.h"
-#include "l2cap/classic_fixed_channel_service.h"
-#include "l2cap/internal/classic_fixed_channel_service_impl.h"
+#include "l2cap/classic/fixed_channel_service.h"
+#include "l2cap/classic/internal/fixed_channel_service_impl.h"
 #include "os/handler.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-class ClassicFixedChannelServiceManagerImpl {
+class FixedChannelServiceManagerImpl {
  public:
-  explicit ClassicFixedChannelServiceManagerImpl(os::Handler* l2cap_layer_handler)
+  explicit FixedChannelServiceManagerImpl(os::Handler* l2cap_layer_handler)
       : l2cap_layer_handler_(l2cap_layer_handler) {}
-  virtual ~ClassicFixedChannelServiceManagerImpl() = default;
+  virtual ~FixedChannelServiceManagerImpl() = default;
 
   // All APIs must be invoked in L2CAP layer handler
 
-  virtual void Register(Cid cid, ClassicFixedChannelServiceImpl::PendingRegistration pending_registration);
-  virtual void Unregister(Cid cid, ClassicFixedChannelService::OnUnregisteredCallback callback, os::Handler* handler);
+  virtual void Register(Cid cid, FixedChannelServiceImpl::PendingRegistration pending_registration);
+  virtual void Unregister(Cid cid, FixedChannelService::OnUnregisteredCallback callback, os::Handler* handler);
   virtual bool IsServiceRegistered(Cid cid) const;
-  virtual ClassicFixedChannelServiceImpl* GetService(Cid cid);
-  virtual std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> GetRegisteredServices();
+  virtual FixedChannelServiceImpl* GetService(Cid cid);
+  virtual std::vector<std::pair<Cid, FixedChannelServiceImpl*>> GetRegisteredServices();
 
  private:
   os::Handler* l2cap_layer_handler_ = nullptr;
-  std::unordered_map<Cid, ClassicFixedChannelServiceImpl> service_map_;
+  std::unordered_map<Cid, FixedChannelServiceImpl> service_map_;
 };
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
  */
 #pragma once
 
-#include "l2cap/internal/classic_fixed_channel_impl.h"
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
 
 #include <gmock/gmock.h>
 
 // Unit test interfaces
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 namespace testing {
 
-class MockClassicFixedChannelServiceManagerImpl : public ClassicFixedChannelServiceManagerImpl {
+class MockFixedChannelServiceManagerImpl : public FixedChannelServiceManagerImpl {
  public:
-  MockClassicFixedChannelServiceManagerImpl() : ClassicFixedChannelServiceManagerImpl(nullptr) {}
-  MOCK_METHOD(void, Register, (Cid cid, ClassicFixedChannelServiceImpl::PendingRegistration pending_registration),
+  MockFixedChannelServiceManagerImpl() : FixedChannelServiceManagerImpl(nullptr) {}
+  MOCK_METHOD(void, Register, (Cid cid, FixedChannelServiceImpl::PendingRegistration pending_registration), (override));
+  MOCK_METHOD(void, Unregister, (Cid cid, FixedChannelService::OnUnregisteredCallback callback, os::Handler* handler),
               (override));
-  MOCK_METHOD(void, Unregister,
-              (Cid cid, ClassicFixedChannelService::OnUnregisteredCallback callback, os::Handler* handler), (override));
   MOCK_METHOD(bool, IsServiceRegistered, (Cid cid), (const, override));
-  MOCK_METHOD(ClassicFixedChannelServiceImpl*, GetService, (Cid cid), (override));
-  MOCK_METHOD((std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>>), GetRegisteredServices, (), (override));
+  MOCK_METHOD(FixedChannelServiceImpl*, GetService, (Cid cid), (override));
+  MOCK_METHOD((std::vector<std::pair<Cid, FixedChannelServiceImpl*>>), GetRegisteredServices, (), (override));
 };
 
 }  // namespace testing
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
  * limitations under the License.
  */
 
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
 
 #include <future>
 
 #include "common/bind.h"
 #include "l2cap/cid.h"
-#include "l2cap/classic_fixed_channel_manager.h"
-#include "l2cap/classic_fixed_channel_service.h"
+#include "l2cap/classic/fixed_channel_manager.h"
+#include "l2cap/classic/fixed_channel_service.h"
 #include "os/handler.h"
 #include "os/thread.h"
 
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-class L2capFixedServiceManagerTest : public ::testing::Test {
+class L2capClassicFixedServiceManagerTest : public ::testing::Test {
  public:
-  ~L2capFixedServiceManagerTest() override = default;
+  ~L2capClassicFixedServiceManagerTest() override = default;
 
-  void OnServiceRegistered(bool expect_success, ClassicFixedChannelManager::RegistrationResult result,
-                           std::unique_ptr<ClassicFixedChannelService> user_service) {
-    EXPECT_EQ(result == ClassicFixedChannelManager::RegistrationResult::SUCCESS, expect_success);
+  void OnServiceRegistered(bool expect_success, FixedChannelManager::RegistrationResult result,
+                           std::unique_ptr<FixedChannelService> user_service) {
+    EXPECT_EQ(result == FixedChannelManager::RegistrationResult::SUCCESS, expect_success);
     service_registered_ = expect_success;
   }
 
  protected:
   void SetUp() override {
-    manager_ = new ClassicFixedChannelServiceManagerImpl{nullptr};
+    manager_ = new FixedChannelServiceManagerImpl{nullptr};
     thread_ = new os::Thread("test_thread", os::Thread::Priority::NORMAL);
     user_handler_ = new os::Handler(thread_);
   }
@@ -62,18 +63,18 @@ class L2capFixedServiceManagerTest : public ::testing::Test {
     future.wait_for(std::chrono::milliseconds(3));
   }
 
-  ClassicFixedChannelServiceManagerImpl* manager_ = nullptr;
+  FixedChannelServiceManagerImpl* manager_ = nullptr;
   os::Thread* thread_ = nullptr;
   os::Handler* user_handler_ = nullptr;
 
   bool service_registered_ = false;
 };
 
-TEST_F(L2capFixedServiceManagerTest, register_and_unregister_classic_fixed_channel) {
-  ClassicFixedChannelServiceImpl::PendingRegistration pending_registration{
+TEST_F(L2capClassicFixedServiceManagerTest, register_and_unregister_classic_fixed_channel) {
+  FixedChannelServiceImpl::PendingRegistration pending_registration{
       .user_handler_ = user_handler_,
       .on_registration_complete_callback_ =
-          common::BindOnce(&L2capFixedServiceManagerTest::OnServiceRegistered, common::Unretained(this), true)};
+          common::BindOnce(&L2capClassicFixedServiceManagerTest::OnServiceRegistered, common::Unretained(this), true)};
   Cid cid = kSmpBrCid;
   EXPECT_FALSE(manager_->IsServiceRegistered(cid));
   manager_->Register(cid, std::move(pending_registration));
@@ -84,11 +85,11 @@ TEST_F(L2capFixedServiceManagerTest, register_and_unregister_classic_fixed_chann
   EXPECT_FALSE(manager_->IsServiceRegistered(cid));
 }
 
-TEST_F(L2capFixedServiceManagerTest, register_classic_fixed_channel_bad_cid) {
-  ClassicFixedChannelServiceImpl::PendingRegistration pending_registration{
+TEST_F(L2capClassicFixedServiceManagerTest, register_classic_fixed_channel_bad_cid) {
+  FixedChannelServiceImpl::PendingRegistration pending_registration{
       .user_handler_ = user_handler_,
       .on_registration_complete_callback_ =
-          common::BindOnce(&L2capFixedServiceManagerTest::OnServiceRegistered, common::Unretained(this), false)};
+          common::BindOnce(&L2capClassicFixedServiceManagerTest::OnServiceRegistered, common::Unretained(this), false)};
   Cid cid = 0x1000;
   EXPECT_FALSE(manager_->IsServiceRegistered(cid));
   manager_->Register(cid, std::move(pending_registration));
@@ -98,5 +99,6 @@ TEST_F(L2capFixedServiceManagerTest, register_classic_fixed_channel_bad_cid) {
 }
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 67%
rename from gd/l2cap/internal/classic_link.cc
rename to gd/l2cap/classic/internal/link.cc
index f529965..692a3fc 100644 (file)
  * limitations under the License.
  */
 
-#include "l2cap/internal/classic_link.h"
-
 #include <chrono>
 #include <memory>
 
 #include "hci/acl_manager.h"
-#include "l2cap/internal/classic_fixed_channel_impl.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
+#include "l2cap/classic/internal/link.h"
 #include "l2cap/internal/parameter_provider.h"
 #include "l2cap/internal/scheduler.h"
 #include "os/alarm.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-ClassicLink::ClassicLink(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_connection,
-                         std::unique_ptr<Scheduler> scheduler, ParameterProvider* parameter_provider)
+Link::Link(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_connection,
+           std::unique_ptr<l2cap::internal::Scheduler> scheduler,
+           l2cap::internal::ParameterProvider* parameter_provider)
     : l2cap_handler_(l2cap_handler), acl_connection_(std::move(acl_connection)), scheduler_(std::move(scheduler)),
       parameter_provider_(parameter_provider) {
   ASSERT(l2cap_handler_ != nullptr);
   ASSERT(acl_connection_ != nullptr);
   ASSERT(scheduler_ != nullptr);
   ASSERT(parameter_provider_ != nullptr);
-  acl_connection_->RegisterDisconnectCallback(
-      common::BindOnce(&ClassicLink::OnAclDisconnected, common::Unretained(this)), l2cap_handler_);
-  link_idle_disconnect_alarm_.Schedule(common::BindOnce(&ClassicLink::Disconnect, common::Unretained(this)),
+  acl_connection_->RegisterDisconnectCallback(common::BindOnce(&Link::OnAclDisconnected, common::Unretained(this)),
+                                              l2cap_handler_);
+  link_idle_disconnect_alarm_.Schedule(common::BindOnce(&Link::Disconnect, common::Unretained(this)),
                                        parameter_provider_->GetClassicLinkIdleDisconnectTimeout());
 }
 
-void ClassicLink::OnAclDisconnected(hci::ErrorCode status) {
+void Link::OnAclDisconnected(hci::ErrorCode status) {
   fixed_channel_allocator_.OnAclDisconnected(status);
   // TODO hsz: add dynamic channel part
 }
 
-void ClassicLink::Disconnect() {
+void Link::Disconnect() {
   acl_connection_->Disconnect(hci::DisconnectReason::REMOTE_USER_TERMINATED_CONNECTION);
 }
 
-std::shared_ptr<ClassicFixedChannelImpl> ClassicLink::AllocateFixedChannel(Cid cid, SecurityPolicy security_policy) {
+std::shared_ptr<FixedChannelImpl> Link::AllocateFixedChannel(Cid cid, SecurityPolicy security_policy) {
   auto channel = fixed_channel_allocator_.AllocateChannel(cid, security_policy);
   scheduler_->AttachChannel(cid, channel->GetQueueDownEnd());
   return channel;
 }
 
-bool ClassicLink::IsFixedChannelAllocated(Cid cid) {
+bool Link::IsFixedChannelAllocated(Cid cid) {
   return fixed_channel_allocator_.IsChannelAllocated(cid);
 }
 
-std::shared_ptr<ClassicDynamicChannelImpl> ClassicLink::AllocateDynamicChannel(Psm psm, Cid remote_cid,
-                                                                               SecurityPolicy security_policy) {
+std::shared_ptr<DynamicChannelImpl> Link::AllocateDynamicChannel(Psm psm, Cid remote_cid,
+                                                                 SecurityPolicy security_policy) {
   auto channel = dynamic_channel_allocator_.AllocateChannel(psm, remote_cid, security_policy);
   scheduler_->AttachChannel(channel->GetCid(), channel->GetQueueDownEnd());
   return channel;
 }
 
-void ClassicLink::FreeDynamicChannel(Cid cid) {}
+void Link::FreeDynamicChannel(Cid cid) {}
 
-void ClassicLink::RefreshRefCount() {
+void Link::RefreshRefCount() {
   int ref_count = 0;
   ref_count += fixed_channel_allocator_.GetRefCount();
   ref_count += dynamic_channel_allocator_.NumberOfChannels();
@@ -79,11 +80,12 @@ void ClassicLink::RefreshRefCount() {
   if (ref_count > 0) {
     link_idle_disconnect_alarm_.Cancel();
   } else {
-    link_idle_disconnect_alarm_.Schedule(common::BindOnce(&ClassicLink::Disconnect, common::Unretained(this)),
+    link_idle_disconnect_alarm_.Schedule(common::BindOnce(&Link::Disconnect, common::Unretained(this)),
                                          parameter_provider_->GetClassicLinkIdleDisconnectTimeout());
   }
 }
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 61%
rename from gd/l2cap/internal/classic_link.h
rename to gd/l2cap/classic/internal/link.h
index f07f0f2..bb5ef85 100644 (file)
@@ -19,9 +19,9 @@
 #include <memory>
 
 #include "hci/acl_manager.h"
-#include "l2cap/internal/classic_dynamic_channel_allocator.h"
-#include "l2cap/internal/classic_dynamic_channel_impl.h"
-#include "l2cap/internal/classic_fixed_channel_impl.h"
+#include "l2cap/classic/internal/dynamic_channel_allocator.h"
+#include "l2cap/classic/internal/dynamic_channel_impl.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
 #include "l2cap/internal/fixed_channel_allocator.h"
 #include "l2cap/internal/parameter_provider.h"
 #include "l2cap/internal/scheduler.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-class ClassicLink {
+class Link {
  public:
-  ClassicLink(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_connection,
-              std::unique_ptr<Scheduler> scheduler, ParameterProvider* parameter_provider);
+  Link(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_connection,
+       std::unique_ptr<l2cap::internal::Scheduler> scheduler, l2cap::internal::ParameterProvider* parameter_provider);
 
-  virtual ~ClassicLink() = default;
+  virtual ~Link() = default;
 
   virtual hci::Address GetDevice() {
     return acl_connection_->GetAddress();
@@ -48,16 +49,16 @@ class ClassicLink {
 
   virtual void Disconnect();
 
-  // ClassicFixedChannel methods
+  // FixedChannel methods
 
-  virtual std::shared_ptr<ClassicFixedChannelImpl> AllocateFixedChannel(Cid cid, SecurityPolicy security_policy);
+  virtual std::shared_ptr<FixedChannelImpl> AllocateFixedChannel(Cid cid, SecurityPolicy security_policy);
 
   virtual bool IsFixedChannelAllocated(Cid cid);
 
   // ClassicDynamicChannel methods
 
-  virtual std::shared_ptr<ClassicDynamicChannelImpl> AllocateDynamicChannel(Psm psm, Cid remote_cid,
-                                                                            SecurityPolicy security_policy);
+  virtual std::shared_ptr<DynamicChannelImpl> AllocateDynamicChannel(Psm psm, Cid remote_cid,
+                                                                     SecurityPolicy security_policy);
 
   virtual void FreeDynamicChannel(Cid cid);
 
@@ -66,15 +67,16 @@ class ClassicLink {
 
  private:
   os::Handler* l2cap_handler_;
-  FixedChannelAllocator<ClassicFixedChannelImpl, ClassicLink> fixed_channel_allocator_{this, l2cap_handler_};
-  ClassicDynamicChannelAllocator dynamic_channel_allocator_{this, l2cap_handler_};
+  l2cap::internal::FixedChannelAllocator<FixedChannelImpl, Link> fixed_channel_allocator_{this, l2cap_handler_};
+  DynamicChannelAllocator dynamic_channel_allocator_{this, l2cap_handler_};
   std::unique_ptr<hci::AclConnection> acl_connection_;
-  std::unique_ptr<Scheduler> scheduler_;
-  ParameterProvider* parameter_provider_;
+  std::unique_ptr<l2cap::internal::Scheduler> scheduler_;
+  l2cap::internal::ParameterProvider* parameter_provider_;
   os::Alarm link_idle_disconnect_alarm_{l2cap_handler_};
-  DISALLOW_COPY_AND_ASSIGN(ClassicLink);
+  DISALLOW_COPY_AND_ASSIGN(Link);
 };
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 71%
rename from gd/l2cap/internal/classic_link_manager.cc
rename to gd/l2cap/classic/internal/link_manager.cc
index a14fece..5cc06bb 100644 (file)
 
 #include "hci/acl_manager.h"
 #include "hci/address.h"
-#include "l2cap/internal/classic_link.h"
+#include "l2cap/classic/internal/link.h"
 #include "l2cap/internal/scheduler_fifo.h"
-#include "l2cap/l2cap_layer.h"
 #include "os/handler.h"
 #include "os/log.h"
 
-#include "l2cap/internal/classic_link_manager.h"
+#include "l2cap/classic/internal/link_manager.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-void ClassicLinkManager::ConnectFixedChannelServices(hci::Address device,
-                                                     PendingFixedChannelConnection pending_fixed_channel_connection) {
+void LinkManager::ConnectFixedChannelServices(hci::Address device,
+                                              PendingFixedChannelConnection pending_fixed_channel_connection) {
   // Check if there is any service registered
   auto fixed_channel_services = service_manager_->GetRegisteredServices();
   if (fixed_channel_services.empty()) {
     // If so, return error
     pending_fixed_channel_connection.handler_->Post(common::BindOnce(
         std::move(pending_fixed_channel_connection.on_fail_callback_),
-        ClassicFixedChannelManager::ConnectionResult{
-            .connection_result_code = ClassicFixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED}));
+        FixedChannelManager::ConnectionResult{
+            .connection_result_code = FixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED}));
     return;
   }
   // Otherwise, check if device has an ACL connection
@@ -56,16 +56,15 @@ void ClassicLinkManager::ConnectFixedChannelServices(hci::Address device,
       // Allocate channel for newly registered fixed channels
       auto fixed_channel_impl = link->AllocateFixedChannel(fixed_channel_service.first, SecurityPolicy());
       fixed_channel_service.second->NotifyChannelCreation(
-          std::make_unique<ClassicFixedChannel>(fixed_channel_impl, l2cap_handler_));
+          std::make_unique<FixedChannel>(fixed_channel_impl, l2cap_handler_));
       num_new_channels++;
     }
     // Declare connection failure if no new channels are created
     if (num_new_channels == 0) {
-      pending_fixed_channel_connection.handler_->Post(
-          common::BindOnce(std::move(pending_fixed_channel_connection.on_fail_callback_),
-                           ClassicFixedChannelManager::ConnectionResult{
-                               .connection_result_code =
-                                   ClassicFixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL}));
+      pending_fixed_channel_connection.handler_->Post(common::BindOnce(
+          std::move(pending_fixed_channel_connection.on_fail_callback_),
+          FixedChannelManager::ConnectionResult{
+              .connection_result_code = FixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL}));
     }
     // No need to create ACL connection, return without saving any pending connections
     return;
@@ -83,28 +82,28 @@ void ClassicLinkManager::ConnectFixedChannelServices(hci::Address device,
   acl_manager_->CreateConnection(device);
 }
 
-ClassicLink* ClassicLinkManager::GetLink(const hci::Address device) {
+Link* LinkManager::GetLink(const hci::Address device) {
   if (links_.find(device) == links_.end()) {
     return nullptr;
   }
   return &links_.find(device)->second;
 }
 
-void ClassicLinkManager::OnConnectSuccess(std::unique_ptr<hci::AclConnection> acl_connection) {
+void LinkManager::OnConnectSuccess(std::unique_ptr<hci::AclConnection> acl_connection) {
   // Same link should not be connected twice
   hci::Address device = acl_connection->GetAddress();
   ASSERT_LOG(GetLink(device) == nullptr, "%s is connected twice without disconnection",
              acl_connection->GetAddress().ToString().c_str());
   auto* link_queue_up_end = acl_connection->GetAclQueueEnd();
   links_.try_emplace(device, l2cap_handler_, std::move(acl_connection),
-                     std::make_unique<Fifo>(link_queue_up_end, l2cap_handler_), parameter_provider_);
+                     std::make_unique<l2cap::internal::Fifo>(link_queue_up_end, l2cap_handler_), parameter_provider_);
   auto* link = GetLink(device);
   // Allocate and distribute channels for all registered fixed channel services
   auto fixed_channel_services = service_manager_->GetRegisteredServices();
   for (auto& fixed_channel_service : fixed_channel_services) {
     auto fixed_channel_impl = link->AllocateFixedChannel(fixed_channel_service.first, SecurityPolicy());
     fixed_channel_service.second->NotifyChannelCreation(
-        std::make_unique<ClassicFixedChannel>(fixed_channel_impl, l2cap_handler_));
+        std::make_unique<FixedChannel>(fixed_channel_impl, l2cap_handler_));
   }
   // Remove device from pending links list, if any
   auto pending_link = pending_links_.find(device);
@@ -116,7 +115,7 @@ void ClassicLinkManager::OnConnectSuccess(std::unique_ptr<hci::AclConnection> ac
   pending_links_.erase(pending_link);
 }
 
-void ClassicLinkManager::OnConnectFail(hci::Address device, hci::ErrorCode reason) {
+void LinkManager::OnConnectFail(hci::Address device, hci::ErrorCode reason) {
   // Notify all pending links for this device
   auto pending_link = pending_links_.find(device);
   if (pending_link == pending_links_.end()) {
@@ -125,17 +124,16 @@ void ClassicLinkManager::OnConnectFail(hci::Address device, hci::ErrorCode reaso
     return;
   }
   for (auto& pending_fixed_channel_connection : pending_link->second.pending_fixed_channel_connections_) {
-    pending_fixed_channel_connection.handler_->Post(
-        common::BindOnce(std::move(pending_fixed_channel_connection.on_fail_callback_),
-                         ClassicFixedChannelManager::ConnectionResult{
-                             .connection_result_code = ClassicFixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR,
-                             .hci_error = reason}));
+    pending_fixed_channel_connection.handler_->Post(common::BindOnce(
+        std::move(pending_fixed_channel_connection.on_fail_callback_),
+        FixedChannelManager::ConnectionResult{
+            .connection_result_code = FixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR, .hci_error = reason}));
   }
   // Remove entry in pending link list
   pending_links_.erase(pending_link);
 }
 
-void ClassicLinkManager::OnDisconnect(hci::Address device, hci::ErrorCode status) {
+void LinkManager::OnDisconnect(hci::Address device, hci::ErrorCode status) {
   auto* link = GetLink(device);
   ASSERT_LOG(link != nullptr, "Device %s is disconnected with reason 0x%x, but not in local database",
              device.ToString().c_str(), static_cast<uint8_t>(status));
@@ -144,5 +142,6 @@ void ClassicLinkManager::OnDisconnect(hci::Address device, hci::ErrorCode status
 }
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 67%
rename from gd/l2cap/internal/classic_link_manager.h
rename to gd/l2cap/classic/internal/link_manager.h
index f156c71..e190a27 100644 (file)
 #include <memory>
 #include <unordered_map>
 
-#include "l2cap/classic_dynamic_channel_manager.h"
-#include "l2cap/classic_fixed_channel_manager.h"
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
-#include "l2cap/internal/classic_link.h"
+#include "hci/acl_manager.h"
+#include "hci/address.h"
+#include "l2cap/classic/dynamic_channel_manager.h"
+#include "l2cap/classic/fixed_channel_manager.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/link.h"
 #include "l2cap/internal/parameter_provider.h"
 #include "l2cap/internal/scheduler.h"
 #include "os/handler.h"
 
-#include "hci/acl_manager.h"
-#include "hci/address.h"
-
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
-class ClassicLinkManager : public hci::ConnectionCallbacks {
+class LinkManager : public hci::ConnectionCallbacks {
  public:
-  ClassicLinkManager(os::Handler* l2cap_handler, hci::AclManager* acl_manager,
-                     ClassicFixedChannelServiceManagerImpl* service_manager, ParameterProvider* parameter_provider)
+  LinkManager(os::Handler* l2cap_handler, hci::AclManager* acl_manager, FixedChannelServiceManagerImpl* service_manager,
+              l2cap::internal::ParameterProvider* parameter_provider)
       : l2cap_handler_(l2cap_handler), acl_manager_(acl_manager), service_manager_(service_manager),
         parameter_provider_(parameter_provider) {
     acl_manager_->RegisterCallbacks(this, l2cap_handler_);
@@ -45,13 +45,13 @@ class ClassicLinkManager : public hci::ConnectionCallbacks {
 
   struct PendingFixedChannelConnection {
     os::Handler* handler_;
-    ClassicFixedChannelManager::OnConnectionFailureCallback on_fail_callback_;
+    FixedChannelManager::OnConnectionFailureCallback on_fail_callback_;
   };
 
   struct PendingDynamicChannelConnection {
     os::Handler* handler_;
-    ClassicDynamicChannelManager::OnConnectionOpenCallback on_open_callback_;
-    ClassicDynamicChannelManager::OnConnectionFailureCallback on_fail_callback_;
+    DynamicChannelManager::OnConnectionOpenCallback on_open_callback_;
+    DynamicChannelManager::OnConnectionFailureCallback on_fail_callback_;
   };
 
   struct PendingLink {
@@ -60,12 +60,12 @@ class ClassicLinkManager : public hci::ConnectionCallbacks {
 
   // ACL methods
 
-  ClassicLink* GetLink(hci::Address device);
+  Link* GetLink(hci::Address device);
   void OnConnectSuccess(std::unique_ptr<hci::AclConnection> acl_connection) override;
   void OnConnectFail(hci::Address device, hci::ErrorCode reason) override;
   void OnDisconnect(hci::Address device, hci::ErrorCode status);
 
-  // ClassicFixedChannelManager methods
+  // FixedChannelManager methods
 
   void ConnectFixedChannelServices(hci::Address device, PendingFixedChannelConnection pending_fixed_channel_connection);
 
@@ -73,15 +73,16 @@ class ClassicLinkManager : public hci::ConnectionCallbacks {
   // Dependencies
   os::Handler* l2cap_handler_;
   hci::AclManager* acl_manager_;
-  ClassicFixedChannelServiceManagerImpl* service_manager_;
-  ParameterProvider* parameter_provider_;
+  FixedChannelServiceManagerImpl* service_manager_;
+  l2cap::internal::ParameterProvider* parameter_provider_;
 
   // Internal states
   std::unordered_map<hci::Address, PendingLink> pending_links_;
-  std::unordered_map<hci::Address, ClassicLink> links_;
-  DISALLOW_COPY_AND_ASSIGN(ClassicLinkManager);
+  std::unordered_map<hci::Address, Link> links_;
+  DISALLOW_COPY_AND_ASSIGN(LinkManager);
 };
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "l2cap/internal/classic_link_manager.h"
+#include "l2cap/classic/internal/link_manager.h"
 
 #include <future>
 #include <thread>
@@ -24,9 +24,9 @@
 #include "hci/acl_manager_mock.h"
 #include "hci/address.h"
 #include "l2cap/cid.h"
-#include "l2cap/classic_fixed_channel_manager.h"
-#include "l2cap/internal/classic_fixed_channel_service_impl_mock.h"
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl_mock.h"
+#include "l2cap/classic/fixed_channel_manager.h"
+#include "l2cap/classic/internal/fixed_channel_service_impl_mock.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl_mock.h"
 #include "l2cap/internal/parameter_provider_mock.h"
 #include "os/handler.h"
 #include "os/thread.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 
 using hci::testing::MockAclConnection;
 using hci::testing::MockAclManager;
+using l2cap::internal::testing::MockParameterProvider;
 using ::testing::_;  // Matcher to any value
 using ::testing::ByMove;
 using ::testing::DoAll;
-using testing::MockClassicFixedChannelServiceImpl;
-using testing::MockClassicFixedChannelServiceManagerImpl;
-using testing::MockParameterProvider;
+using testing::MockFixedChannelServiceImpl;
+using testing::MockFixedChannelServiceManagerImpl;
 using ::testing::Return;
 using ::testing::SaveArg;
 
@@ -83,7 +84,7 @@ class L2capClassicLinkManagerTest : public ::testing::Test {
 };
 
 TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl) {
-  MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
+  MockFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
   MockAclManager mock_acl_manager;
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -93,23 +94,23 @@ TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl) {
   os::Handler* hci_callback_handler = nullptr;
   EXPECT_CALL(mock_acl_manager, RegisterCallbacks(_, _))
       .WillOnce(DoAll(SaveArg<0>(&hci_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
-  ClassicLinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager,
-                                          &mock_classic_fixed_channel_service_manager, mock_parameter_provider_);
+  LinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager, &mock_classic_fixed_channel_service_manager,
+                                   mock_parameter_provider_);
   EXPECT_EQ(hci_connection_callbacks, &classic_link_manager);
   EXPECT_EQ(hci_callback_handler, l2cap_handler_);
 
   // Register fake services
-  MockClassicFixedChannelServiceImpl mock_service_1, mock_service_2;
-  std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> results;
+  MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+  std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
   results.emplace_back(kSmpBrCid, &mock_service_1);
   results.emplace_back(kConnectionlessCid, &mock_service_2);
   EXPECT_CALL(mock_classic_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
 
   // Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
   EXPECT_CALL(mock_acl_manager, CreateConnection(device)).Times(1);
-  ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
       .handler_ = user_handler.get(),
-      .on_fail_callback_ = common::BindOnce([](ClassicFixedChannelManager::ConnectionResult result) { FAIL(); })};
+      .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
   classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection));
 
   // Step 3: ACL connection success event should trigger channel creation for all registered services
@@ -118,11 +119,13 @@ TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl) {
   hci::AclConnection::Queue link_queue{10};
   EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
   EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
-  std::unique_ptr<ClassicFixedChannel> channel_1, channel_2;
-  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_))
-      .WillOnce([&channel_1](std::unique_ptr<ClassicFixedChannel> channel) { channel_1 = std::move(channel); });
-  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_))
-      .WillOnce([&channel_2](std::unique_ptr<ClassicFixedChannel> channel) { channel_2 = std::move(channel); });
+  std::unique_ptr<FixedChannel> channel_1, channel_2;
+  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
+    channel_1 = std::move(channel);
+  });
+  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
+    channel_2 = std::move(channel);
+  });
   hci_callback_handler->Post(common::BindOnce(&hci::ConnectionCallbacks::OnConnectSuccess,
                                               common::Unretained(hci_connection_callbacks), std::move(acl_connection)));
   SyncHandler(hci_callback_handler);
@@ -130,26 +133,27 @@ TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl) {
   EXPECT_NE(channel_2, nullptr);
 
   // Step 4: Calling ConnectServices() to the same device will no trigger another connection attempt
-  ClassicFixedChannelManager::ConnectionResult my_result;
-  ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_2{
+  FixedChannelManager::ConnectionResult my_result;
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_2{
       .handler_ = user_handler.get(),
       .on_fail_callback_ = common::testing::BindLambdaForTesting(
-          [&my_result](ClassicFixedChannelManager::ConnectionResult result) { my_result = result; })};
+          [&my_result](FixedChannelManager::ConnectionResult result) { my_result = result; })};
   classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection_2));
   SyncHandler(user_handler.get());
   EXPECT_EQ(my_result.connection_result_code,
-            ClassicFixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL);
+            FixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL);
 
   // Step 5: Register new service will cause new channels to be created during ConnectServices()
-  MockClassicFixedChannelServiceImpl mock_service_3;
+  MockFixedChannelServiceImpl mock_service_3;
   results.emplace_back(kSmpBrCid + 1, &mock_service_3);
   EXPECT_CALL(mock_classic_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
-  ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_3{
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_3{
       .handler_ = user_handler.get(),
-      .on_fail_callback_ = common::BindOnce([](ClassicFixedChannelManager::ConnectionResult result) { FAIL(); })};
-  std::unique_ptr<ClassicFixedChannel> channel_3;
-  EXPECT_CALL(mock_service_3, NotifyChannelCreation(_))
-      .WillOnce([&channel_3](std::unique_ptr<ClassicFixedChannel> channel) { channel_3 = std::move(channel); });
+      .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
+  std::unique_ptr<FixedChannel> channel_3;
+  EXPECT_CALL(mock_service_3, NotifyChannelCreation(_)).WillOnce([&channel_3](std::unique_ptr<FixedChannel> channel) {
+    channel_3 = std::move(channel);
+  });
   classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection_3));
   EXPECT_NE(channel_3, nullptr);
 
@@ -159,7 +163,7 @@ TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl) {
 }
 
 TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl_with_no_service) {
-  MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
+  MockFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
   MockAclManager mock_acl_manager;
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -169,32 +173,31 @@ TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl_wi
   os::Handler* hci_callback_handler = nullptr;
   EXPECT_CALL(mock_acl_manager, RegisterCallbacks(_, _))
       .WillOnce(DoAll(SaveArg<0>(&hci_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
-  ClassicLinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager,
-                                          &mock_classic_fixed_channel_service_manager, mock_parameter_provider_);
+  LinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager, &mock_classic_fixed_channel_service_manager,
+                                   mock_parameter_provider_);
   EXPECT_EQ(hci_connection_callbacks, &classic_link_manager);
   EXPECT_EQ(hci_callback_handler, l2cap_handler_);
 
   // Make sure no service is registered
-  std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> results;
+  std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
   EXPECT_CALL(mock_classic_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
 
   // Step 2: Connect to fixed channel without any service registered will result in failure
   EXPECT_CALL(mock_acl_manager, CreateConnection(device)).Times(0);
-  ClassicFixedChannelManager::ConnectionResult my_result;
-  ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+  FixedChannelManager::ConnectionResult my_result;
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
       .handler_ = user_handler.get(),
       .on_fail_callback_ = common::testing::BindLambdaForTesting(
-          [&my_result](ClassicFixedChannelManager::ConnectionResult result) { my_result = result; })};
+          [&my_result](FixedChannelManager::ConnectionResult result) { my_result = result; })};
   classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection));
   SyncHandler(user_handler.get());
-  EXPECT_EQ(my_result.connection_result_code,
-            ClassicFixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED);
+  EXPECT_EQ(my_result.connection_result_code, FixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED);
 
   user_handler->Clear();
 }
 
 TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl_with_hci_failure) {
-  MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
+  MockFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
   MockAclManager mock_acl_manager;
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -204,24 +207,24 @@ TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl_wi
   os::Handler* hci_callback_handler = nullptr;
   EXPECT_CALL(mock_acl_manager, RegisterCallbacks(_, _))
       .WillOnce(DoAll(SaveArg<0>(&hci_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
-  ClassicLinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager,
-                                          &mock_classic_fixed_channel_service_manager, mock_parameter_provider_);
+  LinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager, &mock_classic_fixed_channel_service_manager,
+                                   mock_parameter_provider_);
   EXPECT_EQ(hci_connection_callbacks, &classic_link_manager);
   EXPECT_EQ(hci_callback_handler, l2cap_handler_);
 
   // Register fake services
-  MockClassicFixedChannelServiceImpl mock_service_1;
-  std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> results;
+  MockFixedChannelServiceImpl mock_service_1;
+  std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
   results.emplace_back(kSmpBrCid, &mock_service_1);
   EXPECT_CALL(mock_classic_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
 
   // Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
   EXPECT_CALL(mock_acl_manager, CreateConnection(device)).Times(1);
-  ClassicFixedChannelManager::ConnectionResult my_result;
-  ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+  FixedChannelManager::ConnectionResult my_result;
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
       .handler_ = user_handler.get(),
       .on_fail_callback_ = common::testing::BindLambdaForTesting(
-          [&my_result](ClassicFixedChannelManager::ConnectionResult result) { my_result = result; })};
+          [&my_result](FixedChannelManager::ConnectionResult result) { my_result = result; })};
   classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection));
 
   // Step 3: ACL connection failure event should trigger connection failure callback
@@ -231,7 +234,7 @@ TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl_wi
                                               hci::ErrorCode::PAGE_TIMEOUT));
   SyncHandler(hci_callback_handler);
   SyncHandler(user_handler.get());
-  EXPECT_EQ(my_result.connection_result_code, ClassicFixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR);
+  EXPECT_EQ(my_result.connection_result_code, FixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR);
   EXPECT_EQ(my_result.hci_error, hci::ErrorCode::PAGE_TIMEOUT);
 
   user_handler->Clear();
@@ -240,7 +243,7 @@ TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl_wi
 TEST_F(L2capClassicLinkManagerTest, not_acquiring_channels_should_disconnect_acl_after_timeout) {
   EXPECT_CALL(*mock_parameter_provider_, GetClassicLinkIdleDisconnectTimeout)
       .WillRepeatedly(Return(kTestIdleDisconnectTimeoutShort));
-  MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
+  MockFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
   MockAclManager mock_acl_manager;
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -250,23 +253,23 @@ TEST_F(L2capClassicLinkManagerTest, not_acquiring_channels_should_disconnect_acl
   os::Handler* hci_callback_handler = nullptr;
   EXPECT_CALL(mock_acl_manager, RegisterCallbacks(_, _))
       .WillOnce(DoAll(SaveArg<0>(&hci_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
-  ClassicLinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager,
-                                          &mock_classic_fixed_channel_service_manager, mock_parameter_provider_);
+  LinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager, &mock_classic_fixed_channel_service_manager,
+                                   mock_parameter_provider_);
   EXPECT_EQ(hci_connection_callbacks, &classic_link_manager);
   EXPECT_EQ(hci_callback_handler, l2cap_handler_);
 
   // Register fake services
-  MockClassicFixedChannelServiceImpl mock_service_1, mock_service_2;
-  std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> results;
+  MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+  std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
   results.emplace_back(kSmpBrCid, &mock_service_1);
   results.emplace_back(kConnectionlessCid, &mock_service_2);
   EXPECT_CALL(mock_classic_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
 
   // Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
   EXPECT_CALL(mock_acl_manager, CreateConnection(device)).Times(1);
-  ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
       .handler_ = user_handler.get(),
-      .on_fail_callback_ = common::BindOnce([](ClassicFixedChannelManager::ConnectionResult result) { FAIL(); })};
+      .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
   classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection));
 
   // Step 3: ACL connection success event should trigger channel creation for all registered services
@@ -275,11 +278,13 @@ TEST_F(L2capClassicLinkManagerTest, not_acquiring_channels_should_disconnect_acl
   hci::AclConnection::Queue link_queue{10};
   EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
   EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
-  std::unique_ptr<ClassicFixedChannel> channel_1, channel_2;
-  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_))
-      .WillOnce([&channel_1](std::unique_ptr<ClassicFixedChannel> channel) { channel_1 = std::move(channel); });
-  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_))
-      .WillOnce([&channel_2](std::unique_ptr<ClassicFixedChannel> channel) { channel_2 = std::move(channel); });
+  std::unique_ptr<FixedChannel> channel_1, channel_2;
+  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
+    channel_1 = std::move(channel);
+  });
+  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
+    channel_2 = std::move(channel);
+  });
   hci_callback_handler->Post(common::BindOnce(&hci::ConnectionCallbacks::OnConnectSuccess,
                                               common::Unretained(hci_connection_callbacks), std::move(acl_connection)));
   SyncHandler(hci_callback_handler);
@@ -308,7 +313,7 @@ TEST_F(L2capClassicLinkManagerTest, not_acquiring_channels_should_disconnect_acl
 TEST_F(L2capClassicLinkManagerTest, acquiring_channels_should_not_disconnect_acl_after_timeout) {
   EXPECT_CALL(*mock_parameter_provider_, GetClassicLinkIdleDisconnectTimeout)
       .WillRepeatedly(Return(kTestIdleDisconnectTimeoutShort));
-  MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
+  MockFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
   MockAclManager mock_acl_manager;
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -318,23 +323,23 @@ TEST_F(L2capClassicLinkManagerTest, acquiring_channels_should_not_disconnect_acl
   os::Handler* hci_callback_handler = nullptr;
   EXPECT_CALL(mock_acl_manager, RegisterCallbacks(_, _))
       .WillOnce(DoAll(SaveArg<0>(&hci_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
-  ClassicLinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager,
-                                          &mock_classic_fixed_channel_service_manager, mock_parameter_provider_);
+  LinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager, &mock_classic_fixed_channel_service_manager,
+                                   mock_parameter_provider_);
   EXPECT_EQ(hci_connection_callbacks, &classic_link_manager);
   EXPECT_EQ(hci_callback_handler, l2cap_handler_);
 
   // Register fake services
-  MockClassicFixedChannelServiceImpl mock_service_1, mock_service_2;
-  std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> results;
+  MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+  std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
   results.emplace_back(kSmpBrCid, &mock_service_1);
   results.emplace_back(kConnectionlessCid, &mock_service_2);
   EXPECT_CALL(mock_classic_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
 
   // Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
   EXPECT_CALL(mock_acl_manager, CreateConnection(device)).Times(1);
-  ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
       .handler_ = user_handler.get(),
-      .on_fail_callback_ = common::BindOnce([](ClassicFixedChannelManager::ConnectionResult result) { FAIL(); })};
+      .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
   classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection));
 
   // Step 3: ACL connection success event should trigger channel creation for all registered services
@@ -343,11 +348,13 @@ TEST_F(L2capClassicLinkManagerTest, acquiring_channels_should_not_disconnect_acl
   hci::AclConnection::Queue link_queue{10};
   EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
   EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
-  std::unique_ptr<ClassicFixedChannel> channel_1, channel_2;
-  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_))
-      .WillOnce([&channel_1](std::unique_ptr<ClassicFixedChannel> channel) { channel_1 = std::move(channel); });
-  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_))
-      .WillOnce([&channel_2](std::unique_ptr<ClassicFixedChannel> channel) { channel_2 = std::move(channel); });
+  std::unique_ptr<FixedChannel> channel_1, channel_2;
+  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
+    channel_1 = std::move(channel);
+  });
+  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
+    channel_2 = std::move(channel);
+  });
   hci_callback_handler->Post(common::BindOnce(&hci::ConnectionCallbacks::OnConnectSuccess,
                                               common::Unretained(hci_connection_callbacks), std::move(acl_connection)));
   SyncHandler(hci_callback_handler);
@@ -378,7 +385,7 @@ TEST_F(L2capClassicLinkManagerTest, acquiring_channels_should_not_disconnect_acl
 TEST_F(L2capClassicLinkManagerTest, acquiring_and_releasing_channels_should_eventually_disconnect_acl) {
   EXPECT_CALL(*mock_parameter_provider_, GetClassicLinkIdleDisconnectTimeout)
       .WillRepeatedly(Return(kTestIdleDisconnectTimeoutShort));
-  MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
+  MockFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
   MockAclManager mock_acl_manager;
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -388,23 +395,23 @@ TEST_F(L2capClassicLinkManagerTest, acquiring_and_releasing_channels_should_even
   os::Handler* hci_callback_handler = nullptr;
   EXPECT_CALL(mock_acl_manager, RegisterCallbacks(_, _))
       .WillOnce(DoAll(SaveArg<0>(&hci_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
-  ClassicLinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager,
-                                          &mock_classic_fixed_channel_service_manager, mock_parameter_provider_);
+  LinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager, &mock_classic_fixed_channel_service_manager,
+                                   mock_parameter_provider_);
   EXPECT_EQ(hci_connection_callbacks, &classic_link_manager);
   EXPECT_EQ(hci_callback_handler, l2cap_handler_);
 
   // Register fake services
-  MockClassicFixedChannelServiceImpl mock_service_1, mock_service_2;
-  std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> results;
+  MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+  std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
   results.emplace_back(kSmpBrCid, &mock_service_1);
   results.emplace_back(kConnectionlessCid, &mock_service_2);
   EXPECT_CALL(mock_classic_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
 
   // Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
   EXPECT_CALL(mock_acl_manager, CreateConnection(device)).Times(1);
-  ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
       .handler_ = user_handler.get(),
-      .on_fail_callback_ = common::BindOnce([](ClassicFixedChannelManager::ConnectionResult result) { FAIL(); })};
+      .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
   classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection));
 
   // Step 3: ACL connection success event should trigger channel creation for all registered services
@@ -413,11 +420,13 @@ TEST_F(L2capClassicLinkManagerTest, acquiring_and_releasing_channels_should_even
   hci::AclConnection::Queue link_queue{10};
   EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
   EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
-  std::unique_ptr<ClassicFixedChannel> channel_1, channel_2;
-  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_))
-      .WillOnce([&channel_1](std::unique_ptr<ClassicFixedChannel> channel) { channel_1 = std::move(channel); });
-  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_))
-      .WillOnce([&channel_2](std::unique_ptr<ClassicFixedChannel> channel) { channel_2 = std::move(channel); });
+  std::unique_ptr<FixedChannel> channel_1, channel_2;
+  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
+    channel_1 = std::move(channel);
+  });
+  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
+    channel_2 = std::move(channel);
+  });
   hci_callback_handler->Post(common::BindOnce(&hci::ConnectionCallbacks::OnConnectSuccess,
                                               common::Unretained(hci_connection_callbacks), std::move(acl_connection)));
   SyncHandler(hci_callback_handler);
@@ -451,5 +460,6 @@ TEST_F(L2capClassicLinkManagerTest, acquiring_and_releasing_channels_should_even
 }
 
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 72%
rename from gd/l2cap/internal/le_link_mock.h
rename to gd/l2cap/classic/internal/link_mock.h
index c3b660e..0f7f1be 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "hci/acl_manager_mock.h"
 #include "hci/address.h"
-#include "l2cap/internal/le_link.h"
+#include "l2cap/classic/internal/link.h"
 #include "l2cap/internal/scheduler_mock.h"
 
 #include <gmock/gmock.h>
 // Unit test interfaces
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 namespace internal {
 namespace testing {
 
 using hci::testing::MockAclConnection;
 
-class MockLeLink : public LeLink {
+class MockLink : public Link {
  public:
-  explicit MockLeLink(os::Handler* handler, ParameterProvider* parameter_provider)
-      : LeLink(handler, std::make_unique<MockAclConnection>(), std::make_unique<MockScheduler>(), parameter_provider){};
+  explicit MockLink(os::Handler* handler, l2cap::internal::ParameterProvider* parameter_provider)
+      : Link(handler, std::make_unique<MockAclConnection>(),
+             std::make_unique<l2cap::internal::testing::MockScheduler>(), parameter_provider){};
   MOCK_METHOD(hci::Address, GetDevice, (), (override));
   MOCK_METHOD(void, OnAclDisconnected, (hci::ErrorCode status), (override));
   MOCK_METHOD(void, Disconnect, (), (override));
-  MOCK_METHOD(std::shared_ptr<LeFixedChannelImpl>, AllocateFixedChannel, (Cid cid, SecurityPolicy security_policy),
+  MOCK_METHOD(std::shared_ptr<FixedChannelImpl>, AllocateFixedChannel, (Cid cid, SecurityPolicy security_policy),
               (override));
   MOCK_METHOD(bool, IsFixedChannelAllocated, (Cid cid), (override));
   MOCK_METHOD(void, RefreshRefCount, (), (override));
@@ -45,5 +47,6 @@ class MockLeLink : public LeLink {
 
 }  // namespace testing
 }  // namespace internal
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
diff --git a/gd/l2cap/classic/l2cap_classic_module.cc b/gd/l2cap/classic/l2cap_classic_module.cc
new file mode 100644 (file)
index 0000000..3dc892b
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2019 The Android Open Source Project
+ *
+ * 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.
+ */
+#define LOG_TAG "l2cap2"
+
+#include <memory>
+
+#include "common/bidi_queue.h"
+#include "hci/acl_manager.h"
+#include "hci/address.h"
+#include "hci/hci_layer.h"
+#include "hci/hci_packets.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/link_manager.h"
+#include "l2cap/internal/parameter_provider.h"
+#include "module.h"
+#include "os/handler.h"
+#include "os/log.h"
+
+#include "l2cap/classic/l2cap_classic_module.h"
+
+namespace bluetooth {
+namespace l2cap {
+namespace classic {
+
+const ModuleFactory L2capClassicModule::Factory = ModuleFactory([]() { return new L2capClassicModule(); });
+
+struct L2capClassicModule::impl {
+  impl(os::Handler* l2cap_handler, hci::AclManager* acl_manager)
+      : l2cap_handler_(l2cap_handler), acl_manager_(acl_manager) {}
+  os::Handler* l2cap_handler_;
+  hci::AclManager* acl_manager_;
+  l2cap::internal::ParameterProvider parameter_provider_;
+  internal::FixedChannelServiceManagerImpl fixed_channel_service_manager_impl_{l2cap_handler_};
+  internal::LinkManager link_manager_{l2cap_handler_, acl_manager_, &fixed_channel_service_manager_impl_,
+                                      &parameter_provider_};
+};
+
+void L2capClassicModule::ListDependencies(ModuleList* list) {
+  list->add<hci::AclManager>();
+}
+
+void L2capClassicModule::Start() {
+  pimpl_ = std::make_unique<impl>(GetHandler(), GetDependency<hci::AclManager>());
+}
+
+void L2capClassicModule::Stop() {
+  pimpl_.reset();
+}
+
+std::unique_ptr<FixedChannelManager> L2capClassicModule::GetFixedChannelManager() {
+  return std::unique_ptr<FixedChannelManager>(new FixedChannelManager(&pimpl_->fixed_channel_service_manager_impl_,
+                                                                      &pimpl_->link_manager_, pimpl_->l2cap_handler_));
+}
+
+}  // namespace classic
+}  // namespace l2cap
+}  // namespace bluetooth
\ No newline at end of file
similarity index 68%
rename from gd/l2cap/l2cap_layer.h
rename to gd/l2cap/classic/l2cap_classic_module.h
index 283ea71..398a920 100644 (file)
 
 #include <memory>
 
-#include "l2cap/classic_fixed_channel_manager.h"
-#include "l2cap/le_fixed_channel_manager.h"
+#include "l2cap/classic/fixed_channel_manager.h"
 #include "module.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace classic {
 
-class L2capLayer : public bluetooth::Module {
+class L2capClassicModule : public bluetooth::Module {
  public:
-  L2capLayer() = default;
-  ~L2capLayer() = default;
+  L2capClassicModule() = default;
+  ~L2capClassicModule() = default;
 
   /**
    * Get the api to the classic fixed channel l2cap module
    */
-  std::unique_ptr<ClassicFixedChannelManager> GetClassicFixedChannelManager();
-
-  /**
-   * Get the api to the LE fixed channel l2cap module
-   */
-  std::unique_ptr<LeFixedChannelManager> GetLeFixedChannelManager();
+  std::unique_ptr<FixedChannelManager> GetFixedChannelManager();
 
   static const ModuleFactory Factory;
 
@@ -51,8 +46,9 @@ class L2capLayer : public bluetooth::Module {
  private:
   struct impl;
   std::unique_ptr<impl> pimpl_;
-  DISALLOW_COPY_AND_ASSIGN(L2capLayer);
+  DISALLOW_COPY_AND_ASSIGN(L2capClassicModule);
 };
 
+}  // namespace classic
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
diff --git a/gd/l2cap/internal/classic_dynamic_channel_service_manager_impl.cc b/gd/l2cap/internal/classic_dynamic_channel_service_manager_impl.cc
deleted file mode 100644 (file)
index 4f996ea..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * 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 "l2cap/internal/classic_dynamic_channel_service_manager_impl.h"
-
-#include "common/bind.h"
-#include "l2cap/internal/classic_dynamic_channel_service_impl.h"
-#include "l2cap/psm.h"
-#include "os/log.h"
-
-namespace bluetooth {
-namespace l2cap {
-namespace internal {
-
-void ClassicDynamicChannelServiceManagerImpl::Register(
-    Psm psm, ClassicDynamicChannelServiceImpl::PendingRegistration pending_registration) {
-  if (!IsPsmValid(psm)) {
-    std::unique_ptr<ClassicDynamicChannelService> invalid_service(new ClassicDynamicChannelService());
-    pending_registration.user_handler_->Post(common::BindOnce(
-        std::move(pending_registration.on_registration_complete_callback_),
-        ClassicDynamicChannelManager::RegistrationResult::FAIL_INVALID_SERVICE, std::move(invalid_service)));
-  } else if (IsServiceRegistered(psm)) {
-    std::unique_ptr<ClassicDynamicChannelService> invalid_service(new ClassicDynamicChannelService());
-    pending_registration.user_handler_->Post(common::BindOnce(
-        std::move(pending_registration.on_registration_complete_callback_),
-        ClassicDynamicChannelManager::RegistrationResult::FAIL_DUPLICATE_SERVICE, std::move(invalid_service)));
-  } else {
-    service_map_.try_emplace(
-        psm, ClassicDynamicChannelServiceImpl(pending_registration.user_handler_,
-                                              std::move(pending_registration.on_connection_open_callback_)));
-    std::unique_ptr<ClassicDynamicChannelService> user_service(
-        new ClassicDynamicChannelService(psm, this, l2cap_layer_handler_));
-    pending_registration.user_handler_->Post(
-        common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
-                         ClassicDynamicChannelManager::RegistrationResult::SUCCESS, std::move(user_service)));
-  }
-}
-
-void ClassicDynamicChannelServiceManagerImpl::Unregister(Psm psm,
-                                                         ClassicDynamicChannelService::OnUnregisteredCallback callback,
-                                                         os::Handler* handler) {
-  if (IsServiceRegistered(psm)) {
-    service_map_.erase(psm);
-    handler->Post(std::move(callback));
-  } else {
-    LOG_ERROR("service not registered psm:%d", psm);
-  }
-}
-
-bool ClassicDynamicChannelServiceManagerImpl::IsServiceRegistered(Psm psm) const {
-  return service_map_.find(psm) != service_map_.end();
-}
-
-ClassicDynamicChannelServiceImpl* ClassicDynamicChannelServiceManagerImpl::GetService(Psm psm) {
-  ASSERT(IsServiceRegistered(psm));
-  return &service_map_.find(psm)->second;
-}
-
-std::vector<std::pair<Psm, ClassicDynamicChannelServiceImpl*>>
-ClassicDynamicChannelServiceManagerImpl::GetRegisteredServices() {
-  std::vector<std::pair<Psm, ClassicDynamicChannelServiceImpl*>> results;
-  for (auto& elem : service_map_) {
-    results.emplace_back(elem.first, &elem.second);
-  }
-  return results;
-}
-
-}  // namespace internal
-}  // namespace l2cap
-}  // namespace bluetooth
diff --git a/gd/l2cap/internal/classic_fixed_channel_service_manager_impl.cc b/gd/l2cap/internal/classic_fixed_channel_service_manager_impl.cc
deleted file mode 100644 (file)
index 5861a93..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * 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 "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
-
-#include "common/bind.h"
-#include "l2cap/cid.h"
-#include "l2cap/internal/classic_fixed_channel_service_impl.h"
-#include "os/log.h"
-
-namespace bluetooth {
-namespace l2cap {
-namespace internal {
-
-void ClassicFixedChannelServiceManagerImpl::Register(
-    Cid cid, ClassicFixedChannelServiceImpl::PendingRegistration pending_registration) {
-  if (cid < kFirstFixedChannel || cid > kLastFixedChannel || cid == kClassicSignallingCid) {
-    std::unique_ptr<ClassicFixedChannelService> invalid_service(new ClassicFixedChannelService());
-    pending_registration.user_handler_->Post(common::BindOnce(
-        std::move(pending_registration.on_registration_complete_callback_),
-        ClassicFixedChannelManager::RegistrationResult::FAIL_INVALID_SERVICE, std::move(invalid_service)));
-  } else if (IsServiceRegistered(cid)) {
-    std::unique_ptr<ClassicFixedChannelService> invalid_service(new ClassicFixedChannelService());
-    pending_registration.user_handler_->Post(common::BindOnce(
-        std::move(pending_registration.on_registration_complete_callback_),
-        ClassicFixedChannelManager::RegistrationResult::FAIL_DUPLICATE_SERVICE, std::move(invalid_service)));
-  } else {
-    service_map_.try_emplace(
-        cid, ClassicFixedChannelServiceImpl(pending_registration.user_handler_,
-                                            std::move(pending_registration.on_connection_open_callback_)));
-    std::unique_ptr<ClassicFixedChannelService> user_service(
-        new ClassicFixedChannelService(cid, this, l2cap_layer_handler_));
-    pending_registration.user_handler_->Post(
-        common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
-                         ClassicFixedChannelManager::RegistrationResult::SUCCESS, std::move(user_service)));
-  }
-}
-
-void ClassicFixedChannelServiceManagerImpl::Unregister(Cid cid,
-                                                       ClassicFixedChannelService::OnUnregisteredCallback callback,
-                                                       os::Handler* handler) {
-  if (IsServiceRegistered(cid)) {
-    service_map_.erase(cid);
-    handler->Post(std::move(callback));
-  } else {
-    LOG_ERROR("service not registered cid:%d", cid);
-  }
-}
-
-bool ClassicFixedChannelServiceManagerImpl::IsServiceRegistered(Cid cid) const {
-  return service_map_.find(cid) != service_map_.end();
-}
-
-ClassicFixedChannelServiceImpl* ClassicFixedChannelServiceManagerImpl::GetService(Cid cid) {
-  ASSERT(IsServiceRegistered(cid));
-  return &service_map_.find(cid)->second;
-}
-
-std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>>
-ClassicFixedChannelServiceManagerImpl::GetRegisteredServices() {
-  std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> results;
-  for (auto& elem : service_map_) {
-    results.emplace_back(elem.first, &elem.second);
-  }
-  return results;
-}
-
-}  // namespace internal
-}  // namespace l2cap
-}  // namespace bluetooth
index 52b1bb0..2162d36 100644 (file)
@@ -15,8 +15,8 @@
  */
 
 #include "l2cap/internal/fixed_channel_allocator.h"
-#include "l2cap/internal/classic_fixed_channel_impl_mock.h"
-#include "l2cap/internal/classic_link_mock.h"
+#include "l2cap/classic/internal/fixed_channel_impl_mock.h"
+#include "l2cap/classic/internal/link_mock.h"
 #include "l2cap/internal/parameter_provider_mock.h"
 
 #include <gmock/gmock.h>
@@ -26,8 +26,8 @@ namespace bluetooth {
 namespace l2cap {
 namespace internal {
 
-using testing::MockClassicFixedChannelImpl;
-using testing::MockClassicLink;
+using l2cap::classic::internal::testing::MockFixedChannelImpl;
+using l2cap::classic::internal::testing::MockLink;
 using testing::MockParameterProvider;
 using ::testing::Return;
 
@@ -39,11 +39,11 @@ class L2capFixedChannelAllocatorTest : public ::testing::Test {
     thread_ = new os::Thread("test_thread", os::Thread::Priority::NORMAL);
     handler_ = new os::Handler(thread_);
     mock_parameter_provider_ = new MockParameterProvider();
-    mock_classic_link_ = new MockClassicLink(handler_, mock_parameter_provider_);
+    mock_classic_link_ = new MockLink(handler_, mock_parameter_provider_);
     EXPECT_CALL(*mock_classic_link_, GetDevice()).WillRepeatedly(Return(device));
     // Use classic as a place holder
-    channel_allocator_ = std::make_unique<FixedChannelAllocator<MockClassicFixedChannelImpl, MockClassicLink>>(
-        mock_classic_link_, handler_);
+    channel_allocator_ =
+        std::make_unique<FixedChannelAllocator<MockFixedChannelImpl, MockLink>>(mock_classic_link_, handler_);
   }
 
   void TearDown() override {
@@ -58,8 +58,8 @@ class L2capFixedChannelAllocatorTest : public ::testing::Test {
   os::Thread* thread_{nullptr};
   os::Handler* handler_{nullptr};
   MockParameterProvider* mock_parameter_provider_{nullptr};
-  MockClassicLink* mock_classic_link_{nullptr};
-  std::unique_ptr<FixedChannelAllocator<MockClassicFixedChannelImpl, MockClassicLink>> channel_allocator_;
+  MockLink* mock_classic_link_{nullptr};
+  std::unique_ptr<FixedChannelAllocator<MockFixedChannelImpl, MockLink>> channel_allocator_;
 };
 
 TEST_F(L2capFixedChannelAllocatorTest, precondition) {
diff --git a/gd/l2cap/l2cap_layer.cc b/gd/l2cap/l2cap_layer.cc
deleted file mode 100644 (file)
index 288b5b0..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * 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.
- */
-#define LOG_TAG "l2cap2"
-
-#include <memory>
-
-#include "common/bidi_queue.h"
-#include "hci/acl_manager.h"
-#include "hci/address.h"
-#include "hci/hci_layer.h"
-#include "hci/hci_packets.h"
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
-#include "l2cap/internal/classic_link_manager.h"
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
-#include "l2cap/internal/le_link_manager.h"
-#include "l2cap/internal/parameter_provider.h"
-#include "module.h"
-#include "os/handler.h"
-#include "os/log.h"
-
-#include "l2cap/l2cap_layer.h"
-
-namespace bluetooth {
-namespace l2cap {
-
-const ModuleFactory L2capLayer::Factory = ModuleFactory([]() { return new L2capLayer(); });
-
-struct L2capLayer::impl {
-  impl(os::Handler* l2cap_handler, hci::AclManager* acl_manager)
-      : l2cap_handler_(l2cap_handler), acl_manager_(acl_manager) {}
-  os::Handler* l2cap_handler_;
-  hci::AclManager* acl_manager_;
-  internal::ParameterProvider parameter_provider_;
-  internal::ClassicFixedChannelServiceManagerImpl classic_fixed_channel_service_manager_impl_{l2cap_handler_};
-  internal::ClassicLinkManager classic_link_manager_{
-      l2cap_handler_, acl_manager_, &classic_fixed_channel_service_manager_impl_, &parameter_provider_};
-  internal::LeFixedChannelServiceManagerImpl le_fixed_channel_service_manager_impl_{l2cap_handler_};
-  internal::LeLinkManager le_link_manager_{l2cap_handler_, acl_manager_, &le_fixed_channel_service_manager_impl_,
-                                           &parameter_provider_};
-};
-
-void L2capLayer::ListDependencies(ModuleList* list) {
-  list->add<hci::AclManager>();
-}
-
-void L2capLayer::Start() {
-  pimpl_ = std::make_unique<impl>(GetHandler(), GetDependency<hci::AclManager>());
-}
-
-void L2capLayer::Stop() {
-  pimpl_.reset();
-}
-
-std::unique_ptr<ClassicFixedChannelManager> L2capLayer::GetClassicFixedChannelManager() {
-  return std::unique_ptr<ClassicFixedChannelManager>(new ClassicFixedChannelManager(
-      &pimpl_->classic_fixed_channel_service_manager_impl_, &pimpl_->classic_link_manager_, pimpl_->l2cap_handler_));
-}
-
-std::unique_ptr<LeFixedChannelManager> L2capLayer::GetLeFixedChannelManager() {
-  return std::unique_ptr<LeFixedChannelManager>(new LeFixedChannelManager(
-      &pimpl_->le_fixed_channel_service_manager_impl_, &pimpl_->le_link_manager_, pimpl_->l2cap_handler_));
-}
-
-}  // namespace l2cap
-}  // namespace bluetooth
\ No newline at end of file
similarity index 52%
rename from gd/l2cap/classic_dynamic_channel.cc
rename to gd/l2cap/le/fixed_channel.cc
index 6dddc48..f598c83 100644 (file)
  * limitations under the License.
  */
 
-#include "l2cap/classic_dynamic_channel.h"
+#include "l2cap/le/fixed_channel.h"
 #include "common/bind.h"
-#include "l2cap/internal/classic_dynamic_channel_impl.h"
+#include "l2cap/le/internal/fixed_channel_impl.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 
-hci::Address ClassicDynamicChannel::GetDevice() const {
+hci::Address FixedChannel::GetDevice() const {
   return impl_->GetDevice();
 }
 
-void ClassicDynamicChannel::RegisterOnCloseCallback(os::Handler* user_handler,
-                                                    ClassicDynamicChannel::OnCloseCallback on_close_callback) {
-  l2cap_handler_->Post(common::BindOnce(&internal::ClassicDynamicChannelImpl::RegisterOnCloseCallback, impl_,
-                                        user_handler, std::move(on_close_callback)));
+void FixedChannel::RegisterOnCloseCallback(os::Handler* user_handler, FixedChannel::OnCloseCallback on_close_callback) {
+  l2cap_handler_->Post(common::BindOnce(&internal::FixedChannelImpl::RegisterOnCloseCallback, impl_, user_handler,
+                                        std::move(on_close_callback)));
 }
 
-void ClassicDynamicChannel::Close() {
-  l2cap_handler_->Post(common::BindOnce(&internal::ClassicDynamicChannelImpl::Close, impl_));
+void FixedChannel::Acquire() {
+  l2cap_handler_->Post(common::BindOnce(&internal::FixedChannelImpl::Acquire, impl_));
+}
+
+void FixedChannel::Release() {
+  l2cap_handler_->Post(common::BindOnce(&internal::FixedChannelImpl::Release, impl_));
 }
 
 common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>*
-ClassicDynamicChannel::GetQueueUpEnd() const {
+FixedChannel::GetQueueUpEnd() const {
   return impl_->GetQueueUpEnd();
 }
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
similarity index 88%
rename from gd/l2cap/le_fixed_channel.h
rename to gd/l2cap/le/fixed_channel.h
index fdc8035..e09083a 100644 (file)
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 
 namespace internal {
-class LeFixedChannelImpl;
+class FixedChannelImpl;
 }  // namespace internal
 
 /**
@@ -36,10 +37,10 @@ class LeFixedChannelImpl;
  * Otherwise, {@link FixedChannel#Release()} will be called automatically.
  *
  */
-class LeFixedChannel {
+class FixedChannel {
  public:
-  // Should only be constructed by modules that have access to LeLinkManager
-  LeFixedChannel(std::shared_ptr<internal::LeFixedChannelImpl> impl, os::Handler* l2cap_handler)
+  // Should only be constructed by modules that have access to LinkManager
+  FixedChannel(std::shared_ptr<internal::FixedChannelImpl> impl, os::Handler* l2cap_handler)
       : impl_(std::move(impl)), l2cap_handler_(l2cap_handler) {
     ASSERT(impl_ != nullptr);
     ASSERT(l2cap_handler_ != nullptr);
@@ -65,7 +66,7 @@ class LeFixedChannel {
 
   /**
    * Indicate that this Fixed Channel is no longer being used. ACL connection will be disconnected after
-   * kLeLinkIdleDisconnectTimeout if no other DynamicChannel is connected or no other Fixed Channel is  using this
+   * kLinkIdleDisconnectTimeout if no other DynamicChannel is connected or no other Fixed Channel is  using this
    * ACL connection. However a module can still receive data on this channel as long as it remains open.
    */
   void Release();
@@ -80,9 +81,10 @@ class LeFixedChannel {
   common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>* GetQueueUpEnd() const;
 
  private:
-  std::shared_ptr<internal::LeFixedChannelImpl> impl_;
+  std::shared_ptr<internal::FixedChannelImpl> impl_;
   os::Handler* l2cap_handler_;
 };
 
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 55%
rename from gd/l2cap/le_fixed_channel_manager.cc
rename to gd/l2cap/le/fixed_channel_manager.cc
index c2c4bb1..44768d1 100644 (file)
  * limitations under the License.
  */
 
-#include "l2cap/le_fixed_channel_manager.h"
-#include "l2cap/internal/le_fixed_channel_service_impl.h"
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
-#include "l2cap/internal/le_link_manager.h"
+#include "l2cap/le/fixed_channel_manager.h"
+#include "l2cap/le/internal/fixed_channel_service_impl.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
+#include "l2cap/le/internal/link_manager.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 
-bool LeFixedChannelManager::ConnectServices(hci::Address device, hci::AddressType address_type,
-                                            OnConnectionFailureCallback on_fail_callback, os::Handler* handler) {
-  internal::LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+bool FixedChannelManager::ConnectServices(hci::Address device, hci::AddressType address_type,
+                                          OnConnectionFailureCallback on_fail_callback, os::Handler* handler) {
+  internal::LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
       .on_fail_callback_ = std::move(on_fail_callback), .handler_ = handler};
-  l2cap_layer_handler_->Post(common::BindOnce(&internal::LeLinkManager::ConnectFixedChannelServices,
+  l2cap_layer_handler_->Post(common::BindOnce(&internal::LinkManager::ConnectFixedChannelServices,
                                               common::Unretained(link_manager_), device, address_type,
                                               std::move(pending_fixed_channel_connection)));
   return true;
 }
 
-bool LeFixedChannelManager::RegisterService(Cid cid, const SecurityPolicy& security_policy,
-                                            OnRegistrationCompleteCallback on_registration_complete,
-                                            OnConnectionOpenCallback on_connection_open, os::Handler* handler) {
-  internal::LeFixedChannelServiceImpl::PendingRegistration pending_registration{
+bool FixedChannelManager::RegisterService(Cid cid, const SecurityPolicy& security_policy,
+                                          OnRegistrationCompleteCallback on_registration_complete,
+                                          OnConnectionOpenCallback on_connection_open, os::Handler* handler) {
+  internal::FixedChannelServiceImpl::PendingRegistration pending_registration{
       .user_handler_ = handler,
       .on_registration_complete_callback_ = std::move(on_registration_complete),
       .on_connection_open_callback_ = std::move(on_connection_open)};
-  l2cap_layer_handler_->Post(common::BindOnce(&internal::LeFixedChannelServiceManagerImpl::Register,
+  l2cap_layer_handler_->Post(common::BindOnce(&internal::FixedChannelServiceManagerImpl::Register,
                                               common::Unretained(service_manager_), cid,
                                               std::move(pending_registration)));
   return true;
 }
 
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 82%
rename from gd/l2cap/le_fixed_channel_manager.h
rename to gd/l2cap/le/fixed_channel_manager.h
index 7e87d46..454da38 100644 (file)
 #include "hci/acl_manager.h"
 #include "hci/address.h"
 #include "l2cap/cid.h"
-#include "l2cap/le_fixed_channel.h"
-#include "l2cap/le_fixed_channel_service.h"
+#include "l2cap/le/fixed_channel.h"
+#include "l2cap/le/fixed_channel_service.h"
 #include "l2cap/security_policy.h"
 #include "os/handler.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 
-class L2capLayer;
+class L2capLeModule;
 
 namespace internal {
-class LeLinkManager;
-class LeFixedChannelServiceManagerImpl;
+class LinkManager;
+class FixedChannelServiceManagerImpl;
 }  // namespace internal
 
-class LeFixedChannelManager {
+class FixedChannelManager {
  public:
   enum class ConnectionResultCode {
     SUCCESS = 0,
@@ -54,9 +55,9 @@ class LeFixedChannelManager {
   using OnConnectionFailureCallback = common::OnceCallback<void(ConnectionResult result)>;
 
   /**
-   * OnConnectionOpenCallback(LeFixedChannel channel);
+   * OnConnectionOpenCallback(FixedChannel channel);
    */
-  using OnConnectionOpenCallback = common::Callback<void(std::unique_ptr<LeFixedChannel>)>;
+  using OnConnectionOpenCallback = common::Callback<void(std::unique_ptr<FixedChannel>)>;
 
   enum class RegistrationResult {
     SUCCESS = 0,
@@ -65,10 +66,10 @@ class LeFixedChannelManager {
   };
 
   /**
-   * OnRegistrationFailureCallback(RegistrationResult result, LeFixedChannelService service);
+   * OnRegistrationFailureCallback(RegistrationResult result, FixedChannelService service);
    */
   using OnRegistrationCompleteCallback =
-      common::OnceCallback<void(RegistrationResult, std::unique_ptr<LeFixedChannelService>)>;
+      common::OnceCallback<void(RegistrationResult, std::unique_ptr<FixedChannelService>)>;
 
   /**
    * Connect to ALL fixed channels on a remote device
@@ -78,10 +79,10 @@ class LeFixedChannelManager {
    * - When true is returned, method caller should wait for on_fail_callback or on_open_callback registered through
    *   RegisterService() API.
    * - If an ACL connection does not exist, this method will create an ACL connection. As a result, on_open_callback
-   *   supplied through RegisterService() will be triggered to provide the actual LeFixedChannel objects
+   *   supplied through RegisterService() will be triggered to provide the actual FixedChannel objects
    * - If HCI connection failed, on_fail_callback will be triggered with FAIL_HCI_ERROR
    * - If fixed channel on a remote device is already reported as connected via on_open_callback and has been acquired
-   *   via LeFixedChannel#Acquire() API, it won't be reported again
+   *   via FixedChannel#Acquire() API, it won't be reported again
    * - If no service is registered, on_fail_callback will be triggered with FAIL_NO_SERVICE_REGISTERED
    * - If there is an ACL connection and channels for each service is allocated, on_fail_callback will be triggered with
    *   FAIL_ALL_SERVICES_HAVE_CHANNEL
@@ -90,7 +91,7 @@ class LeFixedChannelManager {
    * This call will initiate an effort to connect all fixed channel services on a remote device.
    * Due to the connectionless nature of fixed channels, all fixed channels will be connected together.
    * If a fixed channel service does not need a particular fixed channel. It should release the received
-   * channel immediately after receiving on_open_callback via LeFixedChannel#Release()
+   * channel immediately after receiving on_open_callback via FixedChannel#Release()
    *
    * A module calling ConnectServices() must have called RegisterService() before.
    * The callback will come back from on_open_callback in the service that is registered
@@ -111,14 +112,14 @@ class LeFixedChannelManager {
    * - This method is asynchronous.
    * - When false is returned, the registration fails immediately.
    * - When true is returned, method caller should wait for on_service_registered callback that contains a
-   *   LeFixedChannelService object. The registered service can be managed from that object.
+   *   FixedChannelService object. The registered service can be managed from that object.
    * - If a CID is already registered or some other error happens, on_registration_complete will be triggered with a
    *   non-SUCCESS value
-   * - After a service is registered, any classic ACL connection will create a LeFixedChannel object that is
+   * - After a service is registered, any classic ACL connection will create a FixedChannel object that is
    *   delivered through on_open_callback
    * - on_open_callback, will only be triggered after on_service_registered callback
    *
-   * @param cid: Le cid used to receive incoming connections
+   * @param cid:  cid used to receive incoming connections
    * @param security_policy: The security policy used for the connection.
    * @param on_registration_complete: A callback to indicate the service setup has completed. If the return status is
    *        not SUCCESS, it means service is not registered due to reasons like CID already take
@@ -129,18 +130,19 @@ class LeFixedChannelManager {
                        OnRegistrationCompleteCallback on_registration_complete,
                        OnConnectionOpenCallback on_connection_open, os::Handler* handler);
 
-  friend class L2capLayer;
+  friend class L2capLeModule;
 
  private:
   // The constructor is not to be used by user code
-  LeFixedChannelManager(internal::LeFixedChannelServiceManagerImpl* service_manager,
-                        internal::LeLinkManager* link_manager, os::Handler* l2cap_layer_handler)
+  FixedChannelManager(internal::FixedChannelServiceManagerImpl* service_manager, internal::LinkManager* link_manager,
+                      os::Handler* l2cap_layer_handler)
       : service_manager_(service_manager), link_manager_(link_manager), l2cap_layer_handler_(l2cap_layer_handler) {}
-  internal::LeFixedChannelServiceManagerImpl* service_manager_ = nullptr;
-  internal::LeLinkManager* link_manager_ = nullptr;
+  internal::FixedChannelServiceManagerImpl* service_manager_ = nullptr;
+  internal::LinkManager* link_manager_ = nullptr;
   os::Handler* l2cap_layer_handler_ = nullptr;
-  DISALLOW_COPY_AND_ASSIGN(LeFixedChannelManager);
+  DISALLOW_COPY_AND_ASSIGN(FixedChannelManager);
 };
 
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 70%
rename from gd/l2cap/le_fixed_channel_service.cc
rename to gd/l2cap/le/fixed_channel_service.cc
index 18393f9..888a741 100644 (file)
  * limitations under the License.
  */
 
-#include "l2cap/le_fixed_channel_service.h"
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
+#include "l2cap/le/fixed_channel_service.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 
-void LeFixedChannelService::Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler) {
+void FixedChannelService::Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler) {
   ASSERT_LOG(manager_ != nullptr, "this service is invalid");
-  l2cap_layer_handler_->Post(common::BindOnce(&internal::LeFixedChannelServiceManagerImpl::Unregister,
+  l2cap_layer_handler_->Post(common::BindOnce(&internal::FixedChannelServiceManagerImpl::Unregister,
                                               common::Unretained(manager_), cid_, std::move(on_unregistered),
                                               on_unregistered_handler));
 }
 
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
similarity index 77%
rename from gd/l2cap/le_fixed_channel_service.h
rename to gd/l2cap/le/fixed_channel_service.h
index 93c8760..0c4556e 100644 (file)
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 
 namespace internal {
-class LeFixedChannelServiceManagerImpl;
+class FixedChannelServiceManagerImpl;
 }
 
-class LeFixedChannelService {
+class FixedChannelService {
  public:
-  LeFixedChannelService() = default;
+  FixedChannelService() = default;
 
   using OnUnregisteredCallback = common::OnceCallback<void()>;
 
@@ -42,16 +43,17 @@ class LeFixedChannelService {
    */
   void Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler);
 
-  friend internal::LeFixedChannelServiceManagerImpl;
+  friend internal::FixedChannelServiceManagerImpl;
 
  private:
-  LeFixedChannelService(Cid cid, internal::LeFixedChannelServiceManagerImpl* manager, os::Handler* handler)
+  FixedChannelService(Cid cid, internal::FixedChannelServiceManagerImpl* manager, os::Handler* handler)
       : cid_(cid), manager_(manager), l2cap_layer_handler_(handler) {}
   Cid cid_ = kInvalidCid;
-  internal::LeFixedChannelServiceManagerImpl* manager_ = nullptr;
+  internal::FixedChannelServiceManagerImpl* manager_ = nullptr;
   os::Handler* l2cap_layer_handler_;
-  DISALLOW_COPY_AND_ASSIGN(LeFixedChannelService);
+  DISALLOW_COPY_AND_ASSIGN(FixedChannelService);
 };
 
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 84%
rename from gd/l2cap/internal/le_fixed_channel_impl.cc
rename to gd/l2cap/le/internal/fixed_channel_impl.cc
index 1aebbec..8d309fd 100644 (file)
 #include <unordered_map>
 
 #include "l2cap/cid.h"
-#include "l2cap/internal/le_fixed_channel_impl.h"
-#include "l2cap/internal/le_link.h"
+#include "l2cap/le/internal/fixed_channel_impl.h"
+#include "l2cap/le/internal/link.h"
 #include "l2cap/security_policy.h"
 #include "os/handler.h"
 #include "os/log.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 namespace internal {
 
-LeFixedChannelImpl::LeFixedChannelImpl(Cid cid, LeLink* link, os::Handler* l2cap_handler)
+FixedChannelImpl::FixedChannelImpl(Cid cid, Link* link, os::Handler* l2cap_handler)
     : cid_(cid), device_(link->GetDevice()), link_(link), l2cap_handler_(l2cap_handler) {
   ASSERT_LOG(cid_ >= kFirstFixedChannel && cid_ <= kLastFixedChannel, "Invalid cid: %d", cid_);
   ASSERT(!device_.IsEmpty());
@@ -35,8 +36,8 @@ LeFixedChannelImpl::LeFixedChannelImpl(Cid cid, LeLink* link, os::Handler* l2cap
   ASSERT(l2cap_handler_ != nullptr);
 }
 
-void LeFixedChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler,
-                                                 LeFixedChannel::OnCloseCallback on_close_callback) {
+void FixedChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler,
+                                               FixedChannel::OnCloseCallback on_close_callback) {
   ASSERT_LOG(user_handler_ == nullptr, "OnCloseCallback can only be registered once");
   // If channel is already closed, call the callback immediately without saving it
   if (closed_) {
@@ -47,7 +48,7 @@ void LeFixedChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler,
   on_close_callback_ = std::move(on_close_callback);
 }
 
-void LeFixedChannelImpl::OnClosed(hci::ErrorCode status) {
+void FixedChannelImpl::OnClosed(hci::ErrorCode status) {
   ASSERT_LOG(!closed_, "Device %s Cid 0x%x closed twice, old status 0x%x, new status 0x%x", device_.ToString().c_str(),
              cid_, static_cast<int>(close_reason_), static_cast<int>(status));
   closed_ = true;
@@ -64,7 +65,7 @@ void LeFixedChannelImpl::OnClosed(hci::ErrorCode status) {
   on_close_callback_.Reset();
 }
 
-void LeFixedChannelImpl::Acquire() {
+void FixedChannelImpl::Acquire() {
   ASSERT_LOG(user_handler_ != nullptr, "Must register OnCloseCallback before calling any methods");
   if (closed_) {
     LOG_WARN("%s is already closed", ToString().c_str());
@@ -79,7 +80,7 @@ void LeFixedChannelImpl::Acquire() {
   link_->RefreshRefCount();
 }
 
-void LeFixedChannelImpl::Release() {
+void FixedChannelImpl::Release() {
   ASSERT_LOG(user_handler_ != nullptr, "Must register OnCloseCallback before calling any methods");
   if (closed_) {
     LOG_WARN("%s is already closed", ToString().c_str());
@@ -95,5 +96,6 @@ void LeFixedChannelImpl::Release() {
 }
 
 }  // namespace internal
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 85%
rename from gd/l2cap/internal/le_fixed_channel_impl.h
rename to gd/l2cap/le/internal/fixed_channel_impl.h
index 7fb90ec..60e042a 100644 (file)
 
 #include "common/bidi_queue.h"
 #include "l2cap/cid.h"
-#include "l2cap/le_fixed_channel.h"
+#include "l2cap/le/fixed_channel.h"
 #include "os/handler.h"
 #include "os/log.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 namespace internal {
 
-class LeLink;
+class Link;
 
-class LeFixedChannelImpl {
+class FixedChannelImpl {
  public:
-  LeFixedChannelImpl(Cid cid, LeLink* link, os::Handler* l2cap_handler);
+  FixedChannelImpl(Cid cid, Link* link, os::Handler* l2cap_handler);
 
-  virtual ~LeFixedChannelImpl() = default;
+  virtual ~FixedChannelImpl() = default;
 
   hci::Address GetDevice() const {
     return device_;
   }
 
-  virtual void RegisterOnCloseCallback(os::Handler* user_handler, LeFixedChannel::OnCloseCallback on_close_callback);
+  virtual void RegisterOnCloseCallback(os::Handler* user_handler, FixedChannel::OnCloseCallback on_close_callback);
 
   virtual void Acquire();
 
@@ -71,12 +72,12 @@ class LeFixedChannelImpl {
   // For logging purpose only
   const hci::Address device_;
   // Needed to handle Acquire() and Release()
-  LeLink* link_;
+  Link* link_;
   os::Handler* l2cap_handler_;
 
   // User supported states
   os::Handler* user_handler_ = nullptr;
-  LeFixedChannel::OnCloseCallback on_close_callback_{};
+  FixedChannel::OnCloseCallback on_close_callback_{};
 
   // Internal states
   bool acquired_ = false;
@@ -86,9 +87,10 @@ class LeFixedChannelImpl {
   common::BidiQueue<packet::PacketView<packet::kLittleEndian>, packet::BasePacketBuilder> channel_queue_{
       kChannelQueueSize};
 
-  DISALLOW_COPY_AND_ASSIGN(LeFixedChannelImpl);
+  DISALLOW_COPY_AND_ASSIGN(FixedChannelImpl);
 };
 
 }  // namespace internal
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
  */
 #pragma once
 
-#include "l2cap/internal/le_fixed_channel_impl.h"
+#include "l2cap/le/internal/fixed_channel_impl.h"
 
 #include <gmock/gmock.h>
 
 // Unit test interfaces
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 namespace internal {
 namespace testing {
 
-class MockLeFixedChannelImpl : public LeFixedChannelImpl {
+class MockFixedChannelImpl : public FixedChannelImpl {
  public:
   MOCK_METHOD(void, RegisterOnCloseCallback,
-              (os::Handler * user_handler, LeFixedChannel::OnCloseCallback on_close_callback), (override));
+              (os::Handler * user_handler, FixedChannel::OnCloseCallback on_close_callback), (override));
   MOCK_METHOD(void, Acquire, (), (override));
   MOCK_METHOD(void, Release, (), (override));
   MOCK_METHOD(bool, IsAcquired, (), (override, const));
@@ -37,5 +38,6 @@ class MockLeFixedChannelImpl : public LeFixedChannelImpl {
 
 }  // namespace testing
 }  // namespace internal
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "l2cap/internal/le_fixed_channel_impl.h"
+#include "l2cap/le/internal/fixed_channel_impl.h"
 
 #include "common/testing/bind_test_util.h"
 #include "l2cap/cid.h"
-#include "l2cap/internal/le_link_mock.h"
 #include "l2cap/internal/parameter_provider_mock.h"
+#include "l2cap/le/internal/link_mock.h"
 #include "os/handler.h"
 
 #include <gmock/gmock.h>
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 namespace internal {
 
-using testing::MockLeLink;
-using testing::MockParameterProvider;
+using l2cap::internal::testing::MockParameterProvider;
+using testing::MockLink;
 using ::testing::Return;
 
 class L2capLeFixedChannelImplTest : public ::testing::Test {
@@ -59,19 +60,19 @@ class L2capLeFixedChannelImplTest : public ::testing::Test {
 
 TEST_F(L2capLeFixedChannelImplTest, get_device) {
   MockParameterProvider mock_parameter_provider;
-  MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
-  LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
   EXPECT_EQ(device, fixed_channel_impl.GetDevice());
 }
 
 TEST_F(L2capLeFixedChannelImplTest, close_triggers_callback) {
   MockParameterProvider mock_parameter_provider;
-  MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
-  LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
 
   // Register on close callback
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -89,10 +90,10 @@ TEST_F(L2capLeFixedChannelImplTest, close_triggers_callback) {
 
 TEST_F(L2capLeFixedChannelImplTest, register_callback_after_close_should_call_immediately) {
   MockParameterProvider mock_parameter_provider;
-  MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
-  LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
 
   // Channel closure should do nothing
   fixed_channel_impl.OnClosed(hci::ErrorCode::REMOTE_USER_TERMINATED_CONNECTION);
@@ -110,10 +111,10 @@ TEST_F(L2capLeFixedChannelImplTest, register_callback_after_close_should_call_im
 
 TEST_F(L2capLeFixedChannelImplTest, close_twice_should_fail) {
   MockParameterProvider mock_parameter_provider;
-  MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
-  LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
 
   // Register on close callback
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -134,10 +135,10 @@ TEST_F(L2capLeFixedChannelImplTest, close_twice_should_fail) {
 
 TEST_F(L2capLeFixedChannelImplTest, multiple_registeration_should_fail) {
   MockParameterProvider mock_parameter_provider;
-  MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
-  LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
 
   // Register on close callback
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -154,28 +155,28 @@ TEST_F(L2capLeFixedChannelImplTest, multiple_registeration_should_fail) {
 
 TEST_F(L2capLeFixedChannelImplTest, call_acquire_before_registeration_should_fail) {
   MockParameterProvider mock_parameter_provider;
-  MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
-  LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
   EXPECT_DEATH(fixed_channel_impl.Acquire(), ".*Acquire.*");
 }
 
 TEST_F(L2capLeFixedChannelImplTest, call_release_before_registeration_should_fail) {
   MockParameterProvider mock_parameter_provider;
-  MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
-  LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
   EXPECT_DEATH(fixed_channel_impl.Release(), ".*Release.*");
 }
 
 TEST_F(L2capLeFixedChannelImplTest, test_acquire_release_channel) {
   MockParameterProvider mock_parameter_provider;
-  MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
-  LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
 
   // Register on close callback
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -200,10 +201,10 @@ TEST_F(L2capLeFixedChannelImplTest, test_acquire_release_channel) {
 
 TEST_F(L2capLeFixedChannelImplTest, test_acquire_after_close) {
   MockParameterProvider mock_parameter_provider;
-  MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
-  LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+  FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
 
   // Register on close callback
   auto user_handler = std::make_unique<os::Handler>(thread_);
@@ -225,5 +226,6 @@ TEST_F(L2capLeFixedChannelImplTest, test_acquire_after_close) {
 }
 
 }  // namespace internal
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
 
 #pragma once
 
-#include "common/bind.h"
-
-#include "l2cap/classic_dynamic_channel.h"
-#include "l2cap/classic_dynamic_channel_manager.h"
-#include "l2cap/classic_dynamic_channel_service.h"
+#include "l2cap/le/fixed_channel.h"
+#include "l2cap/le/fixed_channel_manager.h"
+#include "l2cap/le/fixed_channel_service.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 namespace internal {
-class ClassicDynamicChannelServiceImpl {
+
+class FixedChannelServiceImpl {
  public:
-  virtual ~ClassicDynamicChannelServiceImpl() = default;
+  virtual ~FixedChannelServiceImpl() = default;
 
   struct PendingRegistration {
     os::Handler* user_handler_ = nullptr;
-    ClassicDynamicChannelManager::OnRegistrationCompleteCallback on_registration_complete_callback_;
-    ClassicDynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
+    FixedChannelManager::OnRegistrationCompleteCallback on_registration_complete_callback_;
+    FixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
   };
 
-  virtual void NotifyChannelCreation(std::unique_ptr<ClassicDynamicChannel> channel) {
+  virtual void NotifyChannelCreation(std::unique_ptr<FixedChannel> channel) {
     user_handler_->Post(common::BindOnce(on_connection_open_callback_, std::move(channel)));
   }
 
-  friend class ClassicDynamicChannelServiceManagerImpl;
+  friend class FixedChannelServiceManagerImpl;
 
  protected:
   // protected access for mocking
-  ClassicDynamicChannelServiceImpl(os::Handler* user_handler,
-                                   ClassicDynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback)
+  FixedChannelServiceImpl(os::Handler* user_handler,
+                          FixedChannelManager::OnConnectionOpenCallback on_connection_open_callback)
       : user_handler_(user_handler), on_connection_open_callback_(std::move(on_connection_open_callback)) {}
 
  private:
   os::Handler* user_handler_ = nullptr;
-  ClassicDynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
+  FixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
 };
 
 }  // namespace internal
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
  */
 #pragma once
 
-#include "l2cap/internal/le_fixed_channel_impl.h"
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
+#include "l2cap/le/internal/fixed_channel_impl.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
 
 #include <gmock/gmock.h>
 
 // Unit test interfaces
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 namespace internal {
 namespace testing {
 
-class MockLeFixedChannelServiceImpl : public LeFixedChannelServiceImpl {
+class MockFixedChannelServiceImpl : public FixedChannelServiceImpl {
  public:
-  MockLeFixedChannelServiceImpl()
-      : LeFixedChannelServiceImpl(nullptr, LeFixedChannelManager::OnConnectionOpenCallback()) {}
-  MOCK_METHOD(void, NotifyChannelCreation, (std::unique_ptr<LeFixedChannel> channel), (override));
+  MockFixedChannelServiceImpl() : FixedChannelServiceImpl(nullptr, FixedChannelManager::OnConnectionOpenCallback()) {}
+  MOCK_METHOD(void, NotifyChannelCreation, (std::unique_ptr<FixedChannel> channel), (override));
 };
 
 }  // namespace testing
 }  // namespace internal
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
diff --git a/gd/l2cap/le/internal/fixed_channel_service_manager_impl.cc b/gd/l2cap/le/internal/fixed_channel_service_manager_impl.cc
new file mode 100644 (file)
index 0000000..3a2de00
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2019 The Android Open Source Project
+ *
+ * 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 "l2cap/le/internal/fixed_channel_service_manager_impl.h"
+
+#include "common/bind.h"
+#include "l2cap/cid.h"
+#include "l2cap/le/internal/fixed_channel_service_impl.h"
+#include "os/log.h"
+
+namespace bluetooth {
+namespace l2cap {
+namespace le {
+namespace internal {
+
+void FixedChannelServiceManagerImpl::Register(Cid cid,
+                                              FixedChannelServiceImpl::PendingRegistration pending_registration) {
+  if (cid < kFirstFixedChannel || cid > kLastFixedChannel || cid == kLeSignallingCid) {
+    std::unique_ptr<FixedChannelService> invalid_service(new FixedChannelService());
+    pending_registration.user_handler_->Post(
+        common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
+                         FixedChannelManager::RegistrationResult::FAIL_INVALID_SERVICE, std::move(invalid_service)));
+  } else if (IsServiceRegistered(cid)) {
+    std::unique_ptr<FixedChannelService> invalid_service(new FixedChannelService());
+    pending_registration.user_handler_->Post(
+        common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
+                         FixedChannelManager::RegistrationResult::FAIL_DUPLICATE_SERVICE, std::move(invalid_service)));
+  } else {
+    service_map_.try_emplace(cid,
+                             FixedChannelServiceImpl(pending_registration.user_handler_,
+                                                     std::move(pending_registration.on_connection_open_callback_)));
+    std::unique_ptr<FixedChannelService> user_service(new FixedChannelService(cid, this, l2cap_layer_handler_));
+    pending_registration.user_handler_->Post(
+        common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
+                         FixedChannelManager::RegistrationResult::SUCCESS, std::move(user_service)));
+  }
+}
+
+void FixedChannelServiceManagerImpl::Unregister(Cid cid, FixedChannelService::OnUnregisteredCallback callback,
+                                                os::Handler* handler) {
+  if (IsServiceRegistered(cid)) {
+    service_map_.erase(cid);
+    handler->Post(std::move(callback));
+  } else {
+    LOG_ERROR("service not registered cid:%d", cid);
+  }
+}
+
+bool FixedChannelServiceManagerImpl::IsServiceRegistered(Cid cid) const {
+  return service_map_.find(cid) != service_map_.end();
+}
+
+FixedChannelServiceImpl* FixedChannelServiceManagerImpl::GetService(Cid cid) {
+  ASSERT(IsServiceRegistered(cid));
+  return &service_map_.find(cid)->second;
+}
+
+std::vector<std::pair<Cid, FixedChannelServiceImpl*>> FixedChannelServiceManagerImpl::GetRegisteredServices() {
+  std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
+  for (auto& elem : service_map_) {
+    results.emplace_back(elem.first, &elem.second);
+  }
+  return results;
+}
+
+}  // namespace internal
+}  // namespace le
+}  // namespace l2cap
+}  // namespace bluetooth
 
 #include <unordered_map>
 
-#include "l2cap/classic_dynamic_channel_service.h"
-#include "l2cap/internal/classic_dynamic_channel_service_impl.h"
-#include "l2cap/psm.h"
+#include "l2cap/cid.h"
+#include "l2cap/le/fixed_channel_service.h"
+#include "l2cap/le/internal/fixed_channel_service_impl.h"
 #include "os/handler.h"
-#include "os/log.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 namespace internal {
 
-class ClassicDynamicChannelServiceManagerImpl {
+class FixedChannelServiceManagerImpl {
  public:
-  explicit ClassicDynamicChannelServiceManagerImpl(os::Handler* l2cap_layer_handler)
+  explicit FixedChannelServiceManagerImpl(os::Handler* l2cap_layer_handler)
       : l2cap_layer_handler_(l2cap_layer_handler) {}
+  virtual ~FixedChannelServiceManagerImpl() = default;
 
-  virtual ~ClassicDynamicChannelServiceManagerImpl() = default;
-  //
   // All APIs must be invoked in L2CAP layer handler
-  //
-  virtual void Register(Psm psm, ClassicDynamicChannelServiceImpl::PendingRegistration pending_registration);
-  virtual void Unregister(Psm psm, ClassicDynamicChannelService::OnUnregisteredCallback callback, os::Handler* handler);
-  virtual bool IsServiceRegistered(Psm psm) const;
-  virtual ClassicDynamicChannelServiceImpl* GetService(Psm psm);
-
-  virtual std::vector<std::pair<Psm, ClassicDynamicChannelServiceImpl*>> GetRegisteredServices();
-  //
+
+  virtual void Register(Cid cid, FixedChannelServiceImpl::PendingRegistration pending_registration);
+  virtual void Unregister(Cid cid, FixedChannelService::OnUnregisteredCallback callback, os::Handler* handler);
+  virtual bool IsServiceRegistered(Cid cid) const;
+  virtual FixedChannelServiceImpl* GetService(Cid cid);
+  virtual std::vector<std::pair<Cid, FixedChannelServiceImpl*>> GetRegisteredServices();
+
  private:
   os::Handler* l2cap_layer_handler_ = nullptr;
-  std::unordered_map<Psm, ClassicDynamicChannelServiceImpl> service_map_;
+  std::unordered_map<Cid, FixedChannelServiceImpl> service_map_;
 };
 }  // namespace internal
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
  */
 #pragma once
 
-#include "l2cap/internal/le_fixed_channel_impl.h"
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
+#include "l2cap/le/internal/fixed_channel_impl.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
 
 #include <gmock/gmock.h>
 
 // Unit test interfaces
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 namespace internal {
 namespace testing {
 
-class MockLeFixedChannelServiceManagerImpl : public LeFixedChannelServiceManagerImpl {
+class MockFixedChannelServiceManagerImpl : public FixedChannelServiceManagerImpl {
  public:
-  MockLeFixedChannelServiceManagerImpl() : LeFixedChannelServiceManagerImpl(nullptr) {}
-  MOCK_METHOD(void, Register, (Cid cid, LeFixedChannelServiceImpl::PendingRegistration pending_registration),
-              (override));
-  MOCK_METHOD(void, Unregister, (Cid cid, LeFixedChannelService::OnUnregisteredCallback callback, os::Handler* handler),
+  MockFixedChannelServiceManagerImpl() : FixedChannelServiceManagerImpl(nullptr) {}
+  MOCK_METHOD(void, Register, (Cid cid, FixedChannelServiceImpl::PendingRegistration pending_registration), (override));
+  MOCK_METHOD(void, Unregister, (Cid cid, FixedChannelService::OnUnregisteredCallback callback, os::Handler* handler),
               (override));
   MOCK_METHOD(bool, IsServiceRegistered, (Cid cid), (const, override));
-  MOCK_METHOD(LeFixedChannelServiceImpl*, GetService, (Cid cid), (override));
-  MOCK_METHOD((std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>>), GetRegisteredServices, (), (override));
+  MOCK_METHOD(FixedChannelServiceImpl*, GetService, (Cid cid), (override));
+  MOCK_METHOD((std::vector<std::pair<Cid, FixedChannelServiceImpl*>>), GetRegisteredServices, (), (override));
 };
 
 }  // namespace testing
 }  // namespace internal
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
  * limitations under the License.
  */
 
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
 
 #include <future>
 
 #include "common/bind.h"
 #include "l2cap/cid.h"
-#include "l2cap/le_fixed_channel_manager.h"
-#include "l2cap/le_fixed_channel_service.h"
+#include "l2cap/le/fixed_channel_manager.h"
+#include "l2cap/le/fixed_channel_service.h"
 #include "os/handler.h"
 #include "os/thread.h"
 
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 namespace internal {
 
-class L2capServiceManagerTest : public ::testing::Test {
+class L2capLeServiceManagerTest : public ::testing::Test {
  public:
-  ~L2capServiceManagerTest() override = default;
+  ~L2capLeServiceManagerTest() override = default;
 
-  void OnServiceRegistered(bool expect_success, LeFixedChannelManager::RegistrationResult result,
-                           std::unique_ptr<LeFixedChannelService> user_service) {
-    EXPECT_EQ(result == LeFixedChannelManager::RegistrationResult::SUCCESS, expect_success);
+  void OnServiceRegistered(bool expect_success, FixedChannelManager::RegistrationResult result,
+                           std::unique_ptr<FixedChannelService> user_service) {
+    EXPECT_EQ(result == FixedChannelManager::RegistrationResult::SUCCESS, expect_success);
     service_registered_ = expect_success;
   }
 
  protected:
   void SetUp() override {
-    manager_ = new LeFixedChannelServiceManagerImpl{nullptr};
+    manager_ = new FixedChannelServiceManagerImpl{nullptr};
     thread_ = new os::Thread("test_thread", os::Thread::Priority::NORMAL);
     user_handler_ = new os::Handler(thread_);
   }
@@ -62,18 +63,18 @@ class L2capServiceManagerTest : public ::testing::Test {
     future.wait_for(std::chrono::milliseconds(3));
   }
 
-  LeFixedChannelServiceManagerImpl* manager_ = nullptr;
+  FixedChannelServiceManagerImpl* manager_ = nullptr;
   os::Thread* thread_ = nullptr;
   os::Handler* user_handler_ = nullptr;
 
   bool service_registered_ = false;
 };
 
-TEST_F(L2capServiceManagerTest, register_and_unregister_le_fixed_channel) {
-  LeFixedChannelServiceImpl::PendingRegistration pending_registration{
+TEST_F(L2capLeServiceManagerTest, register_and_unregister_le_fixed_channel) {
+  FixedChannelServiceImpl::PendingRegistration pending_registration{
       .user_handler_ = user_handler_,
       .on_registration_complete_callback_ =
-          common::BindOnce(&L2capServiceManagerTest::OnServiceRegistered, common::Unretained(this), true)};
+          common::BindOnce(&L2capLeServiceManagerTest::OnServiceRegistered, common::Unretained(this), true)};
   Cid cid = kSmpBrCid;
   EXPECT_FALSE(manager_->IsServiceRegistered(cid));
   manager_->Register(cid, std::move(pending_registration));
@@ -84,11 +85,11 @@ TEST_F(L2capServiceManagerTest, register_and_unregister_le_fixed_channel) {
   EXPECT_FALSE(manager_->IsServiceRegistered(cid));
 }
 
-TEST_F(L2capServiceManagerTest, register_le_fixed_channel_bad_cid) {
-  LeFixedChannelServiceImpl::PendingRegistration pending_registration{
+TEST_F(L2capLeServiceManagerTest, register_le_fixed_channel_bad_cid) {
+  FixedChannelServiceImpl::PendingRegistration pending_registration{
       .user_handler_ = user_handler_,
       .on_registration_complete_callback_ =
-          common::BindOnce(&L2capServiceManagerTest::OnServiceRegistered, common::Unretained(this), false)};
+          common::BindOnce(&L2capLeServiceManagerTest::OnServiceRegistered, common::Unretained(this), false)};
   Cid cid = 0x1000;
   EXPECT_FALSE(manager_->IsServiceRegistered(cid));
   manager_->Register(cid, std::move(pending_registration));
@@ -98,5 +99,6 @@ TEST_F(L2capServiceManagerTest, register_le_fixed_channel_bad_cid) {
 }
 
 }  // namespace internal
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 75%
rename from gd/l2cap/internal/le_link.h
rename to gd/l2cap/le/internal/link.h
index 1fefe48..1ada89b 100644 (file)
 
 #include "hci/acl_manager.h"
 #include "l2cap/internal/fixed_channel_allocator.h"
-#include "l2cap/internal/le_fixed_channel_impl.h"
 #include "l2cap/internal/parameter_provider.h"
 #include "l2cap/internal/scheduler.h"
+#include "l2cap/le/internal/fixed_channel_impl.h"
 #include "os/alarm.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 namespace internal {
 
-class LeLink {
+class Link {
  public:
-  LeLink(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_connection,
-         std::unique_ptr<Scheduler> scheduler, ParameterProvider* parameter_provider)
+  Link(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_connection,
+       std::unique_ptr<l2cap::internal::Scheduler> scheduler, l2cap::internal::ParameterProvider* parameter_provider)
       : l2cap_handler_(l2cap_handler), acl_connection_(std::move(acl_connection)), scheduler_(std::move(scheduler)),
         parameter_provider_(parameter_provider) {
     ASSERT(l2cap_handler_ != nullptr);
     ASSERT(acl_connection_ != nullptr);
     ASSERT(scheduler_ != nullptr);
     ASSERT(parameter_provider_ != nullptr);
-    acl_connection_->RegisterDisconnectCallback(common::BindOnce(&LeLink::OnAclDisconnected, common::Unretained(this)),
+    acl_connection_->RegisterDisconnectCallback(common::BindOnce(&Link::OnAclDisconnected, common::Unretained(this)),
                                                 l2cap_handler_);
-    link_idle_disconnect_alarm_.Schedule(common::BindOnce(&LeLink::Disconnect, common::Unretained(this)),
+    link_idle_disconnect_alarm_.Schedule(common::BindOnce(&Link::Disconnect, common::Unretained(this)),
                                          parameter_provider_->GetLeLinkIdleDisconnectTimeout());
   }
 
-  virtual ~LeLink() = default;
+  virtual ~Link() = default;
 
   inline virtual hci::Address GetDevice() {
     return acl_connection_->GetAddress();
@@ -62,9 +63,9 @@ class LeLink {
     acl_connection_->Disconnect(hci::DisconnectReason::REMOTE_USER_TERMINATED_CONNECTION);
   }
 
-  // LeFixedChannel methods
+  // FixedChannel methods
 
-  virtual std::shared_ptr<LeFixedChannelImpl> AllocateFixedChannel(Cid cid, SecurityPolicy security_policy) {
+  virtual std::shared_ptr<FixedChannelImpl> AllocateFixedChannel(Cid cid, SecurityPolicy security_policy) {
     auto channel = fixed_channel_allocator_.AllocateChannel(cid, security_policy);
     scheduler_->AttachChannel(cid, channel->GetQueueDownEnd());
     return channel;
@@ -82,21 +83,22 @@ class LeLink {
     if (ref_count > 0) {
       link_idle_disconnect_alarm_.Cancel();
     } else {
-      link_idle_disconnect_alarm_.Schedule(common::BindOnce(&LeLink::Disconnect, common::Unretained(this)),
+      link_idle_disconnect_alarm_.Schedule(common::BindOnce(&Link::Disconnect, common::Unretained(this)),
                                            parameter_provider_->GetLeLinkIdleDisconnectTimeout());
     }
   }
 
  private:
   os::Handler* l2cap_handler_;
-  FixedChannelAllocator<LeFixedChannelImpl, LeLink> fixed_channel_allocator_{this, l2cap_handler_};
+  l2cap::internal::FixedChannelAllocator<FixedChannelImpl, Link> fixed_channel_allocator_{this, l2cap_handler_};
   std::unique_ptr<hci::AclConnection> acl_connection_;
-  std::unique_ptr<Scheduler> scheduler_;
-  ParameterProvider* parameter_provider_;
+  std::unique_ptr<l2cap::internal::Scheduler> scheduler_;
+  l2cap::internal::ParameterProvider* parameter_provider_;
   os::Alarm link_idle_disconnect_alarm_{l2cap_handler_};
-  DISALLOW_COPY_AND_ASSIGN(LeLink);
+  DISALLOW_COPY_AND_ASSIGN(Link);
 };
 
 }  // namespace internal
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 75%
rename from gd/l2cap/internal/le_link_manager.cc
rename to gd/l2cap/le/internal/link_manager.cc
index 8768f20..785888e 100644 (file)
 
 #include "hci/acl_manager.h"
 #include "hci/address.h"
-#include "l2cap/internal/le_link.h"
 #include "l2cap/internal/scheduler_fifo.h"
-#include "l2cap/l2cap_layer.h"
+#include "l2cap/le/internal/link.h"
 #include "os/handler.h"
 #include "os/log.h"
 
-#include "l2cap/internal/le_link_manager.h"
+#include "l2cap/le/internal/link_manager.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 namespace internal {
 
-void LeLinkManager::ConnectFixedChannelServices(hci::Address device, hci::AddressType address_type,
-                                                PendingFixedChannelConnection pending_fixed_channel_connection) {
+void LinkManager::ConnectFixedChannelServices(hci::Address device, hci::AddressType address_type,
+                                              PendingFixedChannelConnection pending_fixed_channel_connection) {
   // Check if there is any service registered
   auto fixed_channel_services = service_manager_->GetRegisteredServices();
   if (fixed_channel_services.empty()) {
     // If so, return error
     pending_fixed_channel_connection.handler_->Post(common::BindOnce(
         std::move(pending_fixed_channel_connection.on_fail_callback_),
-        LeFixedChannelManager::ConnectionResult{
-            .connection_result_code = LeFixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED}));
+        FixedChannelManager::ConnectionResult{
+            .connection_result_code = FixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED}));
     return;
   }
   // Otherwise, check if device has an ACL connection
@@ -56,15 +56,15 @@ void LeLinkManager::ConnectFixedChannelServices(hci::Address device, hci::Addres
       // Allocate channel for newly registered fixed channels
       auto fixed_channel_impl = link->AllocateFixedChannel(fixed_channel_service.first, SecurityPolicy());
       fixed_channel_service.second->NotifyChannelCreation(
-          std::make_unique<LeFixedChannel>(fixed_channel_impl, l2cap_handler_));
+          std::make_unique<FixedChannel>(fixed_channel_impl, l2cap_handler_));
       num_new_channels++;
     }
     // Declare connection failure if no new channels are created
     if (num_new_channels == 0) {
       pending_fixed_channel_connection.handler_->Post(common::BindOnce(
           std::move(pending_fixed_channel_connection.on_fail_callback_),
-          LeFixedChannelManager::ConnectionResult{
-              .connection_result_code = LeFixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL}));
+          FixedChannelManager::ConnectionResult{
+              .connection_result_code = FixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL}));
     }
     // No need to create ACL connection, return without saving any pending connections
     return;
@@ -82,28 +82,28 @@ void LeLinkManager::ConnectFixedChannelServices(hci::Address device, hci::Addres
   acl_manager_->CreateLeConnection(device, address_type);
 }
 
-LeLink* LeLinkManager::GetLink(const hci::Address device) {
+Link* LinkManager::GetLink(const hci::Address device) {
   if (links_.find(device) == links_.end()) {
     return nullptr;
   }
   return &links_.find(device)->second;
 }
 
-void LeLinkManager::OnLeConnectSuccess(std::unique_ptr<hci::AclConnection> acl_connection) {
+void LinkManager::OnLeConnectSuccess(std::unique_ptr<hci::AclConnection> acl_connection) {
   // Same link should not be connected twice
   hci::Address device = acl_connection->GetAddress();
   ASSERT_LOG(GetLink(device) == nullptr, "%s is connected twice without disconnection",
              acl_connection->GetAddress().ToString().c_str());
   auto* link_queue_up_end = acl_connection->GetAclQueueEnd();
   links_.try_emplace(device, l2cap_handler_, std::move(acl_connection),
-                     std::make_unique<Fifo>(link_queue_up_end, l2cap_handler_), parameter_provider_);
+                     std::make_unique<l2cap::internal::Fifo>(link_queue_up_end, l2cap_handler_), parameter_provider_);
   auto* link = GetLink(device);
   // Allocate and distribute channels for all registered fixed channel services
   auto fixed_channel_services = service_manager_->GetRegisteredServices();
   for (auto& fixed_channel_service : fixed_channel_services) {
     auto fixed_channel_impl = link->AllocateFixedChannel(fixed_channel_service.first, SecurityPolicy());
     fixed_channel_service.second->NotifyChannelCreation(
-        std::make_unique<LeFixedChannel>(fixed_channel_impl, l2cap_handler_));
+        std::make_unique<FixedChannel>(fixed_channel_impl, l2cap_handler_));
   }
   // Remove device from pending links list, if any
   auto pending_link = pending_links_.find(device);
@@ -115,7 +115,7 @@ void LeLinkManager::OnLeConnectSuccess(std::unique_ptr<hci::AclConnection> acl_c
   pending_links_.erase(pending_link);
 }
 
-void LeLinkManager::OnLeConnectFail(hci::Address device, hci::AddressType address_type, hci::ErrorCode reason) {
+void LinkManager::OnLeConnectFail(hci::Address device, hci::AddressType address_type, hci::ErrorCode reason) {
   // Notify all pending links for this device
   auto pending_link = pending_links_.find(device);
   if (pending_link == pending_links_.end()) {
@@ -124,17 +124,16 @@ void LeLinkManager::OnLeConnectFail(hci::Address device, hci::AddressType addres
     return;
   }
   for (auto& pending_fixed_channel_connection : pending_link->second.pending_fixed_channel_connections_) {
-    pending_fixed_channel_connection.handler_->Post(
-        common::BindOnce(std::move(pending_fixed_channel_connection.on_fail_callback_),
-                         LeFixedChannelManager::ConnectionResult{
-                             .connection_result_code = LeFixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR,
-                             .hci_error = reason}));
+    pending_fixed_channel_connection.handler_->Post(common::BindOnce(
+        std::move(pending_fixed_channel_connection.on_fail_callback_),
+        FixedChannelManager::ConnectionResult{
+            .connection_result_code = FixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR, .hci_error = reason}));
   }
   // Remove entry in pending link list
   pending_links_.erase(pending_link);
 }
 
-void LeLinkManager::OnDisconnect(hci::Address device, hci::ErrorCode status) {
+void LinkManager::OnDisconnect(hci::Address device, hci::ErrorCode status) {
   auto* link = GetLink(device);
   ASSERT_LOG(link != nullptr, "Device %s is disconnected with reason 0x%x, but not in local database",
              device.ToString().c_str(), static_cast<uint8_t>(status));
@@ -143,5 +142,6 @@ void LeLinkManager::OnDisconnect(hci::Address device, hci::ErrorCode status) {
 }
 
 }  // namespace internal
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 72%
rename from gd/l2cap/internal/le_link_manager.h
rename to gd/l2cap/le/internal/link_manager.h
index 5b8a881..ee13c57 100644 (file)
 
 #include "os/handler.h"
 
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
-#include "l2cap/internal/le_link.h"
 #include "l2cap/internal/parameter_provider.h"
 #include "l2cap/internal/scheduler.h"
-#include "l2cap/le_fixed_channel_manager.h"
+#include "l2cap/le/fixed_channel_manager.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
+#include "l2cap/le/internal/link.h"
 
 #include "hci/acl_manager.h"
 #include "hci/address.h"
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 namespace internal {
 
-class LeLinkManager : public hci::LeConnectionCallbacks {
+class LinkManager : public hci::LeConnectionCallbacks {
  public:
-  LeLinkManager(os::Handler* l2cap_handler, hci::AclManager* acl_manager,
-                LeFixedChannelServiceManagerImpl* service_manager, ParameterProvider* parameter_provider)
+  LinkManager(os::Handler* l2cap_handler, hci::AclManager* acl_manager, FixedChannelServiceManagerImpl* service_manager,
+              l2cap::internal::ParameterProvider* parameter_provider)
       : l2cap_handler_(l2cap_handler), acl_manager_(acl_manager), service_manager_(service_manager),
         parameter_provider_(parameter_provider) {
     acl_manager_->RegisterLeCallbacks(this, l2cap_handler_);
@@ -45,7 +46,7 @@ class LeLinkManager : public hci::LeConnectionCallbacks {
 
   struct PendingFixedChannelConnection {
     os::Handler* handler_;
-    LeFixedChannelManager::OnConnectionFailureCallback on_fail_callback_;
+    FixedChannelManager::OnConnectionFailureCallback on_fail_callback_;
   };
 
   struct PendingLink {
@@ -54,12 +55,12 @@ class LeLinkManager : public hci::LeConnectionCallbacks {
 
   // ACL methods
 
-  LeLink* GetLink(hci::Address device);
+  Link* GetLink(hci::Address device);
   void OnLeConnectSuccess(std::unique_ptr<hci::AclConnection> acl_connection) override;
   void OnLeConnectFail(hci::Address device, hci::AddressType address_type, hci::ErrorCode reason) override;
   void OnDisconnect(hci::Address device, hci::ErrorCode status);
 
-  // LeFixedChannelManager methods
+  // FixedChannelManager methods
 
   void ConnectFixedChannelServices(hci::Address device, hci::AddressType address_type,
                                    PendingFixedChannelConnection pending_fixed_channel_connection);
@@ -68,15 +69,16 @@ class LeLinkManager : public hci::LeConnectionCallbacks {
   // Dependencies
   os::Handler* l2cap_handler_;
   hci::AclManager* acl_manager_;
-  LeFixedChannelServiceManagerImpl* service_manager_;
-  ParameterProvider* parameter_provider_;
+  FixedChannelServiceManagerImpl* service_manager_;
+  l2cap::internal::ParameterProvider* parameter_provider_;
 
   // Internal states
   std::unordered_map<hci::Address, PendingLink> pending_links_;
-  std::unordered_map<hci::Address, LeLink> links_;
-  DISALLOW_COPY_AND_ASSIGN(LeLinkManager);
+  std::unordered_map<hci::Address, Link> links_;
+  DISALLOW_COPY_AND_ASSIGN(LinkManager);
 };
 
 }  // namespace internal
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 78%
rename from gd/l2cap/internal/le_link_manager_test.cc
rename to gd/l2cap/le/internal/link_manager_test.cc
index a0808ff..b0f4004 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "l2cap/internal/le_link_manager.h"
+#include "l2cap/le/internal/link_manager.h"
 
 #include <future>
 #include <thread>
 #include "hci/acl_manager_mock.h"
 #include "hci/address.h"
 #include "l2cap/cid.h"
-#include "l2cap/internal/le_fixed_channel_service_impl_mock.h"
-#include "l2cap/internal/le_fixed_channel_service_manager_impl_mock.h"
 #include "l2cap/internal/parameter_provider_mock.h"
-#include "l2cap/le_fixed_channel_manager.h"
+#include "l2cap/le/fixed_channel_manager.h"
+#include "l2cap/le/internal/fixed_channel_service_impl_mock.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl_mock.h"
 #include "os/handler.h"
 #include "os/thread.h"
 
 
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 namespace internal {
 
 using hci::testing::MockAclConnection;
 using hci::testing::MockAclManager;
+using l2cap::internal::testing::MockParameterProvider;
 using ::testing::_;  // Matcher to any value
 using ::testing::ByMove;
 using ::testing::DoAll;
-using testing::MockLeFixedChannelServiceImpl;
-using testing::MockLeFixedChannelServiceManagerImpl;
-using testing::MockParameterProvider;
+using testing::MockFixedChannelServiceImpl;
+using testing::MockFixedChannelServiceManagerImpl;
 using ::testing::Return;
 using ::testing::SaveArg;
 
@@ -83,7 +84,7 @@ class L2capLeLinkManagerTest : public ::testing::Test {
 };
 
 TEST_F(L2capLeLinkManagerTest, connect_fixed_channel_service_without_acl) {
-  MockLeFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
+  MockFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
   MockAclManager mock_acl_manager;
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   hci::AddressType address_type = hci::AddressType::RANDOM_DEVICE_ADDRESS;
@@ -94,23 +95,23 @@ TEST_F(L2capLeLinkManagerTest, connect_fixed_channel_service_without_acl) {
   os::Handler* hci_callback_handler = nullptr;
   EXPECT_CALL(mock_acl_manager, RegisterLeCallbacks(_, _))
       .WillOnce(DoAll(SaveArg<0>(&hci_le_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
-  LeLinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
-                                mock_parameter_provider_);
+  LinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
+                              mock_parameter_provider_);
   EXPECT_EQ(hci_le_connection_callbacks, &le_link_manager);
   EXPECT_EQ(hci_callback_handler, l2cap_handler_);
 
   // Register fake services
-  MockLeFixedChannelServiceImpl mock_service_1, mock_service_2;
-  std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> results;
+  MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+  std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
   results.emplace_back(kSmpBrCid, &mock_service_1);
   results.emplace_back(kConnectionlessCid, &mock_service_2);
   EXPECT_CALL(mock_le_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
 
   // Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
   EXPECT_CALL(mock_acl_manager, CreateLeConnection(device, address_type)).Times(1);
-  LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
       .handler_ = user_handler.get(),
-      .on_fail_callback_ = common::BindOnce([](LeFixedChannelManager::ConnectionResult result) { FAIL(); })};
+      .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
   le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection));
 
   // Step 3: ACL connection success event should trigger channel creation for all registered services
@@ -119,11 +120,11 @@ TEST_F(L2capLeLinkManagerTest, connect_fixed_channel_service_without_acl) {
   hci::AclConnection::Queue link_queue{10};
   EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
   EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
-  std::unique_ptr<LeFixedChannel> channel_1, channel_2;
-  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<LeFixedChannel> channel) {
+  std::unique_ptr<FixedChannel> channel_1, channel_2;
+  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
     channel_1 = std::move(channel);
   });
-  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<LeFixedChannel> channel) {
+  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
     channel_2 = std::move(channel);
   });
   hci_callback_handler->Post(common::BindOnce(&hci::LeConnectionCallbacks::OnLeConnectSuccess,
@@ -134,25 +135,25 @@ TEST_F(L2capLeLinkManagerTest, connect_fixed_channel_service_without_acl) {
   EXPECT_NE(channel_2, nullptr);
 
   // Step 4: Calling ConnectServices() to the same device will no trigger another connection attempt
-  LeFixedChannelManager::ConnectionResult my_result;
-  LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_2{
+  FixedChannelManager::ConnectionResult my_result;
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_2{
       .handler_ = user_handler.get(),
       .on_fail_callback_ = common::testing::BindLambdaForTesting(
-          [&my_result](LeFixedChannelManager::ConnectionResult result) { my_result = result; })};
+          [&my_result](FixedChannelManager::ConnectionResult result) { my_result = result; })};
   le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection_2));
   SyncHandler(user_handler.get());
   EXPECT_EQ(my_result.connection_result_code,
-            LeFixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL);
+            FixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL);
 
   // Step 5: Register new service will cause new channels to be created during ConnectServices()
-  MockLeFixedChannelServiceImpl mock_service_3;
+  MockFixedChannelServiceImpl mock_service_3;
   results.emplace_back(kSmpBrCid + 1, &mock_service_3);
   EXPECT_CALL(mock_le_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
-  LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_3{
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_3{
       .handler_ = user_handler.get(),
-      .on_fail_callback_ = common::BindOnce([](LeFixedChannelManager::ConnectionResult result) { FAIL(); })};
-  std::unique_ptr<LeFixedChannel> channel_3;
-  EXPECT_CALL(mock_service_3, NotifyChannelCreation(_)).WillOnce([&channel_3](std::unique_ptr<LeFixedChannel> channel) {
+      .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
+  std::unique_ptr<FixedChannel> channel_3;
+  EXPECT_CALL(mock_service_3, NotifyChannelCreation(_)).WillOnce([&channel_3](std::unique_ptr<FixedChannel> channel) {
     channel_3 = std::move(channel);
   });
   le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection_3));
@@ -164,7 +165,7 @@ TEST_F(L2capLeLinkManagerTest, connect_fixed_channel_service_without_acl) {
 }
 
 TEST_F(L2capLeLinkManagerTest, connect_fixed_channel_service_without_acl_with_no_service) {
-  MockLeFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
+  MockFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
   MockAclManager mock_acl_manager;
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   hci::AddressType address_type = hci::AddressType::PUBLIC_DEVICE_ADDRESS;
@@ -175,31 +176,31 @@ TEST_F(L2capLeLinkManagerTest, connect_fixed_channel_service_without_acl_with_no
   os::Handler* hci_callback_handler = nullptr;
   EXPECT_CALL(mock_acl_manager, RegisterLeCallbacks(_, _))
       .WillOnce(DoAll(SaveArg<0>(&hci_le_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
-  LeLinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
-                                mock_parameter_provider_);
+  LinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
+                              mock_parameter_provider_);
   EXPECT_EQ(hci_le_connection_callbacks, &le_link_manager);
   EXPECT_EQ(hci_callback_handler, l2cap_handler_);
 
   // Make sure no service is registered
-  std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> results;
+  std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
   EXPECT_CALL(mock_le_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
 
   // Step 2: Connect to fixed channel without any service registered will result in failure
   EXPECT_CALL(mock_acl_manager, CreateLeConnection(device, address_type)).Times(0);
-  LeFixedChannelManager::ConnectionResult my_result;
-  LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+  FixedChannelManager::ConnectionResult my_result;
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
       .handler_ = user_handler.get(),
       .on_fail_callback_ = common::testing::BindLambdaForTesting(
-          [&my_result](LeFixedChannelManager::ConnectionResult result) { my_result = result; })};
+          [&my_result](FixedChannelManager::ConnectionResult result) { my_result = result; })};
   le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection));
   SyncHandler(user_handler.get());
-  EXPECT_EQ(my_result.connection_result_code, LeFixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED);
+  EXPECT_EQ(my_result.connection_result_code, FixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED);
 
   user_handler->Clear();
 }
 
 TEST_F(L2capLeLinkManagerTest, connect_fixed_channel_service_without_acl_with_hci_failure) {
-  MockLeFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
+  MockFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
   MockAclManager mock_acl_manager;
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   hci::AddressType address_type = hci::AddressType::RANDOM_DEVICE_ADDRESS;
@@ -210,24 +211,24 @@ TEST_F(L2capLeLinkManagerTest, connect_fixed_channel_service_without_acl_with_hc
   os::Handler* hci_callback_handler = nullptr;
   EXPECT_CALL(mock_acl_manager, RegisterLeCallbacks(_, _))
       .WillOnce(DoAll(SaveArg<0>(&hci_le_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
-  LeLinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
-                                mock_parameter_provider_);
+  LinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
+                              mock_parameter_provider_);
   EXPECT_EQ(hci_le_connection_callbacks, &le_link_manager);
   EXPECT_EQ(hci_callback_handler, l2cap_handler_);
 
   // Register fake services
-  MockLeFixedChannelServiceImpl mock_service_1;
-  std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> results;
+  MockFixedChannelServiceImpl mock_service_1;
+  std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
   results.emplace_back(kSmpBrCid, &mock_service_1);
   EXPECT_CALL(mock_le_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
 
   // Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
   EXPECT_CALL(mock_acl_manager, CreateLeConnection(device, address_type)).Times(1);
-  LeFixedChannelManager::ConnectionResult my_result;
-  LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+  FixedChannelManager::ConnectionResult my_result;
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
       .handler_ = user_handler.get(),
       .on_fail_callback_ = common::testing::BindLambdaForTesting(
-          [&my_result](LeFixedChannelManager::ConnectionResult result) { my_result = result; })};
+          [&my_result](FixedChannelManager::ConnectionResult result) { my_result = result; })};
   le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection));
 
   // Step 3: ACL connection failure event should trigger connection failure callback
@@ -237,7 +238,7 @@ TEST_F(L2capLeLinkManagerTest, connect_fixed_channel_service_without_acl_with_hc
                                               hci::ErrorCode::PAGE_TIMEOUT));
   SyncHandler(hci_callback_handler);
   SyncHandler(user_handler.get());
-  EXPECT_EQ(my_result.connection_result_code, LeFixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR);
+  EXPECT_EQ(my_result.connection_result_code, FixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR);
   EXPECT_EQ(my_result.hci_error, hci::ErrorCode::PAGE_TIMEOUT);
 
   user_handler->Clear();
@@ -246,7 +247,7 @@ TEST_F(L2capLeLinkManagerTest, connect_fixed_channel_service_without_acl_with_hc
 TEST_F(L2capLeLinkManagerTest, not_acquiring_channels_should_disconnect_acl_after_timeout) {
   EXPECT_CALL(*mock_parameter_provider_, GetLeLinkIdleDisconnectTimeout)
       .WillRepeatedly(Return(kTestIdleDisconnectTimeoutShort));
-  MockLeFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
+  MockFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
   MockAclManager mock_acl_manager;
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   hci::AddressType address_type = hci::AddressType::RANDOM_DEVICE_ADDRESS;
@@ -257,23 +258,23 @@ TEST_F(L2capLeLinkManagerTest, not_acquiring_channels_should_disconnect_acl_afte
   os::Handler* hci_callback_handler = nullptr;
   EXPECT_CALL(mock_acl_manager, RegisterLeCallbacks(_, _))
       .WillOnce(DoAll(SaveArg<0>(&hci_le_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
-  LeLinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
-                                mock_parameter_provider_);
+  LinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
+                              mock_parameter_provider_);
   EXPECT_EQ(hci_le_connection_callbacks, &le_link_manager);
   EXPECT_EQ(hci_callback_handler, l2cap_handler_);
 
   // Register fake services
-  MockLeFixedChannelServiceImpl mock_service_1, mock_service_2;
-  std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> results;
+  MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+  std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
   results.emplace_back(kSmpBrCid, &mock_service_1);
   results.emplace_back(kConnectionlessCid, &mock_service_2);
   EXPECT_CALL(mock_le_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
 
   // Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
   EXPECT_CALL(mock_acl_manager, CreateLeConnection(device, address_type)).Times(1);
-  LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
       .handler_ = user_handler.get(),
-      .on_fail_callback_ = common::BindOnce([](LeFixedChannelManager::ConnectionResult result) { FAIL(); })};
+      .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
   le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection));
 
   // Step 3: ACL connection success event should trigger channel creation for all registered services
@@ -282,11 +283,11 @@ TEST_F(L2capLeLinkManagerTest, not_acquiring_channels_should_disconnect_acl_afte
   hci::AclConnection::Queue link_queue{10};
   EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
   EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
-  std::unique_ptr<LeFixedChannel> channel_1, channel_2;
-  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<LeFixedChannel> channel) {
+  std::unique_ptr<FixedChannel> channel_1, channel_2;
+  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
     channel_1 = std::move(channel);
   });
-  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<LeFixedChannel> channel) {
+  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
     channel_2 = std::move(channel);
   });
   hci_callback_handler->Post(common::BindOnce(&hci::LeConnectionCallbacks::OnLeConnectSuccess,
@@ -302,7 +303,7 @@ TEST_F(L2capLeLinkManagerTest, not_acquiring_channels_should_disconnect_acl_afte
   channel_2->RegisterOnCloseCallback(
       user_handler.get(), common::testing::BindLambdaForTesting([&](hci::ErrorCode status) { status_2 = status; }));
 
-  // Step 4: Leave channel IDLE long enough, they will disconnect
+  // Step 4: ave channel IDLE long enough, they will disconnect
   EXPECT_CALL(*raw_acl_connection, Disconnect(hci::DisconnectReason::REMOTE_USER_TERMINATED_CONNECTION)).Times(1);
   std::this_thread::sleep_for(kTestIdleDisconnectTimeoutShort * 1.2);
 
@@ -318,7 +319,7 @@ TEST_F(L2capLeLinkManagerTest, not_acquiring_channels_should_disconnect_acl_afte
 TEST_F(L2capLeLinkManagerTest, acquiring_channels_should_not_disconnect_acl_after_timeout) {
   EXPECT_CALL(*mock_parameter_provider_, GetLeLinkIdleDisconnectTimeout)
       .WillRepeatedly(Return(kTestIdleDisconnectTimeoutShort));
-  MockLeFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
+  MockFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
   MockAclManager mock_acl_manager;
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   hci::AddressType address_type = hci::AddressType::RANDOM_DEVICE_ADDRESS;
@@ -329,23 +330,23 @@ TEST_F(L2capLeLinkManagerTest, acquiring_channels_should_not_disconnect_acl_afte
   os::Handler* hci_callback_handler = nullptr;
   EXPECT_CALL(mock_acl_manager, RegisterLeCallbacks(_, _))
       .WillOnce(DoAll(SaveArg<0>(&hci_le_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
-  LeLinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
-                                mock_parameter_provider_);
+  LinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
+                              mock_parameter_provider_);
   EXPECT_EQ(hci_le_connection_callbacks, &le_link_manager);
   EXPECT_EQ(hci_callback_handler, l2cap_handler_);
 
   // Register fake services
-  MockLeFixedChannelServiceImpl mock_service_1, mock_service_2;
-  std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> results;
+  MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+  std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
   results.emplace_back(kSmpBrCid, &mock_service_1);
   results.emplace_back(kConnectionlessCid, &mock_service_2);
   EXPECT_CALL(mock_le_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
 
   // Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
   EXPECT_CALL(mock_acl_manager, CreateLeConnection(device, address_type)).Times(1);
-  LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
       .handler_ = user_handler.get(),
-      .on_fail_callback_ = common::BindOnce([](LeFixedChannelManager::ConnectionResult result) { FAIL(); })};
+      .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
   le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection));
 
   // Step 3: ACL connection success event should trigger channel creation for all registered services
@@ -354,11 +355,11 @@ TEST_F(L2capLeLinkManagerTest, acquiring_channels_should_not_disconnect_acl_afte
   hci::AclConnection::Queue link_queue{10};
   EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
   EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
-  std::unique_ptr<LeFixedChannel> channel_1, channel_2;
-  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<LeFixedChannel> channel) {
+  std::unique_ptr<FixedChannel> channel_1, channel_2;
+  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
     channel_1 = std::move(channel);
   });
-  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<LeFixedChannel> channel) {
+  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
     channel_2 = std::move(channel);
   });
   hci_callback_handler->Post(common::BindOnce(&hci::LeConnectionCallbacks::OnLeConnectSuccess,
@@ -376,7 +377,7 @@ TEST_F(L2capLeLinkManagerTest, acquiring_channels_should_not_disconnect_acl_afte
 
   channel_1->Acquire();
 
-  // Step 4: Leave channel IDLE, it won't disconnect to due acquired channel 1
+  // Step 4: ave channel IDLE, it won't disconnect to due acquired channel 1
   EXPECT_CALL(*raw_acl_connection, Disconnect(hci::DisconnectReason::REMOTE_USER_TERMINATED_CONNECTION)).Times(0);
   std::this_thread::sleep_for(kTestIdleDisconnectTimeoutShort * 2);
 
@@ -392,7 +393,7 @@ TEST_F(L2capLeLinkManagerTest, acquiring_channels_should_not_disconnect_acl_afte
 TEST_F(L2capLeLinkManagerTest, acquiring_and_releasing_channels_should_eventually_disconnect_acl) {
   EXPECT_CALL(*mock_parameter_provider_, GetLeLinkIdleDisconnectTimeout)
       .WillRepeatedly(Return(kTestIdleDisconnectTimeoutShort));
-  MockLeFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
+  MockFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
   MockAclManager mock_acl_manager;
   hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
   hci::AddressType address_type = hci::AddressType::PUBLIC_IDENTITY_ADDRESS;
@@ -403,23 +404,23 @@ TEST_F(L2capLeLinkManagerTest, acquiring_and_releasing_channels_should_eventuall
   os::Handler* hci_callback_handler = nullptr;
   EXPECT_CALL(mock_acl_manager, RegisterLeCallbacks(_, _))
       .WillOnce(DoAll(SaveArg<0>(&hci_le_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
-  LeLinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
-                                mock_parameter_provider_);
+  LinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
+                              mock_parameter_provider_);
   EXPECT_EQ(hci_le_connection_callbacks, &le_link_manager);
   EXPECT_EQ(hci_callback_handler, l2cap_handler_);
 
   // Register fake services
-  MockLeFixedChannelServiceImpl mock_service_1, mock_service_2;
-  std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> results;
+  MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+  std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
   results.emplace_back(kSmpBrCid, &mock_service_1);
   results.emplace_back(kConnectionlessCid, &mock_service_2);
   EXPECT_CALL(mock_le_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
 
   // Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
   EXPECT_CALL(mock_acl_manager, CreateLeConnection(device, address_type)).Times(1);
-  LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+  LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
       .handler_ = user_handler.get(),
-      .on_fail_callback_ = common::BindOnce([](LeFixedChannelManager::ConnectionResult result) { FAIL(); })};
+      .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
   le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection));
 
   // Step 3: ACL connection success event should trigger channel creation for all registered services
@@ -428,11 +429,11 @@ TEST_F(L2capLeLinkManagerTest, acquiring_and_releasing_channels_should_eventuall
   hci::AclConnection::Queue link_queue{10};
   EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
   EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
-  std::unique_ptr<LeFixedChannel> channel_1, channel_2;
-  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<LeFixedChannel> channel) {
+  std::unique_ptr<FixedChannel> channel_1, channel_2;
+  EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
     channel_1 = std::move(channel);
   });
-  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<LeFixedChannel> channel) {
+  EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
     channel_2 = std::move(channel);
   });
   hci_callback_handler->Post(common::BindOnce(&hci::LeConnectionCallbacks::OnLeConnectSuccess,
@@ -450,11 +451,11 @@ TEST_F(L2capLeLinkManagerTest, acquiring_and_releasing_channels_should_eventuall
 
   channel_1->Acquire();
 
-  // Step 4: Leave channel IDLE, it won't disconnect to due acquired channel 1
+  // Step 4: ave channel IDLE, it won't disconnect to due acquired channel 1
   EXPECT_CALL(*raw_acl_connection, Disconnect(hci::DisconnectReason::REMOTE_USER_TERMINATED_CONNECTION)).Times(0);
   std::this_thread::sleep_for(kTestIdleDisconnectTimeoutShort * 2);
 
-  // Step 5: Leave channel IDLE long enough, they will disconnect
+  // Step 5: ave channel IDLE long enough, they will disconnect
   channel_1->Release();
   EXPECT_CALL(*raw_acl_connection, Disconnect(hci::DisconnectReason::REMOTE_USER_TERMINATED_CONNECTION)).Times(1);
   std::this_thread::sleep_for(kTestIdleDisconnectTimeoutShort * 1.2);
@@ -469,5 +470,6 @@ TEST_F(L2capLeLinkManagerTest, acquiring_and_releasing_channels_should_eventuall
 }
 
 }  // namespace internal
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
similarity index 72%
rename from gd/l2cap/internal/classic_link_mock.h
rename to gd/l2cap/le/internal/link_mock.h
index 0b03f55..800d1c7 100644 (file)
 
 #include "hci/acl_manager_mock.h"
 #include "hci/address.h"
-#include "l2cap/internal/classic_link.h"
 #include "l2cap/internal/scheduler_mock.h"
+#include "l2cap/le/internal/link.h"
 
 #include <gmock/gmock.h>
 
 // Unit test interfaces
 namespace bluetooth {
 namespace l2cap {
+namespace le {
 namespace internal {
 namespace testing {
 
 using hci::testing::MockAclConnection;
 
-class MockClassicLink : public ClassicLink {
+class MockLink : public Link {
  public:
-  explicit MockClassicLink(os::Handler* handler, ParameterProvider* parameter_provider)
-      : ClassicLink(handler, std::make_unique<MockAclConnection>(), std::make_unique<MockScheduler>(),
-                    parameter_provider){};
+  explicit MockLink(os::Handler* handler, l2cap::internal::ParameterProvider* parameter_provider)
+      : Link(handler, std::make_unique<MockAclConnection>(),
+             std::make_unique<l2cap::internal::testing::MockScheduler>(), parameter_provider){};
   MOCK_METHOD(hci::Address, GetDevice, (), (override));
   MOCK_METHOD(void, OnAclDisconnected, (hci::ErrorCode status), (override));
   MOCK_METHOD(void, Disconnect, (), (override));
-  MOCK_METHOD(std::shared_ptr<ClassicFixedChannelImpl>, AllocateFixedChannel, (Cid cid, SecurityPolicy security_policy),
+  MOCK_METHOD(std::shared_ptr<FixedChannelImpl>, AllocateFixedChannel, (Cid cid, SecurityPolicy security_policy),
               (override));
   MOCK_METHOD(bool, IsFixedChannelAllocated, (Cid cid), (override));
   MOCK_METHOD(void, RefreshRefCount, (), (override));
@@ -46,5 +47,6 @@ class MockClassicLink : public ClassicLink {
 
 }  // namespace testing
 }  // namespace internal
+}  // namespace le
 }  // namespace l2cap
 }  // namespace bluetooth
\ No newline at end of file
diff --git a/gd/l2cap/le/l2cap_le_module.cc b/gd/l2cap/le/l2cap_le_module.cc
new file mode 100644 (file)
index 0000000..938df8b
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2019 The Android Open Source Project
+ *
+ * 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.
+ */
+#define LOG_TAG "l2cap2"
+
+#include <memory>
+
+#include "common/bidi_queue.h"
+#include "hci/acl_manager.h"
+#include "hci/address.h"
+#include "hci/hci_layer.h"
+#include "hci/hci_packets.h"
+#include "l2cap/internal/parameter_provider.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
+#include "l2cap/le/internal/link_manager.h"
+#include "module.h"
+#include "os/handler.h"
+#include "os/log.h"
+
+#include "l2cap/le/l2cap_le_module.h"
+
+namespace bluetooth {
+namespace l2cap {
+namespace le {
+
+const ModuleFactory L2capLeModule::Factory = ModuleFactory([]() { return new L2capLeModule(); });
+
+struct L2capLeModule::impl {
+  impl(os::Handler* l2cap_handler, hci::AclManager* acl_manager)
+      : l2cap_handler_(l2cap_handler), acl_manager_(acl_manager) {}
+  os::Handler* l2cap_handler_;
+  hci::AclManager* acl_manager_;
+  l2cap::internal::ParameterProvider parameter_provider_;
+  internal::FixedChannelServiceManagerImpl fixed_channel_service_manager_impl_{l2cap_handler_};
+  internal::LinkManager link_manager_{l2cap_handler_, acl_manager_, &fixed_channel_service_manager_impl_,
+                                      &parameter_provider_};
+};
+
+void L2capLeModule::ListDependencies(ModuleList* list) {
+  list->add<hci::AclManager>();
+}
+
+void L2capLeModule::Start() {
+  pimpl_ = std::make_unique<impl>(GetHandler(), GetDependency<hci::AclManager>());
+}
+
+void L2capLeModule::Stop() {
+  pimpl_.reset();
+}
+
+std::unique_ptr<FixedChannelManager> L2capLeModule::GetFixedChannelManager() {
+  return std::unique_ptr<FixedChannelManager>(new FixedChannelManager(&pimpl_->fixed_channel_service_manager_impl_,
+                                                                      &pimpl_->link_manager_, pimpl_->l2cap_handler_));
+}
+
+}  // namespace le
+}  // namespace l2cap
+}  // namespace bluetooth
\ No newline at end of file
diff --git a/gd/l2cap/le/l2cap_le_module.h b/gd/l2cap/le/l2cap_le_module.h
new file mode 100644 (file)
index 0000000..0185403
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2019 The Android Open Source Project
+ *
+ * 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.
+ */
+#pragma once
+
+#include <memory>
+
+#include "l2cap/le/fixed_channel_manager.h"
+#include "module.h"
+
+namespace bluetooth {
+namespace l2cap {
+namespace le {
+
+class L2capLeModule : public bluetooth::Module {
+ public:
+  L2capLeModule() = default;
+  ~L2capLeModule() = default;
+
+  /**
+   * Get the api to the LE fixed channel l2cap module
+   */
+  std::unique_ptr<FixedChannelManager> GetFixedChannelManager();
+
+  static const ModuleFactory Factory;
+
+ protected:
+  void ListDependencies(ModuleList* list) override;
+
+  void Start() override;
+
+  void Stop() override;
+
+ private:
+  struct impl;
+  std::unique_ptr<impl> pimpl_;
+  DISALLOW_COPY_AND_ASSIGN(L2capLeModule);
+};
+
+}  // namespace le
+}  // namespace l2cap
+}  // namespace bluetooth
\ No newline at end of file
index 3f4ad09..063f5e2 100644 (file)
@@ -20,7 +20,8 @@
 #include "hal/hci_hal.h"
 #include "hci/acl_manager.h"
 #include "hci/classic_security_manager.h"
-#include "l2cap/l2cap_layer.h"
+#include "l2cap/classic/l2cap_classic_module.h"
+#include "l2cap/le/l2cap_le_module.h"
 #include "os/log.h"
 #include "os/thread.h"
 #include "shim/controller.h"
@@ -41,7 +42,8 @@ struct bluetooth::shim::Stack::impl {
     modules.add<::bluetooth::hal::HciHal>();
     modules.add<::bluetooth::hci::AclManager>();
     modules.add<::bluetooth::hci::ClassicSecurityManager>();
-    modules.add<::bluetooth::l2cap::L2capLayer>();
+    modules.add<::bluetooth::l2cap::classic::L2capClassicModule>();
+    modules.add<::bluetooth::l2cap::le::L2capLeModule>();
     modules.add<::bluetooth::shim::Controller>();
     modules.add<::bluetooth::shim::HciLayer>();