1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "sal/config.h"
25 
26 #include "com/sun/star/uno/Reference.hxx"
27 #include "com/sun/star/uno/RuntimeException.hpp"
28 #include "com/sun/star/uno/XInterface.hpp"
29 #include "rtl/ustring.h"
30 #include "rtl/ustring.hxx"
31 #include "uno/current_context.h"
32 #include "uno/dispatcher.hxx"
33 #include "uno/lbnames.h"
34 
35 #include "currentcontext.hxx"
36 
37 namespace binaryurp {
38 
39 namespace {
40 
41 namespace css = com::sun::star;
42 
43 }
44 
45 namespace current_context {
46 
get()47 css::uno::UnoInterfaceReference get() {
48     css::uno::UnoInterfaceReference cc;
49     if (!uno_getCurrentContext(
50             reinterpret_cast< void ** >(&cc.m_pUnoI),
51             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO)).pData, 0))
52     {
53         throw css::uno::RuntimeException(
54             rtl::OUString(
55                 RTL_CONSTASCII_USTRINGPARAM("uno_getCurrentContext failed")),
56             css::uno::Reference< css::uno::XInterface >());
57     }
58     return cc;
59 }
60 
set(css::uno::UnoInterfaceReference const & value)61 void set(css::uno::UnoInterfaceReference const & value) {
62     css::uno::UnoInterfaceReference cc(value);
63     if (!uno_setCurrentContext(
64             cc.m_pUnoI,
65             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO)).pData, 0))
66     {
67         throw css::uno::RuntimeException(
68             rtl::OUString(
69                 RTL_CONSTASCII_USTRINGPARAM("uno_setCurrentContext failed")),
70             css::uno::Reference< css::uno::XInterface >());
71     }
72 }
73 
74 }
75 
76 }
77