[PORTCLS] Centralize AddRef/Release implementation.

And make it thread-safe.

Co-authored-by: Thomas Faber <thomas.faber@reactos.org>
This commit is contained in:
Victor Perevertkin 2022-02-16 01:25:25 +03:00
parent 7db9fb3ba6
commit 6e97b4314f
No known key found for this signature in database
GPG key ID: C750B7222E9C7830
27 changed files with 81 additions and 548 deletions

View file

@ -25,36 +25,16 @@ RtlCreateUnicodeString(
); );
class CUnregisterPhysicalConnection : public IUnregisterPhysicalConnection class CUnregisterPhysicalConnection : public CUnknownImpl<IUnregisterPhysicalConnection>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IUnregisterPhysicalConnection; IMP_IUnregisterPhysicalConnection;
CUnregisterPhysicalConnection(IUnknown *OuterUnknown){} CUnregisterPhysicalConnection(IUnknown *OuterUnknown){}
virtual ~CUnregisterPhysicalConnection(){} virtual ~CUnregisterPhysicalConnection(){}
protected:
LONG m_Ref;
}; };
NTSTATUS NTSTATUS

View file

@ -14,7 +14,7 @@
#include <debug.h> #include <debug.h>
class CDmaChannelInit : public IDmaChannelInit class CDmaChannelInit : public CUnknownImpl<IDmaChannelInit>
{ {
public: public:
inline inline
@ -29,22 +29,6 @@ public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IDmaChannelInit; IMP_IDmaChannelInit;
CDmaChannelInit(IUnknown * OuterUnknown) : CDmaChannelInit(IUnknown * OuterUnknown) :
m_pDeviceObject(nullptr), m_pDeviceObject(nullptr),
@ -60,8 +44,7 @@ public:
m_Address({0}), m_Address({0}),
m_Buffer(nullptr), m_Buffer(nullptr),
m_Mdl(nullptr), m_Mdl(nullptr),
m_WriteToDevice(FALSE), m_WriteToDevice(FALSE)
m_Ref(0)
{ {
} }
virtual ~CDmaChannelInit(){} virtual ~CDmaChannelInit(){}
@ -89,8 +72,6 @@ protected:
BOOLEAN m_WriteToDevice; BOOLEAN m_WriteToDevice;
friend IO_ALLOCATION_ACTION NTAPI AdapterControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID MapRegisterBase, IN PVOID Context); friend IO_ALLOCATION_ACTION NTAPI AdapterControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID MapRegisterBase, IN PVOID Context);
LONG m_Ref;
}; };

View file

@ -14,34 +14,14 @@
#include <debug.h> #include <debug.h>
class CDrmPort2 : public IDrmPort2 class CDrmPort2 : public CUnknownImpl<IDrmPort2>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IDrmPort2; IMP_IDrmPort2;
CDrmPort2(IUnknown *OuterUnknown){} CDrmPort2(IUnknown *OuterUnknown){}
virtual ~CDrmPort2(){} virtual ~CDrmPort2(){}
protected:
LONG m_Ref;
}; };
NTSTATUS NTSTATUS

View file

@ -14,27 +14,11 @@
#include <debug.h> #include <debug.h>
class CPortFilterDMus : public IPortFilterDMus class CPortFilterDMus : public CUnknownImpl<IPortFilterDMus>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortFilterDMus; IMP_IPortFilterDMus;
CPortFilterDMus(IUnknown *OuterUnknown){} CPortFilterDMus(IUnknown *OuterUnknown){}
virtual ~CPortFilterDMus(){} virtual ~CPortFilterDMus(){}
@ -43,7 +27,6 @@ protected:
IPortDMus* m_Port; IPortDMus* m_Port;
IPortPinDMus ** m_Pins; IPortPinDMus ** m_Pins;
SUBDEVICE_DESCRIPTOR * m_Descriptor; SUBDEVICE_DESCRIPTOR * m_Descriptor;
LONG m_Ref;
}; };
NTSTATUS NTSTATUS

View file

