globals.hpp
8.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#ifndef GLOBALS_HPP_INCLUDED
#define GLOBALS_HPP_INCLUDED 1
#define UNX 1
#define GCC 1
#define LINUX 1
#define CPPU_ENV gcc3
#define HAVE_GCC_VISIBILITY_FEATURE 1
#define LANGUAGE_BINDING_NAME "gcc3"
#include <stdio.h>
#include <lib3270.h>
#if defined(HAVE_DBUS)
#include <stdio.h>
#include <dbus/dbus.h>
#endif // HAVE_DBUS
#include <rtl/uuid.h>
#include <osl/thread.hxx>
#include <cppuhelper/implbase3.hxx> // "3" implementing three interfaces
#include <cppuhelper/factory.hxx>
#include <cppuhelper/implementationentry.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <pw3270intf.hpp>
/*---[ Debug macros ]--------------------------------------------------------------------------------------*/
#ifdef DEBUG
#define trace(fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fflush(stderr);
#else
#define trace( fmt, ... ) /* fmt __VA_ARGS__ */
#endif
/*---[ Object implementation ]-----------------------------------------------------------------------------*/
#define IMPLNAME "br.com.bb.pw3270intf"
#define SERVICENAME "br.com.bb.pw3270"
using namespace br::com::bb;
using namespace ::rtl; // for OUString
using namespace ::com::sun::star; // for sdk interfaces
using namespace ::com::sun::star::uno; // for basic types
namespace pw3270
{
class uno_impl;
class session
{
public:
session();
virtual ~session();
virtual int get_revision(void) = 0;
virtual LIB3270_MESSAGE get_state(void) = 0;
virtual char * get_text_at(int row, int col, int len) = 0;
virtual int set_text_at(int row, int col, const char *text) = 0;
virtual int cmp_text_at(int row, int col, const char *text) = 0;
virtual void set_toggle(LIB3270_TOGGLE toggle, bool state) = 0;
virtual int connect(const char *uri) = 0;
virtual int disconnect(void) = 0;
virtual bool connected(void) = 0;
virtual int enter(void) = 0;
virtual int pfkey(int key) = 0;
virtual int pakey(int key) = 0;
virtual bool in_tn3270e() = 0;
virtual void mem_free(void *) = 0;
void sleep(int seconds = 1);
void log(const char *fmt, const char *msg);
rtl_TextEncoding get_encoding();
};
class lib3270_session : public session
{
public:
lib3270_session(uno_impl *obj) throw( RuntimeException );
virtual ~lib3270_session();
virtual int get_revision(void);
virtual LIB3270_MESSAGE get_state(void);
virtual int connect(const char *uri);
virtual int disconnect(void);
virtual bool connected(void);
virtual bool in_tn3270e(void);
virtual int enter(void);
virtual int pfkey(int key);
virtual int pakey(int key);
virtual char * get_text_at(int row, int col, int len);
virtual int set_text_at(int row, int col, const char *text);
virtual int cmp_text_at(int row, int col, const char *text);
virtual void mem_free(void *ptr);
virtual void set_toggle(LIB3270_TOGGLE toggle, bool state);
private:
bool enabled;
oslModule hModule;
oslThread hThread;
H3270 * hSession;
/* Internal calls */
static void start_connect(lib3270_session *session);
void network_loop(void);
/* lib3270 entry points */
const char * (* _get_revision)(void);
LIB3270_MESSAGE (* _get_program_message)(H3270 *);
int (* _in_tn3270e)(H3270 *);
char * (* _get_text_at)(H3270 *,int,int,int);
int (* _set_text_at)(H3270 *,int,int,const unsigned char *);
int (* _cmp_text_at)(H3270 *,int,int,const char *);
int (* _enter)(H3270 *);
int (* _pfkey)(H3270 *, int);
int (* _pakey)(H3270 *, int);
void * (* _mem_free)(void *);
void (*_set_toggle)(void *h, LIB3270_TOGGLE ix, int value);
};
class ipc3270_session : public session
{
public:
ipc3270_session(uno_impl *obj, const char *name) throw( RuntimeException );
virtual ~ipc3270_session();
virtual int get_revision(void);
virtual LIB3270_MESSAGE get_state(void);
virtual char * get_text_at(int row, int col, int len);
virtual int set_text_at(int row, int col, const char *text);
virtual int cmp_text_at(int row, int col, const char *text);
virtual void set_toggle(LIB3270_TOGGLE toggle, bool state);
virtual int connect(const char *uri);
virtual int disconnect(void);
virtual bool connected(void);
virtual int enter(void);
virtual int pfkey(int key);
virtual int pakey(int key);
virtual bool in_tn3270e();
virtual void mem_free(void *);
private:
#if defined(HAVE_DBUS)
DBusConnection * conn;
char * dest;
char * path;
char * intf;
DBusMessage * create_message(const char *method);
DBusMessage * call(DBusMessage *msg);
char * query_string(const char *method);
int query_intval(const char *method);
#endif // HAVE_DBUS
};
class uno_impl : public ::cppu::WeakImplHelper3< br::com::bb::pw3270intf, com::sun::star::lang::XServiceInfo, com::sun::star::lang::XInitialization >
{
public:
uno_impl( const com::sun::star::uno::Reference< XComponentContext > & xContext );
virtual ~uno_impl();
// XInitialization will be called upon createInstanceWithArguments[AndContext]()
virtual void SAL_CALL initialize( Sequence< Any > const & args ) throw (Exception);
// XServiceInfo implementation
virtual OUString SAL_CALL getImplementationName( ) throw(RuntimeException);
virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException);
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(RuntimeException);
// pw3270 implementation - Main
virtual ::sal_Int16 SAL_CALL getRevision() throw (RuntimeException);
virtual ::rtl::OUString SAL_CALL getVersion( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int16 SAL_CALL Connect( const ::rtl::OUString& hostinfo ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int16 SAL_CALL Disconnect( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int16 SAL_CALL getConnectionState( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int16 SAL_CALL sleep( ::sal_Int16 seconds ) throw (::com::sun::star::uno::RuntimeException);
virtual ::rtl::OUString SAL_CALL getTextAt( ::sal_Int16 row, ::sal_Int16 col, ::sal_Int16 size ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int16 SAL_CALL setTextAt( ::sal_Int16 row, ::sal_Int16 col, const ::rtl::OUString& text ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int16 SAL_CALL log(const ::rtl::OUString& text ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int16 SAL_CALL enter( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int16 SAL_CALL pfkey( ::sal_Int16 keycode ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int16 SAL_CALL pakey( ::sal_Int16 keycode ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int16 SAL_CALL cmpTextAt( ::sal_Int16 row, ::sal_Int16 col, const ::rtl::OUString& text ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Bool SAL_CALL isReady( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Bool SAL_CALL isConnected( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Bool SAL_CALL hasTextAt( ::sal_Int16 row, ::sal_Int16 col, const ::rtl::OUString& text ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int16 SAL_CALL waitForReady( ::sal_Int16 seconds ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int16 SAL_CALL dsTrace( ::sal_Bool state ) throw (::com::sun::star::uno::RuntimeException);
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;
};
};
#endif // GLOBALS_HPP_INCLUDED