00001 /* 00002 * networkpeer.cpp,v 1.14 2004/01/10 14:27:11 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 "cobain.h" 00026 #include "clientsession.h" 00027 #include "clientservercommon.h" 00028 00029 CNetworkPeer::CNetworkPeer(RCobainClientSession &aSession, 00030 TProtocol aProtocol) 00031 : iSession(aSession), 00032 iProtocol(aProtocol) 00033 { 00034 } 00035 00036 CNetworkPeer* CNetworkPeer::NewL(RCobainClientSession &aSession, 00037 TProtocol aProtocol, 00038 TPeerData &aPeerData) 00039 { 00040 CNetworkPeer *c = new CNetworkPeer(aSession, aProtocol); 00041 CleanupStack::PushL(c); 00042 c->ConstructL(aPeerData); 00043 CleanupStack::Pop(); // c 00044 00045 return c; 00046 } 00047 00048 void CNetworkPeer::ConstructL(TPeerData &aPeerData) 00049 { 00050 iDeviceName = aPeerData.iDeviceName.AllocL(); 00051 iDeviceAddress = aPeerData.iDeviceAddress.AllocL(); 00052 iServiceName = aPeerData.iServiceName.AllocL(); 00053 00054 // initialize protocol specific peer properties 00055 CopyPeerPropertiesL(aPeerData); 00056 } 00057 00058 TDesC8* CNetworkPeer::CopyPeerPropertiesL(TPeerData &aPeerData) 00059 { 00060 TBTPeerPropertiesBuf *btprops; 00061 00062 switch( iProtocol ) { 00063 case EBluetooth: 00064 btprops = new (ELeave) TBTPeerPropertiesBuf(); 00065 (*btprops) = aPeerData.p.iBtProperties; 00066 iProtocolSpecificPeerData = btprops; 00067 break; 00068 } 00069 00070 return NULL; 00071 } 00072 00073 void CNetworkPeer::WritePeerData(TPeerData &aPeerData) 00074 { 00075 aPeerData.iDeviceAddress.Copy(GetDeviceAddress()); 00076 aPeerData.iDeviceName.Copy(GetDeviceName()); 00077 00078 switch( iProtocol ) { 00079 case EBluetooth: 00080 Mem::Copy(&(aPeerData.p.iBtProperties), iProtocolSpecificPeerData->Ptr(), 00081 sizeof(TBTPeerProperties)); 00082 break; 00083 } 00084 } 00085 00086 // 00087 // public methods 00088 // 00089 00090 EXPORT_C CNetworkPeer::~CNetworkPeer() 00091 { 00092 delete iDeviceName; 00093 delete iDeviceAddress; 00094 delete iServiceName; 00095 delete iProtocolSpecificPeerData; 00096 } 00097 00098 EXPORT_C RCobainSocket* CNetworkPeer::ConnectL() 00099 { 00100 return iSession.ConnectSocketL(this); 00101 } 00102
1.3.5