@ -14,27 +14,11 @@
#include <debug.h> #include <debug.h>
class CPortFilterTopology : public IPortFilterTopology class CPortFilterTopology : public CUnknownImpl<IPortFilterTopology>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortFilterTopology; IMP_IPortFilterTopology;
CPortFilterTopology(IUnknown *OuterUnknown){} CPortFilterTopology(IUnknown *OuterUnknown){}
virtual ~CPortFilterTopology(){} virtual ~CPortFilterTopology(){}
@ -43,7 +27,6 @@ protected:
IPortTopology * m_Port; IPortTopology * m_Port;
SUBDEVICE_DESCRIPTOR * m_Descriptor; SUBDEVICE_DESCRIPTOR * m_Descriptor;
ISubdevice * m_SubDevice; ISubdevice * m_SubDevice;
LONG m_Ref;
}; };

View file

@ -14,27 +14,11 @@
#include <debug.h> #include <debug.h>
class CPortFilterWaveCyclic : public IPortFilterWaveCyclic class CPortFilterWaveCyclic : public CUnknownImpl<IPortFilterWaveCyclic>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortFilterWaveCyclic; IMP_IPortFilterWaveCyclic;
CPortFilterWaveCyclic(IUnknown *OuterUnknown){} CPortFilterWaveCyclic(IUnknown *OuterUnknown){}
virtual ~CPortFilterWaveCyclic(){} virtual ~CPortFilterWaveCyclic(){}
@ -44,7 +28,6 @@ protected:
IPortPinWaveCyclic ** m_Pins; IPortPinWaveCyclic ** m_Pins;
SUBDEVICE_DESCRIPTOR * m_Descriptor; SUBDEVICE_DESCRIPTOR * m_Descriptor;
ISubdevice * m_SubDevice; ISubdevice * m_SubDevice;
LONG m_Ref;
}; };
NTSTATUS NTSTATUS

View file

@ -14,27 +14,11 @@
#include <debug.h> #include <debug.h>
class CPortFilterWavePci : public IPortFilterWavePci class CPortFilterWavePci : public CUnknownImpl<IPortFilterWavePci>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortFilterPci; IMP_IPortFilterPci;
CPortFilterWavePci(IUnknown *OuterUnknown){} CPortFilterWavePci(IUnknown *OuterUnknown){}
virtual ~CPortFilterWavePci(){} virtual ~CPortFilterWavePci(){}
@ -43,8 +27,6 @@ protected:
IPortWavePci* m_Port; IPortWavePci* m_Port;
IPortPinWavePci ** m_Pins; IPortPinWavePci ** m_Pins;
SUBDEVICE_DESCRIPTOR * m_Descriptor; SUBDEVICE_DESCRIPTOR * m_Descriptor;
LONG m_Ref;
}; };
NTSTATUS NTSTATUS

View file

@ -14,38 +14,20 @@
#include <debug.h> #include <debug.h>
class CPortFilterWaveRT : public IPortFilterWaveRT class CPortFilterWaveRT : public CUnknownImpl<IPortFilterWaveRT>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortFilterWaveRT; IMP_IPortFilterWaveRT;
CPortFilterWaveRT(IUnknown *OuterUnknown){} CPortFilterWaveRT(IUnknown *OuterUnknown){}
virtual ~CPortFilterWaveRT(){} virtual ~CPortFilterWaveRT(){}
protected: protected:
IPortWaveRT* m_Port; IPortWaveRT* m_Port;
IPortPinWaveRT ** m_Pins; IPortPinWaveRT ** m_Pins;
SUBDEVICE_DESCRIPTOR * m_Descriptor; SUBDEVICE_DESCRIPTOR * m_Descriptor;
LONG m_Ref;
}; };
NTSTATUS NTSTATUS

View file

@ -21,27 +21,11 @@ typedef struct
PVOID DynamicContext; PVOID DynamicContext;
}SYNC_ENTRY, *PSYNC_ENTRY; }SYNC_ENTRY, *PSYNC_ENTRY;
class CInterruptSync : public IInterruptSync class CInterruptSync : public CUnknownImpl<IInterruptSync>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IInterruptSync; IMP_IInterruptSync;
CInterruptSync(IUnknown *OuterUnknown){} CInterruptSync(IUnknown *OuterUnknown){}
virtual ~CInterruptSync(){} virtual ~CInterruptSync(){}
@ -59,8 +43,6 @@ public:
PVOID m_DynamicContext; PVOID m_DynamicContext;
NTSTATUS m_Status; NTSTATUS m_Status;
LONG m_Ref;
friend BOOLEAN NTAPI CInterruptSynchronizedRoutine(IN PVOID ServiceContext); friend BOOLEAN NTAPI CInterruptSynchronizedRoutine(IN PVOID ServiceContext);
friend BOOLEAN NTAPI IInterruptServiceRoutine(IN PKINTERRUPT Interrupt, IN PVOID ServiceContext); friend BOOLEAN NTAPI IInterruptServiceRoutine(IN PKINTERRUPT Interrupt, IN PVOID ServiceContext);
}; };

