|
1 /* |
|
2 * Copyright (c) 2010 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: This application is to monitor Harvester and Search Server |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "CWDmonitor.h" |
|
19 #include "WatchDogCommon.h" |
|
20 #include "CWDTimer.h" |
|
21 #include <HarvesterServerLogger.h> |
|
22 // ----------------------------------------------------------------------------- |
|
23 // CWDMonitor::NewL |
|
24 // ----------------------------------------------------------------------------- |
|
25 // |
|
26 CWDMonitor* CWDMonitor::NewL( ) |
|
27 { |
|
28 CWDMonitor* self = CWDMonitor::NewLC( ); |
|
29 CleanupStack::Pop(); |
|
30 return self; |
|
31 } |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CWDMonitor::NewLC |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CWDMonitor* CWDMonitor::NewLC( ) |
|
37 { |
|
38 CWDMonitor* self = new ( ELeave ) CWDMonitor( ); |
|
39 CleanupStack::PushL( self ); |
|
40 self->ConstructL(); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CWDMonitor::~CWDMonitor() |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CWDMonitor::~CWDMonitor() |
|
49 { |
|
50 delete iWDTimer; |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CWDMonitor::CWDMonitor() |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CWDMonitor::CWDMonitor( ) |
|
58 { |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CWDMonitor::ConstructL() |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CWDMonitor::ConstructL() |
|
66 { |
|
67 iWDTimer = CWDTimer::NewL( this ); |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CWDMonitor::StartMonitor() |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 void CWDMonitor::HandleWDTimerL() |
|
75 { |
|
76 CPIXLOGSTRING("CWDMonitor::HandleWDTimerL(): Check the servers"); |
|
77 TFindServer harvesterServer(KHarvesterServer); |
|
78 TFindServer searchServer(KSearchServer); |
|
79 |
|
80 TFullName name; |
|
81 |
|
82 if ( harvesterServer.Next(name) != KErrNone) |
|
83 { |
|
84 CPIXLOGSTRING("Harvester Server is down, Starting Harvester Server"); |
|
85 //Harvester server is not running. |
|
86 //Start Harvester server |
|
87 StartServer( KHarvesterServer , KHServerUid3 ,KHarvesterServerSemaphoreName); |
|
88 } |
|
89 else if ( searchServer.Next( name ) != KErrNone) |
|
90 { |
|
91 CPIXLOGSTRING("Search Server is down, Starting Search Server"); |
|
92 //Search server is not running. |
|
93 //Start search server |
|
94 StartServer( KSearchServer , KSServerUid3 ,KSearchServerSemaphoreName); |
|
95 } |
|
96 return; |
|
97 } |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CWDMonitor::StartMonitor() |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void CWDMonitor::StartMonitor() |
|
103 { |
|
104 CPIXLOGSTRING("CWDMonitor::StartMonitor(): Entered"); |
|
105 iWDTimer->StartWDTimer(); |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CWDMonitor::StartServer() |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 TInt CWDMonitor::StartServer( const TDesC& aServerName , TUid aServerUid , |
|
113 const TDesC& aSemaphoreName) |
|
114 { |
|
115 RSemaphore semaphore; |
|
116 TInt result = semaphore.CreateGlobal(aSemaphoreName, 0); |
|
117 if (result != KErrNone) |
|
118 { |
|
119 return result; |
|
120 } |
|
121 |
|
122 result = CreateServerProcess( aServerName , aServerUid); |
|
123 if (result != KErrNone) |
|
124 { |
|
125 return result; |
|
126 } |
|
127 |
|
128 semaphore.Wait(); |
|
129 semaphore.Close(); |
|
130 return result; |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CWDMonitor::CreateServerProcess() |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 TInt CWDMonitor::CreateServerProcess( const TDesC& aServerName , TUid aServerUid ) |
|
138 { |
|
139 TInt result; |
|
140 |
|
141 const TUidType serverUid( KNullUid, KNullUid, aServerUid); |
|
142 |
|
143 RProcess server; |
|
144 |
|
145 result = server.Create(aServerName, KNullDesC, serverUid); |
|
146 if (result != KErrNone) |
|
147 { |
|
148 return result; |
|
149 } |
|
150 |
|
151 server.Resume(); |
|
152 server.Close(); |
|
153 return KErrNone; |
|
154 } |
|
155 |
|
156 //End of file |