summaryrefslogtreecommitdiffstats
path: root/mDNSResponder/Clients/ExplorerPlugin/ClassFactory.cpp
blob: e578e23935f5f3d941da87e8f3e141ab4313363f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* -*- Mode: C; tab-width: 4 -*-
 *
 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

#include	"StdAfx.h"

#include	"DebugServices.h"

#include	"ExplorerBar.h"
#include	"ExplorerPlugin.h"

#include	"ClassFactory.h"

// MFC Debugging

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//===========================================================================================================================
//	ClassFactory
//===========================================================================================================================

ClassFactory::ClassFactory( CLSID inCLSID )
{
	mCLSIDObject 	= inCLSID;
	mRefCount		= 1;
	++gDLLRefCount;
}

//===========================================================================================================================
//	~ClassFactory
//===========================================================================================================================

ClassFactory::~ClassFactory( void )
{
	check( gDLLRefCount > 0 );
	
	--gDLLRefCount;
}

#if 0
#pragma mark -
#pragma mark == IUnknown methods ==
#endif

//===========================================================================================================================
//	QueryInterface
//===========================================================================================================================

STDMETHODIMP	ClassFactory::QueryInterface( REFIID inID, LPVOID *outResult )
{
	HRESULT		err;
	
	check( outResult );
	
	if( IsEqualIID( inID, IID_IUnknown ) )
	{
		*outResult = this;
	}
	else if( IsEqualIID( inID, IID_IClassFactory ) )
	{
		*outResult = (IClassFactory *) this;
	}   
	else
	{
		*outResult = NULL;
		err = E_NOINTERFACE;
		goto exit;
	}
	
	( *( (LPUNKNOWN *) outResult ) )->AddRef();
	err = S_OK;
	
exit:
	return( err );
}                                             

//===========================================================================================================================
//	AddRef
//===========================================================================================================================

STDMETHODIMP_( DWORD )	ClassFactory::AddRef( void )
{
	return( ++mRefCount );
}

//===========================================================================================================================
//	Release
//===========================================================================================================================

STDMETHODIMP_( DWORD )	ClassFactory::Release( void )
{
	DWORD		count;
	
	count = --mRefCount;
	if( count == 0 )
	{
		delete this;
	}
	return( count );
}

#if 0
#pragma mark -
#pragma mark == IClassFactory methods ==
#endif

//===========================================================================================================================
//	CreateInstance
//===========================================================================================================================

STDMETHODIMP	ClassFactory::CreateInstance( LPUNKNOWN inUnknown, REFIID inID, LPVOID *outObject )
{
	HRESULT		err;
	LPVOID		obj;
	
	check( outObject );
	
	obj 		= NULL;
	*outObject 	= NULL;
	require_action( !inUnknown, exit, err = CLASS_E_NOAGGREGATION );
	
	// Create the object based on the CLSID.
	
	if( IsEqualCLSID( mCLSIDObject, CLSID_ExplorerBar ) )
	{
		try
		{
			obj = new ExplorerBar();
		}
		catch( ... )
		{
			// Don't let exception escape.
		}
		require_action( obj, exit, err = E_OUTOFMEMORY );
	}
	else
	{
		err = E_FAIL;
		goto exit;
	}
	
	// Query for the specified interface. Release the factory since QueryInterface retains it.
		
	err = ( (LPUNKNOWN ) obj )->QueryInterface( inID, outObject );
	( (LPUNKNOWN ) obj )->Release();
	
exit:
	return( err );
}

//===========================================================================================================================
//	LockServer
//===========================================================================================================================

STDMETHODIMP	ClassFactory::LockServer( BOOL inLock )
{
	DEBUG_UNUSED( inLock );
	
	return( E_NOTIMPL );
}