Windows-classic-samples/Samples/AmbientLightAware/cpp/AmbientLightAwareSensorEvents.h
2025-11-28 00:35:46 +09:00

62 lines
2.4 KiB
C++

//-----------------------------------------------------------------------
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright © Microsoft Corporation. All rights reserved.
//
// Module:
// AmbientLightAwareSensorEvents.h
//
// Description:
// Implementation of ISensorEvents
//
// Comments:
// This is a standard c++ class, but needs to support IUnknown methods
// to be properly implemented. This class overrides ISensorEvents and
// functions to receive updated information from Sensors API when it
// is published.
//
//-----------------------------------------------------------------------
#pragma once
// Forward declarations.
class CAmbientLightAwareDlg;
class CAmbientLightAwareSensorManagerEvents;
class CAmbientLightAwareSensorEvents :
public ISensorEvents
{
public:
// These three methods are for IUnknown
STDMETHOD(QueryInterface)(REFIID riid, void** ppObject );
ULONG _stdcall AddRef();
ULONG _stdcall Release();
// Constructor and destructor
CAmbientLightAwareSensorEvents(CAmbientLightAwareDlg* dlg, CAmbientLightAwareSensorManagerEvents* sensorManagerEvents);
virtual ~CAmbientLightAwareSensorEvents();
// ISensorEvents method overrides
STDMETHOD(OnStateChanged)(__RPC__in_opt ISensor* pSensor, SensorState state);
STDMETHOD(OnDataUpdated)(__RPC__in_opt ISensor* pSensor, __RPC__in_opt ISensorDataReport* pNewData);
STDMETHOD(OnEvent)(__RPC__in_opt ISensor* pSensor, __RPC__in REFGUID eventID, __RPC__in_opt IPortableDeviceValues* pEventData);
STDMETHOD(OnLeave)(__RPC__in REFSENSOR_ID sensorID);
// Helper functions, also called by parent SensorManagerEvents class
HRESULT GetSensorData(ISensor* pSensor);
private:
// Member variable to implement IUnknown reference count
LONG m_lRefCount;
// Helper functions
HRESULT UpdateLux();
HRESULT GetSensorData(ISensor* pSensor, ISensorDataReport* pDataReport);
CAmbientLightAwareDlg* m_pParentDlg; // Parent dialog used for callbacks
CAmbientLightAwareSensorManagerEvents* m_pSensorManagerEvents; // Parent class for callbacks
CAtlMap<SENSOR_ID, float> m_mapLux; // Map to store lux values for each sensor
};