程序拨号及检测何时挂断的解决方案
来源:互联网 发布:thinkphp5子域名 编辑:程序博客网 时间:2024/06/05 18:37
程序拨号及检测何时挂断的解决方案
用过Nokia智能手机的人都知道,当电话拨通以后,原来的程序就被切换到后台运行去了,但是当电话挂断以后,Nokia并没有把原来的程序给切换到前台,不知道Nokia为什么要这样做.本篇给出一份代码,内容包括拨号,CallBack电话挂断事件,把原来的程序切换到前台.
/*
* ============================================================================
* Name : CDailEngine from CDailEngine.h
* Part of : None
* Created : 08.08.2006 by Zhaojiangwei
* Last Modifed: 22.08.2006
* Implementation notes:
*
* Version : 1.0
* Copyright: All rights reserved
* ============================================================================
*/
#ifndef __DAILENGINE_H__
#define __DAILENGINE_H__
#include <etel.h>
class MPhoneCallClientObserver
{
public:
virtual void HandleCallHungUpL() = 0;
};
class CDailEngine:public CActive
{
public:
static CDailEngine* NewL(MPhoneCallClientObserver& aObserver);
~CDailEngine();
public:
// CActive
virtual void RunL();
virtual void DoCancel();
public:
void MakeCallL(const TDesC& aNumber);
private:
// the state of this object governs what happens when the
// StartL() / Stop() / RunL() / DoCancel() functions are called.
enum TState
{
ENoState,
EDialling,
EWatching
};
private:
CDailEngine(MPhoneCallClientObserver& aObserver);
void ConstructL();
private:
void StartL();
void Stop();
void InitCallServerL();
void TelephonyCleanup();
private:
MPhoneCallClientObserver& iObserver;
RCall iCall;
RTelServer iServer;
RPhone iPhone;
RLine iLine;
RCall::TStatus iCallStatus;
TState iState;
TPtrC iNumber;
};
#endif
/*
* ============================================================================
* Name : CDailEngine from CDailEngine.cpp
* Part of : None
* Created : 08.08.2006 by Zhaojiangwei
* Last Modifed: 22.08.2006
* Implementation notes:
*
* Version : 1.0
* Copyright: All rights reserved
* ============================================================================
*/
#include "DailEngine.h"
_LIT (KTsyName,"phonetsy.tsy");
CDailEngine::CDailEngine(MPhoneCallClientObserver& aObserver)
:CActive(EPriorityNormal),
iObserver(aObserver), iState(ENoState)
{
}
CDailEngine::~CDailEngine()
{
Cancel();
TelephonyCleanup();
}
CDailEngine* CDailEngine::NewL(MPhoneCallClientObserver& aObserver)
{
CDailEngine* self = new (ELeave) CDailEngine(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
void CDailEngine::ConstructL()
{
CActiveScheduler::Add(this);
}
void CDailEngine::MakeCallL(const TDesC& aNumber)
{
iState = EDialling;
InitCallServerL();
iNumber.Set(aNumber);
StartL();
}
void CDailEngine::InitCallServerL()
{
iServer.Connect();
iServer.LoadPhoneModule(KTsyName);
//Find the number of phones available from the tel server
TInt numberPhones;
User::LeaveIfError(iServer.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(iServer.GetPhoneInfo(0, info));
//Use this info to open a connection to the phone, the phone is identified by its name
User::LeaveIfError(iPhone.Open(iServer, info.iName));
//Get info about the first line from the phone
RPhone::TLineInfo lineInfo;
User::LeaveIfError(iPhone.GetLineInfo(0, lineInfo));
//Use this to open a line
User::LeaveIfError(iLine.Open(iPhone, lineInfo.iName));
}
void CDailEngine::StartL()
{
switch(iState)
{
case ENoState:
return;
case EDialling:
{
User::LeaveIfError(iCall.OpenNewCall(iLine));
iCall.Dial(iStatus, iNumber);
break;
}
case EWatching:
iCall.NotifyStatusChange(iStatus, iCallStatus);
break;
}
SetActive();
}
void CDailEngine::RunL()
{
// if the caller hangs up, then we will get KErrGeneral error here
if(iState == EDialling && iStatus.Int() == KErrGeneral)
{
Stop();
iObserver.HandleCallHungUpL();
return;
}
if(iStatus.Int() != KErrNone)
return;
switch(iState)
{
case EDialling:
iState = EWatching;
StartL();
break;
case EWatching:
User::LeaveIfError(iCall.GetStatus(iCallStatus));
if(iCallStatus == RCall::EStatusHangingUp || iCallStatus == RCall::EStatusIdle)
{
Stop();
iObserver.HandleCallHungUpL();
}
else
{
StartL();
}
break;
default:
break;
}
}
void CDailEngine::DoCancel()
{
Stop();
}
void CDailEngine::Stop()
{
switch(iState)
{
case ENoState:
break;
case EDialling:
iCall.HangUp();
iCall.Close();
break;
case EWatching:
iCall.NotifyStatusChangeCancel();
iCall.Close();
break;
}
iState = ENoState;
}
void CDailEngine::TelephonyCleanup()
{
//free up the resource
iPhone.Close();
iLine.Close();
iServer.Close();
}
/*
* ============================================================================
* Name : CDailEngine from CDailEngine.h
* Part of : None
* Created : 08.08.2006 by Zhaojiangwei
* Last Modifed: 22.08.2006
* Implementation notes:
*
* Version : 1.0
* Copyright: All rights reserved
* ============================================================================
*/
#ifndef __DAILENGINE_H__
#define __DAILENGINE_H__
#include <etel.h>
class MPhoneCallClientObserver
{
public:
virtual void HandleCallHungUpL() = 0;
};
class CDailEngine:public CActive
{
public:
static CDailEngine* NewL(MPhoneCallClientObserver& aObserver);
~CDailEngine();
public:
// CActive
virtual void RunL();
virtual void DoCancel();
public:
void MakeCallL(const TDesC& aNumber);
private:
// the state of this object governs what happens when the
// StartL() / Stop() / RunL() / DoCancel() functions are called.
enum TState
{
ENoState,
EDialling,
EWatching
};
private:
CDailEngine(MPhoneCallClientObserver& aObserver);
void ConstructL();
private:
void StartL();
void Stop();
void InitCallServerL();
void TelephonyCleanup();
private:
MPhoneCallClientObserver& iObserver;
RCall iCall;
RTelServer iServer;
RPhone iPhone;
RLine iLine;
RCall::TStatus iCallStatus;
TState iState;
TPtrC iNumber;
};
#endif
/*
* ============================================================================
* Name : CDailEngine from CDailEngine.cpp
* Part of : None
* Created : 08.08.2006 by Zhaojiangwei
* Last Modifed: 22.08.2006
* Implementation notes:
*
* Version : 1.0
* Copyright: All rights reserved
* ============================================================================
*/
#include "DailEngine.h"
_LIT (KTsyName,"phonetsy.tsy");
CDailEngine::CDailEngine(MPhoneCallClientObserver& aObserver)
:CActive(EPriorityNormal),
iObserver(aObserver), iState(ENoState)
{
}
CDailEngine::~CDailEngine()
{
Cancel();
TelephonyCleanup();
}
CDailEngine* CDailEngine::NewL(MPhoneCallClientObserver& aObserver)
{
CDailEngine* self = new (ELeave) CDailEngine(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
void CDailEngine::ConstructL()
{
CActiveScheduler::Add(this);
}
void CDailEngine::MakeCallL(const TDesC& aNumber)
{
iState = EDialling;
InitCallServerL();
iNumber.Set(aNumber);
StartL();
}
void CDailEngine::InitCallServerL()
{
iServer.Connect();
iServer.LoadPhoneModule(KTsyName);
//Find the number of phones available from the tel server
TInt numberPhones;
User::LeaveIfError(iServer.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(iServer.GetPhoneInfo(0, info));
//Use this info to open a connection to the phone, the phone is identified by its name
User::LeaveIfError(iPhone.Open(iServer, info.iName));
//Get info about the first line from the phone
RPhone::TLineInfo lineInfo;
User::LeaveIfError(iPhone.GetLineInfo(0, lineInfo));
//Use this to open a line
User::LeaveIfError(iLine.Open(iPhone, lineInfo.iName));
}
void CDailEngine::StartL()
{
switch(iState)
{
case ENoState:
return;
case EDialling:
{
User::LeaveIfError(iCall.OpenNewCall(iLine));
iCall.Dial(iStatus, iNumber);
break;
}
case EWatching:
iCall.NotifyStatusChange(iStatus, iCallStatus);
break;
}
SetActive();
}
void CDailEngine::RunL()
{
// if the caller hangs up, then we will get KErrGeneral error here
if(iState == EDialling && iStatus.Int() == KErrGeneral)
{
Stop();
iObserver.HandleCallHungUpL();
return;
}
if(iStatus.Int() != KErrNone)
return;
switch(iState)
{
case EDialling:
iState = EWatching;
StartL();
break;
case EWatching:
User::LeaveIfError(iCall.GetStatus(iCallStatus));
if(iCallStatus == RCall::EStatusHangingUp || iCallStatus == RCall::EStatusIdle)
{
Stop();
iObserver.HandleCallHungUpL();
}
else
{
StartL();
}
break;
default:
break;
}
}
void CDailEngine::DoCancel()
{
Stop();
}
void CDailEngine::Stop()
{
switch(iState)
{
case ENoState:
break;
case EDialling:
iCall.HangUp();
iCall.Close();
break;
case EWatching:
iCall.NotifyStatusChangeCancel();
iCall.Close();
break;
}
iState = ENoState;
}
void CDailEngine::TelephonyCleanup()
{
//free up the resource
iPhone.Close();
iLine.Close();
iServer.Close();
}
- 程序拨号及检测何时挂断的解决方案
- 程序拨号及检测何时挂断的解决方案
- 程序拨号及检测何时挂断的解决方案
- Android(AIDL)自动重复拨号及挂断/接听电话
- ppp-off拨号挂断脚本
- 建立GPRS连接,拨号和挂断
- WAVECOM CDMA AT指令--拨号&挂断
- 使用IntentFilter的拨号程序
- Android拨号程序的编写
- linphone快速挂断后的程序崩溃问题
- linphone快速挂断后的程序崩溃问题
- linphone快速挂断后的程序崩溃问题
- Linphone快速挂断后程序的崩溃问题
- nohup方式 真正的后台不挂断运行程序
- 中文pppoe中文拨号的解决方案
- 校园网无法拨号的一些解决方案
- Ubuntu提示检测到系统程序出现问题的解决方案
- Bash漏洞检测及解决方案
- Oracle管理常用命令
- 电话簿与vCard的格式转换
- 手机撒谎软件之实现
- 有点迷茫……
- Symbian OS 之活动对象
- 程序拨号及检测何时挂断的解决方案
- Linux做WAP网关
- VS2003绑定VSS的问题
- 让Symbian应用程序开机自动启动
- 当前流行的AJAX技术选用
- 好男孩的爱情
- 使用日志类RFileLogger输出调试信息
- 用installshield打包asp.net项目
- 如何检测手机型号