View file

@ -39,27 +39,11 @@ RemoveHeadList_IRP(
/* no non canceled irp has been found */ /* no non canceled irp has been found */
return NULL; return NULL;
} }
class CIrpQueue : public IIrpQueue class CIrpQueue : public CUnknownImpl<IIrpQueue>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IIrpQueue; IMP_IIrpQueue;
CIrpQueue(IUnknown *OuterUnknown){} CIrpQueue(IUnknown *OuterUnknown){}
virtual ~CIrpQueue(){} virtual ~CIrpQueue(){}
@ -83,7 +67,6 @@ protected:
ULONG m_CurrentOffset; ULONG m_CurrentOffset;
PIRP m_Irp; PIRP m_Irp;
volatile LONG m_Ref;
}; };
typedef struct typedef struct

View file

@ -66,13 +66,9 @@ const ULONG kMPUInputBufferSize = 128;
* so it can expose this interface and CUnknown so it automatically gets * so it can expose this interface and CUnknown so it automatically gets
* reference counting and aggregation support. * reference counting and aggregation support.
*/ */
class CMiniportDMusUART class CMiniportDMusUART : public CUnknownImpl<IMiniportDMus, IMusicTechnology, IPowerNotify>
: public IMiniportDMus,
public IMusicTechnology,
public IPowerNotify
{ {
private: private:
LONG m_Ref; // Reference count
KSSTATE m_KSStateInput; // Miniport state (RUN/PAUSE/ACQUIRE/STOP) KSSTATE m_KSStateInput; // Miniport state (RUN/PAUSE/ACQUIRE/STOP)
PPORTDMUS m_pPort; // Callback interface. PPORTDMUS m_pPort; // Callback interface.
PUCHAR m_pPortBase; // Base port address. PUCHAR m_pPortBase; // Base port address.
@ -105,23 +101,6 @@ private:
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
CMiniportDMusUART(IUnknown * Unknown){} CMiniportDMusUART(IUnknown * Unknown){}
virtual ~CMiniportDMusUART(); virtual ~CMiniportDMusUART();
@ -204,10 +183,9 @@ public:
* so it can expose this interface and CUnknown so it automatically gets * so it can expose this interface and CUnknown so it automatically gets
* reference counting and aggregation support. * reference counting and aggregation support.
*/ */
class CMiniportDMusUARTStream : public IMXF class CMiniportDMusUARTStream : public CUnknownImpl<IMXF>
{ {
private: private:
LONG m_Ref; // Reference Count
CMiniportDMusUART * m_pMiniport; // Parent. CMiniportDMusUART * m_pMiniport; // Parent.
REFERENCE_TIME m_SnapshotTimeStamp; // Current snapshot of miniport's input timestamp. REFERENCE_TIME m_SnapshotTimeStamp; // Current snapshot of miniport's input timestamp.
PUCHAR m_pPortBase; // Base port address. PUCHAR m_pPortBase; // Base port address.
@ -230,23 +208,6 @@ private:
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
virtual ~CMiniportDMusUARTStream(); virtual ~CMiniportDMusUARTStream();
STDMETHODIMP_(NTSTATUS) Init STDMETHODIMP_(NTSTATUS) Init

View file

@ -14,27 +14,11 @@
#include <debug.h> #include <debug.h>
class CPortPinDMus : public IPortPinDMus class CPortPinDMus : public CUnknownImpl<IPortPinDMus>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortPinDMus; IMP_IPortPinDMus;
IMP_IServiceSink; IMP_IServiceSink;
IMP_IMasterClock; IMP_IMasterClock;
@ -76,8 +60,6 @@ protected:
ULONG m_PostCompleted; ULONG m_PostCompleted;
ULONG m_LastTag; ULONG m_LastTag;
LONG m_Ref;
}; };
typedef struct typedef struct

View file

@ -14,8 +14,7 @@
#include <debug.h> #include <debug.h>
class CPortPinWaveCyclic : public IPortPinWaveCyclic, class CPortPinWaveCyclic : public CUnknownImpl<IPortPinWaveCyclic, IServiceSink>
public IServiceSink
{ {
public: public:
inline inline
@ -30,22 +29,6 @@ public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortPinWaveCyclic; IMP_IPortPinWaveCyclic;
IMP_IServiceSink; IMP_IServiceSink;
CPortPinWaveCyclic(IUnknown *OuterUnknown) : CPortPinWaveCyclic(IUnknown *OuterUnknown) :
@ -73,8 +56,7 @@ public:
m_EventListLock(0), m_EventListLock(0),
m_EventList({nullptr}), m_EventList({nullptr}),
m_ResetState(KSRESET_BEGIN), m_ResetState(KSRESET_BEGIN),
m_Delay(0), m_Delay(0)
m_Ref(0)
{ {
} }
virtual ~CPortPinWaveCyclic(){} virtual ~CPortPinWaveCyclic(){}
@ -125,8 +107,6 @@ protected:
KSRESET m_ResetState; KSRESET m_ResetState;
ULONG m_Delay; ULONG m_Delay;
LONG m_Ref;
}; };

View file

@ -14,29 +14,11 @@
#include <debug.h> #include <debug.h>
class CPortPinWavePci : public IPortPinWavePci, class CPortPinWavePci : public CUnknownImpl<IPortPinWavePci, IServiceSink, IPortWavePciStream>
public IServiceSink,
public IPortWavePciStream
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortPinWavePci; IMP_IPortPinWavePci;
IMP_IServiceSink; IMP_IServiceSink;
IMP_IPortWavePciStream; IMP_IPortWavePciStream;
@ -74,8 +56,6 @@ protected:
KSALLOCATOR_FRAMING m_AllocatorFraming; KSALLOCATOR_FRAMING m_AllocatorFraming;
LONG m_Ref;
NTSTATUS NTAPI HandleKsProperty(IN PIRP Irp); NTSTATUS NTAPI HandleKsProperty(IN PIRP Irp);
NTSTATUS NTAPI HandleKsStream(IN PIRP Irp); NTSTATUS NTAPI HandleKsStream(IN PIRP Irp);
}; };

