uifw/AvKon/akncompamode/src/akncompasrvclient.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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:  Client interface to CompaKeySrv
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <coemain.h> // CCoeEnv
       
    20 
       
    21 #include "akncompasrv.h"
       
    22 #include "akncompasrvclient.h"
       
    23 
       
    24 // --------------------------------------------------------------------------
       
    25 // Start the server process
       
    26 // --------------------------------------------------------------------------
       
    27 static TInt StartServer()
       
    28     {
       
    29     // Simultaneous launching of two processes should be detected when
       
    30     // the second one attempts to create the server object, failing
       
    31     // with KErrAlreadyExists.
       
    32     const TUidType serverUid(KNullUid, KNullUid, KAknCompaSrvUid3);
       
    33     RProcess server;
       
    34     TInt r = server.Create(KAknCompaSrvName, KNullDesC, serverUid);
       
    35     if (r != KErrNone)
       
    36         {
       
    37         return r;        
       
    38         }
       
    39     TRequestStatus stat;
       
    40     server.Rendezvous(stat);
       
    41     if (stat!=KRequestPending)
       
    42         {
       
    43         server.Kill(0); // abort startup
       
    44         }
       
    45     else
       
    46         {
       
    47         server.Resume();// logon OK - start the server
       
    48         }
       
    49     User::WaitForRequest(stat); // wait for start or death
       
    50     // we can't use the 'exit reason' if the server panicked as this
       
    51     // is the panic 'reason' and may be '0' which cannot be distinguished
       
    52     // from KErrNone
       
    53     r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
       
    54     server.Close();
       
    55     return r;
       
    56     }
       
    57 
       
    58 // --------------------------------------------------------------------------
       
    59 // Connect to compa key-server
       
    60 // --------------------------------------------------------------------------
       
    61 TInt RAknCompaSrvSession::Connect()
       
    62     {
       
    63     TInt retry = KServerRetryCount;
       
    64     TInt r = KErrNone;
       
    65     while(ETrue)
       
    66         {
       
    67         r = CreateSession(KAknCompaSrvName, Version(),
       
    68             KAknCompaSrvMessageSlots);
       
    69         if( r != KErrNotFound && r != KErrServerTerminated)
       
    70             {
       
    71             return r;            
       
    72             }
       
    73         if(--retry == 0)
       
    74             {
       
    75             return r;            
       
    76             }
       
    77         r = StartServer();
       
    78         if( r!= KErrNone && r != KErrAlreadyExists)
       
    79             {
       
    80             return r;            
       
    81             }
       
    82         }
       
    83     }
       
    84 
       
    85 // --------------------------------------------------------------------------
       
    86 //
       
    87 // --------------------------------------------------------------------------
       
    88 TVersion RAknCompaSrvSession::Version(void) const
       
    89     {
       
    90     return TVersion(
       
    91         KAknCompaSrvMajorVersionNumber,
       
    92         KAknCompaSrvMinorVersionNumber,
       
    93         KAknCompaSrvBuildVersionNumber);
       
    94     }
       
    95 
       
    96 // --------------------------------------------------------------------------
       
    97 // Simulate key event to application
       
    98 // --------------------------------------------------------------------------
       
    99 void RAknCompaSrvSession::SimulateKeyEventL(TInt aScanCode, TBool aKeyDown)
       
   100     {
       
   101     TIpcArgs args(aScanCode, aKeyDown);
       
   102     User::LeaveIfError(SendReceive(ECompaSrvSimulateKeyEvent, args));
       
   103     }
       
   104 
       
   105 // --------------------------------------------------------------------------
       
   106 // Disable transition effects
       
   107 // --------------------------------------------------------------------------
       
   108 TInt RAknCompaSrvSession::DisaTransEffects()
       
   109     {
       
   110     return SendReceive(ECompaSrvDisaTransEffects);
       
   111     }
       
   112 
       
   113 // --------------------------------------------------------------------------
       
   114 // Restore transition effects to a state before DisaTransEffects()
       
   115 // --------------------------------------------------------------------------
       
   116 TInt RAknCompaSrvSession::RestoreTransEffects()
       
   117     {
       
   118     return SendReceive(ECompaSrvRestoreTransEffects);
       
   119     }