|
1 /* |
|
2 * Copyright (c) 2005-2009 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: |
|
15 * This class implements RemCon bearer pulgin interface. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "bmbcmdlistener.h" |
|
20 #include <btengprivatepskeys.h> |
|
21 #include "debug.h" |
|
22 #include "bmbpanic.h" |
|
23 |
|
24 CBmbCmdListener* CBmbCmdListener::NewL(CBmbPlugin& aParent) |
|
25 { |
|
26 CBmbCmdListener* self = new(ELeave) CBmbCmdListener(aParent); |
|
27 CleanupStack::PushL(self); |
|
28 self->ConstructL(); |
|
29 CleanupStack::Pop(self); |
|
30 return self; |
|
31 } |
|
32 |
|
33 CBmbCmdListener::~CBmbCmdListener() |
|
34 { |
|
35 Cancel(); |
|
36 iProperty.Close(); |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // Send the response via PS, and starts listening the next command |
|
41 // to be handled by this bearer. |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 void CBmbCmdListener::HandlingDataCompleted( const TDesC8& aResp ) |
|
45 { |
|
46 // No better error handling than ignoring it. |
|
47 (void) iProperty.Set( aResp ); |
|
48 // Handling previous received command has completed, this object |
|
49 // is ready for picking up the next one, regardless of |
|
50 // response sent successfully or not. |
|
51 Subscribe(); |
|
52 TRACE_FUNC |
|
53 } |
|
54 |
|
55 CBmbCmdListener::CBmbCmdListener(CBmbPlugin& aParent) |
|
56 : CActive(CActive::EPriorityStandard), iParent(aParent) |
|
57 { |
|
58 CActiveScheduler::Add(this); |
|
59 } |
|
60 |
|
61 void CBmbCmdListener::ConstructL() |
|
62 { |
|
63 TRACE_FUNC |
|
64 LEAVE_IF_ERROR(iProperty.Attach(KPSUidBluetoothEnginePrivateCategory, KBTATCodec)); |
|
65 Subscribe(); |
|
66 } |
|
67 |
|
68 void CBmbCmdListener::RunL() |
|
69 { |
|
70 TRACE_FUNC |
|
71 TInt err = iStatus.Int(); |
|
72 // Error could be received from Subscribe when the PS |
|
73 // key is deleted due to powering BT off. In |
|
74 // this case, we just re-subscribe. |
|
75 if(err == KErrNone) |
|
76 { |
|
77 iAtCmdBuf.Zero(); |
|
78 err = iProperty.Get(iAtCmdBuf); |
|
79 if ( !err && iAtCmdBuf.Length() > 0 ) |
|
80 { |
|
81 // An AT command to be processed by iParent. |
|
82 // At command handling completion, iParent will call this object |
|
83 // to send out response via HandlingDataCompleted() |
|
84 // which will subscribe to PS key update after the response has been |
|
85 // sent. |
|
86 iParent.DataFromRemote(iAtCmdBuf); |
|
87 } |
|
88 else |
|
89 { |
|
90 // No valid command in the PS key, re-subscribe. |
|
91 err = KErrArgument; |
|
92 } |
|
93 } |
|
94 TRACE_ERROR((_L8("listener Status %d"), err)) |
|
95 // If err is 0, this object shall not immediately listen to new commands via |
|
96 // Subscribe() function while a command is under processing by iParent. |
|
97 // Btmonocmdhandler ensures not to deliver |
|
98 // the next command to this bearer while a command is being processed. |
|
99 if(err != KErrNone) |
|
100 { |
|
101 Subscribe(); |
|
102 } |
|
103 } |
|
104 |
|
105 void CBmbCmdListener::DoCancel() |
|
106 { |
|
107 iProperty.Cancel(); |
|
108 } |
|
109 |
|
110 void CBmbCmdListener::Subscribe() |
|
111 { |
|
112 __ASSERT_ALWAYS( !IsActive(), Panic(EBmbPanicCmdListenerBadState) ); |
|
113 iProperty.Subscribe(iStatus); |
|
114 SetActive(); |
|
115 TRACE_FUNC |
|
116 } |