View file

@ -14,27 +14,11 @@
#include <debug.h> #include <debug.h>
class CPortPinWaveRT : public IPortPinWaveRT class CPortPinWaveRT : public CUnknownImpl<IPortPinWaveRT>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortPinWaveRT; IMP_IPortPinWaveRT;
CPortPinWaveRT(IUnknown *OuterUnknown){} CPortPinWaveRT(IUnknown *OuterUnknown){}
virtual ~CPortPinWaveRT(){} virtual ~CPortPinWaveRT(){}
@ -68,8 +52,6 @@ protected:
MEMORY_CACHING_TYPE m_CacheType; MEMORY_CACHING_TYPE m_CacheType;
PMDL m_Mdl; PMDL m_Mdl;
LONG m_Ref;
NTSTATUS NTAPI HandleKsProperty(IN PIRP Irp); NTSTATUS NTAPI HandleKsProperty(IN PIRP Irp);
NTSTATUS NTAPI HandleKsStream(IN PIRP Irp); NTSTATUS NTAPI HandleKsStream(IN PIRP Irp);
VOID NTAPI SetStreamState(IN KSSTATE State); VOID NTAPI SetStreamState(IN KSSTATE State);

View file

@ -14,28 +14,11 @@
#include <debug.h> #include <debug.h>
class CPortDMus : public IPortDMus, class CPortDMus : public CUnknownImpl<IPortDMus, ISubdevice>
public ISubdevice
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortDMus; IMP_IPortDMus;
IMP_ISubdevice; IMP_ISubdevice;
CPortDMus(IUnknown *OuterUnknown){} CPortDMus(IUnknown *OuterUnknown){}
@ -55,8 +38,6 @@ protected:
PPCFILTER_DESCRIPTOR m_pDescriptor; PPCFILTER_DESCRIPTOR m_pDescriptor;
PSUBDEVICE_DESCRIPTOR m_SubDeviceDescriptor; PSUBDEVICE_DESCRIPTOR m_SubDeviceDescriptor;
LONG m_Ref;
friend VOID GetDMusMiniport(IN IPortDMus * iface, IN PMINIPORTDMUS * Miniport, IN PMINIPORTMIDI * MidiMiniport); friend VOID GetDMusMiniport(IN IPortDMus * iface, IN PMINIPORTDMUS * Miniport, IN PMINIPORTMIDI * MidiMiniport);
}; };

