|
1 /* |
|
2 * Copyright (c) 2004 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: Symbian OS Server source. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "nsmlsosserver.h" |
|
20 |
|
21 // -------------------------------------------------------------------------- |
|
22 // CNSmlHistoryLog::CNSmlHistoryLog( const TInt aProfId ) |
|
23 // -------------------------------------------------------------------------- |
|
24 // |
|
25 CNSmlHistoryLog::CNSmlHistoryLog( const TInt aProfId, CNSmlSOSSession& aSession ) |
|
26 : iProfId(aProfId), iSession(aSession), iDataPtr(NULL, 0, 0) |
|
27 { |
|
28 } |
|
29 |
|
30 // -------------------------------------------------------------------------- |
|
31 // CNSmlHistoryLog::~CNSmlHistoryLog() |
|
32 // -------------------------------------------------------------------------- |
|
33 // |
|
34 CNSmlHistoryLog::~CNSmlHistoryLog() |
|
35 { |
|
36 delete iBuffer; |
|
37 } |
|
38 |
|
39 // -------------------------------------------------------------------------- |
|
40 // TInt CNSmlHistoryLog::FetchDataL() |
|
41 // -------------------------------------------------------------------------- |
|
42 // |
|
43 TInt CNSmlHistoryLog::FetchDataL() |
|
44 { |
|
45 TInt ret(KErrNotFound); |
|
46 if ( iProfId < KMaxDataSyncID ) // DS Profile |
|
47 { |
|
48 CNSmlDSProfile* prof = iSession.DSSettings().ProfileL( iProfId ); |
|
49 if ( prof ) |
|
50 { |
|
51 CleanupStack::PushL(prof); |
|
52 |
|
53 CBufFlat* buffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity ); |
|
54 CleanupStack::PushL( buffer ); |
|
55 RBufWriteStream stream( *buffer ); |
|
56 |
|
57 RReadStream logStream = prof->LogReadStreamL(); |
|
58 CleanupClosePushL(logStream); |
|
59 |
|
60 TInt size = logStream.Source()->SizeL(); |
|
61 logStream.ReadL( stream, size ); |
|
62 |
|
63 CleanupStack::PopAndDestroy(&logStream); |
|
64 delete iBuffer; |
|
65 iBuffer = buffer; |
|
66 CleanupStack::Pop( buffer ); |
|
67 CleanupStack::PopAndDestroy(prof); |
|
68 ret = KErrNone; |
|
69 } |
|
70 } |
|
71 else // DM Profile |
|
72 { |
|
73 CNSmlDMProfile* prof = iSession.DMSettings().ProfileL( iProfId ); |
|
74 |
|
75 if ( prof ) |
|
76 { |
|
77 CleanupStack::PushL(prof); |
|
78 |
|
79 CBufFlat* buffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity ); |
|
80 CleanupStack::PushL( buffer ); |
|
81 RBufWriteStream stream( *buffer ); |
|
82 |
|
83 RReadStream logStream = prof->LogReadStreamL(); |
|
84 CleanupClosePushL(logStream); |
|
85 |
|
86 TInt size = logStream.Source()->SizeL(); |
|
87 logStream.ReadL( stream, size ); |
|
88 |
|
89 CleanupStack::PopAndDestroy(&logStream); |
|
90 |
|
91 delete iBuffer; |
|
92 iBuffer = buffer; |
|
93 CleanupStack::Pop( buffer ); |
|
94 |
|
95 CleanupStack::PopAndDestroy(prof); |
|
96 |
|
97 ret = KErrNone; |
|
98 } |
|
99 } |
|
100 return ret; |
|
101 } |
|
102 |
|
103 // -------------------------------------------------------------------------- |
|
104 // TInt CNSmlHistoryLog::DataSize() |
|
105 // -------------------------------------------------------------------------- |
|
106 // |
|
107 TInt CNSmlHistoryLog::DataSize() |
|
108 { |
|
109 return iBuffer->Size(); |
|
110 } |
|
111 |
|
112 // -------------------------------------------------------------------------- |
|
113 // const TPtr8& CNSmlHistoryLog::ReadData() |
|
114 // -------------------------------------------------------------------------- |
|
115 // |
|
116 const TPtr8& CNSmlHistoryLog::ReadData() |
|
117 { |
|
118 if ( iBuffer ) |
|
119 { |
|
120 iDataPtr.Set( iBuffer->Ptr(0) ); |
|
121 } |
|
122 return iDataPtr; |
|
123 } |
|
124 |
|
125 // -------------------------------------------------------------------------- |
|
126 // void CNSmlHistoryLog::ResetL() |
|
127 // -------------------------------------------------------------------------- |
|
128 // |
|
129 void CNSmlHistoryLog::ResetL() |
|
130 { |
|
131 if ( iProfId < KMaxDataSyncID ) // DS Profile |
|
132 { |
|
133 CNSmlDSProfile* prof = iSession.DSSettings().ProfileL( iProfId ); |
|
134 if ( prof ) |
|
135 { |
|
136 CleanupStack::PushL(prof); |
|
137 |
|
138 RWriteStream logStream = prof->LogWriteStreamL(); |
|
139 CleanupClosePushL(logStream); |
|
140 |
|
141 logStream.WriteL( TPtrC() ); |
|
142 CleanupStack::PopAndDestroy(&logStream); |
|
143 |
|
144 prof->WriteStreamCommitL(); |
|
145 |
|
146 CleanupStack::PopAndDestroy(prof); |
|
147 } |
|
148 } |
|
149 else // DM Profile |
|
150 { |
|
151 CNSmlDMProfile* prof = iSession.DMSettings().ProfileL( iProfId ); |
|
152 if ( prof ) |
|
153 { |
|
154 CleanupStack::PushL(prof); |
|
155 |
|
156 RWriteStream logStream = prof->LogWriteStreamL(); |
|
157 CleanupClosePushL(logStream); |
|
158 |
|
159 logStream.WriteL( TPtrC() ); |
|
160 CleanupStack::PopAndDestroy(&logStream); |
|
161 |
|
162 prof->WriteStreamCommitL(); |
|
163 |
|
164 CleanupStack::PopAndDestroy(prof); |
|
165 } |
|
166 } |
|
167 } |