1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
33 #include "cppuhelper/bootstrap.hxx"
34 #include "rtl/process.h"
35 #include "typelib/typedescription.hxx"
37 #include "com/sun/star/bridge/ModelDependent.hpp"
38 #include "com/sun/star/bridge/XBridgeSupplier2.hpp"
39 #include "com/sun/star/uno/TypeClass.hpp"
40 #include "com/sun/star/script/XInvocation.hpp"
41 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
42 #include "com/sun/star/uno/XComponentContext.hpp"
43 #include <com/sun/star/bridge/oleautomation/NamedArgument.hpp>
44 #include "rtl/ustring.hxx"
46 using namespace com::sun::star::bridge
;
47 using namespace com::sun::star::bridge::ModelDependent
;
48 using namespace com::sun::star::uno
;
49 using namespace com::sun::star::lang
;
50 using namespace com::sun::star::script
;
51 using namespace com::sun::star::bridge::oleautomation
;
56 bool equalSequences(const Sequence
<T
>& seqIn
, const Sequence
<Any
> & returned
);
59 Reference
< XMultiServiceFactory
> objectFactory
;//
62 Reference
<XMultiServiceFactory
> getMultiServiceFactory()
64 static Reference
< XMultiServiceFactory
> factory
;
65 if( ! objectFactory
.is() )
67 Reference
<XComponentContext
> context
= defaultBootstrap_InitialComponentContext();
68 factory
= Reference
<XMultiServiceFactory
>( context
->getServiceManager(), UNO_QUERY
);
74 Reference
<XInvocation
> getComObject( OUString progId
)
77 Reference
< XInvocation
> ret
;
78 // Reference<XMultiServiceFactory> fac;
79 if( ! objectFactory
.is())
80 { Reference
<XMultiServiceFactory
> mgr
= getMultiServiceFactory();
81 Reference
<XInterface
> xInt
= mgr
->createInstance(
82 OUString(L
"com.sun.star.bridge.oleautomation.Factory"));
83 objectFactory
= Reference
<XMultiServiceFactory
>::query( xInt
);
86 if( objectFactory
.is())
88 Reference
<XInterface
> xIntAx
= objectFactory
->createInstance( progId
.getStr());
91 Reference
< XInvocation
> xInv( xIntAx
, UNO_QUERY
);
98 Reference
<XInvocation
> convertComObject( IUnknown
* pUnk
)
100 Reference
< XMultiServiceFactory
> mgr
= getMultiServiceFactory();
101 Reference
< XInterface
> xIntSupplier
= mgr
->createInstance(OUString(L
"com.sun.star.bridge.OleBridgeSupplier2"));
102 Reference
< XBridgeSupplier2
> xSuppl( xIntSupplier
, UNO_QUERY
);
105 CComVariant
var( pUnk
);
106 any
<<= ( sal_uInt32
)&var
;
108 rtl_getGlobalProcessId( arId
);
109 Any target
= xSuppl
->createBridge( any
, Sequence
<sal_Int8
>( (sal_Int8
*)arId
, 16), OLE
, UNO
);
111 Reference
<XInvocation
> ret
;
117 Parameter values contains the expected return values. The value at index 0
118 correspond to parameter 0 (left - most). For parameters which are not out or
119 in/out the value must be a void any.
121 The number of items in value must be the
122 same as the number of provided parameter during the call on the method.
124 The parameter outArgs, indices correspond to the sequences which are
125 arguments to XInvocation::invoke
127 bool checkOutArgs(const Sequence
<Any
> & outArgs
,
128 const Sequence
<sal_Int16
> & indices
, const Sequence
<Any
> & values
)
130 if (values
.getLength() != outArgs
.getLength())
132 //iterate over all parameters. i represents the parameter index
133 for (int i
= 0; i
< values
.getLength(); i
++)
135 if (values
[i
].getValueType() == getVoidCppuType())
138 //Based on the parameter index find the correspondent out value
139 int indexOutSeq
= -1;
140 for (int iIndices
= indices
.getLength() - 1; iIndices
>= 0; iIndices
--)
142 if (indices
[iIndices
] == i
)
144 indexOutSeq
= iIndices
;
148 if (indexOutSeq
== -1)
154 outArgs
[indexOutSeq
] >>=out
;
159 if (values
[i
].getValueType() == getCppuType((NamedArgument
*) 0))
161 NamedArgument inNamed
;
162 values
[i
] >>= inNamed
;
163 value
<<= inNamed
.Value
;
165 if (value
!= outArgs
[indexOutSeq
])
171 /* The returned sequence always contains Any elements
173 bool equalSequences(const Any
& orig
, const Any
& returned
)
175 if (orig
.getValueTypeClass() != TypeClass_SEQUENCE
)
180 TypeDescription
td(orig
.getValueTypeRef());
181 typelib_IndirectTypeDescription
* indirect_td
= (typelib_IndirectTypeDescription
*) td
.get();
183 switch (indirect_td
->pType
->eTypeClass
)
187 Sequence
<sal_Unicode
> seq
;
191 return equalSequences(seq
, seq2
);
193 case TypeClass_BOOLEAN
:
195 Sequence
<sal_Bool
> seq
;
199 return equalSequences(seq
, seq2
);
203 Sequence
<sal_Int8
> seq
;
207 return equalSequences(seq
, seq2
);
209 case TypeClass_SHORT
:
211 Sequence
<sal_Int16
> seq
;
215 return equalSequences(seq
, seq2
);
219 Sequence
<sal_Int32
> seq
;
223 return equalSequences(seq
, seq2
);
225 case TypeClass_FLOAT
:
231 return equalSequences(seq
, seq2
);
233 case TypeClass_DOUBLE
:
235 Sequence
<double> seq
;
239 return equalSequences(seq
, seq2
);
241 case TypeClass_STRING
:
243 Sequence
<OUString
> seq
;
247 return equalSequences(seq
, seq2
);
255 return equalSequences(seq
, seq2
);
257 case TypeClass_SEQUENCE
:
259 //Sequence<sal_Unicode> seq;
261 //Sequence<Any> seq2;
263 //return equalSequences(seq, seq2);
266 case TypeClass_INTERFACE
:
268 Sequence
<Reference
<XInvocation
> > seq
;
272 return equalSequences(seq
, seq2
);
281 bool equalSequences(const Sequence
<T
>& seqIn
, const Sequence
<Any
> & seqOut
)
283 if (seqIn
.getLength() != seqOut
.getLength())
285 int len
= seqIn
.getLength();
286 for (int i
= 0; i
< len
; i
++)
290 Any anyOut
= seqOut
[i
];
298 void printSequence( Sequence
<Any
>& val
)
301 // typelib_TypeDescription* desc;
302 // val.getValueTypeDescription( &desc);
303 // typelib_typedescription_release( desc);
312 for( i
=0; i
< val
.getLength(); i
++)
315 switch ( elem
.getValueTypeClass())
318 sprintf( tmpBuf
, "sal_Int8 %d \n", *(sal_Int8
*)elem
.getValue());
320 case TypeClass_SHORT
:
321 sprintf( tmpBuf
, "sal_Int16 %d \n", *(sal_Int16
*)elem
.getValue());
324 sprintf( tmpBuf
, "sal_Int32 %d \n", *(sal_Int32
*)elem
.getValue());
326 case TypeClass_DOUBLE
:
327 sprintf( tmpBuf
, "double %f \n", *(double*)elem
.getValue());
329 case TypeClass_FLOAT
:
330 sprintf( tmpBuf
, "float %f \n", *(float*)elem
.getValue());
332 case TypeClass_STRING
:
333 sprintf( tmpBuf
, "%S \n", (*(OUString
*)elem
.getValue()).getStr());
335 case TypeClass_INTERFACE
:
337 // we assume that the interface is XInvocation of a AxTestControls.Basic component.
338 Reference
<XInvocation
> inv
;
342 Any prpVal
= inv
->getValue( OUString( L
"prpString"));
343 sprintf( tmpBuf
, "Property prpString: %S \n", (*(OUString
*)prpVal
.getValue()).getStr());
349 strcat( buff
, tmpBuf
);
353 MessageBox( NULL
, A2T(buff
), _T("clientTest: printing Sequence elements"), MB_OK
);