sl@0: // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // sl@0: // Permission is hereby granted, free of charge, to any person obtaining a sl@0: // copy of this software and/or associated documentation files (the sl@0: // "Materials"), to deal in the Materials without restriction, including sl@0: // without limitation the rights to use, copy, modify, merge, publish, sl@0: // distribute, sublicense, and/or sell copies of the Materials, and to sl@0: // permit persons to whom the Materials are furnished to do so, subject to sl@0: // the following conditions: sl@0: // sl@0: // The above copyright notice and this permission notice shall be included sl@0: // in all copies or substantial portions of the Materials. sl@0: // sl@0: // THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, sl@0: // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF sl@0: // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. sl@0: // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY sl@0: // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, sl@0: // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE sl@0: // MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. sl@0: // sl@0: // Description: sl@0: // Console adaptation for OpenWFC conformance tests sl@0: // sl@0: // sl@0: sl@0: #include "owfdebug.h" sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: static const TInt KOpenWfcImplCleanupKey = 0x10286FC4; // same as DLL UID3 sl@0: sl@0: /** sl@0: Re-directs vprintf to RDebug so the console doesn't trash the visual tests. sl@0: sl@0: Not exported. The CT should not depend on functions provided by the SI adaptation. sl@0: */ sl@0: extern "C" int xvprintf(const char* aFormat, va_list aArgs) sl@0: { sl@0: #define SAFE_STRING_SIZE 2040 sl@0: char buffer[SAFE_STRING_SIZE+4]; sl@0: buffer[SAFE_STRING_SIZE]=0; sl@0: buffer[SAFE_STRING_SIZE+1]=0; sl@0: buffer[SAFE_STRING_SIZE+2]=0; sl@0: // Symbian format syntax is different so convert to a buffer using P.I.P.S first sl@0: vsnprintf(buffer,SAFE_STRING_SIZE, aFormat, aArgs); sl@0: TPtrC8 ptr(reinterpret_cast(buffer), strlen(buffer)); sl@0: RDebug::RawPrint(ptr); sl@0: return ptr.Length(); sl@0: } sl@0: sl@0: /** sl@0: Re-directs printf to RDebug so the console doesn't trash the visual tests. sl@0: sl@0: Not exported. The CT should not depend on functions provided by the SI adaptation. sl@0: */ sl@0: extern "C" void xprintf(const char* aFormat, ...) sl@0: { sl@0: va_list list; sl@0: va_start(list, aFormat); sl@0: // Disabled Coverity warning, since it does not support vararg and throws a warning sl@0: // coverity[uninit_use_in_call] sl@0: xvprintf(aFormat, list); sl@0: va_end(list); sl@0: } sl@0: sl@0: static void (*gAtExitFunc)(void) = NULL; sl@0: sl@0: static int DoAtExit(void* aData) sl@0: /** sl@0: * This function is required because the signature of atexit callback is sl@0: * different to TCallBack func. Additionaly, this function checks the heap sl@0: * supplied to the callback is the heap used for the singelton. sl@0: * sl@0: * It is intended but not guaranteed that WServ will invoke this callback at sl@0: * shutdown. The primary purpose is to support detection of memory leaks so sl@0: * production code should not depend on this function being called. sl@0: * sl@0: * @param aData The data parameter for the callback which must be a pointer sl@0: * to the heap that the singleton was created on. sl@0: */ sl@0: { sl@0: // Blank the property for this callback sl@0: RThread t; sl@0: RProperty prop; sl@0: TCallBack cb(NULL, NULL); sl@0: TPckgC cbPckg(cb); sl@0: prop.Set(TUid::Uid(t.SecureId().iId), KOpenWfcImplCleanupKey, cbPckg); sl@0: prop.Close(); sl@0: t.Close(); sl@0: sl@0: if (aData == &User::Heap() && gAtExitFunc) sl@0: { sl@0: gAtExitFunc(); sl@0: return 1; sl@0: } sl@0: return 0; sl@0: } sl@0: sl@0: extern "C" void RegisterCleanup(TInt (*aFunction)(void* aPtr)) sl@0: /** sl@0: * Register the cleanup function in a property defined by WServ. sl@0: * @param aFunction A pointer to the function that WServ should use to sl@0: * cleanup singletons on exit. sl@0: */ sl@0: { sl@0: RThread t; sl@0: TUid category = {t.SecureId().iId}; sl@0: RProperty prop; sl@0: TCallBack cb(aFunction, &User::Heap()); sl@0: TPckgC cbPckg(cb); sl@0: sl@0: // If the property cannot be set the assumption is that the cleanup is not needed sl@0: (void) prop.Set(category, KOpenWfcImplCleanupKey, cbPckg); sl@0: prop.Close(); sl@0: t.Close(); sl@0: } sl@0: sl@0: extern "C" int xatexit(void (*func)(void)) sl@0: /** sl@0: * To minimise changes to the SI code the function is similar to the standard sl@0: * atexit function. However, instead of providing a general purpose cleanup sl@0: * operation this implementaion simply allows WServ to trigger the cleanup sl@0: * of singleton objects during memory leak tests. sl@0: * sl@0: * This is done purely to simplify the implementation. sl@0: * sl@0: * @param func A pointer to the function responsible for deleting singletons sl@0: * owned by OpenWFC. sl@0: */ sl@0: { sl@0: __ASSERT_ALWAYS( ( ! gAtExitFunc ) || ( gAtExitFunc == func ), User::Invariant()); sl@0: gAtExitFunc = func; sl@0: RegisterCleanup( DoAtExit ); sl@0: return 0; sl@0: }