void GetPhoneInfoL(RTelServer& aTelServer, const TDesC& aLoadedTsyName, RTelServer::TPhoneInfo& aInfo)
	{
	TInt count;
	User::LeaveIfError(aTelServer.EnumeratePhones(count));
	if (count<=0)
		{
		User::Leave(KErrNotFound);
		}

	TBool found = EFalse;
	for (TInt i=0; i < count; i++)
		{
		TBuf<KCommsDbSvrMaxFieldLength> currentTsyName;
		User::LeaveIfError(aTelServer.GetTsyName(i,currentTsyName));

		TInt r=currentTsyName.Locate('.');
		if (r!=KErrNotFound)
			{
			currentTsyName.SetLength(r);
			}
		if (currentTsyName.CompareF(aLoadedTsyName)==KErrNone)
			{
			User::LeaveIfError(aTelServer.GetPhoneInfo(i,aInfo));
			found = ETrue;
			break;
			}
		}

	if (!found)
		{
		User::Leave(KErrNotFound);
		}
	}
void CSmsStackTestServer::LoadTsyL(RTelServer& aServer, RPhone& aPhone, const TDesC& aTsyName)
    {
    INFO_PRINTF2(_L("Using TSY \"%S\"Loading RTelServer..."), &aTsyName);

    TInt ret = aServer.LoadPhoneModule(aTsyName);
    if (ret!=KErrNone)
        {
        ERR_PRINTF2(_L("Loading Phone Module returned %d"), ret);
        User::Leave(ret);
        }
    
    // Find the phone corresponding to this TSY and open a number of handles on it
    TInt numPhones;
    ret = aServer.EnumeratePhones(numPhones);
    if (ret!=KErrNone)
        {
        ERR_PRINTF2(_L("Enumerate Phones  returned %d"), ret);
        User::Leave(ret);
        }
    
    TBool found=EFalse;

    while (numPhones--)
        {
        TName phoneTsy;
        ret = aServer.GetTsyName(numPhones,phoneTsy);
        if (ret!=KErrNone)
            {
            ERR_PRINTF2(_L("GetTsyName returned %d"), ret);
            User::Leave(ret);
            }
        
        if (phoneTsy.CompareF(aTsyName)==KErrNone)
            {
            INFO_PRINTF1(_L("Found RPhone..."));
            found = ETrue;
            RTelServer::TPhoneInfo info;
            ret = aServer.GetPhoneInfo(numPhones,info);
            if (ret!=KErrNone)
                {
                ERR_PRINTF2(_L("GetPhoneInfo returned %d"), ret);
                User::Leave(ret);
                }
            ret = aPhone.Open(aServer,info.iName);
            if (ret!=KErrNone)
                {
                ERR_PRINTF2(_L("Opening phone returned %d"), ret);
                User::Leave(ret);
                }
 
            INFO_PRINTF1(_L("Initializing..."));
            ret = aPhone.Initialise();
            TTimeIntervalMicroSeconds32 InitPause=9000000;  //Required Pause to Allow SMSStack to Complete its Async Init
            User::After(InitPause);                         //call to the TSY and finish its StartUp.
            if (ret!=KErrNone)
                {
                ERR_PRINTF2(_L("Completed Initialize returned %d"), ret);
                User::Leave(ret);
                }
            break;
            }
        }
    
    if(!found)
        {
        ERR_PRINTF2(_L("Couldn't find the phone for TSY %S"), &aTsyName);
        }
    }
