|
1 // Copyright (c) 1997-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 // Together, these classes and the CBTPortProxy implement the |
|
15 // State pattern. The states themselves are implemented using |
|
16 // the Flyweight pattern. Each state is a Flyweight object |
|
17 // and CBTPortStateFactory is manager of these objects. As a |
|
18 // result of being a flyweight, no state object may have a state |
|
19 // that can't be shared between all possible users of the state. |
|
20 // |
|
21 // |
|
22 |
|
23 #include <bluetooth/logger.h> |
|
24 #include <cs_port.h> |
|
25 #include "btcomm.h" |
|
26 #include "btstate.h" |
|
27 #ifdef DEBUG |
|
28 #include "btcommutil.h" |
|
29 #endif |
|
30 |
|
31 #ifdef __FLOG_ACTIVE |
|
32 _LIT8(KLogComponent, LOG_COMPONENT_BT_COMM); |
|
33 #endif |
|
34 |
|
35 CBTPortStateFactory::CBTPortStateFactory() |
|
36 /** |
|
37 CBTPortStateFactory constructor nulls all the iState ptrs in here. |
|
38 **/ |
|
39 { |
|
40 LOG_FUNC |
|
41 iStates.Reset(); |
|
42 } |
|
43 |
|
44 CBTPortStateFactory::~CBTPortStateFactory() |
|
45 /** |
|
46 CBTPortStateFactory destructor deletes all states. |
|
47 **/ |
|
48 { |
|
49 LOG_FUNC |
|
50 iStates.DeleteAll(); |
|
51 } |
|
52 |
|
53 CBTPortStateFactory* CBTPortStateFactory::NewL() |
|
54 /** |
|
55 This creates the static CSY state objects. |
|
56 Declared private so only a friend (CBTPortFactory) |
|
57 can instantiate one of these. |
|
58 **/ |
|
59 { |
|
60 LOG_STATIC_FUNC |
|
61 CBTPortStateFactory *psf; |
|
62 psf=new (ELeave) CBTPortStateFactory(); |
|
63 CleanupStack::PushL(psf); |
|
64 psf->InitL(); |
|
65 CleanupStack::Pop(); |
|
66 return psf; |
|
67 } |
|
68 |
|
69 void CBTPortStateFactory::InitL() |
|
70 /** |
|
71 This method creates the static instances of the CSY state objects. |
|
72 **/ |
|
73 { |
|
74 LOG_FUNC |
|
75 iStates[EIdle] =new (ELeave) TBTPortStateIdle(this); |
|
76 iStates[ELoadingProtocol] =new (ELeave) TBTPortStateLoadingProtocol(this); |
|
77 iStates[EDiscovering] =new (ELeave) TBTPortStateDiscovering(this); |
|
78 iStates[ESDPConnected] =new (ELeave) TBTPortStateSDPConnected(this); |
|
79 iStates[ESDPServiceQuery] =new (ELeave) TBTPortStateSDPServiceQuery(this); |
|
80 iStates[ESDPAttribListRetrieved] =new (ELeave) TBTPortStateSDPAttributeListRetrieved(this); |
|
81 iStates[EConnecting] =new (ELeave) TBTPortStateConnecting(this); |
|
82 iStates[EOpen] =new (ELeave) TBTPortStateOpen(this); |
|
83 iStates[EClosing] =new (ELeave) TBTPortStateClosing(this); |
|
84 iStates[EError] =new (ELeave) TBTPortErrorState(this); |
|
85 iStates[ESDPServiceIDListRetrieved] =new (ELeave) TBTPortStateServiceIDListRetrieved(this); |
|
86 } |
|
87 |
|
88 TBTPortState& CBTPortStateFactory::GetState(const TCSYState aState) |
|
89 /** |
|
90 Returns ptr to the state object corresponding to the TCSYState passed in. |
|
91 **/ |
|
92 { |
|
93 LOG_FUNC |
|
94 __ASSERT_DEBUG(aState != EMaxCSYStates, BTCommUtil::Panic(EBTCommPortStateOutOfBounds)); |
|
95 return *iStates[aState]; |
|
96 } |
|
97 |
|
98 TInt CBTPortStateFactory::StateIndex(const TBTPortState* aState) const |
|
99 { |
|
100 LOG_FUNC |
|
101 TInt state; |
|
102 for (state = 0; state < EMaxCSYStates; state++) |
|
103 { |
|
104 if (iStates[state] == aState) |
|
105 { |
|
106 return state; |
|
107 } |
|
108 } |
|
109 |
|
110 return KUnknownState; |
|
111 } |
|
112 |