Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Symbian debugging and profiling functions
23 #if defined(M3G_SYMBIAN_REMOTE_LOGGING)
24 #include <EcmtClient.h>
31 # if defined(M3G_SYMBIAN_REMOTE_LOGGING)
35 # if defined(M3G_ENABLE_PROFILING)
36 M3Guint tickCount[M3G_STAT_MAX];
37 M3Guint lastOutputTickCount;
41 /*----------------------------------------------------------------------
43 *--------------------------------------------------------------------*/
46 * \brief Symbian implementation of the block inflation function for
49 extern "C" M3Gsizei m3gSymbianInflateBlock(M3Gsizei srcLength,
56 M3G_ASSERT(srcLength > 0);
59 uLongf len = (uLongf) dstLength;
60 if (uncompress((Bytef *) dst, &len,
61 (const Bytef *) src, (uLong) srcLength) != Z_OK) {
64 return (M3Gsizei) len;
69 * \brief Logging function
71 * \note This currently creates a session to the file server for each
72 * message, so performance will be sub-optimal if logging is frequent
74 extern "C" void m3gLogMessage(const char *format, ...)
76 # if !defined(M3G_SYMBIAN_REMOTE_LOGGING)
77 _LIT(KFileName, "c:\\m3g_event.log");
82 if (fileSrv.Connect() != KErrNone) {
86 TInt accessMode = EFileWrite|EFileShareExclusive;
87 TInt err = file.Open(fileSrv, KFileName, accessMode);
89 // If the file exists, seek to the end; if it doesn't, create it
91 if (err == KErrNone) {
93 file.Seek(ESeekEnd, pos);
95 else if (err == KErrNotFound) {
96 if (file.Create(fileSrv, KFileName, accessMode) != KErrNone) {
101 # endif // !M3G_SYMBIAN_REMOTE_LOGGING
103 // Format and write the message
106 TPtrC8 aFormat((const TUint8 *) format);
109 VA_START(aList, format);
111 msg.FormatList(aFormat, aList);
115 # if defined(M3G_SYMBIAN_REMOTE_LOGGING)
117 M3GLogger *logger = (M3GLogger*) Dll::Tls();
122 logger->iEcmt.Write(msg16);
128 // Close the file and the server connection
134 # endif // !M3G_SYMBIAN_REMOTE_LOGGING
138 * \brief Create new log file
140 extern "C" void m3gBeginLog(void)
142 # if defined(M3G_SYMBIAN_REMOTE_LOGGING)
144 M3GLogger *logger = (M3GLogger*) Dll::Tls();
147 logger = new M3GLogger();
148 logger->refCount = 0;
149 logger->lastOutputTickCount = User::TickCount();
153 if (++logger->refCount == 1) {
154 logger->iEcmt.Connect();
159 /* Just delete any existing log file */
161 _LIT(KFileName, "c:\\m3g_event.log");
166 if (fileSrv.Connect() != KErrNone) {
170 TInt accessMode = EFileWrite|EFileShareExclusive;
171 if (file.Replace(fileSrv, KFileName, accessMode) == KErrNone) {
177 # endif // !M3G_SYMBIAN_REMOTE_LOGGING
179 /* Output initial message(s) */
181 m3gLogMessage("--- M3G event log ---\n");
187 extern "C" void m3gEndLog(void)
189 # if defined(M3G_SYMBIAN_REMOTE_LOGGING)
191 M3GLogger *logger = (M3GLogger*) Dll::Tls();
193 if (--logger->refCount == 0) {
194 logger->iEcmt.Close();
202 m3gLogMessage("--- end of log ---\n");
206 * \brief Assertion handler
208 extern "C" void m3gAssertFailed(const char *filename, int line)
210 M3G_LOG2(M3G_LOG_ALL, "Assertion failed: %s, line %d\n", filename, line);
211 User::Panic(_L("M3G-ASSERT"), line);
214 #if defined(M3G_BUILD_DLL)
216 * \brief DLL load check
219 GLDEF_C TInt E32Dll( TDllReason /* aReason */ )
224 #endif /* M3G_BUILD_DLL */
226 /*----------------------------------------------------------------------
228 *--------------------------------------------------------------------*/
230 #if defined(M3G_ENABLE_PROFILING)
232 extern "C" void m3gCleanupProfile(void)
237 extern "C" void m3gBeginProfile(int stat)
239 M3GLogger *logger = (M3GLogger*) Dll::Tls();
241 logger->tickCount[stat] = User::TickCount();
245 extern "C" int m3gEndProfile(int stat)
247 M3GLogger *logger = (M3GLogger*) Dll::Tls();
249 return User::TickCount() - logger->tickCount[stat];
254 extern "C" M3Gint m3gProfileTriggered(void)
256 # if (M3G_PROFILE_LOG_INTERVAL > 0)
257 M3GLogger *logger = (M3GLogger*) Dll::Tls();
259 M3Guint tickCount = User::TickCount();
260 M3Guint delta = tickCount - logger->lastOutputTickCount;
261 if (delta >= M3G_PROFILE_LOG_INTERVAL) {
262 logger->lastOutputTickCount = tickCount;
263 return (M3Gint) delta;