Commit 2cd612601a8828b9d08feade833aaa23a4c0e02e

Authored by perry.werneck@gmail.com
1 parent 00cc966a

Incluindo suporte à gravação de log via syslog na extensão oxt

src/oxt/globals.hpp
@@ -70,6 +70,8 @@ @@ -70,6 +70,8 @@
70 70
71 void sleep(int seconds = 1); 71 void sleep(int seconds = 1);
72 72
  73 + void log(const char *fmt, const char *msg);
  74 +
73 rtl_TextEncoding get_encoding(); 75 rtl_TextEncoding get_encoding();
74 76
75 }; 77 };
@@ -145,6 +147,7 @@ @@ -145,6 +147,7 @@
145 virtual ::sal_Int16 SAL_CALL sleep( ::sal_Int16 seconds ) throw (::com::sun::star::uno::RuntimeException); 147 virtual ::sal_Int16 SAL_CALL sleep( ::sal_Int16 seconds ) throw (::com::sun::star::uno::RuntimeException);
146 virtual ::rtl::OUString SAL_CALL getTextAt( ::sal_Int16 row, ::sal_Int16 col, ::sal_Int16 size ) throw (::com::sun::star::uno::RuntimeException); 148 virtual ::rtl::OUString SAL_CALL getTextAt( ::sal_Int16 row, ::sal_Int16 col, ::sal_Int16 size ) throw (::com::sun::star::uno::RuntimeException);
147 virtual ::sal_Int16 SAL_CALL setTextAt( ::sal_Int16 row, ::sal_Int16 col, const ::rtl::OUString& text ) throw (::com::sun::star::uno::RuntimeException); 149 virtual ::sal_Int16 SAL_CALL setTextAt( ::sal_Int16 row, ::sal_Int16 col, const ::rtl::OUString& text ) throw (::com::sun::star::uno::RuntimeException);
  150 + virtual ::sal_Int16 SAL_CALL log(const ::rtl::OUString& text ) throw (::com::sun::star::uno::RuntimeException);
148 virtual ::sal_Int16 SAL_CALL enter( ) throw (::com::sun::star::uno::RuntimeException); 151 virtual ::sal_Int16 SAL_CALL enter( ) throw (::com::sun::star::uno::RuntimeException);
149 virtual ::sal_Int16 SAL_CALL pfkey( ::sal_Int16 keycode ) throw (::com::sun::star::uno::RuntimeException); 152 virtual ::sal_Int16 SAL_CALL pfkey( ::sal_Int16 keycode ) throw (::com::sun::star::uno::RuntimeException);
150 virtual ::sal_Int16 SAL_CALL pakey( ::sal_Int16 keycode ) throw (::com::sun::star::uno::RuntimeException); 153 virtual ::sal_Int16 SAL_CALL pakey( ::sal_Int16 keycode ) throw (::com::sun::star::uno::RuntimeException);
src/oxt/local.cxx
@@ -32,6 +32,11 @@ @@ -32,6 +32,11 @@
32 #include "globals.hpp" 32 #include "globals.hpp"
33 #include <errno.h> 33 #include <errno.h>
34 34
  35 + #ifdef HAVE_SYSLOG
  36 + #include <syslog.h>
  37 + #include <stdarg.h>
  38 + #endif // HAVE_SYSLOG
  39 +
35 /* 40 /*
36 * NOTE: Take a better look at osl_createEmptySocketAddr() & osl_connectSocketTo() to see if there's 41 * NOTE: Take a better look at osl_createEmptySocketAddr() & osl_connectSocketTo() to see if there's
37 * a way to use this calls to connect with the host for better performance. 42 * a way to use this calls to connect with the host for better performance.
@@ -42,6 +47,15 @@ @@ -42,6 +47,15 @@
42 47
43 /*---[ Implement ]-----------------------------------------------------------------------------------------*/ 48 /*---[ Implement ]-----------------------------------------------------------------------------------------*/
44 49
  50 +static void loghandler(H3270 *session, const char *module, int rc, const char *fmt, va_list args)
  51 +{
  52 +#ifdef HAVE_SYSLOG
  53 + openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER);
  54 + vsyslog(LOG_INFO,fmt,args);
  55 + closelog();
  56 +#endif // HAVE_SYSLOG
  57 +}
  58 +
