imagehandlingutilities/thumbnailmanager/tmiadrestart/src/tmiadrestart.cpp
branchRCL_3
changeset 22 9d4d3445ce6e
parent 21 6257223ede8a
equal deleted inserted replaced
21:6257223ede8a 22:9d4d3445ce6e
    20 #include <e32std.h>  
    20 #include <e32std.h>  
    21 #include <e32property.h>
    21 #include <e32property.h>
    22 #include "thumbnaillog.h"
    22 #include "thumbnaillog.h"
    23 
    23 
    24 #include "thumbnailmanagerconstants.h"
    24 #include "thumbnailmanagerconstants.h"
    25 #include "OstTraceDefinitions.h"
       
    26 #ifdef OST_TRACE_COMPILER_IN_USE
       
    27 #include "tmiadrestartTraces.h"
       
    28 #endif
       
    29 
    25 
    30 LOCAL_C void MainL()
    26 LOCAL_C void MainL()
    31     {
    27     {
    32     // delay so that cenrep has time to read new config
    28     // delay so that cenrep has time to read new config
    33     TN_DEBUG1( "MainL() after" );
    29     TN_DEBUG1( "MainL() after" );
    34     OstTrace0( TRACE_NORMAL, _MAINL, "::MainL - after" );
       
    35     
       
    36     User::After(5000000);
    30     User::After(5000000);
    37     
    31     
    38     TInt res( KErrNone );
    32     TInt res( KErrNone );
    39     RProcess process;
    33     RProcess process;
    40     TFullName name;
    34     TFullName name;
    41     
    35     
    42     // find and terminate Thumb AG Daemon
    36     // find and terminate Thumb AG Daemon
    43     TN_DEBUG1( "MainL() KTAGDaemonProcess find" );
    37     TN_DEBUG1( "MainL() KTAGDaemonProcess find" );
    44     OstTrace0( TRACE_NORMAL, DUP1__MAINL, "::MainL - find" );
       
    45     TFindProcess findProcess( KTAGDaemonProcess );   
    38     TFindProcess findProcess( KTAGDaemonProcess );   
    46 
    39 
    47     if ( findProcess.Next(name) == KErrNone )
    40     if ( findProcess.Next(name) == KErrNone )
    48         {
    41         {
    49         res = process.Open(name);
    42         res = process.Open(name);
    50         TN_DEBUG2( "MainL() KTAGDaemonProcess open res = %d", res );    
    43         TN_DEBUG2( "MainL() KTAGDaemonProcess open res = %d", res );    
    51         OstTrace1( TRACE_NORMAL, DUP2__MAINL, "::MainL;res=%d - open res", res );
       
    52         
    44         
    53         // logon to get termination signal
    45         // logon to get termination signal
    54         TRequestStatus status;
    46         TRequestStatus status;
    55         TN_DEBUG1( "MainL() KTAGDaemonProcess logon" );
    47         TN_DEBUG1( "MainL() KTAGDaemonProcess logon" );
    56         OstTrace0( TRACE_NORMAL, DUP3__MAINL, "::MainL - logon" );
       
    57         process.Logon(status);
    48         process.Logon(status);
    58 
    49 
    59         // shutdown using P&S key
    50         // shutdown using P&S key
    60         TN_DEBUG2( "MainL() KTAGDaemonProcess Set = %d", res );
    51         TN_DEBUG2( "MainL() KTAGDaemonProcess Set = %d", res );
    61         OstTrace1( TRACE_NORMAL, DUP4__MAINL, "::MainL - Set = res;res=%d", res );
       
    62         res = RProperty::Set(KTAGDPSNotification,KShutdown,1);
    52         res = RProperty::Set(KTAGDPSNotification,KShutdown,1);
    63        
    53        
    64         // blocks here until thread is terminated
    54         // blocks here until thread is terminated
    65         TN_DEBUG1( "MainL() KTAGDaemonProcess wait" );
    55         TN_DEBUG1( "MainL() KTAGDaemonProcess wait" );
    66         OstTrace0( TRACE_NORMAL, DUP5__MAINL, "::MainL - KTAGDaemonProcess wait" );
       
    67         User::WaitForRequest(status);
    56         User::WaitForRequest(status);
    68         
    57         
    69         // reset key
    58         // reset key
    70         TN_DEBUG1( "MainL() KTAGDaemonProcess reset" );
    59         TN_DEBUG1( "MainL() KTAGDaemonProcess reset" );
    71         OstTrace0( TRACE_NORMAL, DUP6__MAINL, "::MainL - KTAGDaemonProcess reset" );
       
    72         res = RProperty::Set(KTAGDPSNotification, KShutdown, 0);
    60         res = RProperty::Set(KTAGDPSNotification, KShutdown, 0);
    73         
    61         
    74         TN_DEBUG1( "MainL() KTAGDaemonProcess close" );
    62         TN_DEBUG1( "MainL() KTAGDaemonProcess close" );
    75         OstTrace0( TRACE_NORMAL, DUP7__MAINL, "::MainL - close" );
       
    76         process.Close();
    63         process.Close();
    77         }
    64         }
    78     
    65     
    79     // find and terminate Thumbnail Server
    66     // find and terminate Thumbnail Server
    80     TFindProcess findProcess2( KThumbnailServerProcess );
    67     TFindProcess findProcess2( KThumbnailServerProcess );
    81     TN_DEBUG1( "MainL() KThumbnailServerProcess find" );
    68     TN_DEBUG1( "MainL() KThumbnailServerProcess find" );
    82     OstTrace0( TRACE_NORMAL, DUP8__MAINL, "::MainL - find" );
       
    83     if ( findProcess2.Next(name) == KErrNone )
    69     if ( findProcess2.Next(name) == KErrNone )
    84         {
    70         {
    85         res = process.Open(name);
    71         res = process.Open(name);
    86         TN_DEBUG2( "MainL() KThumbnailServerProcess open res = %d", res );
    72         TN_DEBUG2( "MainL() KThumbnailServerProcess open res = %d", res );
    87         OstTrace1( TRACE_NORMAL, DUP9__MAINL, "::MainL - KThumbnailServerProcess open;res=%d", res );
       
    88         
    73         
    89         // logon to get termination signal
    74         // logon to get termination signal
    90         TRequestStatus status;
    75         TRequestStatus status;
    91         TN_DEBUG1( "MainL() KThumbnailServerProcess logon" );
    76         TN_DEBUG1( "MainL() KThumbnailServerProcess logon" );
    92         OstTrace0( TRACE_NORMAL, DUP10__MAINL, "::MainL - KThumbnailServerProcess logon" );
       
    93         process.Logon(status);
    77         process.Logon(status);
    94           
    78           
    95         // shutdown using P&S key
    79         // shutdown using P&S key
    96         TN_DEBUG2( "MainL() KThumbnailServerProcess Set res = %d", res );
    80         TN_DEBUG2( "MainL() KThumbnailServerProcess Set res = %d", res );
    97         OstTrace1( TRACE_NORMAL, DUP11__MAINL, "::MainL - KThumbnailServerProcess Set;res=%d", res );
       
    98         res = RProperty::Set(KTMPSNotification,KShutdown,1);
    81         res = RProperty::Set(KTMPSNotification,KShutdown,1);
    99          
    82          
   100         // blocks here until thread is terminated
    83         // blocks here until thread is terminated
   101         TN_DEBUG1( "MainL() KThumbnailServerProcess wait" );
    84         TN_DEBUG1( "MainL() KThumbnailServerProcess wait" );
   102         OstTrace0( TRACE_NORMAL, DUP12__MAINL, "::MainL - KThumbnailServerProcess wait" );
       
   103         User::WaitForRequest(status);
    85         User::WaitForRequest(status);
   104          
    86          
   105         // reset key
    87         // reset key
   106         TN_DEBUG2( "MainL() KThumbnailServerProcess reset res = %d", res );
    88         TN_DEBUG2( "MainL() KThumbnailServerProcess reset res = %d", res );
   107         OstTrace1( TRACE_NORMAL, DUP13__MAINL, "::MainL;res=%d - KThumbnailServerProcess reset", res );
       
   108         res = RProperty::Set(KTMPSNotification, KShutdown, 0);
    89         res = RProperty::Set(KTMPSNotification, KShutdown, 0);
   109 
    90 
   110         TN_DEBUG1( "MainL() KThumbnailServerProcess close" );
    91         TN_DEBUG1( "MainL() KThumbnailServerProcess close" );
   111         OstTrace0( TRACE_NORMAL, DUP14__MAINL, "::MainL - close" );
       
   112         process.Close();
    92         process.Close();
   113         }    
    93         }    
   114     
    94     
   115     // delay just in case old daemon hasn't died yet
    95     // delay just in case old daemon hasn't died yet
   116     TN_DEBUG1( "MainL() after" );
    96     TN_DEBUG1( "MainL() after" );
   121     TInt retryCount = 0;
   101     TInt retryCount = 0;
   122     
   102     
   123     // Create the server process
   103     // Create the server process
   124     // KNullDesC param causes server's E32Main() to be run
   104     // KNullDesC param causes server's E32Main() to be run
   125     TN_DEBUG2( "MainL() KTAGDaemonExe create res = %d", res );
   105     TN_DEBUG2( "MainL() KTAGDaemonExe create res = %d", res );
   126     OstTrace1( TRACE_NORMAL, DUP15__MAINL, "::MainL - KTAGDaemonExe create res;res=%d", res );
       
   127     res = server.Create( KTAGDaemonExe, KNullDesC );
   106     res = server.Create( KTAGDaemonExe, KNullDesC );
   128     
   107     
   129     // try again 3 times if fails
   108     // try again 3 times if fails
   130     while ( res != KErrNone)
   109     while ( res != KErrNone)
   131         {
   110         {
   132         TN_DEBUG1( "MainL() KTAGDaemonExe retry" );
   111         TN_DEBUG1( "MainL() KTAGDaemonExe retry" );
   133         OstTrace0( TRACE_NORMAL, DUP16__MAINL, "::MainL- KTAGDaemonExe retry" );
       
   134         if (retryCount > 2)
   112         if (retryCount > 2)
   135             {
   113             {
   136             TN_DEBUG1( "MainL() KTAGDaemonExe retry > 2" );
   114             TN_DEBUG1( "MainL() KTAGDaemonExe retry > 2" );
   137             OstTrace0( TRACE_NORMAL, DUP17__MAINL, "::MainL - KTAGDaemonExe retry > 2" );
       
   138             return;
   115             return;
   139             }
   116             }
   140         
   117         
   141         TN_DEBUG1( "MainL() after" );
   118         TN_DEBUG1( "MainL() after" );
   142         OstTrace0( TRACE_NORMAL, DUP18__MAINL, "::MainL - after" );
       
   143         User::After(2500000);
   119         User::After(2500000);
   144         TN_DEBUG2( "MainL() KTAGDaemonExe create res = %d", res );
   120         TN_DEBUG2( "MainL() KTAGDaemonExe create res = %d", res );
   145         OstTrace1( TRACE_NORMAL, DUP19__MAINL, "::MainL - KTAGDaemonExe create;res=%d", res );
       
   146         res = server.Create( KTAGDaemonExe, KNullDesC );
   121         res = server.Create( KTAGDaemonExe, KNullDesC );
   147         retryCount++;
   122         retryCount++;
   148         }
   123         }
   149     
   124     
   150     // Process created successfully
   125     // Process created successfully
   151     TRequestStatus status;
   126     TRequestStatus status;
   152     TN_DEBUG1( "MainL() Rendezvous" );
   127     TN_DEBUG1( "MainL() Rendezvous" );
   153     OstTrace0( TRACE_NORMAL, DUP20__MAINL, "::MainL - Rendezvous" );
       
   154     server.Rendezvous( status );
   128     server.Rendezvous( status );
   155     TN_DEBUG1( "MainL() Resume" );
   129     TN_DEBUG1( "MainL() Resume" );
   156     OstTrace0( TRACE_NORMAL, DUP21__MAINL, "::MainL - resume" );
       
   157     server.Resume(); // start it going
   130     server.Resume(); // start it going
   158     
   131     
   159     
   132     
   160     // Wait until the completion of the server creation
   133     // Wait until the completion of the server creation
   161     TN_DEBUG1( "MainL() wait" );
   134     TN_DEBUG1( "MainL() wait" );
   162     OstTrace0( TRACE_NORMAL, DUP22__MAINL, "::MainL - wait" );
       
   163     User::WaitForRequest( status );
   135     User::WaitForRequest( status );
   164     TN_DEBUG1( "MainL() wait done" );
   136     TN_DEBUG1( "MainL() wait done" );
   165     OstTrace0( TRACE_NORMAL, DUP23__MAINL, "::MainL - wait done"  );
       
   166     
   137     
   167     // Server created successfully
   138     // Server created successfully
   168     server.Close(); // we're no longer interested in the other process
   139     server.Close(); // we're no longer interested in the other process
   169     }
   140     }
   170 
   141