Main Page | Class Hierarchy | Data Structures | File List | Data Fields | Globals

cobain.h

Go to the documentation of this file.
00001 /*
00002  * cobain.h,v 1.36 2003/11/25 19:29:55 mattid Exp
00003  *
00004  * COBAIN - Communications API for EPOC Environments
00005  * Copyright (C) 2002-2003 Matti Dahlbom, Matti Kokkola
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * Contact: Matti Dahlbom <matti@777-team.org>
00022  *          Matti Kokkola <matti.kokkola@iki.fi>
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 // forward declarations
00035 class RCobainClientSession;
00036 class CBTDriver;
00037 class RCobainSocket;
00038 class MNetworkDriverListener;
00039 
00040 // file logging info
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 // RCobainSocket's panic category and error codes
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         // whether this socket has been closed
00130         TBool iIsClosed;
00131 
00132         // socket id
00133         TInt iId;
00134 
00135         // reference to the client session
00136         RCobainClientSession &iSession;
00137 
00138         // the socket listener
00139         MSocketListener *iSocketListener;
00140 
00141         // receive buffer
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; // for use in a linked list
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         // peer's protocol (type)
00212         TProtocol iProtocol;
00213 
00214         // name of the peer's device
00215         TDesC *iDeviceName;
00216 
00217         // service id of the peer service
00218         TDesC8 *iServiceID;
00219 
00220         // address of the peer's device (protocol dependent)
00221         TDesC8 *iDeviceAddress;
00222 
00223         // port of the peer (protocol dependent)
00224         TUint iPort;
00225 
00226         // reference to session
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 // MNetworkDriver error codes
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         //##TODO## document us!
00357         IMPORT_C static CCobainLayer * NewL();
00358         IMPORT_C void Shutdown();
00359         IMPORT_C MNetworkDriver * GetDriverL(TProtocol aDriverProtocol);
00360         IMPORT_C ~CCobainLayer();
00361 
00362         //##TODO## remove
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

Generated on Mon Dec 8 10:26:06 2003 for CobainAPIImplementation by doxygen 1.3.5