17 // INCLUDE FILES |
17 // INCLUDE FILES |
18 #include "mdesessionstartupao.h" |
18 #include "mdesessionstartupao.h" |
19 |
19 |
20 #include "mdeenginesession.h" |
20 #include "mdeenginesession.h" |
21 #include "mdesessionimpl.h" |
21 #include "mdesessionimpl.h" |
|
22 |
|
23 const TInt KRetryDelay = 2; // 2 seconds |
|
24 const TInt KMillion = 1000000; |
22 |
25 |
23 // ========================= MEMBER FUNCTIONS ================================== |
26 // ========================= MEMBER FUNCTIONS ================================== |
24 |
27 |
25 CMdESessionStartupAO* CMdESessionStartupAO::NewL( |
28 CMdESessionStartupAO* CMdESessionStartupAO::NewL( |
26 CMdESessionImpl& aSessionImpl, RMdEEngineSession& aSession ) |
29 CMdESessionImpl& aSessionImpl, RMdEEngineSession& aSession ) |
52 iState = EStartupOpenServer; |
55 iState = EStartupOpenServer; |
53 } |
56 } |
54 |
57 |
55 void CMdESessionStartupAO::ConstructL() |
58 void CMdESessionStartupAO::ConstructL() |
56 { |
59 { |
|
60 iTimer.CreateLocal(); |
57 SetActive(); |
61 SetActive(); |
58 TRequestStatus* status = &iStatus; |
62 TRequestStatus* status = &iStatus; |
59 User::RequestComplete( status, KErrNone ); |
63 User::RequestComplete( status, KErrNone ); |
60 } |
64 } |
61 |
65 |
62 CMdESessionStartupAO::~CMdESessionStartupAO() |
66 CMdESessionStartupAO::~CMdESessionStartupAO() |
63 { |
67 { |
64 Cancel(); // Causes call to DoCancel() |
68 Cancel(); // Causes call to DoCancel() |
|
69 iTimer.Close(); |
65 } |
70 } |
66 |
71 |
67 void CMdESessionStartupAO::DoCancel() |
72 void CMdESessionStartupAO::DoCancel() |
68 { |
73 { |
69 iSession.OpenCancel( iStatus ); |
74 iTimer.Cancel(); |
|
75 iSession.OpenCancel(); |
70 } |
76 } |
71 |
77 |
72 void CMdESessionStartupAO::RunL() |
78 void CMdESessionStartupAO::RunL() |
73 { |
79 { |
74 const TInt status = iStatus.Int(); |
|
75 |
|
76 switch ( iState ) |
80 switch ( iState ) |
77 { |
81 { |
78 case EStartupOpenServer: |
82 case EStartupOpenServer: |
79 { |
83 { |
80 iSession.OpenL( iStatus ); |
84 iSession.OpenL(); |
81 |
85 |
82 iState = EStartupConnect; |
86 iState = EStartupConnect; |
83 |
87 |
84 SetActive(); |
88 SetActive(); |
|
89 TRequestStatus* status = &iStatus; |
|
90 User::RequestComplete( status, KErrNone ); |
85 |
91 |
86 break; |
92 break; |
87 } |
93 } |
88 case EStartupConnect: |
94 case EStartupConnect: |
89 { |
95 { |
123 } |
129 } |
124 } |
130 } |
125 |
131 |
126 TInt CMdESessionStartupAO::RunError(TInt aError) |
132 TInt CMdESessionStartupAO::RunError(TInt aError) |
127 { |
133 { |
128 iSessionImpl.NotifyError( aError ); |
134 // If server was not fully initialized when session was tried to be |
|
135 // created, try to establish session again |
|
136 if( iState == EStartupOpenServer && |
|
137 (aError == KErrNotReady || |
|
138 aError == KErrAlreadyExists ) ) |
|
139 { |
|
140 TTimeIntervalMicroSeconds32 delay( KRetryDelay * KMillion ); |
|
141 iState = EStartupOpenServer; |
|
142 iTimer.After( iStatus, delay ); |
|
143 SetActive(); |
|
144 } |
|
145 else if( iState == EStartupConnect && |
|
146 ( aError == KErrCommsBreak || |
|
147 aError == KErrServerTerminated || |
|
148 aError == KErrNotReady ) ) |
|
149 { |
|
150 TTimeIntervalMicroSeconds32 delay( KRetryDelay * KMillion ); |
|
151 iState = EStartupOpenServer; |
|
152 iTimer.After( iStatus, delay ); |
|
153 SetActive(); |
|
154 } |
|
155 // If schema was not loaded already when it was |
|
156 // attempted to be loaded, try to load schema again |
|
157 else if( iState == EStartupLoadSchema && |
|
158 aError == KErrNotReady ) |
|
159 { |
|
160 TTimeIntervalMicroSeconds32 delay( KRetryDelay * KMillion ); |
|
161 iState = EStartupLoadSchema; |
|
162 iTimer.After( iStatus, delay ); |
|
163 SetActive(); |
|
164 } |
|
165 else |
|
166 { |
|
167 iSessionImpl.NotifyError( aError ); |
|
168 } |
129 |
169 |
130 return KErrNone; |
170 return KErrNone; |
131 } |
171 } |