diff options
Diffstat (limited to 'cli_ure/source/ure')
-rw-r--r-- | cli_ure/source/ure/makefile.mk | 101 | ||||
-rw-r--r-- | cli_ure/source/ure/uno/util/DisposeGuard.cs | 101 | ||||
-rw-r--r-- | cli_ure/source/ure/uno/util/WeakAdapter.cs | 152 | ||||
-rw-r--r-- | cli_ure/source/ure/uno/util/WeakBase.cs | 212 | ||||
-rw-r--r-- | cli_ure/source/ure/uno/util/WeakComponentBase.cs | 143 |
5 files changed, 709 insertions, 0 deletions
diff --git a/cli_ure/source/ure/makefile.mk b/cli_ure/source/ure/makefile.mk new file mode 100644 index 000000000000..ae8c7fc7547f --- /dev/null +++ b/cli_ure/source/ure/makefile.mk @@ -0,0 +1,101 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: dbo $ $Date: 2003-03-28 10:17:42 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ = ..$/.. +PRJNAME = cli_ure + +.INCLUDE : $(PRJ)$/util$/makefile.pmk +.IF "$(BUILD_FOR_CLI)" != "" + +# for dummy +TARGET = cli_ure + +.INCLUDE : settings.mk + +.INCLUDE : $(PRJ)$/util$/target.pmk +.INCLUDE : target.mk + +CLI_URE = $(OUT)$/bin$/cli_ure.dll + +ALLTAR : \ + $(CLI_URE) + +CSFILES = \ + uno$/QueryInterface.cs \ + uno$/Runtime.cs \ + uno$/util$/ServiceImplementationAttribute.cs \ + uno$/util$/DisposeGuard.cs \ + uno$/util$/WeakAdapter.cs \ + uno$/util$/WeakBase.cs \ + uno$/util$/WeakComponentBase.cs \ + uno$/util$/ServiceBase.cs \ + uno$/util$/ServiceFactory.cs + +$(CLI_URE) : $(CLI_UDKAPI) $(CSFILES) + +csc.exe $(CSCFLAGS) \ + -target:library \ + -out:$@ \ + -reference:$(CLI_UDKAPI) \ + -reference:System.dll \ + $(CSFILES) + +.ENDIF diff --git a/cli_ure/source/ure/uno/util/DisposeGuard.cs b/cli_ure/source/ure/uno/util/DisposeGuard.cs new file mode 100644 index 000000000000..a3c38e828136 --- /dev/null +++ b/cli_ure/source/ure/uno/util/DisposeGuard.cs @@ -0,0 +1,101 @@ +/************************************************************************* + * + * $RCSfile: DisposeGuard.cs,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: dbo $ $Date: 2003-03-28 10:17:44 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +using System; +using unoidl.com.sun.star.lang; + +namespace uno.util +{ + +/** Helper class to conveniently auto dispose UNO objects from within + managed code. +*/ +public struct DisposeGuard : IDisposable +{ + private XComponent m_xComponent; + + /** ctor. + + @param obj target object + */ + public DisposeGuard( Object obj ) + { + m_xComponent = (XComponent) uno.Runtime.queryInterface_throw( typeof (XComponent), obj ); + } + /** ctor. + + @param obj target object + */ + public DisposeGuard( XComponent obj ) + { + m_xComponent = obj; + } + + /** System.IDisposable impl + */ + public void Dispose() + { + if (null != m_xComponent) + m_xComponent.dispose(); + } +} + +} diff --git a/cli_ure/source/ure/uno/util/WeakAdapter.cs b/cli_ure/source/ure/uno/util/WeakAdapter.cs new file mode 100644 index 000000000000..3089cc5f4cac --- /dev/null +++ b/cli_ure/source/ure/uno/util/WeakAdapter.cs @@ -0,0 +1,152 @@ +/************************************************************************* + * + * $RCSfile: WeakAdapter.cs,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: dbo $ $Date: 2003-03-28 10:17:46 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +using System; +using unoidl.com.sun.star.uno; +using unoidl.com.sun.star.lang; + +namespace uno.util +{ + +/** An XAdapter implementation that holds a weak reference + (System.WeakReference) to an object. + Clients can register listeners (unoidl.com.sun.star.lang.XReference) + which are notified when the object (the one which is kept weak) is + being finalized. That is, that object is being destroyed because there + are not any hard references to it. +*/ +public class WeakAdapter : XAdapter +{ + // references the XWeak implementation + private WeakReference m_weakRef; + // contains XReference objects registered by addReference + private delegate void XReference_dispose(); + private XReference_dispose m_XReference_dispose; + + /** ctor. + + @param obj the object that is to be held weakly + */ + public WeakAdapter( Object obj ) + { + m_weakRef = new WeakReference( obj ); + m_XReference_dispose = null; + } + + /** Called by the XWeak implementation (WeakBase) when it is being + finalized. It is only being called once. + The registererd XReference listeners are notified. On notification + they are to unregister themselves. The notification is thread-safe. + However, it is possible to add a listener during the notification + process, which will never receive a notification. + To prevent this, one would have to synchronize this method with + the addReference method. But this can result in deadlocks in a + multithreaded environment. + */ + internal /* non-virtual */ void referentDying() + { + XReference_dispose call; + lock (this) + { + call = m_XReference_dispose; + m_XReference_dispose = null; + } + if (null != call) + call(); + } + + // XAdapter impl + + /** Called to obtain a hard reference o the object which is kept weakly + by this instance. + + @return hard reference to the object + */ + public Object queryAdapted() + { + return m_weakRef.Target; + } + /** Called by clients to register listener which are notified when the + weak object is dying. + + @param xReference a listener + */ + public void removeReference( XReference xReference ) + { + lock (this) + { + m_XReference_dispose -= new XReference_dispose( xReference.dispose ); + } + } + /** Called by clients to unregister listeners. + + @param xReference a listener + */ + public void addReference( XReference xReference ) + { + lock (this) + { + m_XReference_dispose += new XReference_dispose( xReference.dispose ); + } + } +} + +} diff --git a/cli_ure/source/ure/uno/util/WeakBase.cs b/cli_ure/source/ure/uno/util/WeakBase.cs new file mode 100644 index 000000000000..28725474a8d9 --- /dev/null +++ b/cli_ure/source/ure/uno/util/WeakBase.cs @@ -0,0 +1,212 @@ +/************************************************************************* + * + * $RCSfile: WeakBase.cs,v $ + * + * $Revision: 1.1 $ + * + * last change: $ $Date: 2003-03-28 10:17:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +using System; +using System.Collections; +using unoidl.com.sun.star.uno; +using unoidl.com.sun.star.lang; + +namespace uno.util +{ + +/** This class can be used as a base class for UNO objects. + It implements the capability to be kept weakly + (unoidl.com.sun.star.uno.XWeak) and it implements + unoidl.com.sun.star.lang.XTypeProvider which is necessary for + using the object from StarBasic. +*/ +public class WeakBase : XWeak, XTypeProvider +{ + // Contains all WeakAdapter which have been created in this class + // They have to be notified when this object dies + private WeakAdapter m_adapter; + + protected static Hashtable s_types = new Hashtable(); + protected static Hashtable s_impl_ids = new Hashtable(); + + // XWeak impl + /** The returned XAdapter implementation can be used to keap a + weak reference to this object. + + @return a weak adapter + */ + public XAdapter queryAdapter() + { + if (null == m_adapter) + { + lock (this) + { + if (null == m_adapter) + m_adapter = new WeakAdapter( this ); + } + } + return m_adapter; + } + + /** Overrides of Object.Finalize method. + When there are no references to this object anymore, then the + garbage collector calls this method, thereby causing the adapter + object to be notified. The adapter, in turn, notifies all + listeners (unoidl.com.sun.star.uno.XReference). + */ + ~WeakBase() + { + if (null != m_adapter) + m_adapter.referentDying(); + } + + // XTypeProvider impl + + /** Returns an array of Type objects which represent all implemented + UNO interfaces of this object. + + @return Type objects of all implemented interfaces. + */ + public Type [] getTypes() + { + Type [] types; + Type type = GetType(); + lock (s_types) + { + types = (Type []) s_types[ type ]; + if (null == types) + { + Type [] interfaces = type.GetInterfaces(); + ArrayList list = new ArrayList( interfaces.Length ); + for ( Int32 pos = 0; pos < interfaces.Length; ++pos ) + { + Type iface = interfaces[ pos ]; + // xxx todo: as long as the bridge cannot introduce + // native CTS types into UNO on the fly + if (iface.FullName.StartsWith( "unoidl." )) + { + list.Add( iface ); + } + } + Int32 len = list.Count; + Type [] ar = new Type [ len ]; + for ( Int32 pos = 0; pos < len; ++pos ) + ar[ pos ] = (Type) list[ pos ]; + s_types[ type ] = ar; + types = ar; + } + } + return types; + } + + /** Provides an identifier that represents the set of UNO interfaces + implemented by this class. All instances of this class which run + in the same CLR return the same array. + + @return identifier as array of bytes + */ + public byte [] getImplementationId() + { + byte [] id; + Type type = GetType(); + lock (s_impl_ids) + { + id = (byte []) s_impl_ids[ type ]; + if (null == id) + { + Int32 hash = GetHashCode(); + String name = type.FullName; + Int32 len= name.Length; + + id = new byte[ 4 + (2 * len) ]; + id[ 0 ]= (byte) (hash & 0xff); + id[ 1 ]= (byte) ((hash >> 8) & 0xff); + id[ 2 ]= (byte) ((hash >> 16) & 0xff); + id[ 3 ]= (byte) ((hash >> 24) & 0xff); + + for ( Int32 pos = 0; pos < len; ++pos ) + { + UInt16 c = Convert.ToUInt16( name[ pos ] ); + id[ 4 + (2 * pos) ] = (byte) (c & 0xff); + id[ 4 + (2 * pos) +1 ] = (byte) ((c >> 8) & 0xff); + } + s_impl_ids[ type ] = id; + } + } + return id; + } + + // System.Object + //______________________________________________________________________________________________ + public override String ToString() + { + System.Text.StringBuilder buf = new System.Text.StringBuilder( base.ToString(), 256 ); + buf.Append( "\nUNO Object Implementation:\n\tImplementationId: " ); + buf.Append( getImplementationId() ); + buf.Append( "\n\tInterfaces: " ); + Type [] types = getTypes(); + for ( Int32 pos = 0; pos < types.Length; ++pos ) + { + buf.Append( types[ pos ].FullName ); + if (pos < (types.Length -1)) + buf.Append( ", " ); + } + return buf.ToString(); + } +} + +} + diff --git a/cli_ure/source/ure/uno/util/WeakComponentBase.cs b/cli_ure/source/ure/uno/util/WeakComponentBase.cs new file mode 100644 index 000000000000..ed20c681e180 --- /dev/null +++ b/cli_ure/source/ure/uno/util/WeakComponentBase.cs @@ -0,0 +1,143 @@ +/************************************************************************* + * + * $RCSfile: WeakComponentBase.cs,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: dbo $ $Date: 2003-03-28 10:17:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +using System; +using unoidl.com.sun.star.lang; + +namespace uno.util +{ + +/** This class can be used as a base class for UNO objects. + It implements the capability to be kept weakly + (unoidl.com.sun.star.uno.XWeak) and it implements + unoidl.com.sun.star.lang.XTypeProvider which is necessary for + using the object from StarBasic. + In addition, it implements the interface + unoidl.com.sun.star.lang.XComponent to be disposed explicitly. +*/ +public class WeakComponentBase : WeakBase, XComponent, IDisposable +{ + private delegate void t_disposing( EventObject evt ); + private t_disposing m_disposing = null; + + /** Disposing callback called when the object is being disposed. + This method has to be implemented by sub classes. + */ + protected virtual void disposing() + { + } + + // XComponent impl + /** This method is called by the owner of this object to explicitly + dispose it. This implementation of dispose() first notifies all + registered event listeners and finally this object by calling its + protected disposing(). + */ + public void dispose() + { + // send disposing notifications to listeners + t_disposing call; + lock (this) + { + call = m_disposing; + m_disposing = null; + } + if (null != call) + { + EventObject evt = new EventObject( this ); + call( evt ); + } + // call sub class + disposing(); + } + /** Registers an event listener being notified when this object is disposed. + + @param xListener event listener + */ + public void addEventListener( XEventListener xListener ) + { + lock (this) + { + m_disposing += new t_disposing( xListener.disposing ); + } + } + /** Revokes an event listener from being notified when this object is disposed. + + @param xListener event listener + */ + public void removeEventListener( XEventListener xListener ) + { + lock (this) + { + m_disposing -= new t_disposing( xListener.disposing ); + } + } + + /** System.IDisposable implementation to conveniently auto dispose + UNO objects within CLI code. + */ + public void Dispose() + { + dispose(); + } +} + +} |