00001 /* 00002 * concreteconnection.h,v 1.14 2003/11/20 07:52:21 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 __CONCRETE_CONNECTION_H 00026 #define __CONCRETE_CONNECTION_H 00027 00028 #include <e32base.h> 00029 #include <es_sock.h> 00030 00031 #include "serversession.h" 00032 00033 // forward declarations 00034 class CAsynchSend; 00035 class CAsynchReceive; 00036 class CAsynchListen; 00037 00048 class CConcreteConnection : public CBase 00049 { 00050 public: 00051 enum TConnectionFailure { 00052 ENoSocket = 67000, 00053 ESocketClosed, 00054 EBadMessage 00055 }; 00056 00057 enum TInitError { 00058 ENullSocket = 68000, 00059 ENullSocketServ 00060 }; 00061 00062 static CConcreteConnection * NewL(RSocket *aSocket, 00063 CServerSession &aSession); 00064 static CConcreteConnection * NewListeningL(RSocket *aSocket, 00065 RSocketServ *aSocketServ, 00066 CServerSession &aSession); 00067 00068 // void SetSession(CServerSession* aSession) { iSession = aSession; } 00069 CServerSession& GetSession() { return iSession; } 00070 ~CConcreteConnection(); 00071 00072 TBool IsListening() { return iIsListening; } 00073 00074 void ReceiveL(const RMessage &aMessage); 00075 void CancelReceive(); 00076 00083 void Close(TBool aImmediately = EFalse); 00084 00085 void SendL(TDesC8 *aBuf); 00086 void ListenL(const RMessage &aMessage); 00087 void CancelListen(); 00088 00089 private: 00090 CConcreteConnection(RSocket* aSocket, 00091 RSocketServ *aSocketServ, 00092 CServerSession &aSession); 00093 void ConstructL(TBool aIsListening); 00094 RSocket& GetSocket() { return *iSocket; } 00095 RSocketServ& GetSocketServ() { return *iSocketServ; } 00096 00097 // whether this connection is a listening connection 00098 TBool iIsListening; 00099 00100 // whether this connection has already been closed 00101 TBool iIsClosed; 00102 00103 // the session that owns this connection 00104 CServerSession &iSession; 00105 00106 // actual socket resources 00107 RSocket* iSocket; 00108 RSocketServ *iSocketServ; 00109 00110 // asynchronous send handler 00111 CAsynchSend *iSender; 00112 00113 // asynchronous listen handler 00114 CAsynchListen *iListener; 00115 00116 // asynchronous receive handler 00117 CAsynchReceive *iReceiver; 00118 00119 friend class CAsynchSend; 00120 friend class CAsynchListen; 00121 friend class CAsynchReceive; 00122 }; 00123 00124 #endif
1.3.5