1 /* |
1 /* |
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
31 } |
31 } |
32 |
32 |
33 CBmbCmdListener::~CBmbCmdListener() |
33 CBmbCmdListener::~CBmbCmdListener() |
34 { |
34 { |
35 Cancel(); |
35 Cancel(); |
36 iProperty.Close(); |
36 iATCmdProperty.Close(); |
|
37 iATRespProperty.Close(); |
37 } |
38 } |
38 |
39 |
39 // --------------------------------------------------------------------------- |
40 // --------------------------------------------------------------------------- |
40 // Send the response via PS, and starts listening the next command |
41 // Send the response via PS, and starts listening the next command |
41 // to be handled by this bearer. |
42 // to be handled by this bearer. |
42 // --------------------------------------------------------------------------- |
43 // --------------------------------------------------------------------------- |
43 // |
44 // |
44 void CBmbCmdListener::HandlingDataCompleted( const TDesC8& aResp ) |
45 void CBmbCmdListener::HandlingDataCompleted( const TDesC8& aResp ) |
45 { |
46 { |
46 // No better error handling than ignoring it. |
47 // No better error handling than ignoring it. |
47 (void) iProperty.Set( aResp ); |
48 (void) iATRespProperty.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 |
49 TRACE_FUNC |
53 } |
50 } |
54 |
51 |
55 CBmbCmdListener::CBmbCmdListener(CBmbPlugin& aParent) |
52 CBmbCmdListener::CBmbCmdListener(CBmbPlugin& aParent) |
56 : CActive(CActive::EPriorityStandard), iParent(aParent) |
53 : CActive(CActive::EPriorityStandard), iParent(aParent) |
59 } |
56 } |
60 |
57 |
61 void CBmbCmdListener::ConstructL() |
58 void CBmbCmdListener::ConstructL() |
62 { |
59 { |
63 TRACE_FUNC |
60 TRACE_FUNC |
64 LEAVE_IF_ERROR(iProperty.Attach(KPSUidBluetoothEnginePrivateCategory, KBTATCodec)); |
61 LEAVE_IF_ERROR(iATCmdProperty.Attach(KPSUidBluetoothEnginePrivateCategory, KBTHfpATCommand)); |
|
62 LEAVE_IF_ERROR(iATRespProperty.Attach(KPSUidBluetoothEnginePrivateCategory, KBTHfpATResponse)); |
65 Subscribe(); |
63 Subscribe(); |
66 } |
64 } |
67 |
65 |
68 void CBmbCmdListener::RunL() |
66 void CBmbCmdListener::RunL() |
69 { |
67 { |
70 TRACE_FUNC |
68 TRACE_FUNC |
71 TInt err = iStatus.Int(); |
69 TInt err = iStatus.Int(); |
|
70 Subscribe(); |
72 // Error could be received from Subscribe when the PS |
71 // Error could be received from Subscribe when the PS |
73 // key is deleted due to powering BT off. In |
72 // key is deleted due to powering BT off. In |
74 // this case, we just re-subscribe. |
73 // this case, we just re-subscribe. |
75 if(err == KErrNone) |
74 if(err == KErrNone) |
76 { |
75 { |
77 iAtCmdBuf.Zero(); |
76 iAtCmdBuf.Zero(); |
78 err = iProperty.Get(iAtCmdBuf); |
77 err = iATCmdProperty.Get(iAtCmdBuf); |
79 if ( !err && iAtCmdBuf.Length() > 0 ) |
78 if ( !err && iAtCmdBuf.Length() > 0 ) |
80 { |
79 { |
81 // An AT command to be processed by iParent. |
80 // An AT command to be processed by iParent. |
82 // At command handling completion, iParent will call this object |
81 // At command handling completion, iParent will call this object |
83 // to send out response via HandlingDataCompleted() |
82 // 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); |
83 iParent.DataFromRemote(iAtCmdBuf); |
87 } |
|
88 else |
|
89 { |
|
90 // No valid command in the PS key, re-subscribe. |
|
91 err = KErrArgument; |
|
92 } |
84 } |
93 } |
85 } |
94 TRACE_ERROR((_L8("listener Status %d"), err)) |
86 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 } |
87 } |
104 |
88 |
105 void CBmbCmdListener::DoCancel() |
89 void CBmbCmdListener::DoCancel() |
106 { |
90 { |
107 iProperty.Cancel(); |
91 iATCmdProperty.Cancel(); |
108 } |
92 } |
109 |
93 |
110 void CBmbCmdListener::Subscribe() |
94 void CBmbCmdListener::Subscribe() |
111 { |
95 { |
112 __ASSERT_ALWAYS( !IsActive(), Panic(EBmbPanicCmdListenerBadState) ); |
96 __ASSERT_ALWAYS( !IsActive(), Panic(EBmbPanicCmdListenerBadState) ); |
113 iProperty.Subscribe(iStatus); |
97 iATCmdProperty.Subscribe(iStatus); |
114 SetActive(); |
98 SetActive(); |
115 TRACE_FUNC |
99 TRACE_FUNC |
116 } |
100 } |