45 pw3270::lib3270_session::lib3270_session() 59 pw3270::lib3270_session::lib3270_session()
46 { 60 {
47 struct _call 61 struct _call
@@ -64,6 +78,7 @@ @@ -64,6 +78,7 @@
64 }; 78 };
65 79
66 H3270 * (*lib3270_new)(const char *); 80 H3270 * (*lib3270_new)(const char *);
  81 + void (*set_log_handler)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list));
67 82
68 hThread = NULL; 83 hThread = NULL;
69 hSession = NULL; 84 hSession = NULL;
@@ -77,9 +92,15 @@ @@ -77,9 +92,15 @@
77 *call[f].entry = (void *) osl_getAsciiFunctionSymbol(hModule,call[f].name); 92 *call[f].entry = (void *) osl_getAsciiFunctionSymbol(hModule,call[f].name);
78 93
79 /* Get lib3270 session handle */ 94 /* Get lib3270 session handle */
  95 + set_log_handler = (void (*)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list))) osl_getAsciiFunctionSymbol(hModule,"lib3270_set_log_handler");
  96 +
  97 + if(set_log_handler)
  98 + set_log_handler(loghandler);
  99 +
80 lib3270_new = (H3270 * (*)(const char *)) osl_getAsciiFunctionSymbol(hModule,"lib3270_session_new"); 100 lib3270_new = (H3270 * (*)(const char *)) osl_getAsciiFunctionSymbol(hModule,"lib3270_session_new");
81 hSession = lib3270_new(""); 101 hSession = lib3270_new("");
82 102
  103 + log("%s UNO extension loaded",PACKAGE_NAME);
83 } 104 }
84 105
85 pw3270::lib3270_session::~lib3270_session() 106 pw3270::lib3270_session::~lib3270_session()
@@ -105,6 +126,7 @@ @@ -105,6 +126,7 @@
105 hModule = NULL; 126 hModule = NULL;
106 } 127 }
107 128
  129 + log("%s UNO extension unloaded",PACKAGE_NAME);
108 } 130 }
109 131
110 int pw3270::lib3270_session::get_revision(void) 132 int pw3270::lib3270_session::get_revision(void)
src/oxt/main.cxx
@@ -31,6 +31,10 @@ @@ -31,6 +31,10 @@
31 31
32 #include "globals.hpp" 32 #include "globals.hpp"
33 33
  34 +#ifdef HAVE_SYSLOG
  35 + #include <syslog.h>
  36 +#endif // HAVE_SYSLOG
  37 +
34 #include <salhelper/timer.hxx> 38 #include <salhelper/timer.hxx>
35 #include <com/sun/star/registry/XRegistryKey.hpp> 39 #include <com/sun/star/registry/XRegistryKey.hpp>
36 #include <com/sun/star/lang/XSingleComponentFactory.hpp> 40 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
@@ -229,6 +233,12 @@ pw3270::uno_impl::~uno_impl() @@ -229,6 +233,12 @@ pw3270::uno_impl::~uno_impl()
229 return 0; 233 return 0;
230 } 234 }
231 235
  236 +::sal_Int16 SAL_CALL pw3270::uno_impl::log( const ::rtl::OUString& msg ) throw (::com::sun::star::uno::RuntimeException)
  237 +{
  238 + hSession->log("%s",rtl::OUStringToOString(msg,RTL_TEXTENCODING_UTF8).getStr());
  239 + return 0;
  240 +}
  241 +
232 242
233 pw3270::session::session() 243 pw3270::session::session()
234 { 244 {
@@ -251,4 +261,14 @@ void pw3270::session::sleep(int seconds) @@ -251,4 +261,14 @@ void pw3270::session::sleep(int seconds)
251 osl_waitThread(&t); 261 osl_waitThread(&t);
252 } 262 }
253 263
  264 +void pw3270::session::log(const char *fmt, const char *msg)
  265 +{
  266 +#ifdef HAVE_SYSLOG
  267 + openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER);
  268 + syslog(LOG_INFO,fmt,msg);
  269 + closelog();
  270 +#else
  271 + #error This module needs syslog support
  272 +#endif // HAVE_SYSLOG
  273 +}
254 274
src/oxt/pw3270.idl
@@ -75,6 +75,7 @@ module br @@ -75,6 +75,7 @@ module br
75 75
76 /* Misc */ 76 /* Misc */
77 short getRevision(); 77 short getRevision();
  78 + short log([in] string msg);
78 short sleep([in] short seconds); 79 short sleep([in] short seconds);
79 boolean isReady(); 80 boolean isReady();
80 boolean hasTextAt([in] short row, [in] short col, [in] string text); 81 boolean hasTextAt([in] short row, [in] short col, [in] string text);