appfw/apparchitecture/apserv/APSSTART.CPP
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // The main startup of the AppArc server
       
    15 // 
       
    16 // apsstart.cpp
       
    17 //
       
    18 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    19 #if !defined(__APA_INTERNAL_H__)
       
    20 #include "apainternal.h"
       
    21 #endif
       
    22 #include "apaidpartner.h"
       
    23 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
       
    24 #include "apsserv.h"
       
    25 #include <fbs.h>
       
    26 
       
    27 #include "APASVST.H"
       
    28 #include "APAFLREC.H"
       
    29 
       
    30 #include <eikdll.h>
       
    31 
       
    32 NONSHARABLE_CLASS(CSvActiveScheduler) : public CActiveScheduler
       
    33 	{
       
    34 public:
       
    35 	static void NewLC();
       
    36 	virtual void Error(TInt anError) const;
       
    37 	};
       
    38 
       
    39 GLDEF_C void CSvActiveScheduler::NewLC()
       
    40 //
       
    41 // Create and install the active scheduler.
       
    42 //
       
    43 	{
       
    44 	CSvActiveScheduler* pA=new(ELeave) CSvActiveScheduler;
       
    45 	CleanupStack::PushL(pA);
       
    46 	CActiveScheduler::Install(pA);
       
    47 	}
       
    48 
       
    49 GLDEF_C void CSvActiveScheduler::Error(TInt) const
       
    50 //
       
    51 // Called if any Run() method leaves.
       
    52 //
       
    53 	{
       
    54 	}
       
    55 
       
    56 static void CleanupRFbsSession(TAny*)
       
    57 	{
       
    58 	RFbsSession::Disconnect();
       
    59 	}
       
    60 
       
    61 static void RunServerL()
       
    62 //
       
    63 // Perform all server initialisation, in particular creation of the
       
    64 // scheduler and server and then run the scheduler
       
    65 //
       
    66 	{
       
    67 	// create and install the active scheduler we need
       
    68 	CSvActiveScheduler::NewLC();
       
    69 
       
    70 	// create a RFbsSession
       
    71 	User::LeaveIfError(RFbsSession::Connect());
       
    72 	CleanupStack::PushL(TCleanupItem(CleanupRFbsSession, NULL));
       
    73 
       
    74 	// create the server (leave it on the cleanup stack)
       
    75 	CApaAppArcServer* appArcServer = CApaAppArcServer::NewL();
       
    76 	CleanupStack::PushL(appArcServer);
       
    77 
       
    78 	// Initialisation complete, now signal the client
       
    79 	RProcess::Rendezvous(KErrNone);
       
    80 
       
    81 	// Ready to run
       
    82 	CActiveScheduler::Start();
       
    83 
       
    84 	// Cleanup the server, RFbsSession and scheduler
       
    85 	CleanupStack::PopAndDestroy(3);
       
    86 	}
       
    87 
       
    88 static TInt RunServer()
       
    89 //
       
    90 // Main entry-point for the server thread
       
    91 //
       
    92 	{
       
    93 	__UHEAP_MARK;
       
    94 	TInt r;
       
    95 	// naming the server thread after the server helps to debug panics
       
    96 	r=RThread::RenameMe(NameApaServServerThread());
       
    97 	//
       
    98 	if (r == KErrNone)
       
    99 		{
       
   100 		CTrapCleanup* cleanup=CTrapCleanup::New();
       
   101 		r=KErrNoMemory;
       
   102 		if (cleanup)
       
   103 			{
       
   104 			TRAP(r,RunServerL());
       
   105 			REComSession::FinalClose();
       
   106 			delete cleanup;
       
   107 			}
       
   108 		}
       
   109 	//
       
   110 	__UHEAP_MARKEND;
       
   111 	return r;
       
   112 	}
       
   113 
       
   114 /**
       
   115 ApaServThreadStart
       
   116 
       
   117 @internalTechnology
       
   118 @released
       
   119 */
       
   120 EXPORT_C TInt ApaServThreadStart(TAny* /*aUnused*/)
       
   121 //
       
   122 // thread entry-point function.
       
   123 //
       
   124 	{
       
   125 	return RunServer();
       
   126 	}