sysstatemgmt/systemstatemgr/cmd/src/ssmcommandutilprovider.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "ssmcommandutilprovider.h"
       
    17 #include "ssmdebug.h"
       
    18 
       
    19 _LIT( KSysMonProxyDLL, "loadsysmon.dll" );
       
    20 typedef MSsmLoadSysMon* (*TFuncCreateL)( void );
       
    21 
       
    22 /**
       
    23 Factory method that returns pointer to the object of CSsmCommandUtilProvider.
       
    24 */
       
    25 EXPORT_C CSsmCommandUtilProvider* CSsmCommandUtilProvider::NewL()
       
    26 	{
       
    27 	CSsmCommandUtilProvider* self = new(ELeave) CSsmCommandUtilProvider();
       
    28 	CleanupStack::PushL(self);
       
    29 	self->ConstructL();
       
    30 	CleanupStack::Pop(self);	
       
    31 	return self;
       
    32 	}
       
    33 
       
    34 /**
       
    35 Returns CStartSafe object
       
    36 */
       
    37 CSsmStartSafe& CSsmCommandUtilProvider::StartSafe()
       
    38 	{
       
    39 	return *iStartSafe;
       
    40 	}
       
    41 
       
    42 /**
       
    43 DTOR
       
    44 */
       
    45 EXPORT_C CSsmCommandUtilProvider::~CSsmCommandUtilProvider()
       
    46 	{
       
    47 	delete iSysMonSession;
       
    48 	delete iStartSafe;
       
    49 	iSysMonProxyLib.Close();
       
    50 	iFs.Close();
       
    51 	}
       
    52 
       
    53 /**
       
    54 Default CTOR
       
    55 */
       
    56 CSsmCommandUtilProvider::CSsmCommandUtilProvider()
       
    57 	{
       
    58 	}
       
    59 
       
    60 /**
       
    61 Returns SysMonSession.
       
    62 @return System monitor session.
       
    63 @leave KErrNotSupported If NULL is assigned to iSysMonSession.
       
    64 @leave One of the system wide error code.
       
    65 @see MSsmLoadSysMon
       
    66 */
       
    67 MSsmLoadSysMon& CSsmCommandUtilProvider::SysMonSessionL()
       
    68 	{
       
    69 	if(!iSysMonSession)
       
    70 		{
       
    71 		// if iSysMonSession is NULL, then sysmon lib is not installed.
       
    72 		User::Leave(KErrNotSupported);
       
    73 		}
       
    74 	if(iSysMonSession)
       
    75 		{
       
    76 		//close the existing session and send the new one to avoid the memory leak.
       
    77 		iSysMonSession->Close();
       
    78 		iSysMonSession->OpenL();
       
    79 		}
       
    80 
       
    81 	return *iSysMonSession;
       
    82 	}
       
    83 
       
    84 /**
       
    85 This function connects to the RFs if Handle is NULL, and returns the connected RFs.
       
    86 @return Connected RFs
       
    87 @
       
    88 */
       
    89 RFs& CSsmCommandUtilProvider::RfsL()
       
    90 	{
       
    91 	if (iFs.Handle() == NULL)
       
    92 		{	
       
    93 		SSMLOGLEAVEIFERROR(iFs.Connect());		// if not already connected then connect 
       
    94 		}
       
    95 	return iFs;
       
    96 	}
       
    97 
       
    98 /**
       
    99  Load the dll interfacing between us and the System Monitor component, if installed.
       
   100 */
       
   101 void CSsmCommandUtilProvider::LoadMonitorProxyLibL()
       
   102 	{
       
   103 	if( KErrNone != iSysMonProxyLib.Load(KSysMonProxyDLL) )
       
   104 	 	{
       
   105 	 	return;	
       
   106 	 	}
       
   107 
       
   108 	TFuncCreateL sysMonProxyCreateL = reinterpret_cast<TFuncCreateL>(iSysMonProxyLib.Lookup(1));
       
   109 
       
   110 	iSysMonSession = sysMonProxyCreateL();
       
   111 	}
       
   112 
       
   113 	/**
       
   114 Constructs the object, Creates the startsafe object and SysMonSession.
       
   115 */
       
   116 void CSsmCommandUtilProvider::ConstructL()
       
   117 	{
       
   118 	iStartSafe = CSsmStartSafe::NewL(); // Creates CStartSafe object.
       
   119 	LoadMonitorProxyLibL();
       
   120 	}
       
   121 
       
   122