|
1 // Copyright (c) 2007-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 // |
|
15 |
|
16 #include <e32base.h> |
|
17 #include <s32buf.h> |
|
18 #include "urilistwritestream.h" |
|
19 #include "ineturiimpl.h" |
|
20 #include "ineturiproperties.h" |
|
21 #include "urilist.h" |
|
22 #include "ineturilistserver.h" |
|
23 #include "uriqueryfilter.h" |
|
24 |
|
25 /** |
|
26 Stanadard factory construction method |
|
27 */ |
|
28 CUriListStream* CUriListStream::NewL ( CUriQueryFilter* aQueryFilter ) |
|
29 { |
|
30 CUriListStream* self = new (ELeave) CUriListStream; |
|
31 CleanupStack::PushL ( self ); |
|
32 self->ConstructL (aQueryFilter); |
|
33 CleanupStack::Pop (); |
|
34 return self; |
|
35 } |
|
36 |
|
37 CUriListStream::CUriListStream () |
|
38 { |
|
39 |
|
40 } |
|
41 |
|
42 CUriListStream::~CUriListStream () |
|
43 { |
|
44 iWriteStream.Close (); |
|
45 delete iInetUri; |
|
46 // Delete the buffer |
|
47 delete iIpcBuffer; |
|
48 delete iQueryFilter; |
|
49 } |
|
50 |
|
51 void CUriListStream::ConstructL ( CUriQueryFilter* aQueryFilter ) |
|
52 { |
|
53 iIpcBuffer = CBufFlat::NewL ( KIpcDataSize ); |
|
54 iIpcBuffer->ExpandL ( 0, KIpcDataSize ); |
|
55 iWriteStream.Open ( *iIpcBuffer ); // Open the stream |
|
56 iInetUri = CInetUriImpl::NewL (); |
|
57 iQueryFilter = aQueryFilter; |
|
58 } |
|
59 |
|
60 /** |
|
61 Writes the URI list to the IPC data stream. The results could contain multiple |
|
62 data records. The stream position will be set to the beginning before the write |
|
63 operation. It returns the total number of records returned via the data stream. |
|
64 */ |
|
65 TInt CUriListStream::WriteUriListL ( TPtrC8& aData ) |
|
66 { |
|
67 ResetL (); |
|
68 |
|
69 MDBTransaction& dbTrans = iQueryFilter->DBTransaction(); |
|
70 |
|
71 TInt totalRecords = 0; |
|
72 TBool dirty = iInetUri->IsDirty (); |
|
73 |
|
74 while ( !dirty || dbTrans.Next() ) |
|
75 { |
|
76 if ( iQueryFilter->MatchRecordL () ) |
|
77 { |
|
78 PopulateDataFieldsL (); |
|
79 if ( PendingWriteStreamSizeL () >= iInetUri->Size() ) |
|
80 { |
|
81 iInetUri->PackL ( iWriteStream ); |
|
82 iInetUri->Clear (); |
|
83 dirty = ETrue; |
|
84 ++totalRecords; // Increment the total no. of records |
|
85 } |
|
86 else |
|
87 { |
|
88 break; |
|
89 } |
|
90 } |
|
91 } |
|
92 // Write to the buffer. |
|
93 aData.Set ( iIpcBuffer->Ptr(0) ); |
|
94 |
|
95 // return with total no. of records |
|
96 return totalRecords; |
|
97 } |
|
98 |
|
99 /** |
|
100 Resets the write stream position to the begining. |
|
101 */ |
|
102 void CUriListStream::ResetL () |
|
103 { |
|
104 MStreamBuf* srcStream = iWriteStream.Sink (); |
|
105 srcStream->SeekL ( MStreamBuf::EWrite, EStreamBeginning, 0 ); |
|
106 } |
|
107 |
|
108 /** |
|
109 Returns the number of bytes remaining in the stream for the write operation. |
|
110 */ |
|
111 TInt CUriListStream::PendingWriteStreamSizeL () |
|
112 { |
|
113 MStreamBuf* srcStream = iWriteStream.Sink (); |
|
114 TStreamPos streamPos = srcStream->TellL ( MStreamBuf::EWrite ); |
|
115 |
|
116 return KIpcDataSize - streamPos.Offset(); |
|
117 } |
|
118 |
|
119 |
|
120 /** |
|
121 Reads the data from the storage and populates the CInetUriImpl object. Later this |
|
122 data will be packed and send it via IPC data buffer |
|
123 */ |
|
124 void CUriListStream::PopulateDataFieldsL () |
|
125 { |
|
126 MDBTransaction& dbTrans = iQueryFilter->DBTransaction(); |
|
127 iInetUri->SetUriId ( dbTrans.ColumnIntL ( URILIST::EId ) ); |
|
128 CUri8* uri = CreateUriL (); |
|
129 iInetUri->SetUri ( *uri ); |
|
130 |
|
131 // Populate the properties |
|
132 CInetUriProperties& properties = iInetUri->Properties (); |
|
133 |
|
134 properties.SetPropId ( dbTrans.ColumnIntL ( URILIST::EPropId - 1 ) ); |
|
135 properties.SetServiceType ( static_cast <InetUriList::TServiceType> ( dbTrans.ColumnIntL ( URILIST::EServiceType - 1 ) ) ); |
|
136 properties.SetListType ( static_cast <InetUriList::TListType> ( dbTrans.ColumnIntL ( URILIST::EListType - 1 ) ) ); |
|
137 properties.SetFavouriteNameL ( dbTrans.ColumnTextL ( URILIST::EFavouriteName - 1 ) ); |
|
138 properties.SetPermission ( static_cast <InetUriList::TPermission> ( dbTrans.ColumnIntL ( URILIST::EPermission - 1 ) ) ); |
|
139 } |
|
140 |
|
141 /** |
|
142 Creates a new URI object by setting the individual components. The individual componentes are |
|
143 read from the storage. |
|
144 */ |
|
145 CUri8* CUriListStream::CreateUriL () |
|
146 { |
|
147 MDBTransaction& dbTrans = iQueryFilter->DBTransaction(); |
|
148 CUri8* uri = CUri8::NewL (); |
|
149 CleanupStack::PushL ( uri ); |
|
150 |
|
151 SetUriComponentL ( *uri, dbTrans.ColumnTextL ( URILIST::EScheme ), EUriScheme ); |
|
152 SetUriComponentL ( *uri, dbTrans.ColumnTextL ( URILIST::EHost ), EUriHost ); |
|
153 SetUriComponentL ( *uri, dbTrans.ColumnTextL ( URILIST::EPort ), EUriPort ); |
|
154 SetUriComponentL ( *uri, dbTrans.ColumnTextL ( URILIST::EUserInfo ), EUriUserinfo ); |
|
155 SetUriComponentL ( *uri, dbTrans.ColumnTextL ( URILIST::EPath ), EUriPath ); |
|
156 SetUriComponentL ( *uri, dbTrans.ColumnTextL ( URILIST::EQuery ), EUriQuery ); |
|
157 SetUriComponentL ( *uri, dbTrans.ColumnTextL ( URILIST::EFragments ), EUriFragment ); |
|
158 |
|
159 CleanupStack::Pop (); // uri |
|
160 return uri; |
|
161 } |
|
162 |
|
163 /** |
|
164 Sets the URI component. |
|
165 */ |
|
166 void CUriListStream::SetUriComponentL ( CUri8& aUri, const TDesC8& aUriComponent, TUriComponent aComponent ) |
|
167 { |
|
168 aUri.SetComponentL ( aUriComponent, aComponent ); |
|
169 } |
|
170 |