在C++下實現的程式撥號代碼

來源:互聯網
上載者:User

 

呵呵,下面是一段撥號代碼(摘自Nokia的例子),代碼雖然不多,但很多地方都值得學習,例如:對R類的使用,清理;server/client機制;參數傳遞機制;編碼風格;注釋風格等等自己體會吧。

 在閱讀代碼之前請熟悉Symbian OS C++中的ETel結構,以及它的核心類RTelServer,RPhone,RLine,RCall.

下面是代碼內容:

 void DialNumberL(const TDesC& aPhoneNumber)

{

//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
 TBuf <100> newCallName;
 RCall call;
 CleanupClosePushL(call);
 User::LeaveIfError(call.OpenNewCall(line, newCallName));

 //newCallName will now contain the name of the call
 User::LeaveIfError(call.Dial(aPhoneNumber));

 //Close the phone, line and call connections and remove them from the cleanup stack
 //NOTE: This does not hang up the call
 CleanupStack::PopAndDestroy(3);//phone, line, call

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

 //Close the connection to the tel server and remove it from the cleanup stack
 CleanupStack::PopAndDestroy(&server);
 }   //

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.