class RConnection : public RCommsSubSession;
1. Overview: The management interface for a network connection or subconnection. Provides clients with the following functionality:
- Opening and closing the connection
- Starting a connection, which means associating it with a new underlying interface
- Attaching the RConnection instance to an existing interface
- Stopping the connection, which means disassociating it from the underlying interface
- Obtaining progress information and notification during connection start-up
- Notifying when subconnections come up and go down
- Notifying when there is a service change for the connection
- Notifying when a given amount of data has been sent or received on a connection or subconnection
- Reading CommDB fields specific to an active connection
- ......
Note that several of the new functions are asynchronous. It is essential for these calls that the client ensures that the parameters they pass to the RConnection API remain in scope for the duration of the asynchronous call.
這個類就如同RFile一樣,在你開啟一個檔案的使用的,你的首先用RFs,然後在用RFile,這裡也是一樣的道理,你首先的用RSsocketServ去建立一個Session,然後用RConncetion來開啟這個session被你所用。API也是對應的,open/close, start(attach)/stop等等。
2. Methods
- IMPORT_C TInt Open(RSocketServ &aSocketServer, TUint aConnectionType=KConnectionTypeDefault);
- Opens a new RConnection instance.
開啟一個Socket server的串連。
- IMPORT_C void Start(TRequestStatus &aStatus)
- Starts a connection asynchronously using the existing connection preferences in CommDb.
- Note that this may or may not result in a dialog prompt, depending on the connection preference settings.
- IMPORT_C void Start(TConnPref &aPref, TRequestStatus &aStatus);
- Starts a connection asynchronously by overriding connection preference settings in CommDb.
- The settings which can be overridden are: IAP Id, Network Id, Dialog Preference, Direction, Bearer Set.
- IMPORT_C TInt Start();
- Starts a connection synchronously using the connection preference settings in CommDb.
- There is no overriding of settings (such as IAP Id, Network Id, Dialog Preference, Direction, Bearer Set).
- This may or may not result in a dialog prompt, depending on the connection preference settings.
- IMPORT_C TInt Start(TConnPref &aPref);
- Starts a connection synchronously by overriding connection preference settings in CommDb.
- The settings which can be overridden are: IAP Id, Network Id, Dialog Preference, Direction, Bearer Set.
start()有四個重載的方法,按同步和非同步分類或是按用CommDb中存在的connection preference還是按照自己設定的分類。第一個是非同步,使用CommDb中存在的connection preference來串連,所以他不保證能夠彈出對話方塊來。第二個也是非同步,但是他覆蓋了CommDb中的connection preference的部分或是全部參數(可以設定的參數有5個:IAP Id, Network Id, Dialog Preference, Direction, Bearer Set;對應的類是Class TCommDbConnPref,其方法是:SetBearerSet(), SetDialogPreference(), SetDirection(), SetIapId(), SetNetId() 各種取值的範圍參考SDK)。如果我們想同步選擇的話就可以用第三個,其傳回值表明串連是否成功,依然是用CommDb中存在的connection preference來串連,不保證能夠彈出對話方塊來。第四個就是用自己設定的connection preference來串連的同步版本。所以方法是很周全的,根據自己的要求來選擇。主要考慮是不是彈出對話方塊,還是slient的進行串連,是否自己有特殊的連結屬性設定等等。
- IMPORT_C TInt Stop();
- Stops the entire connection by disconnecting the underlying network interface immediately, regardless of whether other clients are using it or not.
- IMPORT_C TInt GetIntSetting(const TDesC &aSettingName, TUint32 &aValue);
- Pre-Condition An attached connection: as a result of performing either a Start() or an Attach()
- Reads current CommDb settings for the active connection.
- const TDesC &aSettingName The CommDb table name and field name to be accessed. Of the form "<table name>\<field name>" (for example "IAP\Id" or "ModemBearer\PortName").
- TUint32 &aValue On return, the value of the table/field pair.
- IMPORT_C TInt GetDesSetting(const TDesC &aSettingName, TDes8 &aValue);
- IMPORT_C TInt GetDesSetting(const TDesC &aSettingName, TDes16 &aValue);
在我們調用的start之後,使用者選擇了存取點,我們就可以用上面的API來取得使用者所選擇的存取點的資訊,可以是所選存取點的索引或是8/16位的名稱。因為在start之前,我們可以設定IAP Id,這裡用的是一個索引,所以一般我們用第一個API。
- IMPORT_C void ProgressNotification(TNifProgressBuf &aProgress, TRequestStatus &aStatus, TUint aSelectedProgress=KConnProgressDefault);
- TNifProgressBuf &aProgress - A buffer to receive progress notification.
- Requests asynchronous progress notification for the connection.
aProgress.iStage參數可以告訴我們現在的串連狀態:KConnectionOpen, KConnectionClosed, KLinkLayerOpen, KLinkLayerClosed, KConnectionFailure等等(nifvar.h檔案中)
- IMPORT_C void Close();
- Closes the connection.
- The connection will not be dropped immediately: it will be dropped when there is no more data traffic on the connection. So if a client needs to graciously shutdown the connection, Close(), not Stop(), needs to be used after shutting down the socket.