os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/OS/symbian/owfconsole.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/OS/symbian/owfconsole.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,141 @@
     1.4 +// Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +//
     1.6 +// Permission is hereby granted, free of charge, to any person obtaining a
     1.7 +// copy of this software and/or associated documentation files (the
     1.8 +// "Materials"), to deal in the Materials without restriction, including
     1.9 +// without limitation the rights to use, copy, modify, merge, publish,
    1.10 +// distribute, sublicense, and/or sell copies of the Materials, and to
    1.11 +// permit persons to whom the Materials are furnished to do so, subject to
    1.12 +// the following conditions:
    1.13 +//
    1.14 +// The above copyright notice and this permission notice shall be included
    1.15 +// in all copies or substantial portions of the Materials.
    1.16 +//
    1.17 +// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    1.18 +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    1.19 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    1.20 +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    1.21 +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    1.22 +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    1.23 +// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
    1.24 +//
    1.25 +// Description:
    1.26 +// Console adaptation for OpenWFC conformance tests
    1.27 +//
    1.28 +//
    1.29 +
    1.30 +#include "owfdebug.h"
    1.31 +
    1.32 +#include <e32base.h>
    1.33 +#include <e32cmn.h>
    1.34 +#include <e32debug.h>
    1.35 +#include <e32property.h>
    1.36 +#include <stdio.h>
    1.37 +#include <string.h>
    1.38 +
    1.39 +static const TInt KOpenWfcImplCleanupKey = 0x10286FC4;  // same as DLL UID3
    1.40 +
    1.41 +/**
    1.42 +Re-directs vprintf to RDebug so the console doesn't trash the visual tests.
    1.43 +
    1.44 +Not exported. The CT should not depend on functions provided by the SI adaptation.
    1.45 +*/
    1.46 +extern "C" int xvprintf(const char* aFormat, va_list aArgs)
    1.47 +	{
    1.48 +#define SAFE_STRING_SIZE 2040
    1.49 +	char buffer[SAFE_STRING_SIZE+4];
    1.50 +    buffer[SAFE_STRING_SIZE]=0;
    1.51 +    buffer[SAFE_STRING_SIZE+1]=0;
    1.52 +    buffer[SAFE_STRING_SIZE+2]=0;
    1.53 +	// Symbian format syntax is different so convert to a buffer using P.I.P.S first
    1.54 +	vsnprintf(buffer,SAFE_STRING_SIZE, aFormat, aArgs);
    1.55 +	TPtrC8 ptr(reinterpret_cast<unsigned char*>(buffer), strlen(buffer));
    1.56 +	RDebug::RawPrint(ptr);
    1.57 +	return ptr.Length();
    1.58 +	}
    1.59 +
    1.60 +/**
    1.61 +Re-directs printf to RDebug so the console doesn't trash the visual tests.
    1.62 +
    1.63 +Not exported. The CT should not depend on functions provided by the SI adaptation.
    1.64 +*/
    1.65 +extern "C" void xprintf(const char* aFormat, ...)
    1.66 +    {
    1.67 +    va_list list; 
    1.68 +    va_start(list, aFormat);
    1.69 +	// Disabled Coverity warning, since it does not support vararg and throws a warning 
    1.70 +	// coverity[uninit_use_in_call]
    1.71 +    xvprintf(aFormat, list);
    1.72 +    va_end(list);
    1.73 +    }
    1.74 +
    1.75 +static void (*gAtExitFunc)(void) = NULL;
    1.76 +
    1.77 +static int DoAtExit(void* aData)
    1.78 +/**
    1.79 + * This function is required because the signature of atexit callback is 
    1.80 + * different to TCallBack func. Additionaly, this function checks the heap
    1.81 + * supplied to the callback is the heap used for the singelton.
    1.82 + * 
    1.83 + * It is intended but not guaranteed that WServ will invoke this callback at
    1.84 + * shutdown. The primary purpose is to support detection of memory leaks so
    1.85 + * production code should not depend on this function being called. 
    1.86 + * 
    1.87 + * @param   aData   The data parameter for the callback which must be a pointer
    1.88 + *                  to the heap that the singleton was created on.
    1.89 + */
    1.90 +    {
    1.91 +    // Blank the property for this callback
    1.92 +    RThread t;
    1.93 +    RProperty prop;
    1.94 +    TCallBack cb(NULL, NULL);
    1.95 +    TPckgC<TCallBack> cbPckg(cb);
    1.96 +    prop.Set(TUid::Uid(t.SecureId().iId), KOpenWfcImplCleanupKey, cbPckg);
    1.97 +    prop.Close();
    1.98 +    t.Close();
    1.99 +    
   1.100 +    if (aData == &User::Heap() && gAtExitFunc)
   1.101 +        {
   1.102 +        gAtExitFunc();
   1.103 +        return 1;
   1.104 +        }
   1.105 +    return 0;
   1.106 +    }
   1.107 +
   1.108 +extern "C" void RegisterCleanup(TInt (*aFunction)(void* aPtr))
   1.109 +/**
   1.110 + * Register the cleanup function in a property defined by WServ. 
   1.111 + * @param   aFunction   A pointer to the function that WServ should use to 
   1.112 + *                      cleanup singletons on exit.
   1.113 + */
   1.114 +    {   
   1.115 +    RThread t;      
   1.116 +    TUid category = {t.SecureId().iId};
   1.117 +    RProperty prop;
   1.118 +    TCallBack cb(aFunction, &User::Heap());
   1.119 +    TPckgC<TCallBack> cbPckg(cb);
   1.120 +    
   1.121 +    // If the property cannot be set the assumption is that the cleanup is not needed
   1.122 +    (void) prop.Set(category, KOpenWfcImplCleanupKey, cbPckg);
   1.123 +    prop.Close();
   1.124 +    t.Close();        
   1.125 +    }
   1.126 +
   1.127 +extern "C" int xatexit(void (*func)(void))
   1.128 +/**
   1.129 + * To minimise changes to the SI code the function is similar to the standard
   1.130 + * atexit function. However, instead of providing a general purpose cleanup
   1.131 + * operation this implementaion simply allows WServ to trigger the cleanup
   1.132 + * of singleton objects during memory leak tests.
   1.133 + * 
   1.134 + * This is done purely to simplify the implementation.
   1.135 + * 
   1.136 + * @param func  A pointer to the function responsible for deleting singletons
   1.137 + *              owned by OpenWFC.
   1.138 + */
   1.139 +    {
   1.140 +    __ASSERT_ALWAYS( ( ! gAtExitFunc ) || ( gAtExitFunc == func ), User::Invariant());
   1.141 +    gAtExitFunc = func;
   1.142 +    RegisterCleanup( DoAtExit );
   1.143 +    return 0;
   1.144 +    }