Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3337025
  • 博文数量: 1450
  • 博客积分: 11163
  • 博客等级: 上将
  • 技术积分: 11101
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-25 14:40
文章分类

全部博文(1450)

文章存档

2017年(5)

2014年(2)

2013年(3)

2012年(35)

2011年(39)

2010年(88)

2009年(395)

2008年(382)

2007年(241)

2006年(246)

2005年(14)

分类: C/C++

2010-02-22 15:57:20

  1. 因为涉及到三版和二版两个版本的API,所以我先发个二版的(其实也就是来电检测不同),要用到的能力有 NetworkControl,NetworkServices,ReadUserData,SwEvent,WriteDeviceData
    下面是H文件

  2. /*
  3. * CTelDial.h
  4. *
  5. *  Created on: 2009年9月18日
  6. *      Author: snowind
  7. */

  8. #ifndef CTELDIAL_H_
  9. #define CTELDIAL_H_

  10. //etel core api
  11. #include
  12. #include

  13. #include

  14. //for the vibra and ring
  15. #include
  16. #include
  17. #include
  18. #include

  19. #include //CR Keys To Control Phone Volume
  20. #include //CRepository

  21. //for the light
  22. #include

  23. //for the loud speaker
  24. #include
  25. #include

  26. //simulation key
  27. #include

  28. class CTelDial: public CActive
  29.         {
  30. public:
  31.         
  32.         static CTelDial* NewL();
  33.                
  34.         void GetDefaultTSY(TDes& aTSYName);
  35.         
  36.         void StartObserve();

  37.         //the dial
  38.         
  39.         void GetDialNumber();
  40.         
  41.         void SetDialNumber(const TDes& aSetDialNumber);
  42.         
  43.         bool CmpDialedNumber();
  44.         
  45.         void OpenLoudSpeaker();
  46.         
  47.         void SetCallVolumn(const TInt aspeakvol);
  48.         
  49.         //the receive

  50.         void GetReceivedNumber();
  51.         
  52.         void SetReceiveNumber(const TDes& aSetReceiveNumber);
  53.         
  54.         bool CmpReceivedNumber();
  55.         
  56.         //detect        
  57.         
  58.         void SetDetectNumber(const TDes& aSetDetectNumber);        
  59.         
  60.         bool CmpDetectNumber();
  61.         
  62.         //light and vibra
  63.         
  64.         void SetVibraAndRing();
  65.         
  66.         void RecoverVibraAndRing();
  67.         
  68.         //simulate key
  69.         
  70.         void SimulateRedKey();
  71.         
  72.         void SimulateRightKey();
  73.         
  74.         //release
  75.         
  76.         void ReleaseOneCall();
  77.         
  78.         ~CTelDial();
  79.         
  80. protected:
  81.         
  82.         void RunL();
  83.         
  84.         void DoCancel();
  85.         
  86. private:
  87.         
  88.         CTelDial();
  89.                
  90.         void ConstructL();
  91.         
  92.         static CTelDial* NewLC();
  93.         
  94. private:
  95.         //const TUid KUidSound =0x101f8798;
  96. //Etel Api
  97. private:
  98.         
  99.         TBuf <20>iTSYName;
  100.         RTelServer iServer;
  101.         RPhone iPhone;
  102.         RPhone::TLineInfo iphonelineinfo;
  103.         RLine iLine;
  104.         RLine::TLineInfo ilineinfo;
  105.         RCall::TStatus iCallStatus;
  106.         //from the etelmm
  107.         RMobileCall iMCall;

  108. //the numbers
  109. private:
  110.         TBuf <11> iNumberDial;
  111.         TBuf <11> iNumberReceive;
  112.         TBuf <11> iNumberDialSet;
  113.         TBuf <11> iNumberReceiveSet;
  114.         TBuf <11> iNumberDetectSet;

  115. //to change the repository
  116. private:
  117.         CRepository* irepository;

  118.         
  119. //for the vibra and ring
  120. private:
  121.         TBool ivibratype;
  122.         TProfileRingingType iRingingType;
  123.         
  124. private:
  125.         CHWRMLight* ilight;
  126.         
  127. private:
  128.         RWindowGroup iwindowgroup;
  129.         
  130. //simulate key
  131. private:
  132.         RWsSession ws;
  133.         TRawEvent ev1;
  134.         
  135.         
  136.         };

  137. #endif /* CTELDIAL_H_ */