Beispiel #3
0
static void DialNumberL(PktBuf &in, PktBuf &out) {
	/// @todo maybe use a CActive object to allow the call to be cancelled from gammu
	TBuf<100> aPhoneNumber;

	in >> aPhoneNumber;

	cons->Printf( _L("dialing... number:\n") );
	cons->Printf( aPhoneNumber );
	cons->Printf( _L("\n") );

	TName newCallName = _L("call");

	//Create a connection to the tel server
	RTelServer server;
	CleanupClosePushL(server);
	User::LeaveIfError(server.Connect());

	//Load in the phone device driver
	User::LeaveIfError(server.LoadPhoneModule(KTsyName));
	
	//Find the number of phones available from the tel server
	TInt numberPhones;
	User::LeaveIfError(server.EnumeratePhones(numberPhones));

	//Check there are available phones
	if (numberPhones < 1)
	{
		User::Leave(KErrNotFound);
	}

	//Get info about the first available phone
	RTelServer::TPhoneInfo info;
	User::LeaveIfError(server.GetPhoneInfo(0, info));

	//Use this info to open a connection to the phone, the phone is identified by its name
	RPhone phone;
	CleanupClosePushL(phone);
	User::LeaveIfError(phone.Open(server, info.iName));

	//Get info about the first line from the phone
	RPhone::TLineInfo lineInfo;
	User::LeaveIfError(phone.GetLineInfo(0, lineInfo));

	//Use this to open a line
	RLine line;
	CleanupClosePushL(line);
	User::LeaveIfError(line.Open(phone, lineInfo.iName));

	//Open a new call on this line
	RCall call;
	CleanupClosePushL(call);
	User::LeaveIfError(call.OpenNewCall(line, newCallName));

	if ((call.Dial(aPhoneNumber) == KErrNone))
	{
		TRequestStatus iStatus;
		RCall::TStatus iLineStatus;
		line.NotifyStatusChange(iStatus, iLineStatus);
		User::WaitForRequest(iStatus);
	}

	CleanupStack::PopAndDestroy(4);//phone, line, call

	//Unload the phone device driver
	User::LeaveIfError(server.UnloadPhoneModule(KTsyName));

	out << (TUint16)GNAPPLET_MSG_PHONEBOOK_DIAL_RESP;
	out << (TUint16)GN_ERR_NONE;
}
void CSmsReplyToStep::InitialiseSimTsyL()
	{
	
	INFO_PRINTF1(_L("Initialising the SimTsy..."));
	
	_LIT(KDefaultTsyName, "SIM"); 
	HBufC* tsyName =KDefaultTsyName().AllocLC();

	//Initialize TSY using the System Agent
	TInt testState;
	TInt testNumber=1;
	if(KErrNone != RProperty::Get(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testState))
		{
		User::LeaveIfError(RProperty::Define(KUidPSSimTsyCategory, KPSSimTsyTestNumber, RProperty::EInt));
		}
	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
	if(KErrNone != RProperty::Get(KUidSystemCategory, KMsvTestUidPhonePwrValue, testState))
		{
		User::LeaveIfError(RProperty::Define(KUidSystemCategory, KMsvTestUidPhonePwrValue, RProperty::EInt));
		}
	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KMsvTestUidPhonePwrValue, EMsvTestPhoneOn));

	User::LeaveIfError(RProperty::Get(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));

	RTelServer etelServer;
	User::LeaveIfError(etelServer.Connect());
	CleanupClosePushL(etelServer);
	User::LeaveIfError(etelServer.LoadPhoneModule(tsyName->Des()));

	// Find the phone corresponding to this TSY and open a number of handles on it
	TInt numPhones;
	User::LeaveIfError(etelServer.EnumeratePhones(numPhones));	
	TBool found=EFalse;
	
	RMobilePhone iPhone;
	while (!found && numPhones--)
		{
		TName phoneTsy;
		User::LeaveIfError(etelServer.GetTsyName(numPhones,phoneTsy));
		if (phoneTsy.CompareF(tsyName->Des())==KErrNone)
			{
			found = ETrue;
			RTelServer::TPhoneInfo info;
			User::LeaveIfError(etelServer.GetPhoneInfo(numPhones,info));
			CleanupClosePushL(iPhone);
			User::LeaveIfError(iPhone.Open(etelServer,info.iName));
			User::LeaveIfError(iPhone.Initialise());
			//Required Pause to Allow SMSStack to Complete its Async Init call to the TSY and finish its StartUp.
			TTimeIntervalMicroSeconds32 InitPause=9000000;  
			User::After(InitPause);							
			
			CleanupStack::PopAndDestroy(&iPhone);
			}
		}
	
	CleanupStack::PopAndDestroy(&etelServer);	

	CMDBSession* dbSession = CMDBSession::NewL(CMDBSession::LatestVersion());
	CleanupStack::PushL(dbSession);
	CMDBRecordSet<CCDGlobalSettingsRecord> globalSettingsRecord(KCDTIdGlobalSettingsRecord);
	TRAPD(err, globalSettingsRecord.LoadL(*dbSession));
	if(err != KErrNone)
		{
		User::Leave(KErrNotFound);				
		}
	
	CCDModemBearerRecord *modemRecord = static_cast<CCDModemBearerRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdModemBearerRecord));		
	CleanupStack::PushL(modemRecord);
	modemRecord->SetRecordId(((CCDGlobalSettingsRecord*)globalSettingsRecord.iRecords[0])->iModemForPhoneServicesAndSMS);
	modemRecord->LoadL(*dbSession);
	modemRecord->iTsyName.SetMaxLengthL(tsyName->Des().Length());
	modemRecord->iTsyName = tsyName->Des();	
	modemRecord->ModifyL(*dbSession);
	CleanupStack::PopAndDestroy(3);  //tsyName, dbSession, modemRecord 	
	
	INFO_PRINTF1(_L("Successfully initialised the Sim Tsy"));
	}
