LibreOffice Module cli_ure (master) 1
WeakAdapter.cs
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 */
18
19using System;
20using unoidl.com.sun.star.uno;
21using unoidl.com.sun.star.lang;
22
23namespace uno.util
24{
25
33public class WeakAdapter : XAdapter
34{
35 // references the XWeak implementation
36 private WeakReference m_weakRef;
37 // contains XReference objects registered by addReference
38 private delegate void XReference_dispose();
40
45 public WeakAdapter( Object obj )
46 {
47 m_weakRef = new WeakReference( obj );
49 }
50
61 internal /* non-virtual */ void referentDying()
62 {
64 lock (this)
65 {
68 }
69 if (null != call)
70 call();
71 }
72
73 // XAdapter impl
74
81 {
82 return m_weakRef.Target;
83 }
89 public void removeReference( XReference xReference )
90 {
91 lock (this)
92 {
94 new XReference_dispose( xReference.dispose );
95 }
96 }
101 public void addReference( XReference xReference )
102 {
103 lock (this)
104 {
106 new XReference_dispose( xReference.dispose );
107 }
108 }
109}
110
111}
An XAdapter implementation that holds a weak reference (System.WeakReference) to an object.
Definition: WeakAdapter.cs:34
void addReference(XReference xReference)
Called by clients to unregister listeners.
Definition: WeakAdapter.cs:101
WeakReference m_weakRef
Definition: WeakAdapter.cs:36
WeakAdapter(Object obj)
ctor.
Definition: WeakAdapter.cs:45
void removeReference(XReference xReference)
Called by clients to register listener which are notified when the weak object is dying.
Definition: WeakAdapter.cs:89
XReference_dispose m_XReference_dispose
Definition: WeakAdapter.cs:39
Object queryAdapted()
Called to obtain a hard reference o the object which is kept weakly by this instance.
Definition: WeakAdapter.cs:80
delegate void XReference_dispose()
std::shared_ptr< osl::Mutex > const & lock()