因为电话挂断有两种方法,所我先发所有的函数申明,然后再发不同的地方

  1. /*
  2. * CTelDial.cpp
  3. *
  4. *  Created on: 2009年9月18日
  5. *      Author: snowind
  6. */

  7. #include
  8. #include
  9. #include "CTelDial.h"

  10. //constructed function
  11. void CTelDial::ConstructL()
  12.         {
  13.         //add the cteldial to the active scheduler
  14.         CActiveScheduler::Add(this);

  15.         ilight = CHWRMLight::NewL();
  16.        

  17.         //use the etel core api
  18.         //create a tel server
  19.         User::LeaveIfError(iServer.Connect()); //connect

  20.         //get the number of phones in the server
  21.         TInt numberphones;
  22.         User::LeaveIfError(iServer.EnumeratePhones(numberphones));

  23.         //get the default tsy
  24.         GetDefaultTSY(iTSYName);

  25.         //load the tsy module
  26.         User::LeaveIfError(iServer.LoadPhoneModule(iTSYName));

  27.         //get the first phone's info
  28.         RTelServer::TPhoneInfo iPhoneinfo;
  29.         User::LeaveIfError(iServer.GetPhoneInfo(0, iPhoneinfo));

  30.         //use this info to connect the phone
  31.         User::LeaveIfError(iPhone.Open(iServer, iPhoneinfo.iName));
  32.         iPhone.Initialise();

  33.         //get the number of line
  34.         TInt numberline;
  35.         User::LeaveIfError(iPhone.EnumerateLines(numberline));
  36.         User::LeaveIfError(iPhone.GetLineInfo(0, iphonelineinfo));
  37.         User::LeaveIfError(iLine.Open(iPhone, iphonelineinfo.iName));
  38.         }

  39. //----------------------------------------------------
  40. //CTelDial::StartObserve()
  41. //observe the call
  42. //----------------------------------------------------
  43. void CTelDial::StartObserve()
  44.         {
  45.         Cancel();

  46.         //if the status of line changes, it means some one is calling this phone
  47.         iLine.NotifyStatusChange(iStatus, iCallStatus);

  48.         //invoke the asynchronous function
  49.         SetActive();
  50.         }



  51. //----------------------------------------------------
  52. //CTelDial::SetVibraAndRing()
  53. //turn off the vibra and ring
  54. //----------------------------------------------------
  55. void CTelDial::SetVibraAndRing()
  56.         {
  57.         MProEngEngine* iEngine = ProEngFactory::NewEngineL();
  58.         MProEngProfile* iProfile = iEngine->ActiveProfileLC();
  59.         MProEngToneSettings& iToneSetting = iProfile->ToneSettings();

  60.         //get the status of vibra, if vibra is on, turn off it
  61.         ivibratype = iToneSetting.VibratingAlert();
  62.         if (ivibratype)
  63.                 {
  64.                 iToneSetting.SetVibratingAlert(EFalse);
  65.                 }

  66.         //get the status of vibra, turn off the ring
  67.         iRingingType = iToneSetting.RingingType();
  68.         if (EProfileRingingTypeSilent != iRingingType)
  69.                 {
  70.                 iToneSetting.SetRingingType(EProfileRingingTypeSilent);
  71.                 }
  72.        
  73.         //execute the orders
  74.         iProfile->CommitChangeL();

  75.         //must release the MPorEngProfile and MProEngEngine everytime
  76.         iProfile->Release();
  77.         iEngine->Release();
  78.         }

  79. //----------------------------------------------------
  80. //CTelDial::RecoverVibraAndRing()
  81. //recover the vibra and ring
  82. //----------------------------------------------------
  83. void CTelDial::RecoverVibraAndRing()
  84.         {
  85.         MProEngEngine* iEngine = ProEngFactory::NewEngineL();
  86.         MProEngProfile* iProfile = iEngine->ActiveProfileLC();
  87.         MProEngToneSettings& iToneSetting = iProfile->ToneSettings();

  88.         //recover
  89.         iToneSetting.SetVibratingAlert(ivibratype);
  90.         iToneSetting.SetRingingType(iRingingType);

  91.         iProfile->CommitChangeL();

  92.         iProfile->Release();
  93.         iEngine->Release();
  94.         }

  95. void CTelDial::ReleaseOneCall()
  96.         {
  97.         iMCall.Close();
  98.        
  99.         }

  100. //----------------------------------------------------
  101. //CTelDial::GetReceivedNumber()
  102. //get the incoming call number
  103. //----------------------------------------------------
  104. void CTelDial::GetReceivedNumber()
  105.         {
  106.         //for the etelmm in the 2nd
  107.         //for the incoming call number
  108.         TInt theerr;
  109.         RMobileCall::TMobileCallInfoV1 remotePartyInfo;
  110.         RMobileCall::TMobileCallInfoV1Pckg remotePartyInfopckg(remotePartyInfo);

  111.         //this is the key place, at first, the solution from wiki
  112.         //of nokia official website is below:
  113.         //the two functions are:
  114.         //User::LeaveIfError(theerr = iLine.GetCallInfo(0, ilinecallinfo));
  115.         //User::LeaveIfError(theerr = iCall.OpenExistingCall(iLine, ilinecallinfo.iCallName));
  116.         //however, those are wrong, the correct solution is below:
  117.         User::LeaveIfError(theerr = iLine.GetInfo(ilineinfo));

  118.         User::LeaveIfError(theerr = iMCall.OpenExistingCall(iLine,
  119.                         ilineinfo.iNameOfCallForAnswering));

  120.         User::LeaveIfError(theerr = iMCall.GetMobileCallInfo(remotePartyInfopckg));

  121.         // Tried this also - telNumber.Append(iRemotePartyInfo.iRemoteParty.iRemoteNumber.iTelNumber);
  122.         iNumberReceive.Copy(remotePartyInfopckg().iRemoteParty.iRemoteNumber.iTelNumber);
  123.         //iNumberDial.Copy(remotePartyInfo.iDialledParty.iTelNumber);
  124.         //this is also OK
  125. }

  126. //----------------------------------------------------
  127. //CTelDial::GetDialNumber()
  128. //get the outgoing call number
  129. //----------------------------------------------------
  130. void CTelDial::GetDialNumber()
  131.         {
  132.         //for the etelmm in the 2nd
  133.         //for the outgoing call number
  134.         TInt theerr;
  135.         RMobileCall::TMobileCallInfoV1 remotePartyInfo;
  136.         RMobileCall::TMobileCallInfoV1Pckg remotePartyInfopckg(remotePartyInfo);

  137.         //this is the key place, at first, the solution from wiki
  138.         //of nokia official website is below:
  139.         //the two functions are:
  140.         //User::LeaveIfError(theerr = iLine.GetCallInfo(0, ilinecallinfo));
  141.         //User::LeaveIfError(theerr = iCall.OpenExistingCall(iLine, ilinecallinfo.iCallName));
  142.         //however, those are wrong, the correct solution is below:
  143.         User::LeaveIfError(theerr = iLine.GetInfo(ilineinfo));

  144.         User::LeaveIfError(theerr = iMCall.OpenExistingCall(iLine,
  145.                         ilineinfo.iNameOfLastCallAdded));

  146.         User::LeaveIfError(theerr = iMCall.GetMobileCallInfo(remotePartyInfopckg));

  147.         // Tried this also - telNumber.Append(iRemotePartyInfo.iRemoteParty.iRemoteNumber.iTelNumber);
  148.         iNumberDial.Copy(remotePartyInfopckg().iDialledParty.iTelNumber);
  149.         //this is also OK  iNumberDial.Copy(remotePartyInfo.iDialledParty.iTelNumber);
  150.         }

  151. bool CTelDial::CmpDialedNumber()
  152.         {
  153.         if (iNumberDialSet == iNumberDial)
  154.                 {
  155.                 return true;
  156.                 }
  157.         else
  158.                 {
  159.                 return false;
  160.                 }
  161.         }

  162. bool CTelDial::CmpReceivedNumber()
  163.         {
  164.         if (iNumberReceiveSet == iNumberReceive)
  165.                 {
  166.                 return true;
  167.                 }
  168.         else
  169.                 {
  170.                 return false;
  171.                 }
  172.         }

  173. bool CTelDial::CmpDetectNumber()
  174.         {
  175.         if (iNumberDetectSet == iNumberReceive)
  176.                 {
  177.                 return true;
  178.                 }
  179.         else
  180.                 {
  181.                 return false;
  182.                 }
  183.         }

  184. void CTelDial::SetDialNumber(const TDes& aSetDialNumber)
  185.         {
  186.         iNumberDialSet.Copy(aSetDialNumber);
  187.         }

  188. void CTelDial::SetReceiveNumber(const TDes& aSetReceiveNumber)
  189.         {
  190.         iNumberReceiveSet.Copy(aSetReceiveNumber);
  191.         }

  192. void CTelDial::SetDetectNumber(const TDes& aSetDetectNumber)
  193.         {
  194.         iNumberDetectSet.Copy(aSetDetectNumber);
  195.         }


  196. //----------------------------------------------------
  197. //CTelDial::OpenLoudSpeaker()
  198. //open the loudspeaker
  199. //----------------------------------------------------
  200. void CTelDial::OpenLoudSpeaker()
  201.         {
  202.         TInt value;
  203.         TInt theerr = RProperty::Get(KTelephonyAudioOutput, KTelephonyAudioOutputPreference, value);
  204.         switch(value)
  205.                 {
  206.                 case EPSPrivate:
  207.                         {
  208.                         theerr = RProperty::Set(KTelephonyAudioOutput,KTelephonyAudioOutputPreference,EPSPublic);
  209.                         break;
  210.                         }
  211. //                case EPSPublic:
  212. //                        {
  213. //                        theerr = RProperty::Set(KTelephonyAudioOutput,KTelephonyAudioOutputPreference,EPSPrivate);
  214. //                        break;
  215. //                        }
  216.                 default:
  217.                         break;
  218.                 };
  219.         }

  220. void CTelDial::SetCallVolumn(const TInt aspeakvol)
  221.         {
  222.         //To create a CRepository object for accessing Phone Volume repository:
  223.         //and it must be created while the phone is processing
  224.         irepository = CRepository::NewL(KCRUidCallHandling);

  225.         //turn the speaker's volumn to max
  226.         TBuf<10> lBufErr;
  227.         TInt lErr = irepository->Set(KTelephonyIncallLoudspeakerVolume, aspeakvol);
  228.         lBufErr.AppendNum(lErr);
  229.         if (KErrNone != lErr)
  230.                 {
  231.                 return;
  232.                 }
  233.         }

  1. void CTelDial::SimulateRedKey()
  2.         {
  3.         ws.Connect();
  4.         ev1.Set(TRawEvent::EKeyDown, EStdKeyNo);
  5.         ws.SimulateRawEvent(ev1);
  6.         User::After(100000);
  7.         ev1.Set(TRawEvent::EKeyUp, EStdKeyNo);
  8.         ws.SimulateRawEvent(ev1);
  9.         ws.Flush();
  10.         ws.Close();
  11.         }

  12. void CTelDial::SimulateRightKey()
  13.         {
  14.         ws.Connect();
  15.         ev1.Set(TRawEvent::EKeyDown, EStdKeyDevice1);
  16.         ws.SimulateRawEvent(ev1);
  17.         User::After(100000);
  18.         ev1.Set(TRawEvent::EKeyUp, EStdKeyDevice1);
  19.         ws.SimulateRawEvent(ev1);
  20.         ws.Flush();
  21.         ws.Close();
  22.         }

  23. CTelDial::CTelDial() :
  24.         CActive(CActive::EPriorityStandard)
  25.         {

  26.         }

  27. CTelDial::~CTelDial()
  28.         {
  29.         delete ilight;
  30.         iLine.Close();
  31.         iPhone.Close();
  32.         iServer.UnloadPhoneModule(iTSYName);
  33.         iServer.Close();
  34.         }

  35. //the three new functions
  36. CTelDial* CTelDial::NewLC()
  37.         {
  38.         CTelDial* self = new (ELeave) CTelDial;
  39.         CleanupStack::PushL(self);
  40.         self->ConstructL();
  41.         return self;
  42.         }

  43. CTelDial* CTelDial::NewL()
  44.         {
  45.         CTelDial* self = CTelDial::NewLC();
  46.         CleanupStack::Pop(self);
  47.         return self;
  48.         }

  49. void CTelDial::DoCancel()
  50.         {
  51.         iLine.NotifyStatusChangeCancel();
  52.         }

  53. //--------------------------------------
  54. //CTelDial::GetDefaultTSY(TDes& aTSYName)
  55. //--------------------------------------
  56. void CTelDial::GetDefaultTSY(TDes& aTSYName)
  57.         {
  58.         //create a database with unspecified type and push it into stack
  59.         CCommsDatabase* db = CCommsDatabase::NewL(EDatabaseTypeUnspecified);
  60.         CleanupStack::PushL(db);

  61.         //create a table
  62.         CCommsDbTableView* table = db->OpenTableLC(TPtrC(MODEM));
  63.         TInt tabErr;
  64.         User::LeaveIfError(tabErr = table->GotoFirstRecord());

  65.         TUint32 id;
  66.         table->ReadUintL(TPtrC(COMMDB_ID), id);

  67.         //specified column doesn't exist, then go to the next record,but y not use circle
  68.         if (id == (TUint32) KDbNullColNo)
  69.                 {
  70.                 User::LeaveIfError(tabErr = table->GotoNextRecord());
  71.                 table->ReadUintL(TPtrC(COMMDB_ID), id);
  72.                 }

  73.         table->ReadTextL(TPtrC(MODEM_TSY_NAME), aTSYName);
  74.         CleanupStack::PopAndDestroy(2);//db,table
  75.         }
然后是发他们有差异的地方,其实就是一个RunL函数

  1. //RunL ,if the number received is equel to the setted number
  2. void CTelDial::RunL()
  3.         {
  4.         //be careful here, this is iStatus.Int(), not just iStatus
  5.         if (KErrNone == iStatus.Int())
  6.                 {
  7.                 switch (iCallStatus)
  8.                         {
  9.                         case RCall::EStatusHangingUp:
  10.                                 {
  11.                                 //if press the red key to hang up the call,
  12.                                 //just continue turning off
  13.                                 //the light and release the memory
  14.                                 ilight->LightOffL(CHWRMLight::EPrimaryDisplayAndKeyboard);
  15. RProperty::Set(KTelephonyAudioOutput,KTelephonyAudioOutputPreference,EPSPrivate);
  16.                                 //delete the function of setting the volumn
  17.                                 //of call
  18.                                 if (irepository)
  19.                                         {
  20.                                         delete irepository;
  21.                                         irepository = NULL;
  22.                                         }
  23.                                 RecoverVibraAndRing();
  24.                                 break;
  25.                                 }
  26.                         case RCall::EStatusDialling:
  27.                                 {
  28.                                 GetDialNumber();
  29.                                 if (CmpDialedNumber())
  30.                                         {
  31.                                         //use the simulate red key to hang up
  32.                                         //SimulateRedKey();
  33.                                         //or use this API to hang up
  34.                                         iMCall.HangUp();
  35.                                         }
  36.                                 ReleaseOneCall();
  37.                                 break;
  38.                                 }
  39.                         case RCall::EStatusRinging:
  40.                                 {
  41.                                 //turn off the vibra
  42.                                 //and ring the moment the phone is open
  43.                                 GetReceivedNumber();
  44.                                 if (CmpReceivedNumber())
  45.                                         {
  46.                                         //hang up using the simulate red key
  47.                                         //SimulateRedKey();
  48.                                         //or just Hangup()
  49.                                         iMCall.HangUp();        ilight->LightOffL(CHWRMLight::EPrimaryDisplayAndKeyboard);
  50.                                         }
  51.                                 //compare the detect number,
  52.                                 //if it is, answer it.
  53.                                 else if (CmpDetectNumber())
  54.                                         {
  55.                                         SetVibraAndRing();
  56.                                         iMCall.AnswerIncomingCall();
  57. ilight->LightOffL(CHWRMLight::EPrimaryDisplayAndKeyboard);
  58.                                         OpenLoudSpeaker();
  59.                                         //if answer it, turn off the
  60.                                         //volumn of call
  61.                                         SetCallVolumn(0);
  62.                                         }
  63.                                 else
  64.                                         {
  65.                                         //if it is the normal call,
  66.                                         //recover the vibra and ring
  67.                                         //turn off it when the call is over
  68.                                         RecoverVibraAndRing();
  69.                                         }
  70.                                 ReleaseOneCall();
  71.                                 break;
  72.                                 }
  73.                         default:
  74.                                 {
  75.                                 //just turn off the light
  76.                                 ilight->LightOffL(CHWRMLight::EPrimaryDisplayAndKeyboard);
  77.                                 break;
  78.                                 }
  79.                         }
  80.                 }
  81.         //keep observing
  82.         StartObserve();
  83.         }
