author | Johnson Ma <johnson.ma@nokia.com> |
Tue, 30 Mar 2010 14:39:29 +0800 | |
changeset 1 | 96906a986c3b |
permissions | -rw-r--r-- |
1
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
1 |
// CommonStreamStore.h |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
2 |
// |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
3 |
// Copyright (c) 2000 Symbian Ltd. All rights reserved. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
4 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
5 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
6 |
#ifndef __CommonStreamStore_H |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
7 |
#define __CommonStreamStore_H |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
8 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
9 |
#include <e32cons.h> |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
10 |
#include <f32file.h> |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
11 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
12 |
// public |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
13 |
LOCAL_D CConsoleBase* console; // write all your messages to this |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
14 |
LOCAL_C void doExampleL(); // code this function for the real example |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
15 |
LOCAL_D RFs fsSession; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
16 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
17 |
// private |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
18 |
LOCAL_C void callExampleL(); // initialize with cleanup stack, then do example |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
19 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
20 |
_LIT(KTxtStore,"STORE"); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
21 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
22 |
GLDEF_C TInt E32Main() // main function called by E32 |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
23 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
24 |
__UHEAP_MARK; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
25 |
CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
26 |
TRAPD(error,callExampleL()); // more initialization, then do example |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
27 |
__ASSERT_ALWAYS(!error,User::Panic(KTxtStore,error)); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
28 |
delete cleanup; // destroy clean-up stack |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
29 |
__UHEAP_MARKEND; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
30 |
return 0; // and return |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
31 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
32 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
33 |
_LIT(KTxtExampleCode,"STORES Example Code"); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
34 |
_LIT(KTxtConnectFailed,"file session connect failed: return code=%d"); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
35 |
_LIT(KTxtFailed,"failed: leave code=%d"); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
36 |
_LIT(KTxtOK,"ok"); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
37 |
_LIT(KTxtPressAnyKey," [press any key]"); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
38 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
39 |
LOCAL_C void callExampleL() // initialize and call example code under cleanup stack |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
40 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
41 |
console=Console::NewL(KTxtExampleCode,TSize(KConsFullScreen,KConsFullScreen)); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
42 |
CleanupStack::PushL(console); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
43 |
TInt fsret = fsSession.Connect(); // start a file session |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
44 |
if (fsret != KErrNone) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
45 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
46 |
console->Printf(KTxtConnectFailed,fsret); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
47 |
User::Leave(fsret); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
48 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
49 |
TRAPD(error,doExampleL()); // perform example function |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
50 |
if (error) console->Printf(KTxtFailed, error); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
51 |
else console->Printf(KTxtOK); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
52 |
console->Printf(KTxtPressAnyKey); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
53 |
console->Getch(); // get and ignore character |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
54 |
fsSession.Close(); //close the file session |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
55 |
CleanupStack::PopAndDestroy(); // close console |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
56 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
57 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
58 |
#endif |