|
1 /* |
|
2 * Copyright (c) 2007-2008 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: Contains CNcdNodeSeenFolderProxy |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdnodeseenfolderproxy.h" |
|
20 #include "catalogsdebug.h" |
|
21 #include "ncdnodefolderproxy.h" |
|
22 #include "catalogsinterfaceidentifier.h" |
|
23 #include "catalogsclientserver.h" |
|
24 #include "ncdnodefunctionids.h" |
|
25 #include "catalogsutils.h" |
|
26 #include "ncdnodeidentifier.h" |
|
27 #include "ncdnodemanagerproxy.h" |
|
28 |
|
29 CNcdNodeSeenFolderProxy* CNcdNodeSeenFolderProxy::NewL( |
|
30 MCatalogsClientServer& aSession, |
|
31 TInt aHandle, |
|
32 CNcdNodeFolderProxy& aNode ) |
|
33 { |
|
34 DLTRACEIN(("")); |
|
35 CNcdNodeSeenFolderProxy* self = NewLC( |
|
36 aSession, aHandle, aNode ); |
|
37 CleanupStack::Pop( self ); |
|
38 return self; |
|
39 } |
|
40 |
|
41 |
|
42 CNcdNodeSeenFolderProxy* CNcdNodeSeenFolderProxy::NewLC( |
|
43 MCatalogsClientServer& aSession, |
|
44 TInt aHandle, |
|
45 CNcdNodeFolderProxy& aNode ) |
|
46 { |
|
47 DLTRACEIN(("")); |
|
48 CNcdNodeSeenFolderProxy* self = |
|
49 new( ELeave ) CNcdNodeSeenFolderProxy( |
|
50 aSession, aHandle, aNode ); |
|
51 // Using PushL because the object does not have any references yet |
|
52 CleanupStack::PushL( self ); |
|
53 self->ConstructL(); |
|
54 return self; |
|
55 } |
|
56 |
|
57 |
|
58 CNcdNodeSeenFolderProxy::CNcdNodeSeenFolderProxy( |
|
59 MCatalogsClientServer& aSession, |
|
60 TInt aHandle, |
|
61 CNcdNodeFolderProxy& aNode ) : |
|
62 CNcdInterfaceBaseProxy( aSession, aHandle, &aNode ), |
|
63 iFolder( aNode ) |
|
64 { |
|
65 } |
|
66 |
|
67 |
|
68 void CNcdNodeSeenFolderProxy::ConstructL() |
|
69 { |
|
70 DLTRACEIN(("")); |
|
71 |
|
72 // Register the interface. |
|
73 MNcdNodeSeenFolder* seen( this ); |
|
74 DLINFO(("SeenFolder-ptr: %X, this: %X", seen, this )); |
|
75 AddInterfaceL( |
|
76 CCatalogsInterfaceIdentifier::NewL( |
|
77 seen, this, MNcdNodeSeenFolder::KInterfaceUid ) ); |
|
78 |
|
79 InternalizeL(); |
|
80 } |
|
81 |
|
82 CNcdNodeSeenFolderProxy::~CNcdNodeSeenFolderProxy() |
|
83 { |
|
84 DLTRACEIN(("")); |
|
85 |
|
86 // Remove interfaces implemented by this class from the interface list. |
|
87 // So, the interface list is up to date when this class object is deleted. |
|
88 RemoveInterface( MNcdNodeSeenFolder::KInterfaceUid ); |
|
89 } |
|
90 |
|
91 |
|
92 void CNcdNodeSeenFolderProxy::InternalizeL() |
|
93 { |
|
94 // Nothing to internalize currently. |
|
95 } |
|
96 |
|
97 void CNcdNodeSeenFolderProxy::SetContentsSeenL() |
|
98 { |
|
99 DLTRACEIN(("")); |
|
100 |
|
101 // Send the message to server side. |
|
102 TInt output; |
|
103 User::LeaveIfError( |
|
104 ClientServerSession().SendSync( |
|
105 NcdNodeFunctionIds::ENcdNodeSeenFolderSetContentsSeen, |
|
106 KNullDesC(), |
|
107 output, |
|
108 Handle() ) ); |
|
109 } |
|
110 |
|
111 |
|
112 TInt CNcdNodeSeenFolderProxy::NewCountL( TInt aLevels ) const |
|
113 { |
|
114 DLTRACEIN(("")); |
|
115 |
|
116 if ( aLevels < 1 ) |
|
117 { |
|
118 User::Leave( KErrArgument ); |
|
119 } |
|
120 |
|
121 // Send the message to server side. |
|
122 RCatalogsBufferWriter writer; |
|
123 writer.OpenLC(); |
|
124 writer().WriteInt32L( aLevels ); |
|
125 |
|
126 TInt count( 0 ); |
|
127 User::LeaveIfError( |
|
128 ClientServerSession().SendSync( |
|
129 NcdNodeFunctionIds::ENcdNodeSeenFolderNewCount, |
|
130 writer.PtrL(), |
|
131 count, |
|
132 Handle() ) ); |
|
133 |
|
134 CleanupStack::PopAndDestroy( &writer ); |
|
135 |
|
136 DLINFO(( "count: %d", count )); |
|
137 return count; |
|
138 } |
|
139 |
|
140 |
|
141 RCatalogsArray<MNcdNode> CNcdNodeSeenFolderProxy::NewNodesL( TInt aLevels ) const |
|
142 { |
|
143 DLTRACEIN(("levels: %d", aLevels)); |
|
144 |
|
145 if ( aLevels < 1 ) |
|
146 { |
|
147 User::Leave( KErrArgument ); |
|
148 } |
|
149 |
|
150 // Send the message to server side. |
|
151 RCatalogsBufferWriter writer; |
|
152 writer.OpenLC(); |
|
153 writer().WriteInt32L( aLevels ); |
|
154 |
|
155 HBufC8* receiveData( NULL ); |
|
156 User::LeaveIfError( |
|
157 ClientServerSession().SendSyncAlloc( |
|
158 NcdNodeFunctionIds::ENcdNodeSeenFolderNewNodes, |
|
159 writer.PtrL(), |
|
160 receiveData, |
|
161 Handle(), |
|
162 0 ) ); |
|
163 |
|
164 CleanupStack::PopAndDestroy( &writer ); |
|
165 |
|
166 RCatalogsArray<MNcdNode> array; |
|
167 CleanupResetAndDestroyPushL( array ); |
|
168 |
|
169 DASSERT( receiveData ); |
|
170 CleanupStack::PushL( receiveData ); |
|
171 |
|
172 // Read the identifiers from receive data and add the nodes to the |
|
173 // array. |
|
174 RDesReadStream desReadStream( *receiveData ); |
|
175 CleanupClosePushL( desReadStream ); |
|
176 |
|
177 TInt identifierCount = desReadStream.ReadInt32L(); |
|
178 |
|
179 for ( TInt i = 0; i < identifierCount; i++ ) |
|
180 { |
|
181 CNcdNodeIdentifier* nodeId = CNcdNodeIdentifier::NewLC( desReadStream ); |
|
182 MNcdNode* node = &iFolder.NodeManager().NodeL( *nodeId ); |
|
183 CleanupStack::PopAndDestroy( nodeId ); |
|
184 array.AppendL( node ); |
|
185 |
|
186 // Add the reference count to make sure the nodes in the |
|
187 // array don't get deleted |
|
188 node->AddRef(); |
|
189 } |
|
190 |
|
191 CleanupStack::PopAndDestroy( &desReadStream ); |
|
192 CleanupStack::PopAndDestroy( receiveData ); |
|
193 CleanupStack::Pop( &array ); |
|
194 |
|
195 return array; |
|
196 } |