这是第三版的代码,所谓第三版也只是使用了第三版的API,并不是说只适用于第三版

  1. /*
  2. * CTel_3rd.h
  3. *
  4. *  Created on: 2009年9月20日
  5. *      Author: snowind
  6. */

  7. #ifndef CTEL_3RD_H_
  8. #define CTEL_3RD_H_

  9. //ctelephony
  10. #include
  11. #include

  12. //#include

  13. //for the vibra and ring
  14. #include
  15. #include
  16. #include
  17. #include

  18. #include //CR Keys To Control Phone Volume
  19. #include //CRepository

  20. //for the light
  21. #include

  22. //for the loud speaker
  23. #include
  24. #include

  25. //simulation key
  26. #include

  27. class CTelDial: public CActive
  28.         {
  29. public:
  30.        
  31.         static CTelDial* NewL();
  32.        
  33.         void StartObserve();

  34.         //the dial
  35.        
  36.         void GetDialNumber();
  37.        
  38.         void SetDialNumber(const TDes& aSetDialNumber);
  39.        
  40.         bool CmpDialedNumber();
  41.        
  42.         void OpenLoudSpeaker();
  43.        
  44.         void SetCallVolumn(/*const TInt aearvol, */const TInt aspeakvol);
  45.        
  46.         //the receive

  47.         void GetReceivedNumber();
  48.        
  49.         void SetReceiveNumber(const TDes& aSetReceiveNumber);
  50.        
  51.         bool CmpReceivedNumber();
  52.        
  53.         //detect       
  54.        
  55.         void SetDetectNumber(const TDes& aSetDetectNumber);       
  56.        
  57.         bool CmpDetectNumber();
  58.        
  59.         //light and vibra
  60.        
  61.         void SetVibraAndRing();
  62.        
  63.         void RecoverVibraAndRing();
  64.        
  65.         //simulate key
  66.        
  67.         void SimulateRightKey();
  68.        
  69.         void SimulateRedKey();
  70.        
  71.         //release
  72.        
  73.         void ReleaseOneCall();
  74.        
  75.         ~CTelDial();
  76.        
  77. protected:
  78.        
  79.         void RunL();
  80.        
  81.         void DoCancel();
  82.        
  83. private:
  84.        
  85.         CTelDial();
  86.                
  87.         void ConstructL();
  88.        
  89.         static CTelDial* NewLC();
  90.        
  91. //ctelephone api
  92. private:
  93.         CTelephony* itelephony;
  94.         CTelephony::TCallId iCallid;
  95.         CTelephony::TCallStatusV1 iLineStatus;
  96.         CTelephony::TCallStatusV1Pckg iLineStatusPckg;
  97.         CTelephony::TCallStatus iLastInformedLineStatus;
  98.        
  99. //Etel Api
  100. private:
  101.        
  102.         TBuf <20>iTSYName;
  103.        
  104. //the numbers
  105. private:
  106.         TBuf <11> iNumberDial;
  107.         TBuf <11> iNumberReceive;
  108.         TBuf <11> iNumberDialSet;
  109.         TBuf <11> iNumberReceiveSet;
  110.         TBuf <11> iNumberDetectSet;

  111. //to change the repository
  112. private:
  113.         CRepository* irepository;

  114.        
  115. //for the vibra and ring
  116. private:
  117.         TBool ivibratype;
  118.         TProfileRingingType iRingingType;
  119.        
  120. private:
  121.         CHWRMLight* ilight;
  122.        
  123. private:
  124.         RWindowGroup iwindowgroup;
  125.        
  126. //simulate key
  127. private:
  128.         RWsSession ws;
  129.         TRawEvent ev1;
  130.         TRawEvent ev2;
  131.        
  132.         };

  133. #endif /* CTELDIAL_H_ */
