25
|
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 |
TInt error = KErrNone;
|
|
94 |
|
|
95 |
// First check that the server isn't already running
|
|
96 |
if ( IsMailServerRunning() )
|
|
97 |
{
|
|
98 |
error = KErrAlreadyExists;
|
|
99 |
}
|
|
100 |
|
|
101 |
// Start application server if we aren't already running
|
|
102 |
if( error == KErrNone )
|
|
103 |
{
|
|
104 |
// Rename to help identification in error situations
|
|
105 |
error = User::RenameThread( KFSMailServerName );
|
|
106 |
|
|
107 |
if( error != KErrNone )
|
|
108 |
{
|
|
109 |
// Keep on going even if thread renaming fails
|
|
110 |
}
|
|
111 |
error = EikStart::RunApplication( NewApplication );
|
|
112 |
}
|
|
113 |
|
|
114 |
return error;
|
|
115 |
}
|
|
116 |
|