View file

@ -14,29 +14,11 @@
#include <debug.h> #include <debug.h>
class CPortTopology : public IPortTopology, class CPortTopology : public CUnknownImpl<IPortTopology, ISubdevice, IPortEvents>
public ISubdevice,
public IPortEvents
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortTopology; IMP_IPortTopology;
IMP_ISubdevice; IMP_ISubdevice;
IMP_IPortEvents; IMP_IPortEvents;
@ -55,8 +37,6 @@ protected:
PSUBDEVICE_DESCRIPTOR m_SubDeviceDescriptor; PSUBDEVICE_DESCRIPTOR m_SubDeviceDescriptor;
IPortFilterTopology * m_Filter; IPortFilterTopology * m_Filter;
LONG m_Ref;
friend PMINIPORTTOPOLOGY GetTopologyMiniport(PPORTTOPOLOGY Port); friend PMINIPORTTOPOLOGY GetTopologyMiniport(PPORTTOPOLOGY Port);
}; };

View file

@ -16,32 +16,15 @@
GUID IID_IDmaChannelSlave; GUID IID_IDmaChannelSlave;
class CPortWaveCyclic : public IPortWaveCyclic, class CPortWaveCyclic : public CUnknownImpl<IPortWaveCyclic, IPortEvents, ISubdevice>
public IPortEvents,
public ISubdevice
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortWaveCyclic; IMP_IPortWaveCyclic;
IMP_ISubdevice; IMP_ISubdevice;
IMP_IPortEvents; IMP_IPortEvents;
CPortWaveCyclic(IUnknown *OuterUnknown) : m_Ref(0) {} CPortWaveCyclic(IUnknown *OuterUnknown) {}
virtual ~CPortWaveCyclic(){} virtual ~CPortWaveCyclic(){}
protected: protected:
@ -53,8 +36,6 @@ protected:
PSUBDEVICE_DESCRIPTOR m_SubDeviceDescriptor; PSUBDEVICE_DESCRIPTOR m_SubDeviceDescriptor;
IPortFilterWaveCyclic * m_Filter; IPortFilterWaveCyclic * m_Filter;
LONG m_Ref;
friend PMINIPORTWAVECYCLIC GetWaveCyclicMiniport(IN IPortWaveCyclic* iface); friend PMINIPORTWAVECYCLIC GetWaveCyclicMiniport(IN IPortWaveCyclic* iface);
friend PDEVICE_OBJECT GetDeviceObject(PPORTWAVECYCLIC iface); friend PDEVICE_OBJECT GetDeviceObject(PPORTWAVECYCLIC iface);
}; };

View file

@ -14,30 +14,11 @@
#include <debug.h> #include <debug.h>
class CPortWavePci : public IPortWavePci, class CPortWavePci : public CUnknownImpl<IPortWavePci, IPortEvents, ISubdevice, IServiceSink>
public IPortEvents,
public ISubdevice,
public IServiceSink
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortWavePci; IMP_IPortWavePci;
IMP_ISubdevice; IMP_ISubdevice;
IMP_IPortEvents; IMP_IPortEvents;
@ -59,8 +40,6 @@ protected:
LIST_ENTRY m_EventList; LIST_ENTRY m_EventList;
KSPIN_LOCK m_EventListLock; KSPIN_LOCK m_EventListLock;
LONG m_Ref;
friend PDEVICE_OBJECT GetDeviceObjectFromPortWavePci(IPortWavePci* iface); friend PDEVICE_OBJECT GetDeviceObjectFromPortWavePci(IPortWavePci* iface);
friend PMINIPORTWAVEPCI GetWavePciMiniport(PPORTWAVEPCI iface); friend PMINIPORTWAVEPCI GetWavePciMiniport(PPORTWAVEPCI iface);

