本文整理汇总了C++中CallGetService函数的典型用法代码示例。如果您正苦于以下问题:C++ CallGetService函数的具体用法?C++ CallGetService怎么用?C++ CallGetService使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CallGetService函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mGLPbuffer
nsCanvasRenderingContextGLPrivate::nsCanvasRenderingContextGLPrivate()
: mGLPbuffer(nsnull), mWidth(0), mHeight(0), mCanvasElement(nsnull)
{
// grab the xpconnect service
if (!gXPConnect) {
nsresult rv = CallGetService(nsIXPConnect::GetCID(), &gXPConnect);
if (NS_FAILED(rv)) {
NS_ERROR("Failed to get XPConnect!");
return;
}
} else {
NS_ADDREF(gXPConnect);
}
if (!gJSRuntimeService) {
nsresult rv = CallGetService("@mozilla.org/js/xpc/RuntimeService;1",
&gJSRuntimeService);
if (NS_FAILED(rv)) {
// uh..
NS_ERROR("Failed to get JS RuntimeService!");
return;
}
gJSRuntimeService->GetRuntime(&gScriptRuntime);
if (!gScriptRuntime) {
NS_RELEASE(gJSRuntimeService);
gJSRuntimeService = nsnull;
NS_ERROR("Unable to get JS runtime from JS runtime service");
}
} else {
NS_ADDREF(gJSRuntimeService);
}
}
示例2: main
int main()
{
/*
* NOTE: This does NOT demonstrate how these functions are
* intended to be used. They are intended for filling in out
* parameters that need to be |AddRef|ed. I'm just too lazy
* to write lots of little getter functions for a test program
* when I don't need to.
*/
NS_NOTREACHED("This test is not intended to run, only to compile!");
/* Test CallQueryInterface */
nsISupports *mySupportsPtr = reinterpret_cast<nsISupports*>(0x1000);
nsITestService *myITestService = nsnull;
CallQueryInterface(mySupportsPtr, &myITestService);
nsTestService *myTestService =
reinterpret_cast<nsTestService*>(mySupportsPtr);
nsISupportsWeakReference *mySupportsWeakRef;
CallQueryInterface(myTestService, &mySupportsWeakRef);
nsCOMPtr<nsISupports> mySupportsCOMPtr = mySupportsPtr;
CallQueryInterface(mySupportsCOMPtr, &myITestService);
nsRefPtr<nsTestService> myTestServiceRefPtr = myTestService;
CallQueryInterface(myTestServiceRefPtr, &mySupportsWeakRef);
/* Test CallQueryReferent */
nsIWeakReference *myWeakRef =
static_cast<nsIWeakReference*>(mySupportsPtr);
CallQueryReferent(myWeakRef, &myITestService);
/* Test CallCreateInstance */
CallCreateInstance(kTestServiceCID, mySupportsPtr, &myITestService);
CallCreateInstance(kTestServiceCID, &myITestService);
CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, mySupportsPtr,
&myITestService);
CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, &myITestService);
/* Test CallGetService */
CallGetService(kTestServiceCID, &myITestService);
CallGetService(NS_TEST_SERVICE_CONTRACTID, &myITestService);
/* Test CallGetInterface */
nsIInterfaceRequestor *myInterfaceRequestor =
static_cast<nsIInterfaceRequestor*>(mySupportsPtr);
CallGetInterface(myInterfaceRequestor, &myITestService);
return 0;
}
示例3: TEST
TEST(LineBreak, WordBreaker)
{
nsIWordBreaker *t = nullptr;
nsresult res = CallGetService(kWBrkCID, &t);
ASSERT_TRUE(NS_SUCCEEDED(res) && t);
NS_IF_RELEASE(t);
res = CallGetService(kWBrkCID, &t);
ASSERT_TRUE(NS_SUCCEEDED(res) && t);
ASSERT_TRUE(TestASCIIWB(t, teng1, wexp1, sizeof(wexp1) / sizeof(uint32_t)));
ASSERT_TRUE(TestASCIIWB(t, teng2, wexp2, sizeof(wexp2) / sizeof(uint32_t)));
ASSERT_TRUE(TestASCIIWB(t, teng3, wexp3, sizeof(wexp3) / sizeof(uint32_t)));
NS_RELEASE(t);
}
示例4: init
nsresult init()
{
nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
if (NS_FAILED(rv))
return rv;
return CallGetService(kCharsetConverterManagerCID, &ccMan);
}
示例5: TEST
TEST(NormalizationTest, Main) {
if (sizeof(wchar_t) != 2) {
printf("This test can only be run where sizeof(wchar_t) == 2\n");
return;
}
if (strlen(versionText) == 0) {
printf("No testcases: to run the tests generate the header file using\n");
printf(" perl genNormalizationData.pl\n");
printf("in intl/unichar/tools and rebuild\n");
return;
}
printf("NormalizationTest: test nsIUnicodeNormalizer. UCD version: %s\n",
versionText);
normalizer = nullptr;
nsresult res;
res = CallGetService(kUnicodeNormalizerCID, &normalizer);
ASSERT_FALSE(NS_FAILED(res)) << "GetService failed";
ASSERT_NE(nullptr, normalizer);
TestPart0();
TestPart1();
TestPart2();
TestPart3();
NS_RELEASE(normalizer);
}
示例6: AsyncNoShutdownTest
nsresult
AsyncNoShutdownTest(int testNumber)
{
// This test gets a service, and also gets an async request for shutdown,
// but the service doesn't get shut down because some other client (who's
// not participating in the async shutdown game as he should) is
// continuing to hang onto the service. This causes myServ variable to
// get set to NULL, but the service doesn't get unloaded right away as
// it should.
nsresult err;
err = BeginTest(testNumber);
if (err != NS_OK) return err;
// Create some other user of kIMyServiceCID, preventing it from
// really going away:
IMyService* otherClient;
err = CallGetService(kIMyServiceCID, &otherClient);
if (err != NS_OK) return err;
err = AsyncShutdown(testNumber);
if (err != NS_OK) return err;
err = EndTest(testNumber);
// Finally, release the other client.
NS_RELEASE(otherClient);
return err;
}
示例7: NS_NAMED_LITERAL_CSTRING
nsresult
nsDirIndexParser::Init() {
mLineStart = 0;
mHasDescription = PR_FALSE;
mFormat = nsnull;
// get default charset to be used for directory listings (fallback to
// ISO-8859-1 if pref is unavailable).
NS_NAMED_LITERAL_CSTRING(kFallbackEncoding, "ISO-8859-1");
nsXPIDLString defCharset;
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefs) {
nsCOMPtr<nsIPrefLocalizedString> prefVal;
prefs->GetComplexValue("intl.charset.default",
NS_GET_IID(nsIPrefLocalizedString),
getter_AddRefs(prefVal));
if (prefVal)
prefVal->ToString(getter_Copies(defCharset));
}
if (!defCharset.IsEmpty())
LossyCopyUTF16toASCII(defCharset, mEncoding); // charset labels are always ASCII
else
mEncoding.Assign(kFallbackEncoding);
nsresult rv;
// XXX not threadsafe
if (gRefCntParser++ == 0)
rv = CallGetService(NS_ITEXTTOSUBURI_CONTRACTID, &gTextToSubURI);
else
rv = NS_OK;
return rv;
}
示例8: CallGetService
nsresult
nsXULContentUtils::Init()
{
if (gRefCnt++ == 0) {
nsresult rv = CallGetService(kRDFServiceCID, &gRDF);
if (NS_FAILED(rv)) {
return rv;
}
#define XUL_RESOURCE(ident, uri) \
PR_BEGIN_MACRO \
rv = gRDF->GetResource(NS_LITERAL_CSTRING(uri), &(ident)); \
if (NS_FAILED(rv)) return rv; \
PR_END_MACRO
#define XUL_LITERAL(ident, val) \
PR_BEGIN_MACRO \
rv = gRDF->GetLiteral(NS_LITERAL_STRING(val).get(), &(ident)); \
if (NS_FAILED(rv)) return rv; \
PR_END_MACRO
#include "nsXULResourceList.h"
#undef XUL_RESOURCE
#undef XUL_LITERAL
rv = CallCreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &gFormat);
if (NS_FAILED(rv)) {
return rv;
}
}
return NS_OK;
}
示例9: NS_NOTREACHED
nsresult
nsDownloadManager::Init()
{
if (gRefCnt++ != 0) {
NS_NOTREACHED("download manager should be used as a service");
return NS_ERROR_UNEXPECTED; // This will make the |CreateInstance| fail.
}
if (!mCurrDownloads.Init())
return NS_ERROR_FAILURE;
nsresult rv;
mRDFContainerUtils = do_GetService("@mozilla.org/rdf/container-utils;1", &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIObserverService> obsService = do_GetService("@mozilla.org/observer-service;1", &rv);
if (NS_FAILED(rv)) return rv;
rv = CallGetService("@mozilla.org/rdf/rdf-service;1", &gRDFService);
if (NS_FAILED(rv)) return rv;
gRDFService->GetResource(NS_LITERAL_CSTRING("NC:DownloadsRoot"), &gNC_DownloadsRoot);
gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "File"), &gNC_File);
gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "URL"), &gNC_URL);
gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Name"), &gNC_Name);
gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "ProgressMode"), &gNC_ProgressMode);
gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "ProgressPercent"), &gNC_ProgressPercent);
gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Transferred"), &gNC_Transferred);
gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "DownloadState"), &gNC_DownloadState);
gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "StatusText"), &gNC_StatusText);
nsCAutoString downloadsDB;
rv = GetProfileDownloadsFileURL(downloadsDB);
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetDataSourceBlocking(downloadsDB.get(), getter_AddRefs(mDataSource));
if (NS_FAILED(rv)) return rv;
mListener = do_CreateInstance("@mozilla.org/download-manager/listener;1", &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
rv = bundleService->CreateBundle(DOWNLOAD_MANAGER_BUNDLE, getter_AddRefs(mBundle));
if (NS_FAILED(rv))
return rv;
// The following two AddObserver calls must be the last lines in this function,
// because otherwise, this function may fail (and thus, this object would be not
// completely initialized), but the observerservice would still keep a reference
// to us and notify us about shutdown, which may cause crashes.
// failure to add an observer is not critical
obsService->AddObserver(this, "profile-before-change", PR_FALSE);
obsService->AddObserver(this, "profile-approve-change", PR_FALSE);
return NS_OK;
}
示例10: InitGlobals
static nsresult InitGlobals()
{
CallGetService(NS_PREF_CONTRACTID, &gPref);
if (!gPref) return NS_ERROR_FAILURE;
gFontMetricsCache = new nsHashtable();
return NS_OK;
}
示例11: BeginTest
nsresult
BeginTest(int testNumber)
{
nsresult err;
NS_ASSERTION(myServ == NULL, "myServ not reset");
err = CallGetService(kIMyServiceCID, &myServ);
return err;
}
示例12: SamplePrintWordWithBreak
void SamplePrintWordWithBreak()
{
PRUint32 numOfFragment = sizeof(wb) / sizeof(char*);
nsIWordBreakerFactory *t = NULL;
nsresult res = CallGetService(kLWBrkCID, &t);
nsIWordBreaker *wbk;
nsAutoString wb_arg;
res = t->GetBreaker(wb_arg, &wbk);
nsAutoString result;
nsAutoString tmp;
for(PRUint32 i = 0; i < numOfFragment; i++)
{
nsAutoString fragText; fragText.AssignWithConversion(wb[i]);
// nsBreakState bk(fragText.get(), fragText.Length());
PRUint32 cur = 0;
PRBool done;
res = wbk->NextWord(fragText.get(), fragText.Length(), cur, &cur, &done);
PRUint32 start = 0;
for(PRUint32 j = 0; ! done ; j++)
{
tmp.Truncate();
fragText.Mid(tmp, start, cur - start);
result.Append(tmp);
result.AppendLiteral("^");
start = cur;
wbk->NextWord(fragText.get(), fragText.Length(), cur, &cur, &done);
}
tmp.Truncate();
fragText.Mid(tmp, start, fragText.Length() - start);
result.Append(tmp);
if( i != (numOfFragment -1 ))
{
nsAutoString nextFragText; nextFragText.AssignWithConversion(wb[i+1]);
PRBool canBreak = PR_TRUE;
res = wbk->BreakInBetween( fragText.get(),
fragText.Length(),
nextFragText.get(),
nextFragText.Length(),
&canBreak
);
if(canBreak)
result.AppendLiteral("^");
fragText = nextFragText;
}
}
printf("Output From SamplePrintWordWithBreak() \n\n");
printf("[%s]\n", NS_LossyConvertUCS2toASCII(result).get());
}
示例13: CallGetService
nsXFormsAccessibleBase::nsXFormsAccessibleBase()
{
if (!sXFormsService) {
nsresult rv = CallGetService("@mozilla.org/xforms-utility-service;1",
&sXFormsService);
if (NS_FAILED(rv))
NS_WARNING("No XForms utility service.");
}
}
示例14: MOZ_COUNT_CTOR
nsBox::nsBox()
{
MOZ_COUNT_CTOR(nsBox);
//mX = 0;
//mY = 0;
if (!gGotTheme) {
gGotTheme = PR_TRUE;
CallGetService("@mozilla.org/chrome/chrome-native-theme;1", &gTheme);
}
}
示例15: CallGetService
NS_IMETHODIMP nsTextToSubURI::ConvertAndEscape(
const char *charset, const PRUnichar *text, char **_retval)
{
if(nullptr == _retval)
return NS_ERROR_NULL_POINTER;
*_retval = nullptr;
nsresult rv = NS_OK;
// Get Charset, get the encoder.
nsICharsetConverterManager *ccm;
rv = CallGetService(kCharsetConverterManagerCID, &ccm);
if(NS_SUCCEEDED(rv)) {
nsIUnicodeEncoder *encoder;
rv = ccm->GetUnicodeEncoder(charset, &encoder);
NS_RELEASE(ccm);
if (NS_SUCCEEDED(rv)) {
rv = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nullptr, (PRUnichar)'?');
if(NS_SUCCEEDED(rv))
{
char buf[256];
char *pBuf = buf;
int32_t ulen = text ? NS_strlen(text) : 0;
int32_t outlen = 0;
if(NS_SUCCEEDED(rv = encoder->GetMaxLength(text, ulen, &outlen)))
{
if(outlen >= 256) {
pBuf = (char*)NS_Alloc(outlen+1);
}
if(nullptr == pBuf) {
outlen = 255;
pBuf = buf;
}
int32_t bufLen = outlen;
if(NS_SUCCEEDED(rv = encoder->Convert(text,&ulen, pBuf, &outlen))) {
// put termination characters (e.g. ESC(B of ISO-2022-JP) if necessary
int32_t finLen = bufLen - outlen;
if (finLen > 0) {
if (NS_SUCCEEDED(encoder->Finish((char *)(pBuf+outlen), &finLen)))
outlen += finLen;
}
pBuf[outlen] = '\0';
*_retval = nsEscape(pBuf, url_XPAlphas);
if(nullptr == *_retval)
rv = NS_ERROR_OUT_OF_MEMORY;
}
}
if(pBuf != buf)
NS_Free(pBuf);
}
NS_RELEASE(encoder);
}
}
return rv;
}