| 1 |
#include "xap_Log.h" |
| 2 |
#include <stdio.h> |
| 3 |
#include "ut_string_class.h" |
| 4 |
#include "ut_string.h" |
| 5 |
#include "xav_View.h" |
| 6 |
#include "ev_EditMethod.h" |
| 7 |
|
| 8 |
XAP_Log *XAP_Log::m_pInstance = 0; |
| 9 |
|
| 10 |
class ABI_EXPORT XAP_LogDestructor |
| 11 |
{ |
| 12 |
public: |
| 13 |
XAP_LogDestructor() : t_(0) {} |
| 14 |
~XAP_LogDestructor() { delete t_; } |
| 15 |
void control(XAP_Log *t) { t_ = t; } |
| 16 |
private: |
| 17 |
XAP_Log *t_; |
| 18 |
}; |
| 19 |
|
| 20 |
static XAP_LogDestructor g_pLogDestructor; |
| 21 |
|
| 22 |
XAP_Log::XAP_Log(const UT_String &logfile) |
| 23 |
{ |
| 24 |
m_pOutput = fopen(logfile.c_str(), "w"); |
| 25 |
fprintf(m_pOutput, "<?xml version=\"1.0\"?>\n"); |
| 26 |
fprintf(m_pOutput, "<logger>\n"); |
| 27 |
} |
| 28 |
|
| 29 |
XAP_Log::~XAP_Log() |
| 30 |
{ |
| 31 |
if (m_pOutput != 0) |
| 32 |
{ |
| 33 |
fprintf(m_pOutput, "</logger>\n"); |
| 34 |
fclose(m_pOutput); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
void XAP_Log::log(const UT_String &method_name, AV_View * /*pAV_View*/, EV_EditMethodCallData *pCallData) |
| 39 |
{ |
| 40 |
UT_ASSERT(m_pOutput != 0); |
| 41 |
fprintf(m_pOutput, "\t<event name=\"%s\"", method_name.c_str()); |
| 42 |
|
| 43 |
if (pCallData != 0) |
| 44 |
{ |
| 45 |
fprintf(m_pOutput, ">\n\t\t<calldata x=\"%d\" y=\"%d\"", |
| 46 |
pCallData->m_xPos, |
| 47 |
pCallData->m_yPos); |
| 48 |
|
| 49 |
// the pCallData->m_bAllocatedData flag is not set when it should |
| 50 |
if (pCallData->m_pData != 0) |
| 51 |
{ |
| 52 |
fprintf(m_pOutput, ">"); |
| 53 |
UT_UCSChar *orig_data; |
| 54 |
UT_UCSChar *data = orig_data = pCallData->m_pData; |
| 55 |
UT_uint32 data_length = pCallData->m_dataLength; |
| 56 |
gchar outbuf[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 57 |
g_unichar_to_utf8(*data++, outbuf); |
| 58 |
UT_String stData(outbuf); |
| 59 |
|
| 60 |
while (static_cast<size_t>(data - pCallData->m_pData) < data_length) { |
| 61 |
memset(outbuf, 0, sizeof(outbuf)); |
| 62 |
g_unichar_to_utf8(*data++, outbuf); |
| 63 |
stData += outbuf; |
| 64 |
} |
| 65 |
|
| 66 |
fprintf(m_pOutput, "%s</calldata>\n\t</event>\n", stData.c_str()); |
| 67 |
|
| 68 |
} |
| 69 |
else |
| 70 |
fprintf(m_pOutput, "/>\n\t</event>\n"); |
| 71 |
|
| 72 |
} |
| 73 |
else |
| 74 |
fprintf(m_pOutput, "/>\n"); |
| 75 |
/* |
| 76 |
UT_UCSChar * m_pData; |
| 77 |
UT_uint32 m_dataLength; |
| 78 |
bool m_bAllocatedData; |
| 79 |
UT_sint32 m_xPos; |
| 80 |
UT_sint32 m_yPos; |
| 81 |
*/ |
| 82 |
} |
| 83 |
|
| 84 |
XAP_Log *XAP_Log::get_instance() |
| 85 |
{ |
| 86 |
if (m_pInstance == 0) |
| 87 |
{ |
| 88 |
m_pInstance = new XAP_Log("fixme_log.txt"); |
| 89 |
g_pLogDestructor.control(m_pInstance); |
| 90 |
} |
| 91 |
|
| 92 |
return m_pInstance; |
| 93 |
} |
| 94 |
|