#ifndef UI_EVENTS_DEVICES_DEVICE_DATA_MANAGER_H_
#define UI_EVENTS_DEVICES_DEVICE_DATA_MANAGER_H_
#include <stdint.h>
#include <array>
#include <memory>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/observer_list.h"
#include "ui/events/devices/device_hotplug_event_observer.h"
#include "ui/events/devices/events_devices_export.h"
#include "ui/events/devices/touch_device_transform.h"
#include "ui/events/devices/touchscreen_device.h"
#if defined(OHOS_INPUT_EVENTS)
#include "ohos_adapter_helper.h"
#endif
namespace ui {
class DeviceDataManagerTest;
class InputDeviceEventObserver;
class EVENTS_DEVICES_EXPORT DeviceDataManager
: public DeviceHotplugEventObserver {
public:
static const int kMaxDeviceNum = 128;
DeviceDataManager(const DeviceDataManager&) = delete;
DeviceDataManager& operator=(const DeviceDataManager&) = delete;
~DeviceDataManager() override;
static void CreateInstance();
static void DeleteInstance();
static DeviceDataManager* GetInstance();
static bool HasInstance();
void ConfigureTouchDevices(
const std::vector<ui::TouchDeviceTransform>& transforms);
void ApplyTouchTransformer(int touch_device_id, float* x, float* y);
int64_t GetTargetDisplayForTouchDevice(int touch_device_id) const;
void ApplyTouchRadiusScale(int touch_device_id, double* radius);
void SetTouchscreensEnabled(bool enabled);
const std::vector<TouchscreenDevice>& GetTouchscreenDevices() const;
const std::vector<InputDevice>& GetKeyboardDevices() const;
const std::vector<InputDevice>& GetMouseDevices() const;
const std::vector<InputDevice>& GetPointingStickDevices() const;
const std::vector<InputDevice>& GetTouchpadDevices() const;
const std::vector<InputDevice>& GetUncategorizedDevices() const;
bool AreDeviceListsComplete() const;
bool AreTouchscreensEnabled() const;
bool AreTouchscreenTargetDisplaysValid() const;
void AddObserver(InputDeviceEventObserver* observer);
void RemoveObserver(InputDeviceEventObserver* observer);
bool HasObserver(InputDeviceEventObserver* observer);
void ResetDeviceListsForTest();
#if defined(OHOS_INPUT_EVENTS)
void AddKeyboardDevice(const InputDevice& device);
void AddMouseDevice(const InputDevice& device);
void AddTouchpadDevice(const InputDevice& device);
void DeleteDevice(const InputDevice& devices);
#endif
protected:
DeviceDataManager();
void OnTouchscreenDevicesUpdated(
const std::vector<TouchscreenDevice>& devices) override;
void OnKeyboardDevicesUpdated(
const std::vector<InputDevice>& devices) override;
void OnMouseDevicesUpdated(
const std::vector<InputDevice>& devices) override;
void OnPointingStickDevicesUpdated(
const std::vector<InputDevice>& devices) override;
void OnTouchpadDevicesUpdated(
const std::vector<InputDevice>& devices) override;
void OnUncategorizedDevicesUpdated(
const std::vector<InputDevice>& devices) override;
void OnDeviceListsComplete() override;
void OnStylusStateChanged(StylusState state) override;
private:
friend class DeviceDataManagerTest;
friend class DeviceDataManagerTestApi;
void ClearTouchDeviceAssociations();
void UpdateTouchInfoFromTransform(
const ui::TouchDeviceTransform& touch_device_transform);
void UpdateTouchMap();
void NotifyObserversTouchscreenDeviceConfigurationChanged();
void NotifyObserversKeyboardDeviceConfigurationChanged();
void NotifyObserversMouseDeviceConfigurationChanged();
void NotifyObserversPointingStickDeviceConfigurationChanged();
void NotifyObserversTouchpadDeviceConfigurationChanged();
void NotifyObserversUncategorizedDeviceConfigurationChanged();
void NotifyObserversDeviceListsComplete();
void NotifyObserversStylusStateChanged(StylusState stylus_state);
static DeviceDataManager* instance_;
std::vector<TouchscreenDevice> touchscreen_devices_;
std::vector<InputDevice> keyboard_devices_;
std::vector<InputDevice> mouse_devices_;
std::vector<InputDevice> pointing_stick_devices_;
std::vector<InputDevice> touchpad_devices_;
std::vector<InputDevice> uncategorized_devices_;
bool device_lists_complete_ = false;
base::ObserverList<InputDeviceEventObserver>::Unchecked observers_;
bool touch_screens_enabled_ = true;
bool are_touchscreen_target_displays_valid_ = false;
base::flat_map<int, TouchDeviceTransform> touch_map_;
#if defined(OHOS_INPUT_EVENTS)
std::unique_ptr<OHOS::NWeb::MMIAdapter> mmi_adapter_ = nullptr;
std::shared_ptr<OHOS::NWeb::MMIListenerAdapter> dev_listener_ = nullptr;
scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_;
#endif
};
}
#endif