imagehandlingutilities/thumbnailmanager/thumbnailclient/src/thumbnailsession.cpp
branchRCL_3
changeset 17 ff2fb7658ff7
parent 10 ee674526fac5
child 21 6257223ede8a
equal deleted inserted replaced
15:f0aa341a25bf 17:ff2fb7658ff7
    29 // ---------------------------------------------------------------------------
    29 // ---------------------------------------------------------------------------
    30 //
    30 //
    31 RThumbnailSession::RThumbnailSession(): RSessionBase()
    31 RThumbnailSession::RThumbnailSession(): RSessionBase()
    32     {
    32     {
    33     // No implementation required
    33     // No implementation required
       
    34     TN_DEBUG1( "RThumbnailSession::RThumbnailSession");
    34     }
    35     }
    35 
    36 
    36 
    37 
    37 // ---------------------------------------------------------------------------
    38 // ---------------------------------------------------------------------------
    38 // RThumbnailSession::Connect()
    39 // RThumbnailSession::Connect()
    39 // ---------------------------------------------------------------------------
    40 // ---------------------------------------------------------------------------
    40 //
    41 //
    41 TInt RThumbnailSession::Connect()
    42 TInt RThumbnailSession::Connect()
    42     { 
    43     { 
       
    44     TN_DEBUG1( "RThumbnailSession::Connect - start");
       
    45     
    43     StartServer();
    46     StartServer();
    44     
    47     
    45     // special case
    48     // special case
    46     // wait possibly needed here to give an old server process
    49     // wait possibly needed here to give an old server process
    47     // time to enter shutdown state
    50     // time to enter shutdown state
    52  
    55  
    53     // special case
    56     // special case
    54     // old server still alive, wait and try again
    57     // old server still alive, wait and try again
    55     while (retry <= 10 && err != KErrNone)
    58     while (retry <= 10 && err != KErrNone)
    56         {
    59         {
       
    60         TN_DEBUG1( "RThumbnailSession::Connect - retry");
       
    61     
    57         User::After(retry * 50000);
    62         User::After(retry * 50000);
    58         StartServer();
    63         StartServer();
    59         err = CreateSession( KThumbnailServerName, Version(), KMessageSlots );
    64         err = CreateSession( KThumbnailServerName, Version(), KMessageSlots );
    60         retry++;
    65         retry++;
    61         }
    66         }
    62     
    67     
       
    68     TN_DEBUG1( "RThumbnailSession::Connect - end");
       
    69     
    63     return err;
    70     return err;
    64     }
    71     }
    65 
    72 
    66 
    73 
    67 // ---------------------------------------------------------------------------
    74 // ---------------------------------------------------------------------------
    69 // Closes session
    76 // Closes session
    70 // ---------------------------------------------------------------------------
    77 // ---------------------------------------------------------------------------
    71 //
    78 //
    72 void RThumbnailSession::Close()
    79 void RThumbnailSession::Close()
    73     {
    80     {
       
    81     TN_DEBUG1( "RThumbnailSession::Close");
       
    82     
    74     RSessionBase::Close();
    83     RSessionBase::Close();
    75     }
    84     }
    76 
    85 
    77 
    86 
    78 // ---------------------------------------------------------------------------
    87 // ---------------------------------------------------------------------------
    92 // RThumbnailSession::StartServer()
   101 // RThumbnailSession::StartServer()
    93 // ---------------------------------------------------------------------------
   102 // ---------------------------------------------------------------------------
    94 //
   103 //
    95 TInt RThumbnailSession::StartServer()
   104 TInt RThumbnailSession::StartServer()
    96     {
   105     {
       
   106     TN_DEBUG1( "RThumbnailSession::StartServer - start");
       
   107     
    97     TInt res( KErrNone );
   108     TInt res( KErrNone );
    98     // create server - if one of this name does not already exist
   109     // create server - if one of this name does not already exist
    99 
   110 
   100     TFindServer findServer( KThumbnailServerName );
   111     TFindServer findServer( KThumbnailServerName );
   101     TFullName name;
   112     TFullName name;
   102     if ( findServer.Next( name ) != KErrNone )
   113     if ( findServer.Next( name ) != KErrNone )
   103     // we don't exist already
   114         // we don't exist already
   104         {
   115         {
       
   116         TN_DEBUG1( "RThumbnailSession::StartServer - server process doesn't exist yet");
       
   117     
   105         RProcess server;
   118         RProcess server;
   106         // Create the server process
   119         // Create the server process
   107         // KNullDesC param causes server's E32Main() to be run
   120         // KNullDesC param causes server's E32Main() to be run
   108         res = server.Create( KThumbnailServerExe, KNullDesC );
   121         res = server.Create( KThumbnailServerExe, KNullDesC );
   109         if ( res != KErrNone )
   122         if ( res != KErrNone )
   110         // thread created ok - now start it going
       
   111             {
   123             {
       
   124             TN_DEBUG2( "RThumbnailSession::StartServer - error creating process: %d", res);
   112             return res;
   125             return res;
   113             }
   126             }
       
   127         
       
   128         TN_DEBUG1( "RThumbnailSession::StartServer - process created");
   114 
   129 
   115         // Process created successfully
   130         // Process created successfully
   116         TRequestStatus status;
   131         TRequestStatus status;
   117         server.Rendezvous( status );
   132         server.Rendezvous( status );
   118         server.Resume(); // start it going
   133         server.Resume(); // start it going
   120         // Wait until the completion of the server creation
   135         // Wait until the completion of the server creation
   121         User::WaitForRequest( status );
   136         User::WaitForRequest( status );
   122 
   137 
   123         if ( status != KErrNone )
   138         if ( status != KErrNone )
   124             {
   139             {
       
   140             TN_DEBUG2( "RThumbnailSession::StartServer - status: %d, closing", status.Int() );
       
   141         
   125             server.Close();
   142             server.Close();
   126             return status.Int();
   143             return status.Int();
   127             }
   144             }
       
   145         
   128         // Server created successfully
   146         // Server created successfully
   129         server.Close(); // we're no longer interested in the other process
   147         server.Close(); // we're no longer interested in the other process
   130 
   148         }
   131         }
   149     
       
   150     TN_DEBUG1( "RThumbnailSession::StartServer - end");
       
   151     
   132     return res;
   152     return res;
   133     }
   153     }
   134 
   154 
   135 
   155 
   136 // ---------------------------------------------------------------------------
   156 // ---------------------------------------------------------------------------