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 .
20 #include "Cli_environment.h"
24 #include "osl/diagnose.h"
25 #include "cli_proxy.h"
27 using namespace System::Runtime::Remoting
;
28 using namespace System::Runtime::Remoting::Proxies
;
29 using namespace System::Collections
;
30 using namespace System::Text
;
31 using namespace System::Diagnostics
;
32 using namespace System::Threading
;
37 inline System::String
^ Cli_environment::createKey(System::String
^ oid
, System::Type
^ t
)
39 return System::String::Concat(oid
, t
->FullName
);
43 inline Cli_environment::Cli_environment()
45 #if OSL_DEBUG_LEVEL >= 2
46 _numRegisteredObjects
= 0;
50 Cli_environment::~Cli_environment()
52 OSL_ENSURE(_numRegisteredObjects
== 0,
53 "cli uno bridge: CLI environment contains unrevoked objects");
57 System::Object
^ Cli_environment::registerInterface(
58 System::Object
^ obj
, System::String
^ oid
)
60 #if OSL_DEBUG_LEVEL >= 1
61 //obj must be a transparent proxy
62 OSL_ASSERT(RemotingServices::IsTransparentProxy(obj
));
63 _numRegisteredObjects
++;
65 OSL_ASSERT( ! m_objects
->ContainsKey(oid
));
66 m_objects
->Add(oid
, gcnew
WeakReference(obj
));
69 System::Object
^ Cli_environment::registerInterface (
70 System::Object
^ obj
, System::String
^ oid
, System::Type
^ type
)
72 #if OSL_DEBUG_LEVEL >= 1
73 //obj must be a real cli object
74 OSL_ASSERT( ! RemotingServices::IsTransparentProxy(obj
));
75 _numRegisteredObjects
++;
77 System::String
^ key
= createKey(oid
, type
);
78 //see synchronization in map_uno2cli in cli_data.cxx
79 OSL_ASSERT( ! m_objects
->ContainsKey(key
));
80 m_objects
->Add(key
, gcnew
WeakReference(obj
));
84 void Cli_environment::revokeInterface(System::String
^ oid
, System::Type
^ type
)
86 System::String
^ key
= type
!= nullptr ? createKey(oid
, type
) : oid
;
87 #if OSL_DEBUG_LEVEL >= 1
88 _numRegisteredObjects
--;
90 #if OSL_DEBUG_LEVEL >= 2
92 if (m_objects
->ContainsKey(key
) == false)
94 Trace::WriteLine("cli uno bridge: try to revoke unregistered interface");
95 Trace::WriteLine(oid
);
98 Trace::WriteLine(System::String::Format(
99 new System::String(S
"cli uno bridge: {0} remaining registered interfaces"),
100 __box(m_objects
->get_Count() - 1)));
102 m_objects
->Remove(key
);
105 inline void Cli_environment::revokeInterface(System::String
^ oid
)
107 return revokeInterface(oid
, nullptr);
110 System::Object
^ Cli_environment::getRegisteredInterface(System::String
^ oid
,
113 //try if it is a UNO interface
114 System::Object
^ ret
= nullptr;
115 ret
= m_objects
[oid
];
118 //try if if it is a proxy for a cli object
119 oid
= createKey(oid
, type
);
120 ret
= m_objects
[ oid
];
124 System::WeakReference
^ weakIface
=
125 static_cast< System::WeakReference
^ >( ret
);
126 ret
= weakIface
->Target
;
129 m_objects
->Remove( oid
);
133 System::String
^ Cli_environment::getObjectIdentifier(System::Object
^ obj
)
135 System::String
^ oId
= nullptr;
136 RealProxy
^ aProxy
= RemotingServices::GetRealProxy(obj
);
139 UnoInterfaceProxy
^ proxyImpl
= dynamic_cast<UnoInterfaceProxy
^>(aProxy
);
141 oId
= proxyImpl
->getOid();
146 StringBuilder
^ buf
= gcnew
StringBuilder(256);
147 bool bFirst
= new bool(false);
148 System::Threading::Monitor::Enter(Cli_environment::typeid);
150 buf
->Append(m_IDGen
->GetId(obj
, bFirst
));
153 System::Threading::Monitor::Exit(Cli_environment::typeid);
156 buf
->Append(sOidPart
);
157 oId
= buf
->ToString();
161 } //namespace cli_uno
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */