|
1 /* |
|
2 * Copyright (c) 2006 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: Inline implementation of message monitor |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <mpxlog.h> |
|
19 #include "mpxsession.h" |
|
20 #include "mpxmessagemonitor.h" |
|
21 |
|
22 const TInt KMPXGetNextMessage=0; |
|
23 const TInt KMPXCancelGetNextMessage=1; |
|
24 |
|
25 // ============================== MEMBER FUNCTIONS ============================ |
|
26 // ---------------------------------------------------------------------------- |
|
27 // Two phases constructor |
|
28 // ---------------------------------------------------------------------------- |
|
29 // |
|
30 EXPORT_C CMPXMessageMonitor* CMPXMessageMonitor::NewL( |
|
31 const RMPXSession& aSession, |
|
32 MMPXMessageObserver& aObserver) |
|
33 { |
|
34 CMPXMessageMonitor* self = new(ELeave)CMPXMessageMonitor(aSession, aObserver); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop(self); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // ---------------------------------------------------------------------------- |
|
42 // Destructor |
|
43 // ---------------------------------------------------------------------------- |
|
44 // |
|
45 EXPORT_C CMPXMessageMonitor::~CMPXMessageMonitor() |
|
46 { |
|
47 MPX_FUNC_EX("CMPXMessageMonitor::~CMPXMessageMonitor"); |
|
48 Cancel(); |
|
49 } |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // C++ constructor |
|
53 // ---------------------------------------------------------------------------- |
|
54 // |
|
55 CMPXMessageMonitor::CMPXMessageMonitor( |
|
56 const RMPXSession& aSession, |
|
57 MMPXMessageObserver& aObserver) |
|
58 : CActive(EPriorityHigh), |
|
59 iSession(aSession), |
|
60 iObserver(aObserver) |
|
61 { |
|
62 CActiveScheduler::Add(this); |
|
63 } |
|
64 |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // 2nd phase construction: |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 void CMPXMessageMonitor::ConstructL() |
|
71 { |
|
72 MPX_FUNC_EX("CMPXMessageMonitor::ConstructL"); |
|
73 GetNextMessage(); |
|
74 } |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // Start to monitor messages |
|
78 // |
|
79 // ---------------------------------------------------------------------------- |
|
80 // |
|
81 EXPORT_C void CMPXMessageMonitor::GetNextMessage() |
|
82 { |
|
83 MPX_FUNC_EX("CMPXMessageMonitor::GetNextMessage"); |
|
84 if (!IsActive()) |
|
85 { |
|
86 MPX_DEBUG1("CMPXMessageMonitor::GetNextMessage send request"); |
|
87 iSession.SendReceive(KMPXGetNextMessage, |
|
88 TIpcArgs(&iMsgDataPkg, &iErrorPkg), |
|
89 iStatus); |
|
90 SetActive(); |
|
91 } |
|
92 } |
|
93 |
|
94 // ---------------------------------------------------------------------------- |
|
95 // From CActive: a new message must have arrived so retrieve it and pass back |
|
96 // to observer, then wait for next message |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 EXPORT_C void CMPXMessageMonitor::RunL() |
|
100 { |
|
101 MPX_FUNC_EX("CMPXMessageMonitor::RunL"); |
|
102 |
|
103 // Try again in case server is down for IAD |
|
104 if (iStatus == KErrDied || iStatus == KErrServerTerminated) |
|
105 { |
|
106 MPX_DEBUG1("-->CMPXMessageMonitor::RunL Reconnecting session for IAD"); |
|
107 |
|
108 // attempt to bring the server back up |
|
109 if (iSession.Reconnect() != KErrNone) |
|
110 { |
|
111 MPX_DEBUG1("-->CMPXMessageMonitor::RunL Reconnect Failed"); |
|
112 |
|
113 User::LeaveIfError(iStatus.Int()); |
|
114 } |
|
115 } |
|
116 else |
|
117 { |
|
118 User::LeaveIfError(iStatus.Int()); |
|
119 iObserver.MessageReceived(iMsgDataPkg(), iErrorPkg()); |
|
120 } |
|
121 } |
|
122 |
|
123 // ---------------------------------------------------------------------------- |
|
124 // From CActive: no more messages are required |
|
125 // ---------------------------------------------------------------------------- |
|
126 // |
|
127 EXPORT_C void CMPXMessageMonitor::DoCancel() |
|
128 { |
|
129 MPX_FUNC_EX("CMPXMessageMonitor::DoCancel"); |
|
130 if (IsActive()) |
|
131 { |
|
132 TRAP_IGNORE(iSession.SendReceiveL(KMPXCancelGetNextMessage)); |
|
133 } |
|
134 } |
|
135 |
|
136 // ---------------------------------------------------------------------------- |
|
137 // Handle leave in the RunL() |
|
138 // ---------------------------------------------------------------------------- |
|
139 // |
|
140 EXPORT_C TInt CMPXMessageMonitor::RunError(TInt aError) |
|
141 { |
|
142 MPX_DEBUG3("-->CMPXMessageMonitor::RunError 0x%08x, error %d", this, aError); |
|
143 if (KErrCancel!=aError && KErrServerTerminated!=aError) |
|
144 { |
|
145 GetNextMessage(); |
|
146 } |
|
147 MPX_DEBUG3("<--CMPXMessageMonitor::RunError 0x%08x, error %d", this, aError); |
|
148 return KErrNone; |
|
149 } |
|
150 |
|
151 // End of file |
|
152 |