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_cli_ure.hxx"
31 #include "Cli_environment.h"
36 #include "osl/diagnose.h"
37 #include "cli_proxy.h"
39 using namespace System::Runtime::Remoting
;
40 using namespace System::Runtime::Remoting::Proxies
;
41 using namespace System::Collections
;
42 using namespace System::Text
;
43 using namespace System::Diagnostics
;
44 using namespace System::Threading
;
49 inline System::String
* Cli_environment::createKey(System::String
* oid
, System::Type
* t
)
51 return System::String::Concat(oid
, t
->get_FullName());
55 inline Cli_environment::Cli_environment()
57 #if OSL_DEBUG_LEVEL >= 2
58 _numRegisteredObjects
= 0;
62 Cli_environment::~Cli_environment()
64 OSL_ENSURE(_numRegisteredObjects
== 0,
65 "cli uno bridge: CLI environment contains unrevoked objects");
69 System::Object
* Cli_environment::registerInterface(
70 System::Object
* obj
, System::String
* oid
)
72 #if OSL_DEBUG_LEVEL >= 1
73 //obj must be a transparent proxy
74 OSL_ASSERT(RemotingServices::IsTransparentProxy(obj
));
75 _numRegisteredObjects
++;
77 OSL_ASSERT( ! m_objects
->ContainsKey(oid
));
78 m_objects
->Add(oid
, new WeakReference(obj
));
81 System::Object
* Cli_environment::registerInterface (
82 System::Object
* obj
, System::String
* oid
, System::Type
* type
)
84 #if OSL_DEBUG_LEVEL >= 1
85 //obj must be a real cli object
86 OSL_ASSERT( ! RemotingServices::IsTransparentProxy(obj
));
87 _numRegisteredObjects
++;
89 System::String
* key
= createKey(oid
, type
);
90 //see synchronization in map_uno2cli in cli_data.cxx
91 OSL_ASSERT( ! m_objects
->ContainsKey(key
));
92 m_objects
->Add(key
, new WeakReference(obj
));
96 void Cli_environment::revokeInterface(System::String
* oid
, System::Type
* type
)
98 System::String
* key
= type
!= NULL
? createKey(oid
, type
) : oid
;
99 #if OSL_DEBUG_LEVEL >= 1
100 _numRegisteredObjects
--;
102 #if OSL_DEBUG_LEVEL >= 2
104 if (m_objects
->ContainsKey(key
) == false)
106 Trace::WriteLine("cli uno bridge: try to revoke unregistered interface");
107 Trace::WriteLine(oid
);
110 Trace::WriteLine(System::String::Format(
111 new System::String(S
"cli uno bridge: {0} remaining registered interfaces"),
112 __box(m_objects
->get_Count() - 1)));
114 m_objects
->Remove(key
);
117 inline void Cli_environment::revokeInterface(System::String
* oid
)
119 return revokeInterface(oid
, NULL
);
122 System::Object
* Cli_environment::getRegisteredInterface(System::String
* oid
,
125 //try if it is a UNO interface
126 System::Object
* ret
= NULL
;
127 ret
= m_objects
->get_Item(oid
);
130 //try if if it is a proxy for a cli object
131 oid
= createKey(oid
, type
);
132 ret
= m_objects
->get_Item( oid
);
136 System::WeakReference
* weakIface
=
137 static_cast< System::WeakReference
* >( ret
);
138 ret
= weakIface
->Target
;
141 m_objects
->Remove( oid
);
145 System::String
* Cli_environment::getObjectIdentifier(System::Object
* obj
)
147 System::String
* oId
= 0;
148 RealProxy
* aProxy
= RemotingServices::GetRealProxy(obj
);
151 UnoInterfaceProxy
* proxyImpl
= dynamic_cast<UnoInterfaceProxy
*>(aProxy
);
153 oId
= proxyImpl
->getOid();
158 StringBuilder
* buf
= new StringBuilder(256);
160 System::Threading::Monitor::Enter(__typeof(Cli_environment
));
162 buf
->Append(m_IDGen
->GetId(obj
, & bFirst
));
165 System::Threading::Monitor::Exit(__typeof(Cli_environment
));
168 buf
->Append(sOidPart
);
169 oId
= buf
->ToString();
173 } //namespace cli_uno