зеркало из https://github.com/mozilla/pjs.git
XPCOM initialize primary event queue. 135531. r=brendan@mozilla.org, sr=darin@netscape.com
This commit is contained in:
Родитель
c5498dafed
Коммит
32a0618efe
|
@ -24,7 +24,6 @@
|
|||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentRegistrar.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIAppStartupNotifier.h"
|
||||
#include "nsIStringBundle.h"
|
||||
|
||||
|
@ -91,19 +90,6 @@ nsresult NS_InitEmbedding(nsILocalFile *mozBinDirectory,
|
|||
sXPCOMCleanupHack.mCleanOnExit = PR_TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Create the Event Queue for the UI thread...
|
||||
//
|
||||
// If an event queue already exists for the thread, then
|
||||
// CreateThreadEventQueue(...) will fail...
|
||||
// CreateThread0ueue(...) will fail...
|
||||
nsCOMPtr<nsIEventQueueService> eventQService(
|
||||
do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
eventQService->CreateThreadEventQueue();
|
||||
|
||||
// Register components
|
||||
if (!sRegistryInitializedFlag)
|
||||
{
|
||||
|
|
|
@ -45,11 +45,7 @@
|
|||
#include "nsIStringBundle.h"
|
||||
|
||||
|
||||
static nsIEventQueue* gEventQ = nsnull;
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kCookieServiceCID, NS_COOKIESERVICE_CID);
|
||||
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
|
||||
void SetACookie(nsICookieService *cookieService, const char* aSpec, const char* aCookieString) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
|
@ -92,16 +88,6 @@ int main(PRInt32 argc, char *argv[])
|
|||
nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
// Create the Event Queue for this thread...
|
||||
nsCOMPtr<nsIEventQueueService> eventQService =
|
||||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
|
||||
|
||||
nsCOMPtr<nsIStringBundleService> bundleService =
|
||||
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
|
|
|
@ -338,12 +338,6 @@ nsresult CoverageTest(int *argc, char **argv)
|
|||
return res;
|
||||
}
|
||||
|
||||
res = eventQService->CreateThreadEventQueue();
|
||||
if (NS_OK != res) {
|
||||
NS_ASSERTION(PR_FALSE, "Could not create the event queue for the thread");
|
||||
return res;
|
||||
}
|
||||
|
||||
// Create a application shell
|
||||
nsIAppShell *appShell;
|
||||
CallCreateInstance(kCAppShellCID, &appShell);
|
||||
|
|
|
@ -119,11 +119,6 @@ TM_OJIAPITest(ThreadManager_PostEvent_6) {
|
|||
|
||||
nsCOMPtr<nsIEventQueue> eventQueue = NULL;
|
||||
|
||||
lrc = eventService->CreateThreadEventQueue();
|
||||
if (lrc != NS_OK) {
|
||||
printf("Can'r create event queue ...\n");
|
||||
nsresult rc = NS_ERROR_FAILURE;
|
||||
}
|
||||
printf("Waiting for thread ID (%p) ...", &id);
|
||||
tm->EnterMonitor(&id);
|
||||
tm->ExitMonitor(&id);
|
||||
|
@ -204,11 +199,6 @@ TM_OJIAPITest(ThreadManager_PostEvent_7) {
|
|||
|
||||
nsCOMPtr<nsIEventQueue> eventQueue = NULL;
|
||||
|
||||
lrc = eventService->CreateThreadEventQueue();
|
||||
if (lrc != NS_OK) {
|
||||
printf("Can't create event queue ...\n");
|
||||
nsresult rc = NS_ERROR_FAILURE;
|
||||
}
|
||||
//tm->EnterMonitor(&id);
|
||||
printf("Waiting for thread ID (%p) ...", &id);
|
||||
while(!id);
|
||||
|
|
|
@ -2521,13 +2521,6 @@ void PR_CALLBACK scanimage_thread_routine( void * arg )
|
|||
return;
|
||||
}
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("Unable to create new thread event queue!\n");
|
||||
// Does this mean that an event queue is already at
|
||||
// our disposal?
|
||||
}
|
||||
|
||||
rv = eventQService->GetThreadEventQueue(pthis->mUIThread,
|
||||
getter_AddRefs(eventQ));
|
||||
if (NS_FAILED(rv)) {
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
#endif
|
||||
|
||||
#include "plstr.h"
|
||||
#include "nsIEventQueue.h"
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIComponentRegistrar.h"
|
||||
|
@ -56,7 +55,6 @@
|
|||
#include "nsINetService.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
|
@ -78,10 +76,6 @@
|
|||
|
||||
// Define CIDs...
|
||||
static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID);
|
||||
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
|
||||
// Define IIDs...
|
||||
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
|
||||
//NS_DEFINE_IID(kIPostToServerIID, NS_IPOSTTOSERVER_IID);
|
||||
|
||||
#ifdef XP_UNIX
|
||||
|
@ -243,7 +237,6 @@ int main(int argc, char **argv)
|
|||
nsAutoString url_address;
|
||||
// char buf[256];
|
||||
// nsIStreamListener *pConsumer;
|
||||
nsIEventQueueService* pEventQService;
|
||||
// nsIURL *pURL;
|
||||
nsresult result;
|
||||
int i;
|
||||
|
@ -262,21 +255,6 @@ int main(int argc, char **argv)
|
|||
testURL(argv[1]);
|
||||
return 0;
|
||||
#if 0
|
||||
nsRepository::RegisterComponent(
|
||||
kEventQueueServiceCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterComponent(
|
||||
kNetServiceCID, NULL, NULL, NETLIB_DLL, PR_FALSE, PR_FALSE);
|
||||
|
||||
// Create the Event Queue for this thread...
|
||||
pEventQService = nsnull;
|
||||
result = nsServiceManager::GetService(kEventQueueServiceCID,
|
||||
kIEventQueueServiceIID,
|
||||
(nsISupports **)&pEventQService);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
// XXX: What if this fails?
|
||||
result = pEventQService->CreateThreadEventQueue();
|
||||
}
|
||||
|
||||
for (i=1; i < argc; i++) {
|
||||
if (PL_strcasecmp(argv[i], "-all") == 0) {
|
||||
testURL(0);
|
||||
|
@ -285,11 +263,6 @@ int main(int argc, char **argv)
|
|||
|
||||
testURL(argv[i]);
|
||||
}
|
||||
|
||||
if (nsnull != pEventQService) {
|
||||
pEventQService->DestroyThreadEventQueue();
|
||||
nsServiceManager::ReleaseService(kEventQueueServiceCID, pEventQService);
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -151,9 +151,6 @@ main(int argc, char* argv[])
|
|||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
|
||||
|
||||
nsCOMPtr<nsICategoryManager> catman =
|
||||
|
|
|
@ -8,7 +8,6 @@ function getEventQueue()
|
|||
var nsIEventQueueService = Components.interfaces.nsIEventQueueService;
|
||||
var CID = Components.classes["@mozilla.org/event-queue-service;1"];
|
||||
var service = CID.getService(nsIEventQueueService);
|
||||
service.createThreadEventQueue();
|
||||
return service.getSpecialEventQueue(nsIEventQueueService.CURRENT_THREAD_EVENT_QUEUE);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ function getEventQueue()
|
|||
var nsIEventQueueService = Components.interfaces.nsIEventQueueService;
|
||||
var CID = Components.classes["@mozilla.org/event-queue-service;1"];
|
||||
var service = CID.getService(nsIEventQueueService);
|
||||
service.createThreadEventQueue();
|
||||
return service.getSpecialEventQueue(nsIEventQueueService.CURRENT_THREAD_EVENT_QUEUE);
|
||||
}
|
||||
|
||||
|
|
|
@ -260,9 +260,6 @@ InitQueue() {
|
|||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get event queue service");
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create event queue");
|
||||
|
||||
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &eventQueue);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get event queue for main thread");
|
||||
|
||||
|
|
|
@ -193,9 +193,6 @@ main(int argc, char* argv[])
|
|||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) goto error_exit;
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) goto error_exit;
|
||||
|
||||
eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(gEventQ));
|
||||
|
||||
/**
|
||||
|
|
|
@ -257,9 +257,6 @@ int main(int argc, char *argv[]) {
|
|||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
|
|
@ -112,10 +112,6 @@ public:
|
|||
nsCOMPtr<nsIEventQueueService> eventQService =
|
||||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &mEventQueue);
|
||||
}
|
||||
|
||||
|
|
|
@ -366,9 +366,6 @@ main(int argc, char* argv[])
|
|||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
|
|
@ -596,9 +596,6 @@ main(int argc, char* argv[])
|
|||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
|
||||
|
||||
int i;
|
||||
|
|
|
@ -268,9 +268,6 @@ InitQueue() {
|
|||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get event queue service");
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create event queue");
|
||||
|
||||
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &eventQueue);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get event queue for main thread");
|
||||
|
||||
|
|
|
@ -209,9 +209,6 @@ TestAsyncRead(const char* url)
|
|||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
|
|
@ -163,9 +163,6 @@ main(int argc, char* argv[])
|
|||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIEventQueue> eventQ;
|
||||
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eventQ));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
|
|
@ -375,9 +375,6 @@ TestConnection::Run(void)
|
|||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
//
|
||||
// Make sure that all resources were allocated in the constructor...
|
||||
//
|
||||
|
@ -641,9 +638,6 @@ main(int argc, char* argv[])
|
|||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
//
|
||||
// Create the connections and threads...
|
||||
//
|
||||
|
|
|
@ -59,16 +59,7 @@ createEventQueue() {
|
|||
nsCOMPtr<nsIEventQueueService> eqs =
|
||||
do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv);
|
||||
if ( NS_SUCCEEDED( rv ) ) {
|
||||
// Have service create us an event queue.
|
||||
rv = eqs->CreateThreadEventQueue();
|
||||
if ( NS_SUCCEEDED( rv ) ) {
|
||||
// Get the event queue it created. BTW, why the heck doesn't
|
||||
// CreateThreadEventQueue just return it?
|
||||
eqs->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(result));
|
||||
} else {
|
||||
printf( "%s %d: nsIEventQueueService::CreateThreadEventQueue failed, rv=0x%08X\n",
|
||||
(char*)__FILE__, (int)__LINE__, (int)rv );
|
||||
}
|
||||
} else {
|
||||
printf( "%s %d: NS_WITH_SERVICE(nsIEventQueueService) failed, rv=0x%08X\n",
|
||||
(char*)__FILE__, (int)__LINE__, (int)rv );
|
||||
|
|
|
@ -145,9 +145,6 @@ main(int argc, char* argv[])
|
|||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
|
||||
|
||||
|
||||
|
|
|
@ -138,9 +138,6 @@ main(int argc, char** argv)
|
|||
(nsISupports**) &theEventQueueService)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = theEventQueueService->CreateThreadEventQueue()))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = theEventQueueService->GetThreadEventQueue(NS_CURRENT_THREAD,
|
||||
&mainQueue)))
|
||||
goto done;
|
||||
|
|
|
@ -156,9 +156,6 @@ main(int argc, char** argv)
|
|||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
RETURN_IF_FAILED(rv, "EventQueueService");
|
||||
|
||||
rv = theEventQueueService->CreateThreadEventQueue();
|
||||
RETURN_IF_FAILED(rv, "CreateThreadEventQueue");
|
||||
|
||||
nsIEventQueue* eq = nsnull;
|
||||
rv = theEventQueueService->GetThreadEventQueue(NS_CURRENT_THREAD, &eq);
|
||||
RETURN_IF_FAILED(rv, "GetThreadEventQueue");
|
||||
|
|
|
@ -139,11 +139,6 @@ main(int argc, char** argv)
|
|||
goto done;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv = theEventQueueService->CreateThreadEventQueue())) {
|
||||
NS_ERROR("unable to create thread event queue");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv = theEventQueueService->GetThreadEventQueue(NS_CURRENT_THREAD,
|
||||
&mainQueue))) {
|
||||
NS_ERROR("unable to get event queue for current thread");
|
||||
|
|
|
@ -85,7 +85,6 @@ protected:
|
|||
|
||||
nsIAppShell* mAppShell;
|
||||
nsIPref* mPrefs;
|
||||
nsIEventQueueService* mEventQService;
|
||||
nsString mStartURL;
|
||||
PRBool mDoPurify;
|
||||
PRBool mLoadTestFromFile;
|
||||
|
|
|
@ -443,8 +443,7 @@ nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result,
|
|||
NS_CATEGORYMANAGER_CONTRACTID,
|
||||
categoryManagerFactory,
|
||||
PR_TRUE);
|
||||
if ( NS_FAILED(rv) )
|
||||
return rv;
|
||||
if ( NS_FAILED(rv) ) return rv;
|
||||
}
|
||||
|
||||
for (int i = 0; i < components_length; i++)
|
||||
|
@ -458,6 +457,12 @@ nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result,
|
|||
nsIInterfaceInfoManager* iim = XPTI_GetInterfaceInfoManager();
|
||||
NS_IF_RELEASE(iim);
|
||||
|
||||
nsCOMPtr<nsIEventQueueService> eventQService(do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv));
|
||||
if ( NS_FAILED(rv) ) return rv;
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if ( NS_FAILED(rv) ) return rv;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -507,6 +512,7 @@ NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine)
|
|||
//
|
||||
nsresult NS_COM NS_ShutdownXPCOM(nsIServiceManager* servMgr)
|
||||
{
|
||||
|
||||
// Notify observers of xpcom shutting down
|
||||
nsresult rv = NS_OK;
|
||||
{
|
||||
|
|
|
@ -1,192 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (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.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef XPCOM_STANDALONE
|
||||
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentRegistrar.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include <iostream.h> //BAD DOG -- no biscuit!
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
|
||||
#define TEST_URL "resource:/res/test.properties"
|
||||
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
static NS_DEFINE_CID(kEventQueueCID, NS_EVENTQUEUE_CID);
|
||||
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#endif
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
#ifndef XPCOM_STANDALONE
|
||||
nsresult ret;
|
||||
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMan;
|
||||
NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
|
||||
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
|
||||
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
|
||||
registrar->AutoRegister(nsnull);
|
||||
|
||||
// Create the Event Queue for this thread...
|
||||
nsCOMPtr<nsIEventQueueService> pEventQService =
|
||||
do_GetService(kEventQueueServiceCID);
|
||||
if (pEventQService)
|
||||
// XXX: What if this fails?
|
||||
pEventQService->CreateThreadEventQueue();
|
||||
|
||||
nsIInputStream* in = nsnull;
|
||||
|
||||
nsCOMPtr<nsIIOService> service(do_GetService(kIOServiceCID, &ret));
|
||||
if (NS_FAILED(ret)) return ret;
|
||||
|
||||
nsCOMPtr<nsIEventQueueService> eventQService =
|
||||
do_GetService(kEventQueueServiceCID, &ret);
|
||||
if (NS_FAILED(ret)) return ret;
|
||||
|
||||
nsIChannel *channel = nsnull;
|
||||
ret = service->NewChannel(NS_LITERAL_CSTRING(TEST_URL), nsnull, nsnull, &channel);
|
||||
if (NS_FAILED(ret)) return ret;
|
||||
|
||||
nsIEventQueue *eventQ = nsnull;
|
||||
ret = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &eventQ);
|
||||
if (NS_FAILED(ret)) return ret;
|
||||
|
||||
ret = channel->Open(&in);
|
||||
if (NS_FAILED(ret)) return ret;
|
||||
|
||||
nsIPersistentProperties* props = nsnull;
|
||||
ret = nsComponentManager::CreateInstance(kPersistentPropertiesCID, NULL,
|
||||
NS_GET_IID(nsIPersistentProperties), (void**) &props);
|
||||
if (NS_FAILED(ret) || (!props)) {
|
||||
printf("create nsIPersistentProperties failed\n");
|
||||
return 1;
|
||||
}
|
||||
ret = props->Load(in);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("cannot load properties\n");
|
||||
return 1;
|
||||
}
|
||||
int i = 1;
|
||||
while (1) {
|
||||
char name[16];
|
||||
name[0] = 0;
|
||||
sprintf(name, "%d", i);
|
||||
nsAutoString v;
|
||||
ret = props->GetStringProperty(NS_ConvertASCIItoUCS2(name), v);
|
||||
if (NS_FAILED(ret) || (!v.Length())) {
|
||||
break;
|
||||
}
|
||||
char* value = ToNewCString(v);
|
||||
if (value) {
|
||||
cout << "\"" << i << "\"=\"" << value << "\"" << endl;
|
||||
delete[] value;
|
||||
}
|
||||
else {
|
||||
printf("%d: ToNewCString failed\n", i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
nsIBidirectionalEnumerator* propEnum = nsnull;
|
||||
ret = props->EnumerateProperties(&propEnum);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("cannot enumerate properties\n");
|
||||
return 1;
|
||||
}
|
||||
ret = propEnum->First();
|
||||
if (NS_FAILED(ret))
|
||||
{
|
||||
printf("enumerator is empty\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
cout << endl << "Key" << "\t" << "Value" << endl;
|
||||
cout << "---" << "\t" << "-----" << endl;
|
||||
while (NS_SUCCEEDED(ret))
|
||||
{
|
||||
nsIPropertyElement* propElem = nsnull;
|
||||
ret = propEnum->CurrentItem((nsISupports**)&propElem);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("failed to get current item\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
PRUnichar *pKey = nsnull;
|
||||
PRUnichar *pVal = nsnull;
|
||||
|
||||
ret = propElem->GetKey(&pKey);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("failed to get current element's key\n");
|
||||
return 1;
|
||||
}
|
||||
ret = propElem->GetValue(&pVal);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("failed to get current element's value\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
nsAutoString keyAdjustedLengthBuff(pKey);
|
||||
nsAutoString valAdjustedLengthBuff(pVal);
|
||||
|
||||
char* keyCStr = ToNewCString(keyAdjustedLengthBuff);
|
||||
char* valCStr = ToNewCString(valAdjustedLengthBuff);
|
||||
if (keyCStr && valCStr)
|
||||
cout << keyCStr << "\t" << valCStr << endl;
|
||||
delete[] keyCStr;
|
||||
delete[] valCStr;
|
||||
delete[] pKey;
|
||||
delete[] pVal;
|
||||
ret = propEnum->Next();
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
|
@ -49,6 +49,7 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
|
||||
static PRBool gUnreg = PR_FALSE, gSilent = PR_FALSE, gQuiet = PR_FALSE;
|
||||
|
||||
|
@ -192,6 +193,12 @@ int main(int argc, char *argv[])
|
|||
|
||||
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
|
||||
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
|
||||
|
||||
nsCOMPtr<nsIEventQueueService> eventQService(do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// XXX: What if this fails?
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
}
|
||||
|
||||
/* With no arguments, RegFactory will autoregister */
|
||||
if (argc <= 1)
|
||||
|
|
Загрузка…
Ссылка в новой задаче