Difference between revisions of "Framework/Article/Asynchronous Callback Service"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Asynchronous callback service)
 
(2 intermediate revisions by 2 users not shown)
Line 9: Line 9:
 
The following code snippets show the interface and service definitions for the new asynchronous callback service.
 
The following code snippets show the interface and service definitions for the new asynchronous callback service.
  
<code>[cpp]
+
<source lang="cpp">
 
#ifndef __com_sun_star_awt_XCallback_idl__
 
#ifndef __com_sun_star_awt_XCallback_idl__
 
#define __com_sun_star_awt_XCallback_idl__
 
#define __com_sun_star_awt_XCallback_idl__
Line 43: Line 43:
  
 
#endif
 
#endif
</code>
+
</source>
  
<code>[cpp]
+
<source lang="cpp">
 
#ifndef __com_sun_star_awt_XRequestCallback_idl__
 
#ifndef __com_sun_star_awt_XRequestCallback_idl__
 
#define __com_sun_star_awt_XRequestCallback_idl__
 
#define __com_sun_star_awt_XRequestCallback_idl__
Line 83: Line 83:
  
 
#endif
 
#endif
</code>
+
</source>
  
<code>[cpp]
+
<source lang="cpp">
 
#ifndef __com_sun_star_awt_AsyncCallback_idl__
 
#ifndef __com_sun_star_awt_AsyncCallback_idl__
 
#define __com_sun_star_awt_AsyncCallback_idl__
 
#define __com_sun_star_awt_AsyncCallback_idl__
Line 106: Line 106:
  
 
#endif
 
#endif
</code>
+
</source>
  
 
The service can be created with a factory method.
 
The service can be created with a factory method.
  
<code>[java]
+
<source lang="java">
 
XRequestCallback xAsyncCallback = AsyncCallback.create(xComponentContext);
 
XRequestCallback xAsyncCallback = AsyncCallback.create(xComponentContext);
  
</code>
+
</source>
  
 
A callback will be added to the asynchronous callback service using addCallback. The method allows one to use an additonal parameter which will be provided to the callback method. The data can be anything which can be transported via a UNO any.
 
A callback will be added to the asynchronous callback service using addCallback. The method allows one to use an additonal parameter which will be provided to the callback method. The data can be anything which can be transported via a UNO any.
  
<code>[java]
+
<source lang="java">
 
MyCallbackCode aCallback = new MyCallback();
 
MyCallbackCode aCallback = new MyCallback();
 
MyData aData = new MyData();
 
MyData aData = new MyData();
  
 
xAsyncCallback.addCallback( aCallback, aData );
 
xAsyncCallback.addCallback( aCallback, aData );
</code>
+
</source>
 +
 
  
[[Category:Development]]
 
 
[[Category:Framework:Article]]
 
[[Category:Framework:Article]]
[[Category:Framework]]
 
 
[[Category:Article]]
 
[[Category:Article]]
 +
[[Category:Documentation/Developer]]
 +
{{Documentation/Candidate}}

Latest revision as of 11:36, 28 March 2010

Asynchronous callback service

UNO awt provides a GUI based uno API for OpenOffice.org developer. Sometimes it's necessary that an implementation is called by OpenOffice.org at a later time to do certain tasks. Sometimes this is also bound to GUI library actions which must be completed before another request can be processed. For example you want to change something when a dialog is ready for user input. The notification windowShown at com.sun.star.awt.XWindowListener can be used to be notified when a dialog becomes visible. The dialog itself is not ready yet. The asynchronous callback service can solve this problem. The callback will be called when OpenOffice.org enters the message loop and the callback message gets processed. There are several other scenarios where this service can be useful.

The service will be available in OpenOffice.org 2.4 and later.

ATTENTION: The asynchronous callback service can only work when VCL has been correctly initialized by OpenOffice.org and the message loop is running.

The following code snippets show the interface and service definitions for the new asynchronous callback service.

#ifndef __com_sun_star_awt_XCallback_idl__
#define __com_sun_star_awt_XCallback_idl__
 
#ifndef __com_sun_star_uno_XInterface_idl__ 
#include <com/sun/star/uno/XInterface.idl> 
#endif
 
//=============================================================================
 
module com { module sun { module star { module awt {
 
//============================================================================= 
 
/** specifices an interface which can be used to call back
    an implementation
 */
interface XCallback
{
	//-------------------------------------------------------------------------
 
	/** notifies the callback implementation
 
        @param aData
		private data which was provided when the callback was requested.
	*/
    void notify( [in] any aData );
};
 
//=============================================================================
 
}; }; }; };
 
#endif
#ifndef __com_sun_star_awt_XRequestCallback_idl__
#define __com_sun_star_awt_XRequestCallback_idl__
 
#ifndef __com_sun_star_awt_XCallback_idl__ 
#include <com/sun/star/awt/XCallback.idl> 
#endif
 
//=============================================================================
 
module com { module sun { module star { module awt {
 
//============================================================================= 
 
/** specifices an interface which can be used to call back
    an implementation
 */
interface XRequestCallback
{
	//-------------------------------------------------------------------------
 
	/** adds a callback request to the implementation
 
        @param aData
		any private data which will be provided to the callback implementation.
 
        @param xCallback
		a reference to the callback which should be called by the implementation
        of this interface.
    */
    void addCallback( [in] XCallback xCallback, [in] any aData );
};
 
//=============================================================================
 
}; }; }; };
 
#endif
#ifndef __com_sun_star_awt_AsyncCallback_idl__
#define __com_sun_star_awt_AsyncCallback_idl__
 
#ifndef __com_sun_star_awt_XRequestCallback_idl__
#include <com/sun/star/awt/XRequestCallback.idl>
#endif
 
module com { module sun { module star { module awt {
 
//============================================================================
/** An implementation which uses the message queue to call the
    callback implementation asynchronously.
 
    @see XRequestCallback
 */
service AsyncCallback: XRequestCallback;
 
}; }; }; };
 
#endif

The service can be created with a factory method.

XRequestCallback xAsyncCallback = AsyncCallback.create(xComponentContext);

A callback will be added to the asynchronous callback service using addCallback. The method allows one to use an additonal parameter which will be provided to the callback method. The data can be anything which can be transported via a UNO any.

MyCallbackCode aCallback = new MyCallback();
MyData aData = new MyData();
 
xAsyncCallback.addCallback( aCallback, aData );
Personal tools