|
1 // Copyright (c) 2003-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 // CStartServer Client side header |
|
15 // Implements an active object to asynchronously start server process, |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalAll |
|
22 */ |
|
23 |
|
24 #include "CA_StartServer.h" |
|
25 #include "CS_AsyncConnect.h" |
|
26 |
|
27 EXPORT_C CStartServer::CStartServer(RAsyncConnectBase& aAsyncConnectBase, const TVersion& aVersion, TInt aAsyncMessageSlots) : |
|
28 CActive(EPriorityStandard), |
|
29 iAsyncConnectBase(aAsyncConnectBase), |
|
30 iVersion(aVersion), |
|
31 iAsyncMessageSlots(aAsyncMessageSlots) |
|
32 /** |
|
33 * Constructor |
|
34 * |
|
35 * @internalTechnology |
|
36 * |
|
37 * @param aAsyncConnectBase the client side server object |
|
38 * @param aVersion the desired version of the server |
|
39 * @param aAsyncMessageSlots number of messages to allocate in client server message queue |
|
40 * |
|
41 */ |
|
42 { |
|
43 CActiveScheduler::Add(this); |
|
44 } |
|
45 |
|
46 EXPORT_C CStartServer::~CStartServer() |
|
47 { |
|
48 Cancel(); |
|
49 } |
|
50 |
|
51 EXPORT_C void CStartServer::Cancel() |
|
52 { |
|
53 iStartProcess.Cancel(); |
|
54 } |
|
55 |
|
56 void CStartServer::DoCancel() |
|
57 {//never !! |
|
58 __ASSERT_DEBUG( EFalse, User::Panic( KNullDesC, KErrGeneral ) ); |
|
59 } |
|
60 |
|
61 void CStartServer::RunL() |
|
62 { |
|
63 if ( iStartProcess.ErrorCode() == KErrCancel ) |
|
64 {//request has been canceled |
|
65 User::RequestComplete(iClientStatus, KErrCancel); |
|
66 } |
|
67 else if (!iProcessStarting && (iStatus.Int()==KErrNotFound || iStatus.Int()==KErrServerTerminated)) |
|
68 { |
|
69 iProcessStarting = 1; |
|
70 iStartProcess.Start(iName, iStatus); |
|
71 SetActive(); |
|
72 //wait for the server to start |
|
73 } |
|
74 else if (iProcessStarting && ((iStatus.Int() == KErrAlreadyExists && ++iCounter < iAttempts) || iStatus.Int() == KErrNone)) |
|
75 { |
|
76 Connect(iName); |
|
77 //wait for the Connect to complete |
|
78 } |
|
79 else |
|
80 {//complete the connection with an error |
|
81 User::RequestComplete(iClientStatus, iStatus.Int()); |
|
82 } |
|
83 } |
|
84 |
|
85 void CStartServer::Connect(const TDesC& aServerName) |
|
86 { |
|
87 iAsyncConnectBase.CreateSession(aServerName, iVersion, iAsyncMessageSlots, iStatus); |
|
88 iName.Des().Copy( aServerName ); |
|
89 iProcessStarting = 0; |
|
90 SetActive(); |
|
91 } |
|
92 |
|
93 EXPORT_C void CStartServer::Connect(const TDesC& aServerName, TRequestStatus& aStatus, TUint aAttempts) |
|
94 /** |
|
95 * The Start method |
|
96 * |
|
97 * Connect the Handle to the Server and asynchronously starts the server if neccessary |
|
98 * |
|
99 * @internalTechnology |
|
100 * |
|
101 * @param aServerName name of the server, no file extension |
|
102 * @param aStatus a request of the client waiting for server to connect |
|
103 * @param aAttempts how many times to try to connect |
|
104 * |
|
105 */ |
|
106 { |
|
107 iAttempts = aAttempts; |
|
108 iClientStatus = &aStatus; |
|
109 *iClientStatus = KRequestPending; |
|
110 iCounter = 0; |
|
111 Connect(aServerName); |
|
112 } |
|
113 |