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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cppuhelper.hxx"
26
27 #include "cppu/EnvDcp.hxx"
28
29 #include "cppu/helper/purpenv/Environment.hxx"
30 #include "cppu/helper/purpenv/Mapping.hxx"
31
32
33
34 #define LOG_LIFECYCLE_TestEnv
35 #ifdef LOG_LIFECYCLE_TestEnv
36 # include <iostream>
37 # define LOG_LIFECYCLE_TestEnv_emit(x) x
38
39 #else
40 # define LOG_LIFECYCLE_TestEnv_emit(x)
41
42 #endif
43
44
45 class SAL_DLLPRIVATE TestEnv : public cppu::Enterable
46 {
47 int m_inCount;
48
49 virtual ~TestEnv();
50
51 public:
52 explicit TestEnv();
53
54 protected:
55 virtual void v_enter(void);
56 virtual void v_leave(void);
57
58 virtual void v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam);
59 virtual void v_callOut_v (uno_EnvCallee * pCallee, va_list * pParam);
60
61 virtual int v_isValid (rtl::OUString * pReason);
62 };
63
TestEnv()64 TestEnv::TestEnv()
65 : m_inCount(0)
66 {
67 LOG_LIFECYCLE_TestEnv_emit(fprintf(stderr, "LIFE: %s -> %p\n", "TestEnv::TestEnv(...)", this));
68 }
69
~TestEnv(void)70 TestEnv::~TestEnv(void)
71 {
72 LOG_LIFECYCLE_TestEnv_emit(fprintf(stderr, "LIFE: %s -> %p\n", "TestEnv::~TestEnv(void)", this));
73 }
74
75
v_callInto_v(uno_EnvCallee * pCallee,va_list * pParam)76 void TestEnv::v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam)
77 {
78 ++ m_inCount;
79 pCallee(pParam);
80 -- m_inCount;
81 }
82
v_callOut_v(uno_EnvCallee * pCallee,va_list * pParam)83 void TestEnv::v_callOut_v(uno_EnvCallee * pCallee, va_list * pParam)
84 {
85 -- m_inCount;
86 pCallee(pParam);
87 ++ m_inCount;
88 }
89
v_enter(void)90 void TestEnv::v_enter(void)
91 {
92 ++ m_inCount;
93 }
94
v_leave(void)95 void TestEnv::v_leave(void)
96 {
97 -- m_inCount;
98 }
99
v_isValid(rtl::OUString * pReason)100 int TestEnv::v_isValid(rtl::OUString * pReason)
101 {
102 int result = m_inCount & 1;
103
104 if (result)
105 *pReason = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OK"));
106
107 else
108 *pReason = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("not entered/invoked"));
109
110 return result;
111 }
112
uno_initEnvironment(uno_Environment * pEnv)113 extern "C" void SAL_CALL uno_initEnvironment(uno_Environment * pEnv) SAL_THROW_EXTERN_C()
114 {
115 cppu::helper::purpenv::Environment_initWithEnterable(pEnv, new TestEnv());
116 }
117
uno_ext_getMapping(uno_Mapping ** ppMapping,uno_Environment * pFrom,uno_Environment * pTo)118 extern "C" void uno_ext_getMapping(uno_Mapping ** ppMapping,
119 uno_Environment * pFrom,
120 uno_Environment * pTo )
121 {
122 cppu::helper::purpenv::createMapping(ppMapping, pFrom, pTo);
123 }
124
125