watchdog/src/watchdog.cpp
changeset 21 50bf9db68373
parent 0 c53acadfccc6
child 28 c461c7fa72c2
--- a/watchdog/src/watchdog.cpp	Fri Mar 19 09:38:01 2010 +0200
+++ b/watchdog/src/watchdog.cpp	Fri Apr 16 15:23:55 2010 +0300
@@ -89,20 +89,46 @@
     PRINT(_L("CWatchdog::ConstructL() - create observer"));
     iShutdownObserver = CWDShutdownObserver::NewL( *this );        
     iSelfShutdownObserver = CWDSelfShutdownObserver::NewL( *this ); 
-    
-    RProcess process;
-    process.SetPriority( EPriorityBackground );
-    process.Close();
     }
 
 void CWatchdog::Start()
-    {
-    
+    {  
     PRINT(_L("CWatchdog::Start()"));
 
-    // Create the server process
+    // Double check that harvester server is not already running
+    TFullName name;
     TInt res( KErrNone );
+   
+    // find really Harvester Server, using TFindServer to avoid logon a dead process
+    TFindServer findServer( KHarvesterServerProcess );
+    if ( findServer.Next(name) == KErrNone )
+        {
+        TFindProcess findProcess( KHarvesterServerProcess );
+        if ( findProcess.Next(name) == KErrNone )
+            {
+            PRINT(_L("CWatchdog::Start() - server already running, start listening"));
+            
+            iProcess.Close();
+            res = iProcess.Open(name);
+            if ( res != KErrNone )
+                {
+                PRINT(_L("CWatchdog::Start() - error in starting listening "));
+                return;
+                }
+            iState = EWaitingRendezvous;
+            SetActive();
+            return;
+            }
+        }  
     
+    // close the panic process
+    TFindProcess findProcess( KHarvesterServerProcess );
+    if ( findProcess.Next(name) == KErrNone )
+        {                
+        iProcess.Close();
+        }
+
+    // Create the server process
     // KNullDesC param causes server's E32Main() to be run
     res = iProcess.Create( KHarvesterServerExe, KNullDesC );
     if ( res != KErrNone )
@@ -189,8 +215,7 @@
               }
             
           default:
-              break;
-              
+              break; 
           
     	}