ncdengine/engine/src/catalogsclientserverserver.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     1 /*
     1 /*
     2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    13 *
    13 *
    14 * Description:   Implementation of CCatalogsClientServerServer
    14 * Description:   Implementation of CCatalogsClientServerServer
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <QCoreApplication>
       
    19 
    18 
    20 #include "catalogsclientserverserver.h"
    19 #include "catalogsclientserverserver.h"
    21 #include "catalogsclientserverserversession.h"
    20 #include "catalogsclientserverserversession.h"
    22 #include "catalogsserverdefines.h"
    21 #include "catalogsserverdefines.h"
    23 #include "catalogsserverengine.h"
    22 #include "catalogsserverengine.h"
    55     ECapabilityUserEnvironment );
    54     ECapabilityUserEnvironment );
    56 
    55 
    57 // ======== MEMBER FUNCTIONS ========
    56 // ======== MEMBER FUNCTIONS ========
    58 
    57 
    59 
    58 
    60 // ---------------------------------------------------------------------------
       
    61 // 
       
    62 // ---------------------------------------------------------------------------
       
    63 // 
       
    64 CCatalogsClientServerServer* CCatalogsClientServerServer::NewL()
       
    65     {
       
    66     CCatalogsClientServerServer* self = CCatalogsClientServerServer::NewLC();
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 // ---------------------------------------------------------------------------
    59 // ---------------------------------------------------------------------------
    71 // 
    60 // 
    72 // ---------------------------------------------------------------------------
    61 // ---------------------------------------------------------------------------
    73 // 
    62 // 
    74 CCatalogsClientServerServer* CCatalogsClientServerServer::NewLC()
    63 CCatalogsClientServerServer* CCatalogsClientServerServer::NewLC()
   210     iSessionCount--;
   199     iSessionCount--;
   211 
   200 
   212     // No more clients, shutdown
   201     // No more clients, shutdown
   213     if ( iSessionCount <= 0 )
   202     if ( iSessionCount <= 0 )
   214         {
   203         {
   215         QCoreApplication::exit(0);
   204         CActiveScheduler::Stop();
   216         }
   205         }
   217     }
   206     }
   218     
   207     
   219 // ---------------------------------------------------------------------------
   208 // ---------------------------------------------------------------------------
   220 // 
   209 // 
   301         {
   290         {
   302         User::Leave( err );
   291         User::Leave( err );
   303         }
   292         }
   304     }
   293     }
   305 
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // 
       
   297 // ---------------------------------------------------------------------------
       
   298 // 
       
   299 void CCatalogsClientServerServer::ThreadFunctionL()
       
   300     {
       
   301     DLTRACEIN((""));
       
   302     DCHECK_HEAP
       
   303     // Construct an active scheduler for the server
       
   304 
       
   305     DLINFO(( "Creating active schduler" ));
       
   306     CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler;
       
   307     CleanupStack::PushL( activeScheduler );
       
   308 
       
   309     // Install active scheduler
       
   310     // No need to check whether an active scheduler is already installed
       
   311     // as this is a new thread, so there won't be one
       
   312     DLINFO(( "Installing active schduler" ));
       
   313     CActiveScheduler::Install( activeScheduler );
       
   314 
       
   315     // Construct our server
       
   316     CCatalogsClientServerServer::NewLC(); // anonymous
       
   317 
       
   318     DLINFO(( "Opening semaphore" ));
       
   319     RSemaphore semaphore;
       
   320     User::LeaveIfError(
       
   321         semaphore.OpenGlobal( KCatalogsServerSemaphoreName ));
       
   322     
       
   323     DLINFO(( "Signalling and closing semaphore" ));
       
   324     // Semaphore opened ok
       
   325     semaphore.Signal();
       
   326     semaphore.Close();
       
   327 
       
   328     // Start handling requests, operation will stop here until
       
   329     // the server dies
       
   330     CActiveScheduler::Start();
       
   331 
       
   332     DLINFO(("Server has shut down"));
       
   333 
       
   334     // The server has been shut down, clean up
       
   335     CleanupStack::PopAndDestroy( 2, activeScheduler );
       
   336     DLTRACEOUT((""));
       
   337     }
       
   338 
       
   339 // ---------------------------------------------------------------------------
       
   340 // 
       
   341 // ---------------------------------------------------------------------------
       
   342 // 
       
   343 TInt CCatalogsClientServerServer::ThreadFunction( TAny* /*aNone*/ )
       
   344     {
       
   345 #ifdef CATALOGS_BUILD_CONFIG_HEAP_MARKS    
       
   346     __UHEAP_MARK;
       
   347 #endif    
       
   348     DLINIT;
       
   349     
       
   350     DLTRACEIN((""));
       
   351     
       
   352     CTrapCleanup* cleanupStack = CTrapCleanup::New();
       
   353     TRAPD( err, ThreadFunctionL() );
       
   354     
       
   355     DLTRACE(( "err: %d", err ));
       
   356     delete cleanupStack;
       
   357     cleanupStack = NULL;
       
   358     
       
   359     DLTRACEOUT((""));
       
   360 
       
   361     DLUNINIT;
       
   362 #ifdef CATALOGS_BUILD_CONFIG_HEAP_MARKS    
       
   363     __UHEAP_MARKEND; 
       
   364 #endif    
       
   365     return err;    
       
   366     }
   306 
   367 
   307 // ---------------------------------------------------------------------------
   368 // ---------------------------------------------------------------------------
   308 // 
   369 // 
   309 // ---------------------------------------------------------------------------
   370 // ---------------------------------------------------------------------------
   310 // 
   371 // 
   377 IMPORT_C TInt WinsMain();
   438 IMPORT_C TInt WinsMain();
   378 EXPORT_C TInt WinsMain()
   439 EXPORT_C TInt WinsMain()
   379 	{
   440 	{
   380 	// WINS DLL entry-point. Just return the real thread function 
   441 	// WINS DLL entry-point. Just return the real thread function 
   381     // cast to TInt
   442     // cast to TInt
   382 	return 0;
   443 	return reinterpret_cast<TInt>( 
       
   444 	    &CCatalogsClientServerServer::ThreadFunction );
   383 	}
   445 	}
   384 
   446 
   385 // ---------------------------------------------------------------------------
   447 // ---------------------------------------------------------------------------
   386 // 
   448 // 
   387 // ---------------------------------------------------------------------------
   449 // ---------------------------------------------------------------------------
   388 // 
   450 // 
   389 int main(int argc, char *argv[])
   451 GLDEF_C TInt E32Main()
   390     {
   452     {
   391     DLINIT;
   453     return CCatalogsClientServerServer::ThreadFunction( NULL );
   392     DCHECK_HEAP
       
   393     int err = KErrNone;
       
   394 #ifdef CATALOGS_BUILD_CONFIG_HEAP_MARKS    
       
   395     __UHEAP_MARK;
       
   396 #endif 
       
   397         {
       
   398         QCoreApplication app(argc, argv);
       
   399         CCatalogsClientServerServer* server = NULL;
       
   400         TRAP( err, server = CCatalogsClientServerServer::NewL() );
       
   401         if ( err == KErrNone )
       
   402             {
       
   403             DLINFO(( "Opening semaphore" ));
       
   404             RSemaphore semaphore;
       
   405             err = semaphore.OpenGlobal( KCatalogsServerSemaphoreName );
       
   406             if (err == KErrNone )
       
   407                 {
       
   408                 DLINFO(( "Signalling and closing semaphore" ));
       
   409                 // Semaphore opened ok
       
   410                 semaphore.Signal();
       
   411                 semaphore.Close();
       
   412                 err = app.exec();
       
   413                 }
       
   414             delete server;
       
   415             }
       
   416     
       
   417         DLINFO(("Server has shut down"));
       
   418         }
       
   419 #ifdef CATALOGS_BUILD_CONFIG_HEAP_MARKS    
       
   420     __UHEAP_MARKEND; 
       
   421 #endif
       
   422     DLUNINIT;
       
   423     return err;
       
   424     }
   454     }
   425 
   455 
   426 
   456 
   427 // ---------------------------------------------------------------------------
   457 // ---------------------------------------------------------------------------
   428 // 
   458 //