2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsErrorService.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static void*
|
2007-03-22 10:30:00 -07:00
|
|
|
CloneCString(nsHashKey *aKey, void *aData, void* closure)
|
|
|
|
{
|
2009-03-25 06:19:08 -07:00
|
|
|
return NS_strdup((const char*)aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
DeleteCString(nsHashKey *aKey, void *aData, void* closure)
|
|
|
|
{
|
2009-03-25 06:19:08 -07:00
|
|
|
NS_Free(aData);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsInt2StrHashtable::nsInt2StrHashtable()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mHashtable(CloneCString, nullptr, DeleteCString, nullptr, 16)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsInt2StrHashtable::Put(uint32_t key, const char* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-03-25 06:19:08 -07:00
|
|
|
char* value = NS_strdup(aData);
|
2012-07-30 07:20:58 -07:00
|
|
|
if (value == nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
nsPRUint32Key k(key);
|
|
|
|
char* oldValue = (char*)mHashtable.Put(&k, value);
|
|
|
|
if (oldValue)
|
2009-04-11 09:33:52 -07:00
|
|
|
NS_Free(oldValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
2012-08-22 08:56:38 -07:00
|
|
|
nsInt2StrHashtable::Get(uint32_t key)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsPRUint32Key k(key);
|
|
|
|
const char* value = (const char*)mHashtable.Get(&k);
|
2012-07-30 07:20:58 -07:00
|
|
|
if (value == nullptr)
|
|
|
|
return nullptr;
|
2009-03-25 06:19:08 -07:00
|
|
|
return NS_strdup(value);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsInt2StrHashtable::Remove(uint32_t key)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsPRUint32Key k(key);
|
|
|
|
char* oldValue = (char*)mHashtable.Remove(&k);
|
|
|
|
if (oldValue)
|
2009-04-11 09:33:52 -07:00
|
|
|
NS_Free(oldValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsErrorService, nsIErrorService)
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsErrorService::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_ENSURE_NO_AGGREGATION(outer);
|
|
|
|
nsErrorService* serv = new nsErrorService();
|
2012-07-30 07:20:58 -07:00
|
|
|
if (serv == nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(serv);
|
|
|
|
nsresult rv = serv->QueryInterface(aIID, aInstancePtr);
|
|
|
|
NS_RELEASE(serv);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsErrorService::RegisterErrorStringBundle(int16_t errorModule, const char *stringBundleURL)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mErrorStringBundleURLMap.Put(errorModule, stringBundleURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsErrorService::UnregisterErrorStringBundle(int16_t errorModule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mErrorStringBundleURLMap.Remove(errorModule);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsErrorService::GetErrorStringBundle(int16_t errorModule, char **result)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
char* value = mErrorStringBundleURLMap.Get(errorModule);
|
2012-07-30 07:20:58 -07:00
|
|
|
if (value == nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
*result = value;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsErrorService::RegisterErrorStringBundleKey(nsresult error, const char *stringBundleKey)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
return mErrorStringBundleKeyMap.Put(static_cast<uint32_t>(error),
|
2012-08-09 01:36:40 -07:00
|
|
|
stringBundleKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsErrorService::UnregisterErrorStringBundleKey(nsresult error)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
return mErrorStringBundleKeyMap.Remove(static_cast<uint32_t>(error));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsErrorService::GetErrorStringBundleKey(nsresult error, char **result)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
char* value = mErrorStringBundleKeyMap.Get(static_cast<uint32_t>(error));
|
2012-07-30 07:20:58 -07:00
|
|
|
if (value == nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
*result = value;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|