63
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 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:
|
|
15 |
*
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include <flogger.h>
|
|
20 |
#include "cmssession.h"
|
|
21 |
#include "cmscommondefines.h"
|
|
22 |
|
|
23 |
//CLASS DECLARATION
|
|
24 |
EXPORT_C RCmsSession::RCmsSession() : iConnected( EFalse )
|
|
25 |
{
|
|
26 |
}
|
|
27 |
|
|
28 |
// ----------------------------------------------------
|
|
29 |
// RCmsClient::Version
|
|
30 |
//
|
|
31 |
// ----------------------------------------------------
|
|
32 |
//
|
|
33 |
EXPORT_C TVersion RCmsSession::Version() const
|
|
34 |
{
|
|
35 |
return TVersion( KCmsSrvMajorVersionNumber,
|
|
36 |
KCmsSrvMinorVersionNumber,
|
|
37 |
KCmsSrvBuildVersionNumber );
|
|
38 |
}
|
|
39 |
|
|
40 |
// ----------------------------------------------------
|
|
41 |
// RCmsClient::~RCmsClient
|
|
42 |
//
|
|
43 |
// ----------------------------------------------------
|
|
44 |
//
|
|
45 |
EXPORT_C RCmsSession::~RCmsSession()
|
|
46 |
{
|
|
47 |
}
|
|
48 |
|
|
49 |
// ----------------------------------------------------
|
|
50 |
// RCmsClient::Connect
|
|
51 |
//
|
|
52 |
// ----------------------------------------------------
|
|
53 |
//
|
|
54 |
EXPORT_C TInt RCmsSession::Connect()
|
|
55 |
{
|
|
56 |
#ifdef _DEBUG
|
|
57 |
RCmsSession::WriteToLog( _L8( "RCmsSession::Connect()" ) );
|
|
58 |
#endif
|
|
59 |
TInt ret = KErrNone;
|
|
60 |
if( !iConnected )
|
|
61 |
{
|
|
62 |
TInt threadStart = StartServer();
|
|
63 |
#ifdef _DEBUG
|
|
64 |
RCmsSession::WriteToLog( _L8( " StartServer() returned %d" ), threadStart );
|
|
65 |
#endif
|
|
66 |
if( threadStart == KErrNone || threadStart == KErrAlreadyExists )
|
|
67 |
{
|
|
68 |
ret = CreateSession( KCmsServerLib, Version(), KTTDefaultMessageSlots );
|
|
69 |
#ifdef _DEBUG
|
|
70 |
RCmsSession::WriteToLog( _L8( " CreateSession() returned %d" ), ret );
|
|
71 |
#endif
|
|
72 |
iConnected = ( ret == KErrNone );
|
|
73 |
}
|
|
74 |
else ret = threadStart;
|
|
75 |
}
|
|
76 |
return ret;
|
|
77 |
}
|
|
78 |
|
|
79 |
// ----------------------------------------------------
|
|
80 |
// RCmsSession::StartServer
|
|
81 |
//
|
|
82 |
// ----------------------------------------------------
|
|
83 |
//
|
|
84 |
TInt RCmsSession::StartServer()
|
|
85 |
{
|
|
86 |
#ifdef _DEBUG
|
|
87 |
RCmsSession::WriteToLog( _L8( "RCmsSession::StartServer()" ) );
|
|
88 |
#endif
|
|
89 |
TInt ret = KErrNone;
|
|
90 |
TRequestStatus status = KRequestPending;
|
|
91 |
if ( !IsRunning() )
|
|
92 |
{
|
|
93 |
RProcess server;
|
|
94 |
ret = server.Create( KCmsServerExe, KNullDesC );
|
|
95 |
#ifdef _DEBUG
|
|
96 |
RCmsSession::WriteToLog( _L8( " RThread::Create() returned: %d" ), ret );
|
|
97 |
#endif
|
|
98 |
if( ret != KErrNone )
|
|
99 |
return ret;
|
|
100 |
server.Rendezvous( status );
|
|
101 |
status != KRequestPending ? server.Kill( 0 ) : server.Resume();
|
|
102 |
//Wait for start or death
|
|
103 |
User::WaitForRequest( status );
|
|
104 |
ret = server.ExitType() == EExitPanic ? KErrGeneral : status.Int();
|
|
105 |
server.Close();
|
|
106 |
}
|
|
107 |
return ret;
|
|
108 |
}
|
|
109 |
|
|
110 |
// ----------------------------------------------------
|
|
111 |
// RCmsSession::IsRunning
|
|
112 |
//
|
|
113 |
// ----------------------------------------------------
|
|
114 |
//
|
|
115 |
TBool RCmsSession::IsRunning()
|
|
116 |
{
|
|
117 |
#ifdef _DEBUG
|
|
118 |
RCmsSession::WriteToLog( _L8( "RCmsSession::IsRunning()" ) );
|
|
119 |
#endif
|
|
120 |
TFindServer findServer( KCmsServerLib );
|
|
121 |
TFullName name;
|
|
122 |
return ( findServer.Next( name ) == KErrNone );
|
|
123 |
}
|
|
124 |
|
|
125 |
#ifdef _DEBUG
|
|
126 |
// ----------------------------------------------------
|
|
127 |
// RCmsSession::::WriteToLog
|
|
128 |
//
|
|
129 |
// ----------------------------------------------------
|
|
130 |
//
|
|
131 |
void RCmsSession::WriteToLog( TRefByValue<const TDesC8> aFmt,... )
|
|
132 |
{
|
|
133 |
VA_LIST list;
|
|
134 |
VA_START( list, aFmt );
|
|
135 |
TBuf8<KClientLogBufferMaxSize> buf;
|
|
136 |
buf.FormatList( aFmt, list );
|
|
137 |
RFileLogger::Write( KCmsClientLogDir, KCmsClientLogFile, EFileLoggingModeAppend, buf );
|
|
138 |
RDebug::RawPrint( buf );
|
|
139 |
}
|
|
140 |
#endif //_DEBUG
|