forked from coronalabs/corona
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRtt_MPlatformDevice.h
157 lines (128 loc) · 4.93 KB
/
Rtt_MPlatformDevice.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//////////////////////////////////////////////////////////////////////////////
//
// This file is part of the Corona game engine.
// For overview and more information on licensing please refer to README.md
// Home page: https://github.com/coronalabs/corona
// Contact: [email protected]
//
//////////////////////////////////////////////////////////////////////////////
#ifndef _Rtt_MPlatformDevice_H__
#define _Rtt_MPlatformDevice_H__
#include "Rtt_MCallback.h"
#include "Rtt_DeviceOrientation.h"
#include "Core/Rtt_Assert.h"
#include "Core/Rtt_Real.h"
// ----------------------------------------------------------------------------
namespace Rtt
{
class PlatformInputDeviceManager;
// ----------------------------------------------------------------------------
class MPlatformDevice
{
public:
typedef enum _EventType
{
kUnknownEvent = -1,
kOrientationEvent = 0,
kAccelerometerEvent,
kGyroscopeEvent,
kLocationEvent,
kHeadingEvent,
kMultitouchEvent,
kCollisionEvent,
kPreCollisionEvent,
kPostCollisionEvent,
kParticleCollisionEvent,
kMemoryWarningEvent,
kTrackingEvent,
kKeyEvent,
kInputDeviceStatusEvent,
kMouseEvent,
kNumTypes
}
EventType;
typedef enum _ActivationType
{
kActivateUnknown = -1,
kActivateControllerUserInteraction = 0,
kActivationTypeCount
}
ActivationType;
typedef enum _EnvironmentType
{
kSimulatorEnvironment = 0,
kDeviceEnvironment,
kBrowserEnvironment
}
EnvironmentType;
typedef enum _IdentifierType
{
// DO NOT CHANGE ENUM VALUES (Android bridge makes assumptions)
kDeviceIdentifier = 0, // The original "deviceId". On some platforms, there was implicit fallback to other identifier types, so we decided to NEVER change the behavior of this API.
kHardwareIdentifier = 1, // The hardware id of the device (could be same as kDeviceIdentifier, but there is no fallback to other id mechanisms)
kOSIdentifier = 2, // An id created by the OS
kMacIdentifier = 3, // The ethernet MAC address
kUdidIdentifier = 4, // Some udid scheme that's platform specific
kIOSAdvertisingIdentifier = 5, // iOS specific advertizing APIs
kIOSAdvertisingTrackingEnabled = 6,
kIOSIdentifierForVendor = 7,
kNumIdentifiers
}
IdentifierType;
public:
virtual const char* GetName() const = 0;
virtual const char* GetManufacturer() const = 0;
virtual const char* GetModel() const = 0;
virtual const char* GetUniqueIdentifier( IdentifierType t ) const = 0;
virtual EnvironmentType GetEnvironment() const = 0;
virtual const char* GetPlatformName() const = 0;
virtual const char* GetPlatform() const = 0;
virtual const char* GetPlatformVersion() const = 0;
virtual const char* GetArchitectureInfo() const = 0;
virtual PlatformInputDeviceManager& GetInputDeviceManager() = 0;
public:
virtual void Vibrate(const char* hapticType, const char* hapticStyle = NULL) const { Vibrate(); };
virtual void Vibrate() const = 0;
public:
virtual void BeginNotifications( EventType type ) const = 0;
virtual void EndNotifications( EventType type ) const = 0;
virtual bool DoesNotify( EventType type ) const = 0;
virtual bool HasEventSource( EventType type ) const = 0;
virtual void SetAccelerometerInterval( U32 frequency ) const = 0;
virtual void SetGyroscopeInterval( U32 frequency ) const = 0;
// Activate/deactivate system features.
// Returns true if the feature is supported on that platform. This is to provide backwards compatibility with
// event-driven system.activate/system.deactivate calls (BeginNotifications/EndNotifications above).
virtual bool Activate( ActivationType key ) const { return false; }
virtual bool Deactivate( ActivationType key ) const { return false; }
public:
virtual void SetLocationAccuracy( Real meters ) const = 0;
virtual void SetLocationThreshold( Real meters ) const = 0;
public:
virtual DeviceOrientation::Type GetOrientation() const = 0;
};
// Use this to implement MPlatformDevice::DoesNotify
class DeviceNotificationTracker
{
public:
typedef MPlatformDevice::EventType EventType;
public:
DeviceNotificationTracker() : fNotifications( 0 ) { }
protected:
bool Verify( EventType type ) const
{
return Rtt_VERIFY( type >= MPlatformDevice::kUnknownEvent
&& type < MPlatformDevice::kNumTypes ) != 0;
}
U32 GetMask( EventType type ) const { return ( 1 << type ); }
public:
void BeginNotifications( EventType type ) const { if ( Verify( type ) ) { fNotifications |= GetMask( type ); } }
void EndNotifications( EventType type ) const { if ( Verify( type ) ) { fNotifications &= ~GetMask( type ); } }
bool DoesNotify( EventType type ) const { return Verify( type ) && ( fNotifications & GetMask( type ) ); }
private:
mutable U32 fNotifications;
};
// ----------------------------------------------------------------------------
} // namespace Rtt
// ----------------------------------------------------------------------------
#endif // _Rtt_MPlatformDevice_H__