|
1 // Copyright (c) 2010 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 "mediaclientpolicyserversession.h" |
|
17 #include <e32std.h> |
|
18 #include "mediaclientvideotrace.h" |
|
19 |
|
20 // Policy Server EXE name |
|
21 _LIT( KIvePolicyServerImg, "ivepolicyserver" ); |
|
22 |
|
23 // Policy Server thread name |
|
24 _LIT( KIvePolicyServerName, "!ivepolicyserver0x10204C27" ); |
|
25 |
|
26 // Number of asynchronous message slots |
|
27 const TInt KIveAsyncMessageSlots = 1; |
|
28 |
|
29 static TInt StartServer() |
|
30 { |
|
31 DEBUG_PRINTF("medialclientsession StartServer +++"); |
|
32 |
|
33 RProcess server; |
|
34 TInt error = server.Create(KIvePolicyServerImg, KNullDesC); |
|
35 if (error != KErrNone) |
|
36 { |
|
37 DEBUG_PRINTF2("medialclientsession StartServer server creation failed %d", error); |
|
38 return error; |
|
39 } |
|
40 |
|
41 TRequestStatus status; |
|
42 |
|
43 server.Rendezvous(status); |
|
44 if (status != KRequestPending) |
|
45 { |
|
46 server.Kill( 0 ); |
|
47 // abort startup |
|
48 } |
|
49 else |
|
50 { |
|
51 server.Resume(); |
|
52 // logon OK - start the server |
|
53 } |
|
54 |
|
55 User::WaitForRequest(status); |
|
56 // wait for start or death |
|
57 error = (server.ExitType() == EExitPanic) ? KErrGeneral : status.Int(); |
|
58 server.Close(); |
|
59 |
|
60 DEBUG_PRINTF(" medialclientsession StartServer ---"); |
|
61 return error; |
|
62 } |
|
63 |
|
64 RMediaClientPolicyServerSession::RMediaClientPolicyServerSession(): |
|
65 RSessionBase() |
|
66 { |
|
67 DEBUG_PRINTF(" RMediaClientPolicyServerSession::RMediaClientPolicyServerSession +++"); |
|
68 DEBUG_PRINTF(" RMediaClientPolicyServerSession::RMediaClientPolicyServerSession ---"); |
|
69 } |
|
70 |
|
71 TInt RMediaClientPolicyServerSession::Connect() |
|
72 { |
|
73 DEBUG_PRINTF(" RMediaClientPolicyServerSession::Connect +++"); |
|
74 |
|
75 TInt error = KErrNone; |
|
76 for (TInt i = 0; i < 2; i++) |
|
77 { |
|
78 // Try to create session. |
|
79 error = CreateSession(KIvePolicyServerName, TVersion( 0, 0, 0 ), KIveAsyncMessageSlots); |
|
80 |
|
81 if (error != KErrNotFound && error != KErrServerTerminated) |
|
82 { |
|
83 DEBUG_PRINTF("RMediaClientPolicyServerSession::Connect Server found and session created."); |
|
84 DEBUG_PRINTF2("RMediaClientPolicyServerSession::Connect --- returns %d", error); |
|
85 return error; |
|
86 } |
|
87 |
|
88 // If session failed, try to start server once. |
|
89 if (i == 0) |
|
90 { |
|
91 DEBUG_PRINTF("RMediaClientPolicyServerSession::Connect StartServer"); |
|
92 // Start server |
|
93 error = StartServer(); |
|
94 if (error != KErrNone && error != KErrAlreadyExists) |
|
95 { |
|
96 DEBUG_PRINTF("RMediaClientPolicyServerSession::Connect Server startup failed."); |
|
97 DEBUG_PRINTF2("RMediaClientPolicyServerSession::Connect --- returns %d", error); |
|
98 return error; |
|
99 } |
|
100 } |
|
101 else |
|
102 { |
|
103 DEBUG_PRINTF2("RMediaClientPolicyServerSession::Connect Session creation failed error %d", error); |
|
104 } |
|
105 } |
|
106 |
|
107 DEBUG_PRINTF2("RMediaClientPolicyServerSession::Connect --- returns %d", error); |
|
108 return error; |
|
109 } |
|
110 |
|
111 TInt RMediaClientPolicyServerSession::SendMessage( TInt aFunction, const TIpcArgs &aArgs ) const |
|
112 { |
|
113 DEBUG_PRINTF("RMediaClientPolicyServerSession::SendMessage +++"); |
|
114 |
|
115 TInt error = SendReceive( aFunction, aArgs ); |
|
116 |
|
117 DEBUG_PRINTF2("RMediaClientPolicyServerSession::SendMessage --- returns %d", error); |
|
118 return error; |
|
119 } |