contentpublishingsrv/contentharvester/contentharvesterserver/src/contentharvesterserver.cpp
changeset 73 4bc7b118b3df
parent 66 32469d7d46ff
child 80 397d00875918
child 81 5ef31a21fdd5
equal deleted inserted replaced
66:32469d7d46ff 73:4bc7b118b3df
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Content Harvester Server
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 //#include <eikenv.h>
       
    20 //#include <eikappui.h>
       
    21 
       
    22 #include <fbs.h>
       
    23 
       
    24 #include "contentharvesterserver.h"
       
    25 #include "contentharvestersession.h"
       
    26 #include "contentharvesterglobals.h"
       
    27 #include "contentharvesterengine.h"
       
    28 #include "cpdebug.h"
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CContentHarvesterServer::CContentHarvesterServer
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CContentHarvesterServer::CContentHarvesterServer( TInt aPriority ) :
       
    39     CServer2(aPriority)
       
    40     {
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CContentHarvesterServer::ConstructL
       
    45 // Symbian 2nd phase constructor can leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void CContentHarvesterServer::ConstructL()
       
    49     {
       
    50     CP_DEBUG( _L8("Start Content Harvester Server" ));
       
    51     StartL( KContentHarvesterName );
       
    52     iEngine = CContentHarvesterEngine::NewL( );
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CContentHarvesterServer::NewL
       
    57 // Two-phased constructor.
       
    58 // -------------------------------------- ---------------------------------------
       
    59 //
       
    60 CContentHarvesterServer* CContentHarvesterServer::NewLC()
       
    61     {
       
    62     CContentHarvesterServer* self = new( ELeave )
       
    63     CContentHarvesterServer( EPriorityNormal );
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL( );
       
    66     return self;
       
    67     }
       
    68 
       
    69 // Destructor
       
    70 CContentHarvesterServer::~CContentHarvesterServer()
       
    71     {
       
    72     CP_DEBUG( _L8("Destroy Content Harvester Server" ));
       
    73     delete iEngine;
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CContentHarvesterServer::NewSessionL
       
    78 // Create new session.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CSession2* CContentHarvesterServer::NewSessionL( const TVersion& aVersion,
       
    82     const RMessage2& /*aMessage*/ ) const
       
    83     {
       
    84     CP_DEBUG(_L8("CContentHarvesterServer::NewSessionL" ));
       
    85     // Check we're the right version
       
    86     if ( !User::QueryVersionSupported( TVersion(
       
    87         KContentHarvesterMajorVersionNumber,
       
    88         KContentHarvesterMinorVersionNumber,
       
    89         KContentHarvesterBuildVersionNumber ), aVersion ) )
       
    90         {
       
    91         User::Leave( KErrNotSupported );
       
    92         }
       
    93     return CContentHarvesterSession::NewL( ( CContentHarvesterServer* ) this );
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CContentHarvesterServer::RunError
       
    98 // RunError is called when RunL leaves.
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 TInt CContentHarvesterServer::RunError( TInt aError )
       
   102     {
       
   103     CP_DEBUG( _L8("CContentHarvesterServer::RunError " ));
       
   104     if ( aError == KErrBadDescriptor )
       
   105         {
       
   106         PanicClient( Message( ), EContentHarvesterBadDescriptor );
       
   107         }
       
   108     else
       
   109         {
       
   110         Message().Complete( aError );
       
   111         }
       
   112 
       
   113     // The leave will result in an early return from CServer::RunL(), skipping
       
   114     // the call to request another message. So do that now in order to keep the
       
   115     // server running.
       
   116     ReStart( );
       
   117     // Handled the error fully
       
   118     return KErrNone;
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CContentHarvesterServer::PanicClient
       
   123 // Panic client.
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CContentHarvesterServer::PanicClient( const RMessage2& aMessage,
       
   127     TContentHarvesterPanic aPanic )
       
   128     {
       
   129     aMessage.Panic( KContentHarvesterName, aPanic );
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CContentHarvesterServer::PanicServer
       
   134 // Panic server.
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CContentHarvesterServer::PanicServer( TContentHarvesterPanic aPanic )
       
   138     {
       
   139     User::Panic( KContentHarvesterName, aPanic );
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CContentHarvesterServer::ThreadFunctionL
       
   144 // Create and start the server.
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CContentHarvesterServer::ThreadFunctionL()
       
   148     {
       
   149     RFbsSession::Connect( );
       
   150     // Construct our server        
       
   151 
       
   152     CContentHarvesterServer* server = CContentHarvesterServer::NewLC( );
       
   153     CP_DEBUG(_L8("Send Rendezvous" ));
       
   154     RProcess::Rendezvous( KErrNone );
       
   155 
       
   156     CActiveScheduler::Start( );
       
   157 
       
   158     CleanupStack::PopAndDestroy( server );
       
   159 
       
   160     RFbsSession::Disconnect( );
       
   161     }
       
   162 // -----------------------------------------------------------------------------
       
   163 // CContentHarvesterServer::ThreadFunctionL
       
   164 // Create and start the server.
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 TInt CContentHarvesterServer::ThreadFunction()
       
   168     {
       
   169     __UHEAP_MARK;
       
   170 
       
   171 	TFindServer findCountServer( KContentHarvesterName );
       
   172 	TFullName   name;
       
   173     
       
   174 	// Need to check that the server exists.
       
   175 	if (findCountServer.Next(name) != KErrNone)
       
   176 		{
       
   177 		User::RenameThread( KContentHarvesterThreadName );
       
   178 	
       
   179 		CTrapCleanup* cleanupStack = CTrapCleanup::New( );
       
   180 		if ( !(cleanupStack ) )
       
   181 			{
       
   182 			PanicServer( EContentHarvesterCreateTrapCleanup );
       
   183 			}
       
   184 	
       
   185 		CContentHarvesterEikonEnv* env = new CContentHarvesterEikonEnv;
       
   186 		__ASSERT_ALWAYS( env, PanicServer( EContentHarvesterEIkonEnv ) );
       
   187 	
       
   188 		CContentHarvesterAppUi* ui = new CContentHarvesterAppUi;
       
   189 		__ASSERT_ALWAYS( ui, PanicServer( EContentHarvesterEIkonEnv ) );
       
   190 	
       
   191 		TRAPD(error, env->ConstructL(); ui->ConstructL());
       
   192 		__ASSERT_ALWAYS( !error, PanicServer( EContentHarvesterEIkonEnv ) );
       
   193 		
       
   194 		TRAPD( err, ThreadFunctionL() );
       
   195 		if ( err != KErrNone )
       
   196 			{
       
   197 			PanicServer( EContentHarvesterSrvCreateServer );
       
   198 			}
       
   199 		ui->PrepareToExit( );
       
   200 		env->DestroyEnvironment( );
       
   201 	
       
   202 		delete cleanupStack;
       
   203 		cleanupStack = NULL;
       
   204 		}
       
   205 	
       
   206     __UHEAP_MARKEND;
       
   207 
       
   208     return KErrNone;
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CContentHarvesterServer::Engine
       
   213 // Getter of engine
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 CContentHarvesterEngine& CContentHarvesterServer::Engine()
       
   217     {
       
   218     return *iEngine;
       
   219     }
       
   220 // -----------------------------------------------------------------------------
       
   221 // CContentHarvesterServer::Engine
       
   222 // Getter of engine
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 void CContentHarvesterServer::Stop()
       
   226     {
       
   227     CActiveScheduler::Stop( );
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CContentHarvesterEikonEnv::DestroyEnvironment
       
   232 // 
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CContentHarvesterServer::CContentHarvesterEikonEnv::DestroyEnvironment()
       
   236     {
       
   237     CEikonEnv::DestroyEnvironment( );
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CContentHarvesterEikonEnv::ConstructL
       
   242 // 
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 void CContentHarvesterServer::CContentHarvesterEikonEnv::ConstructL()
       
   246     {
       
   247     CEikonEnv::ConstructL( EFalse );
       
   248     SetAutoForwarding( ETrue );
       
   249     User::SetPriorityControl( EFalse );
       
   250     }
       
   251 // -----------------------------------------------------------------------------
       
   252 // CContentHarvesterAppUi::~CContentHarvesterAppUi
       
   253 // 
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 CContentHarvesterServer::CContentHarvesterAppUi::~CContentHarvesterAppUi()
       
   257     {
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CContentHarvesterAppUi::ConstructL
       
   262 // 
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 void CContentHarvesterServer::CContentHarvesterAppUi::ConstructL()
       
   266     {
       
   267     CEikAppUi::BaseConstructL( ENoAppResourceFile|ENoScreenFurniture );
       
   268     }
       
   269 
       
   270 // ============================= LOCAL FUNCTIONS ===============================
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // E32Main entry point.
       
   274 // Returns: KErrNone
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 TInt E32Main()
       
   278     {
       
   279     return CContentHarvesterServer::ThreadFunction( );
       
   280     }
       
   281 
       
   282 // End of File
       
   283