[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:
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;
CUnregisterPhysicalConnection(IUnknown *OuterUnknown){}
virtual ~CUnregisterPhysicalConnection(){}
protected:
LONG m_Ref;
};
NTSTATUS

View file

@ -14,7 +14,7 @@
#include <debug.h>
class CDmaChannelInit : public IDmaChannelInit
class CDmaChannelInit : public CUnknownImpl<IDmaChannelInit>
{
public:
inline
@ -29,22 +29,6 @@ public:
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;
CDmaChannelInit(IUnknown * OuterUnknown) :
m_pDeviceObject(nullptr),
@ -60,8 +44,7 @@ public:
m_Address({0}),
m_Buffer(nullptr),
m_Mdl(nullptr),
m_WriteToDevice(FALSE),
m_Ref(0)
m_WriteToDevice(FALSE)
{
}
virtual ~CDmaChannelInit(){}
@ -89,8 +72,6 @@ protected:
BOOLEAN m_WriteToDevice;
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>
class CDrmPort2 : public IDrmPort2
class CDrmPort2 : public CUnknownImpl<IDrmPort2>
{
public:
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;
CDrmPort2(IUnknown *OuterUnknown){}
virtual ~CDrmPort2(){}
protected:
LONG m_Ref;
};
NTSTATUS

View file

@ -14,27 +14,11 @@
#include <debug.h>
class CPortFilterDMus : public IPortFilterDMus
class CPortFilterDMus : public CUnknownImpl<IPortFilterDMus>
{
public:
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;
CPortFilterDMus(IUnknown *OuterUnknown){}
virtual ~CPortFilterDMus(){}
@ -43,7 +27,6 @@ protected:
IPortDMus* m_Port;
IPortPinDMus ** m_Pins;
SUBDEVICE_DESCRIPTOR * m_Descriptor;
LONG m_Ref;
};
NTSTATUS

View file

@ -14,27 +14,11 @@
#include <debug.h>
class CPortFilterTopology : public IPortFilterTopology
class CPortFilterTopology : public CUnknownImpl<IPortFilterTopology>
{
public:
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;
CPortFilterTopology(IUnknown *OuterUnknown){}
virtual ~CPortFilterTopology(){}
@ -43,7 +27,6 @@ protected:
IPortTopology * m_Port;
SUBDEVICE_DESCRIPTOR * m_Descriptor;
ISubdevice * m_SubDevice;
LONG m_Ref;
};

View file

@ -14,27 +14,11 @@
#include <debug.h>
class CPortFilterWaveCyclic : public IPortFilterWaveCyclic
class CPortFilterWaveCyclic : public CUnknownImpl<IPortFilterWaveCyclic>
{
public:
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;
CPortFilterWaveCyclic(IUnknown *OuterUnknown){}
virtual ~CPortFilterWaveCyclic(){}
@ -44,7 +28,6 @@ protected:
IPortPinWaveCyclic ** m_Pins;
SUBDEVICE_DESCRIPTOR * m_Descriptor;
ISubdevice * m_SubDevice;
LONG m_Ref;
};
NTSTATUS

View file

@ -14,27 +14,11 @@
#include <debug.h>
class CPortFilterWavePci : public IPortFilterWavePci
class CPortFilterWavePci : public CUnknownImpl<IPortFilterWavePci>
{
public:
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;
CPortFilterWavePci(IUnknown *OuterUnknown){}
virtual ~CPortFilterWavePci(){}
@ -43,8 +27,6 @@ protected:
IPortWavePci* m_Port;
IPortPinWavePci ** m_Pins;
SUBDEVICE_DESCRIPTOR * m_Descriptor;
LONG m_Ref;
};
NTSTATUS

View file

@ -14,38 +14,20 @@
#include <debug.h>
class CPortFilterWaveRT : public IPortFilterWaveRT
class CPortFilterWaveRT : public CUnknownImpl<IPortFilterWaveRT>
{
public:
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;
CPortFilterWaveRT(IUnknown *OuterUnknown){}
virtual ~CPortFilterWaveRT(){}
protected:
IPortWaveRT* m_Port;
IPortPinWaveRT ** m_Pins;
SUBDEVICE_DESCRIPTOR * m_Descriptor;
LONG m_Ref;
};
NTSTATUS

View file

@ -21,27 +21,11 @@ typedef struct
PVOID DynamicContext;
}SYNC_ENTRY, *PSYNC_ENTRY;
class CInterruptSync : public IInterruptSync
class CInterruptSync : public CUnknownImpl<IInterruptSync>
{
public:
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;
CInterruptSync(IUnknown *OuterUnknown){}
virtual ~CInterruptSync(){}
@ -59,8 +43,6 @@ public:
PVOID m_DynamicContext;
NTSTATUS m_Status;
LONG m_Ref;
friend BOOLEAN NTAPI CInterruptSynchronizedRoutine(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 */
return NULL;
}
class CIrpQueue : public IIrpQueue
class CIrpQueue : public CUnknownImpl<IIrpQueue>
{
public:
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;
CIrpQueue(IUnknown *OuterUnknown){}
virtual ~CIrpQueue(){}
@ -83,7 +67,6 @@ protected:
ULONG m_CurrentOffset;
PIRP m_Irp;
volatile LONG m_Ref;
};
typedef struct

View file

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

View file

@ -14,27 +14,11 @@
#include <debug.h>
class CPortPinDMus : public IPortPinDMus
class CPortPinDMus : public CUnknownImpl<IPortPinDMus>
{
public:
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_IServiceSink;
IMP_IMasterClock;
@ -76,8 +60,6 @@ protected:
ULONG m_PostCompleted;
ULONG m_LastTag;
LONG m_Ref;
};
typedef struct

View file

@ -14,8 +14,7 @@
#include <debug.h>
class CPortPinWaveCyclic : public IPortPinWaveCyclic,
public IServiceSink
class CPortPinWaveCyclic : public CUnknownImpl<IPortPinWaveCyclic, IServiceSink>
{
public:
inline
@ -30,22 +29,6 @@ public:
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_IServiceSink;
CPortPinWaveCyclic(IUnknown *OuterUnknown) :
@ -73,8 +56,7 @@ public:
m_EventListLock(0),
m_EventList({nullptr}),
m_ResetState(KSRESET_BEGIN),
m_Delay(0),
m_Ref(0)
m_Delay(0)
{
}
virtual ~CPortPinWaveCyclic(){}
@ -125,8 +107,6 @@ protected:
KSRESET m_ResetState;
ULONG m_Delay;
LONG m_Ref;
};

View file

@ -14,29 +14,11 @@
#include <debug.h>
class CPortPinWavePci : public IPortPinWavePci,
public IServiceSink,
public IPortWavePciStream
class CPortPinWavePci : public CUnknownImpl<IPortPinWavePci, IServiceSink, IPortWavePciStream>
{
public:
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_IServiceSink;
IMP_IPortWavePciStream;
@ -74,8 +56,6 @@ protected:
KSALLOCATOR_FRAMING m_AllocatorFraming;
LONG m_Ref;
NTSTATUS NTAPI HandleKsProperty(IN PIRP Irp);
NTSTATUS NTAPI HandleKsStream(IN PIRP Irp);
};

View file

@ -14,27 +14,11 @@
#include <debug.h>
class CPortPinWaveRT : public IPortPinWaveRT
class CPortPinWaveRT : public CUnknownImpl<IPortPinWaveRT>
{
public:
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;
CPortPinWaveRT(IUnknown *OuterUnknown){}
virtual ~CPortPinWaveRT(){}
@ -68,8 +52,6 @@ protected:
MEMORY_CACHING_TYPE m_CacheType;
PMDL m_Mdl;
LONG m_Ref;
NTSTATUS NTAPI HandleKsProperty(IN PIRP Irp);
NTSTATUS NTAPI HandleKsStream(IN PIRP Irp);
VOID NTAPI SetStreamState(IN KSSTATE State);

View file

@ -14,28 +14,11 @@
#include <debug.h>
class CPortDMus : public IPortDMus,
public ISubdevice
class CPortDMus : public CUnknownImpl<IPortDMus, ISubdevice>
{
public:
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_ISubdevice;
CPortDMus(IUnknown *OuterUnknown){}
@ -55,8 +38,6 @@ protected:
PPCFILTER_DESCRIPTOR m_pDescriptor;
PSUBDEVICE_DESCRIPTOR m_SubDeviceDescriptor;
LONG m_Ref;
friend VOID GetDMusMiniport(IN IPortDMus * iface, IN PMINIPORTDMUS * Miniport, IN PMINIPORTMIDI * MidiMiniport);
};

View file

@ -14,29 +14,11 @@
#include <debug.h>
class CPortTopology : public IPortTopology,
public ISubdevice,
public IPortEvents
class CPortTopology : public CUnknownImpl<IPortTopology, ISubdevice, IPortEvents>
{
public:
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_ISubdevice;
IMP_IPortEvents;
@ -55,8 +37,6 @@ protected:
PSUBDEVICE_DESCRIPTOR m_SubDeviceDescriptor;
IPortFilterTopology * m_Filter;
LONG m_Ref;
friend PMINIPORTTOPOLOGY GetTopologyMiniport(PPORTTOPOLOGY Port);
};

View file

@ -16,32 +16,15 @@
GUID IID_IDmaChannelSlave;
class CPortWaveCyclic : public IPortWaveCyclic,
public IPortEvents,
public ISubdevice
class CPortWaveCyclic : public CUnknownImpl<IPortWaveCyclic, IPortEvents, ISubdevice>
{
public:
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_ISubdevice;
IMP_IPortEvents;
CPortWaveCyclic(IUnknown *OuterUnknown) : m_Ref(0) {}
CPortWaveCyclic(IUnknown *OuterUnknown) {}
virtual ~CPortWaveCyclic(){}
protected:
@ -53,8 +36,6 @@ protected:
PSUBDEVICE_DESCRIPTOR m_SubDeviceDescriptor;
IPortFilterWaveCyclic * m_Filter;
LONG m_Ref;
friend PMINIPORTWAVECYCLIC GetWaveCyclicMiniport(IN IPortWaveCyclic* iface);
friend PDEVICE_OBJECT GetDeviceObject(PPORTWAVECYCLIC iface);
};

View file

@ -14,30 +14,11 @@
#include <debug.h>
class CPortWavePci : public IPortWavePci,
public IPortEvents,
public ISubdevice,
public IServiceSink
class CPortWavePci : public CUnknownImpl<IPortWavePci, IPortEvents, ISubdevice, IServiceSink>
{
public:
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_ISubdevice;
IMP_IPortEvents;
@ -59,8 +40,6 @@ protected:
LIST_ENTRY m_EventList;
KSPIN_LOCK m_EventListLock;
LONG m_Ref;
friend PDEVICE_OBJECT GetDeviceObjectFromPortWavePci(IPortWavePci* iface);
friend PMINIPORTWAVEPCI GetWavePciMiniport(PPORTWAVEPCI iface);

View file

@ -14,29 +14,11 @@
#include <debug.h>
class CPortWaveRT : public IPortWaveRT,
public IPortEvents,
public ISubdevice
class CPortWaveRT : public CUnknownImpl<IPortWaveRT, IPortEvents, ISubdevice>
{
public:
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_ISubdevice;
IMP_IPortEvents;
@ -57,8 +39,6 @@ protected:
friend PMINIPORTWAVERT GetWaveRTMiniport(IN IPortWaveRT* iface);
friend PDEVICE_OBJECT GetDeviceObjectFromPortWaveRT(PPORTWAVERT iface);
LONG m_Ref;
};
static GUID InterfaceGuids[3] =
@ -145,7 +125,7 @@ CPortWaveRT::QueryInterface(
IsEqualGUIDAligned(refiid, IID_IUnknown))
{
*Output = PVOID(PPORTWAVERT(this));
PUNKNOWN(*Output)->AddRef();
PUNKNOWN(*Output)->AddRef();
return STATUS_SUCCESS;
}
else if (IsEqualGUIDAligned(refiid, IID_IPortEvents))

View file

@ -14,34 +14,15 @@
#include <debug.h>
class CPortWaveRTStreamInit : public IPortWaveRTStreamInit
class CPortWaveRTStreamInit : public CUnknownImpl<IPortWaveRTStreamInit>
{
public:
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;
CPortWaveRTStreamInit(IUnknown *OuterUnknown) {}
virtual ~CPortWaveRTStreamInit() {}
protected:
LONG m_Ref;
};
NTSTATUS

View file

@ -439,4 +439,37 @@ typedef struct
PKSOBJECT_CREATE_ITEM CreateItem;
}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 */

View file

@ -14,30 +14,18 @@
#include <debug.h>
class CRegistryKey : public IRegistryKey
class CRegistryKey : public CUnknownImpl<IRegistryKey>
{
public:
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;
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();
protected:
@ -45,7 +33,6 @@ protected:
HANDLE m_hKey;
BOOL m_Deleted;
BOOL m_CanDelete;
LONG m_Ref;
};
CRegistryKey::~CRegistryKey()

View file

@ -17,31 +17,22 @@
#include <debug.h>
class CResourceList : public IResourceList
class CResourceList : public CUnknownImpl<IResourceList>
{
public:
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;
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();
public:
@ -51,7 +42,6 @@ public:
PCM_RESOURCE_LIST m_UntranslatedResourceList;
ULONG m_NumberOfEntries;
ULONG m_MaxEntries;
LONG m_Ref;
};
CResourceList::~CResourceList()
@ -461,7 +451,7 @@ PcNewResourceSublist(
/* Store members */
NewList->m_OuterUnknown = OuterUnknown;
NewList->m_PoolType = PoolType;
NewList->m_Ref = 1;
NewList->AddRef();
NewList->m_NumberOfEntries = 0;
NewList->m_MaxEntries = MaximumEntries;

View file

@ -29,28 +29,11 @@ typedef struct
IN PSERVICESINK pServiceSink;
}GROUP_ENTRY, *PGROUP_ENTRY;
class CServiceGroup : public IServiceGroup
class CServiceGroup : public CUnknownImpl<IServiceGroup>
{
public:
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;
CServiceGroup(IUnknown * OuterUnknown);
virtual ~CServiceGroup() {}
@ -65,9 +48,6 @@ protected:
KSPIN_LOCK m_Lock;
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>
class CUnregisterSubdevice : public IUnregisterSubdevice
class CUnregisterSubdevice : public CUnknownImpl<IUnregisterSubdevice>
{
public:
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;
CUnregisterSubdevice(IUnknown * OuterUnknown) : m_Ref(0) {}
CUnregisterSubdevice(IUnknown * OuterUnknown) {}
virtual ~CUnregisterSubdevice(){}
protected:
LONG m_Ref;
};
NTSTATUS

View file

@ -14,42 +14,20 @@
#include <debug.h>
class CPortClsVersion : public IPortClsVersion
class CPortClsVersion : public CUnknownImpl<IPortClsVersion>
{
public:
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;
CPortClsVersion(IUnknown *OuterUnknown)
{
m_Ref = 0;
}
virtual ~CPortClsVersion()
{
}
protected:
LONG m_Ref;
};