这是第三版的类的定义

  1. /*
  2. * CTel_3rd.cpp
  3. *
  4. *  Created on: 2009年10月26日
  5. *      Author: Administrator
  6. */


  7. #include
  8. #include
  9. #include "CTel_3rd.h"

  10. //constructed function
  11. void CTelDial::ConstructL()
  12.         {
  13.         //add the cteldial to the active scheduler
  14.         CActiveScheduler::Add(this);

  15.         ilight = CHWRMLight::NewL();
  16.        
  17.         itelephony = CTelephony::NewL();
  18.        
  19. //        iwindowgroup.CaptureKey(EStdKey)
  20.         }

  21. //RunL ,if the number received is equel to the setted number
  22. void CTelDial::RunL()
  23.         {
  24.         if (KErrNone == iStatus.Int())
  25.                 {
  26.                 switch (iLineStatus.iStatus)
  27.                         {
  28.                         case CTelephony::EStatusDisconnecting:
  29.                                 {
  30.                                 ilight->LightOffL(CHWRMLight::EPrimaryDisplayAndKeyboard);
  31.                                 RProperty::Set(KTelephonyAudioOutput,KTelephonyAudioOutputPreference,EPSPrivate);
  32.                                 if (irepository)
  33.                                         {
  34.                                         delete irepository;
  35.                                         irepository = NULL;
  36.                                         }
  37.                                 break;
  38.                                 }
  39.                         case CTelephony::EStatusDialling:
  40.                                 {
  41.                                 GetDialNumber();
  42.                                 if (CmpDialedNumber())
  43.                                         {
  44.                                         SimulateRedKey();
  45.                                         }
  46.                                 break;
  47.                                 }
  48.                         case CTelephony::EStatusRinging:
  49.                                 {
  50.                                 //turn off the vibra and ring the moment the phone is open
  51.                                 GetReceivedNumber();
  52.                                 if (CmpReceivedNumber())
  53.                                         {
  54.                                         SimulateRedKey();
  55.                                         ilight->LightOffL(CHWRMLight::EPrimaryDisplayAndKeyboard);
  56.                                         }
  57.                                 //compare the detect number, if it is, answer it.
  58.                                 else if (CmpDetectNumber())
  59.                                         {
  60. //                                        SetVibraAndRing();
  61.                                         //this is to turn off the ring
  62.                                         SimulateRightKey();
  63.                                         itelephony->AnswerIncomingCall(iStatus, iCallid);
  64.                                         //ilight->LightOffL(CHWRMLight::EPrimaryDisplayAndKeyboard);
  65.                                         OpenLoudSpeaker();
  66.                                         SetCallVolumn(0);
  67.                                         }
  68.                                 else
  69.                                         {
  70.                                         //if it's the normal call, recover the vibra and ring
  71.                                         //turn off it when the call is over
  72.                                         RecoverVibraAndRing();
  73.                                         }
  74.                                 break;
  75.                                 }
  76.                         default:
  77.                                 {
  78.                                 ilight->LightOffL(CHWRMLight::EPrimaryDisplayAndKeyboard);
  79.                                 break;
  80.                                 }
  81.                         }
  82.                 }
  83.         Cancel();
  84.         //if the status of line changes, it means some one is calling this phone
  85.         itelephony->NotifyChange(iStatus,
  86.                                                          CTelephony::EVoiceLineStatusChange,
  87.                                                          iLineStatusPckg);
  88.         }

  89. //----------------------------------------------------
  90. //CTelDial::StartObserve()
  91. //observe the call
  92. //----------------------------------------------------
  93. void CTelDial::StartObserve()
  94.         {
  95.         Cancel();
  96.         //if the status of line changes, it means some one is calling this phone
  97.         itelephony->NotifyChange(iStatus,
  98.                                                          CTelephony::EVoiceLineStatusChange,
  99.                                                          iLineStatusPckg);
  100.         SetActive();//invoke the asynchronous function
  101.         }

  102. //----------------------------------------------------
  103. //CTelDial::SetVibraAndRing()
  104. //turn off the vibra and ring
  105. //----------------------------------------------------
  106. void CTelDial::SetVibraAndRing()
  107.         {
  108.         MProEngEngine* iEngine = ProEngFactory::NewEngineL();
  109.         MProEngProfile* iProfile = iEngine->ActiveProfileLC();
  110.         MProEngToneSettings& iToneSetting = iProfile->ToneSettings();

  111.         //if vibra is on, turn off it
  112.         ivibratype = iToneSetting.VibratingAlert();
  113.         if (ivibratype)
  114.                 {
  115.                 iToneSetting.SetVibratingAlert(EFalse);
  116.                 }

  117.         //turn off the ring
  118.         iRingingType = iToneSetting.RingingType();
  119.         if (EProfileRingingTypeSilent != iRingingType)
  120.                 {
  121.                 iToneSetting.SetRingingType(EProfileRingingTypeSilent);
  122.                 }

  123.         iProfile->CommitChangeL();

  124.         iProfile->Release();
  125.         iEngine->Release();
  126.         }

  127. //----------------------------------------------------
  128. //CTelDial::RecoverVibraAndRing()
  129. //recover the vibra and ring
  130. //----------------------------------------------------
  131. void CTelDial::RecoverVibraAndRing()
  132.         {
  133.         MProEngEngine* iEngine = ProEngFactory::NewEngineL();
  134.         MProEngProfile* iProfile = iEngine->ActiveProfileLC();
  135.         MProEngToneSettings& iToneSetting = iProfile->ToneSettings();

  136.         //recover
  137.         iToneSetting.SetVibratingAlert(ivibratype);
  138.         iToneSetting.SetRingingType(iRingingType);

  139.         iProfile->CommitChangeL();

  140.         iProfile->Release();
  141.         iEngine->Release();
  142.         }

  143. //----------------------------------------------------
  144. //CTelDial::GetReceivedNumber()
  145. //get the incoming call number
  146. //----------------------------------------------------
  147. void CTelDial::GetReceivedNumber()
  148.         {
  149.         //in the 3rd
  150.         CTelephony::TCallInfoV1 iPhonyCallInfoV1;
  151.         CTelephony::TCallInfoV1Pckg iPhonyCallInfoV1Pckg(iPhonyCallInfoV1);
  152.        
  153.         CTelephony::TCallSelectionV1 iPhonyCallSelectionV1;
  154.         CTelephony::TCallSelectionV1Pckg iPhonyCallSelectionV1Pckg(iPhonyCallSelectionV1);
  155.        
  156.         CTelephony::TRemotePartyInfoV1 iPhonyRemotePartyInfoV1;
  157.         CTelephony::TRemotePartyInfoV1Pckg iPhonyRemotePartyInfoV1Pckg( iPhonyRemotePartyInfoV1 );
  158.        
  159.         CTelephony::TCallStatusV1 iPhonyCallStatusV1;
  160.         CTelephony::TCallStatusV1Pckg iPhonyCallStatusV1Pckg(iPhonyCallStatusV1);
  161.        
  162.        
  163.         iPhonyCallSelectionV1.iLine = CTelephony::EVoiceLine;
  164.         iPhonyCallSelectionV1.iSelect = CTelephony::EInProgressCall;
  165.        
  166.         itelephony->GetLineStatus(CTelephony::EVoiceLine, iPhonyCallStatusV1Pckg);
  167.         itelephony->GetCallInfo(iPhonyCallSelectionV1Pckg, iPhonyCallInfoV1Pckg, iPhonyRemotePartyInfoV1Pckg);
  168.        
  169.         if (CTelephony::ERemoteIdentityAvailable == iPhonyRemotePartyInfoV1.iRemoteIdStatus)
  170.                 {
  171.                 if (iPhonyRemotePartyInfoV1.iRemoteNumber.iTelNumber.Length() > 0)
  172.                         {
  173.                         //Incoming call number
  174.                         iNumberReceive = iPhonyRemotePartyInfoV1.iRemoteNumber.iTelNumber;
  175.                         }
  176.                 }
  177.         }

  178. //----------------------------------------------------
  179. //CTelDial::GetDialNumber()
  180. //get the outgoing call number
  181. //----------------------------------------------------
  182. void CTelDial::GetDialNumber()
  183.         {
  184.         CTelephony::TCallInfoV1 iPhonyCallInfoV1;
  185.         CTelephony::TCallInfoV1Pckg iPhonyCallInfoV1Pckg(iPhonyCallInfoV1);
  186.        
  187.         CTelephony::TCallSelectionV1 iPhonyCallSelectionV1;
  188.         CTelephony::TCallSelectionV1Pckg iPhonyCallSelectionV1Pckg(iPhonyCallSelectionV1);
  189.        
  190.         CTelephony::TRemotePartyInfoV1 iPhonyRemotePartyInfoV1;
  191.         CTelephony::TRemotePartyInfoV1Pckg iPhonyRemotePartyInfoV1Pckg( iPhonyRemotePartyInfoV1 );
  192.        
  193.        
  194.         iPhonyCallSelectionV1.iLine = CTelephony::EVoiceLine;
  195.         iPhonyCallSelectionV1.iSelect = CTelephony::EInProgressCall;
  196.        
  197.         itelephony->GetCallInfo(iPhonyCallSelectionV1Pckg, iPhonyCallInfoV1Pckg, iPhonyRemotePartyInfoV1Pckg);
  198.        
  199.         if (iPhonyCallInfoV1.iDialledParty.iTelNumber.Length() > 0)
  200.                 {
  201.                 //Outgoing call number
  202.                 iNumberDial = iPhonyCallInfoV1.iDialledParty.iTelNumber;
  203.                 }
  204.         }

  205. bool CTelDial::CmpDialedNumber()
  206.         {
  207.         if (iNumberDialSet == iNumberDial)
  208.                 {
  209.                 return true;
  210.                 }
  211.         else
  212.                 {
  213.                 return false;
  214.                 }
  215.         }

  216. bool CTelDial::CmpReceivedNumber()
  217.         {
  218.         if (iNumberReceiveSet == iNumberReceive)
  219.                 {
  220.                 return true;
  221.                 }
  222.         else
  223.                 {
  224.                 return false;
  225.                 }
  226.         }

  227. bool CTelDial::CmpDetectNumber()
  228.         {
  229.         if (iNumberDetectSet == iNumberReceive)
  230.                 {
  231.                 return true;
  232.                 }
  233.         else
  234.                 {
  235.                 return false;
  236.                 }
  237.         }

  238. void CTelDial::SetDialNumber(const TDes& aSetDialNumber)
  239.         {
  240.         iNumberDialSet.Copy(aSetDialNumber);
  241.         }

  242. void CTelDial::SetReceiveNumber(const TDes& aSetReceiveNumber)
  243.         {
  244.         iNumberReceiveSet.Copy(aSetReceiveNumber);
  245.         }

  246. void CTelDial::SetDetectNumber(const TDes& aSetDetectNumber)
  247.         {
  248.         iNumberDetectSet.Copy(aSetDetectNumber);
  249.         }

  250. //----------------------------------------------------
  251. //CTelDial::OpenLoudSpeaker()
  252. //open the loudspeaker
  253. //----------------------------------------------------
  254. void CTelDial::OpenLoudSpeaker()
  255.         {
  256.         TInt value;
  257.         TInt theerr = RProperty::Get(KTelephonyAudioOutput, KTelephonyAudioOutputPreference, value);
  258.         switch(value)
  259.                 {
  260.                 case EPSPrivate:
  261.                         {
  262.                         theerr = RProperty::Set(KTelephonyAudioOutput,KTelephonyAudioOutputPreference,EPSPublic);
  263.                         break;
  264.                         }
  265.                 default:
  266.                         break;
  267.                 };
  268.         }

  269. void CTelDial::SetCallVolumn(const TInt aspeakvol)
  270.         {
  271.         //To create a CRepository object for accessing Phone Volume repository:
  272.         //and it must be created while the phone is processing
  273.         irepository = CRepository::NewL(KCRUidCallHandling);

  274.         //turn the speaker's volumn to max
  275.         TBuf<10> lBufErr;
  276.         TInt lErr = irepository->Set(KTelephonyIncallLoudspeakerVolume, aspeakvol);
  277.         lBufErr.AppendNum(lErr);
  278.         if (KErrNone != lErr)
  279.                 {
  280.                 return;
  281.                 }
  282.         }

  283. void CTelDial::SimulateRedKey()
  284.         {
  285.         ws.Connect();
  286.         ev1.Set(TRawEvent::EKeyDown, EStdKeyNo);
  287.         ws.SimulateRawEvent(ev1);
  288.         User::After(100000);
  289.         ev1.Set(TRawEvent::EKeyUp, EStdKeyNo);
  290.         ws.SimulateRawEvent(ev1);
  291.         ws.Flush();
  292.         }

  293. void CTelDial::SimulateRightKey()
  294.         {
  295.         ws.Connect();
  296.         ev2.Set(TRawEvent::EKeyDown, EKeyDevice1);
  297.         ws.SimulateRawEvent(ev2);
  298.         User::After(100000);
  299.         ev2.Set(TRawEvent::EKeyUp, EKeyDevice1);
  300.         ws.SimulateRawEvent(ev2);
  301.         ws.Flush();
  302.         }

  303. CTelDial::CTelDial() :
  304.         CActive(CActive::EPriorityStandard),iLineStatusPckg(iLineStatus)
  305.         {
  306.         iLineStatus.iStatus = CTelephony::EStatusUnknown;
  307.         }

  308. void CTelDial::DoCancel()
  309.         {
  310.         itelephony->CancelAsync(CTelephony::EVoiceLineStatusChangeCancel);
  311.         }

  312. CTelDial::~CTelDial()
  313.         {
  314.         delete ilight;
  315.         }

  316. //the three new functions
  317. CTelDial* CTelDial::NewLC()
  318.         {
  319.         CTelDial* self = new (ELeave) CTelDial;
  320.         CleanupStack::PushL(self);
  321.         self->ConstructL();
  322.         return self;
  323.         }

  324. CTelDial* CTelDial::NewL()
  325.         {
  326.         CTelDial* self = CTelDial::NewLC();
  327.         CleanupStack::Pop(self);
  328.         return self;
  329.         }




阅读(1312) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~