bluetooth/btexample/example/codsetter/CodSetter.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2005-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 <e32base.h>
       
    17 #include <e32std.h>
       
    18 #include <e32test.h>
       
    19 #include <bt_subscribe.h>
       
    20 #include <bt_sock.h>
       
    21 #include "CodSetter.h"
       
    22 
       
    23 _LIT(KInstructions, "O - ObjectTransfer\nP = Positioning\nN - Networking\nC - Capturing\nA - Audio\nT - Telephony\nI - Information\nR - Rendering\n");
       
    24 
       
    25 GLDEF_D RTest test(_L("Cod Setter App"));
       
    26 
       
    27 void TestL()
       
    28 	{
       
    29 	test.Printf(_L("%S\n"), &KInstructions);
       
    30 
       
    31 	CCodSetter* codsetter = CCodSetter::NewL(test);
       
    32 
       
    33 	CActiveScheduler::Start();
       
    34 
       
    35 	delete codsetter;
       
    36 	}
       
    37 
       
    38 
       
    39 CCodSetter* CCodSetter::NewL(RTest& aTest)
       
    40 	{
       
    41 	CCodSetter* s = new(ELeave) CCodSetter(aTest);
       
    42 	CleanupStack::PushL(s);
       
    43 	s->ConstructL();
       
    44 	CleanupStack::Pop(s);
       
    45 	return s;
       
    46 	}
       
    47 
       
    48 CCodSetter::CCodSetter(RTest& aTest)
       
    49 : CActive(EPriorityStandard), iTest(aTest)
       
    50 	{
       
    51 	CActiveScheduler::Add(this);
       
    52 	}
       
    53 
       
    54 CCodSetter::~CCodSetter()
       
    55 	{
       
    56 	Cancel();
       
    57 	}
       
    58 
       
    59 void CCodSetter::ConstructL()
       
    60 	{
       
    61 	TInt err;
       
    62 	
       
    63 
       
    64 _LIT_SECURITY_POLICY_PASS(KPassPolicy);
       
    65 	err=iProperty.Define(KPropertyUidBluetoothCategory,
       
    66 							KPropertyKeyBluetoothSetDeviceClass,
       
    67 							RProperty::EInt,
       
    68 							KPassPolicy,		//	Read policy
       
    69 							KPassPolicy);		//	Write policy
       
    70 	
       
    71 	if (err) test.Printf(_L("Error %d defining property, continuing anyway\n"),err);
       
    72 	Start();
       
    73 	}
       
    74 
       
    75 void CCodSetter::Start()
       
    76 	{
       
    77 	iTest.Console()->Read(iStatus);
       
    78 	SetActive();
       
    79 	}
       
    80 
       
    81 void CCodSetter::RunL()
       
    82 	{
       
    83 	Start();
       
    84 	
       
    85 	TChar ch = iTest.Console()->KeyCode();
       
    86 
       
    87 	TUint16 bit = 0;
       
    88 
       
    89 	switch (ch)
       
    90 		{
       
    91 		case 'i': case 'I':
       
    92 			bit = EMajorServiceInformation;
       
    93 			break;
       
    94 
       
    95 		case 'p': case 'P':
       
    96 			bit = EMajorServicePositioning;
       
    97 			break;
       
    98 
       
    99 		case 'o': case 'O':
       
   100 			bit = EMajorServiceObjectTransfer;
       
   101 			break;
       
   102 
       
   103 		case 'n': case 'N':
       
   104 			bit = EMajorServiceNetworking;
       
   105 			break;
       
   106 
       
   107 		case 'c': case 'C':
       
   108 			bit = EMajorServiceCapturing;
       
   109 			break;
       
   110 
       
   111 		case 'r': case 'R':
       
   112 			bit = EMajorServiceRendering;
       
   113 			break;
       
   114 
       
   115 		case 't': case 'T':
       
   116 			bit = EMajorServiceTelephony;
       
   117 			break;
       
   118 
       
   119 		default:
       
   120 			break; // do nothing
       
   121 		}
       
   122 
       
   123 	TUint16 s = iServiceClassToSet;
       
   124 	s ^= bit;
       
   125 	TBTDeviceClass cod(s,KMajorDeviceClass,KMinorDeviceClass);
       
   126 
       
   127 	iProperty.Set(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetDeviceClass, cod.DeviceClass());
       
   128 
       
   129 	iServiceClassToSet = static_cast<TBTMajorServiceClass>(s);
       
   130 	}
       
   131 
       
   132 void CCodSetter::DoCancel()
       
   133 	{
       
   134 	iTest.Console()->ReadCancel();
       
   135 	}
       
   136 
       
   137 
       
   138 TInt E32Main()
       
   139 	{
       
   140 	CTrapCleanup* cleanupStack=CTrapCleanup::New();
       
   141 	CActiveScheduler::Install(new CActiveScheduler);
       
   142 
       
   143 	TRAPD(err,TestL());	//	Ignore err
       
   144 
       
   145 	if (err != KErrNone)
       
   146 		{
       
   147 		test.Printf(_L("Error %d"), err);
       
   148 		test.Getch();
       
   149 		}
       
   150 
       
   151 	delete cleanupStack;
       
   152 	return err;
       
   153 	}