|
1 /* |
|
2 * Copyright (c) 2005-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: DRM PlayUtility Session |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "mmfdrmSession.h" |
|
20 #include "DRMPlayClientServer.h" |
|
21 |
|
22 #ifdef _DEBUG |
|
23 #define DEP_PRN0(str) RDebug::Print(str) |
|
24 #define DEP_PRN1(str, v1) RDebug::Print(str, v1) |
|
25 #define DEP_PRN2(str, v1, v2) RDebug::Print(str, v1, v2) |
|
26 #else |
|
27 #define DEP_PRN0(str) |
|
28 #define DEP_PRN1(str, v1) |
|
29 #define DEP_PRN2(str, v1, v2) |
|
30 #endif // _DEBUG |
|
31 |
|
32 |
|
33 |
|
34 // Standard server startup code |
|
35 // |
|
36 static TInt StartServer() |
|
37 { |
|
38 DEP_PRN0(_L("DRM Client: Starting server...")); |
|
39 |
|
40 // EPOC is easy, we just create a new server process. Simultaneous |
|
41 // launching of two such processes should be detected when the second one |
|
42 // attempts to create the server object, failing with KErrAlreadyExists. |
|
43 RProcess server; |
|
44 //TInt r=server.Create(KHelloWorldServerImg,KNullDesC,serverUid); |
|
45 TInt r=server.Create(KDRMPlayServerImg,KNullDesC); |
|
46 |
|
47 if (r!=KErrNone) |
|
48 { |
|
49 DEP_PRN1(_L(" DRM Client: server start failed %d"),r); |
|
50 |
|
51 return r; |
|
52 } |
|
53 TRequestStatus stat; |
|
54 server.Rendezvous(stat); |
|
55 if (stat!=KRequestPending) |
|
56 server.Kill(0); // abort startup |
|
57 else |
|
58 server.Resume(); // logon OK - start the server |
|
59 |
|
60 DEP_PRN0(_L("DRM Client: Started")); |
|
61 |
|
62 User::WaitForRequest(stat); // wait for start or death |
|
63 // we can't use the 'exit reason' if the server panicked as this |
|
64 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
65 // from KErrNone |
|
66 r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); |
|
67 server.Close(); |
|
68 return r; |
|
69 } |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 RDrmSession::RDrmSession() |
|
75 { |
|
76 } |
|
77 |
|
78 RDrmSession::~RDrmSession() |
|
79 { |
|
80 if ( Handle() ) |
|
81 { |
|
82 Disconnect(); |
|
83 } |
|
84 } |
|
85 |
|
86 |
|
87 TInt RDrmSession::Connect() |
|
88 { |
|
89 // Try 2 times |
|
90 TInt retry(2); |
|
91 for (;;) |
|
92 { |
|
93 TInt r = CreateSession( KDRMPlayServerName, TVersion(0,0,0), -1); |
|
94 if ((r != KErrNotFound) && (r != KErrServerTerminated) ) |
|
95 return r; |
|
96 if (--retry == 0) |
|
97 return r; |
|
98 r = StartServer(); |
|
99 if (( r!= KErrNone) && (r !=KErrAlreadyExists)) |
|
100 return r; |
|
101 } |
|
102 } |
|
103 |
|
104 void RDrmSession::Disconnect() |
|
105 { |
|
106 RSessionBase::Close(); |
|
107 } |
|
108 |
|
109 TVersion RDrmSession::Version() const |
|
110 { |
|
111 return(TVersion(KDRMPlayServMajorVersionNumber, |
|
112 KDRMPlayServMinorVersionNumber, |
|
113 KDRMPlayServBuildVersionNumber)); |
|
114 } |
|
115 |
|
116 //Sync send no data |
|
117 TInt RDrmSession::Send(TInt aFunction) |
|
118 { |
|
119 TInt status(KErrSessionClosed); |
|
120 if (Handle()) |
|
121 { |
|
122 status = RSessionBase::SendReceive(aFunction); |
|
123 } |
|
124 return status; |
|
125 } |
|
126 |
|
127 //Sync send with data |
|
128 TInt RDrmSession::Send(TInt aFunction,const TIpcArgs& aArgs) |
|
129 { |
|
130 TInt status(KErrSessionClosed); |
|
131 if (Handle()) |
|
132 { |
|
133 status = RSessionBase::SendReceive(aFunction, aArgs); |
|
134 } |
|
135 return status; |
|
136 } |
|
137 |
|
138 //Async send no data |
|
139 void RDrmSession::Send(TInt aFunction,TRequestStatus& aStatus) |
|
140 { |
|
141 if (Handle()) |
|
142 { |
|
143 RSessionBase::SendReceive(aFunction, aStatus); |
|
144 } |
|
145 else |
|
146 { |
|
147 TRequestStatus* s = &aStatus; |
|
148 User::RequestComplete( s , KErrSessionClosed ); |
|
149 } |
|
150 } |
|
151 |
|
152 //Async send with data |
|
153 void RDrmSession::Send(TInt aFunction,const TIpcArgs& aArgs,TRequestStatus& aStatus) |
|
154 { |
|
155 if (Handle()) |
|
156 { |
|
157 RSessionBase::SendReceive(aFunction, aArgs, aStatus); |
|
158 } |
|
159 else |
|
160 { |
|
161 TRequestStatus* s = &aStatus; |
|
162 User::RequestComplete( s , KErrSessionClosed ); |
|
163 } |
|
164 } |
|
165 |
|
166 // End of file |