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

driver.cpp

Go to the documentation of this file.
00001 /*
00002  * driver.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 "driver.h"
00026 #include "clientsession.h"
00027 
00028 CDriver::CDriver(RCobainClientSession &aClientSession,
00029                  TProtocol aProtocol)
00030     : iClientSession(aClientSession),
00031       iProtocol(aProtocol),
00032       iPeerListPump(aProtocol, aClientSession)
00033 {
00034 }
00035 
00036 CDriver::~CDriver()
00037 {
00038     // cancel possibly pending peer list retrieval
00039     iPeerListPump.Cancel();
00040 
00041     if( iConnectionListener != NULL ) {
00042         StopListeningL();
00043     }
00044 }
00045 
00046 void CDriver::ListenL(TUint aServiceID, MConnectionListener *aListener, TUint aExtraInfo)
00047 {
00048     // check there is no pending listen
00049     __ASSERT_ALWAYS(iConnectionListener == NULL, User::Leave(KErrDriverAlreadyListening));
00050 
00051     // validate aExtraInfo parameter
00052     switch( iProtocol ) {
00053         case EBluetooth:
00054             __ASSERT_ALWAYS((aExtraInfo == KRFCOMM) || (aExtraInfo == KL2CAP),
00055                             User::Leave(KErrArgument));
00056             break;
00057         default:
00058             User::Panic(KCobainClientPanic, KErrNotSupported);
00059             break;
00060     }
00061 
00062     // create connection listener
00063     iConnectionListener = new (ELeave) CConnectionListener(iClientSession, this);
00064 
00065     // synchronous call to start listening
00066     iClientSession.StartListeningL(iProtocol, aServiceID, aExtraInfo);
00067         
00068     // launch connection listening active object
00069     iConnectionListener->Listen(aListener);
00070 }
00071 
00072 void CDriver::StopListeningL()
00073 {
00074     // check there is a pending listen
00075     __ASSERT_ALWAYS(iConnectionListener != NULL, User::Leave(KErrDriverNotListening));
00076 
00077     // cancel pending listen operation (will call server to cancel serverside)
00078     iConnectionListener->Cancel();
00079 
00080     delete iConnectionListener;
00081     iConnectionListener;
00082 
00083     // no more connections will be received
00084     iListener = NULL;
00085 }
00086 
00087 void CDriver::DiscoverPeersL(TUint aServiceClassID, MNetworkDriverListener *aListener)
00088 {
00089     iPeerListPump.DiscoverPeers(aServiceClassID, aListener);
00090 }
00091 
00092 void CDriver::CancelPeerDiscovery()
00093 {
00094     iPeerListPump.Cancel();
00095 }
00096 

Generated on Tue Jan 13 15:47:07 2004 for CobainAPIImplementation by doxygen 1.3.5