ncdengine/engine/src/catalogsclientserverserver.cpp
changeset 64 48c14c385b0e
parent 0 ba25891c3a9e
child 66 8b7f4e561641
equal deleted inserted replaced
58:67f2119dc623 64:48c14c385b0e
     1 /*
     1 /*
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2006-2010 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>
    18 
    19 
    19 #include "catalogsclientserverserver.h"
    20 #include "catalogsclientserverserver.h"
    20 #include "catalogsclientserverserversession.h"
    21 #include "catalogsclientserverserversession.h"
    21 #include "catalogsserverdefines.h"
    22 #include "catalogsserverdefines.h"
    22 #include "catalogsserverengine.h"
    23 #include "catalogsserverengine.h"
    54     ECapabilityUserEnvironment );
    55     ECapabilityUserEnvironment );
    55 
    56 
    56 // ======== MEMBER FUNCTIONS ========
    57 // ======== MEMBER FUNCTIONS ========
    57 
    58 
    58 
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // 
       
    62 // ---------------------------------------------------------------------------
       
    63 // 
       
    64 CCatalogsClientServerServer* CCatalogsClientServerServer::NewL()
       
    65     {
       
    66     CCatalogsClientServerServer* self = CCatalogsClientServerServer::NewLC();
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
    59 // ---------------------------------------------------------------------------
    70 // ---------------------------------------------------------------------------
    60 // 
    71 // 
    61 // ---------------------------------------------------------------------------
    72 // ---------------------------------------------------------------------------
    62 // 
    73 // 
    63 CCatalogsClientServerServer* CCatalogsClientServerServer::NewLC()
    74 CCatalogsClientServerServer* CCatalogsClientServerServer::NewLC()
   199     iSessionCount--;
   210     iSessionCount--;
   200 
   211 
   201     // No more clients, shutdown
   212     // No more clients, shutdown
   202     if ( iSessionCount <= 0 )
   213     if ( iSessionCount <= 0 )
   203         {
   214         {
   204         CActiveScheduler::Stop();
   215         QCoreApplication::exit(0);
   205         }
   216         }
   206     }
   217     }
   207     
   218     
   208 // ---------------------------------------------------------------------------
   219 // ---------------------------------------------------------------------------
   209 // 
   220 // 
   290         {
   301         {
   291         User::Leave( err );
   302         User::Leave( err );
   292         }
   303         }
   293     }
   304     }
   294 
   305 
   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     }
       
   367 
   306 
   368 // ---------------------------------------------------------------------------
   307 // ---------------------------------------------------------------------------
   369 // 
   308 // 
   370 // ---------------------------------------------------------------------------
   309 // ---------------------------------------------------------------------------
   371 // 
   310 // 
   438 IMPORT_C TInt WinsMain();
   377 IMPORT_C TInt WinsMain();
   439 EXPORT_C TInt WinsMain()
   378 EXPORT_C TInt WinsMain()
   440 	{
   379 	{
   441 	// WINS DLL entry-point. Just return the real thread function 
   380 	// WINS DLL entry-point. Just return the real thread function 
   442     // cast to TInt
   381     // cast to TInt
   443 	return reinterpret_cast<TInt>( 
   382 	return 0;
   444 	    &CCatalogsClientServerServer::ThreadFunction );
       
   445 	}
   383 	}
   446 
   384 
   447 // ---------------------------------------------------------------------------
   385 // ---------------------------------------------------------------------------
   448 // 
   386 // 
   449 // ---------------------------------------------------------------------------
   387 // ---------------------------------------------------------------------------
   450 // 
   388 // 
   451 GLDEF_C TInt E32Main()
   389 int main(int argc, char *argv[])
   452     {
   390     {
   453     return CCatalogsClientServerServer::ThreadFunction( NULL );
   391     DLINIT;
       
   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;
   454     }
   424     }
   455 
   425 
   456 
   426 
   457 // ---------------------------------------------------------------------------
   427 // ---------------------------------------------------------------------------
   458 // 
   428 //