emailservices/emailserver/src/fsmailserver.cpp
changeset 0 8466d47a6819
child 1 12c456ceeff2
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of FSMailServer startup and other basic 
       
    15 *                functionality
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "emailtrace.h"
       
    21 #include <e32base.h>
       
    22 #include <eikstart.h>
       
    23 #include <eikenv.h>
       
    24 #include <bautils.h>
       
    25 
       
    26 #include "fsmailserverdefinitions.h"
       
    27 #include "FsEmailGlobalDialogsApplication.h"
       
    28 
       
    29 _LIT( KFSMailServerName, "FSMailServer" );
       
    30 
       
    31 // ======== GLOBAL FUNCTIONS ========
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // Checks if the process is already running
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 LOCAL_C TBool IsMailServerRunning()
       
    38     {
       
    39     TBool oneIsRunning( EFalse );
       
    40     
       
    41     TFileName fileName;
       
    42     TFindProcess finder;
       
    43     while ( finder.Next( fileName ) == KErrNone )
       
    44         {
       
    45         RProcess process;
       
    46         TInt outcome = process.Open( fileName );
       
    47         if ( outcome != KErrNone )
       
    48             {
       
    49             continue;
       
    50             }
       
    51         
       
    52         // Check is this mail server process and is it running
       
    53         if ( process.SecureId() == KFSMailServerUid && 
       
    54              process.ExitType() == EExitPending )
       
    55             {
       
    56             if ( oneIsRunning )
       
    57                 {
       
    58                 // Found second process with the same sid. This
       
    59                 // means that one other process besides this process
       
    60                 // with the same sid is already running.
       
    61                 // So one instance of fsmailserver is already running.
       
    62                 process.Close();
       
    63                 return ETrue;
       
    64                 }
       
    65             else
       
    66                 {
       
    67                 oneIsRunning = ETrue;
       
    68                 }
       
    69             }
       
    70         
       
    71         process.Close();
       
    72         }
       
    73     
       
    74     return EFalse;
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // Create new FSMailServer application, called by UI framework
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 LOCAL_C CApaApplication* NewApplication()
       
    82     {
       
    83     FUNC_LOG;
       
    84     return new CFsEmailGlobalDialogsApplication;
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // Main function of the application executable.
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 GLDEF_C TInt E32Main()
       
    92     {
       
    93 
       
    94     
       
    95     TInt error = KErrNone;
       
    96     
       
    97     // First check that the server isn't already running
       
    98     if ( IsMailServerRunning() )
       
    99         {
       
   100         error = KErrAlreadyExists;
       
   101         }
       
   102     
       
   103     // Start application server if we aren't already running
       
   104     if( error == KErrNone )
       
   105         {
       
   106         // Rename to help identification in error situations
       
   107         error = User::RenameThread( KFSMailServerName );
       
   108         
       
   109         if( error != KErrNone )
       
   110             {
       
   111             // Keep on going even if thread renaming fails
       
   112         }
       
   113         error = EikStart::RunApplication( NewApplication );
       
   114         }
       
   115     
       
   116     return error;
       
   117     }
       
   118