contentcontrolsrv/ccclientsession/src/ccclientsession.cpp
changeset 0 79c6a41cd166
child 18 bd874ee5e5e2
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2  * Copyright (c) 2008 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  *
       
    16  */
       
    17 
       
    18 // System include files
       
    19 
       
    20 // User include files
       
    21 #include "ccclientsession.h"
       
    22 #include "ccresource.h"
       
    23 #include "ccsrvapi.h"
       
    24 
       
    25 
       
    26 // Local constants
       
    27 // Home screen content control server definitions
       
    28 const TUid KCcServerUid3 = {0x20026f53};
       
    29 _LIT( KCcSrvName,"ccserver" );
       
    30 const TUint KCcSrvMajorVersionNumber = 1;
       
    31 const TUint KCcSrvMinorVersionNumber = 0;
       
    32 const TUint KCcSrvBuildVersionNumber = 0;
       
    33 
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // StartServer()
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 static TInt StartServer()
       
    40     {
       
    41     const TUidType serverUid( KNullUid,KNullUid,KCcServerUid3 );
       
    42     RProcess server;
       
    43     TInt r = server.Create( KCcSrvName,KNullDesC );
       
    44     if ( r != KErrNone )
       
    45         {
       
    46         return r;
       
    47         }
       
    48     TRequestStatus stat;
       
    49     server.Rendezvous( stat );
       
    50     if ( stat != KRequestPending )
       
    51         {
       
    52         server.Kill( 0 );   // abort startup
       
    53         }
       
    54     else
       
    55         {
       
    56         server.Resume();  // logon OK - start the server
       
    57         }
       
    58 
       
    59     User::WaitForRequest( stat );   // wait for start or death
       
    60 
       
    61     r=( server.ExitType() == EExitPanic ) ? KErrGeneral : stat.Int();
       
    62     server.Close();
       
    63     return r;
       
    64     }
       
    65 
       
    66 // ======== MEMBER FUNCTIONS ========
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // RCcClientSession::Connect
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 EXPORT_C TInt RCcClientSession::Connect()
       
    73     {
       
    74     TVersion ver = TVersion(
       
    75         KCcSrvMajorVersionNumber,
       
    76         KCcSrvMinorVersionNumber,
       
    77         KCcSrvBuildVersionNumber);    
       
    78     TInt retry=2;
       
    79     for (;;)
       
    80         {
       
    81         TInt r = CreateSession( KCcSrvName, ver );
       
    82   
       
    83         if (r != KErrNotFound && r != KErrServerTerminated)
       
    84             {
       
    85             return r;
       
    86             }
       
    87         
       
    88         if ( --retry==0 )
       
    89             {
       
    90             return r;
       
    91             }
       
    92         
       
    93         r = StartServer();
       
    94         if ( r!=KErrNone && r!=KErrAlreadyExists )
       
    95             {
       
    96             return r;
       
    97             }
       
    98         }
       
    99     }
       
   100   
       
   101 // -----------------------------------------------------------------------------
       
   102 // RCcClientSession::Close()
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 EXPORT_C void RCcClientSession::Close()
       
   106     {
       
   107     RSessionBase::Close();
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // RCcClientSession::RegisterProvider()
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 EXPORT_C TInt RCcClientSession::RegisterProvider(
       
   115     TPckgBuf<TUint32>& aProvider,
       
   116     TPckgBuf<TUint32>& aAddress )
       
   117     {
       
   118     TInt err = SendReceive( 
       
   119         ECcReqisterProvider, 
       
   120         TIpcArgs( &aProvider,&aAddress,0,0 ) );
       
   121     return err;
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // RCcClientSession::RegisterObserver()
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 EXPORT_C TInt RCcClientSession::RegisterObserver(
       
   129     TPckgBuf<TUint32>& aProvider,
       
   130     TPckgBuf<TUint32>& aAddress )
       
   131     {
       
   132     TInt err = SendReceive( 
       
   133         ECcRegisterObserver, 
       
   134         TIpcArgs( &aProvider,&aAddress,0,0 ) );
       
   135     return err;
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // RCcClientSession::CancelReq()
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 EXPORT_C TInt RCcClientSession::CancelReq(
       
   143     TPckgBuf<TInt>& aFunction )
       
   144     {
       
   145     TInt err = SendReceive( 
       
   146         ECcCancel, 
       
   147         TIpcArgs( &aFunction,0,0,0 ) );
       
   148     return err;
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // RCcClientSession::WaitForApiReq()
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 EXPORT_C void RCcClientSession::WaitForApiReq(
       
   156     TPckgBuf<TUint32>& aProvider,
       
   157     TPckgBuf<TUint32>& aSender,
       
   158     TPckgBuf<TUint32>& aReceiver,
       
   159     TPtr8& aBuf,
       
   160     TRequestStatus& aStatus )
       
   161     {
       
   162     SendReceive( 
       
   163         ECcWaitForApiReq, 
       
   164         TIpcArgs( &aProvider,
       
   165                   &aSender, 
       
   166                   &aReceiver, 
       
   167                   &aBuf ),
       
   168         aStatus );
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // RCcClientSession::WaitForApiNtf()
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 EXPORT_C void RCcClientSession::WaitForApiNtf(
       
   176     TPckgBuf<TUint32>& aProvider,
       
   177     TPckgBuf<TUint32>& aSender,
       
   178     TPckgBuf<TUint32>& aReceiver,
       
   179     TPtr8& aBuf,
       
   180     TRequestStatus& aStatus )
       
   181     {
       
   182     SendReceive( 
       
   183         ECcWaitForApiNtf, 
       
   184         TIpcArgs( &aProvider,
       
   185                   &aSender, 
       
   186                   &aReceiver, 
       
   187                   &aBuf ),
       
   188         aStatus );
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // RCcClientSession::Send()
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 EXPORT_C TInt RCcClientSession::Send(
       
   196     TInt aFunction,
       
   197     TPckgBuf<TUint32>& aProvider,
       
   198     TPckgBuf<TUint32>& aSender,
       
   199     TPckgBuf<TUint32>& aReceiver,
       
   200     TPtr8& aBuf )
       
   201     {    
       
   202     TInt err = SendReceive( 
       
   203         aFunction, 
       
   204         TIpcArgs( &aProvider, 
       
   205                   &aSender, 
       
   206                   &aReceiver, 
       
   207                   &aBuf ) );
       
   208     return err;
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // RCcClientSession::GetMsgData()
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 EXPORT_C TInt RCcClientSession::GetMsgData(
       
   216     TPckgBuf<TUint32>& aTrId,
       
   217     TPtr8& aBuf )
       
   218     {    
       
   219     TInt err = SendReceive( 
       
   220         ECcGetMsgData, 
       
   221         TIpcArgs( &aTrId, &aBuf, 0, 0) );
       
   222     return err;
       
   223     }
       
   224 
       
   225 // End of file