diff --git a/src/oxt/globals.hpp b/src/oxt/globals.hpp index 70c1f88..e39c280 100644 --- a/src/oxt/globals.hpp +++ b/src/oxt/globals.hpp @@ -52,6 +52,8 @@ namespace pw3270 { + class uno_impl; + class session { public: @@ -85,7 +87,7 @@ class lib3270_session : public session { public: - lib3270_session(); + lib3270_session(uno_impl *obj) throw( RuntimeException ); virtual ~lib3270_session(); virtual int get_revision(void); @@ -136,7 +138,7 @@ class ipc3270_session : public session { public: - ipc3270_session(const char *name); + ipc3270_session(uno_impl *obj, const char *name) throw( RuntimeException ); virtual ~ipc3270_session(); virtual int get_revision(void); virtual LIB3270_MESSAGE get_state(void); @@ -210,12 +212,12 @@ virtual ::sal_Int16 SAL_CALL screenTrace( ::sal_Bool state ) throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Int16 SAL_CALL setSession( const ::rtl::OUString& name ) throw (::com::sun::star::uno::RuntimeException); + void failed(const char *fmt, ...) throw( ::com::sun::star::uno::RuntimeException ); + private: session *hSession; - - }; }; diff --git a/src/oxt/local.cxx b/src/oxt/local.cxx index b1a3820..6847e5e 100644 --- a/src/oxt/local.cxx +++ b/src/oxt/local.cxx @@ -96,7 +96,7 @@ #endif // HAVE_SYSLOG } - pw3270::lib3270_session::lib3270_session() + pw3270::lib3270_session::lib3270_session(uno_impl *obj) throw( RuntimeException ) { struct _call { @@ -136,7 +136,7 @@ if(!hModule) { - log("%s","Error loading lib3270"); + obj->failed("%s","Can't load lib3270"); return; } @@ -144,7 +144,7 @@ { *call[f].entry = (void *) osl_getAsciiFunctionSymbol(hModule,call[f].name); if(!*call[f].entry) - log("Error loading lib3270::%s",call[f].name); + obj->failed("Error loading lib3270::%s",call[f].name); } /* Get lib3270 session handle */ diff --git a/src/oxt/main.cxx b/src/oxt/main.cxx index 00fb3c6..a2f2500 100644 --- a/src/oxt/main.cxx +++ b/src/oxt/main.cxx @@ -30,6 +30,7 @@ */ #include "globals.hpp" +#include #ifdef HAVE_SYSLOG #include @@ -218,7 +219,7 @@ Sequence< OUString > pw3270::uno_impl::getSupportedServiceNames() throw (Runtime pw3270::uno_impl::uno_impl( const Reference< XComponentContext > & xContext ) { - this->hSession = new lib3270_session(); + this->hSession = new lib3270_session(this); } pw3270::uno_impl::~uno_impl() @@ -285,12 +286,35 @@ void pw3270::session::log(const char *fmt, const char *msg) #endif // HAVE_SYSLOG } +void pw3270::uno_impl::failed(const char *fmt, ...) throw( ::com::sun::star::uno::RuntimeException ) +{ + va_list arg_ptr; + char * msg = (char *) malloc(1024); + + va_start(arg_ptr, fmt); + vsnprintf(msg, 1023, fmt, arg_ptr); + va_end(arg_ptr); + +#ifdef HAVE_SYSLOG + openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); + syslog(LOG_ERR,"%s",msg); + closelog(); +#endif // HAVE_SYSLOG + + ::rtl::OUString str = OUString(msg, strlen(msg), RTL_TEXTENCODING_UTF8, RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_IGNORE); + + free(msg); + + throw Exception( str , *this ); + +} + ::sal_Int16 SAL_CALL pw3270::uno_impl::setSession( const ::rtl::OUString& name ) throw (::com::sun::star::uno::RuntimeException) { OString str = rtl::OUStringToOString( name , hSession->get_encoding() ); delete this->hSession; - this->hSession = new ipc3270_session(str.getStr()); + this->hSession = new ipc3270_session(this,str.getStr()); return 0; } diff --git a/src/oxt/remote.cxx b/src/oxt/remote.cxx index 900bbab..e34a6dd 100644 --- a/src/oxt/remote.cxx +++ b/src/oxt/remote.cxx @@ -151,7 +151,7 @@ int pw3270::ipc3270_session::query_intval(const char *method) #endif // HAVE_DBUS -pw3270::ipc3270_session::ipc3270_session(const char *name) : pw3270::session() +pw3270::ipc3270_session::ipc3270_session(uno_impl *obj, const char *name) throw( RuntimeException ) : pw3270::session() { #ifdef HAVE_DBUS @@ -226,13 +226,14 @@ pw3270::ipc3270_session::ipc3270_session(const char *name) : pw3270::session() if (dbus_error_is_set(&err)) { - log("DBUS Connection Error (%s)", err.message); + obj->failed("DBUS Connection Error (%s)", err.message); dbus_error_free(&err); + return; } if(!conn) { - log("%s", "DBUS Connection failed"); + obj->failed("%s", "DBUS Connection failed"); return; } @@ -240,7 +241,7 @@ pw3270::ipc3270_session::ipc3270_session(const char *name) : pw3270::session() if (dbus_error_is_set(&err)) { - log("Name Error (%s)", err.message); + obj->failed("DBUS Name Error (%s)", err.message); dbus_error_free(&err); conn = NULL; return; @@ -248,7 +249,7 @@ pw3270::ipc3270_session::ipc3270_session(const char *name) : pw3270::session() if(rc != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - log("%s", "DBUS request name failed"); + obj->failed("%s", "DBUS request name failed"); conn = NULL; return; } -- libgit2 0.21.2