1998-10-19 21:48:55 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __nsRespository_h
|
|
|
|
#define __nsRespository_h
|
|
|
|
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "prlog.h"
|
|
|
|
#include "prmon.h"
|
|
|
|
#include "nsCom.h"
|
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsIFactory.h"
|
|
|
|
#include "nsHashtable.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prototypes for dynamic library export functions
|
|
|
|
*/
|
|
|
|
|
1999-01-25 11:05:00 +03:00
|
|
|
class nsIServiceManager;
|
|
|
|
|
|
|
|
|
|
|
|
//***********************************************************
|
|
|
|
//
|
|
|
|
// NSGetFactory should take nsISupports instead of nsIServiceManager
|
|
|
|
// as the second param. This is done on purpose!! Please don't change
|
|
|
|
// it.
|
|
|
|
// sudu / stanley
|
|
|
|
//
|
|
|
|
//***********************************************************
|
1998-10-19 21:48:55 +04:00
|
|
|
extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aClass,
|
1999-01-25 11:05:00 +03:00
|
|
|
nsISupports* serviceMgr,
|
1998-10-19 21:48:55 +04:00
|
|
|
nsIFactory **aFactory);
|
1999-02-03 10:03:17 +03:00
|
|
|
extern "C" NS_EXPORT PRBool NSCanUnload();
|
|
|
|
extern "C" NS_EXPORT nsresult NSRegisterSelf(const char *fullpath);
|
|
|
|
extern "C" NS_EXPORT nsresult NSUnregisterSelf(const char *fullpath);
|
1998-10-19 21:48:55 +04:00
|
|
|
|
1999-02-06 23:43:10 +03:00
|
|
|
/* Quick Registration
|
|
|
|
*
|
|
|
|
* For quick registration, dlls can define
|
|
|
|
* NSQuickRegisterClassData g_NSQuickRegisterData[];
|
|
|
|
* and export the symbol "g_NSQuickRegisterData"
|
|
|
|
*
|
|
|
|
* Quick registration is tried only if the symbol "NSRegisterSelf"
|
|
|
|
* is not found. If it is found but fails registration, quick registration
|
|
|
|
* will not kick in.
|
|
|
|
*
|
|
|
|
* The array is terminated by having a NULL last element. Specifically, the
|
|
|
|
* array will be assumed to end when
|
|
|
|
* (g_NSQuickRegisterData[i].classIdStr == NULL)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define NS_QUICKREGISTER_DATA_SYMBOL "g_NSQuickRegisterData"
|
|
|
|
|
|
|
|
typedef struct NSQuickRegisterClassData {
|
1999-02-09 23:29:46 +03:00
|
|
|
const char *CIDString; // {98765-8776-8958758759-958785}
|
|
|
|
const char *className; // "Layout Engine"
|
|
|
|
const char *progID; // "Gecko.LayoutEngine.1"
|
1999-02-06 23:43:10 +03:00
|
|
|
} NSQuickRegisterClassData;
|
|
|
|
|
|
|
|
typedef NSQuickRegisterClassData* NSQuickRegisterData;
|
|
|
|
|
|
|
|
/* Autoregistration will try only files with these extensions.
|
|
|
|
* All extensions are case insensitive.
|
|
|
|
".dll", // Windows
|
|
|
|
".dso", // Unix
|
|
|
|
".so", // Unix
|
1999-02-07 02:23:58 +03:00
|
|
|
".sl", // Unix: HP
|
1999-02-06 23:43:10 +03:00
|
|
|
"_dll", // Mac
|
|
|
|
".dlm", // new for all platforms
|
|
|
|
*/
|
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
/*
|
|
|
|
* Dynamic library export function types
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef nsresult (*nsFactoryProc)(const nsCID &aCLass,
|
1999-01-25 11:05:00 +03:00
|
|
|
nsISupports* serviceMgr,
|
1998-10-19 21:48:55 +04:00
|
|
|
nsIFactory **aFactory);
|
|
|
|
typedef PRBool (*nsCanUnloadProc)(void);
|
|
|
|
typedef nsresult (*nsRegisterProc)(const char *path);
|
|
|
|
typedef nsresult (*nsUnregisterProc)(const char *path);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Support types
|
|
|
|
*/
|
|
|
|
|
|
|
|
class FactoryEntry;
|
1999-02-03 18:39:13 +03:00
|
|
|
class nsDllStore;
|
1999-02-06 23:43:10 +03:00
|
|
|
class nsDll;
|
|
|
|
|
|
|
|
enum NSRegistrationInstant
|
|
|
|
{
|
|
|
|
NS_Startup = 0,
|
|
|
|
NS_Script = 1,
|
|
|
|
NS_Timer = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Error codes generated by the repository methods */
|
|
|
|
|
|
|
|
#define NS_XPCOM_ERRORCODE_IS_DIR 1
|
|
|
|
|
|
|
|
/* The separator for each path part in the pathlist for autoregistration */
|
|
|
|
|
|
|
|
#define NS_PATH_SEPARATOR ';'
|
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nsRepository class
|
|
|
|
*/
|
|
|
|
|
|
|
|
class NS_COM nsRepository {
|
|
|
|
private:
|
1999-02-06 23:43:10 +03:00
|
|
|
|
|
|
|
#define NS_MAX_FILENAME_LEN 1024
|
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
static nsHashtable *factories;
|
|
|
|
static PRMonitor *monitor;
|
|
|
|
|
|
|
|
static nsresult checkInitialized(void);
|
|
|
|
static nsresult loadFactory(FactoryEntry *aEntry, nsIFactory **aFactory);
|
1999-02-07 00:19:11 +03:00
|
|
|
static nsresult SelfRegisterDll(nsDll *dll);
|
|
|
|
static nsresult SelfUnregisterDll(nsDll *dll);
|
1999-02-07 02:23:58 +03:00
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
public:
|
1999-02-03 18:39:13 +03:00
|
|
|
static nsDllStore *dllStore;
|
1999-02-03 10:03:17 +03:00
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
static nsresult Initialize(void);
|
|
|
|
// Finds a factory for a specific class ID
|
|
|
|
static nsresult FindFactory(const nsCID &aClass,
|
|
|
|
nsIFactory **aFactory);
|
|
|
|
|
|
|
|
// Creates a class instance for a specific class ID
|
|
|
|
static nsresult CreateInstance(const nsCID &aClass,
|
|
|
|
nsISupports *aDelegate,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult);
|
|
|
|
|
|
|
|
// Creates a class instance for a specific class ID
|
1999-02-09 23:29:46 +03:00
|
|
|
/*
|
1998-10-19 21:48:55 +04:00
|
|
|
static nsresult CreateInstance2(const nsCID &aClass,
|
|
|
|
nsISupports *aDelegate,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void *aSignature,
|
|
|
|
void **aResult);
|
1999-02-09 23:29:46 +03:00
|
|
|
*/
|
1998-10-19 21:48:55 +04:00
|
|
|
|
|
|
|
// Manually registry a factory for a class
|
|
|
|
static nsresult RegisterFactory(const nsCID &aClass,
|
|
|
|
nsIFactory *aFactory,
|
|
|
|
PRBool aReplace);
|
|
|
|
|
|
|
|
// Manually registry a dynamically loaded factory for a class
|
|
|
|
static nsresult RegisterFactory(const nsCID &aClass,
|
|
|
|
const char *aLibrary,
|
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist);
|
|
|
|
|
|
|
|
// Manually unregister a factory for a class
|
|
|
|
static nsresult UnregisterFactory(const nsCID &aClass,
|
|
|
|
nsIFactory *aFactory);
|
|
|
|
|
|
|
|
// Manually unregister a dynamically loaded factory for a class
|
|
|
|
static nsresult UnregisterFactory(const nsCID &aClass,
|
|
|
|
const char *aLibrary);
|
|
|
|
|
|
|
|
// Unload dynamically loaded factories that are not in use
|
|
|
|
static nsresult FreeLibraries(void);
|
1999-02-03 18:39:13 +03:00
|
|
|
|
1999-02-06 23:43:10 +03:00
|
|
|
// DLL registration support
|
|
|
|
static nsresult AutoRegister(NSRegistrationInstant when,
|
|
|
|
const char* pathlist);
|
1999-02-07 02:23:58 +03:00
|
|
|
// Pathlist is a semicolon separated list of pathnames
|
1999-02-06 23:43:10 +03:00
|
|
|
static nsresult AddToDefaultPathList(const char *pathlist);
|
|
|
|
static nsresult SyncComponentsInPathList(const char *pathlist);
|
|
|
|
static nsresult SyncComponentsInDir(const char *path);
|
|
|
|
static nsresult SyncComponentsInFile(const char *fullname);
|
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|