|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : ChatBt.h 00004 * Part of : Chat 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2005-2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 #ifndef CHATBT_H 00017 #define CHATBT_H 00018 00019 00020 #include <es_sock.h> 00021 #include <bt_sock.h> 00022 #include <BTextNotifiers.h> 00023 #include <BtSdp.h> 00024 #include "ChatBase.h" 00025 00026 // FORWARD DECLARATIONS 00027 class CChatServiceSearcher; 00028 class CChatServiceAdvertiser; 00029 class MLog; 00030 00031 /** 00032 * CChatBt 00033 * Connects and sends messages to a remote machine using bluetooth 00034 */ 00035 class CChatBt : public CChatBase 00036 { 00037 public: // Constructors and destructor 00038 00039 /** 00040 * NewL() 00041 * Construct a CChatBt 00042 * @param aLog the log to send output to 00043 * @return a pointer to the created instance of CChatBt 00044 */ 00045 static CChatBt* NewL( MLog& aLog ); 00046 00047 /** 00048 * NewLC() 00049 * Construct a CChatBt 00050 * @param aLog the log to send output to 00051 * @return a pointer to the created instance of CChatBt 00052 */ 00053 static CChatBt* NewLC( MLog& aLog ); 00054 00055 /** 00056 * ~CChatBt() 00057 * Destroy the object and release all memory objects. 00058 * Close any open sockets. 00059 */ 00060 virtual ~CChatBt(); 00061 00062 public: // New functions 00063 00064 00065 /** 00066 * ConnectL() 00067 * Connect to an available service on a remote machine 00068 */ 00069 void ConnectL(); 00070 00071 /** 00072 * DisconnectL() 00073 * Disconnect from remote machine 00074 */ 00075 void DisconnectL(); 00076 00077 /** 00078 * SendMessageL() 00079 * Sends a message to a service on a remote machine. 00080 * @param aText Text to send 00081 */ 00082 void SendMessageL( TDes& aText ); 00083 00084 /** 00085 * StartL() 00086 * Start server and waiting for connection. 00087 */ 00088 void StartL(); 00089 00090 /** 00091 * StopL() 00092 * Stop server. 00093 */ 00094 void StopL(); 00095 00096 protected: // from CActive 00097 00098 /** 00099 * DoCancel() 00100 * Cancel any outstanding requests 00101 */ 00102 void DoCancel(); 00103 00104 /** 00105 * RunL() 00106 * Respond to an event 00107 */ 00108 void RunL(); 00109 00110 private: // Functions from base classes 00111 00112 /** 00113 * ConnectToServerL 00114 * Connects to the service 00115 */ 00116 void ConnectToServerL(); 00117 00118 /** 00119 * DisonnectFromServerL() 00120 * Disconnects from the service 00121 */ 00122 void DisconnectFromServerL(); 00123 00124 /** 00125 * CChatBt() 00126 * Constructs this object 00127 * @param aLog the log to send output to 00128 */ 00129 CChatBt( MLog& aLog ); 00130 00131 /** 00132 * ConstructL() 00133 * Performs second phase construction of this object 00134 */ 00135 void ConstructL(); 00136 00137 private: // New functions 00138 00139 /** 00140 * RequestData() 00141 * Request data from the client, this object is notified 00142 * when data becomes available 00143 */ 00144 void RequestData(); 00145 00146 00147 /** 00148 * SetSecurityWithChannelL 00149 * Sets the security on the channel port 00150 * And returns the channel available. 00151 * @param aAuthentication is authentication used 00152 * @param aEncryption is encryption used 00153 * @param aAuthorisation is authorisation used 00154 * @param aDenied is denied used 00155 * @return an available channel 00156 */ 00157 void SetSecurityWithChannelL( TBool aAuthentication, 00158 TBool aEncryption, 00159 TBool aAuthorisation, 00160 TBool aDenied, 00161 TInt& aChannel ); 00162 00163 /** 00164 * SetSecurityOnChannelL() 00165 * Sets the security on the channel port 00166 * @param aAuthentication is authentication used 00167 * @param aEncryption is encryption used 00168 * @param aAuthorisation is authorisation used 00169 * @param aChannel used channel ID 00170 */ 00171 static void SetSecurityOnChannelL( TBool aAuthentication, 00172 TBool aEncryption, 00173 TBool aAuthorisation, 00174 TInt aChannel ); 00175 00176 private: // data 00177 00178 /** 00179 * iServiceSearcher searches for service this 00180 * client can connect to. 00181 * Owned by CChatBt 00182 */ 00183 CChatServiceSearcher* iServiceSearcher; 00184 00185 /** 00186 * iLog 00187 * the log to send output to 00188 */ 00189 MLog& iLog; 00190 00191 /** 00192 * iMessage a copy of the message to send 00193 * Owned by CChatBt 00194 */ 00195 HBufC8* iMessage; 00196 00197 /** 00198 * iSocketServer 00199 * a connection to the socket server 00200 */ 00201 RSocketServ iSocketServer; 00202 00203 /** 00204 * iSocket 00205 * a socket to connect with 00206 */ 00207 RSocket iSocket; 00208 00209 /** 00210 * iServiceClass 00211 * the service class UUID to search for 00212 */ 00213 TUUID iServiceClass; 00214 00215 /** 00216 * iBuffer 00217 * the buffer to read data to 00218 */ 00219 TBuf8<KChatTextBufLength> iBuffer; 00220 00221 /** 00222 * iAdvertiser used to advertise this service 00223 * Owned by CChatServer 00224 */ 00225 CChatServiceAdvertiser* iAdvertiser; 00226 00227 /** 00228 * iAcceptedSocket 00229 * the socket that connections are accepted to 00230 */ 00231 RSocket iAcceptedSocket; 00232 00233 /** 00234 * iLen 00235 * length of data read 00236 */ 00237 TSockXfrLength iLen; 00238 00239 /** 00240 * iActiveSocket 00241 * the active socket 00242 */ 00243 RSocket* iActiveSocket; 00244 00245 }; 00246 00247 #endif // CHATBT_H 00248 00249 // End of File
|
© Nokia 2006 |