Main Page | Data Structures | File List | Data Fields

cobain.h

00001 /*
00002  * cobain.h,v 1.40 2004/01/08 13:20:21 mattid Exp
00003  *
00004  * COBAIN - Communications API for EPOC Environments
00005  * Copyright (C) 2002-2004 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 #include <bt_sock.h> // for KRFCOMM / KL2CAP constants
00032 
00033 #include "clientservercommon.h"
00034 #include "Log.h" // offer logging for API client
00035 
00036 // forward declarations
00037 class RCobainClientSession;
00038 class CBTDriver;
00039 class RCobainSocket;
00040 class MNetworkDriverListener;
00041 class CBTUtil;
00042 
00043 // file logging info
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 // RCobainSocket's panic category and error codes
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         // whether this socket has been closed
00133         TBool iIsClosed;
00134 
00135         // socket id
00136         TInt iId;
00137 
00138         // reference to the client session
00139         RCobainClientSession &iSession;
00140 
00141         // the socket listener
00142         MSocketListener *iSocketListener;
00143 
00144         // receive buffer
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; // for use in a linked list
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         // peer's protocol (type)
00224         TProtocol iProtocol;
00225 
00226         // name of the peer's device
00227         HBufC *iDeviceName;
00228 
00229         // address of the peer's device (protocol dependent)
00230         HBufC8 *iDeviceAddress;
00231 
00232         // name of the service
00233         HBufC *iServiceName;
00234 
00235         // reference to session
00236         RCobainClientSession &iSession;
00237 
00238         // protocol specific peer data 
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 // MNetworkDriver error codes
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         //##TODO## document us!
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

Generated on Tue Jan 13 15:42:05 2004 for CobainAPI by doxygen 1.3.5