#ifndef __TOOLBOX_HELPER
#define __TOOLBOX_HELPER

#include "toolboxdebug.h"

// internal logging
#ifdef UNDER_CE
	#define MAX_LogFileSize	100000
#else
	#define MAX_LogFileSize	1000000
#endif


bool GetAppDataDir(LPTSTR lpDir, size_t size, LPCTSTR lpSubFolder = NULL);

/**
 *

 Include (eg. add to the project's stdafx.h):

 #include "toolboxdebug.h"
 #include "toolboxdebugsettings.h"
 #include "toolbox.h"
 ______________________________________________

 Preprocessor defn:

 1. TBD_DEBUG - enables this logging module
 2. TBD_ENCRYPT - enables simple encryption to log file
 ______________________________________________

 Add all files to the project from the TOOLBOX folder:

 ToolboxHelper.cpp
 ToolboxHelper.h
 toolbox.cpp
 toolbox.h
 toolboxdebug.cpp
 toolboxdebug.h
 toolboxdebugsettings.cpp
 toolboxdebugsettings.h
 ToolBoxW4Settings.h
 Usage.txt
 Windows_W3.h
 ______________________________________________

 Projects setting:

 Precompiled Headers->Create/Use Precompiled Header:

 1. StdAfx.cpp - set to "Create Precompiled Header"
 2. All other files - set to "Automatically Generate"

 ______________________________________________

 ToolboxHelper:

 - creates the log file into the user's temp folder for Win2K and newer:
 C:\Documents and Settings\<username>\Application Data\Sierra Wireless Inc\Logs

 - defines the max log file size as: 100000000 bytes
 - therefore once the logfile reaches the max, a new file will be created (the old file will be backed up)

 ______________________________________________

 High-level usage summary:
 -	define TBD_DEBUG in your project settings
 -	Call ToolboxHelper::LoggingInit();
 -	Call TBD API's to add log items (see Usage)
 -	Call ToolboxHelper::LoggingDeinit();


 Logging Levels:

 For each log item, the class and level determines what will be entered into the log file.

 // valid class types
 TBDCT_ALL, TBDCT_ALL_FUNCTIONS, TBDCT_ALL_MEMORY, TBDCT_INFO, TBDCT_ALWAYS

 // Valid tracing levels - from lowest to highest priority ie TBDOL_ERROR highest
 TBDOL_TRACE - mainly used for debugging/tracing purposes (usually not enabled for release builds)
 TBDOL_FUNC - logs function information; enter, exit, execution time ie. function profiling
 TBDOL_INFORMATION - used for logging data values - usually included in rel builds
 TBDOL_ERROR - logs errors


 Filters:
 - ToolboxHelper currently enables ALL logging (ie. no filters are set):
 TBD_ENABLE_CLASS(TBDCT_ALL, TRUE);
 TBD_ENABLE_CLASS(TBDCT_ALL_FUNCTIONS, TRUE);
 TBD_ENABLE_CLASS(TBDCT_ALL_MEMORY, TRUE);
 TBD_ENABLE_CLASS(TBDCT_INFO, TRUE);
 TBD_ENABLE_CLASS(TBDCT_READ, TRUE);
 TBD_SET_LEVEL(TBDOL_TRACE);


 Eg:
 TBD_ENABLE_CLASS(TBDCT_ALL_FUNCTIONS, FALSE) - disables all function logging: TBD_FUNCTION()

 TBD_SET_LEVEL(TBDOL_INFORMATION) - enables log items with TBDOL_INFORMATION and higher priority:

 - NOT logged: 
 TBD_OUTPUT(TBDCT_INFO, TBDOL_TRACE, TEXT("DllMain : DLL_PROCESS_DETACH"));

 - LOGGED:
 TBD_OUTPUT(TBDCT_INFO, TBDOL_INFORMATION, TEXT("DllMain : DLL_PROCESS_DETACH"));



 Usage:
 -	TBD_FUNCTION (Function Name) - logs execution time and statistics
 -	TBD_OUTPUT (string) - logs the formatted info you want
 -	TBD_OUTPUT (TBDCT_ALWAYS, TBDOL_ERROR, _T("ERROR: ")) - ERROR log; will always be logged regardless of the logging class/levels
 -	TBD_ASSERT(0) - same syntax as ASSERT(), however, this func will log the file and line # of the assertion location.

 -	TBD_OUTPUT(TBDCT_INFO, TBDOL_TRACE, TEXT("debug logs")) - debug logs
 -	TBD_OUTPUT(TBDCT_INFO, TBDOL_INFORMATION, TEXT("release log")) - release logs

 ______________________________________________


 Sample code:

 Initialization:

 #define TBD_MMM_OUTPUT_FILE_NAME	TEXT("swimmmcomm.txt")
 #define TBD_MMM_OUTPUT_TITLE		TEXT("swimmmcomm")


 #ifdef TBD_DEBUG
 LoggingInit LOG_OUTPUT_FILE_NAME, LOG_OUTPUT_TITLE);
 TBD_OUTPUT(TBDCT_ALWAYS, TBDOL_TRACE, TEXT("DllMain : DLL_PROCESS_ATTACH"));


 TBD_OUTPUT(TBDCT_ALWAYS, TBDOL_TRACE, TEXT("DllMain : DLL_PROCESS_DETACH"));
 LoggingDeinit ();
 #endif


 Logging:

 For sample code, see: $\Projects\SwiSoftware\Dlls\SwiCxnMgr\SwiCxnMgr.cpp


 ----------------- End of document ---------------------
*/
 //////////////////////////////////////////////////////////////////////////
 // Name:		STRUCT_TBD_Logging
 //
 // Description:	TBD logging structure
 //
 // Notes:		
 //////////////////////////////////////////////////////////////////////////
