httpfilters/cookie/ManagerSrc/CookieManagerStart.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 31 Mar 2010 22:32:15 +0300
branchRCL_3
changeset 9 2611c08ee28e
parent 0 b16258d2340f
permissions -rw-r--r--
Revision: 201011 Kit: 201013

/*
* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Server starting for CookieManager.
*
*/


// INCLUDE FILES
	// System includes
#include <e32std.h>
#include <basched.h>

	// User includes
#include "CookieManagerStart.h"
#include "CookieManagerServer.h"
#include "CookieLogger.h"
#include "CookieServerDef.h"

// CONSTANTS

//**********************************
// Single exported function
//**********************************

/**
* An exported function on the global name space that runs the server.
*/
EXPORT_C TInt StartCookieServer( TAny* /*anArg*/ )
	{
    CLOG( ( EServerStart, 0, _L( "" ) ) );
    CLOG( ( EServerStart, 0, _L( "*****************" ) ) );
    CLOG( ( EServerStart, 0, _L( "-> StartCookieServerStart" ) ) );

	//__UHEAP_MARK;

	TBuf<32> name( KCookieServerThreadName );

    RThread().RenameMe( name );

	TInt result = KErrNone;

	CTrapCleanup* cleanup = CTrapCleanup::New();
	if ( cleanup == NULL )
		{
		result = KErrNoMemory;
        CLOG( ( EServerStart, 0, _L( "TrapCleanup failure" ) ) );
		}
	else
		{
		CBaActiveScheduler* scheduler = new CBaActiveScheduler;
		if ( scheduler == NULL )
			{
			result = KErrNoMemory;
            CLOG( ( EServerStart, 0, _L( "CBaActiveScheduler failure" ) ) );
			}
		else
			{
			CActiveScheduler::Install( scheduler );
    
			CLOG( ( EServerStart, 0, _L( "ActiveScheduler installed OK" ) ) );

			CCookieManagerServer* server = NULL;
			TRAP( result, server = CCookieManagerServer::NewL() );
			if ( result == KErrNone )
				{
                RProcess::Rendezvous( result );
				CLOG( ( EServerStart, 0, _L( "Starting ActiveScheduler" ) ) );

				// It starts an infinite loop from which we can break out
				// only if we stop the active scheduler
				CActiveScheduler::Start();

				CLOG( ( EServerStart, 0, _L( "ActiveScheduler stopped" ) ) );

				// finished
				delete server;
				}
            else
                {
                CLOG( ( EServerStart, 0,
                    _L( "Cookie Server start-up failure %d" ), result ) );
                }
			delete scheduler;
			}
		delete cleanup;
		}

	//__UHEAP_MARKEND;

    CLOG( ( EServerStart, 0, _L( "<- StartCookieServerStart err%d" ),
                            result ) );

	return result;
	}

// End of file