connectionmonitoring/connmon/connectionmonitor/src/CCsdFax.cpp
changeset 0 5a93021fdf25
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2002-2009 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:  Provides information on CSD fax calls.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <mmtsy_names.h>
       
    19 #include <rmmcustomapi.h>
       
    20 #include "ConnMonServ.h"
       
    21 #include "ConnMonIAP.h"
       
    22 #include "CEventQueue.h"
       
    23 #include "CCsdFax.h"
       
    24 #include "log.h"
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CCsdFax::CCsdFax
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CCsdFax::CCsdFax(
       
    31         CConnMonServer* aServer,
       
    32         RTelServer* aTelServer,
       
    33         RMobilePhone* aMobilePhone )
       
    34         :
       
    35         iServer( aServer ),
       
    36         iTelServer( aTelServer ),
       
    37         iMobilePhone( aMobilePhone )
       
    38     {
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CCsdFax::ConstructL
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 void CCsdFax::ConstructL()
       
    46     {
       
    47     //LOGENTRFN("CCsdFax::ConstructL()")
       
    48     // Open "Data" line
       
    49     TInt ret = iLine.Open( *iMobilePhone, KMmTsyDataLineName );
       
    50 
       
    51     if ( ret != KErrNone )
       
    52         {
       
    53         LOGIT("CCsdFax: Could not open data line.")
       
    54         return;
       
    55         }
       
    56     else
       
    57         {
       
    58         iState = ELineOpen;
       
    59         }
       
    60 
       
    61     // Start external connection Up notifier
       
    62     if ( iConnUpNotifier == 0 )
       
    63         {
       
    64         iConnUpNotifier = new( ELeave ) CCsdFaxUpNotifier(
       
    65                 this,
       
    66                 iServer,
       
    67                 iMobilePhone,
       
    68                 iLine);
       
    69         iConnUpNotifier->Construct();
       
    70         iConnUpNotifier->Receive();
       
    71         }
       
    72 
       
    73     // Start external connection Up notifier
       
    74     if ( iStatusNotifier == 0 )
       
    75         {
       
    76         iStatusNotifier = new( ELeave ) CCsdStatusNotifier(
       
    77                 this,
       
    78                 iServer );
       
    79         iStatusNotifier->Construct();
       
    80         }
       
    81     //LOGEXITFN("CCsdFax::ConstructL()")
       
    82     }
       
    83 
       
    84 // Destructor
       
    85 CCsdFax::~CCsdFax()
       
    86     {
       
    87     if ( iConnUpNotifier != 0 )
       
    88         {
       
    89         iConnUpNotifier->Cancel();
       
    90         delete iConnUpNotifier;
       
    91         iConnUpNotifier = 0;
       
    92         }
       
    93 
       
    94     if ( iStatusNotifier != 0 )
       
    95         {
       
    96         iStatusNotifier->Cancel();
       
    97         delete iStatusNotifier;
       
    98         iStatusNotifier = 0;
       
    99         }
       
   100 
       
   101     if ( iState == ECallOpen )
       
   102         {
       
   103         CloseCall();
       
   104         }
       
   105 
       
   106     if ( iState > EModuleClosed )
       
   107         {
       
   108         iLine.Close();
       
   109         }
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CCsdFax::OpenCall
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TInt CCsdFax::OpenCall( const TDes& aName )
       
   117     {
       
   118     if ( iState == ECallOpen )
       
   119         {
       
   120         CloseCall();
       
   121         }
       
   122 
       
   123     RTelServer::TPhoneInfo phoneInfo;
       
   124     TInt err = iTelServer->GetPhoneInfo( 0, phoneInfo );
       
   125 
       
   126     if ( err != KErrNone )
       
   127         {
       
   128         return err;
       
   129         }
       
   130 
       
   131     iCsdFaxCallName.Copy( phoneInfo.iName );
       
   132     iCsdFaxCallName.Append( KDoubleColon );
       
   133     iCsdFaxCallName.Append( KMmTsyDataLineName );
       
   134     iCsdFaxCallName.Append( KDoubleColon );
       
   135     iCsdFaxCallName.Append( aName );
       
   136 
       
   137     err = iCall.OpenExistingCall( *iTelServer, iCsdFaxCallName );
       
   138 
       
   139     if ( KErrNone == err )
       
   140         {
       
   141         iState = ECallOpen;
       
   142 
       
   143         // Start status event watcher
       
   144         if ( !iStatusNotifier->IsActive() )
       
   145             {
       
   146             iStatusNotifier->Start( &iCall );
       
   147             }
       
   148         }
       
   149 
       
   150     return err;
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CCsdFax::CloseCall
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 void CCsdFax::CloseCall()
       
   158     {
       
   159     if ( iStatusNotifier != 0 )
       
   160         {
       
   161         iStatusNotifier->Cancel();
       
   162         }
       
   163 
       
   164     iCall.Close();
       
   165     iState = ELineOpen;
       
   166 
       
   167     iCsdFaxCallName.FillZ();
       
   168     iCsdFaxCallName.Zero();
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CCsdFax::IsValid
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 TBool CCsdFax::IsValid()
       
   176     {
       
   177     if ( iState == ECallOpen )
       
   178         {
       
   179         return ETrue;
       
   180         }
       
   181     else
       
   182         {
       
   183         return EFalse;
       
   184         }
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CCsdFax::FindCall
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 TInt CCsdFax::FindCall()
       
   192     {
       
   193     TInt ret( KErrNone );
       
   194     TInt countCalls( 0 );
       
   195 
       
   196     if ( iState == ECallOpen )
       
   197         {
       
   198         return KErrNone;
       
   199         }
       
   200     else if ( iState < ELineOpen )
       
   201         {
       
   202         return KErrNotFound;
       
   203         }
       
   204 
       
   205     // Enumerate calls on data line
       
   206     ret = iLine.EnumerateCall( countCalls );
       
   207 
       
   208     if ( ret != KErrNone )
       
   209         {
       
   210         return ret;
       
   211         }
       
   212     else if ( countCalls == 0 )
       
   213         {
       
   214         return KErrNotFound;
       
   215         }
       
   216 
       
   217     RMmCustomAPI customApi;
       
   218     RMmCustomAPI::TCallOrigin origin;
       
   219 
       
   220     ret = customApi.Open( *iMobilePhone );
       
   221 
       
   222     if ( ret != KErrNone )
       
   223         {
       
   224         return ret;
       
   225         }
       
   226 
       
   227     // Get call info
       
   228     for ( TInt j = 0; j < countCalls; j++ )
       
   229         {
       
   230         RLine::TCallInfo callInfo;
       
   231 
       
   232         ret = iLine.GetCallInfo( j, callInfo );
       
   233         if ( ret != KErrNone )
       
   234             {
       
   235             customApi.Close();
       
   236             return ret;
       
   237             }
       
   238 
       
   239         customApi.CallOrigin( callInfo.iCallName, origin );
       
   240 
       
   241         // TF
       
   242         if ( origin == RMmCustomAPI::EOutsider )
       
   243             {
       
   244             ret = KErrNone;
       
   245             OpenCall( callInfo.iCallName );
       
   246             break;
       
   247             }
       
   248         else
       
   249             {
       
   250             ret = KErrNotFound;
       
   251             }
       
   252         }
       
   253 
       
   254     customApi.Close();
       
   255     return ret;
       
   256     }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CCsdFax::GetBearer
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 TInt CCsdFax::GetBearer( TInt& aBearer, TBearerInfo& aBearerInfo ) const
       
   263     {
       
   264     TInt ret( KErrNone );
       
   265     RMobileCall::TMobileCallStatus mobileCallStatus;
       
   266 
       
   267     if ( iState < ECallOpen )
       
   268         {
       
   269         return KErrNotFound;
       
   270         }
       
   271 
       
   272     // Is network WCDMA
       
   273     RMobilePhone::TMobilePhoneNetworkMode mode;
       
   274     ret = iMobilePhone->GetCurrentMode( mode );
       
   275 
       
   276     if ( ret != KErrNone )
       
   277         {
       
   278         return ret;
       
   279         }
       
   280     if ( mode == RMobilePhone::ENetworkModeWcdma )
       
   281         {
       
   282         aBearer = EBearerExternalWcdmaCSD;
       
   283         aBearerInfo.iBearer = EBearerInfoWcdmaCSD;
       
   284         aBearerInfo.iInternal = EFalse;
       
   285 
       
   286         return KErrNone;
       
   287         }
       
   288 
       
   289     ret = iCall.GetMobileCallStatus( mobileCallStatus );
       
   290 
       
   291     if ( ret != KErrNone )
       
   292         {
       
   293         return ret;
       
   294         }
       
   295 
       
   296     aBearer = EBearerExternalCSD;
       
   297     aBearerInfo.iBearer = EBearerInfoCSD;
       
   298     aBearerInfo.iInternal = EFalse;
       
   299 
       
   300     if ( mobileCallStatus != RMobileCall::EStatusIdle )
       
   301         {
       
   302         RMobileCall::TMobileCallHscsdInfoV1 hscsdInfo;
       
   303         RMobileCall::TMobileCallHscsdInfoV1Pckg hscsdInfoPckg( hscsdInfo );
       
   304 
       
   305         for ( TInt a = 0; a < KBearerQueryCount; a++ )
       
   306             {
       
   307             ret = iCall.GetCurrentHscsdInfo( hscsdInfoPckg );
       
   308 
       
   309             if ( ret != KErrEtelCallNotActive )
       
   310                 {
       
   311                 break;
       
   312                 }
       
   313 
       
   314             User::After( KBearerQueryTimeout );
       
   315             }
       
   316 
       
   317         if ( KErrNone == ret )
       
   318             {
       
   319             if ( hscsdInfo.iAiur != RMobileCall::EAiurBpsUnspecified )
       
   320                 {
       
   321                 aBearer = EBearerExternalHSCSD;
       
   322                 aBearerInfo.iBearer = EBearerInfoHSCSD;
       
   323                 }
       
   324             }
       
   325         }
       
   326     return KErrNone;
       
   327     }
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // CCsdFax::GetStatus
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 TInt CCsdFax::GetStatus( TInt& aStatus ) const
       
   334     {
       
   335     TInt ret( KErrNone );
       
   336 
       
   337     if ( iState < ECallOpen )
       
   338         {
       
   339         return KErrNotFound;
       
   340         }
       
   341 
       
   342     RMobileCall::TMobileCallStatus mobileCallStatus;
       
   343     ret = iCall.GetMobileCallStatus( mobileCallStatus );
       
   344 
       
   345     if ( ret != KErrNone )
       
   346         {
       
   347         return ret;
       
   348         }
       
   349 
       
   350     aStatus = mobileCallStatus;
       
   351     ret = MapStatus( aStatus );
       
   352 
       
   353     return ret;
       
   354     }
       
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // CCsdFax::MapStatus
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 TInt CCsdFax::MapStatus( TInt& aStatus ) const
       
   361     {
       
   362     switch( aStatus )
       
   363         {
       
   364         case RMobileCall::EStatusUnknown:
       
   365             return KErrUnknown;
       
   366 
       
   367         case RMobileCall::EStatusIdle:
       
   368             aStatus = KConnectionUninitialised;
       
   369             break;
       
   370 
       
   371         case RMobileCall::EStatusDialling:
       
   372             aStatus = KCsdStartingDialling;
       
   373             break;
       
   374 
       
   375         case RMobileCall::EStatusRinging:
       
   376             return KErrUnknown;
       
   377 
       
   378         case RMobileCall::EStatusAnswering:
       
   379             aStatus = KCsdStartingAnswer;
       
   380             break;
       
   381 
       
   382         case RMobileCall::EStatusConnecting:
       
   383             aStatus = KCsdStartingConnect;
       
   384             break;
       
   385 
       
   386         case RMobileCall::EStatusConnected:
       
   387             aStatus = KCsdConnectionOpen;
       
   388             break;
       
   389 
       
   390          case RMobileCall::EStatusDisconnecting:
       
   391          case RMobileCall::EStatusDisconnectingWithInband:
       
   392             aStatus = KCsdStartingHangUp;
       
   393             break;
       
   394 
       
   395         default:
       
   396             return KErrUnknown;
       
   397         }
       
   398 
       
   399     return KErrNone;
       
   400     }
       
   401 
       
   402 // -----------------------------------------------------------------------------
       
   403 // CCsdFax::GetTelNumber
       
   404 // -----------------------------------------------------------------------------
       
   405 //
       
   406 TInt CCsdFax::GetTelNumber( TDes& aNumber ) const
       
   407     {
       
   408     LOGENTRFN("CCsdFax::GetTelNumber()")
       
   409     TInt err( KErrNone );
       
   410 
       
   411     if ( iState < ECallOpen )
       
   412         {
       
   413         err = KErrNotFound;
       
   414         }
       
   415     else
       
   416         {
       
   417         RMobileCall::TMobileCallInfoV1 info;
       
   418         RMobileCall::TMobileCallInfoV1Pckg infoPckg( info );
       
   419         err = iCall.GetMobileCallInfo( infoPckg );
       
   420 
       
   421         if ( KErrNone == err )
       
   422             {
       
   423             if ( infoPckg().iRemoteParty.iRemoteNumber.iTelNumber.Length() > 0 )
       
   424                 {
       
   425                 aNumber = infoPckg().iRemoteParty.iRemoteNumber.iTelNumber;
       
   426                 }
       
   427             else if ( infoPckg().iDialledParty.iTelNumber.Length() > 0 )
       
   428                 {
       
   429                 aNumber = infoPckg().iDialledParty.iTelNumber;
       
   430                 }
       
   431             }
       
   432         }
       
   433 
       
   434     LOGEXITFN1("CCsdFax::GetTelNumber()", err)
       
   435     return err;
       
   436     }
       
   437 
       
   438 // -----------------------------------------------------------------------------
       
   439 // CCsdFax::GetStartTime
       
   440 // -----------------------------------------------------------------------------
       
   441 //
       
   442 TInt CCsdFax::GetStartTime( TTime& aTime ) const
       
   443     {
       
   444     TInt ret( KErrNone );
       
   445 
       
   446     if ( iState < ECallOpen )
       
   447         {
       
   448         return KErrNotFound;
       
   449         }
       
   450 
       
   451     TTimeIntervalSeconds duration;
       
   452     ret = iCall.GetCallDuration( duration );
       
   453 
       
   454     if ( KErrNone == ret )
       
   455         {
       
   456         TTime current;
       
   457         current.UniversalTime();
       
   458         aTime = current - duration;
       
   459         }
       
   460     return ret;
       
   461     }
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // CCsdFax::Stop
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 TInt CCsdFax::Stop()
       
   468     {
       
   469     TInt err( KErrNone );
       
   470 
       
   471     if ( iState != ECallOpen )
       
   472         {
       
   473         return KErrNotFound;
       
   474         }
       
   475 
       
   476     err = iCall.HangUp();
       
   477 
       
   478     // Remove from server tables if
       
   479     // status notifier is not active.
       
   480     if ( !iStatusNotifier->IsActive() )
       
   481         {
       
   482         RemoveFromServer();
       
   483         }
       
   484 
       
   485     return err;
       
   486     }
       
   487 
       
   488 // -----------------------------------------------------------------------------
       
   489 // CCsdFax::RemoveFromServer
       
   490 // -----------------------------------------------------------------------------
       
   491 //
       
   492 void CCsdFax::RemoveFromServer()
       
   493     {
       
   494     // Remove the connection from internal table
       
   495     TInt bearer( 0 );
       
   496     TBearerInfo bearerInfo( EBearerInfoCSD, ETrue);
       
   497 
       
   498     TConnInfo connInfo( 0, 0, 0, EBearerExternalCSD, bearerInfo );
       
   499 
       
   500     TInt err = GetBearer( bearer, bearerInfo );
       
   501 
       
   502     if ( KErrNone == err )
       
   503         {
       
   504         connInfo.iBearer = bearer;
       
   505         connInfo.iBearerInfo.iBearer = bearerInfo.iBearer;
       
   506         connInfo.iBearerInfo.iInternal = bearerInfo.iInternal;
       
   507         }
       
   508 
       
   509     iServer->Iap()->RemoveConnection( connInfo );
       
   510     }
       
   511 
       
   512 
       
   513 // ============================ MEMBER FUNCTIONS ===============================
       
   514 
       
   515 // -----------------------------------------------------------------------------
       
   516 // CCsdFaxUpNotifier::CCsdFaxUpNotifier
       
   517 // -----------------------------------------------------------------------------
       
   518 //
       
   519 CCsdFaxUpNotifier::CCsdFaxUpNotifier(
       
   520         CCsdFax* aFaxModule,
       
   521         CConnMonServer* aServer,
       
   522         RMobilePhone* aMobilePhone,
       
   523         RLine& aLine)
       
   524         :
       
   525         CActive( EConnMonPriorityNormal ),
       
   526         iFaxModule( aFaxModule ),
       
   527         iServer( aServer ),
       
   528         iMobilePhone( aMobilePhone ),
       
   529         iLine( aLine )
       
   530     {
       
   531     }
       
   532 
       
   533 // -----------------------------------------------------------------------------
       
   534 // CCsdFaxUpNotifier::Construct
       
   535 // -----------------------------------------------------------------------------
       
   536 //
       
   537 void CCsdFaxUpNotifier::Construct()
       
   538     {
       
   539     CActiveScheduler::Add( this );
       
   540     }
       
   541 
       
   542 // Destructor
       
   543 CCsdFaxUpNotifier::~CCsdFaxUpNotifier()
       
   544     {
       
   545     Cancel();
       
   546     }
       
   547 
       
   548 // -----------------------------------------------------------------------------
       
   549 // CCsdFaxUpNotifier::Receive
       
   550 // Requests a new event (connection up/down) from RConnection
       
   551 // -----------------------------------------------------------------------------
       
   552 //
       
   553 void CCsdFaxUpNotifier::Receive()
       
   554     {
       
   555     if ( IsActive() )
       
   556         {
       
   557         Cancel();
       
   558         }
       
   559 
       
   560     iName.FillZ();
       
   561 
       
   562     iLine.NotifyCallAdded( iStatus, iName );
       
   563     SetActive();
       
   564     }
       
   565 
       
   566 // -----------------------------------------------------------------------------
       
   567 // CCsdFaxUpNotifier::DoCancel
       
   568 // Cancels the request from RConnection.
       
   569 // -----------------------------------------------------------------------------
       
   570 //
       
   571 void CCsdFaxUpNotifier::DoCancel()
       
   572     {
       
   573     if ( IsActive() )
       
   574         {
       
   575         iLine.NotifyCallAddedCancel();
       
   576         }
       
   577     }
       
   578 
       
   579 // -----------------------------------------------------------------------------
       
   580 // CCsdFaxUpNotifier::RunL
       
   581 // Handles the event that has arrived from RConnection
       
   582 // -----------------------------------------------------------------------------
       
   583 //
       
   584 void CCsdFaxUpNotifier::RunL()
       
   585     {
       
   586     // All RunL():s outside CServer-derived main class MUST NOT LEAVE.
       
   587     // Use TRAPD when needed.
       
   588 
       
   589     if ( iStatus.Int() != KErrNone )
       
   590         {
       
   591         LOGIT1("External Csd up event FAILED <%d>", iStatus.Int() )
       
   592         }
       
   593     else
       
   594         {
       
   595         RMmCustomAPI customApi;
       
   596         RMmCustomAPI::TCallOrigin origin( RMmCustomAPI::EUnknown );
       
   597 
       
   598         TInt ret = customApi.Open( *iMobilePhone );
       
   599 
       
   600         if ( KErrNone == ret )
       
   601             {
       
   602             customApi.CallOrigin( iName, origin );
       
   603             customApi.Close();
       
   604             }
       
   605 
       
   606         if ( origin == RMmCustomAPI::EOutsider )
       
   607             {
       
   608             TInt bearer( 0 );
       
   609             TBearerInfo bearerInfo;
       
   610             TInt err( KErrNone );
       
   611 
       
   612             LOGIT("SERVER: EVENT -> new EXTERNAL CSD connection")
       
   613 
       
   614             if ( iFaxModule->IsValid() )
       
   615                 {
       
   616                 // Sometimes when data call is rejected by the other end, a new
       
   617                 // data call is started before the old one has been notified to
       
   618                 // be closed. In this case send the EConnMonDeleteConnection to
       
   619                 // all clients that are listening.
       
   620                 iEventInfo.Reset();
       
   621                 iEventInfo.iEventType = EConnMonDeleteConnection;
       
   622                 iEventInfo.iConnectionId = iFaxModule->ConnectionId();
       
   623 
       
   624                 iServer->EventQueue()->Add( iEventInfo );
       
   625 
       
   626                 // Remove from server tables
       
   627                 iFaxModule->RemoveFromServer();
       
   628 
       
   629                 // Close the call
       
   630                 iFaxModule->CloseCall();
       
   631 
       
   632                 LOGIT("SERVER: Closed the unfinished EXTERNAL CSD connection")
       
   633                 }
       
   634 
       
   635             err = iFaxModule->OpenCall( iName );
       
   636 
       
   637             if ( KErrNone == err )
       
   638                 {
       
   639                 err = iFaxModule->GetBearer( bearer, bearerInfo );
       
   640                 }
       
   641 
       
   642             if ( KErrNone == err )
       
   643                 {
       
   644                 // Send event to clients
       
   645                 TConnInfo connInfo( 0, 0, 0, bearer, bearerInfo );
       
   646 
       
   647                 iEventInfo.Reset();
       
   648 
       
   649                 iEventInfo.iEventType = EConnMonCreateConnection;
       
   650 
       
   651                 // Add to the connection table and fill in the new connectioId to connInfo
       
   652                 TRAP( ret, ( err = iServer->Iap()->AddConnectionL( connInfo ) ) );
       
   653 
       
   654                 if ( ret )
       
   655                     {
       
   656                     LOGIT("AddConnectionL failed.")
       
   657                     return; // Can't leave
       
   658                     }
       
   659 
       
   660                 // Set connection id
       
   661                 iEventInfo.iConnectionId = connInfo.iConnectionId;
       
   662                 iFaxModule->SetConnectionId( connInfo.iConnectionId );
       
   663 
       
   664                 // Send event to all clients that are listening
       
   665                 iServer->EventQueue()->Add( iEventInfo );
       
   666                 }
       
   667             else
       
   668                 {
       
   669                 LOGIT("Could not get the external call info!")
       
   670                 }
       
   671             }
       
   672 
       
   673         // New request
       
   674         Receive();
       
   675         }
       
   676     }
       
   677 
       
   678 // ============================ MEMBER FUNCTIONS ===============================
       
   679 
       
   680 // -----------------------------------------------------------------------------
       
   681 // CCsdStatusNotifier::CCsdStatusNotifier
       
   682 // -----------------------------------------------------------------------------
       
   683 //
       
   684 CCsdStatusNotifier::CCsdStatusNotifier(
       
   685         CCsdFax* aFaxModule,
       
   686         CConnMonServer* aServer )
       
   687         :
       
   688         CActive( EConnMonPriorityNormal ),
       
   689         iFaxModule( aFaxModule ),
       
   690         iServer( aServer )
       
   691     {
       
   692     }
       
   693 
       
   694 // -----------------------------------------------------------------------------
       
   695 // CCsdStatusNotifier::Construct
       
   696 // -----------------------------------------------------------------------------
       
   697 //
       
   698 void CCsdStatusNotifier::Construct()
       
   699     {
       
   700     CActiveScheduler::Add( this );
       
   701     }
       
   702 
       
   703 // Destructor
       
   704 CCsdStatusNotifier::~CCsdStatusNotifier()
       
   705     {
       
   706     Cancel();
       
   707     }
       
   708 
       
   709 // -----------------------------------------------------------------------------
       
   710 // CCsdStatusNotifier::Start
       
   711 // Requests a new event (connection up/down) from RConnection
       
   712 // -----------------------------------------------------------------------------
       
   713 //
       
   714 void CCsdStatusNotifier::Start( RMobileCall* aCall )
       
   715     {
       
   716     // Cancel must be called before assigning a new aCall handle
       
   717     if ( IsActive() )
       
   718         {
       
   719         Cancel();
       
   720         }
       
   721 
       
   722     iCall = aCall;
       
   723     Receive();
       
   724     }
       
   725 
       
   726 // -----------------------------------------------------------------------------
       
   727 // CCsdStatusNotifier::Receive
       
   728 // Requests a new event (connection up/down) from RConnection
       
   729 // -----------------------------------------------------------------------------
       
   730 //
       
   731 void CCsdStatusNotifier::Receive()
       
   732     {
       
   733     if ( IsActive() )
       
   734         {
       
   735         Cancel();
       
   736         }
       
   737 
       
   738     iCall->NotifyMobileCallStatusChange( iStatus, iMobileCallStatus );
       
   739     SetActive();
       
   740     }
       
   741 
       
   742 // -----------------------------------------------------------------------------
       
   743 // CCsdStatusNotifier::DoCancel
       
   744 // Cancels the request from RConnection.
       
   745 // -----------------------------------------------------------------------------
       
   746 //
       
   747 void CCsdStatusNotifier::DoCancel()
       
   748     {
       
   749     if ( IsActive() )
       
   750         {
       
   751         iCall->CancelAsyncRequest( EMobileCallNotifyMobileCallStatusChange );
       
   752         }
       
   753     }
       
   754 
       
   755 // -----------------------------------------------------------------------------
       
   756 // CCsdStatusNotifier::RunL
       
   757 // Handles the event that has arrived from RConnection
       
   758 // -----------------------------------------------------------------------------
       
   759 //
       
   760 void CCsdStatusNotifier::RunL()
       
   761     {
       
   762     // All RunL():s outside CServer-derived main class MUST NOT LEAVE.
       
   763     // Use TRAPD when needed.
       
   764 
       
   765     if ( iStatus.Int() != KErrNone )
       
   766         {
       
   767         LOGIT1("External Csd status FAILED <%d>", iStatus.Int() )
       
   768         }
       
   769     else
       
   770         {
       
   771         // Send event to clients
       
   772         LOGIT1("SERVER: EVENT -> EXTERNAL CSD status changed <%d>", iMobileCallStatus )
       
   773 
       
   774         iEventInfo.Reset();
       
   775         iEventInfo.iEventType = EConnMonConnectionStatusChange;
       
   776 
       
   777         iEventInfo.iConnectionId = iFaxModule->ConnectionId();
       
   778 
       
   779         TInt status = iMobileCallStatus;
       
   780         TInt err = iFaxModule->MapStatus( status );
       
   781         iEventInfo.iData = status;
       
   782 
       
   783         if ( ( iServer->NumberOfListeners() > 0 ) && ( err == KErrNone ) )
       
   784             {
       
   785             // Send event to all clients that are listening
       
   786             iServer->EventQueue()->Add( iEventInfo );
       
   787             }
       
   788 
       
   789         if ( ( iMobileCallStatus == ( TInt )RMobileCall::EStatusDisconnecting )
       
   790               ||
       
   791              ( iMobileCallStatus == ( TInt )RMobileCall::EStatusDisconnectingWithInband ) )
       
   792             {
       
   793             // Send connection closed event to all clients that are listening
       
   794             iEventInfo.Reset();
       
   795             iEventInfo.iEventType = EConnMonDeleteConnection;
       
   796             iEventInfo.iConnectionId = iFaxModule->ConnectionId();
       
   797 
       
   798             iServer->EventQueue()->Add( iEventInfo );
       
   799 
       
   800             // Remove from server tables
       
   801             iFaxModule->RemoveFromServer();
       
   802 
       
   803             // Close the call
       
   804             iFaxModule->CloseCall();
       
   805 
       
   806             // Stop listening
       
   807             return;
       
   808             }
       
   809 
       
   810         // New request
       
   811         Receive();
       
   812         }
       
   813     }
       
   814 
       
   815 // End-of-file