1/*
2 *  IOFireWireLibIUnknown.cpp
3 *  IOFireWireFamily
4 *
5 *  Created by Niels on Thu Feb 27 2003.
6 *  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
7 *
8 *	$ Log:IOFireWireLibIUnknown.cpp,v $
9 */
10
11#import "IOFireWireLibIUnknown.h"
12#import <assert.h>
13#import <string.h>		// bzero
14
15namespace IOFireWireLib {
16
17	IOFireWireIUnknown::IOFireWireIUnknown( const IUnknownVTbl & interface )
18	: mInterface( interface, this ),
19	  mRefCount(1)
20	{
21	}
22#if IOFIREWIRELIBDEBUG
23	IOFireWireIUnknown::~IOFireWireIUnknown()
24	{
25		bzero( this, sizeof( IOFireWireIUnknown ) ) ;
26	}
27#endif
28
29	// static
30	HRESULT
31	IOFireWireIUnknown::SQueryInterface(void* self, REFIID iid, void** ppv)
32	{
33		return IOFireWireIUnknown::InterfaceMap<IOFireWireIUnknown>::GetThis(self)->QueryInterface(iid, ppv) ;
34	}
35
36	UInt32
37	IOFireWireIUnknown::SAddRef(void* self)
38	{
39		return IOFireWireIUnknown::InterfaceMap<IOFireWireIUnknown>::GetThis(self)->AddRef() ;
40	}
41
42	ULONG
43	IOFireWireIUnknown::SRelease(void* self)
44	{
45		return IOFireWireIUnknown::InterfaceMap<IOFireWireIUnknown>::GetThis(self)->Release() ;
46	}
47
48	ULONG
49	IOFireWireIUnknown::AddRef()
50	{
51		return ++mRefCount ;
52	}
53
54	ULONG
55	IOFireWireIUnknown::Release()
56	{
57		assert( mRefCount > 0) ;
58
59		UInt32 newCount = mRefCount;
60
61		if (mRefCount == 1)
62		{
63			mRefCount = 0 ;
64			delete this ;
65		}
66		else
67			mRefCount-- ;
68
69		return newCount ;
70	}
71} // namespace
72