1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 #include "cppuhelper/bootstrap.hxx"
24 #include "rtl/process.h"
25 #include "typelib/typedescription.hxx"
27 #include "com/sun/star/bridge/ModelDependent.hpp"
28 #include "com/sun/star/bridge/XBridgeSupplier2.hpp"
29 #include "com/sun/star/uno/TypeClass.hpp"
30 #include "com/sun/star/script/XInvocation.hpp"
31 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
32 #include "com/sun/star/uno/XComponentContext.hpp"
33 #include <com/sun/star/bridge/oleautomation/NamedArgument.hpp>
34 #include "rtl/ustring.hxx"
36 using namespace com::sun::star::bridge
;
37 using namespace com::sun::star::bridge::ModelDependent
;
38 using namespace com::sun::star::uno
;
39 using namespace com::sun::star::lang
;
40 using namespace com::sun::star::script
;
41 using namespace com::sun::star::bridge::oleautomation
;
46 bool equalSequences(const Sequence
<T
>& seqIn
, const Sequence
<Any
> & returned
);
49 Reference
< XMultiServiceFactory
> objectFactory
;
52 Reference
<XMultiServiceFactory
> getMultiServiceFactory()
54 static Reference
< XMultiServiceFactory
> factory
;
55 if( ! objectFactory
.is() )
57 Reference
<XComponentContext
> context
= defaultBootstrap_InitialComponentContext();
58 factory
.set(context
->getServiceManager(), UNO_QUERY
);
64 Reference
<XInvocation
> getComObject( OUString progId
)
67 Reference
< XInvocation
> ret
;
68 if( ! objectFactory
.is())
69 { Reference
<XMultiServiceFactory
> mgr
= getMultiServiceFactory();
70 Reference
<XInterface
> xInt
= mgr
->createInstance(
71 "com.sun.star.bridge.oleautomation.Factory");
72 objectFactory
.set(xInt
, UNO_QUERY
);
75 if( objectFactory
.is())
77 Reference
<XInterface
> xIntAx
= objectFactory
->createInstance( progId
.getStr());
80 Reference
< XInvocation
> xInv( xIntAx
, UNO_QUERY
);
87 Reference
<XInvocation
> convertComObject( IUnknown
* pUnk
)
89 Reference
< XMultiServiceFactory
> mgr
= getMultiServiceFactory();
90 Reference
< XInterface
> xIntSupplier
= mgr
->createInstance("com.sun.star.bridge.OleBridgeSupplier2");
91 Reference
< XBridgeSupplier2
> xSuppl( xIntSupplier
, UNO_QUERY
);
94 CComVariant
var( pUnk
);
95 any
<<= (sal_uIntPtr
) &var
;
97 rtl_getGlobalProcessId( arId
);
98 Any target
= xSuppl
->createBridge( any
, Sequence
<sal_Int8
>( (sal_Int8
*)arId
, 16), OLE
, UNO
);
100 Reference
<XInvocation
> ret
;
106 Parameter values contains the expected return values. The value at index 0
107 correspond to parameter 0 (left - most). For parameters which are not out or
108 in/out the value must be a void any.
110 The number of items in value must be the
111 same as the number of provided parameter during the call on the method.
113 The parameter outArgs, indices correspond to the sequences which are
114 arguments to XInvocation::invoke
116 bool checkOutArgs(const Sequence
<Any
> & outArgs
,
117 const Sequence
<sal_Int16
> & indices
, const Sequence
<Any
> & values
)
119 if (values
.getLength() != outArgs
.getLength())
121 //iterate over all parameters. i represents the parameter index
122 for (int i
= 0; i
< values
.getLength(); i
++)
124 if (values
[i
].getValueType() == cppu::UnoType
<void>::get())
127 //Based on the parameter index find the correspondent out value
128 int indexOutSeq
= -1;
129 for (int iIndices
= indices
.getLength() - 1; iIndices
>= 0; iIndices
--)
131 if (indices
[iIndices
] == i
)
133 indexOutSeq
= iIndices
;
137 if (indexOutSeq
== -1)
143 outArgs
[indexOutSeq
] >>=out
;
148 if (values
[i
].getValueType() == cppu::UnoType
<NamedArgument
>::get())
150 NamedArgument inNamed
;
151 values
[i
] >>= inNamed
;
152 value
<<= inNamed
.Value
;
154 if (value
!= outArgs
[indexOutSeq
])
160 /* The returned sequence always contains Any elements
162 bool equalSequences(const Any
& orig
, const Any
& returned
)
164 if (orig
.getValueTypeClass() != TypeClass_SEQUENCE
)
169 TypeDescription
td(orig
.getValueTypeRef());
170 typelib_IndirectTypeDescription
* indirect_td
= (typelib_IndirectTypeDescription
*) td
.get();
172 switch (indirect_td
->pType
->eTypeClass
)
176 Sequence
<sal_Unicode
> seq
;
180 return equalSequences(seq
, seq2
);
182 case TypeClass_BOOLEAN
:
184 Sequence
<sal_Bool
> seq
;
188 return equalSequences(seq
, seq2
);
192 Sequence
<sal_Int8
> seq
;
196 return equalSequences(seq
, seq2
);
198 case TypeClass_SHORT
:
200 Sequence
<sal_Int16
> seq
;
204 return equalSequences(seq
, seq2
);
208 Sequence
<sal_Int32
> seq
;
212 return equalSequences(seq
, seq2
);
214 case TypeClass_FLOAT
:
220 return equalSequences(seq
, seq2
);
222 case TypeClass_DOUBLE
:
224 Sequence
<double> seq
;
228 return equalSequences(seq
, seq2
);
230 case TypeClass_STRING
:
232 Sequence
<OUString
> seq
;
236 return equalSequences(seq
, seq2
);
244 return equalSequences(seq
, seq2
);
246 case TypeClass_SEQUENCE
:
248 //Sequence<sal_Unicode> seq;
250 //Sequence<Any> seq2;
252 //return equalSequences(seq, seq2);
255 case TypeClass_INTERFACE
:
257 Sequence
<Reference
<XInvocation
> > seq
;
261 return equalSequences(seq
, seq2
);
270 bool equalSequences(const Sequence
<T
>& seqIn
, const Sequence
<Any
> & seqOut
)
272 if (seqIn
.getLength() != seqOut
.getLength())
274 int len
= seqIn
.getLength();
275 for (int i
= 0; i
< len
; i
++)
279 Any anyOut
= seqOut
[i
];
287 void printSequence( Sequence
<Any
>& val
)
290 // typelib_TypeDescription* desc;
291 // val.getValueTypeDescription( &desc);
292 // typelib_typedescription_release( desc);
301 for( i
=0; i
< val
.getLength(); i
++)
304 switch ( elem
.getValueTypeClass())
307 sprintf( tmpBuf
, "sal_Int8 %d \n", *(sal_Int8
*)elem
.getValue());
309 case TypeClass_SHORT
:
310 sprintf( tmpBuf
, "sal_Int16 %d \n", *(sal_Int16
*)elem
.getValue());
313 sprintf( tmpBuf
, "sal_Int32 %d \n", *(sal_Int32
*)elem
.getValue());
315 case TypeClass_DOUBLE
:
316 sprintf( tmpBuf
, "double %f \n", *(double*)elem
.getValue());
318 case TypeClass_FLOAT
:
319 sprintf( tmpBuf
, "float %f \n", *(float*)elem
.getValue());
321 case TypeClass_STRING
:
322 sprintf( tmpBuf
, "%S \n", (*(OUString
*)elem
.getValue()).getStr());
324 case TypeClass_INTERFACE
:
326 // we assume that the interface is XInvocation of an AxTestControls.Basic component.
327 Reference
<XInvocation
> inv
;
331 Any prpVal
= inv
->getValue( OUString( L
"prpString"));
332 sprintf( tmpBuf
, "Property prpString: %S \n", (*(OUString
*)prpVal
.getValue()).getStr());
338 strcat( buff
, tmpBuf
);
342 MessageBox( NULL
, A2T(buff
), _T("clientTest: printing Sequence elements"), MB_OK
);
345 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */