1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* The contents of this file are subject to the Mozilla Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/MPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
14
* Rusty Lynch <rusty.lynch@intel.com>
17
* Implements the SANE plugin factory class.
22
#include "nsIServiceManager.h"
23
#include "nsSanePlugin_CID.h"
24
#include "nsSanePlugin.h"
25
#include "nsSanePluginFactory.h"
28
#define PLUGIN_NAME "SANE Plugin"
29
#define PLUGIN_DESCRIPTION "SANE Plugin is a generic scanner interface"
30
#define PLUGIN_MIME_DESCRIPTION "application/X-sane-plugin::Scanner/Camera"
31
#define PLUGIN_MIME_TYPE "application/X-sane-plugin"
33
static NS_DEFINE_IID( kISupportsIID, NS_ISUPPORTS_IID );
34
static NS_DEFINE_IID( kIFactoryIID, NS_IFACTORY_IID );
35
static NS_DEFINE_IID( kIPluginIID, NS_IPLUGIN_IID );
36
static NS_DEFINE_CID( kComponentManagerCID, NS_COMPONENTMANAGER_CID );
37
static NS_DEFINE_CID( knsSanePluginControlCID, NS_SANE_PLUGIN_CONTROL_CID );
38
static NS_DEFINE_CID( knsSanePluginInst, NS_SANE_PLUGIN_CID );
40
////////////////////////////////////////////////////////////////////////
42
nsSanePluginFactoryImpl::nsSanePluginFactoryImpl( const nsCID &aClass,
43
const char* className,
44
const char* contractID )
45
: mClassID(aClass), mClassName(className), mContractID(contractID)
48
printf("nsSanePluginFactoryImpl::nsSanePluginFactoryImpl()\n");
52
nsSanePluginFactoryImpl::~nsSanePluginFactoryImpl()
55
printf("nsSanePluginFactoryImpl::~nsSanePluginFactoryImpl()\n");
58
printf("mRefCnt = %i\n", mRefCnt);
59
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
63
nsSanePluginFactoryImpl::QueryInterface(const nsIID &aIID,
67
printf("nsSanePluginFactoryImpl::QueryInterface()\n");
71
return NS_ERROR_NULL_POINTER;
73
if (aIID.Equals(kISupportsIID)) {
74
*aInstancePtr = NS_STATIC_CAST(nsISupports*,this);
75
} else if (aIID.Equals(kIFactoryIID)) {
76
*aInstancePtr = NS_STATIC_CAST(nsISupports*,
77
NS_STATIC_CAST(nsIFactory*,this));
78
} else if (aIID.Equals(kIPluginIID)) {
79
*aInstancePtr = NS_STATIC_CAST(nsISupports*,
80
NS_STATIC_CAST(nsIPlugin*,this));
82
*aInstancePtr = nsnull;
83
return NS_ERROR_NO_INTERFACE;
86
NS_ADDREF(NS_REINTERPRET_CAST(nsISupports*,*aInstancePtr));
91
// Standard implementation of AddRef and Release
92
NS_IMPL_ADDREF( nsSanePluginFactoryImpl )
93
NS_IMPL_RELEASE( nsSanePluginFactoryImpl )
96
nsSanePluginFactoryImpl::CreateInstance( nsISupports *aOuter,
101
printf("nsSanePluginFactoryImpl::CreateInstance()\n");
105
return NS_ERROR_NULL_POINTER;
108
return NS_ERROR_NO_AGGREGATION;
110
nsSanePluginInstance * inst = new nsSanePluginInstance();
112
return NS_ERROR_OUT_OF_MEMORY;
120
nsSanePluginFactoryImpl::LockFactory(PRBool aLock)
123
printf("nsSanePluginFactoryImpl::LockFactory()\n");
126
// Needs to be implemented
133
nsSanePluginFactoryImpl::Initialize()
136
printf("nsSanePluginFactoryImpl::Initialize()\n");
144
nsSanePluginFactoryImpl::Shutdown( void )
147
printf("nsSanePluginFactoryImpl::Shutdown()\n");
155
nsSanePluginFactoryImpl::GetMIMEDescription(const char* *result)
158
printf("nsSanePluginFactoryImpl::GetMIMEDescription()\n");
161
// caller is responsible for releasing
162
*result = PL_strdup( PLUGIN_MIME_DESCRIPTION );
168
nsSanePluginFactoryImpl::GetValue( nsPluginVariable variable, void *value )
171
printf("nsSanePluginFactoryImpl::GetValue()\n");
174
nsresult err = NS_OK;
176
if ( variable == nsPluginVariable_NameString ) {
178
*( ( char ** )value ) = strdup( PLUGIN_NAME );
180
} else if ( variable == nsPluginVariable_DescriptionString ) {
182
*( ( char ** )value ) = strdup( PLUGIN_DESCRIPTION );
186
err = NS_ERROR_FAILURE;
195
nsSanePluginFactoryImpl::CreatePluginInstance( nsISupports *aOuter,
197
const char* aPluginMIMEType,
201
printf("nsSanePluginFactoryImpl::CreatePluginInstance()\n");
204
// Need to find out what this is used for. The npsimple
205
// plugin looks like it just does a CreateInstance and
206
// ignores the mime type.
207
return NS_ERROR_NOT_IMPLEMENTED;
211
////////////////////////////////////////////////////////////////////////
214
* The XPCOM runtime will call this to get a new factory object for the
215
* CID/contractID it passes in. XPCOM is responsible for caching the resulting
218
* return the proper factory to the caller
220
extern "C" PR_IMPLEMENT(nsresult)
221
NSGetFactory( nsISupports* aServMgr,
223
const char *aClassName,
224
const char *aContractID,
225
nsIFactory **aFactory)
228
return NS_ERROR_NULL_POINTER;
230
nsSanePluginFactoryImpl* factory = new nsSanePluginFactoryImpl(aClass,
233
if ( factory == nsnull )
234
return NS_ERROR_OUT_OF_MEMORY;
244
extern "C" PR_IMPLEMENT( nsresult )
245
NSRegisterSelf( nsISupports* aServMgr, const char* aPath )
249
nsCOMPtr<nsIServiceManager> servMgr( do_QueryInterface( aServMgr, &rv ) );
250
if ( NS_FAILED( rv ) )
253
nsCOMPtr<nsIComponentManager> compMgr =
254
do_GetService( kComponentManagerCID, &rv );
255
if ( NS_FAILED( rv ) )
258
// Register the plugin control portion.
259
rv = compMgr->RegisterComponent(knsSanePluginControlCID,
260
"SANE Plugin Control",
261
"@mozilla.org/plugins/sane-control;1",
262
aPath, PR_TRUE, PR_TRUE );
264
// Register the plugin portion.
266
contractID.AssignWithConversion( NS_INLINE_PLUGIN_CONTRACTID_PREFIX );
268
contractID.AppendWithConversion(PLUGIN_MIME_TYPE);
269
buf = ( char * )calloc( 2000, sizeof( char ) );
270
contractID.ToCString( buf, 1999 );
272
rv = compMgr->RegisterComponent( knsSanePluginInst,
273
"SANE Plugin Component",
275
aPath, PR_TRUE, PR_TRUE);
278
if ( NS_FAILED( rv ) )
285
extern "C" PR_IMPLEMENT( nsresult )
286
NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
290
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
291
if (NS_FAILED(rv)) return rv;
293
nsCOMPtr<nsIComponentManager> compMgr =
294
do_GetService(kComponentManagerCID, &rv);
295
if (NS_FAILED(rv)) return rv;
297
rv = compMgr->UnregisterComponent(knsSanePluginControlCID, aPath);
298
if (NS_FAILED(rv)) return rv;