|
1 // Copyright (c) 2005-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 : SIPServerStarter.cpp |
|
15 // Part of : SIPClient |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include <e32math.h> |
|
23 #include "SIPServerStarter.h" |
|
24 #include "sipclientserver.h" |
|
25 #include "sipclient.pan" |
|
26 |
|
27 _LIT(KSipServerStarterMutex, "SipServerStarterMutex"); |
|
28 |
|
29 #define RETURN_IF_ERROR(err) {TInt _err=err; if(_err!=KErrNone) {return _err;}} |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // SIPServerStarter::Start |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 TInt SIPServerStarter::Start () |
|
36 { |
|
37 TInt err = KErrNone; |
|
38 |
|
39 RMutex mutex; |
|
40 err = mutex.CreateGlobal(KSipServerStarterMutex); |
|
41 if (err != KErrNone) |
|
42 { |
|
43 err = mutex.OpenGlobal(KSipServerStarterMutex); |
|
44 if (err != KErrNone) |
|
45 { |
|
46 return err; |
|
47 } |
|
48 } |
|
49 mutex.Wait(); |
|
50 { |
|
51 // Protected with a mutex |
|
52 TFindServer findServer(KSipServerName); |
|
53 TFullName name; |
|
54 if (findServer.Next(name) == KErrNone) |
|
55 { |
|
56 mutex.Signal(); |
|
57 mutex.Close(); |
|
58 return KErrNone; // Server already running |
|
59 } |
|
60 |
|
61 RSemaphore semaphore; |
|
62 err = semaphore.CreateGlobal(KSipServerSemaphoreName,0); |
|
63 if (err == KErrNone) |
|
64 { |
|
65 err = CreateServerProcess(semaphore); |
|
66 semaphore.Close(); |
|
67 } |
|
68 } |
|
69 mutex.Signal(); |
|
70 mutex.Close(); |
|
71 |
|
72 return err; |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // SIPServerStarter::CreateServerProcess |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 TInt SIPServerStarter::CreateServerProcess (RSemaphore& aSemaphore) |
|
80 { |
|
81 const TUidType serverUid (KNullUid, KNullUid, KServerUid3); |
|
82 RProcess server; |
|
83 RETURN_IF_ERROR(server.Create(KSipServerName,KNullDesC,serverUid)) |
|
84 server.Resume (); |
|
85 aSemaphore.Wait(); |
|
86 TInt exitReason = server.ExitReason(); |
|
87 server.Close (); |
|
88 return exitReason; |
|
89 } |