enum TVerdict CTestPhoneInfo::doTestStepL()
{
    INFO_PRINTF1(_L("Test Phone Info"));

    RTelServer server;
    TInt ret = server.Connect();
    TESTCHECK(ret, KErrNone);

    TInt  originalNumPhones;
    ret = server.EnumeratePhones(originalNumPhones);
    TESTCHECK(ret, KErrNone);

    ret=server.LoadPhoneModule(DSTD_MODULE_NAME);
    TESTCHECK(ret, KErrNone);
    ret=server.LoadPhoneModule(DSTDNC_MODULE_NAME);
    TESTCHECK(ret, KErrNone);

    TInt numPhones;
    ret=server.EnumeratePhones(numPhones);
    TESTCHECK(ret, KErrNone);
    INFO_PRINTF2(_L("EnumeratePhones returned %d"),numPhones);

    INFO_PRINTF4(_L("Should equal %d + %d + %d"), DSTDNC_NUMBER_OF_PHONES, DSTD_NUMBER_OF_PHONES,
                 originalNumPhones);
    TESTCHECK(numPhones, (DSTDNC_NUMBER_OF_PHONES + DSTD_NUMBER_OF_PHONES + originalNumPhones));

    RTelServer::TPhoneInfo info;
    TName tsyName;
    TInt  phoneIndex = originalNumPhones;

    // first phone
    ret=server.GetPhoneInfo(phoneIndex,info);
    TESTCHECK(ret, KErrNone);
    TESTCHECK(info.iNetworkType, DSTD_NETWORK_TYPE);
    TESTCHECKSTR(info.iName, DSTD_PHONE_NAME);
    TESTCHECK(info.iNumberOfLines, DSTD_NUMBER_OF_LINES);

    ret=server.GetTsyName(phoneIndex,tsyName);
    TESTCHECK(ret, KErrNone);
    TESTCHECKSTR(tsyName, DSTD_MODULE_NAME);
    phoneIndex++;

    // second phone
    ret=server.GetPhoneInfo(phoneIndex,info);
    TESTCHECK(ret, KErrNone);
    TESTCHECK(info.iNetworkType, DSTDFC_NETWORK_TYPE);
    TESTCHECKSTR(info.iName, DSTDFC_PHONE_NAME);
    TESTCHECK(info.iNumberOfLines, DSTDFC_NUMBER_OF_LINES);

    ret=server.GetTsyName(phoneIndex,tsyName);
    TESTCHECK(ret, KErrNone);
    TESTCHECKSTR(tsyName, DSTD_MODULE_NAME);
    phoneIndex++;

    // third phone
    ret=server.GetPhoneInfo(phoneIndex,info);
    TESTCHECK(ret, KErrNone);
    TESTCHECK(info.iNetworkType, DSTDPM_NETWORK_TYPE);
    TESTCHECKSTR(info.iName, DSTDPM_PHONE_NAME);
    TESTCHECK(info.iNumberOfLines, DSTDPM_NUMBER_OF_LINES);

    ret=server.GetTsyName(phoneIndex,tsyName);
    TESTCHECK(ret, KErrNone);
    TESTCHECKSTR(tsyName, DSTD_MODULE_NAME);
    phoneIndex++;

    // fourth phone
    ret=server.GetPhoneInfo(phoneIndex,info);
    TESTCHECK(ret, KErrNone);
    TESTCHECK(info.iNetworkType, DSTDPM_NETWORK_TYPE);
    TESTCHECKSTR(info.iName, DSTD_SLOW_PHONE_NAME);
    TESTCHECK(info.iNumberOfLines, DSTDPM_NUMBER_OF_LINES);

    ret=server.GetTsyName(phoneIndex,tsyName);
    TESTCHECK(ret, KErrNone);
    TESTCHECKSTR(tsyName, DSTD_MODULE_NAME);
    phoneIndex++;

