sl@0: /*
sl@0: * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). 
sl@0: * All rights reserved.
sl@0: * This component and the accompanying materials are made available
sl@0: * under the terms of "Eclipse Public License v1.0"
sl@0: * which accompanies this distribution, and is available
sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: *
sl@0: * Initial Contributors:
sl@0: * Nokia Corporation - initial contribution.
sl@0: *
sl@0: * Contributors:
sl@0: *
sl@0: * Description:   DRM Play Server
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: #include <e32std.h>
sl@0: #include <e32svr.h>
sl@0: #include "DRMPlayClientServer.h"
sl@0: #include "DRMPlayServer.h"
sl@0: 
sl@0: 
sl@0: 
sl@0: CDRMPlayServer::CDRMPlayServer(TInt aPriority)
sl@0:     : CServer2(aPriority)
sl@0:     {
sl@0:     }
sl@0: 
sl@0: 
sl@0: // Create and start a new DRM play server.
sl@0: CDRMPlayServer* CDRMPlayServer::New()
sl@0:     {
sl@0:     CDRMPlayServer *pS=new CDRMPlayServer(EPriority);
sl@0:     __ASSERT_ALWAYS(pS!=NULL,PanicServer(ESvrCreateServer));
sl@0:     __ASSERT_ALWAYS(pS->Start(KDRMPlayServerName)==KErrNone, PanicServer(ESvrCreateServer));
sl@0:     return pS;
sl@0:     }
sl@0: 
sl@0: 
sl@0: // Create a new server session.
sl@0: CSession2 *CDRMPlayServer::NewSessionL(const TVersion& aVersion,const RMessage2& aMessage ) const
sl@0:     {
sl@0:     // check we're the right version
sl@0:     TVersion v(KDRMPlayServMajorVersionNumber,KDRMPlayServMinorVersionNumber,KDRMPlayServBuildVersionNumber);
sl@0:     if (!User::QueryVersionSupported(v,aVersion))
sl@0:         User::Leave(KErrNotSupported);
sl@0:     // make new session
sl@0:     return CDRMPlayServerSession::NewL(const_cast<CDRMPlayServer*>(this), aMessage);
sl@0:     }
sl@0: 
sl@0: CDRMPlayServer::~CDRMPlayServer()
sl@0:     {
sl@0: 
sl@0:     }
sl@0: 
sl@0: 
sl@0: // Panic the server
sl@0: GLDEF_C void PanicServer(TDRMPlayServPanic aPanic)
sl@0:     {
sl@0:     _LIT(KTxtServerPanic,"DRM Play server panic");
sl@0:     User::Panic(KTxtServerPanic,aPanic);
sl@0:     }
sl@0: 
sl@0: 
sl@0: static void StartDRMPlayServerL()
sl@0: // Perform all server initialisation, in particular creation of the
sl@0: // scheduler and server and then run the scheduler
sl@0: //
sl@0:     {
sl@0: 
sl@0: 
sl@0: 
sl@0:     // Naming the server thread after the server helps to debug panics
sl@0: 
sl@0:     User::LeaveIfError(User::RenameThread(KDRMPlayServerName));
sl@0: 
sl@0:     // Create and install the active scheduler we need
sl@0:     CActiveScheduler* scheduler = new(ELeave)CActiveScheduler;
sl@0:     CActiveScheduler::Install(scheduler);
sl@0: 
sl@0:     // create the server
sl@0:     CDRMPlayServer* server = CDRMPlayServer::New();
sl@0: 
sl@0:     // Initialisation complete, now signal the client
sl@0:     RProcess::Rendezvous(KErrNone);
sl@0: 
sl@0:     // Start the scheduler and wait for client requests
sl@0:     CActiveScheduler::Start();
sl@0: 
sl@0:     // Cleanup the server and scheduler
sl@0:     CActiveScheduler::Install(NULL);
sl@0:     delete scheduler;
sl@0:     delete server;
sl@0:     }
sl@0: 
sl@0: TInt E32Main()
sl@0: //
sl@0: // Server process entry-point
sl@0: // Recover the startup parameters and run the server
sl@0: //
sl@0:     {
sl@0:     __UHEAP_MARK;
sl@0:     //
sl@0:     CTrapCleanup* cleanup=CTrapCleanup::New();
sl@0:     TInt r=KErrNoMemory;
sl@0:     if (cleanup)
sl@0:         {
sl@0:         TRAP(r,StartDRMPlayServerL());
sl@0:         delete cleanup;
sl@0:         }
sl@0:     //
sl@0:     __UHEAP_MARKEND;
sl@0:     return r;
sl@0:     }
sl@0: 
sl@0: // End of file