mmserv/sts/stsimplementation/src/rstssession.cpp
changeset 14 80975da52420
child 16 43d09473c595
equal deleted inserted replaced
12:5a06f39ad45b 14:80975da52420
       
     1 /*
       
     2  * Copyright (c) 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  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  * The file provides the implementation of the client side session
       
    16  * to the STS Server.
       
    17  */
       
    18 
       
    19 #include "rstssession.h"
       
    20 #include "stsclientservercommon.h"
       
    21 
       
    22 const TUint KNumSlots = 30;
       
    23 
       
    24 TInt RStsSession::StartServer()
       
    25     {
       
    26     TInt err = KErrNone;
       
    27 
       
    28     // Launch the server executable (i.e. in it its own process).
       
    29 
       
    30     // Create a new server process. Simultaneous launching of two such processes 
       
    31     // should be detected when the second one attempts to create the server 
       
    32     // object, failing with KErrAlreadyExists.
       
    33     RProcess server;
       
    34     err = server.Create(KStsServerFile, KNullDesC);
       
    35 
       
    36     if (err == KErrNone)
       
    37         {
       
    38         TRequestStatus rendezvousStatus;
       
    39         server.Rendezvous(rendezvousStatus);
       
    40 
       
    41         if (rendezvousStatus != KRequestPending)
       
    42             {
       
    43             server.Kill(0); // abort startup
       
    44             }
       
    45         else
       
    46             {
       
    47             server.Resume(); // logon OK - start the server thread
       
    48             } // end if
       
    49 
       
    50         User::WaitForRequest(rendezvousStatus); // wait for start or death
       
    51 
       
    52         // we can't use the 'exit reason' if the server panicked as this
       
    53         // is the panic 'reason' and may be '0' which cannot be distinguished
       
    54         // from KErrNone  
       
    55         err = (server.ExitType() == EExitPanic)
       
    56                                                 ? KErrGeneral
       
    57                                                    : rendezvousStatus.Int();
       
    58         server.Close();
       
    59         }
       
    60 
       
    61     return err;
       
    62     }
       
    63 
       
    64 TInt RStsSession::Connect()
       
    65     {
       
    66     TInt result = CreateSession(KStsServerName, TVersion(
       
    67             KStsServerMajorVersion, KStsServerMinorVersion, KStsServerBuild),
       
    68             KNumSlots, EIpcSession_Sharable);
       
    69 
       
    70     if (result == KErrNotFound)
       
    71         {
       
    72         result = StartServer();
       
    73         if (result == KErrNone || result == KErrAlreadyExists)
       
    74             {
       
    75             result = CreateSession(KStsServerName, TVersion(
       
    76                     KStsServerMajorVersion, KStsServerMinorVersion,
       
    77                     KStsServerBuild), KNumSlots);
       
    78             }
       
    79         }
       
    80 
       
    81     if (result == KErrNone)
       
    82         {
       
    83         result = ShareAuto();
       
    84 
       
    85         if (result != KErrNone)
       
    86             {
       
    87             Close();
       
    88             }
       
    89         }
       
    90 
       
    91     return result;
       
    92     }
       
    93 
       
    94 void RStsSession::Close()
       
    95     {
       
    96     RSessionBase::Close();
       
    97     }
       
    98 
       
    99 TInt RStsSession::SendPlayTone(CSystemToneService::TToneType aToneType,
       
   100         unsigned int& aPlayToneContext)
       
   101     {
       
   102     TPckg<unsigned int> playToneContextPckg(aPlayToneContext);
       
   103     return SendReceive(StsMsg_PlayTone, TIpcArgs((TInt) aToneType,
       
   104             &playToneContextPckg));
       
   105     }
       
   106 
       
   107 TInt RStsSession::SendStopTone(unsigned int aPlayToneContext)
       
   108     {
       
   109     return SendReceive(StsMsg_StopTone, TIpcArgs(aPlayToneContext));
       
   110     }