    // fifth phone
    ret=server.GetPhoneInfo(phoneIndex,info);
    TESTCHECK(ret, KErrNone);
    TESTCHECK(info.iNetworkType, DSTDNC_NETWORK_TYPE);
    TESTCHECKSTR(info.iName, DSTDNC_PHONE_NAME);
    TESTCHECK(info.iNumberOfLines, DSTDNC_NUMBER_OF_LINES);

    ret=server.GetTsyName(phoneIndex,tsyName);
    TESTCHECK(ret, KErrNone);
    TESTCHECKSTR(tsyName, DSTDNC_MODULE_NAME);
    phoneIndex++;

    // sixth phone
    ret=server.GetPhoneInfo(phoneIndex,info);
    TESTCHECK(ret, KErrNotFound);

    ret=server.GetTsyName(phoneIndex,tsyName);
    TESTCHECK(ret, KErrNotFound);
    phoneIndex++;

    ret=server.UnloadPhoneModule(DSTD_MODULE_NAME);
    TESTCHECK(ret, KErrNone);
    ret=server.UnloadPhoneModule(DSTDNC_MODULE_NAME);
    TESTCHECK(ret, KErrNone);
    ServerClose(server);

    ret = server.Connect();
    TESTCHECK(ret, KErrNone);
    ret=server.LoadPhoneModule(DSTDNC_MODULE_NAME);
    TESTCHECK(ret, KErrNone);

    ret=server.LoadPhoneModule(DSTD_MODULE_NAME);
    TESTCHECK(ret, KErrNone);

    ret=server.EnumeratePhones(numPhones);
    TESTCHECK(ret, KErrNone);
    TESTCHECK(numPhones, (DSTD_NUMBER_OF_PHONES + DSTDNC_NUMBER_OF_PHONES + originalNumPhones));

    phoneIndex = originalNumPhones;

    ret=server.GetPhoneInfo(phoneIndex,info);
    TESTCHECK(ret, KErrNone);
    TESTCHECK(info.iNetworkType, DSTDNC_NETWORK_TYPE);
    TESTCHECKSTR(info.iName, DSTDNC_PHONE_NAME);
    TESTCHECK(info.iNumberOfLines, DSTDNC_NUMBER_OF_LINES);
    phoneIndex++;

    ret=server.GetPhoneInfo(phoneIndex,info);
    TESTCHECK(ret, KErrNone);
    TESTCHECK(info.iNetworkType, DSTD_NETWORK_TYPE);
    TESTCHECKSTR(info.iName, DSTD_PHONE_NAME);
    TESTCHECK(info.iNumberOfLines, DSTD_NUMBER_OF_LINES);
    phoneIndex++;

    ret=server.GetPhoneInfo(phoneIndex,info);
    TESTCHECK(ret, KErrNone);
    TESTCHECK(info.iNetworkType, DSTDFC_NETWORK_TYPE);
    TESTCHECKSTR(info.iName, DSTDFC_PHONE_NAME);
    TESTCHECK(info.iNumberOfLines, DSTDFC_NUMBER_OF_LINES);
    phoneIndex++;

    ret=server.GetPhoneInfo(phoneIndex,info);
    TESTCHECK(ret, KErrNone);
    TESTCHECK(info.iNetworkType, DSTDPM_NETWORK_TYPE);
    TESTCHECKSTR(info.iName, DSTDPM_PHONE_NAME);
    TESTCHECK(info.iNumberOfLines, DSTDPM_NUMBER_OF_LINES);
    phoneIndex++;

    ret=server.GetPhoneInfo(phoneIndex,info);
    TESTCHECK(ret, KErrNone);
    TESTCHECK(info.iNetworkType, DSTDPM_NETWORK_TYPE);
    TESTCHECKSTR(info.iName, DSTD_SLOW_PHONE_NAME);
    TESTCHECK(info.iNumberOfLines, DSTDPM_NUMBER_OF_LINES);
    phoneIndex++;

    ret=server.GetPhoneInfo(phoneIndex,info);
    TESTCHECK(ret, KErrNotFound);
    phoneIndex++;

    ret=server.UnloadPhoneModule(DSTD_MODULE_NAME);
    TESTCHECK(ret, KErrNone);
    ret=server.UnloadPhoneModule(DSTDNC_MODULE_NAME);
    TESTCHECK(ret, KErrNone);
    ServerClose(server);

    return TestStepResult();
}
static inline TInt EnumeratePhones(RTelServer& aTelServer, TInt& aNumPhones)
	{
	return aTelServer.EnumeratePhones(aNumPhones);
	}