View file

@ -14,29 +14,11 @@
#include <debug.h> #include <debug.h>
class CPortWaveRT : public IPortWaveRT, class CPortWaveRT : public CUnknownImpl<IPortWaveRT, IPortEvents, ISubdevice>
public IPortEvents,
public ISubdevice
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortWaveRT; IMP_IPortWaveRT;
IMP_ISubdevice; IMP_ISubdevice;
IMP_IPortEvents; IMP_IPortEvents;
@ -57,8 +39,6 @@ protected:
friend PMINIPORTWAVERT GetWaveRTMiniport(IN IPortWaveRT* iface); friend PMINIPORTWAVERT GetWaveRTMiniport(IN IPortWaveRT* iface);
friend PDEVICE_OBJECT GetDeviceObjectFromPortWaveRT(PPORTWAVERT iface); friend PDEVICE_OBJECT GetDeviceObjectFromPortWaveRT(PPORTWAVERT iface);
LONG m_Ref;
}; };
static GUID InterfaceGuids[3] = static GUID InterfaceGuids[3] =

View file

@ -14,34 +14,15 @@
#include <debug.h> #include <debug.h>
class CPortWaveRTStreamInit : public IPortWaveRTStreamInit class CPortWaveRTStreamInit : public CUnknownImpl<IPortWaveRTStreamInit>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortWaveRTStreamInit; IMP_IPortWaveRTStreamInit;
CPortWaveRTStreamInit(IUnknown *OuterUnknown) {} CPortWaveRTStreamInit(IUnknown *OuterUnknown) {}
virtual ~CPortWaveRTStreamInit() {} virtual ~CPortWaveRTStreamInit() {}
protected:
LONG m_Ref;
}; };
NTSTATUS NTSTATUS

View file

@ -439,4 +439,37 @@ typedef struct
PKSOBJECT_CREATE_ITEM CreateItem; PKSOBJECT_CREATE_ITEM CreateItem;
}DISPATCH_CONTEXT, *PDISPATCH_CONTEXT; }DISPATCH_CONTEXT, *PDISPATCH_CONTEXT;
template<typename... Interfaces>
class CUnknownImpl : public Interfaces...
{
private:
volatile LONG m_Ref;
protected:
CUnknownImpl() :
m_Ref(0)
{
}
virtual ~CUnknownImpl()
{
}
public:
STDMETHODIMP_(ULONG) AddRef()
{
ULONG Ref = InterlockedIncrement(&m_Ref);
ASSERT(Ref < 0x10000);
return Ref;
}
STDMETHODIMP_(ULONG) Release()
{
ULONG Ref = InterlockedDecrement(&m_Ref);
ASSERT(Ref < 0x10000);
if (!Ref)
{
delete this;
return 0;
}
return Ref;
}
};
#endif /* PORTCLS_PRIVATE_H */ #endif /* PORTCLS_PRIVATE_H */

View file

@ -14,30 +14,18 @@
#include <debug.h> #include <debug.h>
class CRegistryKey : public IRegistryKey class CRegistryKey : public CUnknownImpl<IRegistryKey>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IRegistryKey; IMP_IRegistryKey;
CRegistryKey(IUnknown * OuterUnknown, HANDLE hKey, BOOL CanDelete) : m_hKey(hKey), m_Deleted(FALSE), m_CanDelete(CanDelete), m_Ref(0){} CRegistryKey(IUnknown * OuterUnknown, HANDLE hKey, BOOL CanDelete) :
m_hKey(hKey),
m_Deleted(FALSE),
m_CanDelete(CanDelete)
{
}
virtual ~CRegistryKey(); virtual ~CRegistryKey();
protected: protected:
@ -45,7 +33,6 @@ protected:
HANDLE m_hKey; HANDLE m_hKey;
BOOL m_Deleted; BOOL m_Deleted;
BOOL m_CanDelete; BOOL m_CanDelete;
LONG m_Ref;
}; };
CRegistryKey::~CRegistryKey() CRegistryKey::~CRegistryKey()

View file

