cellularsrvapitest/telephonydevsoundhaitest/etelmm/src/T_RMobilePhoneData.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_RMobilePhoneData.h"
       
    25 
       
    26 
       
    27 _LIT(KTelServerKey,			"RTelServer");
       
    28 _LIT(KPhone,				"Phone");
       
    29 
       
    30 /*@{*/
       
    31 //LIT's for commands
       
    32 _LIT(KCmdOpen, 				"Open");
       
    33 _LIT(KCmdClose, 			"Close");
       
    34 _LIT(KCmdInitialise,		"Initialise");
       
    35 /*}@*/
       
    36 
       
    37 /**
       
    38  * Two phase constructor
       
    39  *
       
    40  * @leave	system wide error
       
    41  */
       
    42 CT_RMobilePhoneData* CT_RMobilePhoneData::NewL()
       
    43 	{
       
    44 	CT_RMobilePhoneData*	ret=new (ELeave) CT_RMobilePhoneData();
       
    45 	CleanupStack::PushL(ret);
       
    46 	ret->ConstructL();
       
    47 	CleanupStack::Pop(ret);
       
    48 	return ret;
       
    49 	}
       
    50 
       
    51 
       
    52 /**
       
    53  * Protected constructor. First phase construction
       
    54  */
       
    55 CT_RMobilePhoneData::CT_RMobilePhoneData()
       
    56 :iMobilePhone(NULL)
       
    57 	{
       
    58 	}
       
    59 
       
    60 /**
       
    61  * Second phase construction
       
    62  *
       
    63  * @internalComponent
       
    64  *
       
    65  * @return	N/A
       
    66  *
       
    67  * @pre		None
       
    68  * @post	None
       
    69  *
       
    70  * @leave	system wide error
       
    71  */
       
    72 void CT_RMobilePhoneData::ConstructL()
       
    73 	{
       
    74 	iMobilePhone = new (ELeave) RMobilePhone();
       
    75 	}
       
    76 
       
    77 /**
       
    78  * Public destructor
       
    79  */
       
    80 CT_RMobilePhoneData::~CT_RMobilePhoneData()
       
    81 	{
       
    82 	if(iMobilePhone)
       
    83 		{
       
    84 		delete iMobilePhone;
       
    85 		iMobilePhone = NULL;
       
    86 		}	
       
    87 	}
       
    88 
       
    89 /**
       
    90  * Return a pointer to the object that the data wraps
       
    91  *
       
    92  * @return	pointer to the object that the data wraps
       
    93  */
       
    94 TAny* CT_RMobilePhoneData::GetObject()
       
    95 	{
       
    96 	return iMobilePhone;
       
    97 	}
       
    98 
       
    99 TBool CT_RMobilePhoneData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
   100 	{
       
   101 	TBool ret = ETrue;
       
   102 	
       
   103 	if ( aCommand==KCmdOpen )
       
   104 		{
       
   105 		DoCmdOpen(aSection);
       
   106 		}
       
   107 	else if ( aCommand==KCmdClose )
       
   108 		{
       
   109 		DoCmdClose();
       
   110 		}
       
   111 	else if ( aCommand==KCmdInitialise )
       
   112 		{
       
   113 		DoCmdInitialise();
       
   114 		}
       
   115 	else
       
   116 		{
       
   117 		ret = EFalse;
       
   118 		ERR_PRINTF1(_L("Unknown command"));
       
   119 		}
       
   120 	
       
   121 	return ret;
       
   122 	}
       
   123 
       
   124 //== Mobile Line functions
       
   125 void CT_RMobilePhoneData::DoCmdOpen(const TDesC& aSection)
       
   126 	{
       
   127 	INFO_PRINTF1(_L("*START*CT_RMobilePhoneData::DoCmdOpen"));
       
   128 	// Check that first phone is available and log phone name.
       
   129 	RTelServer::TPhoneInfo info;
       
   130 	// Reading phone info for the first available phone
       
   131 	TBool dataOk = ETrue;
       
   132 	TInt parPhone = 0;
       
   133 	if ( !GetIntFromConfig(aSection, KPhone(), parPhone) )
       
   134 		{
       
   135 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KPhone);
       
   136 		SetBlockResult(EFail);
       
   137 		dataOk = EFalse;
       
   138 		}
       
   139 	TPtrC telServerName;
       
   140 	if ( !GetStringFromConfig(aSection, KTelServerKey(), telServerName) )
       
   141 		{
       
   142 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KTelServerKey);
       
   143 		SetBlockResult(EFail);
       
   144 		dataOk = EFalse;
       
   145 		}
       
   146 	if ( dataOk )
       
   147 		{
       
   148 		RTelServer* telServerObject = static_cast<RTelServer*>(GetDataObjectL(telServerName));
       
   149 		INFO_PRINTF1(_L("Check if phone info was found."));
       
   150 		TRAPD ( error, telServerObject->GetPhoneInfo(parPhone, info) );
       
   151 		if (error != KErrNone)
       
   152 			{
       
   153 			ERR_PRINTF2(_L("Failed to read phone info for phone KFirstPhone with error %d"), error);
       
   154 			SetError(error);
       
   155 			}
       
   156 		else
       
   157 			{
       
   158 			// Connect to RMobilePhone interface.
       
   159 			INFO_PRINTF1(_L("Opening connection to phone"));
       
   160 			error = iMobilePhone->Open(*telServerObject, info.iName);
       
   161 			if (error != KErrNone)
       
   162 				{
       
   163 				ERR_PRINTF2(_L("Connection to phone failed with error %d"), error);
       
   164 				SetError(error);
       
   165 				}
       
   166 			else
       
   167 				{
       
   168 				INFO_PRINTF1(_L("Opening connection to phone sucessfull"));
       
   169 				}
       
   170 			}
       
   171 		}
       
   172 	INFO_PRINTF1(_L("*END*CT_RMobilePhoneData::DoCmdOpen"));
       
   173 	}
       
   174 
       
   175 void CT_RMobilePhoneData::DoCmdInitialise()
       
   176 	{
       
   177 	INFO_PRINTF1(_L("*START*CT_RMobilePhoneData::DoCmdInitialise"));
       
   178 	INFO_PRINTF1(_L("Initialising the phone"));
       
   179 	TRAPD( error, iMobilePhone->Initialise() );
       
   180 	if (error != KErrNone)
       
   181 		{
       
   182 		ERR_PRINTF2(_L("Failed to initalise the phone with error %d"), error);
       
   183         SetError(error);
       
   184 		}
       
   185 	INFO_PRINTF1(_L("*END*CT_RMobilePhoneData::DoCmdInitialise"));
       
   186 	}
       
   187 
       
   188 void CT_RMobilePhoneData::DoCmdClose()
       
   189 	{
       
   190 	INFO_PRINTF1(_L("*START*CT_RMobilePhoneData::DoCmdClosePhone"));
       
   191 	INFO_PRINTF1(_L("Closing mobile phone session..."));
       
   192 	iMobilePhone->Close();
       
   193 	INFO_PRINTF1(_L("*END*CT_RMobilePhoneData::DoCmdInitialise"));
       
   194 	}
       
   195