|
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: Contains CNcdNodeUserDataProxy class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdnodeuserdataproxy.h" |
|
20 #include "ncdnodemetadataproxy.h" |
|
21 #include "ncdoperationimpl.h" |
|
22 #include "catalogsclientserver.h" |
|
23 #include "ncdnodeidentifier.h" |
|
24 #include "ncdnodefunctionids.h" |
|
25 #include "ncdnodeclassids.h" |
|
26 #include "catalogsinterfaceidentifier.h" |
|
27 #include "catalogsutils.h" |
|
28 #include "catalogsdebug.h" |
|
29 |
|
30 |
|
31 CNcdNodeUserDataProxy::CNcdNodeUserDataProxy( |
|
32 MCatalogsClientServer& aSession, |
|
33 TInt aHandle, |
|
34 CNcdNodeMetadataProxy& aNodeMetadata ) |
|
35 : CNcdInterfaceBaseProxy( aSession, aHandle, &aNodeMetadata ), |
|
36 iNodeMetadata( aNodeMetadata ) |
|
37 { |
|
38 } |
|
39 |
|
40 |
|
41 void CNcdNodeUserDataProxy::ConstructL() |
|
42 { |
|
43 // Register the interface |
|
44 MNcdNodeUserData* interface( this ); |
|
45 AddInterfaceL( |
|
46 CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodeUserData::KInterfaceUid ) ); |
|
47 } |
|
48 |
|
49 |
|
50 CNcdNodeUserDataProxy* CNcdNodeUserDataProxy::NewL( |
|
51 MCatalogsClientServer& aSession, |
|
52 TInt aHandle, |
|
53 CNcdNodeMetadataProxy& aNodeMetadata ) |
|
54 { |
|
55 CNcdNodeUserDataProxy* self = |
|
56 CNcdNodeUserDataProxy::NewLC( aSession, aHandle, aNodeMetadata ); |
|
57 CleanupStack::Pop( self ); |
|
58 return self; |
|
59 } |
|
60 |
|
61 CNcdNodeUserDataProxy* CNcdNodeUserDataProxy::NewLC( |
|
62 MCatalogsClientServer& aSession, |
|
63 TInt aHandle, |
|
64 CNcdNodeMetadataProxy& aNodeMetadata ) |
|
65 { |
|
66 CNcdNodeUserDataProxy* self = |
|
67 new( ELeave ) CNcdNodeUserDataProxy( aSession, aHandle, aNodeMetadata ); |
|
68 // Using PushL because the object does not have any references yet |
|
69 CleanupStack::PushL( self ); |
|
70 self->ConstructL(); |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 CNcdNodeUserDataProxy::~CNcdNodeUserDataProxy() |
|
76 { |
|
77 // Delete member variables here |
|
78 // Do not delete node because this object does not own it. |
|
79 |
|
80 // Remove the interface that is not used anymore |
|
81 RemoveInterface( MNcdNodeUserData::KInterfaceUid ); |
|
82 } |
|
83 |
|
84 |
|
85 // MNcdNodeUserData functions |
|
86 |
|
87 HBufC8* CNcdNodeUserDataProxy::UserDataL() const |
|
88 { |
|
89 DLTRACEIN(("")); |
|
90 |
|
91 HBufC8* data( NULL ); |
|
92 |
|
93 // Because we do not know the exact size of the data, use |
|
94 // the alloc method, which creates the buffer of the right size |
|
95 // and sets the pointer to point to the created buffer. |
|
96 // Get all the data that is necessary to internalize this object |
|
97 // from the server side. |
|
98 User::LeaveIfError( |
|
99 ClientServerSession(). |
|
100 SendSyncAlloc( NcdNodeFunctionIds::ENcdUserData, |
|
101 KNullDesC8, |
|
102 data, |
|
103 Handle(), |
|
104 0 ) ); |
|
105 |
|
106 if ( data == NULL ) |
|
107 { |
|
108 DLERROR(("")); |
|
109 User::Leave( KErrNotFound ); |
|
110 } |
|
111 |
|
112 DLTRACEOUT(( "Received user data: %S", data )); |
|
113 |
|
114 return data; |
|
115 } |
|
116 |
|
117 void CNcdNodeUserDataProxy::SetUserDataL( const TDesC8* aData ) |
|
118 { |
|
119 DLTRACEIN(("")); |
|
120 |
|
121 // Ret data does not need to contain anything. |
|
122 TPtr8 retData( NULL, 0 ); |
|
123 |
|
124 if( aData == NULL ) |
|
125 { |
|
126 DLTRACE(("User data NULL" )); |
|
127 |
|
128 // This means that the user data should be cleared |
|
129 // from the db. No need to send any data to the server. |
|
130 // Just use the right function. |
|
131 User::LeaveIfError( |
|
132 ClientServerSession(). |
|
133 SendSync( NcdNodeFunctionIds::ENcdClearUserData, |
|
134 KNullDesC8, |
|
135 retData, |
|
136 Handle() ) ); |
|
137 } |
|
138 else |
|
139 { |
|
140 DLTRACE(("Set user data: %S", aData )); |
|
141 |
|
142 // Send the data to the server side. |
|
143 User::LeaveIfError( |
|
144 ClientServerSession(). |
|
145 SendSync( NcdNodeFunctionIds::ENcdSetUserData, |
|
146 *aData, |
|
147 retData, |
|
148 Handle() ) ); |
|
149 } |
|
150 |
|
151 |
|
152 // The aData should not be deleted here, because |
|
153 // the ownership is not transferred. Even though the |
|
154 // parameter is the pointer. |
|
155 |
|
156 DLTRACEOUT(("")); |
|
157 } |
|
158 |
|
159 |
|
160 // Other functions |
|
161 |
|
162 CNcdNodeMetadataProxy& CNcdNodeUserDataProxy::NodeMetadata() const |
|
163 { |
|
164 return iNodeMetadata; |
|
165 } |