|
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: This file contains implementation of RDRMNotifierClient class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "DRMNotifierClient.h" |
|
22 #include "drmnotifierclientserver.h" |
|
23 #include "drmrightsclient.h" |
|
24 // EXTERNAL DATA STRUCTURES |
|
25 // EXTERNAL FUNCTION PROTOTYPES |
|
26 // CONSTANTS |
|
27 // MACROS |
|
28 // LOCAL CONSTANTS AND MACROS |
|
29 // MODULE DATA STRUCTURES |
|
30 // LOCAL FUNCTION PROTOTYPES |
|
31 // FORWARD DECLARATIONS |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // RDRMNotifierClient::RDRMNotifierClient |
|
37 // C++ default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 RDRMNotifierClient::RDRMNotifierClient(TDRMEventType* aEventType, TDRMEventType* aEventTypeWait, |
|
42 TPtr8* aPtr, TPtr8* aWaitPtr) : |
|
43 iEventType( aEventType ), |
|
44 iEventTypeWait( aEventTypeWait ), |
|
45 iData( aPtr ), |
|
46 iWaitData( aWaitPtr ), |
|
47 numdata( 0 ) |
|
48 { |
|
49 // Nothing |
|
50 } |
|
51 |
|
52 // Destructor |
|
53 RDRMNotifierClient::~RDRMNotifierClient() |
|
54 { |
|
55 Close(); |
|
56 } |
|
57 |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // RDRMNotifierClient::Connect |
|
61 // Connects to the server |
|
62 // (other items were commented in a header). |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 TInt RDRMNotifierClient::Connect( void ) |
|
66 { |
|
67 const TVersion requiredVersion( |
|
68 DRMNotifier::KServerMajorVersion, |
|
69 DRMNotifier::KServerMinorVersion, |
|
70 DRMNotifier::KServerBuildVersion ); |
|
71 |
|
72 TInt ret = KErrNotFound; |
|
73 TUint8 count( 0 ); |
|
74 TUint8 cont( 1 ); |
|
75 |
|
76 do |
|
77 { |
|
78 ret = CreateSession( DRMNotifier::KServerName, |
|
79 requiredVersion, |
|
80 KMaxMessageSlots ); |
|
81 if ( !ret ) |
|
82 { |
|
83 cont = 0; |
|
84 } |
|
85 else |
|
86 { |
|
87 if ( ( count++ == 0 ) && ( ret == KErrNotFound ) ) |
|
88 { |
|
89 ret = RDRMRightsClient::StartServer(); |
|
90 } |
|
91 } |
|
92 } |
|
93 while ( cont && ( count < 2 ) ); |
|
94 |
|
95 return ret; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // RDRMNotifierClient::Close |
|
100 // Closes the connection to the server |
|
101 // (other items were commented in a header). |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void RDRMNotifierClient::Close() |
|
105 { |
|
106 RHandleBase::Close(); |
|
107 } |
|
108 |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // RDRMNotifierClient::SendEvent |
|
112 // Sends an event to the client, asynchronous |
|
113 // (other items were commented in a header). |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void RDRMNotifierClient::SendEvent(TRequestStatus& aStatus) |
|
117 { |
|
118 // Send the message. |
|
119 SendReceive( DRMNotifier::ENotifyClients, TIpcArgs(iData, *iEventType), |
|
120 aStatus ); |
|
121 }; |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // RDRMNotifierClient::WaitForCompletion |
|
125 // Waits for the notifications from the server, asynchronous |
|
126 // (other items were commented in a header). |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 void RDRMNotifierClient::WaitForCompletion(TRequestStatus& aStatus) |
|
130 { |
|
131 numdata.Set(reinterpret_cast<TUint8*>(iEventTypeWait),sizeof(TDRMEventType),sizeof(TDRMEventType)); |
|
132 |
|
133 // Send the message. |
|
134 SendReceive( DRMNotifier::ERecieveNotification, TIpcArgs(iWaitData, &numdata), |
|
135 aStatus ); |
|
136 }; |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // RDRMNotifierClient::RegisterForType |
|
140 // Registeres a type to the server, synchronous |
|
141 // (other items were commented in a header). |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 void RDRMNotifierClient::RegisterForType( TDRMEventType aEventType, |
|
145 HBufC8* aURI ) |
|
146 { |
|
147 TPckg<TInt> eventType(0); |
|
148 eventType.Set(reinterpret_cast<TUint8*>(&aEventType),sizeof(TDRMEventType),sizeof(TDRMEventType)); |
|
149 |
|
150 if( aURI ) |
|
151 { |
|
152 TUint8* dataptr = const_cast<TUint8*>(aURI->Ptr()); |
|
153 TPtr8 uriPkg(dataptr,aURI->Size(),aURI->Size()); |
|
154 |
|
155 // Send the message. |
|
156 SendReceive( DRMNotifier::ERegisterURI, TIpcArgs(&uriPkg, &eventType)); |
|
157 } |
|
158 else |
|
159 { |
|
160 // Send the message. |
|
161 SendReceive( DRMNotifier::ERegister, TIpcArgs(&eventType)); |
|
162 } |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // RDRMNotifierClient::UnRegisterFromType |
|
167 // Unregisteres a type from the server, synchronous |
|
168 // (other items were commented in a header). |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 void RDRMNotifierClient::UnRegisterFromType( TDRMEventType aEventType, |
|
172 HBufC8* aURI) |
|
173 { |
|
174 TPckg<TInt> eventType(0); |
|
175 eventType.Set(reinterpret_cast<TUint8*>(&aEventType),sizeof(TDRMEventType),sizeof(TDRMEventType)); |
|
176 |
|
177 if( aURI ) |
|
178 { |
|
179 TUint8* dataptr = const_cast<TUint8*>(aURI->Ptr()); |
|
180 TPtr8 uriPkg(dataptr,aURI->Size(),aURI->Size()); |
|
181 |
|
182 // Send the message. |
|
183 SendReceive( DRMNotifier::EUnRegisterURI, TIpcArgs(&uriPkg, &eventType)); |
|
184 } |
|
185 else |
|
186 { |
|
187 // Send the message. |
|
188 SendReceive( DRMNotifier::EUnRegister, TIpcArgs(&eventType)); |
|
189 } |
|
190 } |
|
191 |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // RDRMNotifierClient::CancelRequest |
|
195 // Cancels the request from the server, synchronous |
|
196 // (other items were commented in a header). |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 void RDRMNotifierClient::CancelRequest() |
|
200 { |
|
201 // Send the message. |
|
202 SendReceive( DRMNotifier::ECancelNotification); |
|
203 }; |
|
204 |
|
205 // End of File |