|
1 /* |
|
2 * Copyright (c) 2007 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: Extension to lockapp clients. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "lockaccessextension.h" |
|
20 #include <lockappclientserver.h> |
|
21 #include <e32property.h> // P&S API |
|
22 #include <apgtask.h> // TApaTask, TApaTaskList |
|
23 #include <coemain.h> // CCoeEnv |
|
24 |
|
25 |
|
26 // Constants |
|
27 const TInt KTimesToConnectServer( 2); |
|
28 const TInt KTimeoutBeforeRetrying( 50000); |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // Gets server version, needed for connection |
|
32 // --------------------------------------------------------------------------- |
|
33 TVersion RLockAccessExtension::GetVersion( ) |
|
34 { |
|
35 return TVersion( KLockAppServMajorVersion, KLockAppServMinorVersion, KLockAppServBuildVersion ); |
|
36 } |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // Connects client to lockapp application server |
|
40 // --------------------------------------------------------------------------- |
|
41 TInt RLockAccessExtension::TryConnect( RWsSession& aWsSession ) |
|
42 { |
|
43 TInt ret(KErrNone); |
|
44 TApaTaskList list(aWsSession); |
|
45 // check that lockapp is running |
|
46 TApaTask task = list.FindApp( KLockAppUid ); |
|
47 if ( task.Exists( ) ) |
|
48 { |
|
49 if ( Handle( )== NULL ) |
|
50 { |
|
51 // connect session to the server |
|
52 ret = CreateSession( KLockAppServerName, GetVersion( ) ); |
|
53 } |
|
54 else |
|
55 { |
|
56 // not CreateSession because Handle( ) not NULL |
|
57 } |
|
58 } |
|
59 else |
|
60 { |
|
61 // LockApp task not found |
|
62 RDebug::Printf( "%s %s (%u) ???? LockApp task not found=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, KLockAppUid ); |
|
63 ret = KErrNotReady; |
|
64 } |
|
65 return ret; |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // Ensures that the connection to the service is alive. |
|
70 // --------------------------------------------------------------------------- |
|
71 TInt RLockAccessExtension::EnsureConnected( ) |
|
72 { |
|
73 TInt ret(KErrNone); |
|
74 // we need CCoeEnv because of window group list |
|
75 CCoeEnv* coeEnv = CCoeEnv::Static( ); |
|
76 if ( coeEnv ) |
|
77 { |
|
78 // All server connections are tried to be made KTriesToConnectServer times because |
|
79 // occasional fails on connections are possible at least on some servers |
|
80 TInt retry(0); |
|
81 while ( (ret = TryConnect( coeEnv->WsSession( ) ) ) != KErrNone && |
|
82 (retry++) <= KTimesToConnectServer ) |
|
83 { |
|
84 User::After( KTimeoutBeforeRetrying ); |
|
85 } |
|
86 // the connection state gets returned |
|
87 } |
|
88 else |
|
89 { |
|
90 // No CCoeEnv |
|
91 ret = KErrNotSupported; |
|
92 } |
|
93 return ret; |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // Sends blind message to lockapp if the session is connected. |
|
98 // --------------------------------------------------------------------------- |
|
99 TInt RLockAccessExtension::SendMessage( TInt aMessage ) |
|
100 { |
|
101 TInt ret = EnsureConnected( ); |
|
102 if ( ret == KErrNone ) |
|
103 { |
|
104 ret = SendReceive( aMessage ); |
|
105 } |
|
106 return ret; |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // Sends blind message to lockapp if the session is connected. |
|
111 // --------------------------------------------------------------------------- |
|
112 TInt RLockAccessExtension::SendMessage( TInt aMessage, TInt aParam1 ) |
|
113 { |
|
114 TInt ret = EnsureConnected( ); |
|
115 if ( ret == KErrNone ) |
|
116 { |
|
117 // assign parameters to IPC argument |
|
118 TIpcArgs args(aParam1); |
|
119 ret = SendReceive( aMessage, args ); |
|
120 } |
|
121 return ret; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // Sends blind message to lockapp if the session is connected. |
|
126 // --------------------------------------------------------------------------- |
|
127 TInt RLockAccessExtension::SendMessage( TInt aMessage, TInt aParam1, TInt aParam2 ) |
|
128 { |
|
129 TInt ret = EnsureConnected( ); |
|
130 if ( ret == KErrNone ) |
|
131 { |
|
132 // assign parameters to IPC argument |
|
133 TIpcArgs args( aParam1, aParam2); |
|
134 ret = SendReceive( aMessage, args ); |
|
135 } |
|
136 return ret; |
|
137 } |
|
138 |
|
139 // End of File |