|
1 // Copyright (c) 2007-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 "tavsrcController.h" |
|
17 |
|
18 #include <remconinterfaceselector.h> |
|
19 #include <remconcoreapicontroller.h> |
|
20 #include <remconbeareravrcp.h> |
|
21 |
|
22 CTavsrcController* CTavsrcController::NewL(CRemConInterfaceSelector& aIfSel, CActiveConsole& aConsole) |
|
23 { |
|
24 CTavsrcController* controller = new(ELeave) CTavsrcController(aIfSel, aConsole); |
|
25 CleanupStack::PushL(controller); |
|
26 controller->ConstructL(); |
|
27 CleanupStack::Pop(controller); |
|
28 return controller; |
|
29 } |
|
30 |
|
31 CTavsrcController::CTavsrcController(CRemConInterfaceSelector& aIfSel, CActiveConsole& aConsole) |
|
32 : CActive(EPriorityStandard), iState(EControllerNotConnected), iSelector(&aIfSel), iConsole(aConsole) |
|
33 { |
|
34 CActiveScheduler::Add(this); |
|
35 } |
|
36 |
|
37 void CTavsrcController::ConstructL() |
|
38 { |
|
39 iCoreController = CRemConCoreApiController::NewL(*iSelector, *this); |
|
40 iGoConnectionOrientedSent = EFalse; |
|
41 } |
|
42 |
|
43 CTavsrcController::~CTavsrcController() |
|
44 { |
|
45 Cancel(); |
|
46 } |
|
47 |
|
48 TInt CTavsrcController::Command(TRemConCoreApiOperationId aOpId) |
|
49 { |
|
50 TInt err = KErrNotReady; |
|
51 |
|
52 if(!IsActive()) |
|
53 { |
|
54 err = KErrNone; |
|
55 |
|
56 if(iState == EControllerConnected) |
|
57 { |
|
58 IssueCommand(aOpId); |
|
59 } |
|
60 else |
|
61 { |
|
62 // Need to connect first |
|
63 TRAP(err, ConnectL()); |
|
64 } |
|
65 } |
|
66 |
|
67 return err; |
|
68 } |
|
69 |
|
70 |
|
71 void CTavsrcController::MrccacoResponse(TRemConCoreApiOperationId aOperationId, TInt aError) |
|
72 { |
|
73 iConsole.Console().Printf(_L("Received Response for Operation %d, Result %d\n"), aOperationId, aError); |
|
74 } |
|
75 |
|
76 void CTavsrcController::IssueCommand(TRemConCoreApiOperationId aOpId) |
|
77 { |
|
78 switch(aOpId) |
|
79 { |
|
80 case ERemConCoreApiVolumeDown: |
|
81 iCoreController->VolumeDown(iStatus, iNumRemotes, ERemConCoreApiButtonClick); |
|
82 break; |
|
83 case ERemConCoreApiVolumeUp: |
|
84 iCoreController->VolumeUp(iStatus, iNumRemotes, ERemConCoreApiButtonPress); |
|
85 break; |
|
86 case ERemConCoreApiForward: |
|
87 iCoreController->Forward(iStatus, iNumRemotes, ERemConCoreApiButtonClick); |
|
88 break; |
|
89 case ERemConCoreApiBackward: |
|
90 iCoreController->Backward(iStatus, iNumRemotes, ERemConCoreApiButtonClick); |
|
91 break; |
|
92 case ERemConCoreApiPlay: |
|
93 iCoreController->Play(iStatus, iNumRemotes, ERemConCoreApiButtonClick); |
|
94 break; |
|
95 case ERemConCoreApiStop: |
|
96 iCoreController->Stop(iStatus, iNumRemotes, ERemConCoreApiButtonClick); |
|
97 break; |
|
98 default: |
|
99 // Cos we don't want to SetActive(), alright? |
|
100 return; |
|
101 } |
|
102 |
|
103 iConsole.Console().Printf(_L("Sending Command Operation %d\n"), aOpId); |
|
104 SetActive(); |
|
105 } |
|
106 |
|
107 void CTavsrcController::ConnectL() |
|
108 { |
|
109 //Ask user which device address we should connect to... |
|
110 iState = ESearchingForDevice; |
|
111 User::LeaveIfError(iNotify.Connect()); |
|
112 iNotify.StartNotifierAndGetResponse(iStatus, KDeviceSelectionNotifierUid, iPckg, iResPckg); |
|
113 SetActive(); |
|
114 } |
|
115 |
|
116 void CTavsrcController::RunL() |
|
117 { |
|
118 switch(iState) |
|
119 { |
|
120 case EControllerConnected: |
|
121 { |
|
122 // We don't care what the result was really |
|
123 // Ask Tim about the display logging and |
|
124 // log it |
|
125 break; |
|
126 } |
|
127 case EControllerNotConnected: |
|
128 { |
|
129 iConsole.Console().Printf(_L("AVRCP connection completed, result = %d\n"), iStatus.Int()); |
|
130 |
|
131 if(iStatus.Int() == KErrNone) |
|
132 { |
|
133 // Connected ok, now issue command |
|
134 iState = EControllerConnected; |
|
135 IssueCommand(iOutstandingOperation); |
|
136 } |
|
137 break; |
|
138 } |
|
139 case ESearchingForDevice: |
|
140 { |
|
141 if (iStatus.Int() == KErrNone) |
|
142 { |
|
143 iState = EControllerNotConnected; |
|
144 |
|
145 iNotify.CancelNotifier(KDeviceSelectionNotifierUid); |
|
146 iNotify.Close(); |
|
147 |
|
148 iConsole.Console().Printf(_L("Opening AVRCP connection...\n")); |
|
149 |
|
150 TBTDevAddr btAddr = iResPckg().BDAddr(); |
|
151 // Store as 8 bit machine readable |
|
152 RBuf8 bearerData; |
|
153 bearerData.CreateL(btAddr.Des()); |
|
154 |
|
155 // Form the RemCon Addr from the AVRCP Uid and the |
|
156 // bluetooth address |
|
157 TRemConAddress addr; |
|
158 addr.BearerUid() = TUid::Uid(KRemConBearerAvrcpImplementationUid); |
|
159 addr.Addr() = bearerData; |
|
160 |
|
161 if (iGoConnectionOrientedSent) |
|
162 { |
|
163 // Only allowed to call GoConnectionOrientedL() once on pain of RemCon panic, |
|
164 // ERemConClientPanicAlreadyConnectionOriented. Solution is to call GoConnectionlessL() |
|
165 // before recalling GoConnectionOrientedL() |
|
166 iSelector->GoConnectionlessL(); |
|
167 } |
|
168 iSelector->GoConnectionOrientedL(addr); |
|
169 iSelector->ConnectBearer(iStatus); |
|
170 iGoConnectionOrientedSent = ETrue; |
|
171 |
|
172 SetActive(); |
|
173 break; |
|
174 } |
|
175 } |
|
176 default: |
|
177 { |
|
178 // hmm shouldn't be here |
|
179 __DEBUGGER(); |
|
180 break; |
|
181 } |
|
182 } |
|
183 } |
|
184 |
|
185 void CTavsrcController::DoCancel() |
|
186 { |
|
187 iCoreController->Cancel(); |
|
188 } |