123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #ifndef __SENSOR_EVENT_H
- #define __SENSOR_EVENT_H
- #pragma once
- #include "stdafx.h"
- #include <InitGuid.h>
- #include <SensorsApi.h>
- #include <Sensors.h>
- class CMyEvents : public ISensorEvents
- {
- public:
- STDMETHODIMP QueryInterface(REFIID iid, void** ppv)
- {
- if (ppv == NULL)
- {
- return E_POINTER;
- }
- if (iid == __uuidof(IUnknown))
- {
- *ppv = static_cast<IUnknown*>(this);
- }
- else if (iid == __uuidof(ISensorEvents))
- {
- *ppv = static_cast<ISensorEvents*>(this);
- }
- else
- {
- *ppv = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- m_count = 0;
- return S_OK;
- }
- STDMETHODIMP_(ULONG) AddRef()
- {
- return InterlockedIncrement(&m_cRef);
- }
- STDMETHODIMP_(ULONG) Release()
- {
- ULONG count = InterlockedDecrement(&m_cRef);
- if (count == 0)
- {
- delete this;
- return 0;
- }
- return count;
- }
- //
- // ISensorEvents methods.
- //
- STDMETHODIMP OnEvent(
- ISensor *pSensor,
- REFGUID eventID,
- IPortableDeviceValues *pEventData)
- {
- HRESULT hr = S_OK;
- // Handle custom events here.
- return hr;
- }
- STDMETHODIMP OnLeave(
- REFSENSOR_ID sensorID)
- {
- HRESULT hr = S_OK;
- // Peform any housekeeping tasks for the sensor that is leaving.
- // For example, if you have maintained a reference to the sensor,
- // release it now and set the pointer to NULL.
- return hr;
- }
- STDMETHODIMP OnDataUpdated(ISensor *pSensor,ISensorDataReport *pNewData);
- STDMETHODIMP OnStateChanged(
- ISensor* pSensor,
- SensorState state)
- {
- HRESULT hr = S_OK;
- if(NULL == pSensor)
- {
- return E_INVALIDARG;
- }
- if(state == SENSOR_STATE_READY)
- {
- wprintf_s(L"\nTime sensor is now ready.");
- }
- else if(state == SENSOR_STATE_ACCESS_DENIED)
- {
- wprintf_s(L"\nNo permission for the time sensor.\n");
- wprintf_s(L"Enable the sensor in the control panel.\n");
- }
- return hr;
- }
- private:
- long m_cRef;
- int m_count;
- };
- #endif //__SENSOR_EVENT_H
|