1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: funcs.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
36 #include "cppuhelper/bootstrap.hxx"
37 #include "rtl/process.h"
38 #include "typelib/typedescription.hxx"
40 #include "com/sun/star/bridge/ModelDependent.hpp"
41 #include "com/sun/star/bridge/XBridgeSupplier2.hpp"
42 #include "com/sun/star/uno/TypeClass.hpp"
43 #include "com/sun/star/script/XInvocation.hpp"
44 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
45 #include "com/sun/star/uno/XComponentContext.hpp"
46 #include <com/sun/star/bridge/oleautomation/NamedArgument.hpp>
47 #include "rtl/ustring.hxx"
49 using namespace com::sun::star::bridge
;
50 using namespace com::sun::star::bridge::ModelDependent
;
51 using namespace com::sun::star::uno
;
52 using namespace com::sun::star::lang
;
53 using namespace com::sun::star::script
;
54 using namespace com::sun::star::bridge::oleautomation
;
59 bool equalSequences(const Sequence
<T
>& seqIn
, const Sequence
<Any
> & returned
);
62 Reference
< XMultiServiceFactory
> objectFactory
;//
65 Reference
<XMultiServiceFactory
> getMultiServiceFactory()
67 static Reference
< XMultiServiceFactory
> factory
;
68 if( ! objectFactory
.is() )
70 Reference
<XComponentContext
> context
= defaultBootstrap_InitialComponentContext();
71 factory
= Reference
<XMultiServiceFactory
>( context
->getServiceManager(), UNO_QUERY
);
77 Reference
<XInvocation
> getComObject( OUString progId
)
80 Reference
< XInvocation
> ret
;
81 // Reference<XMultiServiceFactory> fac;
82 if( ! objectFactory
.is())
83 { Reference
<XMultiServiceFactory
> mgr
= getMultiServiceFactory();
84 Reference
<XInterface
> xInt
= mgr
->createInstance(
85 OUString(L
"com.sun.star.bridge.oleautomation.Factory"));
86 objectFactory
= Reference
<XMultiServiceFactory
>::query( xInt
);
89 if( objectFactory
.is())
91 Reference
<XInterface
> xIntAx
= objectFactory
->createInstance( progId
.getStr());
94 Reference
< XInvocation
> xInv( xIntAx
, UNO_QUERY
);
101 Reference
<XInvocation
> convertComObject( IUnknown
* pUnk
)
103 Reference
< XMultiServiceFactory
> mgr
= getMultiServiceFactory();
104 Reference
< XInterface
> xIntSupplier
= mgr
->createInstance(OUString(L
"com.sun.star.bridge.OleBridgeSupplier2"));
105 Reference
< XBridgeSupplier2
> xSuppl( xIntSupplier
, UNO_QUERY
);
108 CComVariant
var( pUnk
);
109 any
<<= ( sal_uInt32
)&var
;
111 rtl_getGlobalProcessId( arId
);
112 Any target
= xSuppl
->createBridge( any
, Sequence
<sal_Int8
>( (sal_Int8
*)arId
, 16), OLE
, UNO
);
114 Reference
<XInvocation
> ret
;
120 Parameter values contains the expected return values. The value at index 0
121 correspond to parameter 0 (left - most). For parameters which are not out or
122 in/out the value must be a void any.
124 The number of items in value must be the
125 same as the number of provided parameter during the call on the method.
127 The parameter outArgs, indices correspond to the sequences which are
128 arguments to XInvocation::invoke
130 bool checkOutArgs(const Sequence
<Any
> & outArgs
,
131 const Sequence
<sal_Int16
> & indices
, const Sequence
<Any
> & values
)
133 if (values
.getLength() != outArgs
.getLength())
135 //iterate over all parameters. i represents the parameter index
136 for (int i
= 0; i
< values
.getLength(); i
++)
138 if (values
[i
].getValueType() == getVoidCppuType())
141 //Based on the parameter index find the correspondent out value
142 int indexOutSeq
= -1;
143 for (int iIndices
= indices
.getLength() - 1; iIndices
>= 0; iIndices
--)
145 if (indices
[iIndices
] == i
)
147 indexOutSeq
= iIndices
;
151 if (indexOutSeq
== -1)
157 outArgs
[indexOutSeq
] >>=out
;
162 if (values
[i
].getValueType() == getCppuType((NamedArgument
*) 0))
164 NamedArgument inNamed
;
165 values
[i
] >>= inNamed
;
166 value
<<= inNamed
.Value
;
168 if (value
!= outArgs
[indexOutSeq
])
174 /* The returned sequence always contains Any elements
176 bool equalSequences(const Any
& orig
, const Any
& returned
)
178 if (orig
.getValueTypeClass() != TypeClass_SEQUENCE
)
183 TypeDescription
td(orig
.getValueTypeRef());
184 typelib_IndirectTypeDescription
* indirect_td
= (typelib_IndirectTypeDescription
*) td
.get();
186 switch (indirect_td
->pType
->eTypeClass
)
190 Sequence
<sal_Unicode
> seq
;
194 return equalSequences(seq
, seq2
);
196 case TypeClass_BOOLEAN
:
198 Sequence
<sal_Bool
> seq
;
202 return equalSequences(seq
, seq2
);
206 Sequence
<sal_Int8
> seq
;
210 return equalSequences(seq
, seq2
);
212 case TypeClass_SHORT
:
214 Sequence
<sal_Int16
> seq
;
218 return equalSequences(seq
, seq2
);
222 Sequence
<sal_Int32
> seq
;
226 return equalSequences(seq
, seq2
);
228 case TypeClass_FLOAT
:
234 return equalSequences(seq
, seq2
);
236 case TypeClass_DOUBLE
:
238 Sequence
<double> seq
;
242 return equalSequences(seq
, seq2
);
244 case TypeClass_STRING
:
246 Sequence
<OUString
> seq
;
250 return equalSequences(seq
, seq2
);
258 return equalSequences(seq
, seq2
);
260 case TypeClass_SEQUENCE
:
262 //Sequence<sal_Unicode> seq;
264 //Sequence<Any> seq2;
266 //return equalSequences(seq, seq2);
269 case TypeClass_INTERFACE
:
271 Sequence
<Reference
<XInvocation
> > seq
;
275 return equalSequences(seq
, seq2
);
284 bool equalSequences(const Sequence
<T
>& seqIn
, const Sequence
<Any
> & seqOut
)
286 if (seqIn
.getLength() != seqOut
.getLength())
288 int len
= seqIn
.getLength();
289 for (int i
= 0; i
< len
; i
++)
293 Any anyOut
= seqOut
[i
];
301 void printSequence( Sequence
<Any
>& val
)
304 // typelib_TypeDescription* desc;
305 // val.getValueTypeDescription( &desc);
306 // typelib_typedescription_release( desc);
315 for( i
=0; i
< val
.getLength(); i
++)
318 switch ( elem
.getValueTypeClass())
321 sprintf( tmpBuf
, "sal_Int8 %d \n", *(sal_Int8
*)elem
.getValue());
323 case TypeClass_SHORT
:
324 sprintf( tmpBuf
, "sal_Int16 %d \n", *(sal_Int16
*)elem
.getValue());
327 sprintf( tmpBuf
, "sal_Int32 %d \n", *(sal_Int32
*)elem
.getValue());
329 case TypeClass_DOUBLE
:
330 sprintf( tmpBuf
, "double %f \n", *(double*)elem
.getValue());
332 case TypeClass_FLOAT
:
333 sprintf( tmpBuf
, "float %f \n", *(float*)elem
.getValue());
335 case TypeClass_STRING
:
336 sprintf( tmpBuf
, "%S \n", (*(OUString
*)elem
.getValue()).getStr());
338 case TypeClass_INTERFACE
:
340 // we assume that the interface is XInvocation of a AxTestControls.Basic component.
341 Reference
<XInvocation
> inv
;
345 Any prpVal
= inv
->getValue( OUString( L
"prpString"));
346 sprintf( tmpBuf
, "Property prpString: %S \n", (*(OUString
*)prpVal
.getValue()).getStr());
352 strcat( buff
, tmpBuf
);
356 MessageBox( NULL
, A2T(buff
), _T("clientTest: printing Sequence elements"), MB_OK
);