|
1 // Copyright (c) 2008-2009 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 // Name : signalclient.cpp |
|
15 // Part of : signal server |
|
16 // |
|
17 // |
|
18 |
|
19 #include "signalclient.h" |
|
20 #include "signalcommon.h" |
|
21 #include <e32std.h> |
|
22 |
|
23 // A version must be specified when creating a session with the server |
|
24 |
|
25 const TUint KIpcServerMajorVersionNumber = 1; |
|
26 const TUint KIpcServerMinorVersionNumber = 0; |
|
27 const TUint KIpcServerBuildVersionNumber = 0; |
|
28 |
|
29 _LIT(KServerName,"SignalServer"); |
|
30 const TUid KServerUid3={0x2001F3C8}; |
|
31 |
|
32 static TInt StartServer() |
|
33 { |
|
34 const TUidType serverUid(KNullUid,KNullUid,KServerUid3); |
|
35 RProcess server; |
|
36 TInt r = server.Create(KServerName,KNullDesC); |
|
37 if ( r != KErrNone ) |
|
38 { |
|
39 return r; |
|
40 } |
|
41 TRequestStatus stat; |
|
42 server.Rendezvous(stat); |
|
43 if ( stat != KRequestPending ) |
|
44 { |
|
45 server.Kill(0); // abort startup |
|
46 } |
|
47 else |
|
48 { |
|
49 server.Resume(); // logon OK - start the server |
|
50 } |
|
51 User::WaitForRequest(stat); // wait for start or death |
|
52 |
|
53 // we can't use the 'exit reason' if the server panicked as this |
|
54 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
55 // from KErrNone |
|
56 |
|
57 r = ( server.ExitType() == EExitPanic ) ? KErrGeneral : stat.Int(); |
|
58 server.Close(); |
|
59 return r; |
|
60 } |
|
61 |
|
62 TInt RSignalSession::Connect() |
|
63 { |
|
64 TInt retry = 2; // A maximum of two iterations of the loop required |
|
65 for(;;) |
|
66 { |
|
67 TInt r = CreateSession(KServerName,TVersion(KIpcServerMajorVersionNumber, |
|
68 KIpcServerMinorVersionNumber, |
|
69 KIpcServerBuildVersionNumber), -1, |
|
70 EIpcSession_Sharable); |
|
71 |
|
72 if ( (KErrNotFound != r) && (KErrServerTerminated != r) ) |
|
73 { |
|
74 return r; |
|
75 } |
|
76 if ( --retry == 0 ) |
|
77 { |
|
78 return r; |
|
79 } |
|
80 r = StartServer(); |
|
81 if ( (KErrNone != r) && (KErrAlreadyExists != r) ) |
|
82 { |
|
83 return r; |
|
84 } |
|
85 } |
|
86 } |
|
87 |
|
88 TInt RSignalSession::OnDemandConnection() |
|
89 { |
|
90 TInt err = KErrNone; |
|
91 //On Demand connection |
|
92 if ( !iIsConnected ) |
|
93 { |
|
94 Lock(); |
|
95 if ( !iIsConnected ) |
|
96 { |
|
97 err = Connect (); |
|
98 if ( KErrNone == err) |
|
99 { |
|
100 iIsConnected = ETrue; |
|
101 } |
|
102 } |
|
103 UnLock(); |
|
104 } |
|
105 return err; |
|
106 } |
|
107 |
|
108 TInt RSignalSession::SendSignal(TInt aPid,TInt aSignal) |
|
109 { |
|
110 TInt err = KErrNone; |
|
111 if (KErrNone != OnDemandConnection()) |
|
112 { |
|
113 return KErrGeneral; |
|
114 } |
|
115 err = SendReceive(ESendSignal, TIpcArgs(aPid,aSignal)); |
|
116 return err; |
|
117 } |
|
118 |
|
119 TInt RSignalSession::SendSignalValue(TInt aPid,TInt aSignal,TInt aValue) |
|
120 { |
|
121 TInt err = KErrNone; |
|
122 if (KErrNone != OnDemandConnection()) |
|
123 { |
|
124 return KErrGeneral; |
|
125 } |
|
126 err = SendReceive(ESendSignalValue, TIpcArgs(aPid,aSignal,aValue)); |
|
127 return err; |
|
128 } |
|
129 |
|
130 TInt RSignalSession::SendPipe(RPipe& aPipe) |
|
131 { |
|
132 TInt err = KErrNone; |
|
133 if (KErrNone != OnDemandConnection()) |
|
134 { |
|
135 return KErrGeneral; |
|
136 } |
|
137 err = SendReceive(ESendPipe, TIpcArgs(aPipe)); |
|
138 return err; |
|
139 } |