(转)APN symbian手机上的接入点编程 二

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.

原文地址:https://www.cnblogs.com/yaoliang11/p/1795714.html