1 // Copyright (c) 2006-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 // SS_COMMSPROV.CPP |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file @internalTechnology |
|
20 */ |
|
21 |
|
22 |
|
23 #include "ss_common.h" |
|
24 #include <comms-infras/ss_log.h> |
|
25 #include <es_panic.h> |
|
26 #include <ss_std.h> |
|
27 using namespace ESock; |
|
28 |
|
29 #ifdef _DEBUG |
|
30 /** Because we strive to maintain a single owner for a message and to pass by reference when ownership |
|
31 it's generally an error for the handle to be set upon destruction. |
|
32 */ |
|
33 RSafeMessage::~RSafeMessage() |
|
34 { |
|
35 if(Handle() != KNullHandle) |
|
36 { |
|
37 LOG(ESockLog::Printf(KESockServerTag, _L8("RSafeMessage(%08x) - WARNING! handle still set in destructor, may be a leak, session %08x"), Handle(), Session()) ); |
|
38 } |
|
39 } |
|
40 #endif |
|
41 |
|
42 /** Complete the message with the given reason code, with detailed logging |
|
43 */ |
|
44 void RSafeMessage::Complete(TInt aReason) const |
|
45 { |
|
46 LOG(ESockLog::Printf(KESockServerTag, _L8("RSafeMessage(%08x)::Complete(%d) - session %08x"), Handle(), aReason, Session()) ); |
|
47 RMessage2::Complete(aReason); |
|
48 } |
|
49 |
|
50 /** Panic the client with the given category & reason code, with detailed logging |
|
51 */ |
|
52 void RSafeMessage::Panic(const TDesC& aCategory, TInt aReason) const |
|
53 { |
|
54 LOG(ESockLog::Printf(KESockServerTag, _L("RSafeMessage(%08x)::Panic(\"%S\", %d) - session %08x"), Handle(), &aCategory, aReason, Session()) ); |
|
55 RMessage2::Panic(aCategory, aReason); |
|
56 } |
|
57 |
|
58 /** Take over a message. Beyond being a simple copy this resets the source's handle so that double-ownership is avoided |
|
59 */ |
|
60 void RSafeMessage::Adopt(RSafeMessage& aSrc) |
|
61 { |
|
62 *this = aSrc; |
|
63 aSrc.ResetHandle(); |
|
64 } |
|
65 |
|
66 /** Duplicate a message, including aliasing the handle & so raising the risk of a double-complete |
|
67 */ |
|
68 void RSafeMessage::Duplicate(const RSafeMessage& aSrc) |
|
69 { |
|
70 *this = aSrc; |
|
71 } |
|
72 |
|
73 /** Null the handle, so this safe message no longer references a client request. This is normally done automatically |
|
74 by completing or panicking the client or transferring message ownership, so this will seldom need to be called |
|
75 explicitly |
|
76 */ |
|
77 void RSafeMessage::ResetHandle() |
|
78 { |
|
79 iHandle = KNullHandle; |
|
80 } |
|
81 |
|
82 RSafeMessage& RSafeMessage::operator=(const RSafeMessage& aSrc) |
|
83 { |
|
84 RMessage2::operator=(aSrc); |
|
85 return *this; |
|
86 } |
|
87 |
|
88 void RSafeMessage::PanicClient(TInt aReason) const |
|
89 { |
|
90 RThread t; |
|
91 RMessage2::Client(t); |
|
92 TUint tid = t.Id(); |
|
93 TExitType exittype=t.ExitType(); |
|
94 t.Close(); |
|
95 if(exittype == EExitPending) // is client alive? |
|
96 { |
|
97 LOG( |
|
98 TBuf8<sizeof(KESockClientPanic) / sizeof(TUint16)> clientPanic8; |
|
99 clientPanic8.Copy(KESockClientPanic); |
|
100 TBuf8<64> messBuf; |
|
101 ESockLog::IPCMessName((TSockMess) RMessage2::Function(), messBuf); |
|
102 ESockLog::Printf(KESockErrorTag, _L8("RSafeMessage:\tPanicClient, Category %S, Reason %d, Tid %d, RMessage2 %08x [%S], Args %08x %08x %08x %08x, ClientStatus %08x"), |
|
103 &clientPanic8, aReason, tid, RMessage2::Handle(), &messBuf, RMessage2::Int0(), RMessage2::Int1(), RMessage2::Int2(), RMessage2::Int3(), RMessage2::ClientStatus()) |
|
104 ); |
|
105 Panic(KESockClientPanic, aReason); |
|
106 } |
|
107 } |
|
108 |
|
109 TInt RSafeMessage::Read(TInt aSrcParamIndex,TDes8 &aDes,TInt anOffset) const |
|
110 { |
|
111 TInt res= RMessage2::Read(aSrcParamIndex,aDes,anOffset); |
|
112 __ASSERT_DEBUG(res!=KErrArgument,Fault(EBadState)); |
|
113 if (res!=KErrNone) |
|
114 { |
|
115 PanicClient(EBadDescriptorRead); |
|
116 res = KErrBadDescriptor; |
|
117 } |
|
118 return res; |
|
119 } |
|
120 |
|
121 void RSafeMessage::ReadL(TInt aSrcParamIndex,TDes8& aDes,TInt anOffset) const |
|
122 { |
|
123 User::LeaveIfError(Read(aSrcParamIndex, aDes, anOffset)); |
|
124 } |
|
125 |
|
126 TInt RSafeMessage::Write(TInt aDstParamIndex,const TDesC8& aDes,TInt anOffset) const |
|
127 { |
|
128 TInt res = RMessage2::Write(aDstParamIndex,aDes,anOffset); |
|
129 __ASSERT_DEBUG(res!=KErrArgument,Fault(EBadState)); |
|
130 if (res!=KErrNone) |
|
131 { |
|
132 PanicClient(EBadDescriptorWrite); |
|
133 res = KErrBadDescriptor; |
|
134 } |
|
135 return res; |
|
136 } |
|
137 |
|
138 void RSafeMessage::WriteL(TInt aDstParamIndex,const TDesC8& aDes,TInt anOffset) const |
|
139 { |
|
140 User::LeaveIfError(Write(aDstParamIndex, aDes, anOffset)); |
|
141 } |
|
142 |
|
143 TInt RSafeMessage::Read(TInt aSrcParamIndex,TDes16 &aDes,TInt anOffset) const |
|
144 { |
|
145 TInt res= RMessage2::Read(aSrcParamIndex,aDes,anOffset); |
|
146 __ASSERT_DEBUG(res!=KErrArgument,Fault(EBadState)); |
|
147 if (res!=KErrNone) |
|
148 { |
|
149 PanicClient(EBadDescriptorRead); |
|
150 res = KErrBadDescriptor; |
|
151 } |
|
152 return res; |
|
153 } |
|
154 |
|
155 void RSafeMessage::ReadL(TInt aSrcParamIndex,TDes16& aDes,TInt anOffset) const |
|
156 { |
|
157 User::LeaveIfError(Read(aSrcParamIndex, aDes, anOffset)); |
|
158 } |
|
159 |
|
160 TInt RSafeMessage::Write(TInt aDstParamIndex,const TDesC16 &aDes,TInt anOffset) const |
|
161 { |
|
162 TInt res = RMessage2::Write(aDstParamIndex,aDes,anOffset); |
|
163 __ASSERT_DEBUG(res!=KErrArgument,Fault(EBadState)); |
|
164 if (res!=KErrNone) |
|
165 { |
|
166 PanicClient(EBadDescriptorWrite); |
|
167 res = KErrBadDescriptor; |
|
168 } |
|
169 return res; |
|
170 } |
|
171 |
|
172 void RSafeMessage::WriteL(TInt aDstParamIndex,const TDesC16& aDes,TInt anOffset) const |
|
173 { |
|
174 User::LeaveIfError(Write(aDstParamIndex,aDes,anOffset)); |
|
175 } |
|
176 |
|
177 TInt RSafeMessage::Write(TInt aDstParamIndex,const TPckg<TUint32>& aDes,TInt anOffset) const |
|
178 { |
|
179 TInt res = RMessage2::Write(aDstParamIndex,aDes,anOffset); |
|
180 __ASSERT_DEBUG(res!=KErrArgument,Fault(EBadState)); |
|
181 if (res!=KErrNone) |
|
182 { |
|
183 PanicClient(EBadDescriptorWrite); |
|
184 res = KErrBadDescriptor; |
|
185 } |
|
186 return res; |
|
187 } |
|
188 |
|
189 void RSafeMessage::WriteL(TInt aDstParamIndex,const TPckg<TUint32>& aDes,TInt anOffset) const |
|
190 { |
|
191 User::LeaveIfError(Write(aDstParamIndex, aDes, anOffset)); |
|
192 } |
|
193 |
|
194 TInt RSafeMessage::GetDesLengthL(TInt aParam) const |
|
195 { |
|
196 TInt res = RMessage2::GetDesLength(aParam); |
|
197 __ASSERT_DEBUG(res!=KErrArgument,Fault(EBadState)); |
|
198 if (res<0) |
|
199 { |
|
200 PanicClient(EBadDescriptorLength); |
|
201 User::Leave(KErrBadDescriptor); |
|
202 } |
|
203 return res; |
|
204 } |
|
205 |
|
206 |
|
207 TInt RSafeMessage::GetDesMaxLengthL(TInt aParam) const |
|
208 { |
|
209 TInt res = RMessage2::GetDesMaxLength(aParam); |
|
210 __ASSERT_DEBUG(res!=KErrArgument, Fault(EBadState)); |
|
211 if (res < 0) |
|
212 { |
|
213 PanicClient(EBadDescriptorLength); |
|
214 User::Leave(KErrBadDescriptor); |
|
215 } |
|
216 return res; |
|
217 } |
|
218 |
|