0
|
1 |
// Copyright (c) 2006-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 the License "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 |
// e32\kernel\crashgzip.h
|
|
15 |
// Definitions for using Zlib
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#ifndef _CRASHGZIP_H
|
|
20 |
#define _CRASHGZIP_H
|
|
21 |
|
|
22 |
#include "crashwriter.h"
|
|
23 |
#include "zutil.h"
|
|
24 |
#include "zlib.h"
|
|
25 |
#include "deflate.h"
|
|
26 |
|
|
27 |
//********** NOTE ************************************************************
|
|
28 |
// This header MUST updated if the version of Zlib used by the crash
|
|
29 |
// logger is changed from 1.2.3.
|
|
30 |
//****************************************************************************
|
|
31 |
|
|
32 |
/** Sets the size of the history window to be used by delfate()
|
|
33 |
@internalComponent
|
|
34 |
*/
|
|
35 |
const TInt KCrashZlibWinBits = 12; // 4KB window
|
|
36 |
|
|
37 |
/** Sets level of RAM use if deflate, higher value can
|
|
38 |
mean more compression
|
|
39 |
@internalComponent
|
|
40 |
*/
|
|
41 |
const TInt KCrashZlibMemLvl = 4; // 8KB for deflate to play with
|
|
42 |
|
|
43 |
/*****************************************************************************
|
|
44 |
Constants for calculating the size of 'heap' buffers used by deflate.
|
|
45 |
*****************************************************************************/
|
|
46 |
|
|
47 |
/** Constant for w_size extracted from deflateInit2_ (v1.2.3):
|
|
48 |
s->w_bits = windowBits;
|
|
49 |
s->w_size = 1 << s->w_bits;
|
|
50 |
@internalComponent
|
|
51 |
*/
|
|
52 |
const TInt KCrashZlib_w_size = 1 << KCrashZlibWinBits;
|
|
53 |
|
|
54 |
/** Constant for hash_size extracted from deflateInit2_:
|
|
55 |
s->hash_bits = memLevel + 7;
|
|
56 |
s->hash_size = 1 << s->hash_bits;
|
|
57 |
@internalComponent
|
|
58 |
*/
|
|
59 |
const TInt KCrashZlib_hash_size = 1 << (KCrashZlibMemLvl+7);
|
|
60 |
|
|
61 |
/** Constant for lit_bufsize extract from deflateInit2_:
|
|
62 |
s->lit_bufsize = 1 << (memLevel + 6);
|
|
63 |
@internalComponent
|
|
64 |
*/
|
|
65 |
const TInt KCrashZlib_lit_bufsize = 1 << (KCrashZlibMemLvl + 6);
|
|
66 |
|
|
67 |
/*****************************************************************************
|
|
68 |
Constants for the size of the buffers allocated on the 'heap' for the
|
|
69 |
deflate algorithm in deflateInit2_()
|
|
70 |
*****************************************************************************/
|
|
71 |
/** Size of buffer used to keep state of deflate algorthim, deflate_state.
|
|
72 |
@internalComponent
|
|
73 |
*/
|
|
74 |
const TInt KCrashZlibBuf1Size = KCrashZlib_w_size * 2 * sizeof(Byte);
|
|
75 |
|
|
76 |
/** Size of buffer used for history window
|
|
77 |
@internalComponent
|
|
78 |
*/
|
|
79 |
const TInt KCrashZlibBuf2Size = KCrashZlib_w_size * sizeof(ush);
|
|
80 |
|
|
81 |
/** Size of buffer s->prev
|
|
82 |
@internalComponent
|
|
83 |
*/
|
|
84 |
const TInt KCrashZlibBuf3Size = KCrashZlib_hash_size * sizeof(ush);
|
|
85 |
|
|
86 |
/** Size of buffer s->head
|
|
87 |
s->lit_bufsize(*sizeof(ush)+2)
|
|
88 |
@internalComponent
|
|
89 |
*/
|
|
90 |
const TInt KCrashZlibBuf4Size = KCrashZlib_lit_bufsize * (sizeof(ush)+2);
|
|
91 |
|
|
92 |
/******************************************************************************
|
|
93 |
Definitions for creating GZip compatible output using zlib
|
|
94 |
******************************************************************************/
|
|
95 |
|
|
96 |
/** The number of bytes the GZip footer will require.
|
|
97 |
Extracted from rfc1952.txt - GZIP file format specification version 4.3
|
|
98 |
[page 5]
|
|
99 |
@internalComponent
|
|
100 |
*/
|
|
101 |
const TInt KCrashGzipFooterSize = 8;
|
|
102 |
|
|
103 |
/** Amount of bytes required to ensure the gzip file can be closed
|
|
104 |
successfully
|
|
105 |
@internalComponent
|
|
106 |
*/
|
|
107 |
const TInt KCrashGzipFooterMax = KCrashZlibBuf4Size+KCrashGzipFooterSize;
|
|
108 |
|
|
109 |
/** Number of bytes of input data to buffer up before passing to deflate
|
|
110 |
@internalComponent
|
|
111 |
*/
|
|
112 |
const TInt KCrashGzipInBufSize = 128;
|
|
113 |
|
|
114 |
/** Size of the buffer for the deflate to pass it output data to.
|
|
115 |
As deflate is creating the GZIP header & footer info this must be large
|
|
116 |
enough for the gzip header on the first call of
|
|
117 |
@internalComponent
|
|
118 |
*/
|
|
119 |
const TInt KCrashGzipOutBufSize = 128;
|
|
120 |
|
|
121 |
/** Number of seconds elapsed between 01/01/0000 AD and 01/01/1970 AD.
|
|
122 |
Value is the number of days multiplied by the number of seconds per day:
|
|
123 |
719540 * 86400
|
|
124 |
*/
|
|
125 |
const TInt64 KYear1970ADInSeconds = I64LIT(62168256000);
|
|
126 |
|
|
127 |
/** Wrapper class for Zlib deflate
|
|
128 |
@internalComponent
|
|
129 |
*/
|
|
130 |
class MCrashGzip : public MCrashWriter
|
|
131 |
{
|
|
132 |
public:
|
|
133 |
|
|
134 |
/** Initialise ready for data output. Sets the deflate algorithm up.
|
|
135 |
@param aFlash The object to write to the crash logger flash sector
|
|
136 |
*/
|
|
137 |
TBool Init();
|
|
138 |
|
|
139 |
/** Write the passed data via the deflate compressor
|
|
140 |
@param aDes The data to be written
|
|
141 |
@return TInt Returns ETrue if the log output has been truncated
|
|
142 |
*/
|
|
143 |
TBool Write(const TDesC8& aDes);
|
|
144 |
|
|
145 |
/** Ensure all compressed data is written to the crash logger flash
|
|
146 |
and force deflate to output the GZip footer data.
|
|
147 |
*/
|
|
148 |
void FlushEnd();
|
|
149 |
|
|
150 |
/** Return the number of uncompressed bytes contained in the
|
|
151 |
compressed data.
|
|
152 |
@return Number of bytes in the compressed data
|
|
153 |
*/
|
|
154 |
TUint32 GetDataCompressed();
|
|
155 |
|
|
156 |
private:
|
|
157 |
TBuf8<KCrashGzipInBufSize> iInBuf; /** Buffer for deflate input*/
|
|
158 |
TBuf8<KCrashGzipOutBufSize> iOutBuf;/** Buffer for data for crash log sector*/
|
|
159 |
TInt iOutBufLen; /** No of bytes currently in iOutBuf*/
|
|
160 |
|
|
161 |
z_stream iDeflateStrm; /** Stream to be used by deflate*/
|
|
162 |
|
|
163 |
private:
|
|
164 |
/** The max no. of bytes that can be written */
|
|
165 |
TInt iMaxBytes;
|
|
166 |
|
|
167 |
/** The number of bytes output so far*/
|
|
168 |
TInt iBytesOut;
|
|
169 |
};
|
|
170 |
#endif //_CRASHGZIP_H
|