📄 tracetool.cpp.svn-base
字号:
//------------------------------------------------------------------------------
/// <summary>
/// Show or hide the trace program
/// </summary>
void TTrace::Show (bool IsVisible)
{
CommandList Commands ;
if (IsVisible == true)
Commands.Add (CST_SHOW , 1);
else
Commands.Add (CST_SHOW , 0);
TTrace::SendToClient (&Commands);
}
//------------------------------------------------------------------------------
// Sub System
// TODO : static void Flush (FlushTimeOut : integer = 5000);
// TODO : static void stop ; // Stop tracetool sub system. Must be called before exiting plugin
// TODO : static void start ; // restart tracetool sub system if STOP was called
//==========================================================================
/* TMemberNode */
/// <summary>
/// Create a Member node (or a sub member)
/// </summary>
/// <param name="strCol1">optional column 1</param>
/// <param name="strCol2">optional column 2</param>
/// <param name="strCol3">optional column 3</param>
TMemberNode::TMemberNode(const char * strCol1 /* = NULL */, const char * strCol2 /* = NULL */, const char * strCol3 /* = NULL */)
{
if (strCol1 != NULL)
col1 = strCol1;
if (strCol2 != NULL)
col2 = strCol2;
if (strCol3 != NULL)
col3 = strCol3;
// create sub members only if needed
m_Members = NULL ; // new deque <TMemberNode *> ;
m_FontDetails = NULL ;
}
//-------------------------------------------------------------------------
/// <summary>
/// Create a Member node (or a sub member)
/// </summary>
/// <param name="strCol1">optional column 1</param>
/// <param name="strCol2">optional column 2</param>
/// <param name="strCol3">optional column 3</param>
TMemberNode::TMemberNode(const wchar_t * strCol1 , const wchar_t * strCol2 /* = NULL */, const wchar_t * strCol3 /* = NULL */)
{
if (strCol1 != NULL)
{
char * col = TTrace::WideToMbs(strCol1) ;
col1 = col ; // copy
free (col) ;
}
if (strCol2 != NULL)
{
char * col = TTrace::WideToMbs(strCol2) ;
col2 = col ; // copy
free (col) ;
}
if (strCol3 != NULL)
{
char * col = TTrace::WideToMbs(strCol3) ;
col3 = col ; // copy
free (col) ;
}
// create sub members only if needed
m_Members = NULL ; // new deque <TMemberNode *> ;
m_FontDetails = NULL ;
}
//-------------------------------------------------------------------------
/// <summary>
// When a TraceNode is send, the "Members" field is converted to commands.
// The convertion automatically delete all sub members and the "Members" field.
// Destructor is then needed only if you don't send the node.
/// </summary>
TMemberNode::~TMemberNode()
{
if (m_Members != NULL)
{
deque <TMemberNode *>::const_iterator MemberBegin;
deque <TMemberNode *>::const_iterator MemberEnd;
MemberEnd = m_Members->end () ;
for (MemberBegin = m_Members->begin (); MemberBegin < MemberEnd ; MemberBegin++)
{
TMemberNode * member = * MemberBegin ;
delete member ;
}
delete m_Members ;
m_Members = NULL ;
}
if (m_FontDetails != NULL)
{
deque <FontDetail *>::const_iterator FontDetailBegin;
deque <FontDetail *>::const_iterator FontDetailEnd;
FontDetailEnd = m_FontDetails->end () ;
for (FontDetailBegin = m_FontDetails->begin (); FontDetailBegin < FontDetailEnd ; FontDetailBegin++)
{
FontDetail * fontDetail = * FontDetailBegin ;
delete fontDetail ;
}
delete m_FontDetails ;
m_FontDetails = NULL ;
}
}
//-------------------------------------------------------------------------
/// <summary>
// create sub members only if needed
/// </summary>
deque <TMemberNode *> * TMemberNode::Members()
{
if (m_Members == NULL)
m_Members = new deque <TMemberNode *> ;
return m_Members ;
}
//-------------------------------------------------------------------------
/// <summary>
/// Recursively add members to the node commandList
/// <summary>
/// <param name="commands">Where to store members </param>
void TMemberNode::AddToStringList (CommandList * commands)
{
if (m_Members == NULL)
return ;
// the root node node itself is not send
deque <TMemberNode *>::const_iterator MemberBegin;
deque <TMemberNode *>::const_iterator MemberEnd;
MemberEnd = m_Members->end () ;
for (MemberBegin = m_Members->begin (); MemberBegin < MemberEnd ; MemberBegin++)
{
TMemberNode * member = * MemberBegin ;
member->_AddToStringList(commands);
delete member ; // delete sub members
}
delete m_Members ; // delete member array
m_Members = NULL ;
}
//-------------------------------------------------------------------------
/// internal recursive
void TMemberNode::_AddToStringList (CommandList * commands)
{
commands->Add (CST_CREATE_MEMBER, col1.c_str()) ; // first column can be NULL
if (! col2.empty())
commands->Add (CST_MEMBER_COL2, col2.c_str()) ;
if (! col3.empty())
commands->Add (CST_MEMBER_COL3, col3.c_str()) ;
if (m_FontDetails != NULL)
{
deque <FontDetail *>::const_iterator FontBegin;
deque <FontDetail *>::const_iterator FontEnd;
FontEnd = m_FontDetails->end () ;
for (FontBegin = m_FontDetails->begin (); FontBegin < FontEnd ; FontBegin++)
{
FontDetail * font = * FontBegin ;
char * message ;
int bold = (font->Bold ) ? 1 : 0 ;
int italic = (font->Italic) ? 1 : 0;
int MsgLen ;
if (font->FontName.empty())
{
message = (char*)malloc(32+1) ;
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && (! UNDER_CE) // visual studio 2005 : deprecated function
sprintf_s(message, 33,"%5d%3d%1d%1d%11d%11d", CST_MEMBER_FONT_DETAIL,font->ColId,bold,italic,font->Color,font->Size);
#else
sprintf(message, "%5d%3d%1d%1d%11d%11d", CST_MEMBER_FONT_DETAIL,font->ColId,bold,italic,font->Color,font->Size);
#endif
} else {
MsgLen = font->FontName.length()+32+1 ;
message = (char*)malloc(MsgLen) ;
const char * fontName = font->FontName.c_str() ;
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && (! UNDER_CE) // visual studio 2005 : deprecated function
sprintf_s(message, MsgLen,"%5d%3d%1d%1d%11d%11d%s", CST_MEMBER_FONT_DETAIL,font->ColId,bold,italic,font->Color,font->Size,fontName);
#else
sprintf(message, "%5d%3d%1d%1d%11d%11d%s", CST_MEMBER_FONT_DETAIL,font->ColId,bold,italic,font->Color,font->Size,fontName);
#endif
}
commands->push_back (message) ;
free (message) ;
delete font ;
}
delete m_FontDetails ;
m_FontDetails = NULL ;
}
if (m_Members != NULL)
{
deque <TMemberNode *>::const_iterator MemberBegin;
deque <TMemberNode *>::const_iterator MemberEnd;
MemberEnd = m_Members->end () ;
for (MemberBegin = m_Members->begin (); MemberBegin < MemberEnd ; MemberBegin++)
{
TMemberNode * member = * MemberBegin ;
member->_AddToStringList(commands);
delete member ;
}
delete m_Members ;
m_Members = NULL ;
}
commands->Add (CST_ADD_MEMBER) ; // close the member group
}
//-------------------------------------------------------------------------
/// <summary>
/// Add a sub member. NOTE : the member in argument will be destroyed when the container node is destroyed
/// </summary>
/// <param name="member">an already constructed sub member</param>
TMemberNode * TMemberNode::Add (TMemberNode * member)
{
Members()->push_back(member);
return member;
}
//-------------------------------------------------------------------------
/// <summary>
/// create and add a sub member
/// </summary>
/// <param name="strCol1">Column 1 of the new sub member</param>
/// <param name="strCol1">Optional column 2 of the new sub member</param>
/// <param name="strCol1">Optional column 3 of the new sub member</param>
TMemberNode * TMemberNode::Add (const char * strCol1 , const char * strCol2 /* = NULL */, const char * strCol3 /* = NULL */)
{
TMemberNode * member;
member = new TMemberNode (strCol1, strCol2, strCol3);
Add(member);
return member;
}
//-------------------------------------------------------------------------
/// <summary>
/// Set member font
/// </summary>
/// <param name="ColId">Column number (-1,0,1,2)</param>
/// <param name="Bold">Change font to bold</param>
/// <param name="Italic">Change font to Italic</param>
/// <param name="Color">Change Color. Use -1 to keep default color</param>
/// <param name="Size">Change font size, use zero to keep normal size</param>
/// <param name="FontName">Change font name</param>
/// <returns>The TMemberNode </returns>
TMemberNode * TMemberNode::SetFontDetail(const int ColId, const bool Bold , const bool Italic /*= false*/ , const int Color /*= -1*/ , const int Size /*= 0*/ , const char * FontName /*= NULL*/)
{
if (m_FontDetails == NULL)
m_FontDetails = new deque <FontDetail *> ;
FontDetail * font = new FontDetail() ;
font->ColId = ColId ;
font->Bold = Bold ;
font->Italic = Italic ;
font->Color = Color ;
font->Size = Size ;
if (FontName != NULL)
font->FontName = FontName ;
m_FontDetails->push_back(font);
return this ;
}
//-------------------------------------------------------------------------
/// <summary>
/// create and add a sub member
/// </summary>
/// <param name="strCol1">Column 1 of the new sub member</param>
/// <param name="strCol1">Optional column 2 of the new sub member</param>
/// <param name="strCol1">Optional column 3 of the new sub member</param>
TMemberNode * TMemberNode::Add (const wchar_t * strCol1 , const wchar_t * strCol2 /* = NULL */, const wchar_t * strCol3 /* = NULL */)
{
TMemberNode * member;
member = new TMemberNode (strCol1, strCol2, strCol3);
Add(member);
return member;
}
//==========================================================================
/* TraceOptions */
/// <summary>
/// TraceTool Options constructor
/// </summary>
TraceOptions::TraceOptions (void)
{
SendProcessName = false ;
SendDate = false ;
m_processFileName = NULL ;
socketHost = NULL ;
socketPort = 8090 ;
#ifdef _WIN32_WCE
// for pocket pc : default is socket and host on 192.168.55.100
sendMode = Socket ;
SetSocketHost("192.168.55.100");
#else
// For windows desktop : default is windows messages. In case of you switch to socket, the default host is localhost
sendMode = WinMsg ;
SetSocketHost("127.0.0.1");
#endif
}
//-------------------------------------------------------------------------
/// <summary>
/// TraceTool Options destructor
/// </summary>
TraceOptions::~TraceOptions(void)
{
if (socketHost != NULL)
free (socketHost) ;
if (m_processFileName != NULL)
free (m_processFileName) ;
}
//-------------------------------------------------------------------------
/// <summary>
/// Set the socket host
/// </summary>
/// <param name="Host">socket host</param>
void TraceOptions::SetSocketHost (const char * Host)
{
if (socketHost != NULL)
free (socketHost) ;
socketHost = NULL ;
if (Host == NULL)
return ;
int lenhost = strlen(Host) + 1 ;
socketHost = (char *) malloc (lenhost) ;
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && (! UNDER_CE) // visual studio 2005 : deprecated function
strcpy_s (socketHost, lenhost, Host) ;
#else
strcpy (socketHost, Host) ;
#endif
}
//-------------------------------------------------------------------------
void TraceOptions::SetSocketHost (const wchar_t * Host)
{
if (socketHost != NULL)
free (socketHost) ;
socketHost = TTrace::WideToMbs(Host) ;
}
//-------------------------------------------------------------------------
/// <summary>
/// Helper function : return the process name without path
/// </summary>
const char * TraceOptions::CheckProcessName (void)
{
if (m_processFileName == NULL)
{
WCHAR wFileName [MAX_PATH+1] ;
size_t nbChar ;
// use wide GetModuleFileNameW in place of GetModuleFileNameA for winCE compatibility
wFileName[GetModuleFileNameW (0 /* hInstance */ ,wFileName,MAX_PATH)] = 0;
// Convert widestring (wcs) to multibyte string (mbs)
char *pmbFilename = (char *)malloc( MAX_PATH+1 );
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && (! UNDER_CE) // visual studio 2005 : deprecated function
//size_t i ;
//nbChar =
wcstombs_s(&nbChar, pmbFilename, MAX_PATH+1, wFileName, MAX_PATH );
#else
nbChar = wcstombs( pmbFilename, wFileName, MAX_PATH );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -