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*
|
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()
|
2014-05-05 10:30:39 -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;
|
|
|
|
}
|
|
|
|
|
2014-05-05 10:30:39 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
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
|
2007-03-22 10:30:00 -07:00
|
|
|
nsErrorService::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
|
|
|
|
{
|
2014-05-05 10:30:39 -07:00
|
|
|
if (NS_WARN_IF(outer))
|
|
|
|
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
|
2012-08-22 08:56:38 -07:00
|
|
|
nsErrorService::RegisterErrorStringBundle(int16_t errorModule, const char *stringBundleURL)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-05-05 10:30:39 -07:00
|
|
|
return mErrorStringBundleURLMap.Put(errorModule, stringBundleURL);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsErrorService::UnregisterErrorStringBundle(int16_t errorModule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-05-05 10:30:39 -07:00
|
|
|
return mErrorStringBundleURLMap.Remove(errorModule);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2014-05-05 10:30:39 -07:00
|
|
|
char* value = mErrorStringBundleURLMap.Get(errorModule);
|
|
|
|
if (value == nullptr)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
*result = value;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|