struct STRUCT_TBD_Logging
{
	TBD_OUTPUT_LEVEL	eLevel;					// logging level
	bool				bTbdAllFunc;			// function flag
	bool				bTbdAllMem;				// memory flag
	bool				bTbdInfo;				// info flag
	bool				bTbdRead;				// read flag
	DWORD				nMaxLogSize;			// log file size
	HKEY				hKey;					// registry key
	bool				bMainApp;				// set to true if main application
	TCHAR				strFileName[MAX_PATH];	// filename of the module/application
};

 /*param lpFileName 
 * \param lpTitle 
 * \param bCreateNew	- true to create fresh new file each time
 *						- false to append to existing log file
 * \param pLogging		- default logging settings
 * \param hModule		- DLL instance handle (optional), usually the HINSTANCE parameter of DllMain. 
 *
 * \return	1: if success
 *			0: if failure
 *
 * \comment		If calling from DllMain, ensure pLogging is not NULL and hModule is set to the 
 *              HINSTANCE parameter of DllMain.  
 */
int		LoggingInit (LPTSTR lpFileName, LPTSTR lpTitle, bool bCreateNew = true, STRUCT_TBD_Logging* pLogging = NULL, HMODULE hModule = NULL);
void	LoggingDeinit ();

////////////////////////////////////////////////////////////////////////////////
//
//   Function   :	LogModuleVersion
//
//   Description:	Get the current module version
//
//   Arguments  :	[IN] lpstrModule - name of module
//
//   Returns:   :	true if successfully retrieved version information, false otherwise
//
////////////////////////////////////////////////////////////////////////////////
bool LogModuleVersion(LPTSTR lpstrModule);

////////////////////////////////////////////////////////////////////////////////
//
//   Function   :	LogModuleVersion
//
//   Description:	Get the current module version
//
//   Arguments  :	[IN] hModule - instance handle of module.
//
//   Returns:   :	true if successfully retrieved version information, false otherwise
//
//   Comments   :	Set hModule = NULL to get the main application version
//
////////////////////////////////////////////////////////////////////////////////
bool LogModuleVersion(HMODULE hModule);

////////////////////////////////////////////////////////////////////////////////
//
//   Function   :	GetExeDir
//
//   Description:	Get the current executable directory
//
//   Arguments  :	[OUT] lpDir - buffer to contain the path
//
//   Returns:   :	true if path retrieved, false otherwise
//
//   Comments   :	MAKE SURE lpDir is at least size MAX_PATH.
//					THIS FUNCTION PERFORMS NO ERROR CHECKING.
//
////////////////////////////////////////////////////////////////////////////////
bool GetExeDir(LPTSTR lpDir, size_t size);

#endif // __TOOLBOX_HELPER
