phoneclientserver/phoneclient/Src/ExtCallWrapper/CPhCltExtPhone.cpp
changeset 0 ff3b6d0fd310
child 19 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Ext Phone for dialing.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <e32std.h>
       
    22 #include    "RPhCltExtCall.h"
       
    23 #include    "RPhCltServer.h"
       
    24 #include    "MPhCltExtPhoneObserver.h"
       
    25 #include    "CPhCltExtPhone.h"
       
    26 
       
    27 
       
    28 // LOCAL CONSTANTS AND MACROS
       
    29 
       
    30 // Panic codes.
       
    31 enum TPhCltExtPhonePanic
       
    32     {
       
    33     EPhCltExtPhonePanicNoObserver,           // No observer found.
       
    34     EPhCltExtPhonePanicInvalidOperationMode  // Operation mode was invalid.
       
    35     };
       
    36 
       
    37 
       
    38 // LOCAL FUNCTION PROTOTYPES
       
    39 
       
    40 // Panic function. Called if panic situation happens.
       
    41 void Panic( TPhCltExtPhonePanic aPanic );
       
    42 
       
    43 
       
    44 
       
    45 // ============================= LOCAL FUNCTIONS ===============================
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // Panic
       
    49 // 
       
    50 // Panics the client
       
    51 //
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void Panic( TPhCltExtPhonePanic aPanic )
       
    55     {
       
    56     _LIT(KPhCltExtPhonePanicCategory, "CPhCltExtPhone");
       
    57     User::Panic( KPhCltExtPhonePanicCategory, aPanic );
       
    58     }
       
    59 
       
    60 
       
    61 
       
    62 // ============================ MEMBER FUNCTIONS ===============================
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CPhCltExtPhone::NewL
       
    66 // Two-phased constructor.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CPhCltExtPhone* CPhCltExtPhone::NewL( MPhCltExtPhoneObserver* aObserver )
       
    70     {
       
    71     CPhCltExtPhone* self = new ( ELeave ) CPhCltExtPhone( aObserver );
       
    72     
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL();
       
    75     CleanupStack::Pop();
       
    76 
       
    77     return self;
       
    78     }   
       
    79 
       
    80 
       
    81 // Destructor
       
    82 CPhCltExtPhone::~CPhCltExtPhone()
       
    83     {
       
    84     // Cancel, close subsessions and finally close the session.
       
    85 
       
    86     Cancel();
       
    87     iCall.Close();
       
    88     iServer.Close();
       
    89     }
       
    90 
       
    91 
       
    92 
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CPhCltExtPhone::DialL
       
    96 // 
       
    97 // If a request is pending, leave with error code KErrInUse.
       
    98 // Otherwise, create a dial request. 
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CPhCltExtPhone::DialL( const TPhCltExtPhoneDialData& aData )
       
   102     {
       
   103     DialPreconditionCheckL();
       
   104     iCall.Dial( iStatus, aData );
       
   105     }
       
   106 
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CPhCltExtPhone::CPhCltExtPhone
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 CPhCltExtPhone::CPhCltExtPhone( MPhCltExtPhoneObserver* aObserver )
       
   113     : CPhCltExtPhoneBase( aObserver ), iMode( EIdle )
       
   114     {
       
   115     CActiveScheduler::Add( this );
       
   116     }
       
   117 
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CPhCltExtPhone::ConstructL
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CPhCltExtPhone::ConstructL() 
       
   124     {
       
   125     User::LeaveIfError( iServer.Connect() );
       
   126     User::LeaveIfError( iCall.Open( iServer ) );
       
   127     }
       
   128 
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CPhCltExtPhone::RunL
       
   132 // 
       
   133 // The method is called when a request is completed. Thus,
       
   134 // it calls appropriate observer method.
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CPhCltExtPhone::RunL()
       
   138     {
       
   139     __ASSERT_ALWAYS( iObserver, Panic( EPhCltExtPhonePanicNoObserver ) );
       
   140     if( iStatus != KErrCancel )
       
   141         {
       
   142         switch( iMode )
       
   143             {                         
       
   144             case EDialling:
       
   145                 iObserver->HandleDialL( iStatus.Int() );
       
   146                 break;
       
   147             case EIdle:
       
   148                 break;
       
   149             default:
       
   150                 Panic( EPhCltExtPhonePanicInvalidOperationMode );
       
   151                 break;
       
   152             }
       
   153         }
       
   154     }
       
   155 
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CPhCltExtPhone::DoCancel
       
   159 // 
       
   160 // Cancels the pending request.
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CPhCltExtPhone::DoCancel()
       
   164     {
       
   165     switch( iMode )
       
   166         {                         
       
   167         case EDialling:
       
   168             iCall.CancelDial();
       
   169             break;
       
   170         case EIdle:
       
   171             break;
       
   172         default:
       
   173             Panic( EPhCltExtPhonePanicInvalidOperationMode );
       
   174             break;
       
   175         }
       
   176     }
       
   177 
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CPhCltExtPhone::DialPreconditionCheckL
       
   181 // 
       
   182 // See header
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CPhCltExtPhone::DialPreconditionCheckL()
       
   186     {
       
   187     if( IsActive() )
       
   188         {
       
   189         User::Leave( KErrInUse );
       
   190         }
       
   191     if( iCall.SubSessionHandle() == 0 )
       
   192         {
       
   193         User::Leave( KErrBadHandle );
       
   194         }
       
   195     iMode = EDialling;
       
   196     SetActive();
       
   197     }
       
   198 
       
   199 
       
   200 //  End of File