author | mikaruus <mika.a.ruuskanen@nokia.com> |
Wed, 17 Feb 2010 13:58:55 +0200 | |
changeset 7 | fa67e03b87df |
parent 5 | 8ccc39f9d787 |
child 9 | 8486d82aef45 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (c) 2009 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 the License "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: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
// INCLUDE FILES |
|
19 |
#include "rusbpnclient.h" |
|
20 |
#include "cusbpnserver.h" |
|
21 |
#include "usbpndefinitions.h" |
|
22 |
#include "usbpntrace.h" |
|
23 |
||
5
8ccc39f9d787
New release based on our 2010wk02 release
mikaruus <mika.a.ruuskanen@nokia.com>
parents:
0
diff
changeset
|
24 |
#include "OstTraceDefinitions.h" |
0 | 25 |
#ifdef OST_TRACE_COMPILER_IN_USE |
26 |
#include "rusbpnclientTraces.h" |
|
27 |
#endif |
|
28 |
||
29 |
||
30 |
// EXTERNAL DATA STRUCTURES |
|
31 |
// EXTERNAL FUNCTION PROTOTYPES |
|
32 |
// CONSTANTS |
|
33 |
// MACROS |
|
34 |
// LOCAL CONSTANTS AND MACROS |
|
35 |
// MODULE DATA STRUCTURES |
|
36 |
// LOCAL FUNCTION PROTOTYPES |
|
37 |
// FORWARD DECLARATIONS |
|
38 |
||
39 |
// ============================= LOCAL FUNCTIONS =============================== |
|
40 |
// ============================ MEMBER FUNCTIONS =============================== |
|
41 |
||
42 |
// ----------------------------------------------------------------------------- |
|
43 |
// RUsbPnClient::RUsbPnClient |
|
44 |
// C++ default constructor can NOT contain any code, that |
|
45 |
// might leave. |
|
46 |
// ----------------------------------------------------------------------------- |
|
47 |
// |
|
48 |
EXPORT_C RUsbPnClient::RUsbPnClient() |
|
49 |
:RSessionBase() |
|
50 |
{ |
|
51 |
} |
|
52 |
||
53 |
// ----------------------------------------------------------------------------- |
|
54 |
// RUsbPnClient::ConnectL |
|
55 |
// (other items were commented in a header). |
|
56 |
// ----------------------------------------------------------------------------- |
|
57 |
// |
|
58 |
EXPORT_C void RUsbPnClient::ConnectL() |
|
59 |
{ |
|
60 |
OstTrace0( TRACE_API, RUSBPNCLIENT_CONNECTL_ENTRY, "RUsbPnClient::ConnectL" ); |
|
61 |
A_TRACE( ( _T( "RUsbPnClient::ConnectL()" ) ) ); |
|
62 |
||
63 |
TInt err( KErrNone ); |
|
64 |
||
65 |
// Create USB Phonet Link Server session |
|
66 |
err = CreateSession( KUsbPnServerName, TVersion(1,0,0)); |
|
67 |
||
68 |
if ( err == KErrNotFound ) |
|
69 |
{ |
|
70 |
// Session not created |
|
71 |
||
72 |
// Find lock semaphore for server process creation |
|
73 |
TFindSemaphore lock( KUsbPnServerName ); |
|
74 |
TFullName semaphoreName; |
|
75 |
err = lock.Next( semaphoreName ); |
|
76 |
||
77 |
if ( err == KErrNotFound ) |
|
78 |
{ |
|
79 |
// Lock is not enabled |
|
80 |
OstTrace0( TRACE_DETAILED, RUSBPNCLIENT_CONNECTL, "RUsbPnClient::ConnectL() - semaphore not found, start server" ); |
|
81 |
E_TRACE( ( _L( "RUsbPnClient::ConnectL() - semaphore not found, start server" ) ) ); |
|
82 |
||
83 |
RSemaphore startLock; |
|
84 |
||
85 |
// Create lock |
|
86 |
User::LeaveIfError( startLock.CreateGlobal( KUsbPnServerName, 0, EOwnerProcess ) ); |
|
87 |
||
88 |
||
89 |
/********************************************/ |
|
90 |
/* Start the USB Phonet Link process process */ |
|
91 |
TRequestStatus status; |
|
92 |
RProcess server; |
|
93 |
||
94 |
User::LeaveIfError( server.Create( KUsbPnServerName, TPtrC( NULL, 0), |
|
95 |
EOwnerThread ) ); |
|
96 |
||
97 |
server.Rendezvous( status ); |
|
98 |
||
99 |
if( status != KRequestPending ) |
|
100 |
{ |
|
101 |
server.Kill(0); // Abort startup |
|
102 |
} |
|
103 |
else |
|
104 |
{ |
|
105 |
server.Resume(); // Logon OK -> start the server |
|
106 |
} |
|
107 |
||
108 |
OstTrace0( TRACE_DETAILED, RUSBPNCLIENT_CONNECTL_DUP1, "RUsbPnClient::ConnectL() - waiting server response" ); |
|
109 |
E_TRACE( ( _T( "RUsbPnClient::ConnectL() - waiting server response" ) ) ); |
|
110 |
User::WaitForRequest( status ); // Wait for start or death |
|
111 |
||
112 |
// we can't use the 'exit reason' if the server panicked as this |
|
113 |
// is the panic 'reason' and may be '0' which cannot be distinguished |
|
114 |
// from KErrNone |
|
115 |
TInt err = status.Int(); |
|
116 |
if (err == KErrNone && (server.ExitType() == EExitPanic || server.ExitType() == EExitKill)) |
|
117 |
{ |
|
118 |
err = KErrServerTerminated; |
|
119 |
} |
|
120 |
||
121 |
server.Close(); |
|
122 |
||
123 |
if( err ) |
|
124 |
{ |
|
125 |
OstTrace1( TRACE_DETAILED, RUSBPNCLIENT_CONNECTL_DUP2, "RUsbPnClient::ConnectL() - waiting server response status; err=%d", err ); |
|
126 |
E_TRACE( ( _T( "RUsbPnClient::ConnectL() - waiting server response status: %d" ), err ) ); |
|
127 |
TRACE_ASSERT_ALWAYS; |
|
128 |
User::LeaveIfError( err ); |
|
129 |
} |
|
130 |
/* End of starting process */ |
|
131 |
/********************************************/ |
|
132 |
||
133 |
OstTrace0( TRACE_DETAILED, RUSBPNCLIENT_CONNECTL_DUP3, "RUsbPnClient::ConnectL() - server is started, signal other clients" ); |
|
134 |
E_TRACE( ( _L( "RUsbPnClient::ConnectL() - server is started, signal other clients" ) ) ); |
|
135 |
// Signal other clients |
|
136 |
startLock.Signal( KMaxTInt ); |
|
137 |
||
138 |
// Close semaphore |
|
139 |
startLock.Close(); |
|
140 |
} |
|
141 |
else |
|
142 |
{ |
|
143 |
// Lock is enabled |
|
144 |
||
145 |
RSemaphore startLock; |
|
146 |
||
147 |
// Open lock semaphore |
|
148 |
User::LeaveIfError( startLock.Open( lock ) ); |
|
149 |
||
150 |
OstTrace0( TRACE_DETAILED, RUSBPNCLIENT_CONNECTL_DUP4, "RUsbPnClient::ConnectL() - server is starting, wait for signal" ); |
|
151 |
E_TRACE( ( _L( "RUsbPnClient::ConnectL() - server is starting, wait for signal" ) ) ); |
|
152 |
// Wait for signal |
|
153 |
startLock.Wait(); |
|
154 |
OstTrace0( TRACE_DETAILED, RUSBPNCLIENT_CONNECTL_DUP5, "RUsbPnClient::ConnectL() - signal received" ); |
|
155 |
E_TRACE( ( _L( "RUsbPnClient::ConnectL() - signal received" ) ) ); |
|
156 |
||
157 |
// Close semaphore |
|
158 |
startLock.Close(); |
|
159 |
||
160 |
} |
|
161 |
||
162 |
// Create USB Phonet Link server session |
|
163 |
OstTrace0( TRACE_DETAILED, RUSBPNCLIENT_CONNECTL_DUP6, "RUsbPnClient::ConnectL() - Create session" ); |
|
164 |
E_TRACE( ( _L( "RUsbPnClient::ConnectL() - Create session" ) ) ); |
|
165 |
||
166 |
User::LeaveIfError( CreateSession( KUsbPnServerName, TVersion(1,0,0) ) ); |
|
167 |
||
7
fa67e03b87df
New release based on our 2010wk08 release
mikaruus <mika.a.ruuskanen@nokia.com>
parents:
5
diff
changeset
|
168 |
OstTrace0( TRACE_DETAILED, RUSBPNCLIENT_CONNECTL_DUP7, "RUsbPnClient::ConnectL() - session created1" ); |
fa67e03b87df
New release based on our 2010wk08 release
mikaruus <mika.a.ruuskanen@nokia.com>
parents:
5
diff
changeset
|
169 |
E_TRACE( ( _L( "RUsbPnClient::ConnectL() - session created1" ) ) ); |
0 | 170 |
} |
171 |
else if ( err ) |
|
172 |
{ |
|
7
fa67e03b87df
New release based on our 2010wk08 release
mikaruus <mika.a.ruuskanen@nokia.com>
parents:
5
diff
changeset
|
173 |
OstTrace0( TRACE_DETAILED, RUSBPNCLIENT_CONNECTL_DUP8, "RUsbPnClient::ConnectL() - session not created, reason uknown" ); |
fa67e03b87df
New release based on our 2010wk08 release
mikaruus <mika.a.ruuskanen@nokia.com>
parents:
5
diff
changeset
|
174 |
E_TRACE( ( _L( "RUsbPnClient::ConnectL() - session not created, reason uknown" ) ) ); |
0 | 175 |
TRACE_ASSERT_ALWAYS; |
176 |
User::Leave( err ); |
|
177 |
} |
|
178 |
else |
|
179 |
{ |
|
7
fa67e03b87df
New release based on our 2010wk08 release
mikaruus <mika.a.ruuskanen@nokia.com>
parents:
5
diff
changeset
|
180 |
OstTrace0( TRACE_DETAILED, RUSBPNCLIENT_CONNECTL_DUP9, "RUsbPnClient::ConnectL() - session created2" ); |
fa67e03b87df
New release based on our 2010wk08 release
mikaruus <mika.a.ruuskanen@nokia.com>
parents:
5
diff
changeset
|
181 |
E_TRACE( ( _T( "RUsbPnClient::ConnectL() - session created2" ) ) ); |
0 | 182 |
} |
183 |
OstTrace0( TRACE_API, RUSBPNCLIENT_CONNECTL_EXIT, "RUsbPnClient::ConnectL() - return void" ); |
|
184 |
A_TRACE( ( _T( "RUsbPnClient::ConnectL() - return void" ) ) ); |
|
185 |
} |
|
186 |
||
187 |
//----------------------------------------------------------------------------- |
|
188 |
// RPtp::DestroyPtpStatck() |
|
189 |
// Destroy PTP stack |
|
190 |
//----------------------------------------------------------------------------- |
|
191 |
// |
|
192 |
EXPORT_C void RUsbPnClient::Detach() |
|
193 |
{ |
|
194 |
OstTrace0( TRACE_API, RUSBPNCLIENT_DETACH_ENTRY, "RUsbPnClient::Detach" ); |
|
195 |
A_TRACE( ( _T( "RUsbPnClient::Disconnect()" ) ) ); |
|
196 |
SendReceive( EPnDetach ); |
|
197 |
// close the session |
|
198 |
RSessionBase::Close(); |
|
199 |
OstTrace0( TRACE_API, RUSBPNCLIENT_DETACH_EXIT, "RUsbPnClient::Detach - return void" ); |
|
200 |
A_TRACE( ( _T( "RUsbPnClient::Disconnect() - return void" ) ) ); |
|
201 |
} |
|
202 |
||
203 |
||
204 |
// ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
205 |
||
206 |
// End of File |