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