2014-05-05 10:30:39 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
2013-09-19 11:29:31 -07:00
|
|
|
#include "nsCRTGlue.h"
|
2013-08-05 08:16:53 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static void*
|
2014-05-09 13:47:36 -07:00
|
|
|
CloneCString(nsHashKey *aKey, void *aData, void* aClosure)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
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
|
2014-05-09 13:47:36 -07:00
|
|
|
DeleteCString(nsHashKey *aKey, void *aData, void* aClosure)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
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()
|
2014-05-05 10:30:39 -07:00
|
|
|
: mHashtable(CloneCString, nullptr, DeleteCString, nullptr, 16)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-05-09 13:47:36 -07:00
|
|
|
nsInt2StrHashtable::Put(uint32_t aKey, 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;
|
2014-05-09 13:47:36 -07:00
|
|
|
nsPRUint32Key k(aKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-05-05 10:30:39 -07:00
|
|
|
char*
|
2014-05-09 13:47:36 -07:00
|
|
|
nsInt2StrHashtable::Get(uint32_t aKey)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-05-09 13:47:36 -07:00
|
|
|
nsPRUint32Key k(aKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
2014-05-09 13:47:36 -07:00
|
|
|
nsInt2StrHashtable::Remove(uint32_t aKey)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-05-09 13:47:36 -07:00
|
|
|
nsPRUint32Key k(aKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsErrorService, nsIErrorService)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsresult
|
2014-05-09 13:47:36 -07:00
|
|
|
nsErrorService::Create(nsISupports* aOuter, const nsIID& aIID, void** aInstancePtr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-05-09 13:47:36 -07:00
|
|
|
if (NS_WARN_IF(aOuter))
|
2014-05-05 10:30:39 -07:00
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
nsRefPtr<nsErrorService> serv = new nsErrorService();
|
|
|
|
return serv->QueryInterface(aIID, aInstancePtr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-09 13:47:36 -07:00
|
|
|
nsErrorService::RegisterErrorStringBundle(int16_t aErrorModule, const char* aStringBundleURL)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-05-09 13:47:36 -07:00
|
|
|
return mErrorStringBundleURLMap.Put(aErrorModule, aStringBundleURL);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-09 13:47:36 -07:00
|
|
|
nsErrorService::UnregisterErrorStringBundle(int16_t aErrorModule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-05-09 13:47:36 -07:00
|
|
|
return mErrorStringBundleURLMap.Remove(aErrorModule);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-09 13:47:36 -07:00
|
|
|
nsErrorService::GetErrorStringBundle(int16_t aErrorModule, char** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-05-09 13:47:36 -07:00
|
|
|
char* value = mErrorStringBundleURLMap.Get(aErrorModule);
|
2014-05-05 10:30:39 -07:00
|
|
|
if (value == nullptr)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2014-05-09 13:47:36 -07:00
|
|
|
*aResult = value;
|
2014-05-05 10:30:39 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|