libmems: Stop exposing internal implementation

Add a factory object to create the iio context. From there, iio device
objects are added. No ..impl.h files are exported anymore.

BUG=none
TEST=Unit tests.

Change-Id: Ib24fd46ca69b85e98e0767c16a2880b6f1fe1db7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/6164341
Reviewed-by: Harvey Yang <chenghaoyang@chromium.org>
Tested-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Cheng-Han Yang <chenghan@chromium.org>
Commit-Queue: Gwendal Grignou <gwendal@chromium.org>
NOKEYCHECK=True
GitOrigin-RevId: 6872e3b5b5c53dc0f68c656ca551d1729ea04c07
diff --git a/BUILD.gn b/BUILD.gn
index 0c44271..37db016 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -29,6 +29,7 @@
   sources = [
     "common_types.cc",
     "iio_channel_impl.cc",
+    "iio_context_factory.cc",
     "iio_context_impl.cc",
     "iio_device.cc",
     "iio_device_impl.cc",
@@ -45,12 +46,10 @@
     "common_types.h",
     "export.h",
     "iio_channel.h",
-    "iio_channel_impl.h",
     "iio_context.h",
-    "iio_context_impl.h",
+    "iio_context_factory.h",
     "iio_device.h",
-    "iio_device_impl.h",
-    "iio_device_trigger_impl.h",
+    "iio_event.h",
     "test_fakes.h",
   ]
   install_path = "/usr/include/chromeos/libmems"
diff --git a/iio_context_factory.cc b/iio_context_factory.cc
new file mode 100644
index 0000000..da9cf87
--- /dev/null
+++ b/iio_context_factory.cc
@@ -0,0 +1,19 @@
+// Copyright 2025 The ChromiumOS Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "libmems/iio_context_factory.h"
+
+#include <memory>
+
+#include "libmems/iio_context_impl.h"
+
+namespace libmems {
+
+IioContextFactory::IioContextFactory() {}
+
+std::unique_ptr<IioContext> IioContextFactory::Generate() {
+  return std::make_unique<IioContextImpl>();
+}
+
+}  // namespace libmems
diff --git a/iio_context_factory.h b/iio_context_factory.h
new file mode 100644
index 0000000..ce57f2b
--- /dev/null
+++ b/iio_context_factory.h
@@ -0,0 +1,25 @@
+// Copyright 2025 The ChromiumOS Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef LIBMEMS_IIO_CONTEXT_FACTORY_H_
+#define LIBMEMS_IIO_CONTEXT_FACTORY_H_
+
+#include <memory>
+
+#include "libmems/export.h"
+#include "libmems/iio_context.h"
+
+namespace libmems {
+
+class LIBMEMS_EXPORT IioContextFactory {
+ public:
+  IioContextFactory();
+  virtual ~IioContextFactory() = default;
+
+  virtual std::unique_ptr<IioContext> Generate();
+};
+
+}  // namespace libmems
+
+#endif  // LIBMEMS_IIO_CONTEXT_FACTORY_H_
diff --git a/test_fakes.h b/test_fakes.h
index 6e2c106..e9f1359 100644
--- a/test_fakes.h
+++ b/test_fakes.h
@@ -21,6 +21,7 @@
 #include "libmems/export.h"
 #include "libmems/iio_channel.h"
 #include "libmems/iio_context.h"
+#include "libmems/iio_context_factory.h"
 #include "libmems/iio_device.h"
 #include "libmems/iio_event.h"
 
@@ -382,6 +383,15 @@
   uint32_t timeout_;
 };
 
+class FakeIioContextFactory : public IioContextFactory {
+ public:
+  ~FakeIioContextFactory() = default;
+
+  std::unique_ptr<IioContext> Generate() {
+    return std::make_unique<FakeIioContext>();
+  }
+};
+
 }  // namespace fakes
 
 }  // namespace libmems