bluetoothengine/btnotif/btnotifclient/src/btnotifclient.cpp
branchRCL_3
changeset 56 9386f31cc85b
parent 55 613943a21004
child 61 269724087bed
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
     1 /*
       
     2 * ============================================================================
       
     3 *  Name        : btnotifclient.cpp
       
     4 *  Part of     : bluetoothengine / btnotifclient
       
     5 *  Description : Session class for client-server interaction with btnotifserver.
       
     6 *
       
     7 *  Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     8 *  All rights reserved.
       
     9 *  This component and the accompanying materials are made available
       
    10 *  under the terms of "Eclipse Public License v1.0"
       
    11 *  which accompanies this distribution, and is available
       
    12 *  at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    13 *
       
    14 *  Initial Contributors:
       
    15 *  Nokia Corporation - initial contribution.
       
    16 *
       
    17 *  Contributors:
       
    18 *  Nokia Corporation
       
    19 * ============================================================================
       
    20 * Template version: 4.1
       
    21 */
       
    22 
       
    23 #include "btnotifclient.h"
       
    24 #include "btnotifclientserver.h"
       
    25 
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // start btnotif server from client.
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 TInt StartBTNotifSrv()
       
    32     {
       
    33     const TUidType serverUid( KNullUid, KNullUid, KBTNotifServerUid3 );
       
    34         // Create a new server process. Simultaneous launching of two processes 
       
    35         // should be detected when the second one attempts to create the server 
       
    36         // object, failing with KErrAlreadyExists.
       
    37     RProcess server;
       
    38     TInt err = server.Create( KBTNotifServerName, KNullDesC, serverUid );
       
    39     if( err != KErrNone )
       
    40         {
       
    41         return err;
       
    42         }
       
    43     TRequestStatus status;
       
    44     server.Rendezvous( status );
       
    45     if( status != KRequestPending )
       
    46         {
       
    47         server.Kill( KErrCancel );  // Abort startup
       
    48         }
       
    49     else
       
    50         {
       
    51         server.Resume();
       
    52         }
       
    53     User::WaitForRequest( status ); // Wait for start or death
       
    54     err = status.Int();
       
    55     if( server.ExitType() == EExitPanic )
       
    56         {
       
    57         // The server actually panicked; inform the client.
       
    58         err = KErrDied;
       
    59         }
       
    60     server.Close();
       
    61     return err;
       
    62     }
       
    63 
       
    64 // ======== MEMBER FUNCTIONS ========
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // Constructor
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 EXPORT_C RBTNotifier::RBTNotifier()
       
    71 :   RSessionBase()
       
    72     {
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // Return the client-server version number we implement.
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C TVersion RBTNotifier::Version()
       
    80     {
       
    81     return TVersion( KBTNotifServerVersionMajor, KBTNotifServerVersionMinor, 
       
    82                 KBTNotifServerVersionBuild );
       
    83     }
       
    84 
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // Connect to the notifier server. Start the server if necessary.
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 EXPORT_C TInt RBTNotifier::Connect()
       
    91     {
       
    92     TInt err = CreateSession( KBTNotifServerName, Version() );
       
    93     if( err == KErrNotFound || err == KErrServerTerminated )
       
    94         {
       
    95         err = StartBTNotifSrv();
       
    96         if( err == KErrNone || err == KErrAlreadyExists )
       
    97             {
       
    98             err = CreateSession( KBTNotifServerName, Version() );
       
    99             }
       
   100         }
       
   101     return err;
       
   102     }
       
   103 
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // Start the specified notifier, synchronous call.
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 EXPORT_C TInt RBTNotifier::StartNotifier( TUid aNotifierUid, const TDesC8& aBuffer )
       
   110     {
       
   111     return SendReceive( EBTNotifStartSyncNotifier,
       
   112                 TIpcArgs( (TInt) aNotifierUid.iUid, &aBuffer ) );
       
   113     }
       
   114 
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // Start the specified notifier, asynchronous call.
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 EXPORT_C void RBTNotifier::StartNotifierAndGetResponse( TRequestStatus& aRs,
       
   121     TUid aNotifierUid, const TDesC8& aBuffer, TDes8& aResponse )
       
   122     {
       
   123     SendReceive( EBTNotifStartAsyncNotifier,
       
   124                 TIpcArgs( (TInt) aNotifierUid.iUid, &aBuffer, &aResponse ), aRs );
       
   125     }
       
   126 
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // Cancel the specified notifier.
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 EXPORT_C TInt RBTNotifier::CancelNotifier( TUid aNotifierUid )
       
   133     {
       
   134     return SendReceive( EBTNotifCancelNotifier, TIpcArgs( (TInt) aNotifierUid.iUid ) );
       
   135     }
       
   136 
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // Update the specified notifier, synchronous call.
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 EXPORT_C TInt RBTNotifier::UpdateNotifier( TUid aNotifierUid, 
       
   143     const TDesC8& aBuffer, TDes8& aResponse )
       
   144     {
       
   145     return SendReceive( EBTNotifUpdateNotifier,
       
   146                 TIpcArgs( (TInt) aNotifierUid.iUid, &aBuffer, &aResponse ) );
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // Issue a pairing request. asynchronous call.
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 EXPORT_C void RBTNotifier::PairDevice( const TBTDevAddrPckgBuf& aDevice, 
       
   154     TInt32 aDeviceClass, TRequestStatus& aStatus )
       
   155     {
       
   156     SendReceive( EBTNotifPairDevice,
       
   157                 TIpcArgs( (TInt) EBTNotifPairDevice, &aDevice, aDeviceClass ), aStatus );
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // Cancel an ongoing pair request.
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 EXPORT_C void RBTNotifier::CancelPairDevice()
       
   165     {
       
   166     (void) SendReceive( EBTNotifCancelPairDevice );
       
   167     }