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