systemswstubs/exampledsy/src/dsymtc.cpp
changeset 0 0ce1b5ce9557
equal deleted inserted replaced
-1:000000000000 0:0ce1b5ce9557
       
     1 /*
       
     2 * Copyright (c) 2002 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 *    It implements the class CDosMtcExample.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "DsyMtc.h"
       
    21 #include "DsyDebug.h"
       
    22 #include <f32file.h>
       
    23 
       
    24 _LIT( KExampleDSYMTCStateFlagFile, "KExampleDSYMTCStateFlagFile.dat");
       
    25 
       
    26 
       
    27 //
       
    28 // ---------------------------------------------------------
       
    29 // CDosMtcExample::NewL
       
    30 // ---------------------------------------------------------
       
    31 //  
       
    32 CDosMtcExample* CDosMtcExample::NewL()
       
    33 {
       
    34 	FLOG(_L("CDosMtcExample::NewL()"));
       
    35 
       
    36 	CDosMtcExample* result = new (ELeave) CDosMtcExample;
       
    37 
       
    38 	CleanupStack::PushL(result);
       
    39 	result->ConstructL();
       
    40 	CleanupStack::Pop();
       
    41 
       
    42 	return result;
       
    43 }
       
    44 
       
    45 
       
    46 //
       
    47 // ---------------------------------------------------------
       
    48 // CDosMtcExample::ConstructL
       
    49 // ---------------------------------------------------------
       
    50 //  
       
    51 void CDosMtcExample::ConstructL()
       
    52 {
       
    53 	FLOG(_L("CDosMtcExample::ConstructL()"));
       
    54 }
       
    55 
       
    56 //
       
    57 // ---------------------------------------------------------
       
    58 // CDosMtcExample::PowerOnL
       
    59 // ---------------------------------------------------------
       
    60 //  
       
    61 TInt CDosMtcExample::PowerOnL()
       
    62 {
       
    63 	FLOG(_L("CDosMtcExample::PowerOnL()"));
       
    64 
       
    65 	return KErrNone;
       
    66 }
       
    67 
       
    68 
       
    69 //
       
    70 // ---------------------------------------------------------
       
    71 // CDosMtcExample::PowerOffL
       
    72 // ---------------------------------------------------------
       
    73 //  
       
    74 TInt CDosMtcExample::PowerOffL()
       
    75 {
       
    76 	FLOG(_L("CDosMtcExample::PowerOffL()"));
       
    77 
       
    78 	return KErrNone;
       
    79 }
       
    80 
       
    81 
       
    82 //
       
    83 // ---------------------------------------------------------
       
    84 // CDosMtcExample::DosSyncL
       
    85 // ---------------------------------------------------------
       
    86 //  
       
    87 TInt CDosMtcExample::DosSyncL()
       
    88 {
       
    89 	FLOG(_L("CDosMtcExample::DosSyncL()"));
       
    90 
       
    91 	return KErrNone;
       
    92 }
       
    93 
       
    94 
       
    95 //
       
    96 // ---------------------------------------------------------
       
    97 // CDosMtcExample::ResetGenerateL
       
    98 // ---------------------------------------------------------
       
    99 //  
       
   100 TInt CDosMtcExample::ResetGenerateL()
       
   101 {
       
   102 	FLOG(_L("CDosMtcExample::ResetGenerateL()"));
       
   103 
       
   104 	return KErrNone;	
       
   105 }
       
   106 
       
   107 //
       
   108 // ---------------------------------------------------------
       
   109 // CDosMtcExample::SetStateL
       
   110 // ---------------------------------------------------------
       
   111 //  
       
   112 TInt CDosMtcExample::SetStateL(const TInt /*aStateType*/)
       
   113 {
       
   114 	FLOG(_L("CDosMtcExample::SetStateL()"));
       
   115 
       
   116 	return KErrNone;
       
   117 }
       
   118 
       
   119 //
       
   120 // ---------------------------------------------------------
       
   121 // CDosMtcExample::SetStateFlagL
       
   122 // ---------------------------------------------------------
       
   123 //  
       
   124 
       
   125 TInt CDosMtcExample::SetStateFlagL(const TDosStateFlag aFlag)
       
   126 {
       
   127 	FLOG(_L("CDosMtcExample::SetStateFlagL() - Write state to disk"));
       
   128 
       
   129 	RFs fsSession;
       
   130 	TInt err = fsSession.Connect();
       
   131 
       
   132 	if ( err == KErrNone )
       
   133 	{
       
   134 		RFile file;
       
   135 		err = file.Open( fsSession, KExampleDSYMTCStateFlagFile, EFileWrite);
       
   136 
       
   137 		if ( err == KErrNotFound) // file does not exist - create it
       
   138 	    {
       
   139 			err = file.Create( fsSession, KExampleDSYMTCStateFlagFile, EFileWrite);
       
   140 			FLOG(_L("CDosMtcExample::SetStateFlagL() - file doesn't exist, create file"));
       
   141 	    }
       
   142 
       
   143 		if ( err == KErrNone )
       
   144 		{
       
   145 			// write stateflag to disk
       
   146 			TBuf8<1> buf;
       
   147 			buf.Append((TInt8)aFlag);
       
   148 			err = file.Write( buf, 1);
       
   149 		}
       
   150 
       
   151 		//close file
       
   152 		file.Close();
       
   153 	}
       
   154 
       
   155 	if ( err != KErrNone) // file does not exist or read fails - aFlag is EDosOfflineStateFlagFalse and return
       
   156     {
       
   157 		FLOG(_L("CDosMtcExample::SetStateFlagL() - flag value write fails"));
       
   158     }
       
   159 
       
   160 	//close session
       
   161 	fsSession.Close();
       
   162 
       
   163 	return KErrNone;
       
   164 }
       
   165 
       
   166 
       
   167 //
       
   168 // ---------------------------------------------------------
       
   169 // CDosMtcExample::GetStateFlagL
       
   170 //
       
   171 // ---------------------------------------------------------
       
   172 //  
       
   173 
       
   174 
       
   175 TInt CDosMtcExample::GetStateFlagL(TDosStateFlag& aFlag)
       
   176 {
       
   177 	FLOG(_L("CDosMtcExample::GetStateFlagL() - Read state from disk"));
       
   178 
       
   179 	// set default value
       
   180 	aFlag = EDosOfflineStateFlagFalse;
       
   181 	
       
   182 	RFs fsSession;
       
   183 	TInt err = fsSession.Connect();
       
   184 
       
   185 	if ( err == KErrNone )
       
   186 	{
       
   187 		RFile file;
       
   188 		err = file.Open( fsSession, KExampleDSYMTCStateFlagFile, EFileRead);
       
   189 
       
   190 		if ( err == KErrNone )
       
   191 		{
       
   192 			// read stateflag status from disk
       
   193 			TBuf8<1> buf(1);
       
   194 			err = file.Read( buf, 1);
       
   195 			if ( err == KErrNone && buf.Size() > 0)
       
   196 			{
       
   197 				if ( buf[0] == (TInt8)EDosOfflineStateFlagTrue )
       
   198 				{
       
   199 					aFlag = EDosOfflineStateFlagTrue;
       
   200 				}
       
   201 			}
       
   202 		}
       
   203 	
       
   204 		//close file
       
   205 		file.Close();
       
   206 	}
       
   207 
       
   208 
       
   209 	if ( err != KErrNone) // file does not exist or read fails - aFlag is EDosOfflineStateFlagFalse and return
       
   210     {
       
   211 		FLOG(_L("CDosMtcExample::GetStateFlagL() - file read fails, default value EDosOfflineStateFlagFalse returned"));
       
   212     }
       
   213 
       
   214 
       
   215 	// close session
       
   216 	fsSession.Close();
       
   217 
       
   218 	return KErrNone;
       
   219 }
       
   220 
       
   221