watchdog/src/cwdmonitor.cpp
changeset 23 d4d56f5e7c55
parent 16 2729d20a0010
child 24 65456528cac2
equal deleted inserted replaced
20:556534771396 23:d4d56f5e7c55
    14 * Description:  This application is to monitor Harvester and Search Server
    14 * Description:  This application is to monitor Harvester and Search Server
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "CWDmonitor.h"
    18 #include "CWDmonitor.h"
    19 #include "WatchDogCommon.h"
       
    20 #include "CWDTimer.h"
    19 #include "CWDTimer.h"
    21 #include <HarvesterServerLogger.h>
    20 #include <HarvesterServerLogger.h>
    22 #include <centralrepository.h>
    21 #include <centralrepository.h>
    23 #include <cpixwatchdogcommon.h>
    22 #include <cpixwatchdogcommon.h>
    24 #include "centrepmonitor.h"
    23 #include "centrepmonitor.h"
       
    24 #include "servermonitor.h"
    25 #include "OstTraceDefinitions.h"
    25 #include "OstTraceDefinitions.h"
    26 #ifdef OST_TRACE_COMPILER_IN_USE
    26 #ifdef OST_TRACE_COMPILER_IN_USE
    27 #include "cwdmonitorTraces.h"
    27 #include "cwdmonitorTraces.h"
    28 #endif
    28 #endif
    29 
    29 
    56 CWDMonitor::~CWDMonitor()
    56 CWDMonitor::~CWDMonitor()
    57     {
    57     {
    58     delete iHSName;
    58     delete iHSName;
    59     delete iSSName;
    59     delete iSSName;
    60     delete iWDTimer;
    60     delete iWDTimer;
       
    61     delete aHSStatusMonitor;
       
    62     delete aSSStatusMonitor;
       
    63     delete aHSUidMonitor;
       
    64     delete aSSUidMonitor;
       
    65     delete aHSNameMonitor;
       
    66     delete aSSNameMonitor;
       
    67     delete iHarvesterMonitor;
       
    68     delete iSearchMonitor;
    61     }
    69     }
    62 
    70 
    63 // -----------------------------------------------------------------------------
    71 // -----------------------------------------------------------------------------
    64 // CWDMonitor::CWDMonitor()
    72 // CWDMonitor::CWDMonitor()
    65 // -----------------------------------------------------------------------------
    73 // -----------------------------------------------------------------------------
   113         }
   121         }
   114     delete wdrepo;
   122     delete wdrepo;
   115     if ( iAllowHS || iAllowSS )
   123     if ( iAllowHS || iAllowSS )
   116         iWDTimer = CWDTimer::NewL( this );
   124         iWDTimer = CWDTimer::NewL( this );
   117     
   125     
   118     aHSMonitor = CentrepMonitor::NewL( this, KHarvesterServerKey);
   126     aHSStatusMonitor = CentrepMonitor::NewL( this, KHarvesterServerKey);
   119     aHSMonitor->StartNotifier();
   127     aHSStatusMonitor->StartNotifier();
   120     aSSMonitor = CentrepMonitor::NewL( this, KSearchServerKey);
   128     aSSStatusMonitor = CentrepMonitor::NewL( this, KSearchServerKey);
   121     aSSMonitor->StartNotifier();
   129     aSSStatusMonitor->StartNotifier();
       
   130     aHSUidMonitor = CentrepMonitor::NewL( this, KHarvesterServerUIDKey);
       
   131     aHSUidMonitor->StartNotifier();
       
   132     aSSUidMonitor = CentrepMonitor::NewL( this, KSearchServerUIDKey);
       
   133     aSSUidMonitor->StartNotifier();
       
   134     aHSNameMonitor = CentrepMonitor::NewL( this, KHarvesterServerNAMEKey);
       
   135     aHSNameMonitor->StartNotifier();
       
   136     aSSNameMonitor = CentrepMonitor::NewL( this, KSearchServerNAMEKey);
       
   137     aSSNameMonitor->StartNotifier();
       
   138     
   122     }
   139     }
   123 
   140 
   124 // -----------------------------------------------------------------------------
   141 // -----------------------------------------------------------------------------
   125 // CWDMonitor::StartMonitor()
   142 // CWDMonitor::StartMonitor()
   126 // -----------------------------------------------------------------------------
   143 // -----------------------------------------------------------------------------
   127 //
   144 //
   128 void CWDMonitor::HandleWDTimerL()
   145 void CWDMonitor::HandleWDTimerL()
   129     {
   146     {
   130     OstTrace0( TRACE_NORMAL, CWDMONITOR_HANDLEWDTIMERL, "CWDMonitor::HandleWDTimerL(): Check the servers" );
   147     OstTrace0( TRACE_NORMAL, CWDMONITOR_HANDLEWDTIMERL, "CWDMonitor::HandleWDTimerL(): Check the servers" );
   131     CPIXLOGSTRING("CWDMonitor::HandleWDTimerL(): Check the servers");
   148     CPIXLOGSTRING("CWDMonitor::HandleWDTimerL(): Check the servers");
   132     TFindServer harvesterServer(*iHSName);
   149 
   133     TFindServer searchServer(*iSSName);
   150     if ( !iHarvesterMonitor )
   134     
   151         {
   135     TFullName name;
   152         if ( iAllowHS )
   136     
   153             iHarvesterMonitor = CServerMonitor::NewL( *iHSName , iHSUid );
   137     if ( iAllowHS && (harvesterServer.Next(name) != KErrNone) )
   154         iWDTimer->StartWDTimer();
   138         {
   155         return;
   139         OstTrace0( TRACE_NORMAL, DUP1_CWDMONITOR_HANDLEWDTIMERL, "Harvester Server is down, Starting Harvester Server" );
   156         }
   140         CPIXLOGSTRING("Harvester Server is down, Starting Harvester Server");
   157     if ( iAllowSS )
   141         //Harvester server is not running. 
   158         iSearchMonitor = CServerMonitor::NewL( *iSSName , iSSUid );
   142         //Start Harvester server
       
   143         StartServer( *iHSName , iHSUid ,KHarvesterServerSemaphoreName);        
       
   144         }
       
   145     else if ( iAllowSS && (searchServer.Next( name ) != KErrNone) )
       
   146         {
       
   147         OstTrace0( TRACE_NORMAL, DUP2_CWDMONITOR_HANDLEWDTIMERL, "Search Server is down, Starting Search Server" );
       
   148         CPIXLOGSTRING("Search Server is down, Starting Search Server");
       
   149         //Search server is not running.
       
   150         //Start search server
       
   151         StartServer( *iSSName , iSSUid ,KSearchServerSemaphoreName);
       
   152         }
       
   153     return;
   159     return;
   154     }
   160     }
   155 // -----------------------------------------------------------------------------
   161 // -----------------------------------------------------------------------------
   156 // CWDMonitor::StartMonitor()
   162 // CWDMonitor::StartMonitor()
   157 // -----------------------------------------------------------------------------
   163 // -----------------------------------------------------------------------------
   161     OstTraceFunctionEntry0( CWDMONITOR_STARTMONITOR_ENTRY );
   167     OstTraceFunctionEntry0( CWDMONITOR_STARTMONITOR_ENTRY );
   162     CPIXLOGSTRING("CWDMonitor::StartMonitor(): Entered");
   168     CPIXLOGSTRING("CWDMonitor::StartMonitor(): Entered");
   163     iWDTimer->StartWDTimer();
   169     iWDTimer->StartWDTimer();
   164     OstTraceFunctionExit0( CWDMONITOR_STARTMONITOR_EXIT );
   170     OstTraceFunctionExit0( CWDMONITOR_STARTMONITOR_EXIT );
   165     }
   171     }
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CWDMonitor::StartServer()
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 TInt CWDMonitor::StartServer( const TDesC& aServerName , TUid aServerUid ,
       
   172                               const TDesC& aSemaphoreName)
       
   173     {
       
   174     RSemaphore semaphore;
       
   175     TInt result = semaphore.CreateGlobal(aSemaphoreName, 0);
       
   176     if (result != KErrNone)
       
   177         {
       
   178         return result;
       
   179         }
       
   180 
       
   181     result = CreateServerProcess( aServerName , aServerUid);
       
   182     if (result != KErrNone)
       
   183         {
       
   184         return result;
       
   185         }
       
   186 
       
   187     semaphore.Wait();
       
   188     semaphore.Close();
       
   189     return result;
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CWDMonitor::CreateServerProcess()
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 TInt CWDMonitor::CreateServerProcess( const TDesC& aServerName , TUid aServerUid  )
       
   197     {
       
   198     TInt result;
       
   199 
       
   200     const TUidType serverUid( KNullUid, KNullUid, aServerUid);
       
   201 
       
   202     RProcess server;
       
   203 
       
   204     result = server.Create(aServerName, KNullDesC, serverUid);
       
   205     if (result != KErrNone)
       
   206         {
       
   207         return result;
       
   208         }
       
   209 
       
   210     server.Resume();
       
   211     server.Close();
       
   212     return KErrNone;
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
   172 // -----------------------------------------------------------------------------
   216 // CWDMonitor::HandlecentrepL()
   173 // CWDMonitor::HandlecentrepL()
   217 // -----------------------------------------------------------------------------
   174 // -----------------------------------------------------------------------------
   218 //
   175 //
   219 void CWDMonitor::HandlecentrepL( TUint32 aKey )
   176 void CWDMonitor::HandlecentrepL( TUint32 aKey )
   220     {
   177     {
   221     CRepository* wdrepo = CRepository::NewL( KWDrepoUidMenu );        
   178     CRepository* wdrepo = CRepository::NewL( KWDrepoUidMenu );        
   222     if ( KHarvesterServerKey == aKey )
   179     if ( KHarvesterServerKey == aKey )
   223         {
   180         {
   224         // get the harvester server status
   181         // get the harvester server status
   225         wdrepo->Get( KHarvesterServerKey , iAllowHS );        
   182         wdrepo->Get( KHarvesterServerKey , iAllowHS );
       
   183         
       
   184         if ( iAllowHS )
       
   185             {
       
   186             //start the Harvester server and start monitoring            
       
   187             iHarvesterMonitor = CServerMonitor::NewL( *iHSName , iHSUid );
       
   188             }
       
   189         else{
       
   190             // Shutdown the harvester server
       
   191             iHarvesterMonitor->Cancel();
       
   192             iHarvesterMonitor->ShutdownServer();                        
       
   193             delete iHarvesterMonitor;
       
   194             iHarvesterMonitor = NULL;
       
   195             }
   226         }
   196         }
   227     else if ( KSearchServerKey == aKey )
   197     else if ( KSearchServerKey == aKey )
   228         {
   198         {
   229         // get the Search server status
   199         // get the Search server status
   230         wdrepo->Get( KSearchServerKey , iAllowSS );        
   200         wdrepo->Get( KSearchServerKey , iAllowSS );
       
   201         
       
   202         if ( iAllowSS )
       
   203             {
       
   204             //Start the Search server and start monitoring
       
   205             iSearchMonitor = CServerMonitor::NewL( *iSSName , iSSUid );
       
   206             }
       
   207         else
       
   208             {
       
   209             //Shutdown the searchserver
       
   210             iSearchMonitor->Cancel();
       
   211             iSearchMonitor->ShutdownServer();                        
       
   212             delete iSearchMonitor;
       
   213             iSearchMonitor = NULL;
       
   214             }
       
   215         }
       
   216     else if ( (KHarvesterServerUIDKey == aKey)||( KHarvesterServerNAMEKey == aKey ) )
       
   217         {
       
   218         // Shutdown the existing server
       
   219         iHarvesterMonitor->Cancel();
       
   220         iHarvesterMonitor->ShutdownServer();                        
       
   221         delete iHarvesterMonitor;
       
   222         iHarvesterMonitor = NULL;
       
   223         //read the new values
       
   224         TBuf<KCenrepUidLength> temp;
       
   225         TInt64 value;
       
   226         TLex uidvalue;
       
   227         if ( KHarvesterServerUIDKey == aKey )
       
   228             {            
       
   229             //Read Harvester server UId value
       
   230             if ( KErrNone == wdrepo->Get( KHarvesterServerUIDKey, temp ) )
       
   231                 {
       
   232                 uidvalue.Assign(temp);        
       
   233                 if (KErrNone == uidvalue.Val( value,EHex ))
       
   234                     iHSUid.iUid = value;
       
   235                 }
       
   236             }
       
   237         else
       
   238             {
       
   239             //read harvester server name
       
   240             delete iHSName;
       
   241             if ( KErrNone == wdrepo->Get( KHarvesterServerNAMEKey, temp ))
       
   242                 {
       
   243                 iHSName = HBufC::NewL( temp.Length() );
       
   244                 TPtr hsname = iHSName->Des();
       
   245                 hsname.Copy( temp );
       
   246                 }
       
   247             }        
       
   248         // Start the server with new values
       
   249         iHarvesterMonitor = CServerMonitor::NewL( *iHSName , iHSUid );
       
   250         }
       
   251     else if ( (KSearchServerUIDKey == aKey)||( KSearchServerNAMEKey == aKey ) )
       
   252         {
       
   253         // Shutdown the existing server
       
   254         iSearchMonitor->Cancel();
       
   255         iSearchMonitor->ShutdownServer();                        
       
   256         delete iSearchMonitor;
       
   257         iSearchMonitor = NULL;
       
   258         //read the new values
       
   259         TBuf<KCenrepUidLength> temp;
       
   260         TInt64 value;
       
   261         TLex uidvalue;
       
   262         if ( KSearchServerUIDKey == aKey )
       
   263             {
       
   264             //read search server uid
       
   265             if ( KErrNone == wdrepo->Get( KSearchServerUIDKey, temp ) )
       
   266                 {
       
   267                 uidvalue.Assign(temp);        
       
   268                 if (KErrNone == uidvalue.Val( value,EHex ))
       
   269                     iSSUid.iUid = value;
       
   270                 }
       
   271             }
       
   272         else
       
   273             {
       
   274             //read search server name
       
   275             delete iSSName;
       
   276             if ( KErrNone == wdrepo->Get( KSearchServerNAMEKey, temp ))
       
   277                 {
       
   278                 iSSName = HBufC::NewL( temp.Length() );
       
   279                 TPtr ssname = iSSName->Des();
       
   280                 ssname.Copy( temp );
       
   281                 }
       
   282             }        
       
   283         // Start the server with new values
       
   284         iSearchMonitor = CServerMonitor::NewL( *iSSName , iSSUid );
   231         }
   285         }
   232     delete wdrepo;
   286     delete wdrepo;
   233     }
   287     }
   234 //End of file
   288 //End of file