ApiLog.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // FileZilla - a Windows ftp client
  2. // Copyright (C) 2002-2004 - Tim Kosse <[email protected]>
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License
  5. // as published by the Free Software Foundation; either version 2
  6. // of the License, or (at your option) any later version.
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License for more details.
  11. // You should have received a copy of the GNU General Public License
  12. // along with this program; if not, write to the Free Software
  13. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. // ApiLog.cpp: Implementierung der Klasse CApiLog.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "ApiLog.h"
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char THIS_FILE[]=__FILE__;
  22. #define new DEBUG_NEW
  23. #endif
  24. //////////////////////////////////////////////////////////////////////
  25. // Konstruktion/Destruktion
  26. //////////////////////////////////////////////////////////////////////
  27. CApiLog::CApiLog()
  28. {
  29. m_hTargetWnd=0;
  30. m_pApiLogParent=0;
  31. m_nDebugLevel=0;
  32. }
  33. CApiLog::~CApiLog()
  34. {
  35. }
  36. BOOL CApiLog::InitLog(CApiLog *pParent)
  37. {
  38. if (!pParent)
  39. return FALSE;
  40. while (pParent->m_pApiLogParent)
  41. pParent=pParent->m_pApiLogParent;
  42. m_hTargetWnd=0;
  43. m_pApiLogParent=pParent;
  44. return TRUE;
  45. }
  46. BOOL CApiLog::InitLog(HWND hTargetWnd, int nLogMessage)
  47. {
  48. if (!hTargetWnd)
  49. return FALSE;
  50. m_hTargetWnd=hTargetWnd;
  51. m_nLogMessage=nLogMessage;
  52. m_pApiLogParent=0;
  53. return TRUE;
  54. }
  55. void CApiLog::LogMessage(int nMessageType, LPCTSTR pMsgFormat, ...) const
  56. {
  57. ASSERT(nMessageType>=0 || nMessageType<=8);
  58. ASSERT(m_hTargetWnd || m_pApiLogParent);
  59. if (nMessageType>=FZ_LOG_APIERROR && (nMessageType-FZ_LOG_APIERROR)>=m_pApiLogParent->m_nDebugLevel)
  60. return;
  61. va_list ap;
  62. va_start(ap, pMsgFormat);
  63. CString text;
  64. text.FormatV(pMsgFormat, ap);
  65. va_end(ap);
  66. #ifdef MPEXT
  67. if (nMessageType>=FZ_LOG_DEBUG)
  68. return;
  69. #endif
  70. SendLogMessage(nMessageType, text);
  71. }
  72. void CApiLog::LogMessageRaw(int nMessageType, LPCTSTR pMsg) const
  73. {
  74. ASSERT(nMessageType>=0 || nMessageType<=8);
  75. ASSERT(m_hTargetWnd || m_pApiLogParent);
  76. if (nMessageType>=FZ_LOG_APIERROR && (nMessageType-FZ_LOG_APIERROR)>=m_pApiLogParent->m_nDebugLevel)
  77. return;
  78. #ifdef MPEXT
  79. if (nMessageType>=FZ_LOG_DEBUG)
  80. return;
  81. #endif
  82. SendLogMessage(nMessageType, pMsg);
  83. }
  84. void CApiLog::LogMessage(int nMessageType, UINT nFormatID, ...) const
  85. {
  86. ASSERT(nMessageType>=0 || nMessageType<=8);
  87. ASSERT(m_hTargetWnd || m_pApiLogParent);
  88. if (nMessageType>=FZ_LOG_APIERROR && (nMessageType-FZ_LOG_APIERROR)>=m_pApiLogParent->m_nDebugLevel)
  89. return;
  90. CString str;
  91. str.LoadString(nFormatID);
  92. va_list ap;
  93. va_start(ap, nFormatID);
  94. CString text;
  95. text.FormatV(str, ap);
  96. va_end(ap);
  97. #ifdef MPEXT
  98. if (nMessageType>=FZ_LOG_DEBUG)
  99. return;
  100. #endif
  101. SendLogMessage(nMessageType, text);
  102. }
  103. void CApiLog::LogMessage(CString SourceFile, int nSourceLine, void *pInstance, int nMessageType, LPCTSTR pMsgFormat, ...) const
  104. {
  105. ASSERT(nMessageType>=4 || nMessageType<=8);
  106. ASSERT(m_hTargetWnd || m_pApiLogParent);
  107. ASSERT(nSourceLine>0);
  108. int pos=SourceFile.ReverseFind('\\');
  109. if (pos!=-1)
  110. SourceFile=SourceFile.Mid(pos+1);
  111. va_list ap;
  112. va_start(ap, pMsgFormat);
  113. CString text;
  114. text.FormatV(pMsgFormat, ap);
  115. va_end(ap);
  116. #ifdef MPEXT
  117. if (nMessageType>=FZ_LOG_DEBUG)
  118. return;
  119. #endif
  120. CString msg;
  121. msg.Format(_T("%s(%d): %s caller=0x%08x"), SourceFile, nSourceLine, text, (int)this);
  122. SendLogMessage(nMessageType, msg);
  123. }
  124. #ifdef MPEXT
  125. BOOL CApiLog::PostMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) const
  126. {
  127. return m_pApiLogParent->PostMessage(hWnd, Msg, wParam, lParam);
  128. }
  129. #endif
  130. void CApiLog::LogMessageRaw(CString SourceFile, int nSourceLine, void *pInstance, int nMessageType, LPCTSTR pMsg) const
  131. {
  132. ASSERT(nMessageType>=4 || nMessageType<=8);
  133. ASSERT(m_hTargetWnd || m_pApiLogParent);
  134. ASSERT(nSourceLine>0);
  135. int pos=SourceFile.ReverseFind('\\');
  136. if (pos!=-1)
  137. SourceFile=SourceFile.Mid(pos+1);
  138. #ifdef MPEXT
  139. if (nMessageType>=FZ_LOG_DEBUG)
  140. return;
  141. #endif
  142. CString msg;
  143. msg.Format(_T("%s(%d): %s caller=0x%08x"), SourceFile, nSourceLine, pMsg, (int)this);
  144. SendLogMessage(nMessageType, msg);
  145. }
  146. void CApiLog::SendLogMessage(int nMessageType, LPCTSTR pMsg) const
  147. {
  148. #ifdef MPEXT
  149. ASSERT(m_pApiLogParent);
  150. ASSERT(m_pApiLogParent->m_hTargetWnd == 0);
  151. ASSERT(m_pApiLogParent->m_nLogMessage == 0);
  152. if (nMessageType>=FZ_LOG_APIERROR && (nMessageType-FZ_LOG_APIERROR)>=m_pApiLogParent->m_nDebugLevel)
  153. return;
  154. //Displays a message in the message log
  155. t_ffam_statusmessage *pStatus = new t_ffam_statusmessage;
  156. pStatus->post = TRUE;
  157. pStatus->status = pMsg;
  158. pStatus->type = nMessageType;
  159. if (!this->PostMessage(m_pApiLogParent->m_hTargetWnd, m_pApiLogParent->m_nLogMessage, FZ_MSG_MAKEMSG(FZ_MSG_STATUS, 0), (LPARAM)pStatus))
  160. delete pStatus;
  161. #else
  162. if (m_hTargetWnd)
  163. {
  164. ASSERT(m_nLogMessage);
  165. if (nMessageType>=FZ_LOG_APIERROR && (nMessageType-FZ_LOG_APIERROR)>=m_nDebugLevel)
  166. return;
  167. }
  168. else
  169. {
  170. ASSERT(m_pApiLogParent);
  171. ASSERT(m_pApiLogParent->m_hTargetWnd);
  172. ASSERT(m_pApiLogParent->m_nLogMessage);
  173. if (nMessageType>=FZ_LOG_APIERROR && (nMessageType-FZ_LOG_APIERROR)>=m_pApiLogParent->m_nDebugLevel)
  174. return;
  175. }
  176. //Displays a message in the message log
  177. t_ffam_statusmessage *pStatus = new t_ffam_statusmessage;
  178. pStatus->post = TRUE;
  179. pStatus->status = pMsg;
  180. pStatus->type = nMessageType;
  181. if (m_hTargetWnd)
  182. {
  183. if (!PostMessage(m_hTargetWnd, m_nLogMessage, FZ_MSG_MAKEMSG(FZ_MSG_STATUS, 0), (LPARAM)pStatus))
  184. delete pStatus;
  185. }
  186. else
  187. if (!PostMessage(m_pApiLogParent->m_hTargetWnd, m_pApiLogParent->m_nLogMessage, FZ_MSG_MAKEMSG(FZ_MSG_STATUS, 0), (LPARAM)pStatus))
  188. delete pStatus;
  189. #endif
  190. }
  191. BOOL CApiLog::SetDebugLevel(int nDebugLevel)
  192. {
  193. if (m_pApiLogParent)
  194. return FALSE;
  195. if (nDebugLevel<0 || nDebugLevel>4)
  196. return FALSE;
  197. m_nDebugLevel=nDebugLevel;
  198. return TRUE;
  199. }
  200. int CApiLog::GetDebugLevel()
  201. {
  202. if (m_pApiLogParent)
  203. return m_pApiLogParent->m_nDebugLevel;
  204. return m_nDebugLevel;
  205. }