00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __COBAIN_H
00026 #define __COBAIN_H
00027
00028 #include <e32base.h>
00029 #include <e32std.h>
00030 #include <flogger.h>
00031 #include <bt_sock.h>
00032
00033 #include "clientservercommon.h"
00034 #include "Log.h"
00035
00036
00037 class RCobainClientSession;
00038 class CBTDriver;
00039 class RCobainSocket;
00040 class MNetworkDriverListener;
00041 class CBTUtil;
00042
00043
00044 _LIT(KClientLogdir, "cobain");
00045 _LIT(KClientLogfile, "client.log");
00046
00053 class MSocketListener
00054 {
00055 public:
00062 virtual void Data(TDesC8 &aDataBuf, RCobainSocket *aSocket) = 0;
00063
00070 virtual void SocketDisconnected(RCobainSocket *aSocket) = 0;
00071
00078 virtual void SocketError(TInt aError, RCobainSocket *aSocket) = 0;
00079 };
00080
00081
00082 _LIT(KCobainSocketPanic, "RCobainSocket");
00083
00084 const TInt KErrCobainSocketBase = -22000;
00085 const TInt KErrCobainSocketNullSocketListener = KErrCobainSocketBase - 1;
00086 const TInt KErrCobainSocketClosed = KErrCobainSocketBase - 2;
00087
00095 class RCobainSocket : public CActive
00096 {
00097 public:
00104 IMPORT_C void SetSocketListener(MSocketListener *aSocketListener);
00105
00111 IMPORT_C void SendL(const TDesC8 *aBuffer);
00112
00119 IMPORT_C void Close(TBool aImmediately = EFalse);
00120
00124 IMPORT_C ~RCobainSocket();
00125
00126 private:
00127 RCobainSocket(RCobainClientSession &aSession, TInt aId);
00128 void RunL();
00129 void DoCancel();
00130 void Receive();
00131
00132
00133 TBool iIsClosed;
00134
00135
00136 TInt iId;
00137
00138
00139 RCobainClientSession &iSession;
00140
00141
00142 MSocketListener *iSocketListener;
00143
00144
00145 TBuf8<KRecvBufSize> iRecvBuf;
00146
00147 friend class CNetworkPeer;
00148 friend class RCobainClientSession;
00149 friend class CConnectionListener;
00150 };
00151
00159 class CNetworkPeer : public CBase
00160 {
00161 public:
00165 IMPORT_C ~CNetworkPeer();
00166
00170 IMPORT_C TDesC& GetDeviceName() const { return *iDeviceName; }
00171
00175 IMPORT_C TDesC8& GetDeviceAddress() const { return *iDeviceAddress; }
00176
00180 IMPORT_C TDesC& GetServiceName() const { return *iServiceName; }
00181
00185 IMPORT_C RCobainSocket* ConnectL();
00186
00190 IMPORT_C TProtocol GetProtocol() const { return iProtocol; }
00191
00192 TSglQueLink iLink;
00193
00194 private:
00195 CNetworkPeer(RCobainClientSession &aSession,
00196 TProtocol aProtocol);
00197
00198 static CNetworkPeer* NewL(RCobainClientSession &aSession,
00199 TProtocol aProtocol,
00200 TPeerData &aPeerData);
00201
00205 void ConstructL(TPeerData &aPeerData);
00206
00210 TDesC8* CopyPeerPropertiesL(TPeerData &aPeerData);
00211
00216 TDes8* GetPeerProperties() const { return iProtocolSpecificPeerData; }
00217
00221 void WritePeerData(TPeerData &aPeerData);
00222
00223
00224 TProtocol iProtocol;
00225
00226
00227 HBufC *iDeviceName;
00228
00229
00230 HBufC8 *iDeviceAddress;
00231
00232
00233 HBufC *iServiceName;
00234
00235
00236 RCobainClientSession &iSession;
00237
00238
00239 TDes8 *iProtocolSpecificPeerData;
00240
00241 friend class RCobainClientSession;
00242 friend class CPeerListPump;
00243 friend class CBTUtil;
00244 };
00245
00246 typedef RPointerArray<CNetworkPeer> TPeerList;
00247
00248 class MConnectionListener;
00249
00250
00251 const TInt KErrDriverBase = -17500;
00252 const TInt KErrDriverAlreadyListening = KErrDriverBase - 1;
00253 const TInt KErrDriverNotListening = KErrDriverBase - 2;
00254
00261 class MNetworkDriver
00262 {
00263 public:
00264 virtual ~MNetworkDriver() {};
00265
00282 virtual void DiscoverPeersL(TUint aServiceID,
00283 MNetworkDriverListener *aListener) = 0;
00284
00288 virtual void CancelPeerDiscovery() = 0;
00289
00295 virtual TProtocol GetProtocol() = 0;
00296
00313 virtual void ListenL(TUint aPort, MConnectionListener *aListener,
00314 TUint aExtraInfo = KRFCOMM) = 0;
00315
00321 virtual void StopListeningL() = 0;
00322 };
00323
00330 class MNetworkDriverListener
00331 {
00332 public:
00339 virtual void PeerListComplete(TPeerList *aPeerList) = 0;
00345 virtual void PeerListRetrievalFailed(TInt aError) = 0;
00346 };
00347
00354 class MConnectionListener
00355 {
00356 public:
00363 virtual void Accept(RCobainSocket *aSocket, MNetworkDriver *aDriver) = 0;
00364 };
00365
00372 class CCobainLayer : public CBase
00373 {
00374 public:
00375
00376 IMPORT_C static CCobainLayer * NewL();
00377 IMPORT_C void Shutdown();
00378 IMPORT_C MNetworkDriver * GetDriverL(TProtocol aDriverProtocol);
00379 IMPORT_C ~CCobainLayer();
00380
00381 private:
00382 CCobainLayer();
00383 void ConstructL();
00384
00385 RCobainClientSession *iClientSession;
00386 };
00387
00388 #endif