|
1 /* |
|
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Handles Set personality request |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <usbwatcher.h> |
|
20 |
|
21 #include "csetpersonality.h" |
|
22 #include "cremotepersonalityhandler.h" |
|
23 #include "debug.h" |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // Two-phase construction |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 CSetPersonality* CSetPersonality::NewL(CRemotePersonalityHandler& aCallBack) |
|
30 { |
|
31 |
|
32 FLOG( _L( "[USBREMOTEPERSONALITY]\tCSetPersonality::NewL" ) ); |
|
33 |
|
34 CSetPersonality* self = new (ELeave) CSetPersonality(aCallBack); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop(self); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // Default construction |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CSetPersonality::CSetPersonality(CRemotePersonalityHandler& aCallBack) : |
|
46 CActive(EPriorityStandard), |
|
47 iCallBack(aCallBack) |
|
48 { |
|
49 CActiveScheduler::Add(this); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // Two-phase construction |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 void CSetPersonality::ConstructL() |
|
57 { |
|
58 |
|
59 FLOG( _L( "[USBREMOTEPERSONALITY]\tCSetPersonality::ConstructL" ) ); |
|
60 |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // Destruction |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CSetPersonality::~CSetPersonality() |
|
68 { |
|
69 |
|
70 FLOG( _L( "[USBREMOTEPERSONALITY]\tCSetPersonality::~CSetPersonality" ) ); |
|
71 Cancel(); |
|
72 |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // Sets Usb Watcher |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 void CSetPersonality::SetUsbWatcher(RUsbWatcher* aUsbWatcher) |
|
80 { |
|
81 iUsbWatcher = aUsbWatcher; |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // Cancellation |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 void CSetPersonality::DoCancel() |
|
89 { |
|
90 iUsbWatcher->CancelSetPersonality(); |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------------------------------- |
|
94 // Standard active object error function. |
|
95 // ---------------------------------------------------------------------------- |
|
96 // |
|
97 TInt CSetPersonality::RunError( TInt /*aError*/ ) |
|
98 { |
|
99 return KErrNone; |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // Asynchronous request has been completed |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 void CSetPersonality::RunL() |
|
107 { |
|
108 |
|
109 FTRACE(FPrint( |
|
110 _L("[USBREMOTEPERSONALITY]\tCSetPersonality::RunL iStatus.Int() = %d" ), iStatus.Int())); |
|
111 |
|
112 CRemotePersonalityHandler::TLastResult result(CRemotePersonalityHandler::EUndefinedError); |
|
113 |
|
114 // set result code according to the problem happened |
|
115 switch(iStatus.Int()) |
|
116 { |
|
117 case KErrNone: |
|
118 { |
|
119 result =CRemotePersonalityHandler::ESuccess; |
|
120 iUsbWatcher->SetPreviousPersonalityOnDisconnect(); |
|
121 break; |
|
122 } |
|
123 case KErrNotFound: |
|
124 { |
|
125 result = CRemotePersonalityHandler::ENonExistingPersonality; |
|
126 break; |
|
127 } |
|
128 case KErrNotSupported: |
|
129 { |
|
130 result = CRemotePersonalityHandler::EFeatureIsNotSupported; |
|
131 break; |
|
132 } |
|
133 case KErrCancel: |
|
134 default: |
|
135 { |
|
136 result = CRemotePersonalityHandler::EUndefinedError; |
|
137 } |
|
138 } |
|
139 iCallBack.SetPersonalityCallBack(result); |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // Process SetPersonality request |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CSetPersonality::SetPersonality(TUint aPersonalityId) |
|
147 { |
|
148 |
|
149 FTRACE(FPrint( |
|
150 _L("[USBREMOTEPERSONALITY]\tCSetPersonality::SetPersonality Personality Id = %d" ), aPersonalityId)); |
|
151 |
|
152 if(IsActive()) |
|
153 { |
|
154 Cancel(); |
|
155 } |
|
156 |
|
157 // No Ask-on-connection query, no confirmation for unload personality |
|
158 iUsbWatcher->SetPersonality(iStatus, aPersonalityId, EFalse, ETrue); |
|
159 SetActive(); |
|
160 |
|
161 } |
|
162 |
|
163 |