cellularsrvapitest/telephonyhaitest/etelmm/src/T_RMobileLineData.cpp
changeset 0 3553901f7fa8
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 /*
       
     2 * Copyright (c) 2005-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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <cdbcols.h>
       
    20 #include <e32base.h>
       
    21 #include <e32def.h>
       
    22 
       
    23 //	User Includes
       
    24 #include "t_rmobilelinedata.h"
       
    25 
       
    26 _LIT( KLineName, 		"Line" );
       
    27 _LIT( KCallName, 		"Call");
       
    28 _LIT( KDefaultSection, 	"Default" );
       
    29 _LIT( KMaxPhoneCalls, 	"MaxPhoneCalls");
       
    30 
       
    31 _LIT(KMobilePhoneKey, 	"RMobilePhone");
       
    32 
       
    33 /*@{*/
       
    34 //LIT's for commands
       
    35 _LIT(KCmdOpen, 					"Open");
       
    36 _LIT(KCmdClose, 				"Close");
       
    37 _LIT(KCmdNotifyIncomingCall, 	"NotifyIncomingCall");
       
    38 /*}@*/
       
    39 
       
    40 /**
       
    41  * Two phase constructor
       
    42  *
       
    43  * @leave	system wide error
       
    44  */
       
    45 CT_RMobileLineData* CT_RMobileLineData::NewL()
       
    46 	{
       
    47 	CT_RMobileLineData*	ret=new (ELeave) CT_RMobileLineData();
       
    48 	CleanupStack::PushL(ret);
       
    49 	ret->ConstructL();
       
    50 	CleanupStack::Pop(ret);
       
    51 	return ret;
       
    52 	}
       
    53 
       
    54 
       
    55 /**
       
    56  * Protected constructor. First phase construction
       
    57  */
       
    58 CT_RMobileLineData::CT_RMobileLineData()
       
    59 :	iActiveCallback(NULL),
       
    60 	iMobileLine(NULL)
       
    61 	{
       
    62 	}
       
    63 
       
    64 /**
       
    65  * Second phase construction
       
    66  *
       
    67  * @internalComponent
       
    68  *
       
    69  * @return	N/A
       
    70  *
       
    71  * @pre		None
       
    72  * @post	None
       
    73  *
       
    74  * @leave	system wide error
       
    75  */
       
    76 void CT_RMobileLineData::ConstructL()
       
    77 	{
       
    78 	iMobileLine = new (ELeave) RMobileLine();
       
    79 	iActiveCallback = CActiveCallback::NewL(*this);
       
    80 	}
       
    81 
       
    82 /**
       
    83  * Third phase construction
       
    84  *
       
    85  * @internalComponent
       
    86  *
       
    87  * @return	N/A
       
    88  *
       
    89  * @pre		None
       
    90  * @post	None
       
    91  *
       
    92  * @leave	system wide error
       
    93  */
       
    94 
       
    95 void CT_RMobileLineData::InitialiseL()
       
    96 	{
       
    97 	CDataWrapperBase::InitialiseL();
       
    98 	GetIntFromConfig(KDefaultSection, KMaxPhoneCalls, iMaxPhoneCalls  );
       
    99 
       
   100 	TName* callName = NULL;
       
   101     for (TInt i = 0; i < iMaxPhoneCalls; ++i)
       
   102         {
       
   103         // Call names
       
   104         callName = new (ELeave) TName();
       
   105         CleanupStack::PushL(callName);
       
   106         iCallNames.Append(*callName);
       
   107         CleanupStack::Pop(callName);
       
   108         }
       
   109 	}
       
   110 /**
       
   111  * Public destructor
       
   112  */
       
   113 CT_RMobileLineData::~CT_RMobileLineData()
       
   114 	{
       
   115 	if(iMobileLine)
       
   116 		{
       
   117 		delete iMobileLine;
       
   118 		iMobileLine = NULL;
       
   119 		}
       
   120 	
       
   121 	if(iActiveCallback)
       
   122 		{
       
   123 		delete iActiveCallback;
       
   124 	    iActiveCallback=NULL;
       
   125 		}
       
   126 	// Empty arrays and also delete objects whose pointers are contained within
       
   127     iCallNames.Reset();
       
   128 	}
       
   129 
       
   130 /**
       
   131  * Return a pointer to the object that the data wraps
       
   132  *
       
   133  * @return	pointer to the object that the data wraps
       
   134  */
       
   135 TAny* CT_RMobileLineData::GetObject()
       
   136 	{
       
   137 	return iMobileLine;
       
   138 	}
       
   139 
       
   140 void CT_RMobileLineData::RunL(CActive* aActive, TInt aIndex)
       
   141     {
       
   142     DecOutstanding(); // One of the async calls has completed 
       
   143     TInt err = aActive->iStatus.Int(); 
       
   144     if( err != KErrNone ) 
       
   145     	{ 
       
   146         ERR_PRINTF2(_L("RunL Error %d"), err); 
       
   147         SetAsyncError( aIndex, err ); 
       
   148         } 
       
   149     else 
       
   150         { 
       
   151         INFO_PRINTF1(_L("RunL  completed successfully")); 
       
   152         } 
       
   153     }
       
   154 
       
   155 TBool CT_RMobileLineData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
   156 	{
       
   157 	TBool ret = ETrue;
       
   158 	
       
   159 	if ( aCommand==KCmdOpen )
       
   160 		{
       
   161 		DoCmdOpen(aSection);
       
   162 		}
       
   163 	else if ( aCommand==KCmdClose )
       
   164 		{
       
   165 		DoCmdClose();
       
   166 		}
       
   167 	else if ( aCommand==KCmdNotifyIncomingCall)
       
   168 		{
       
   169 		DoCmdNotifyIncomingCall(aSection, aAsyncErrorIndex);
       
   170 		}
       
   171 	else
       
   172 		{
       
   173 		ERR_PRINTF1(_L("Unknown command"));
       
   174 		ret = EFalse;
       
   175 		}
       
   176 	return ret;
       
   177 	}
       
   178 
       
   179 void CT_RMobileLineData::DoCmdOpen(const TDesC& aSection)
       
   180 	{
       
   181     INFO_PRINTF1(_L("*START*CT_RMobileLineData::OpenLine"));
       
   182     TInt error(0);
       
   183     TBool dataOk = ETrue;
       
   184     TPtrC resultLineName;
       
   185     if( !GetStringFromConfig(aSection, KLineName, resultLineName) )
       
   186     	{
       
   187     	ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KLineName);
       
   188     	SetBlockResult(EFail);
       
   189     	dataOk = EFalse;
       
   190     	}
       
   191     TPtrC mobilePhoneName;
       
   192     if( !GetStringFromConfig(aSection, KMobilePhoneKey, mobilePhoneName) )
       
   193     	{
       
   194     	ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KMobilePhoneKey);
       
   195     	SetBlockResult(EFail);
       
   196     	dataOk = EFalse;
       
   197     	}
       
   198     if(dataOk)
       
   199     	{
       
   200 		RMobilePhone* mobilePhoneObject = static_cast<RMobilePhone*>(GetDataObjectL(mobilePhoneName));
       
   201 		INFO_PRINTF1(_L("Opening Line"));
       
   202 	    error = iMobileLine->Open(*mobilePhoneObject, resultLineName);
       
   203 	    if(error != KErrNone)
       
   204 	    	{
       
   205 	    	ERR_PRINTF2(_L("Failed to open Line with error %d"), error);
       
   206 	    	SetError(error);
       
   207 	    	}
       
   208 	    else
       
   209 	    	{
       
   210 	    	INFO_PRINTF1(_L("OpenLine succeeded"));
       
   211 	    	}
       
   212     	}
       
   213     INFO_PRINTF1(_L("*END*CT_RMobileLineData::OpenLine"));
       
   214 	}
       
   215 
       
   216 void CT_RMobileLineData::DoCmdClose()
       
   217 	{
       
   218     INFO_PRINTF1(_L("*START*CT_RMobileLineData::CloseLine"));
       
   219     iMobileLine->Close();
       
   220     INFO_PRINTF1(_L("CloseLine succeeded"));
       
   221 	INFO_PRINTF1(_L("*END*CT_RMobileLineData::CloseLine"));
       
   222 	}
       
   223 
       
   224 void CT_RMobileLineData::DoCmdNotifyIncomingCall(const TDesC& aSection, const TInt aAsyncErrorIndex)
       
   225 	{
       
   226 	INFO_PRINTF1(_L("*START*CT_VoiceCallDriverData::DoCmdNotifyIncomingCall"));
       
   227 
       
   228 	TInt callNameParameter;
       
   229 	if( !GetIntFromConfig(aSection, KCallName, callNameParameter ) )
       
   230     	{
       
   231     	ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KCallName);
       
   232     	SetBlockResult(EFail);
       
   233     	}
       
   234 	else
       
   235 		{
       
   236 		TName* CallName = NULL;
       
   237 		TRAPD(error, CallName = GetCallNameL(callNameParameter));
       
   238 		if(error != KErrNone)
       
   239 			{
       
   240 			ERR_PRINTF2(_L("Left while getting call name with error %d"), error);
       
   241 			SetError(error);
       
   242 			}
       
   243 		else
       
   244 			{
       
   245 			INFO_PRINTF1(_L("Start NotifyIncomingCall Asynchronous call."));
       
   246 			iMobileLine->NotifyIncomingCall(iActiveCallback->iStatus, *CallName);
       
   247 		    iActiveCallback->Activate(aAsyncErrorIndex);
       
   248 		    IncOutstanding();
       
   249 			}
       
   250 		}
       
   251     INFO_PRINTF1(_L("*END*CT_VoiceCallDriverData::DoCmdNotifyIncomingCall"));
       
   252 	}
       
   253 
       
   254 TName* CT_RMobileLineData::GetCallNameL(TInt aCall)
       
   255 	{
       
   256 	INFO_PRINTF1(_L("*START*CT_VoiceCallDriverData::GetCallNameL"));
       
   257 	
       
   258 	INFO_PRINTF2(_L("Get TName: %d name"), aCall);
       
   259 
       
   260 	// Check that over/under flow does not occur
       
   261 	if (aCall < 0 || aCall >= iCallNames.Count())
       
   262 		{
       
   263     	ERR_PRINTF2(_L("There is no such name as (%d)"), aCall);
       
   264     	User::Leave(KErrArgument);
       
   265 		}
       
   266 	
       
   267 	INFO_PRINTF1(_L("*END*CT_VoiceCallDriverData::GetCallNameL"));
       
   268 	return &iCallNames[aCall];
       
   269 	}
       
   270