Msrp/MsrpClient/src/RMSRP.cpp
branchMSRP_FrameWork
changeset 25 505ad3f0ce5c
equal deleted inserted replaced
22:f1578314b8da 25:505ad3f0ce5c
       
     1 /*
       
     2 * Copyright (c) 2009-2010 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 * Initial Contributors:
       
     9 * Nokia Corporation - initial contribution.
       
    10 * Contributors:
       
    11 *
       
    12 * Description:
       
    13 * MSRP Implementation
       
    14 *
       
    15 */
       
    16 
       
    17 //  Include Files
       
    18 #include "MsrpCommon.h"
       
    19 #include "RMSRP.h"
       
    20 
       
    21 
       
    22 //  Member Functions
       
    23 
       
    24 RMSRP::RMSRP() : 
       
    25     RSessionBase()
       
    26     {
       
    27     MSRPLOG("RMSRP.. Ctor");
       
    28     }
       
    29 
       
    30 TInt RMSRP::CreateServerSession()
       
    31     {
       
    32     MSRPLOG("RMSRP.. ");
       
    33     TInt result = StartServer();
       
    34     if (( result == KErrNone) || (result == KErrAlreadyExists))
       
    35         {
       
    36         MSRPLOG("RMSRP.. Create client-server session");
       
    37         result = CreateSession( KMSRPServerName, Version() );
       
    38         }
       
    39 
       
    40     return result;
       
    41     }
       
    42 
       
    43 TVersion RMSRP::Version() const
       
    44     {
       
    45     
       
    46     MSRPLOG("RMSRP.. Get version");
       
    47     
       
    48     return TVersion(
       
    49         KMSRPServerMajorVersionNumber,
       
    50         KMSRPServerMinorVersionNumber,
       
    51         KMSRPServerBuildVersionNumber );
       
    52     }
       
    53 
       
    54 TInt RMSRP::StartServer( ) const
       
    55     {
       
    56     
       
    57     MSRPLOG("RMSRP.. Start transient server");
       
    58     
       
    59     RProcess p; // codescanner::resourcenotoncleanupstack
       
    60     TRequestStatus status;
       
    61 
       
    62     TBuf< KSizeOfProgramPath > serverPath;
       
    63     serverPath.Append( KMSRPExe );
       
    64 
       
    65     TInt err = p.Create( serverPath, KNullDesC );
       
    66     if ( err == KErrAlreadyExists )
       
    67         {
       
    68         return KErrNone;
       
    69         }
       
    70 
       
    71     if ( err != KErrNone )
       
    72         {
       
    73         return err;
       
    74         }
       
    75 
       
    76     // wait for server
       
    77     p.Rendezvous( status );
       
    78 
       
    79     if ( status != KRequestPending )
       
    80         {
       
    81         p.Kill(0); // abort startup
       
    82         p.Close();
       
    83         return KErrGeneral;
       
    84         }
       
    85     else
       
    86         {
       
    87         p.Resume(); // logon OK - start the server
       
    88         }
       
    89 
       
    90     User::WaitForRequest( status ); // codescanner::userWaitForRequest
       
    91     
       
    92     if (p.ExitType()==EExitPanic)
       
    93         {
       
    94         status = KErrServerTerminated;
       
    95         }
       
    96   
       
    97     if ( status != KErrNone )
       
    98         {
       
    99         p.Close();
       
   100         return status.Int();
       
   101         }
       
   102     p.Close();
       
   103 
       
   104     return KErrNone;
       
   105     }
       
   106