@ -17,31 +17,22 @@
#include <debug.h> #include <debug.h>
class CResourceList : public IResourceList class CResourceList : public CUnknownImpl<IResourceList>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IResourceList; IMP_IResourceList;
CResourceList(IUnknown * OuterUnknown) : m_OuterUnknown(OuterUnknown), m_PoolType(NonPagedPool), m_TranslatedResourceList(0), m_UntranslatedResourceList(0), m_NumberOfEntries(0), m_MaxEntries(0), m_Ref(0) {} CResourceList(IUnknown * OuterUnknown) :
m_OuterUnknown(OuterUnknown),
m_PoolType(NonPagedPool),
m_TranslatedResourceList(0),
m_UntranslatedResourceList(0),
m_NumberOfEntries(0),
m_MaxEntries(0)
{
}
virtual ~CResourceList(); virtual ~CResourceList();
public: public:
@ -51,7 +42,6 @@ public:
PCM_RESOURCE_LIST m_UntranslatedResourceList; PCM_RESOURCE_LIST m_UntranslatedResourceList;
ULONG m_NumberOfEntries; ULONG m_NumberOfEntries;
ULONG m_MaxEntries; ULONG m_MaxEntries;
LONG m_Ref;
}; };
CResourceList::~CResourceList() CResourceList::~CResourceList()
@ -461,7 +451,7 @@ PcNewResourceSublist(
/* Store members */ /* Store members */
NewList->m_OuterUnknown = OuterUnknown; NewList->m_OuterUnknown = OuterUnknown;
NewList->m_PoolType = PoolType; NewList->m_PoolType = PoolType;
NewList->m_Ref = 1; NewList->AddRef();
NewList->m_NumberOfEntries = 0; NewList->m_NumberOfEntries = 0;
NewList->m_MaxEntries = MaximumEntries; NewList->m_MaxEntries = MaximumEntries;

View file

@ -29,28 +29,11 @@ typedef struct
IN PSERVICESINK pServiceSink; IN PSERVICESINK pServiceSink;
}GROUP_ENTRY, *PGROUP_ENTRY; }GROUP_ENTRY, *PGROUP_ENTRY;
class CServiceGroup : public IServiceGroup class CServiceGroup : public CUnknownImpl<IServiceGroup>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IServiceGroup; IMP_IServiceGroup;
CServiceGroup(IUnknown * OuterUnknown); CServiceGroup(IUnknown * OuterUnknown);
virtual ~CServiceGroup() {} virtual ~CServiceGroup() {}
@ -65,9 +48,6 @@ protected:
KSPIN_LOCK m_Lock; KSPIN_LOCK m_Lock;
friend VOID NTAPI IServiceGroupDpc(IN struct _KDPC *Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2); friend VOID NTAPI IServiceGroupDpc(IN struct _KDPC *Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2);
LONG m_Ref;
}; };

View file

@ -14,37 +14,16 @@
#include <debug.h> #include <debug.h>
class CUnregisterSubdevice : public IUnregisterSubdevice class CUnregisterSubdevice : public CUnknownImpl<IUnregisterSubdevice>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IUnregisterSubdevice; IMP_IUnregisterSubdevice;
CUnregisterSubdevice(IUnknown * OuterUnknown) : m_Ref(0) {} CUnregisterSubdevice(IUnknown * OuterUnknown) {}
virtual ~CUnregisterSubdevice(){} virtual ~CUnregisterSubdevice(){}
protected:
LONG m_Ref;
}; };
NTSTATUS NTSTATUS

View file

@ -14,42 +14,20 @@
#include <debug.h> #include <debug.h>
class CPortClsVersion : public IPortClsVersion class CPortClsVersion : public CUnknownImpl<IPortClsVersion>
{ {
public: public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
STDMETHODIMP_(ULONG) AddRef()
{
InterlockedIncrement(&m_Ref);
return m_Ref;
}
STDMETHODIMP_(ULONG) Release()
{
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
delete this;
return 0;
}
return m_Ref;
}
IMP_IPortClsVersion; IMP_IPortClsVersion;
CPortClsVersion(IUnknown *OuterUnknown) CPortClsVersion(IUnknown *OuterUnknown)
{ {
m_Ref = 0;
} }
virtual ~CPortClsVersion() virtual ~CPortClsVersion()
{ {
} }
protected:
LONG m_Ref;
}; };