|
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: Base class to connect with server AVCPEngine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32math.h> |
|
21 #include "upnpavcpengineclient.h" |
|
22 |
|
23 #include <Uri16.h> |
|
24 |
|
25 // Number of message slots to reserve for this client server session. |
|
26 const TUint KDefaultMessageSlots = 10; |
|
27 const TUid KServerUid3 = {0x101F977A}; |
|
28 |
|
29 // Function prototypes |
|
30 static TInt StartServer( void ); |
|
31 static TInt CreateServerProcess( void ); |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // RUpnpAVCPEngineClient::RUpnpAVCPEngineClient |
|
35 // C++ default constructor can NOT contain any code, that |
|
36 // might leave. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 RUpnpAVCPEngineClient::RUpnpAVCPEngineClient() |
|
40 :RSessionBase() |
|
41 { |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // RUpnpAVCPEngineClient::Connect |
|
46 // Connect to ... session. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 EXPORT_C TInt RUpnpAVCPEngineClient::Connect() |
|
50 { |
|
51 TInt error = ::StartServer(); |
|
52 |
|
53 if ( KErrNone == error ) |
|
54 { |
|
55 error = CreateSession( KAVCPEngineName, |
|
56 Version(), |
|
57 KDefaultMessageSlots ); |
|
58 } |
|
59 return error; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // RUpnpAVCPEngineClient::Version |
|
64 // Version information. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 TVersion RUpnpAVCPEngineClient::Version() const |
|
68 { |
|
69 return( TVersion( KAVCPEngineMajorVersionNumber, |
|
70 KAVCPEngineMinorVersionNumber, |
|
71 KAVCPEngineBuildVersionNumber ) ); |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // StartServer |
|
76 // Static method to start the server. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 static TInt StartServer() |
|
80 { |
|
81 TInt result; |
|
82 |
|
83 TFindServer findMessageHandler( KAVCPEngineName ); |
|
84 TFullName name; |
|
85 |
|
86 result = findMessageHandler.Next( name ); |
|
87 if ( result == KErrNone ) |
|
88 { |
|
89 // Server already running |
|
90 return KErrNone; |
|
91 } |
|
92 result = CreateServerProcess(); |
|
93 if ( result != KErrNone ) |
|
94 { |
|
95 return result; |
|
96 } |
|
97 return KErrNone; |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CreateServerProcess |
|
102 // Static method to create the server process. |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 static TInt CreateServerProcess() |
|
106 { |
|
107 TInt result; |
|
108 |
|
109 const TUidType serverUid( KNullUid, KNullUid, KServerUid3 ); |
|
110 RProcess server; |
|
111 |
|
112 result = server.Create( KAVCPEngineFilename, KNullDesC, serverUid ); |
|
113 if ( result != KErrNone ) |
|
114 { |
|
115 return result; |
|
116 } |
|
117 |
|
118 TRequestStatus stat = KRequestPending; |
|
119 server.Rendezvous(stat); |
|
120 if ( stat != KRequestPending ) |
|
121 { |
|
122 server.Kill( 0 ); // abort startup |
|
123 } |
|
124 else |
|
125 { |
|
126 server.Resume(); // logon OK - start the server |
|
127 } |
|
128 |
|
129 User::WaitForRequest(stat); // wait for start or death |
|
130 result = (server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); |
|
131 server.Close(); |
|
132 |
|
133 return result; |
|
134 } |
|
135 |
|
136 // End of File |