]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/ExplorerPlugin/ClassFactory.cpp
mDNSResponder-379.27.tar.gz
[apple/mdnsresponder.git] / Clients / ExplorerPlugin / ClassFactory.cpp
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #include "StdAfx.h"
19
20 #include "DebugServices.h"
21
22 #include "ExplorerBar.h"
23 #include "ExplorerPlugin.h"
24
25 #include "ClassFactory.h"
26
27 // MFC Debugging
28
29 #ifdef _DEBUG
30 #define new DEBUG_NEW
31 #undef THIS_FILE
32 static char THIS_FILE[] = __FILE__;
33 #endif
34
35 //===========================================================================================================================
36 // ClassFactory
37 //===========================================================================================================================
38
39 ClassFactory::ClassFactory( CLSID inCLSID )
40 {
41 mCLSIDObject = inCLSID;
42 mRefCount = 1;
43 ++gDLLRefCount;
44 }
45
46 //===========================================================================================================================
47 // ~ClassFactory
48 //===========================================================================================================================
49
50 ClassFactory::~ClassFactory( void )
51 {
52 check( gDLLRefCount > 0 );
53
54 --gDLLRefCount;
55 }
56
57 #if 0
58 #pragma mark -
59 #pragma mark == IUnknown methods ==
60 #endif
61
62 //===========================================================================================================================
63 // QueryInterface
64 //===========================================================================================================================
65
66 STDMETHODIMP ClassFactory::QueryInterface( REFIID inID, LPVOID *outResult )
67 {
68 HRESULT err;
69
70 check( outResult );
71
72 if( IsEqualIID( inID, IID_IUnknown ) )
73 {
74 *outResult = this;
75 }
76 else if( IsEqualIID( inID, IID_IClassFactory ) )
77 {
78 *outResult = (IClassFactory *) this;
79 }
80 else
81 {
82 *outResult = NULL;
83 err = E_NOINTERFACE;
84 goto exit;
85 }
86
87 ( *( (LPUNKNOWN *) outResult ) )->AddRef();
88 err = S_OK;
89
90 exit:
91 return( err );
92 }
93
94 //===========================================================================================================================
95 // AddRef
96 //===========================================================================================================================
97
98 STDMETHODIMP_( DWORD ) ClassFactory::AddRef( void )
99 {
100 return( ++mRefCount );
101 }
102
103 //===========================================================================================================================
104 // Release
105 //===========================================================================================================================
106
107 STDMETHODIMP_( DWORD ) ClassFactory::Release( void )
108 {
109 DWORD count;
110
111 count = --mRefCount;
112 if( count == 0 )
113 {
114 delete this;
115 }
116 return( count );
117 }
118
119 #if 0
120 #pragma mark -
121 #pragma mark == IClassFactory methods ==
122 #endif
123
124 //===========================================================================================================================
125 // CreateInstance
126 //===========================================================================================================================
127
128 STDMETHODIMP ClassFactory::CreateInstance( LPUNKNOWN inUnknown, REFIID inID, LPVOID *outObject )
129 {
130 HRESULT err;
131 LPVOID obj;
132
133 check( outObject );
134
135 obj = NULL;
136 *outObject = NULL;
137 require_action( !inUnknown, exit, err = CLASS_E_NOAGGREGATION );
138
139 // Create the object based on the CLSID.
140
141 if( IsEqualCLSID( mCLSIDObject, CLSID_ExplorerBar ) )
142 {
143 try
144 {
145 obj = new ExplorerBar();
146 }
147 catch( ... )
148 {
149 // Don't let exception escape.
150 }
151 require_action( obj, exit, err = E_OUTOFMEMORY );
152 }
153 else
154 {
155 err = E_FAIL;
156 goto exit;
157 }
158
159 // Query for the specified interface. Release the factory since QueryInterface retains it.
160
161 err = ( (LPUNKNOWN ) obj )->QueryInterface( inID, outObject );
162 ( (LPUNKNOWN ) obj )->Release();
163
164 exit:
165 return( err );
166 }
167
168 //===========================================================================================================================
169 // LockServer
170 //===========================================================================================================================
171
172 STDMETHODIMP ClassFactory::LockServer( BOOL inLock )
173 {
174 DEBUG_UNUSED( inLock );
175
176 return( E_NOTIMPL );
177 }