blob: c0f72cacee6a282d6f67152794e54c4aa97e5d43 (
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
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
|
//Copyright (C) Microsoft Corporation, All Rights Reserved
//
//Abstract:
//
// This module contains the type definitions for the pedometer sample driver
// hardware simulator.
//
//Environment:
//
// Windows User-Mode Driver Framework (UMDF)
#pragma once
#include <windows.h>
#include <wdf.h>
#include "SensorsTrace.h"
#include <SensorsCx.h>
#include "Device.h"
#define SIMULATOR_HARDWARE_INTERVAL_MS (1000) // 1 second interval in milliseconds
typedef enum SIMULATOR_STATE
{
SimulatorState_NotInitialized = 0,
SimulatorState_Initialized,
SimulatorState_Started
} SIMULATOR_STATE;
typedef class HistoryIterator
{
public:
HistoryIterator();
~HistoryIterator();
NTSTATUS Next(_Out_ PedometerSample *Sample);
}HistoryIterator, *PHistoryIterator;
typedef class HardwareSimulator
{
private:
WDFTIMER m_Timer;
ULONG m_Index;
WDFWAITLOCK m_Lock;
SIMULATOR_STATE m_State;
WDFOBJECT m_SimulatorInstance;
BOOLEAN m_HasReset;
// History operation
WDFWAITLOCK m_HistoryLock;
WDFTIMER m_HistoryTimer;
HistoryCircBuffer m_History;
ULONG m_HistoryIntervalInMs;
BOOLEAN m_HistoryStarted;
HANDLE m_HistoryCancelReadEvt;
public:
HardwareSimulator();
~HardwareSimulator();
// WDF callbacks
static EVT_WDF_TIMER OnTimerExpire;
static NTSTATUS Initialize(_In_ WDFDEVICE Device, _Out_ WDFOBJECT *SimulatorInstance);
NTSTATUS Cleanup();
NTSTATUS Start();
NTSTATUS Stop();
NTSTATUS GetSample(_Out_ PedometerSample *Sample);
NTSTATUS Reset();
NTSTATUS ClearHistory();
NTSTATUS StartHistory();
NTSTATUS StopHistory();
NTSTATUS ReadHistory(_Inout_ PULONG SamplesCount, _Out_writes_to_(*SamplesCount, *SamplesCount) PPedometerSample HistorySamplesBuffer);
NTSTATUS SignalReadCancellation();
static EVT_WDF_TIMER OnHistoryTimerExpire;
ULONG GetHistorySizeInRecords()
{
return m_History.BufferLength;
}
ULONG GetHistoryIntervalInMs()
{
return m_HistoryIntervalInMs;
}
private:
NTSTATUS InitializeInternal(_In_ WDFOBJECT SimulatorInstance);
NTSTATUS AddHistoryEntry(_In_ PedometerSample& Sample);
_Requires_lock_held_(m_HistoryLock)
NTSTATUS AddDataElemToHistoryBuffer(_In_ PPedometerSample pData);
_Requires_lock_held_(m_HistoryLock)
NTSTATUS RemoveDataElemFromHistoryBuffer(_Out_ PPedometerSample pData);
} HardwareSimulator, *PHardwareSimulator;
// Set up accessor function to retrieve device context
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(HardwareSimulator, GetHardwareSimulatorContextFromInstance);
|