Commit 858ac02b8c181e738f9cfa6528748d74d95b1214

Authored by perry.werneck@gmail.com
1 parent 74df497c

Incluindo excessões na extensão libreoffice

src/oxt/globals.hpp
@@ -52,6 +52,8 @@ @@ -52,6 +52,8 @@
52 namespace pw3270 52 namespace pw3270
53 { 53 {
54 54
  55 + class uno_impl;
  56 +
55 class session 57 class session
56 { 58 {
57 public: 59 public:
@@ -85,7 +87,7 @@ @@ -85,7 +87,7 @@
85 class lib3270_session : public session 87 class lib3270_session : public session
86 { 88 {
87 public: 89 public:
88 - lib3270_session(); 90 + lib3270_session(uno_impl *obj) throw( RuntimeException );
89 virtual ~lib3270_session(); 91 virtual ~lib3270_session();
90 92
91 virtual int get_revision(void); 93 virtual int get_revision(void);
@@ -136,7 +138,7 @@ @@ -136,7 +138,7 @@
136 class ipc3270_session : public session 138 class ipc3270_session : public session
137 { 139 {
138 public: 140 public:
139 - ipc3270_session(const char *name); 141 + ipc3270_session(uno_impl *obj, const char *name) throw( RuntimeException );
140 virtual ~ipc3270_session(); 142 virtual ~ipc3270_session();
141 virtual int get_revision(void); 143 virtual int get_revision(void);
142 virtual LIB3270_MESSAGE get_state(void); 144 virtual LIB3270_MESSAGE get_state(void);
@@ -210,12 +212,12 @@ @@ -210,12 +212,12 @@
210 virtual ::sal_Int16 SAL_CALL screenTrace( ::sal_Bool state ) throw (::com::sun::star::uno::RuntimeException); 212 virtual ::sal_Int16 SAL_CALL screenTrace( ::sal_Bool state ) throw (::com::sun::star::uno::RuntimeException);
211 virtual ::sal_Int16 SAL_CALL setSession( const ::rtl::OUString& name ) throw (::com::sun::star::uno::RuntimeException); 213 virtual ::sal_Int16 SAL_CALL setSession( const ::rtl::OUString& name ) throw (::com::sun::star::uno::RuntimeException);
212 214
  215 + void failed(const char *fmt, ...) throw( ::com::sun::star::uno::RuntimeException );
  216 +
213 private: 217 private:
214 218
215 session *hSession; 219 session *hSession;
216 220
217 -  
218 -  
219 }; 221 };
220 222
221 }; 223 };
src/oxt/local.cxx
@@ -96,7 +96,7 @@ @@ -96,7 +96,7 @@
96 #endif // HAVE_SYSLOG 96 #endif // HAVE_SYSLOG
97 } 97 }
98 98
99 - pw3270::lib3270_session::lib3270_session() 99 + pw3270::lib3270_session::lib3270_session(uno_impl *obj) throw( RuntimeException )
100 { 100 {
101 struct _call 101 struct _call
102 { 102 {
@@ -136,7 +136,7 @@ @@ -136,7 +136,7 @@
136 136
137 if(!hModule) 137 if(!hModule)
138 { 138 {
139 - log("%s","Error loading lib3270"); 139 + obj->failed("%s","Can't load lib3270");
140 return; 140 return;
141 } 141 }
142 142
@@ -144,7 +144,7 @@ @@ -144,7 +144,7 @@
144 { 144 {
145 *call[f].entry = (void *) osl_getAsciiFunctionSymbol(hModule,call[f].name); 145 *call[f].entry = (void *) osl_getAsciiFunctionSymbol(hModule,call[f].name);
146 if(!*call[f].entry) 146 if(!*call[f].entry)
147 - log("Error loading lib3270::%s",call[f].name); 147 + obj->failed("Error loading lib3270::%s",call[f].name);
148 } 148 }
149 149
150 /* Get lib3270 session handle */ 150 /* Get lib3270 session handle */
src/oxt/main.cxx
@@ -30,6 +30,7 @@ @@ -30,6 +30,7 @@
30 */ 30 */
31 31
32 #include "globals.hpp" 32 #include "globals.hpp"
  33 +#include <string.h>
33 34
34 #ifdef HAVE_SYSLOG 35 #ifdef HAVE_SYSLOG
35 #include <syslog.h> 36 #include <syslog.h>
@@ -218,7 +219,7 @@ Sequence&lt; OUString &gt; pw3270::uno_impl::getSupportedServiceNames() throw (Runtime @@ -218,7 +219,7 @@ Sequence&lt; OUString &gt; pw3270::uno_impl::getSupportedServiceNames() throw (Runtime
218 219
219 pw3270::uno_impl::uno_impl( const Reference< XComponentContext > & xContext ) 220 pw3270::uno_impl::uno_impl( const Reference< XComponentContext > & xContext )
220 { 221 {
221 - this->hSession = new lib3270_session(); 222 + this->hSession = new lib3270_session(this);
222 } 223 }
223 224
224 pw3270::uno_impl::~uno_impl() 225 pw3270::uno_impl::~uno_impl()
@@ -285,12 +286,35 @@ void pw3270::session::log(const char *fmt, const char *msg) @@ -285,12 +286,35 @@ void pw3270::session::log(const char *fmt, const char *msg)
285 #endif // HAVE_SYSLOG 286 #endif // HAVE_SYSLOG
286 } 287 }
287 288
  289 +void pw3270::uno_impl::failed(const char *fmt, ...) throw( ::com::sun::star::uno::RuntimeException )
  290 +{
  291 + va_list arg_ptr;
  292 + char * msg = (char *) malloc(1024);
  293 +
  294 + va_start(arg_ptr, fmt);
  295 + vsnprintf(msg, 1023, fmt, arg_ptr);
  296 + va_end(arg_ptr);
  297 +
  298 +#ifdef HAVE_SYSLOG
  299 + openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER);
  300 + syslog(LOG_ERR,"%s",msg);
  301 + closelog();
  302 +#endif // HAVE_SYSLOG
  303 +
  304 + ::rtl::OUString str = OUString(msg, strlen(msg), RTL_TEXTENCODING_UTF8, RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_IGNORE);
  305 +
  306 + free(msg);
  307 +
  308 + throw Exception( str , *this );
  309 +
  310 +}
  311 +
288 ::sal_Int16 SAL_CALL pw3270::uno_impl::setSession( const ::rtl::OUString& name ) throw (::com::sun::star::uno::RuntimeException) 312 ::sal_Int16 SAL_CALL pw3270::uno_impl::setSession( const ::rtl::OUString& name ) throw (::com::sun::star::uno::RuntimeException)
289 { 313 {
290 OString str = rtl::OUStringToOString( name , hSession->get_encoding() ); 314 OString str = rtl::OUStringToOString( name , hSession->get_encoding() );
291 315
292 delete this->hSession; 316 delete this->hSession;
293 - this->hSession = new ipc3270_session(str.getStr()); 317 + this->hSession = new ipc3270_session(this,str.getStr());
294 318
295 return 0; 319 return 0;
296 } 320 }
src/oxt/remote.cxx
@@ -151,7 +151,7 @@ int pw3270::ipc3270_session::query_intval(const char *method) @@ -151,7 +151,7 @@ int pw3270::ipc3270_session::query_intval(const char *method)
151 #endif // HAVE_DBUS 151 #endif // HAVE_DBUS
152 152
153 153
154 -pw3270::ipc3270_session::ipc3270_session(const char *name) : pw3270::session() 154 +pw3270::ipc3270_session::ipc3270_session(uno_impl *obj, const char *name) throw( RuntimeException ) : pw3270::session()
155 { 155 {
156 #ifdef HAVE_DBUS 156 #ifdef HAVE_DBUS
157 157
@@ -226,13 +226,14 @@ pw3270::ipc3270_session::ipc3270_session(const char *name) : pw3270::session() @@ -226,13 +226,14 @@ pw3270::ipc3270_session::ipc3270_session(const char *name) : pw3270::session()
226 226
227 if (dbus_error_is_set(&err)) 227 if (dbus_error_is_set(&err))
228 { 228 {
229 - log("DBUS Connection Error (%s)", err.message); 229 + obj->failed("DBUS Connection Error (%s)", err.message);
230 dbus_error_free(&err); 230 dbus_error_free(&err);
  231 + return;
231 } 232 }
232 233
233 if(!conn) 234 if(!conn)
234 { 235 {
235 - log("%s", "DBUS Connection failed"); 236 + obj->failed("%s", "DBUS Connection failed");
236 return; 237 return;
237 } 238 }
238 239
@@ -240,7 +241,7 @@ pw3270::ipc3270_session::ipc3270_session(const char *name) : pw3270::session() @@ -240,7 +241,7 @@ pw3270::ipc3270_session::ipc3270_session(const char *name) : pw3270::session()
240 241
241 if (dbus_error_is_set(&err)) 242 if (dbus_error_is_set(&err))
242 { 243 {
243 - log("Name Error (%s)", err.message); 244 + obj->failed("DBUS Name Error (%s)", err.message);
244 dbus_error_free(&err); 245 dbus_error_free(&err);
245 conn = NULL; 246 conn = NULL;
246 return; 247 return;
@@ -248,7 +249,7 @@ pw3270::ipc3270_session::ipc3270_session(const char *name) : pw3270::session() @@ -248,7 +249,7 @@ pw3270::ipc3270_session::ipc3270_session(const char *name) : pw3270::session()
248 249
249 if(rc != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) 250 if(rc != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
250 { 251 {
251 - log("%s", "DBUS request name failed"); 252 + obj->failed("%s", "DBUS request name failed");
252 conn = NULL; 253 conn = NULL;
253 return; 254 return;
254 } 255 }