os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/OS/symbian/owfconsole.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 //
     3 // Permission is hereby granted, free of charge, to any person obtaining a
     4 // copy of this software and/or associated documentation files (the
     5 // "Materials"), to deal in the Materials without restriction, including
     6 // without limitation the rights to use, copy, modify, merge, publish,
     7 // distribute, sublicense, and/or sell copies of the Materials, and to
     8 // permit persons to whom the Materials are furnished to do so, subject to
     9 // the following conditions:
    10 //
    11 // The above copyright notice and this permission notice shall be included
    12 // in all copies or substantial portions of the Materials.
    13 //
    14 // THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    17 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    18 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    19 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    20 // MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
    21 //
    22 // Description:
    23 // Console adaptation for OpenWFC conformance tests
    24 //
    25 //
    26 
    27 #include "owfdebug.h"
    28 
    29 #include <e32base.h>
    30 #include <e32cmn.h>
    31 #include <e32debug.h>
    32 #include <e32property.h>
    33 #include <stdio.h>
    34 #include <string.h>
    35 
    36 static const TInt KOpenWfcImplCleanupKey = 0x10286FC4;  // same as DLL UID3
    37 
    38 /**
    39 Re-directs vprintf to RDebug so the console doesn't trash the visual tests.
    40 
    41 Not exported. The CT should not depend on functions provided by the SI adaptation.
    42 */
    43 extern "C" int xvprintf(const char* aFormat, va_list aArgs)
    44 	{
    45 #define SAFE_STRING_SIZE 2040
    46 	char buffer[SAFE_STRING_SIZE+4];
    47     buffer[SAFE_STRING_SIZE]=0;
    48     buffer[SAFE_STRING_SIZE+1]=0;
    49     buffer[SAFE_STRING_SIZE+2]=0;
    50 	// Symbian format syntax is different so convert to a buffer using P.I.P.S first
    51 	vsnprintf(buffer,SAFE_STRING_SIZE, aFormat, aArgs);
    52 	TPtrC8 ptr(reinterpret_cast<unsigned char*>(buffer), strlen(buffer));
    53 	RDebug::RawPrint(ptr);
    54 	return ptr.Length();
    55 	}
    56 
    57 /**
    58 Re-directs printf to RDebug so the console doesn't trash the visual tests.
    59 
    60 Not exported. The CT should not depend on functions provided by the SI adaptation.
    61 */
    62 extern "C" void xprintf(const char* aFormat, ...)
    63     {
    64     va_list list; 
    65     va_start(list, aFormat);
    66 	// Disabled Coverity warning, since it does not support vararg and throws a warning 
    67 	// coverity[uninit_use_in_call]
    68     xvprintf(aFormat, list);
    69     va_end(list);
    70     }
    71 
    72 static void (*gAtExitFunc)(void) = NULL;
    73 
    74 static int DoAtExit(void* aData)
    75 /**
    76  * This function is required because the signature of atexit callback is 
    77  * different to TCallBack func. Additionaly, this function checks the heap
    78  * supplied to the callback is the heap used for the singelton.
    79  * 
    80  * It is intended but not guaranteed that WServ will invoke this callback at
    81  * shutdown. The primary purpose is to support detection of memory leaks so
    82  * production code should not depend on this function being called. 
    83  * 
    84  * @param   aData   The data parameter for the callback which must be a pointer
    85  *                  to the heap that the singleton was created on.
    86  */
    87     {
    88     // Blank the property for this callback
    89     RThread t;
    90     RProperty prop;
    91     TCallBack cb(NULL, NULL);
    92     TPckgC<TCallBack> cbPckg(cb);
    93     prop.Set(TUid::Uid(t.SecureId().iId), KOpenWfcImplCleanupKey, cbPckg);
    94     prop.Close();
    95     t.Close();
    96     
    97     if (aData == &User::Heap() && gAtExitFunc)
    98         {
    99         gAtExitFunc();
   100         return 1;
   101         }
   102     return 0;
   103     }
   104 
   105 extern "C" void RegisterCleanup(TInt (*aFunction)(void* aPtr))
   106 /**
   107  * Register the cleanup function in a property defined by WServ. 
   108  * @param   aFunction   A pointer to the function that WServ should use to 
   109  *                      cleanup singletons on exit.
   110  */
   111     {   
   112     RThread t;      
   113     TUid category = {t.SecureId().iId};
   114     RProperty prop;
   115     TCallBack cb(aFunction, &User::Heap());
   116     TPckgC<TCallBack> cbPckg(cb);
   117     
   118     // If the property cannot be set the assumption is that the cleanup is not needed
   119     (void) prop.Set(category, KOpenWfcImplCleanupKey, cbPckg);
   120     prop.Close();
   121     t.Close();        
   122     }
   123 
   124 extern "C" int xatexit(void (*func)(void))
   125 /**
   126  * To minimise changes to the SI code the function is similar to the standard
   127  * atexit function. However, instead of providing a general purpose cleanup
   128  * operation this implementaion simply allows WServ to trigger the cleanup
   129  * of singleton objects during memory leak tests.
   130  * 
   131  * This is done purely to simplify the implementation.
   132  * 
   133  * @param func  A pointer to the function responsible for deleting singletons
   134  *              owned by OpenWFC.
   135  */
   136     {
   137     __ASSERT_ALWAYS( ( ! gAtExitFunc ) || ( gAtExitFunc == func ), User::Invariant());
   138     gAtExitFunc = func;
   139     RegisterCleanup( DoAtExit );
   140     return 0;
   141     }