00001 /* 00002 * ConnectionListener.cpp,v 1.3 2004/01/06 19:43:01 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 #include "ConnectionListener.h" 00026 #include "clientsession.h" 00027 00028 // 00029 // the listen process is as follows: 00030 // 00031 // 1. user calls driver->Listen() 00032 // 2. driver launches con listener AO 00033 // 3. AO waits asynchronously for notification about available 00034 // incoming connection 00035 // 4. when there is a new inbound connection, the server completes the 00036 // existing call with the id of the new connection 00037 // 00038 00039 CConnectionListener::CConnectionListener(RCobainClientSession &aClientSession, 00040 MNetworkDriver *aDriver) 00041 : CActive(CActive::EPriorityStandard), 00042 iClientSession(aClientSession), 00043 iDriver(aDriver) 00044 { 00045 CActiveScheduler::Add(this); 00046 } 00047 00048 CConnectionListener::~CConnectionListener() 00049 { 00050 Cancel(); 00051 Deque(); 00052 } 00053 00054 // actual call to start listening for a connection 00055 void CConnectionListener::DoListen() 00056 { 00057 // asynchronous call that is completed when there is a new 00058 // inbound connection available on the server 00059 iClientSession.GetIncomingSocketL(iStatus); 00060 00061 // start waiting 00062 SetActive(); 00063 } 00064 00065 void CConnectionListener::Listen(MConnectionListener *aListener) 00066 { 00067 // register application callback 00068 iConnectionListener = aListener; 00069 00070 DoListen(); 00071 } 00072 00073 void CConnectionListener::RunL() 00074 { 00075 // get the socket id from the request status of the completed call 00076 TInt id = iStatus.Int(); 00077 00078 // check for error 00079 if( id < 0 ) { 00080 //##TODO## need to do something 00081 Cancel(); 00082 return; 00083 } 00084 00085 // construct a socket object and return it 00086 RCobainSocket *socket = new (ELeave) RCobainSocket(iClientSession, id); 00087 00088 // call application callback 00089 iConnectionListener->Accept(socket, iDriver); 00090 00091 // start listening for the next connection 00092 DoListen(); 00093 } 00094 00095 void CConnectionListener::DoCancel() 00096 { 00097 // call server to stop listening 00098 iClientSession.StopListening(EBluetooth, 0); 00099 }
1.3.5