|
1 /* |
|
2 * Copyright (c) 2005-2009 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 * Demonstration use of the TestExecute standalone PIPS logger client API |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 @file TestExecutePIPSLoggerTest.cpp |
|
23 */ |
|
24 |
|
25 #include <testexecutepipslog.h> |
|
26 #include <e32cons.h> |
|
27 #include <stdio.h> |
|
28 #include <errno.h> |
|
29 #include <sys/stat.h> |
|
30 #include <sys/fcntl.h> |
|
31 |
|
32 _LIT(KLogFile1,"c:/pipe_no1"); |
|
33 _LIT(K16BitText,"This is a short line of 16 Bit Text"); |
|
34 _LIT8(K8BitText,"This is a short line of 8 Bit Text"); |
|
35 _LIT(K16BitFormatText,"This is a short line of 16 Bit Format Text int = %d string = %S"); |
|
36 _LIT8(K8BitFormatText,"This is a short line of 8 Bit Format Text int = %d string = %S"); |
|
37 _LIT(K16BitString,"The String16"); |
|
38 _LIT8(K8BitString,"The String8"); |
|
39 |
|
40 #define HALF_DUPLEX "c:/pipe_no1" |
|
41 #define MAX_BUF_SIZE 255 |
|
42 |
|
43 void MainL() |
|
44 { |
|
45 |
|
46 /* Create the named - pipe */ |
|
47 int ret_val = mkfifo(HALF_DUPLEX, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH); |
|
48 |
|
49 if ((ret_val == -1) && (errno != EEXIST)) { |
|
50 perror("Error creating the named pipe"); |
|
51 return ; |
|
52 //exit (1); |
|
53 } |
|
54 |
|
55 int pipe = open(HALF_DUPLEX, O_RDONLY | O_NONBLOCK); |
|
56 |
|
57 _LIT(KTitle,"TestExecute Standalone Logger Test Code"); |
|
58 CConsoleBase* console = Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen)); |
|
59 CleanupStack::PushL(console); |
|
60 |
|
61 _LIT(KMessage1,"Connect() To Logger and Close() immediately\r\n"); |
|
62 console->Printf(KMessage1); |
|
63 RTestExecutePIPSLogServ logger; |
|
64 User::LeaveIfError(logger.Connect()); |
|
65 logger.Close(); |
|
66 |
|
67 _LIT(KMessage2,"Immediate re-Connect() To Logger and Close() immediately\r\n"); |
|
68 console->Printf(KMessage2); |
|
69 User::LeaveIfError(logger.Connect()); |
|
70 logger.Close(); |
|
71 |
|
72 _LIT(KMessage3,"Immediate re-Connect() To Logger CreateLog() and Close() immediately\r\n"); |
|
73 console->Printf(KMessage3); |
|
74 User::LeaveIfError(logger.Connect()); |
|
75 User::LeaveIfError(logger.CreateLog(KLogFile1)); |
|
76 logger.Close(); |
|
77 |
|
78 // OS needs time to shutdown the server |
|
79 // No delay means we get server terminated from the OS |
|
80 User::After(1000000); |
|
81 |
|
82 _LIT(KMessage4,"Connect() To Logger CreateLog() %S Call API's\r\n"); |
|
83 TBuf<80> logFile(KLogFile1); |
|
84 console->Printf(KMessage4,&logFile); |
|
85 User::LeaveIfError(logger.Connect()); |
|
86 User::LeaveIfError(logger.CreateLog(KLogFile1)); |
|
87 TBuf<20> buf16(K16BitString); |
|
88 TBuf8<20> buf8(K8BitString); |
|
89 logger.Write(K16BitText); |
|
90 logger.Write(K8BitText); |
|
91 logger.WriteFormat(K16BitFormatText,16,&buf16); |
|
92 logger.WriteFormat(K8BitFormatText,8,&buf8); |
|
93 logger.LogExtra(((TText8*)__FILE__), __LINE__,ESevrInfo,K16BitFormatText,1,&buf16); |
|
94 |
|
95 _LIT(KMessage5,"ALL API's Called - Call Close(),\r\n"); |
|
96 console->Printf(KMessage5); |
|
97 //console->Getch(); |
|
98 logger.Close(); |
|
99 |
|
100 //try an empty pipe |
|
101 _LIT(KLogFileEmpty,""); |
|
102 _LIT(KMessageEmp,"Connect() To Logger CreateLog() %S Call API's\r\n"); |
|
103 TBuf<80> logFiley(KLogFileEmpty); |
|
104 console->Printf(KMessageEmp,&logFiley); |
|
105 User::LeaveIfError(logger.Connect()); |
|
106 User::LeaveIfError(logger.CreateLog(KLogFileEmpty)); |
|
107 logger.Write(K16BitText); |
|
108 logger.Write(K8BitText); |
|
109 logger.WriteFormat(K16BitFormatText,16,&buf16); |
|
110 logger.WriteFormat(K8BitFormatText,8,&buf8); |
|
111 logger.LogExtra(((TText8*)__FILE__), __LINE__,ESevrInfo,K16BitFormatText,1,&buf16); |
|
112 console->Printf(KMessage5); |
|
113 console->Getch(); |
|
114 logger.Close(); |
|
115 |
|
116 CleanupStack::PopAndDestroy(console); |
|
117 |
|
118 } |
|
119 |
|
120 // Entry point for all Epoc32 executables |
|
121 // See PSP Chapter 2 Getting Started |
|
122 int main(int,char**,char* ) |
|
123 { |
|
124 // Heap balance checking |
|
125 // See PSP Chapter 6 Error Handling |
|
126 __UHEAP_MARK; |
|
127 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
128 if(cleanup == NULL) |
|
129 { |
|
130 return KErrNoMemory; |
|
131 } |
|
132 TRAPD(err,MainL()); |
|
133 _LIT(KPanic,"PIPSLoggerTest"); |
|
134 __ASSERT_ALWAYS(!err, User::Panic(KPanic,err)); |
|
135 delete cleanup; |
|
136 __UHEAP_MARKEND; |
|
137 return KErrNone; |
|
138 } |