connectivitymodules/SeCon/catalogspcconnectivityplugin/src/catalogspcconnectivityclient.cpp
branchRCL_3
changeset 19 0aa8cc770c8a
parent 18 453dfc402455
child 20 4a793f564d72
equal deleted inserted replaced
18:453dfc402455 19:0aa8cc770c8a
     1 /*
       
     2 * Copyright (c) 2006 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 that communicate with CatalogsEnginePCClientFrontEnd
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "catalogspcconnectivityclient.h"
       
    20 #include "catalogspcconnectivitydefines.h"
       
    21 
       
    22 
       
    23 // ======== MEMBER FUNCTIONS ========
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // Constructor
       
    27 // ---------------------------------------------------------------------------
       
    28 //
       
    29 RCatalogsPCConnectivityClient::RCatalogsPCConnectivityClient()
       
    30     {
       
    31     }
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // Destructor
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 RCatalogsPCConnectivityClient::~RCatalogsPCConnectivityClient()
       
    38     {
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // Start server and create session with server
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 TInt RCatalogsPCConnectivityClient::Connect()
       
    46     {
       
    47     TInt err = StartServer();
       
    48         
       
    49     if ( err == KErrNone )
       
    50         {
       
    51         err = CreateSession( 
       
    52             KCatalogsPCConnectivityServerName,
       
    53             Version(), 
       
    54             KCatalogsPCConnectivityDefaultMessageSlots );
       
    55         }
       
    56     return err;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // Close session (After session is closed will server be closed too)
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 void RCatalogsPCConnectivityClient::Close()
       
    64     {
       
    65     RHandleBase::Close();
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // Give MIME types supported by this Module
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 RPointerArray<TDataType> RCatalogsPCConnectivityClient::
       
    73 SupportedMimeTypesL()
       
    74     {
       
    75     RPointerArray<TDataType> supportedMIMEs;
       
    76     TBool isThereMore = ETrue;
       
    77     TPckgBuf<TBool> pckgIsThereMore;
       
    78     TDataType* tempMIME = 0;
       
    79     TPckgBuf<TDataType> pckgMIME;
       
    80     
       
    81     while( isThereMore )
       
    82         {
       
    83         User::LeaveIfError( SendReceive( 
       
    84                 ECatalogsPCConnectivitySupportedMimeTypes, 
       
    85                 TIpcArgs( &pckgMIME, &pckgIsThereMore ) ) );
       
    86         isThereMore = pckgIsThereMore();
       
    87         tempMIME = new( ELeave ) TDataType( pckgMIME() );
       
    88         User::LeaveIfError( supportedMIMEs.Append( tempMIME ) );
       
    89         }
       
    90 
       
    91     return supportedMIMEs;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // Data package from CatalogsPCConnectivityPlugin
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void RCatalogsPCConnectivityClient::PutDataL( 
       
    99     const TDataType& aMimeType, const CBufFlat& aData )
       
   100     {
       
   101     TInt size = aData.Size();
       
   102     
       
   103     RBuf8 desData;
       
   104     desData.CreateL( size );
       
   105     desData.CleanupClosePushL();
       
   106     aData.Read( 0, desData, size );
       
   107     TPckgBuf<TDataType> pckgMIME( aMimeType );
       
   108 
       
   109     User::LeaveIfError( SendReceive( 
       
   110             ECatalogsPCConnectivityPutData, 
       
   111             TIpcArgs( &pckgMIME, &desData, size ) ) );
       
   112 
       
   113     CleanupStack::Pop(); //desData
       
   114     desData.Close();
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // Data request from CatalogsPCConnectivityPlugin
       
   119 // First ask the size from server, then give correct size CBufFlat
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void RCatalogsPCConnectivityClient::GetDataL( 
       
   123     TDataType& aMimeType, CBufFlat& aData )
       
   124     {
       
   125     TPckgBuf<TInt> pckgSize;
       
   126     TPckgBuf<TDataType> pckgMIME;
       
   127     
       
   128     User::LeaveIfError( SendReceive( 
       
   129             ECatalogsPCConnectivityGetSize, 
       
   130             TIpcArgs( &pckgMIME, &pckgSize ) ) );
       
   131     
       
   132     TInt size = pckgSize();
       
   133     aMimeType = pckgMIME();
       
   134     
       
   135     RBuf8 desData;
       
   136     desData.CreateL( size );
       
   137     desData.CleanupClosePushL();
       
   138     
       
   139     User::LeaveIfError( SendReceive( 
       
   140             ECatalogsPCConnectivityGetData, 
       
   141             TIpcArgs( &desData ) ) );
       
   142     
       
   143     aData.Reset();
       
   144     aData.ExpandL( 0, size );
       
   145     aData.Write( 0, desData, size );        
       
   146             
       
   147     CleanupStack::Pop(); //desData
       
   148     desData.Close();
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // Return version number
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 TVersion RCatalogsPCConnectivityClient::Version() const
       
   156     {
       
   157     return( TVersion( KCatalogsPCConnectivityMajorVersionNumber,
       
   158             KCatalogsPCConnectivityMinorVersionNumber,
       
   159             KCatalogsPCConnectivityBuildVersionNumber ) );
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // Start server if it isn't running already
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 TInt RCatalogsPCConnectivityClient::StartServer()
       
   167     {
       
   168     // Check if the server is already running
       
   169     TFindServer findServer( KCatalogsPCConnectivityServerName );
       
   170     TFullName name;
       
   171 
       
   172     TInt result = findServer.Next( name );
       
   173     if ( result == KErrNone )
       
   174         {
       
   175         // Server is running
       
   176         return KErrNone;
       
   177         }
       
   178 
       
   179     // Create a semaphore so we can wait while the server starts
       
   180     RSemaphore semaphore;
       
   181     result = semaphore.CreateGlobal( 
       
   182     	KCatalogsPCConnectivityServerSemaphoreName, 0 );
       
   183     if ( result != KErrNone )
       
   184         {
       
   185         return result;
       
   186         }
       
   187 
       
   188     // Create new Engine service process 
       
   189     result = CreateServerProcess();
       
   190     if ( result != KErrNone )
       
   191         {
       
   192         semaphore.Close();
       
   193         return result;
       
   194         }
       
   195 
       
   196     // Wait while the server starts
       
   197     semaphore.Wait();
       
   198 
       
   199     // Semaphore has been signaled, close and return
       
   200     semaphore.Close();
       
   201 
       
   202     return KErrNone;
       
   203     }
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // Create server process
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 TInt RCatalogsPCConnectivityClient::CreateServerProcess()
       
   210     {
       
   211 
       
   212     RProcess server;
       
   213 
       
   214     TInt result = server.Create( 
       
   215         KCatalogsPCConnectivityServerFilename, KNullDesC );
       
   216     if ( result != KErrNone )
       
   217         {
       
   218         return result;
       
   219         }
       
   220     
       
   221     // Resume server thread and close handle
       
   222     server.Resume();
       
   223     server.Close();  
       
   224 
       
   225     return KErrNone;
       
   226     }
       
   227 
       
   228 
       
   229 //end