telephonyserverplugins/common_tsy/commontsy/src/mmtsy/cmmfaxlinetsy.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
child 42 3adadc800673
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 //INCLUDES
       
    19 #include "cmmfaxlinetsy.h"
       
    20 #include "cmmphonetsy.h"
       
    21 #include "cmmfaxcalltsy.h"
       
    22 #include "cmmcallextinterface.h"
       
    23 #include "cmmlinelist.h"
       
    24 #include "cmmcalllist.h"
       
    25 #include "cmmtsyreqhandlestore.h"
       
    26 #include "cmmmessagemanagerbase.h"
       
    27 #include <ctsy/tflogger.h>
       
    28 #include <ctsy/pluginapi/cmmdatapackage.h>
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 CMmFaxLineTsy::CMmFaxLineTsy()
       
    33     {
       
    34     }
       
    35 
       
    36 
       
    37 CMmFaxLineTsy* CMmFaxLineTsy::NewL(
       
    38     CMmPhoneTsy* aMmPhone,
       
    39     RMobilePhone::TMobileService aMode,
       
    40     const TDesC& aName,
       
    41     CMmMessageManagerBase* aMessageManager )
       
    42     {
       
    43     CMmFaxLineTsy* mmLineTsy = NULL;
       
    44 
       
    45     if ( aMmPhone != NULL && aMode == RMobilePhone::EFaxService )
       
    46         {
       
    47         mmLineTsy = new ( ELeave ) CMmFaxLineTsy();
       
    48  
       
    49         CleanupClosePushL( *mmLineTsy );
       
    50         mmLineTsy->iMmPhone  = aMmPhone;    
       
    51         mmLineTsy->iLineName = aName;
       
    52         mmLineTsy->iLineMode = aMode;
       
    53         mmLineTsy->iMessageManager = aMessageManager;
       
    54         mmLineTsy->ConstructL();
       
    55         CleanupStack::Pop();
       
    56         }
       
    57 
       
    58     return mmLineTsy;
       
    59     }
       
    60 
       
    61 CMmFaxLineTsy::~CMmFaxLineTsy()
       
    62     {
       
    63     TFLOGSTRING2("TSY: CMmFaxLineTsy::~CMmFaxLineTsy. Line name: %S",
       
    64         &iLineName);
       
    65 
       
    66     iLastIncomingFaxCall = NULL;
       
    67     }
       
    68     
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CMmFaxLineTsy::OpenNewObjectL
       
    72 // This method creates a new name for a call and opens a new  call. This  
       
    73 // methodis called when the client uses RCall::OpenNewCall method. Currently 
       
    74 // the maximum number of opened calls from tsy is 20.
       
    75 // (other items were commented in a header).
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CTelObject* CMmFaxLineTsy::OpenNewObjectL(
       
    79     TDes& aNewName )
       
    80     {
       
    81     CMmFaxCallTsy* mmCall = NULL;
       
    82 
       
    83     // mmfax: Fax client expects that it get's the existing call object,
       
    84     // not the new one..
       
    85     if ( iLastIncomingFaxCall )
       
    86         {
       
    87         aNewName.Copy(iLastIncomingFaxCall->CallName());
       
    88         iLastIncomingFaxCall = NULL;
       
    89         mmCall = reinterpret_cast<CMmFaxCallTsy*>(
       
    90             OpenNewObjectByNameL(aNewName) );
       
    91         return mmCall;
       
    92         }
       
    93 
       
    94     //Logic here to prevent creation of unlimited amount of call objects
       
    95     //by clients. The proposed maximum amount of call objects is 20:
       
    96     //
       
    97     //  - 2 voice call object (1 for each line for incoming calls
       
    98     //  - 1 data call object (for incoming data call)
       
    99     //  - 1 emergency call object
       
   100     //  - 1+7 call objects for Confence call (max number of CC participants)
       
   101     //  - phonebook 1
       
   102     //  - javaphone 1
       
   103     //  - WTA 1
       
   104     //  - voice mail box 1
       
   105     //  - csd 1
       
   106     //  - fax 1
       
   107     //  - 3rd party 2
       
   108     //
       
   109 
       
   110     //Incoming calls can not be created if the maximum number is exceeded!
       
   111     if ( KMaxNumberOfCallObjectsFromTsy 
       
   112             > iMmPhone->CallList()->GetNumberOfObjects() )
       
   113         {
       
   114         CreateNewCallName( aNewName );
       
   115         mmCall = CMmFaxCallTsy::NewL(
       
   116             iMmPhone, this, iLineMode, aNewName, iMessageManager );
       
   117         iNameOfLastCallAdded = aNewName;
       
   118 
       
   119         // Add the new call to the list of calls
       
   120         TInt ret = iMmPhone->CallList()->AddObject( mmCall );
       
   121         if ( KErrNone != ret )
       
   122             {
       
   123             //If call cannot be added to CallList -> leave with KErrNoMemory
       
   124             //CallList has to have information about every call.
       
   125             mmCall->Close();
       
   126             mmCall = NULL;
       
   127             User::Leave( KErrNoMemory );
       
   128             }
       
   129         else
       
   130             {
       
   131             CompleteNotifyCallAdded( aNewName );
       
   132             }
       
   133         }
       
   134     else
       
   135         {
       
   136         User::Leave( KErrAccessDenied );
       
   137         }
       
   138 
       
   139     return mmCall;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CMmFaxLineTsy::InitInternalAttributesL
       
   144 // Initialises miscellaneous internal attributes.
       
   145 // (other items were commented in a header).
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 void CMmFaxLineTsy::InitInternalAttributesL()
       
   149     {
       
   150     CMmLineTsy::InitInternalAttributesL();
       
   151 
       
   152     // The line supports data connections.
       
   153     iLineCaps.iFlags = RLine::KCapsFax | RLine::KCapsEventIncomingCall;
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CMmFaxLineTsy::CreateCallObjectForIncomingCall
       
   158 // This function creates and stores a Call object that is used for a incoming 
       
   159 // call.
       
   160 // (other items were commented in a header).
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 TInt CMmFaxLineTsy::CreateCallObjectForIncomingCall()
       
   164     {
       
   165     TInt trapError( KErrNone );
       
   166     TInt result = CMmPhoneTsy::EMultimodePhoneOutOfMemory;
       
   167 
       
   168     if ( !iCallForIncomingCall )
       
   169         {
       
   170         TName newName;
       
   171         CreateNewCallName( newName );
       
   172 
       
   173         TRAP( trapError,
       
   174             iCallForIncomingCall = CMmFaxCallTsy::NewL(
       
   175                 iMmPhone, this, iLineMode, newName, iMessageManager );
       
   176             );
       
   177 
       
   178         if ( trapError == KErrNone ) 
       
   179             {
       
   180             iNameOfLastCallAdded = newName;
       
   181             // Don't add the new call to the list of calls yet. Will be
       
   182             // added when incoming call has been received...
       
   183             result = KErrNone;
       
   184             }
       
   185         }
       
   186 
       
   187     return result;
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CMmFaxLineTsy::CreateGhostCallObject
       
   192 // This method creates a Call object for the Ghost call. A ghost call is a  
       
   193 // call that has been initiated bypassing the ETel.
       
   194 // (other items were commented in a header).
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 CMmCallTsy* CMmFaxLineTsy::CreateGhostCallObject(
       
   198     TInt aCallId,
       
   199     RMobilePhone::TMobileService,
       
   200     RMobileCall::TMobileCallStatus aCallStatus )
       
   201     {
       
   202     TInt trapError( KErrNone );
       
   203 
       
   204     TName newName;
       
   205     CreateNewCallName( newName );
       
   206     CMmFaxCallTsy* mmCall = NULL;
       
   207 
       
   208     TRAP( trapError,
       
   209         mmCall = CMmFaxCallTsy::NewL(
       
   210             iMmPhone, this, iLineMode, newName, iMessageManager );
       
   211         );
       
   212 
       
   213     if ( KErrNone == trapError && NULL != mmCall )
       
   214         {
       
   215         //set call ID
       
   216         mmCall->SetCallId( aCallId );
       
   217         //set call status
       
   218         if( aCallStatus >= RMobileCall::EStatusDialling )
       
   219             {
       
   220             //Status is allways set to dialing. If call is alredy
       
   221             //e.g. connecting, missed status changes are simulated.
       
   222             mmCall->SetCallStatus(
       
   223                 RCall::EStatusDialling, RMobileCall::EStatusDialling );
       
   224             }
       
   225         //set call caps
       
   226         mmCall->SetCallCaps( RCall::KCapsFax | RCall::KCapsHangUp );
       
   227         //set call direction to MO call
       
   228         mmCall->SetCallDirection( RMobileCall::EMobileOriginated );
       
   229         //set flag indicating that this is a ghost call
       
   230         mmCall->SetGhostCall( ETrue );
       
   231         //save name of the last added call
       
   232         iNameOfLastCallAdded = mmCall->CallName();
       
   233         }
       
   234 
       
   235     return mmCall;
       
   236     }
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // CMmFaxLineTsy::CompleteNotifyIncomingCall
       
   240 // This method is used to notify to the client about the incoming call. Basic 
       
   241 // information: one Call object is allocated in the boot-up for incoming call. 
       
   242 // When an incoming call occurs the call object will be given to the client 
       
   243 // that answers the call. Therefore we have to create a new call object for 
       
   244 // the next incoming call. In case that we are out of memory, the next 
       
   245 // incoming call cannot be received! General error message about OutOfMemory  
       
   246 // situation is sent to the client. 
       
   247 // (other items were commented in a header).
       
   248 // ---------------------------------------------------------------------------
       
   249 //
       
   250 void CMmFaxLineTsy::CompleteNotifyIncomingCall(
       
   251     CMmDataPackage* aDataPackage )
       
   252     {
       
   253     TInt callId( -1 );
       
   254     RMobilePhone::TMobileService callMode( RMobilePhone::EVoiceService );
       
   255 
       
   256     CCallDataPackage* callDataPackage =
       
   257         reinterpret_cast<CCallDataPackage*>(aDataPackage);
       
   258 
       
   259     callDataPackage->GetCallIdAndMode( callId, callMode ); 
       
   260 
       
   261     TFLOGSTRING3("TSY: CMmFaxLineTsy::CompleteNotifyIncomingCall - \
       
   262         Line name: %S, Call id: %d", &iLineName, callId );
       
   263 
       
   264     //reset req handle. Returns the deleted req handle
       
   265     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
   266         EMultimodeLineNotifyIncomingCall );
       
   267 
       
   268     CMmFaxCallTsy* mmCall = NULL;
       
   269 
       
   270     // Check if notification is requested
       
   271     if ( EMultimodeLineReqHandleUnknown != reqHandle )
       
   272         {
       
   273         mmCall = reinterpret_cast<CMmFaxCallTsy*>(
       
   274             CallObjectForIncomingCall() );
       
   275 
       
   276         if ( mmCall )
       
   277             {
       
   278             // Add the new call to the list of calls
       
   279             TInt ret = iMmPhone->CallList()->AddObject( mmCall );
       
   280 
       
   281             if ( KErrNone == ret )
       
   282                 {
       
   283                 //set flag indicating that this is a unowned incoming call
       
   284                 mmCall->SetUnownedCallObjectFlag( ETrue );
       
   285                 // Set call ID
       
   286                 mmCall->SetCallId( callId );
       
   287                 // Set call direction to EMobileTerminated
       
   288                 mmCall->SetCallDirection( RMobileCall::EMobileTerminated );
       
   289 
       
   290                 // Add answer capability and remove dial capability to
       
   291                 // existing call capabilities
       
   292                 TUint32 callCaps = mmCall->CallCaps();
       
   293                 callCaps |= RCall::KCapsAnswer; 
       
   294                 callCaps &= ~RCall::KCapsDial;
       
   295                 mmCall->SetCallCaps( callCaps );
       
   296 
       
   297                 //set data to gsm extension
       
   298                 //( direction added because not uppdated in messagehandler)
       
   299                 mmCall->ActiveCallExtension()->SetMobileCallData(
       
   300                     aDataPackage, RMobileCall::EMobileTerminated );
       
   301 
       
   302                 // mmfax: Save ptr to last incoming fax call, so that
       
   303                 // it can be used to open right call object for fax.
       
   304                 iLastIncomingFaxCall = mmCall;
       
   305 
       
   306                 iNameOfCallForAnswering = mmCall->CallName();
       
   307 
       
   308                 *iRetIncomingCallName = mmCall->CallName(); 
       
   309                 iCallForIncomingCall = NULL;
       
   310                 iNumCalls++;
       
   311                 
       
   312                 ReqCompleted( reqHandle, KErrNone );
       
   313 
       
   314                 // Create and store a new Call Object for incoming call.
       
   315                 CreateCallObjectForIncomingCall();
       
   316 
       
   317                 RMobileCall::TMobileCallStatus status(
       
   318                     RMobileCall::EStatusRinging );
       
   319                 CCallDataPackage dataPackage;
       
   320                 dataPackage.SetCallIdAndMode( callId, callMode );
       
   321                 dataPackage.PackData( &status );
       
   322                 }
       
   323             else
       
   324                 {
       
   325                 //call object could not be added to the call list. Incoming 
       
   326                 //call cannot be received.
       
   327                 ReqCompleted( reqHandle, KErrNoMemory );
       
   328                 }
       
   329             }
       
   330         else
       
   331             {
       
   332             //call object could not be get. Incoming call cannot be received.
       
   333             //General error message about OutOfMemory situation has been sent
       
   334             //to the client.
       
   335             ReqCompleted( reqHandle, KErrNoMemory );
       
   336             }
       
   337         }
       
   338     }
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // CMmFaxLineTsy::CompleteNotifyDiallingStatus
       
   342 // This method notifies line that a call has entered Dialling state. It means
       
   343 // that Call ID should be saved and in case of ghost call a new call object
       
   344 // should be created.
       
   345 // (other items were commented in a header).
       
   346 // ---------------------------------------------------------------------------
       
   347 //
       
   348 void CMmFaxLineTsy::CompleteNotifyDiallingStatus(
       
   349     CMmDataPackage* aDataPackage )
       
   350     {
       
   351     TFLOGSTRING("TSY: CMmFaxLineTsy::CompleteNotifyDiallingStatus");
       
   352     TInt callId( -1 );
       
   353     TBool ghostCall( EFalse );
       
   354     RMobilePhone::TMobileService callMode( RMobilePhone::EFaxService );
       
   355     
       
   356     CCallDataPackage* callData 
       
   357         = reinterpret_cast<CCallDataPackage*>(aDataPackage);
       
   358 
       
   359     callData->GetCallIdAndMode( callId, callMode );
       
   360 
       
   361     CMmFaxCallTsy* mmCall = reinterpret_cast<CMmFaxCallTsy*>(
       
   362         iMmPhone->CallList()->GetMmCallByMode( callMode ) );
       
   363 
       
   364     if ( NULL == mmCall )
       
   365         {
       
   366         TFLOGSTRING("TSY: CMmFaxLineTsy::CompleteNotifyDiallingStatus - \
       
   367             GhostCall");
       
   368         ghostCall = ETrue;
       
   369         }
       
   370     else
       
   371         {
       
   372         TBool result( EFalse );
       
   373 
       
   374         //now we have to check, if this is a ghost call
       
   375         result = mmCall->IsServiceLocallyRequested(
       
   376             CMmCallTsy::EMultimodeCallDial );
       
   377 
       
   378         if ( result )
       
   379             {
       
   380             for ( TInt i = 0; i < iMmPhone->CallList()->GetNumberOfObjects(); 
       
   381                 i++ )
       
   382                 {    
       
   383                 mmCall = reinterpret_cast<CMmFaxCallTsy*>(
       
   384                     iMmPhone->CallList()->GetMmCallByIndex(i) );
       
   385                 if ( mmCall->ServiceRequested(
       
   386                         CMmCallTsy::EMultimodeCallDial ) )
       
   387                     {
       
   388                     mmCall->SetCallId( callId );
       
   389                     mmCall->CompleteNotifyMobileCallInfoChange( 
       
   390                         aDataPackage );
       
   391                     break;   
       
   392                     }
       
   393                 }
       
   394             }
       
   395         else
       
   396             {
       
   397             TFLOGSTRING("TSY: CMmFaxLineTsy::CompleteNotifyDiallingStatus - \
       
   398                 Dial not found");
       
   399             ghostCall = ETrue;
       
   400             }
       
   401         }
       
   402     //Ghost call handling starts here
       
   403     if ( ghostCall )
       
   404         {
       
   405         //complete call added notification directly from here
       
   406         CompleteNotifyAddBypassingCall( aDataPackage ); 
       
   407         }
       
   408     }
       
   409 
       
   410 // ---------------------------------------------------------------------------
       
   411 // CMmFaxLineTsy::ResetLastIncomingCall
       
   412 // This method sets iLastIncomingFaxCall to NULL
       
   413 // ---------------------------------------------------------------------------
       
   414 //
       
   415 void CMmFaxLineTsy::ResetLastIncomingCall()
       
   416     {
       
   417     TFLOGSTRING("TSY: CMmFaxLineTsy::ResetLastIncomingCall");
       
   418     iLastIncomingFaxCall = NULL;
       
   419     }
       
   420     
       
   421 //  End of File