wifi: Restructure wifi legacy HAL implementation

Restructured the existing code to create a new class called
|WifiLegacyHal|. This class will be used as a wrapper to invoke
all the legacy HAL functions and handle the "C" style callbacks.

Bug: 31936700
Test: mmma -j32 hardware/interfaces/wifi/1.0/default
Change-Id: I63e8543f49886f8446101320a97d1e96e30d1035
diff --git a/wifi/1.0/default/wifi_legacy_hal.h b/wifi/1.0/default/wifi_legacy_hal.h
new file mode 100644
index 0000000..1af9f1a
--- /dev/null
+++ b/wifi/1.0/default/wifi_legacy_hal.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef WIFI_LEGACY_WIFI_HAL_H_
+#define WIFI_LEGACY_WIFI_HAL_H_
+
+#include <functional>
+#include <thread>
+
+#include <hardware_legacy/wifi_hal.h>
+
+namespace android {
+namespace hardware {
+namespace wifi {
+namespace V1_0 {
+namespace implementation {
+
+/**
+ * Class that encapsulates all legacy HAL interactions.
+ * This class manages the lifetime of the event loop thread used by legacy HAL.
+ */
+class WifiLegacyHal {
+ public:
+  WifiLegacyHal();
+  // Initialize the legacy HAL and start the event looper thread.
+  wifi_error start();
+  // Deinitialize the legacy HAL and stop the event looper thread.
+  wifi_error stop(const std::function<void()>& on_complete_callback);
+
+ private:
+  // Retrieve the interface handle to be used for the "wlan" interface.
+  wifi_error retrieveWlanInterfaceHandle();
+  // Run the legacy HAL event loop thread.
+  void runEventLoop();
+
+  // Event loop thread used by legacy HAL.
+  std::thread event_loop_thread_;
+  // Global function table of legacy HAL.
+  wifi_hal_fn global_func_table_;
+  // Opaque handle to be used for all global operations.
+  wifi_handle global_handle_;
+  // Opaque handle to be used for all wlan0 interface specific operations.
+  wifi_interface_handle wlan_interface_handle_;
+  // Flag to indicate if we have initiated the cleanup of legacy HAL.
+  bool awaiting_event_loop_termination_;
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace wifi
+}  // namespace hardware
+}  // namespace android
+
+#endif  // WIFI_LEGACY_WIFI_HAL_H_