summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h
blob: 4f734e2824fa6973211ca3581fc51c5704897b43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2010 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <memory>
#include <mutex>
#include <string>
#include <vector>

#include "Common/Common.h"
#include "Common/IniFile.h"
#include "InputCommon/ControllerInterface/Device.h"

class ControllerInterface;

#define sign(x) ((x) ? (x) < 0 ? -1 : 1 : 0)

const char* const named_directions[] = {_trans("Up"), _trans("Down"), _trans("Left"),
                                        _trans("Right")};

namespace ControllerEmu
{
class ControlGroup;

class EmulatedController
{
public:
  virtual ~EmulatedController();
  virtual std::string GetName() const = 0;

  virtual void LoadDefaults(const ControllerInterface& ciface);

  virtual void LoadConfig(IniFile::Section* sec, const std::string& base = "");
  virtual void SaveConfig(IniFile::Section* sec, const std::string& base = "");

  bool IsDefaultDeviceConnected() const;
  const ciface::Core::DeviceQualifier& GetDefaultDevice() const;
  void SetDefaultDevice(const std::string& device);
  void SetDefaultDevice(ciface::Core::DeviceQualifier devq);

  void UpdateReferences(const ControllerInterface& devi);

  // This returns a lock that should be held before calling State() on any control
  // references and GetState(), by extension. This prevents a race condition
  // which happens while handling a hotplug event because a control reference's State()
  // could be called before we have finished updating the reference.
  static std::unique_lock<std::recursive_mutex> GetStateLock();

  std::vector<std::unique_ptr<ControlGroup>> groups;

private:
  ciface::Core::DeviceQualifier m_default_device;
  bool m_default_device_is_connected{false};
};
}  // namespace ControllerEmu