main.cxx
8.19 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
* "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
* (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
* aplicativos mainframe. Registro no INPI sob o nome G3270.
*
* Copyright (C) <2008> <Banco do Brasil S.A.>
*
* Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
* os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
* Free Software Foundation.
*
* Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
* GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
* A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
* obter mais detalhes.
*
* Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
* programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA, 02111-1307, USA
*
* Este programa está nomeado como main.cxx e possui - linhas de código.
*
* Contatos:
*
* perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
* erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
* licinio@bb.com.br (Licínio Luis Branco)
* kraucer@bb.com.br (Kraucer Fernandes Mazuco)
* macmiranda@bb.com.br (Marco Aurélio Caldas Miranda)
*
*/
#include "globals.hpp"
#include <rtl/uuid.h>
#include <com/sun/star/registry/XRegistryKey.hpp>
#include <com/sun/star/lang/XSingleComponentFactory.hpp>
#include <stdio.h>
#include "ooo3270.hpp"
// #include <comphelper/componentmodule.hxx>
// http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/WritingUNO/C%2B%2B/C%2B%2B_Component
// http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/WritingUNO/C%2B%2B/Providing_a_Single_Factory_Using_a_Helper_Method
using namespace com::sun::star::registry; // for XRegistryKey
using namespace com::sun::star::lang; // for XSingleComponentFactory
/*---[ Statics ]-------------------------------------------------------------------------------------------*/
static Sequence< OUString > getSupportedServiceNames()
{
Sequence<OUString> names(1);
TRACE("%s returns: %s",__FUNCTION__, SERVICENAME);
names[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME ) );
return names;
}
/*
static OUString getImplementationName()
{
TRACE("%s returns: %s",__FUNCTION__, IMPLNAME);
return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) );
}
*/
static Reference< XInterface > SAL_CALL CreateInstance( const Reference< XComponentContext > & xContext )
{
return static_cast< XTypeProvider * >( new pw3270::uno_impl( xContext ) );
}
/*---[ Implement exported calls ]--------------------------------------------------------------------------*/
/**************************************************************
* Function to determine the environment of the implementation.
*
* If the environment is NOT session specific
* (needs no additional context), then this function
* should return the environment type name and leave ppEnv (0).
*
* @param ppEnvTypeName environment type name;
* string must be constant
* @param ppEnv function returns its environment
* if the environment is session specific,
* i.e. has special context
*/
extern "C" void SAL_CALL component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv)
{
#ifdef LANGUAGE_BINDING_NAME
TRACE("%s set envtype to %s\n",__FUNCTION__,LANGUAGE_BINDING_NAME);
*ppEnvTypeName = LANGUAGE_BINDING_NAME;
#else
TRACE("%s set envtype to %s\n",__FUNCTION__,"msci");
*ppEnvTypeName = "msci";
#endif
}
/************************************************************
* Optional function to retrieve a component description.
*
* @return an XML formatted string containing a short
* component description
*/
// typedef const sal_Char * (SAL_CALL * component_getDescriptionFunc)(void);
/**********************************************************
* Writes component registry info, at least writing the
* supported service names.
*
* @param pServiceManager a service manager
* (the type is XMultiServiceFactory
* to be used by the environment
* returned by
* component_getImplementationEnvironment)
*
* @param pRegistryKey a registry key
* (the type is XRegistryKey to be used
* by the environment returned by
* component_getImplementationEnvironment)
*
* @return true if everything went fine
*/
extern "C" sal_Bool SAL_CALL component_writeInfo(void * pServiceManager, void * pRegistryKey)
{
sal_Bool result = sal_False;
TRACE("%s",__FUNCTION__);
if (pRegistryKey)
{
try
{
Reference< XRegistryKey > xNewKey(
reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME "/UNO/SERVICES") ) ) );
const Sequence< OUString > & rSNL = getSupportedServiceNames();
const OUString * pArray = rSNL.getConstArray();
for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
xNewKey->createKey( pArray[nPos] );
return sal_True;
}
catch (InvalidRegistryException &)
{
// we should not ignore exceptions
}
}
return result;
}
/*********************************************************
* Retrieves a factory to create component instances.
*
* @param pImplName desired implementation name
*
* @param pServiceManager a service manager
* (the type is XMultiServiceFactory
* to be used by the environment
* returned by
* component_getImplementationEnvironment)
*
* @param pRegistryKey a registry key
* (the type is XRegistryKey to be used
* by the environment returned by
* component_getImplementationEnvironment)
*
* @return acquired component factory
* (the type is XInterface to be used by the
* environment returned by
* component_getImplementationEnvironment)
*/
extern "C" void * SAL_CALL component_getFactory(const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey)
{
void * pRet = 0;
TRACE("%s",__FUNCTION__);
if(pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
{
Reference< XSingleComponentFactory > xFactory( ::cppu::createSingleComponentFactory(
CreateInstance, OUString::createFromAscii( IMPLNAME ), getSupportedServiceNames() ));
if (xFactory.is())
{
xFactory->acquire();
pRet = xFactory.get();
}
}
return pRet;
}
/*---[ Implement XInitialization ]-------------------------------------------------------------------------*/
void SAL_CALL pw3270::uno_impl::initialize( Sequence< Any > const & args ) throw (Exception)
{
TRACE("%s",__FUNCTION__);
}
/*---[ Implement XServiceInfo ]----------------------------------------------------------------------------*/
OUString SAL_CALL pw3270::uno_impl::getImplementationName( ) throw(RuntimeException)
{
TRACE("%s",__FUNCTION__);
return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) );
}
sal_Bool SAL_CALL pw3270::uno_impl::supportsService( const OUString& ServiceName ) throw(RuntimeException)
{
TRACE("%s",__FUNCTION__);
return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("IMPLNAME") );
}
Sequence< OUString > pw3270::uno_impl::getSupportedServiceNames() throw (RuntimeException)
{
return getSupportedServiceNames();
}
/*---[ Implement pw3270 ]----------------------------------------------------------------------------------*/
// static bool started = false;
static int instances = 0;
pw3270::uno_impl::uno_impl( const Reference< XComponentContext > & xContext )
{
hThread = NULL;
hostinfo = NULL;
instances++;
/*
if(!started)
{
started = true;
TRACE("Initializing library with %s",OFFICE_PROGRAM);
lib3270_init();
}
*/
this->hSession = new_3270_session();
TRACE("Object created %s (instances: %d session: %p)",__FUNCTION__,instances,this->hSession);
}
pw3270::uno_impl::~uno_impl()
{
Disconnect();
if(hostinfo)
free(hostinfo);
instances--;
TRACE("Object deleted %s (instances: %d)",__FUNCTION__,instances);
}
OUString SAL_CALL pw3270::uno_impl::getRevision() throw (RuntimeException)
{
return OUString( RTL_CONSTASCII_USTRINGPARAM( PACKAGE_REVISION ) );
}
OUString SAL_CALL pw3270::uno_impl::getVersion() throw (RuntimeException)
{
return OUString( RTL_CONSTASCII_USTRINGPARAM( PACKAGE_VERSION ) );
}