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
00032 #include "clientservercommon.h"
00033
00034
00035 class RCobainClientSession;
00036 class CBTDriver;
00037 class RCobainSocket;
00038 class MNetworkDriverListener;
00039
00040
00041 _LIT(KClientLogdir, "cobain");
00042 _LIT(KClientLogfile, "client.log");
00043
00050 class MSocketListener
00051 {
00052 public:
00059 virtual void Data(TDesC8 &aDataBuf, RCobainSocket *aSocket) = 0;
00060
00067 virtual void SocketDisconnected(RCobainSocket *aSocket) = 0;
00068
00075 virtual void SocketError(TInt aError, RCobainSocket *aSocket) = 0;
00076 };
00077
00078
00079 _LIT(KCobainSocketPanic, "RCobainSocket");
00080
00081 const TInt KErrCobainSocketBase = -22000;
00082 const TInt KErrCobainSocketNullSocketListener = KErrCobainSocketBase - 1;
00083 const TInt KErrCobainSocketClosed = KErrCobainSocketBase - 2;
00084
00092 class RCobainSocket : public CActive
00093 {
00094 public:
00101 IMPORT_C void SetSocketListener(MSocketListener *aSocketListener);
00102
00108 IMPORT_C void SendL(const TDesC8 *aBuffer);
00109
00116 IMPORT_C void Close(TBool aImmediately = EFalse);
00117
00121 IMPORT_C ~RCobainSocket();
00122
00123 private:
00124 RCobainSocket(RCobainClientSession &aSession, TInt aId);
00125 void RunL();
00126 void DoCancel();
00127 void Receive();
00128
00129
00130 TBool iIsClosed;
00131
00132
00133 TInt iId;
00134
00135
00136 RCobainClientSession &iSession;
00137
00138
00139 MSocketListener *iSocketListener;
00140
00141
00142 TBuf8<KRecvBufSize> iRecvBuf;
00143
00144 friend class CNetworkPeer;
00145 friend class RCobainClientSession;
00146 friend class CConnectionListener;
00147 };
00148
00156 class CNetworkPeer : public CBase
00157 {
00158 public:
00162 IMPORT_C ~CNetworkPeer();
00163
00167 IMPORT_C TDesC& GetDeviceName() { return *iDeviceName; }
00168
00172 IMPORT_C TDesC8& GetDeviceAddress() { return *iDeviceAddress; }
00173
00177 IMPORT_C TDesC8& GetServiceID() { return *iServiceID; }
00178
00182 IMPORT_C TUint GetPort() { return iPort; }
00183
00187 IMPORT_C RCobainSocket* ConnectL();
00188
00192 IMPORT_C TProtocol GetProtocol() { return iProtocol; }
00193
00194 TSglQueLink iLink;
00195
00196 private:
00197 CNetworkPeer(RCobainClientSession &aSession,
00198 TProtocol aProtocol,
00199 TUint aPort);
00200
00201 static CNetworkPeer* NewL(RCobainClientSession &aSession,
00202 TProtocol aProtocol,
00203 TDesC &aDeviceName,
00204 TDesC8 &aDeviceAddress,
00205 TDesC8 &aServiceID,
00206 TUint aPort);
00207 void ConstructL(TDesC &aDeviceName,
00208 TDesC8 &aDeviceAddress,
00209 TDesC8 &aServiceID);
00210
00211
00212 TProtocol iProtocol;
00213
00214
00215 TDesC *iDeviceName;
00216
00217
00218 TDesC8 *iServiceID;
00219
00220
00221 TDesC8 *iDeviceAddress;
00222
00223
00224 TUint iPort;
00225
00226
00227 RCobainClientSession &iSession;
00228
00229 friend class RCobainClientSession;
00230 friend class CPeerListPump;
00231 };
00232
00233 typedef RPointerArray<CNetworkPeer> TPeerList;
00234
00235 class MConnectionListener;
00236
00237
00238 const TInt KErrDriverBase = -17500;
00239 const TInt KErrDriverAlreadyListening = KErrDriverBase - 1;
00240 const TInt KErrDriverNotListening = KErrDriverBase - 2;
00241
00248 class MNetworkDriver
00249 {
00250 public:
00251 virtual ~MNetworkDriver() {};
00252
00261 virtual TPeerList* GetPeersL(TUint aPort) = 0;
00262
00272 virtual void DiscoverPeersL(TUint aPort, MNetworkDriverListener *aListener) = 0;
00273
00277 virtual void CancelPeerDiscovery() = 0;
00278
00284 virtual TProtocol GetProtocol() = 0;
00285
00295 virtual void ListenL(TUint aPort, MConnectionListener *aListener) = 0;
00296
00302 virtual void StopListeningL() = 0;
00303 };
00304
00311 class MNetworkDriverListener
00312 {
00313 public:
00320 virtual void PeerListComplete(TPeerList *aPeerList) = 0;
00326 virtual void PeerListRetrievalFailed(TInt aError) = 0;
00327 };
00328
00335 class MConnectionListener
00336 {
00337 public:
00344 virtual void Accept(RCobainSocket *aSocket, MNetworkDriver *aDriver) = 0;
00345 };
00346
00353 class CCobainLayer : public CBase
00354 {
00355 public:
00356
00357 IMPORT_C static CCobainLayer * NewL();
00358 IMPORT_C void Shutdown();
00359 IMPORT_C MNetworkDriver * GetDriverL(TProtocol aDriverProtocol);
00360 IMPORT_C ~CCobainLayer();
00361
00362
00363 IMPORT_C static void Log(const TDesC &aMessage,
00364 TFileLoggingMode aMode = EFileLoggingModeAppend);
00365
00366 private:
00367 CCobainLayer();
00368 void ConstructL();
00369
00370 RCobainClientSession *iClientSession;
00371 };
00372
00373 #endif