bluetoothcommsprofiles/btpan/panhelpersvr/panhelpercli.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <c32root.h>
       
    17 #include "panhelper.h"
       
    18 #include "panhelperdevicediscoverer.h"
       
    19 #include "panhelperremotesdp.h"
       
    20 
       
    21 using namespace PanHelper;
       
    22 
       
    23 /**
       
    24 @file
       
    25 @internalTechnology
       
    26 */
       
    27 
       
    28 
       
    29 //
       
    30 // PAN device roles list
       
    31 //
       
    32 
       
    33 EXPORT_C TPanDeviceRolesList::TPanDeviceRolesList()
       
    34 /**
       
    35 Set the initially supported set of roles to none
       
    36 */
       
    37 	{
       
    38 	iSupportedRoles = KPanDeviceRolesListNone;
       
    39 	}
       
    40 
       
    41 EXPORT_C TBool TPanDeviceRolesList::SupportsU() const
       
    42 /**
       
    43 Does the device support the PAN-U role?
       
    44 */
       
    45 	{
       
    46 	return((iSupportedRoles & KPanDeviceRolesListPanU) ? ETrue : EFalse);
       
    47 	}
       
    48 
       
    49 EXPORT_C TBool TPanDeviceRolesList::SupportsGn() const
       
    50 /**
       
    51 Does the device support the PAN-GN role?
       
    52 */
       
    53 	{
       
    54 	return((iSupportedRoles & KPanDeviceRolesListPanGn) ? ETrue : EFalse);
       
    55 	}
       
    56 
       
    57 EXPORT_C TBool TPanDeviceRolesList::SupportsNap() const
       
    58 /**
       
    59 Does the device support the PAN-NAP role?
       
    60 */
       
    61 	{
       
    62 	return((iSupportedRoles & KPanDeviceRolesListPanNap) ? ETrue : EFalse);
       
    63 	}
       
    64 	
       
    65 EXPORT_C void TPanDeviceRolesList::SetSupportsU()
       
    66 /**
       
    67 Indicate that the device supports PAN-U
       
    68 */
       
    69 	{
       
    70 	iSupportedRoles = iSupportedRoles | KPanDeviceRolesListPanU;
       
    71 	}
       
    72 
       
    73 EXPORT_C void TPanDeviceRolesList::SetSupportsU(TBool aSupportsU)
       
    74 /**
       
    75 Set whether the device supports PAN-U or not
       
    76 @param aSupportsU Indicate whether the device support PAN-U role or not
       
    77 */
       
    78 	{
       
    79 	if(aSupportsU)
       
    80 		{
       
    81 		SetSupportsU();
       
    82 		}
       
    83 	else
       
    84 		{
       
    85 		iSupportedRoles = iSupportedRoles & ~KPanDeviceRolesListPanU;	
       
    86 		}
       
    87 	}
       
    88 	
       
    89 EXPORT_C void TPanDeviceRolesList::SetSupportsGn()
       
    90 /**
       
    91 Indicate that the remote device supports PAN-GN
       
    92 */
       
    93 	{
       
    94 	iSupportedRoles = iSupportedRoles | KPanDeviceRolesListPanGn;
       
    95 	}
       
    96 
       
    97 EXPORT_C void TPanDeviceRolesList::SetSupportsGn(TBool aSupportsGn)
       
    98 /**
       
    99 Indicate that the remote device supports PAN-GN
       
   100 @param aSupportsGn Indicate whether the remote device support PAN-GN role or not
       
   101 */
       
   102 	{
       
   103 	if(aSupportsGn)
       
   104 		{
       
   105 		SetSupportsGn();
       
   106 		}
       
   107 	else
       
   108 		{
       
   109 		iSupportedRoles = iSupportedRoles & ~KPanDeviceRolesListPanGn;	
       
   110 		}
       
   111 	}
       
   112 
       
   113 EXPORT_C void TPanDeviceRolesList::SetSupportsNap()
       
   114 /**
       
   115 Indicate that the remote device supports PAN-NAP
       
   116 */
       
   117 	{
       
   118 	iSupportedRoles = iSupportedRoles | KPanDeviceRolesListPanNap;
       
   119 	}
       
   120 
       
   121 EXPORT_C void TPanDeviceRolesList::SetSupportsNap(TBool aSupportsNap)
       
   122 /**
       
   123 Indicate that the remote device supports PAN-NAP
       
   124 @param aSupportsNap Indicate whether the remote device support PAN-NAP role or not
       
   125 */
       
   126 	{
       
   127 	if(aSupportsNap)
       
   128 		{
       
   129 		SetSupportsNap();
       
   130 		}
       
   131 	else
       
   132 		{
       
   133 		iSupportedRoles = iSupportedRoles & ~KPanDeviceRolesListPanNap;	
       
   134 		}
       
   135 	}
       
   136 	
       
   137 EXPORT_C TBool TPanDeviceRolesList::IsSupported(TBluetoothPanRole aPanRole) const
       
   138 /**
       
   139 Checks whether the supplied role is supported
       
   140 @param aPanRole The role to check
       
   141 @return ETrue if the role is supported, else EFalse
       
   142 */
       
   143 	{
       
   144 	switch(aPanRole)
       
   145 		{
       
   146 		case EPanRoleU:
       
   147 			return(SupportsU());
       
   148 		case EPanRoleGn:
       
   149 			return(SupportsGn());
       
   150 		case EPanRoleNap:
       
   151 			return(SupportsNap());
       
   152 		default:
       
   153 			return EFalse;
       
   154 		}
       
   155 	}
       
   156 
       
   157 
       
   158 EXPORT_C TPanDeviceWorthTryingRolesList::TPanDeviceWorthTryingRolesList()
       
   159 /**
       
   160 Set the initial set of worth trying roles to all
       
   161 */
       
   162 	{
       
   163 	iWorthTryingRoles = KPanDeviceRolesListAll;
       
   164 	}
       
   165 
       
   166 
       
   167 EXPORT_C TBool TPanDeviceWorthTryingRolesList::IsWorthTryingU() const
       
   168 /**
       
   169 Is the PAN-U role worth trying?
       
   170 */
       
   171 	{
       
   172 	return((TBool)(iWorthTryingRoles & KPanDeviceRolesListPanU));
       
   173 	}
       
   174 
       
   175 EXPORT_C TBool TPanDeviceWorthTryingRolesList::IsWorthTryingGn() const
       
   176 /**
       
   177 Is the PAN-Gn role worth trying?
       
   178 */
       
   179 	{
       
   180 	return((TBool)(iWorthTryingRoles & KPanDeviceRolesListPanGn));
       
   181 	}
       
   182 
       
   183 EXPORT_C TBool TPanDeviceWorthTryingRolesList::IsWorthTryingNap() const
       
   184 /**
       
   185 Is the PAN-Nap role worth trying?
       
   186 */
       
   187 	{
       
   188 	return((TBool)(iWorthTryingRoles & KPanDeviceRolesListPanNap));
       
   189 	}
       
   190 	
       
   191 EXPORT_C void TPanDeviceWorthTryingRolesList::SetWorthTrying(TBluetoothPanRole aPanRole, TBool aWorthTrying)
       
   192 	{
       
   193 	switch(aPanRole)
       
   194 		{ 
       
   195 		case EPanRoleU:
       
   196 			SetWorthTryingU(aWorthTrying);
       
   197 			break;
       
   198 		case EPanRoleGn:
       
   199 			SetWorthTryingGn(aWorthTrying);
       
   200 			break;
       
   201 		case EPanRoleNap:
       
   202 			SetWorthTryingNap(aWorthTrying);
       
   203 			break;
       
   204 		}
       
   205 	}
       
   206 
       
   207 EXPORT_C void TPanDeviceWorthTryingRolesList::SetWorthTryingU()
       
   208 /**
       
   209 Set the PAN-U role to worth trying
       
   210 */
       
   211 	{
       
   212 	iWorthTryingRoles = iWorthTryingRoles | KPanDeviceRolesListPanU;
       
   213 	}
       
   214 
       
   215 EXPORT_C void TPanDeviceWorthTryingRolesList::SetWorthTryingU(TBool aWorthTryingU)
       
   216 /**
       
   217 Set whether we the PAN-U role is worth trying
       
   218 @param aWorthTryingU Indicate whether the PAN-U role is worth trying with the remote device
       
   219 */
       
   220 	{
       
   221 	if(aWorthTryingU)
       
   222 		{
       
   223 		SetWorthTryingU();
       
   224 		}
       
   225 	else
       
   226 		{
       
   227 		iWorthTryingRoles = iWorthTryingRoles & ~KPanDeviceRolesListPanU;	
       
   228 		}
       
   229 	}
       
   230 	
       
   231 EXPORT_C void TPanDeviceWorthTryingRolesList::SetWorthTryingGn()
       
   232 /**
       
   233 Set the PAN-Gn role to worth trying
       
   234 */
       
   235 	{
       
   236 	iWorthTryingRoles = iWorthTryingRoles | KPanDeviceRolesListPanGn;
       
   237 	}
       
   238 
       
   239 EXPORT_C void TPanDeviceWorthTryingRolesList::SetWorthTryingGn(TBool aWorthTryingGn)
       
   240 /**
       
   241 Set whether the PAN-Gn role is worth trying
       
   242 @param aWorthTryingGn Indicate whether or not the PAN-GN role is worth trying with the remote device
       
   243 */
       
   244 	{
       
   245 	if(aWorthTryingGn)
       
   246 		{
       
   247 		SetWorthTryingGn();
       
   248 		}
       
   249 	else
       
   250 		{
       
   251 		iWorthTryingRoles = iWorthTryingRoles & ~KPanDeviceRolesListPanGn;	
       
   252 		}
       
   253 	}
       
   254 
       
   255 EXPORT_C void TPanDeviceWorthTryingRolesList::SetWorthTryingNap()
       
   256 /**
       
   257 Set the PAN-Nap role to worth trying
       
   258 */
       
   259 	{
       
   260 	iWorthTryingRoles = iWorthTryingRoles | KPanDeviceRolesListPanNap;
       
   261 	}
       
   262 
       
   263 EXPORT_C void TPanDeviceWorthTryingRolesList::SetWorthTryingNap(TBool aWorthTryingNap)
       
   264 /**
       
   265 Set whether the PAN-Nap role is worth trying
       
   266 @param aWorthTryingNap Indicate whether or not the PAN-NAP role is worth trying with the remote device
       
   267 */
       
   268 	{
       
   269 	if(aWorthTryingNap)
       
   270 		{
       
   271 		SetWorthTryingNap();
       
   272 		}
       
   273 	else
       
   274 		{
       
   275 		iWorthTryingRoles = iWorthTryingRoles & ~KPanDeviceRolesListPanNap;	
       
   276 		}
       
   277 	}
       
   278 	
       
   279 EXPORT_C TBool TPanDeviceWorthTryingRolesList::IsWorthTryingARole(TBluetoothPanRole aPanRole) const
       
   280 /**
       
   281 Checks whether the supplied role is worth trying
       
   282 @param aPanRole The role to check
       
   283 @return ETrue if the role is worth trying, else ETrue (safer return for the use of this)
       
   284 */
       
   285 	{
       
   286 	TBool isWorthTryingRole = ETrue;
       
   287 
       
   288 	switch(aPanRole)
       
   289 		{
       
   290 		case EPanRoleU:
       
   291 			isWorthTryingRole = IsWorthTryingU();
       
   292 			break;
       
   293 		case EPanRoleGn:
       
   294 			isWorthTryingRole = IsWorthTryingGn();
       
   295 			break;
       
   296 		case EPanRoleNap:
       
   297 			isWorthTryingRole = IsWorthTryingNap();
       
   298 			break;
       
   299 		}
       
   300 	return(isWorthTryingRole);
       
   301 	}
       
   302 
       
   303 
       
   304 EXPORT_C void TPanDeviceWorthTryingRolesList::ResetWorthTryingRoles()
       
   305 /**
       
   306 Clear all the worth trying flag so all roles are worth trying now
       
   307 */
       
   308 	{
       
   309 	iWorthTryingRoles = KPanDeviceRolesListAll;
       
   310 	}
       
   311 	
       
   312 //
       
   313 // Remote SDP querier
       
   314 //
       
   315 
       
   316 EXPORT_C TInt RPanRemoteSdpQuerier::Open()
       
   317 /**
       
   318 Open a handle to the PAN remote SDP query service
       
   319 */
       
   320 	{
       
   321 	TRAPD(err, iSdpQuerier = CPanHelperRemoteSdpQuerier::NewL());
       
   322 	return err;
       
   323 	}
       
   324 	
       
   325 EXPORT_C void RPanRemoteSdpQuerier::Close()
       
   326 /**
       
   327 
       
   328 */
       
   329 	{
       
   330 	if(iSdpQuerier)
       
   331 		{
       
   332 		delete iSdpQuerier;
       
   333 		iSdpQuerier = NULL;
       
   334 		}
       
   335 	}
       
   336 	
       
   337 EXPORT_C TInt RPanRemoteSdpQuerier::Query(const TBTDevAddr& aAddr, TDes8& aSupportedRemoteRoles, TRequestStatus& aStatus)
       
   338 /**
       
   339 Query the given remote device to find out what roles it supports
       
   340 @param aAddr A descriptor-packaged Bluetooth device address of the device to query
       
   341 @param aSupportedRemoteRoles A descriptor-packaged remote role class.  On return, contains the roles that the remote device is advertising in SDP
       
   342 @param aStatus The TRequestStatus to be signalled on completion
       
   343 */
       
   344 	{
       
   345 	aStatus = KRequestPending;
       
   346 	TRAPD(err, iSdpQuerier->QueryL(aAddr, aSupportedRemoteRoles, aStatus));
       
   347 	return err;
       
   348 	}
       
   349 	
       
   350 EXPORT_C void RPanRemoteSdpQuerier::CancelQuery()
       
   351 /**
       
   352 Cancel the SDP query of the remote device
       
   353 */
       
   354 	{
       
   355 	iSdpQuerier->CancelQuery();
       
   356 	}
       
   357 	
       
   358 //
       
   359 // Remote device discovery
       
   360 //
       
   361 
       
   362 EXPORT_C TInt RPanRemoteDeviceDiscoverer::Open()
       
   363 /**
       
   364 
       
   365 */
       
   366 	{
       
   367 	TRAPD(rerr, iDeviceDiscoverer = CPanHelperDeviceDiscoverer::NewL());
       
   368 	return rerr;
       
   369 	}
       
   370 	
       
   371 EXPORT_C void RPanRemoteDeviceDiscoverer::Close()
       
   372 /**
       
   373 
       
   374 */
       
   375 	{
       
   376 	if(iDeviceDiscoverer)
       
   377 		{
       
   378 		delete iDeviceDiscoverer;
       
   379 		iDeviceDiscoverer = NULL;
       
   380 		}
       
   381 	}
       
   382 		
       
   383 EXPORT_C void RPanRemoteDeviceDiscoverer::FindDevice(TDesC& aDeviceAddrList, TDes8& aDeviceAddr, TRequestStatus& aStatus)
       
   384 /**
       
   385 Find a device from the supplied list of comma-seperated readable BT device addresses
       
   386 @param aDeviceAddrList A comma-separated list of BT dev addrs in readable format
       
   387 @param aDeviceAddr On return, contains a device address from the list that was found; if no devices
       
   388 are found then the method completes with an error code
       
   389 */
       
   390 	{
       
   391 	aStatus = KRequestPending;
       
   392 	iDeviceDiscoverer->FindDevice(aDeviceAddrList, aDeviceAddr, aStatus);
       
   393 	}
       
   394 	
       
   395 EXPORT_C void RPanRemoteDeviceDiscoverer::CancelFindDevice()
       
   396 /**
       
   397 
       
   398 */
       
   399 	{
       
   400 	iDeviceDiscoverer->CancelFindDevice();
       
   401 	}