|
1 /** @file |
|
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: Implementation of RUpnpSessionBase |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "upnpsessionbase.h" |
|
19 // ======== LOCAL FUNCTIONS ======== |
|
20 #include "upnpcustomlog.h" |
|
21 |
|
22 // ----------------------------------------------------------------------------- |
|
23 // StartServer |
|
24 // Static method to start the server. |
|
25 // Start the server process. Simultaneous launching |
|
26 // of two such processes should be detected when the second one attempts to |
|
27 // create the server object, failing with KErrAlreadyExists. |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 static TInt StartServer( TUid aUid3, const TDesC& aFileName ) |
|
31 { |
|
32 const TUidType serverUid( KNullUid, KNullUid, aUid3 ); |
|
33 RProcess server; |
|
34 TInt r = server.Create( aFileName, KNullDesC, serverUid ); |
|
35 if ( r != KErrNone ) |
|
36 { |
|
37 return r; |
|
38 } |
|
39 TRequestStatus stat; |
|
40 server.Rendezvous( stat ); |
|
41 if ( stat != KRequestPending ) |
|
42 { |
|
43 server.Kill( 0 ); // abort startup |
|
44 } |
|
45 else |
|
46 { |
|
47 server.Resume(); // logon OK - start the server |
|
48 } |
|
49 User::WaitForRequest( stat ); // wait for start or death |
|
50 // we can't use the 'exit reason' if the server panicked as this |
|
51 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
52 // from KErrNone |
|
53 r = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int(); |
|
54 server.Close(); |
|
55 return r; |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // RUpnpSessionBase::Connect |
|
60 // Connect to the server, attempting to start it if necessary |
|
61 // ----------------------------------------------------------------------------- |
|
62 EXPORT_C TInt RUpnpSessionBase::Connect( const TDesC& aServerName, TVersion aServerVersion, |
|
63 TInt aServerMessageSlots, TInt aServerStartRetryCount, |
|
64 const TDesC& aServerFileName, TUid aServerUid3 ) |
|
65 { |
|
66 TInt retry = aServerStartRetryCount; |
|
67 for ( ;; ) |
|
68 { |
|
69 TInt r = CreateSession( aServerName, aServerVersion, aServerMessageSlots ); |
|
70 if ( r != KErrNotFound && r != KErrServerTerminated ) |
|
71 { |
|
72 return r; |
|
73 } |
|
74 if ( --retry == 0 ) |
|
75 { |
|
76 return r; |
|
77 } |
|
78 r = StartServer( aServerUid3, aServerFileName ); |
|
79 if ( r != KErrNone && r != KErrAlreadyExists ) |
|
80 { |
|
81 return r; |
|
82 } |
|
83 } |
|
84 } |