videoconnutility/connutility/src/vcxconnectionutility.cpp
branchRCL_3
changeset 23 13a33d82ad98
parent 0 822a42b6c3f1
equal deleted inserted replaced
22:826cea16efd9 23:13a33d82ad98
       
     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 the License "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:    Class to handle connection creation.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32cmn.h>
       
    22 #include <e32std.h>
       
    23 #include <mpxlog.h>
       
    24 
       
    25 #include <ipvideo/vcxconnectionutility.h>
       
    26 #include <ipvideo/tvcxconnutilnotifierparams.h>
       
    27 #include "vcxconnectionutility.hrh"
       
    28 #include "vcxconnutilimpl.h"
       
    29 
       
    30 // CONSTANTS 
       
    31 const TInt KVCxConnUtilAppUid =  0x20016BA1;
       
    32 
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CVcxConnectionUtility::InstanceL()
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 EXPORT_C CVcxConnectionUtility* CVcxConnectionUtility::InstanceL()
       
    41     {
       
    42     MPX_DEBUG1("vcxconnutil ## CVcxConnectionUtility::InstanceL() in");
       
    43     
       
    44     CVcxConnectionUtility* self = NULL;
       
    45     TAny* instance = UserSvr::DllTls( KVCxConnUtilAppUid );
       
    46     
       
    47     if ( !instance )
       
    48         {
       
    49         self = new( ELeave ) CVcxConnectionUtility;
       
    50         CleanupStack::PushL( self );
       
    51         self->ConstructL();
       
    52         User::LeaveIfError( UserSvr::DllSetTls( KVCxConnUtilAppUid, self ) );
       
    53         CleanupStack::Pop( self );
       
    54         }
       
    55     else
       
    56         {
       
    57         self = reinterpret_cast<CVcxConnectionUtility*>( instance );
       
    58         }
       
    59     self->iReferenceCount++;
       
    60        
       
    61     MPX_DEBUG1("vcxconnutil ## CVcxConnectionUtility::InstanceL() out");
       
    62     
       
    63     return self;
       
    64 
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CVcxConnectionUtility::DecreaseReferenceCount()
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C void CVcxConnectionUtility::DecreaseReferenceCount()
       
    72     {
       
    73     TAny* singleton = UserSvr::DllTls( KVCxConnUtilAppUid );
       
    74 
       
    75     if ( singleton == this )
       
    76         {
       
    77         iReferenceCount--;
       
    78         if( iReferenceCount == 0 )
       
    79             {
       
    80             UserSvr::DllFreeTls( KVCxConnUtilAppUid );
       
    81             delete this;
       
    82             }
       
    83         }
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CVcxConnectionUtility::ConstructL()
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CVcxConnectionUtility::ConstructL()
       
    91     {
       
    92     MPX_DEBUG1("vcxconnutil ## CVcxNsConnectionUtility::ConstructL() in");
       
    93         
       
    94     iUtilImpl = CVcxConnUtilImpl::NewL( this );
       
    95      
       
    96     MPX_DEBUG1("vcxconnutil ## CVcxNsConnectionUtility::ConstructL() out");
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CVcxConnectionUtility::CVcxNsConnectionUtility()
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 CVcxConnectionUtility::CVcxConnectionUtility( ) :
       
   104 CActive( EPriorityStandard )
       
   105     {
       
   106     CActiveScheduler::Add(this); 
       
   107     }
       
   108     
       
   109 // -----------------------------------------------------------------------------
       
   110 // CVcxConnectionUtility::~CVcxConnectionUtility()
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 CVcxConnectionUtility::~CVcxConnectionUtility()
       
   114     {   
       
   115     MPX_DEBUG1("vcxconnutil ## CVcxConnectionUtility::~CConnectionManager in");
       
   116     CloseWaitNote(); 
       
   117   
       
   118     delete iUtilImpl;   
       
   119     iNotifier.Close();
       
   120     
       
   121     MPX_DEBUG1("vcxconnutil ## CVcxConnectionUtility::~CConnectionManager out");
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CVcxConnectionUtility::RegisterObserverL
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 EXPORT_C void CVcxConnectionUtility::RegisterObserverL( MConnUtilEngineObserver* aObserver )
       
   129    {
       
   130    iUtilImpl->RegisterObserverL( aObserver );
       
   131    }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CVcxConnectionUtility::RemoveObserver
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 EXPORT_C void CVcxConnectionUtility::RemoveObserver( MConnUtilEngineObserver* aObserver )
       
   138    {
       
   139    iUtilImpl->RemoveObserver( aObserver );
       
   140    }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CVcxConnectionUtility::GetIap
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 EXPORT_C TInt CVcxConnectionUtility::GetIap( TUint32& aIapId, TBool aSilent )
       
   147     {
       
   148     MPX_DEBUG1("vcxconnutil ## CVcxConnectionUtility::GetIap in ");
       
   149     TInt err( KErrNone );
       
   150     
       
   151     err = iUtilImpl->GetIap( aIapId, aSilent );
       
   152     
       
   153     MPX_DEBUG2("vcxconnutil ## CVcxConnectionUtility::GetIap out error: %d ", err );
       
   154     return err;
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CVcxConnectionUtility::WapIdFromIapIdL
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 EXPORT_C TUint32 CVcxConnectionUtility::WapIdFromIapIdL( TUint32 aIapId )
       
   162     {
       
   163     MPX_DEBUG1("vcxconnutil ## CVcxConnectionUtility::WapIdFromIapIdL in ");
       
   164     TUint32 wapId = iUtilImpl->WapIdFromIapIdL( aIapId );
       
   165     MPX_DEBUG1("vcxconnutil ## CVcxConnectionUtility::WapIdFromIapIdL out ");
       
   166     return wapId;
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CVcxConnectionUtility::Disconnect()
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 EXPORT_C void CVcxConnectionUtility::DisconnectL()
       
   174     {
       
   175     MPX_DEBUG1( "vcxconnutil ## CVcxConnectionUtility::Disconnect in");
       
   176     if( iReferenceCount <= 1 )
       
   177         {
       
   178         iUtilImpl->DisconnectL();
       
   179         }
       
   180     MPX_DEBUG1( "vcxconnutil ## CVcxConnectionUtility::Disconnect out");
       
   181     }
       
   182 
       
   183 
       
   184 void CVcxConnectionUtility::RunL()
       
   185     {
       
   186     TInt err = iStatus.Int();
       
   187     if ( iStatus.Int() == KErrCancel && 
       
   188          iUtilImpl->EngineConnectionStatus() == EVCxConnecting )
       
   189         {
       
   190         // This implifies that user has cancelled connecting dialog,
       
   191         // if currently connecting, disconnect
       
   192         TRAP_IGNORE( iUtilImpl->DisconnectL() );       
       
   193         }
       
   194     }
       
   195 
       
   196 
       
   197 void CVcxConnectionUtility::DoCancel()
       
   198     {
       
   199     // complete request if we're active.
       
   200     // othervise app blocks
       
   201     if( IsActive() )
       
   202         {
       
   203         TRequestStatus* s = &iStatus;
       
   204         User::RequestComplete( s, KErrNone );    
       
   205         }
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CVcxConnectionUtility::DisplayWaitNote()
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CVcxConnectionUtility::DisplayWaitNote(const TDesC& aConnectionName)
       
   213      {
       
   214      if( !IsActive() )
       
   215          {
       
   216          TVcxNotifierParams value;
       
   217          value.iEvent = TVcxNotifierParams::EConnecting;            
       
   218          
       
   219          value.iMsg = aConnectionName;
       
   220         
       
   221          TPckg<TVcxNotifierParams> param( value );                                   
       
   222         
       
   223          TPckgBuf<TBool> resultPckg; // Output parameters
       
   224         
       
   225          // get connection to the notify server         
       
   226          iNotifier.Close();
       
   227          
       
   228          if( iNotifier.Connect() == KErrNone )
       
   229              {        
       
   230              iStatus = KRequestPending;
       
   231              iNotifier.StartNotifierAndGetResponse( iStatus, KVcxNotifierImplUid, 
       
   232                                                      param, resultPckg );        
       
   233              SetActive();
       
   234              }
       
   235          }
       
   236      }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // CVcxConnectionUtility::CloseWaitNote()
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 void CVcxConnectionUtility::CloseWaitNote()
       
   243     {
       
   244     
       
   245     if( IsActive() )
       
   246         {
       
   247         Cancel();
       
   248         }
       
   249     
       
   250     TVcxNotifierParams value;
       
   251     value.iEvent = TVcxNotifierParams::EConnected;             
       
   252     value.iMsg.Zero();
       
   253     
       
   254     TPckg<TVcxNotifierParams> param( value );                                   
       
   255 
       
   256     TPckgBuf<TBool> resultPckg; 
       
   257 
       
   258     iNotifier.Close();
       
   259     
       
   260     if( iNotifier.Connect() == KErrNone )
       
   261         {
       
   262 
       
   263         TRequestStatus stat;
       
   264         iNotifier.StartNotifierAndGetResponse( stat, KVcxNotifierImplUid, param, resultPckg );
       
   265     
       
   266         User::WaitForRequest( stat );
       
   267     
       
   268         iNotifier.Close();
       
   269         }
       
   270     }
       
   271 
       
   272 //  End of File