imagehandlingutilities/thumbnailmanager/tmiadrestart/src/tmiadrestart.cpp
branchRCL_3
changeset 28 ff2fb7658ff7
parent 0 2014ca87e772
child 33 221be23823c5
equal deleted inserted replaced
24:f0aa341a25bf 28:ff2fb7658ff7
    17 
    17 
    18 
    18 
    19 #include <e32base.h>
    19 #include <e32base.h>
    20 #include <e32std.h>  
    20 #include <e32std.h>  
    21 #include <e32property.h>
    21 #include <e32property.h>
       
    22 #include "thumbnaillog.h"
    22 
    23 
    23 #include "thumbnailmanagerconstants.h"
    24 #include "thumbnailmanagerconstants.h"
    24 
    25 
    25 LOCAL_C void MainL()
    26 LOCAL_C void MainL()
    26     {
    27     {
    27     // delay so that cenrep has time to read new config
    28     // delay so that cenrep has time to read new config
       
    29     TN_DEBUG1( "MainL() after" );
    28     User::After(5000000);
    30     User::After(5000000);
    29     
    31     
    30     TInt res( KErrNone );
    32     TInt res( KErrNone );
    31     RProcess process;
    33     RProcess process;
    32     TFullName name;
    34     TFullName name;
    33     
    35     
    34     // find and terminate Thumb AG Daemon
    36     // find and terminate Thumb AG Daemon
       
    37     TN_DEBUG1( "MainL() KTAGDaemonProcess find" );
    35     TFindProcess findProcess( KTAGDaemonProcess );   
    38     TFindProcess findProcess( KTAGDaemonProcess );   
       
    39 
    36     if ( findProcess.Next(name) == KErrNone )
    40     if ( findProcess.Next(name) == KErrNone )
    37         {
    41         {
    38         res = process.Open(name);
    42         res = process.Open(name);
       
    43         TN_DEBUG2( "MainL() KTAGDaemonProcess open res = %d", res );    
    39         
    44         
    40         // logon to get termination signal
    45         // logon to get termination signal
    41         TRequestStatus status;
    46         TRequestStatus status;
       
    47         TN_DEBUG1( "MainL() KTAGDaemonProcess logon" );
    42         process.Logon(status);
    48         process.Logon(status);
    43          
    49 
    44         // shutdown using P&S key
    50         // shutdown using P&S key
    45         RProperty::Set(KTAGDPSNotification,KShutdown,1);
    51         TN_DEBUG2( "MainL() KTAGDaemonProcess Set = %d", res );
    46         
    52         res = RProperty::Set(KTAGDPSNotification,KShutdown,1);
       
    53        
    47         // blocks here until thread is terminated
    54         // blocks here until thread is terminated
    48         User::WaitForRequest(status); 
    55         TN_DEBUG1( "MainL() KTAGDaemonProcess wait" );
       
    56         User::WaitForRequest(status);
    49         
    57         
    50         // reset key
    58         // reset key
    51         RProperty::Set(KTAGDPSNotification,KShutdown,0);
    59         TN_DEBUG1( "MainL() KTAGDaemonProcess reset" );
       
    60         res = RProperty::Set(KTAGDPSNotification, KShutdown, 0);
    52         
    61         
       
    62         TN_DEBUG1( "MainL() KTAGDaemonProcess close" );
    53         process.Close();
    63         process.Close();
    54         }
    64         }
    55     
    65     
    56     // find and terminate Thumbnail Server
    66     // find and terminate Thumbnail Server
    57     TFindProcess findProcess2( KThumbnailServerProcess );
    67     TFindProcess findProcess2( KThumbnailServerProcess );
       
    68     TN_DEBUG1( "MainL() KThumbnailServerProcess find" );
    58     if ( findProcess2.Next(name) == KErrNone )
    69     if ( findProcess2.Next(name) == KErrNone )
    59         {
    70         {
    60         res = process.Open(name);
    71         res = process.Open(name);
    61          
    72         TN_DEBUG2( "MainL() KThumbnailServerProcess open res = %d", res );
       
    73         
    62         // logon to get termination signal
    74         // logon to get termination signal
    63         TRequestStatus status;
    75         TRequestStatus status;
       
    76         TN_DEBUG1( "MainL() KThumbnailServerProcess logon" );
    64         process.Logon(status);
    77         process.Logon(status);
    65           
    78           
    66         // shutdown using P&S key
    79         // shutdown using P&S key
    67         RProperty::Set(KTMPSNotification,KShutdown,1);
    80         TN_DEBUG2( "MainL() KThumbnailServerProcess Set res = %d", res );
       
    81         res = RProperty::Set(KTMPSNotification,KShutdown,1);
    68          
    82          
    69         // blocks here until thread is terminated
    83         // blocks here until thread is terminated
    70         User::WaitForRequest(status); 
    84         TN_DEBUG1( "MainL() KThumbnailServerProcess wait" );
       
    85         User::WaitForRequest(status);
    71          
    86          
    72         // reset key
    87         // reset key
    73         RProperty::Set(KTMPSNotification,KShutdown,0);
    88         TN_DEBUG2( "MainL() KThumbnailServerProcess reset res = %d", res );
    74          
    89         res = RProperty::Set(KTMPSNotification, KShutdown, 0);
       
    90 
       
    91         TN_DEBUG1( "MainL() KThumbnailServerProcess close" );
    75         process.Close();
    92         process.Close();
    76         }    
    93         }    
    77     
    94     
    78     // delay just in case old daemon hasn't died yet
    95     // delay just in case old daemon hasn't died yet
       
    96     TN_DEBUG1( "MainL() after" );
    79     User::After(2500000);
    97     User::After(2500000);
    80     
    98     
    81     // start new ThumbAGDaemon
    99     // start new ThumbAGDaemon
    82     RProcess server;
   100     RProcess server;
    83     TInt retryCount = 0;
   101     TInt retryCount = 0;
    84     
   102     
    85     // Create the server process
   103     // Create the server process
    86     // KNullDesC param causes server's E32Main() to be run
   104     // KNullDesC param causes server's E32Main() to be run
       
   105     TN_DEBUG2( "MainL() KTAGDaemonExe create res = %d", res );
    87     res = server.Create( KTAGDaemonExe, KNullDesC );
   106     res = server.Create( KTAGDaemonExe, KNullDesC );
    88     
   107     
    89     // try again 3 times if fails
   108     // try again 3 times if fails
    90     while ( res != KErrNone)
   109     while ( res != KErrNone)
    91         {
   110         {
       
   111         TN_DEBUG1( "MainL() KTAGDaemonExe retry" );
    92         if (retryCount > 2)
   112         if (retryCount > 2)
    93             {
   113             {
       
   114             TN_DEBUG1( "MainL() KTAGDaemonExe retry > 2" );
    94             return;
   115             return;
    95             }
   116             }
    96         
   117         
       
   118         TN_DEBUG1( "MainL() after" );
    97         User::After(2500000);
   119         User::After(2500000);
       
   120         TN_DEBUG2( "MainL() KTAGDaemonExe create res = %d", res );
    98         res = server.Create( KTAGDaemonExe, KNullDesC );
   121         res = server.Create( KTAGDaemonExe, KNullDesC );
    99         
       
   100         retryCount++;
   122         retryCount++;
   101         }
   123         }
   102     
   124     
   103     // Process created successfully
   125     // Process created successfully
   104     TRequestStatus status;
   126     TRequestStatus status;
       
   127     TN_DEBUG1( "MainL() Rendezvous" );
   105     server.Rendezvous( status );
   128     server.Rendezvous( status );
       
   129     TN_DEBUG1( "MainL() Resume" );
   106     server.Resume(); // start it going
   130     server.Resume(); // start it going
   107     
   131     
       
   132     
   108     // Wait until the completion of the server creation
   133     // Wait until the completion of the server creation
       
   134     TN_DEBUG1( "MainL() wait" );
   109     User::WaitForRequest( status );
   135     User::WaitForRequest( status );
       
   136     TN_DEBUG1( "MainL() wait done" );
   110     
   137     
   111     // Server created successfully
   138     // Server created successfully
   112     server.Close(); // we're no longer interested in the other process
   139     server.Close(); // we're no longer interested in the other process
   113     }
   140     }
   114 
   141