Difference between revisions of "Effort/Make Dialogs Asynchronous"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Adapted Links.)
 
(22 intermediate revisions by 4 users not shown)
Line 1: Line 1:
As we proceed with the [[Uno/Effort/Creating the Uno Threading Framework|Uno Threading Framework]], it becomes necessary to fix asynchronous dialogs so as to avoid deadlocks. This page documents the background, necessary tasks and the status of '''Modal OpenOffice.org Dialogs in Multi-threaded Environments'''.
+
As we proceed with [[Effort/Make VCL Thread-Transparent|making VCL thread-transparent]], it becomes necessary to fix asynchronous dialogs so as to avoid deadlocks. This page documents the background, necessary tasks and the status of '''Modal OpenOffice.org Dialogs in Multi-threaded Environments'''.
 
* Author: Kai Sommerfeld  
 
* Author: Kai Sommerfeld  
 
* Version: 1.0
 
* Version: 1.0
 
* Feb. 13, 2006
 
* Feb. 13, 2006
 +
* [[CWS]]: {{Uno/CWS|SRC680|asyncdialogs}}
 +
 +
For '''Current Status''', please use '''[[Media:Asyncdialog CaseList.ods |this spreadsheet]]'''
  
 
==The Problem==  
 
==The Problem==  
Currently VCL dialogs are executed using synchronous Dialog::Execute().  
+
Currently [[VCL]] dialogs are executed using synchronous Dialog::Execute(). Dialog::Execute() calls Application::Yield() periodically, until dialog is about to be ended. Today, Application::Yield() releases the [[VCL]] mutex (the [[Terms/Solar Mutex|Solar Mutex]]), which is wrong, because due to this a second thread can enter [[VCL]] while another thread is already within [[VCL]] (Dialog::Execute()). The logical consequence for a fix is that Application::Yield() must no longer release the [[Terms/Solar Mutex|VCL Solar Mutex]]. But then another problem arises.
Dialog::Execute() calls Application::Yield() periodically, until dialog  
+
is about to be ended. Today, Application::Yield() releases the VCL mutex  
+
(the Solar Mutex), which is wrong, because due to this a second thread can
+
enter VCL while another thread is already within VCL (Dialog::Execute()).  
+
The logical consequence for a fix is that Application::Yield() must no
+
longer release the VCL mutex. But then another problem arises.
+
  
The thread calling Dialog::Execute() will acquire the VCL mutex once it and
+
The thread calling Dialog::Execute() will acquire the [[Terms/Solar Mutex|VCL Solar Mutex]] once it and not release it until Dialog::Execute() has finished. This means, that during the time a thread executes a dialog, no other thread can enter [[VCL]]. If a dialog implementation creates (or uses) a thread in order to obtain data it needs itself for being able to end sometimes and this thread needs to call back to [[VCL]] in order to fullfil its work (example: deliver search results to a [[VCL]] control contained in a search dialog), this will no longer work. The worker thread will never be able to enter [[VCL]] and therefore never end. The dialog thread, staying in [[VCL]] all the time, will never get results from the worker thread and therefore never end.  
not release it until Dialog::Execute() has finished. This means, that during
+
the time a thread executes a dialog, no other thread can enter VCL. If a
+
dialog implementation creates (or uses) a thread in order to obtain data it  
+
needs itself for being able to end sometimes and this thread needs to call  
+
back to VCL in order to fullfil its work (example: deliver search results to a  
+
VCL control contained in a search dialog), this will no longer work. The  
+
worker thread will never be able to enter VCL and therefore never end. The  
+
dialog thread, staying in VCL all the time, will never get results from
+
the worker thread and therefore never end.  
+
  
Unfortunately, in the current OOo code base there are some dialogs that
+
Unfortunately, in the current OOo code base there are some dialogs that suffer from the problem just described.
suffer from the problem just described.
+
  
The demand to fix those dialogs soon comes from the upcoming [[Uno/Effort/Creating the Uno Threading Framework|Uno Threading Framework]]. There, the Solar Mutex will be retired and replaced by another
+
The demand to fix those dialogs soon comes from the upcoming [[Effort/Make VCL Thread-Transparent|thread-transparent VCL]]. There, the [[Terms/Solar Mutex|Solar Mutex]] will be retired and replaced by an outer, global mutex that will be used to synchronize access to all [[Uno/Term/Thread Unsafe|thread-unsafe]] components (incl. thread-unsafe [[Uno]] components). Additionally, Application::Yield() will be fixed not to release this new mutex for the reasons discussed earlier.
global mutex that will be used to synchronize access to all [[Uno/Term/Thread Unsafe|thread-unsafe]]
+
components (incl. thread-unsafe [[Uno]] components). Additionally,  
+
Application::Yield() will be fixed not to release this new mutex for the
+
reasons discussed earlier.
+
  
 
==The Solution==  
 
==The Solution==  
We want to change the dialog execution model to an asynchronous one. The  
+
We want to change the dialog execution model to an asynchronous one. The code that wants to display a dialog simply triggers execution and enters [[VCL]] just for a short time, leaves [[VCL]] immediately after having triggered  
code that wants to display a dialog simply triggers execution and enters  
+
VCL just for a short time, leaves VCL immediately after having triggered  
+
 
the dialog. Results will be delivered asynchronously using a callback.
 
the dialog. Results will be delivered asynchronously using a callback.
  
Unfortunately, we also have chosen the broken dialog API design for the  
+
Unfortunately, we also have chosen the broken dialog API design for the Uno API that models dialogs. We need to introduce a new API for Uno dialogs as well and to extend (not replace: compatibility!!!) the existing  
UNO API that models dialogs. We need to introduce a new API for UNO dialogs  
+
as well and to extend (not replace: compatibility!!!) the existing  
+
 
components that implement the old interface.
 
components that implement the old interface.
  
 
==Old Dialog Interfaces==
 
==Old Dialog Interfaces==
  
===VCL===
+
===[[VCL]]===
 
'''(vcl/inc/dialog.hxx)'''
 
'''(vcl/inc/dialog.hxx)'''
  
<pre>  
+
<code>[cpp]
 
+
 
class VCL_DLLPUBLIC Dialog : public SystemWindow
 
class VCL_DLLPUBLIC Dialog : public SystemWindow
 
{
 
{
Line 58: Line 36:
 
...
 
...
 
};
 
};
 
+
</code>
</pre>
+
  
 
===[[Uno]]===
 
===[[Uno]]===
Line 65: Line 42:
 
'''(offapi/com/sun/star/ui/dialogs/XExecutableDialog.idl)'''
 
'''(offapi/com/sun/star/ui/dialogs/XExecutableDialog.idl)'''
  
<pre>
+
<code>[cpp]
 
published interface XExecutableDialog: com::sun::star::uno::XInterface
 
published interface XExecutableDialog: com::sun::star::uno::XInterface
 
{
 
{
Line 71: Line 48:
 
         short execute();
 
         short execute();
 
};
 
};
</pre>
+
</code>
  
 
==New Dialog Interfaces==
 
==New Dialog Interfaces==
  
===VCL===
+
===[[VCL]]===
<pre>
+
<code>[cpp]
 
class VCL_DLLPUBLIC Dialog : public SystemWindow
 
class VCL_DLLPUBLIC Dialog : public SystemWindow
 
{
 
{
Line 88: Line 65:
 
...
 
...
 
};
 
};
</pre>
+
</code>
  
 
===[[Uno]]===
 
===[[Uno]]===
 
 
* (offapi/com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.idl)
 
* (offapi/com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.idl)
 
* (offapi/com/sun/star/ui/dialogs/XDialogClosedListener.idl)
 
* (offapi/com/sun/star/ui/dialogs/XDialogClosedListener.idl)
 
* (offapi/com/sun/star/ui/dialogs/DialogClosedEvent.idl)
 
* (offapi/com/sun/star/ui/dialogs/DialogClosedEvent.idl)
  
<pre>
+
<code>[cpp]
 
interface XAsynchronousExecutableDialog: com::sun::star::uno::XInterface
 
interface XAsynchronousExecutableDialog: com::sun::star::uno::XInterface
 
{
 
{
Line 115: Line 91:
 
     short DialogResult;
 
     short DialogResult;
 
};
 
};
</pre>
+
</code>
  
 
==Status==
 
==Status==
 +
We already created a Child Workspace (CWS) for changing all dialogs that must be changed in order to make them compatible with the upcoming [[Effort/Make VCL Thread-Transparent|thread-transparent VCL]]. The name of the CWS is 'asyncdialogs'.
  
We already created a Child Workspace (CWS) for changing all dialogs
+
The new dialog API ([[VCL]] and [[Uno]]) is available in this CWS.  
that must be changed in order to make them compatible with the upcoming [[Uno/Effort/Creating the Uno Threading Framework|Threading Framework]]. The name of the CWS is 'asyncdialogs'.
+
  
The new dialog API (VCL and [[Uno]]) is available in this CWS.  
+
Many affected dialogs are already adapted. Although the number of affected dialogs is not that big, lots of work is to be done because not only the dialog itself but all its callers that rely on data that are
 +
synchronously returned by the dialog must be adapted, too. This is like the well-known snowball effect.
  
Many affected dialogs are already adapted. Although the number of
+
The latest changes were the replacement of SfxApplication::InsertDocumentDialog(). Now we want to close this CWS because the amount of changes are already big and our Quality Assurance needs much time to approve them. The CWS is resynced to m171. All platforms are built. After this CWS is integrated we will open a new CWS (asyncdialogs2). It is planned to integrate asyncdialog early in OOo 2.1.
affected dialogs is not that big, lots of work is to be done because not
+
only the dialog itself but all its callers that rely on data that are
+
synchronously returned by the dialog must be adapted, too. This is like
+
the well-known snowball effect.
+
 
+
The latest changes were the replacement of SfxApplication::InsertDocumentDialog().
+
Now we want to close this CWS because the amount of changes are already big and our Quality Assurance needs much time to approve them. The CWS is resynced to m171. All platforms are built.
+
After this CWS is integrated we will open a new CWS (asyncdialogs2).  
+
It is planned to integrate asyncdialog early in OOo 2.1.
+
  
 
==Work Required==  
 
==Work Required==  
It is necessary to find and adapt all dialogs that  
+
It is necessary to find and adapt all dialogs that are executed synchronously and that use SvtURLBox  
are executed synchronously and that use SvtURLBox  
+
(svtools/source/control/inettbc.cxx). SvtURLBox creates a thread for filename autocompletion which will no longer work once the [[Effort/Make VCL Thread-Transparent|thread-transparent VCL]] is in place. We need to adapt all callers of the dialogs just mentioned, if those callers rely directly or indirectly on data  
(svtools/source/control/inettbc.cxx). SvtURLBox creates a thread for  
+
filename autocompletion which will no longer work once the [[Uno/Effort/Creating the Uno Threading Framework|Threading Framework]] is in place. We need to adapt all callers of the dialogs just  
+
mentioned, if those callers rely directly or indirectly on data  
+
 
synchronously delivered by the dialogs.
 
synchronously delivered by the dialogs.
  
Important affected dialogs are the OOo Filepicker and the OOo Folderpicker  
+
Important affected dialogs are the OOo Filepicker and the OOo Folderpicker dialogs (fpicker/source/office/*). Those are heavily used throughout the whole OOo code. They must be changed, because they use SvtURLBox. Changing all affected code, especially the dozens of direct and indirect clients of the picker dialogs, is really much work.
dialogs (fpicker/source/office/*). Those are heavily used throughout the  
+
 
whole OOo code. They must be changed, because they use SvtURLBox. Changing  
+
Currently, we are in the middle of adapting sfx2::FileDialogHelper (sfx2/include/filedlghelper.hxx) that is a wrapper for the file dialog and that is heavily used in the OOo code.
all affected code, especially the dozens of direct and indirect clients of
+
 
the picker dialogs, is really much work.
+
Other affected SvtURLBox clients are subject of further investigations (LXR is your friend...)
  
Currently, we are in the middle of adapting sfx2::FileDialogHelper
+
To help find the classes that use SvtURLBox or use a dialog that has a SvtURLBox embedded in it, this (hopefully correct) UML diagram was created: [http://wiki.services.openoffice.org/mwiki/images/6/60/SvtURLBox_UML.jpg SvtURLBox_UML.jpg]  (The Visual Paradigm file would be here: [http://wiki.services.openoffice.org/mwiki/images/6/60/SvtURLBox.vpp SvtURLBox.vpp] ...but I couldn't upload .vpp files)
(sfx2/include/filedlghelper.hxx) that is a wrapper for the file dialog and
+
that is heavily used in the OOo code.
+
  
Other affected SvtURLBox clients are subject of further investigations
+
AntoXu has made [[Media:Asyncdialog CaseList.ods |this spreadsheet]] which lists all the dialog cases that need to be fixed, location, how to fix and how to test.
(LXR is  your friend...)
+
  
To help find the classes that use SvtURLBox or use a dialog that has a SvtURLBox embedded in it, this (hopefully correct) UML diagram was created:
+
==About Development==
[http://wiki.services.openoffice.org/mwiki/images/6/60/SvtURLBox_UML.jpg SvtURLBox_UML.jpg] (The Visual Paradigm file would be here: [http://wiki.services.openoffice.org/mwiki/images/6/60/SvtURLBox.vpp SvtURLBox.vpp] ...but I couldn't upload .vpp files)
+
Currently, we have fixed about 50 cases, to call for more people to join us, we divided all cases we found into 6 categories and wrote a development guide to help people understand our working process and the possible clue of how to fix a case under a particular category. If any people want to contribute to this project, we suggest that he or she could start from this page and read [[Media:AsyncDialogsDevGuide.odt |the development guide]] and [[Media:ExamplePatches.tar.gz |the example fixes]], and selects an unfixed case in cases list and create patches.
  
 
==Conclusion==
 
==Conclusion==
Much work is already done in order to solve the problem that certain OOo  
+
Much work is already done in order to solve the problem that certain OOo dialogs will have in conjunction with the new OOo [[Effort/Make VCL Thread-Transparent|thread-transparent VCL]]. All conceptional work is done. What's open is to finish adapting affected OOo code.
dialogs will have in conjunction with the new OOo [[Uno/Effort/Creating the Uno Threading Framework|Threading Framework]]. All
+
conceptional work is done. What's open is to finish adapting affected OOo
+
code.
+
  
 
==Typical Changes - Example==  
 
==Typical Changes - Example==  
IMO a simple example for the code changes typical for asyncdialog can be found in /svx/source/dialog/cuigaldlg.cxx and the respective header file in the same directory.
+
IMO a simple example for the code changes typical for asyncdialog can be found in svx/source/dialog/cuigaldlg.cxx and the respective header file in the same directory.
  
There is a class SearchProgress which creates an instance of class SearchThread. The SearchThread worker thread calls back into VCL (e.g. SearchThread::ImplSearch(): mpBrowser->aLbxFound.InsertEntry()).
+
There is a class SearchProgress which creates an instance of class SearchThread. The SearchThread worker thread calls back into [[VCL]] (e.g. SearchThread::ImplSearch(): mpBrowser->aLbxFound.InsertEntry()).
  
 
In asyncdialogs the latter will lead to a deadlock, because:  
 
In asyncdialogs the latter will lead to a deadlock, because:  
Line 175: Line 134:
 
* But Execute() will never return, because it waits for the SearchThread to end.
 
* But Execute() will never return, because it waits for the SearchThread to end.
 
   
 
   
In fact it waits indefinetly that CleanUpHdl will be called (handler calls EndDialog() and this will let Execute() return), which is only done from inside SearchThread::onTerminated(). But the worker thread only terminates if it is ably to deliver search results to VCL, but it will never be able to do so because every VCL call will automatically guarded by the Office [[Uno/Spec/Thread Unsafety Bridge|thread-unsafe environment]] ...
+
In fact it waits indefinetly that CleanUpHdl will be called (handler calls EndDialog() and this will let Execute() return), which is only done from inside SearchThread::onTerminated(). But the worker thread only terminates if it is ably to deliver search results to [[VCL]], but it will never be able to do so because every [[VCL]] call will automatically guarded by the Office [[Uno/Spec/Thread Unsafety Bridge|thread-unsafe environment]] ...
  
The solution was to switch to the new asyncdialog VCL Dialog execution API.
+
The solution was to switch to the new asyncdialog [[VCL]] Dialog execution API.
  
 
   Another solution would be to deliver the results of the SearchThread asynchronously - wouldn't it?
 
   Another solution would be to deliver the results of the SearchThread asynchronously - wouldn't it?
Line 185: Line 144:
 
   (Frank Schönheit)
 
   (Frank Schönheit)
 
:: You mean, would have been, don't you?! ;-). Your suggested solution probably would have worked to fix this one dialog again, but would have left the following points open:
 
:: You mean, would have been, don't you?! ;-). Your suggested solution probably would have worked to fix this one dialog again, but would have left the following points open:
::* While a synchronous (AKA ::execute) dialog is open, no function call can enter the office over the UNO API.
+
::* While a synchronous (AKA ::execute) dialog is open, no function call can enter the office over the Uno API.
 
::* Synchronous dialogs keep staying on the stack, therefor enforcing that the opened dialogs need to be closed in the reverse order (just try to open some dialogs in otherwise unrelated documents, dependent on the a/synchrnous nature of the involved dialogs, you need to close these in the reverse order).
 
::* Synchronous dialogs keep staying on the stack, therefor enforcing that the opened dialogs need to be closed in the reverse order (just try to open some dialogs in otherwise unrelated documents, dependent on the a/synchrnous nature of the involved dialogs, you need to close these in the reverse order).
 
::* Depending on the actual call stack, mutexes etc. may be kept locked, while the dialog is open, potentially introducing long lasting locks respectively deadlocks.  
 
::* Depending on the actual call stack, mutexes etc. may be kept locked, while the dialog is open, potentially introducing long lasting locks respectively deadlocks.  
::* Last but not least: "::execute" is a blocking and potentially long lasting call, conflicting with a potential [[Proposal/Advanced Threading-Architecture|event based architecture]] I think we should head for.
+
::* Last but not least: "::execute" is a blocking and potentially long lasting call, conflicting with a potential [[Architecture/Proposal/Advanced Threading-Architecture|event based architecture]] I think we should head for.
 
:: So, basically converting all dialogs to asynchronous is the "right thing" anyway :-). [[User:Kr|Kr]] 13:27, 19 July 2006 (CEST)
 
:: So, basically converting all dialogs to asynchronous is the "right thing" anyway :-). [[User:Kr|Kr]] 13:27, 19 July 2006 (CEST)
  
::: The first item is not really convinicing, as it affects only the UNO API which is "protected" using the SolarMutex. Other API would continue to work fine. The other items sounds more convincing :) (fs)
+
::: The first item is not really convinicing, as it affects only the Uno API which is "protected" using the [[Terms/Solar Mutex|Solar Mutex]]. Other API would continue to work fine. The other items sounds more convincing :) (fs)
  
 
==To DO==  
 
==To DO==  
Line 197: Line 156:
  
 
===General===
 
===General===
* Find and change all dialogs that are executed via Dialog::Execute() and that indirectly or directly spawn threads that need to call back to [[Uno/Term/Thread Unsafe|thread-unsafe]] code (for example VCL API, [[Uno/Term/Thread Unsafe|thread-unsafe]] Uno objects) in order to get the dialog finished.
+
* Find and change all dialogs that are executed via Dialog::Execute() and that indirectly or directly spawn threads that need to call back to [[Uno/Term/Thread Unsafe|thread-unsafe]] code (for example [[VCL]] API, [[Uno/Term/Thread Unsafe|thread-unsafe]] Uno objects) in order to get the dialog finished.
** VCL: deprecate Dialog::Execute() => changes mail!
+
** [[VCL]]: deprecate Dialog::Execute() => changes mail!
** UNO: deprecate css::ui::dialogs::XExecutableDialog => changes mail!
+
** [[Uno]]: deprecate css::ui::dialogs::XExecutableDialog => changes mail!
  
=== Affected dialogs ===
+
===Affected dialogs===
 
* '''unopkg binary -- gui mode'''
 
* '''unopkg binary -- gui mode'''
 
** desktop/source/deployment/gui/dp_gui_service.cxx => ServiceImpl::execute()
 
** desktop/source/deployment/gui/dp_gui_service.cxx => ServiceImpl::execute()
Line 245: Line 204:
 
***# sw/source/ui/dbui/dbmgr.cxx
 
***# sw/source/ui/dbui/dbmgr.cxx
 
***# sw/source/ui/dbui/mailmergechildwindow.cxx
 
***# sw/source/ui/dbui/mailmergechildwindow.cxx
*** MailDispatcher has interface for regsistration of UNO listeners
+
*** MailDispatcher has interface for regsistration of Uno listeners
***# no Dialog::Execute in any possible callstack (currently only reachable via UNO API) ==> DONE: no change needed
+
***# no Dialog::Execute in any possible callstack (currently only reachable via Uno API) ==> DONE: no change needed
 
***# SwMailSendDialog is a modeless dialog, does not need to be changed therfore, but is called by MailMergeWizard which has overridden Dialog::Execute()
 
***# SwMailSendDialog is a modeless dialog, does not need to be changed therfore, but is called by MailMergeWizard which has overridden Dialog::Execute()
 
***** MailMergeWizard and calling code must be changed ==> DONE: changed
 
***** MailMergeWizard and calling code must be changed ==> DONE: changed
Line 257: Line 216:
  
 
[[Category:Effort]]
 
[[Category:Effort]]
 +
[[Category:Architecture]]
 +
[[Category:Multi-Threading]]

Latest revision as of 07:13, 19 June 2007

As we proceed with making VCL thread-transparent, it becomes necessary to fix asynchronous dialogs so as to avoid deadlocks. This page documents the background, necessary tasks and the status of Modal OpenOffice.org Dialogs in Multi-threaded Environments.

For Current Status, please use this spreadsheet

The Problem

Currently VCL dialogs are executed using synchronous Dialog::Execute(). Dialog::Execute() calls Application::Yield() periodically, until dialog is about to be ended. Today, Application::Yield() releases the VCL mutex (the Solar Mutex), which is wrong, because due to this a second thread can enter VCL while another thread is already within VCL (Dialog::Execute()). The logical consequence for a fix is that Application::Yield() must no longer release the VCL Solar Mutex. But then another problem arises.

The thread calling Dialog::Execute() will acquire the VCL Solar Mutex once it and not release it until Dialog::Execute() has finished. This means, that during the time a thread executes a dialog, no other thread can enter VCL. If a dialog implementation creates (or uses) a thread in order to obtain data it needs itself for being able to end sometimes and this thread needs to call back to VCL in order to fullfil its work (example: deliver search results to a VCL control contained in a search dialog), this will no longer work. The worker thread will never be able to enter VCL and therefore never end. The dialog thread, staying in VCL all the time, will never get results from the worker thread and therefore never end.

Unfortunately, in the current OOo code base there are some dialogs that suffer from the problem just described.

The demand to fix those dialogs soon comes from the upcoming thread-transparent VCL. There, the Solar Mutex will be retired and replaced by an outer, global mutex that will be used to synchronize access to all thread-unsafe components (incl. thread-unsafe Uno components). Additionally, Application::Yield() will be fixed not to release this new mutex for the reasons discussed earlier.

The Solution

We want to change the dialog execution model to an asynchronous one. The code that wants to display a dialog simply triggers execution and enters VCL just for a short time, leaves VCL immediately after having triggered the dialog. Results will be delivered asynchronously using a callback.

Unfortunately, we also have chosen the broken dialog API design for the Uno API that models dialogs. We need to introduce a new API for Uno dialogs as well and to extend (not replace: compatibility!!!) the existing components that implement the old interface.

Old Dialog Interfaces

VCL

(vcl/inc/dialog.hxx)

[cpp] class VCL_DLLPUBLIC Dialog : public SystemWindow { ... public:

   virtual short Execute();

... };

Uno

(offapi/com/sun/star/ui/dialogs/XExecutableDialog.idl)

[cpp] published interface XExecutableDialog: com::sun::star::uno::XInterface {

       void setTitle( [in] string aTitle );
       short execute();

};

New Dialog Interfaces

VCL

[cpp] class VCL_DLLPUBLIC Dialog : public SystemWindow { ... public:

   // Link impl: DECL_LINK( MyEndDialogHdl, Dialog* ); 
   // - param is a pointer to the dialog just ended
   virtual void StartExecuteModal( const Link& rEndDialogHdl );
   long         GetResult() const;

... };

Uno

  • (offapi/com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.idl)
  • (offapi/com/sun/star/ui/dialogs/XDialogClosedListener.idl)
  • (offapi/com/sun/star/ui/dialogs/DialogClosedEvent.idl)

[cpp] interface XAsynchronousExecutableDialog: com::sun::star::uno::XInterface {

   void setDialogTitle( [in] string aTitle );
   void startExecuteModal( [in] XDialogClosedListener xListener );

};

interface XDialogClosedListener: com::sun::star::lang::XEventListener {

   void dialogClosed( [in] DialogClosedEvent aEvent );

};

struct DialogClosedEvent: com::sun::star::lang::EventObject {

   /*
      @see <type>ExecutableDialogResults</type>
    */
   short DialogResult;

};

Status

We already created a Child Workspace (CWS) for changing all dialogs that must be changed in order to make them compatible with the upcoming thread-transparent VCL. The name of the CWS is 'asyncdialogs'.

The new dialog API (VCL and Uno) is available in this CWS.

Many affected dialogs are already adapted. Although the number of affected dialogs is not that big, lots of work is to be done because not only the dialog itself but all its callers that rely on data that are synchronously returned by the dialog must be adapted, too. This is like the well-known snowball effect.

The latest changes were the replacement of SfxApplication::InsertDocumentDialog(). Now we want to close this CWS because the amount of changes are already big and our Quality Assurance needs much time to approve them. The CWS is resynced to m171. All platforms are built. After this CWS is integrated we will open a new CWS (asyncdialogs2). It is planned to integrate asyncdialog early in OOo 2.1.

Work Required

It is necessary to find and adapt all dialogs that are executed synchronously and that use SvtURLBox (svtools/source/control/inettbc.cxx). SvtURLBox creates a thread for filename autocompletion which will no longer work once the thread-transparent VCL is in place. We need to adapt all callers of the dialogs just mentioned, if those callers rely directly or indirectly on data synchronously delivered by the dialogs.

Important affected dialogs are the OOo Filepicker and the OOo Folderpicker dialogs (fpicker/source/office/*). Those are heavily used throughout the whole OOo code. They must be changed, because they use SvtURLBox. Changing all affected code, especially the dozens of direct and indirect clients of the picker dialogs, is really much work.

Currently, we are in the middle of adapting sfx2::FileDialogHelper (sfx2/include/filedlghelper.hxx) that is a wrapper for the file dialog and that is heavily used in the OOo code.

Other affected SvtURLBox clients are subject of further investigations (LXR is your friend...)

To help find the classes that use SvtURLBox or use a dialog that has a SvtURLBox embedded in it, this (hopefully correct) UML diagram was created: SvtURLBox_UML.jpg (The Visual Paradigm file would be here: SvtURLBox.vpp ...but I couldn't upload .vpp files)

AntoXu has made this spreadsheet which lists all the dialog cases that need to be fixed, location, how to fix and how to test.

About Development

Currently, we have fixed about 50 cases, to call for more people to join us, we divided all cases we found into 6 categories and wrote a development guide to help people understand our working process and the possible clue of how to fix a case under a particular category. If any people want to contribute to this project, we suggest that he or she could start from this page and read the development guide and the example fixes, and selects an unfixed case in cases list and create patches.

Conclusion

Much work is already done in order to solve the problem that certain OOo dialogs will have in conjunction with the new OOo thread-transparent VCL. All conceptional work is done. What's open is to finish adapting affected OOo code.

Typical Changes - Example

IMO a simple example for the code changes typical for asyncdialog can be found in svx/source/dialog/cuigaldlg.cxx and the respective header file in the same directory.

There is a class SearchProgress which creates an instance of class SearchThread. The SearchThread worker thread calls back into VCL (e.g. SearchThread::ImplSearch(): mpBrowser->aLbxFound.InsertEntry()).

In asyncdialogs the latter will lead to a deadlock, because:

  • The thread that calls SearchProgress::Execute() thereby enters the Office thread-unsafe environment.
  • That thread stays there at least until Execute() returns.
  • But Execute() will never return, because it waits for the SearchThread to end.

In fact it waits indefinetly that CleanUpHdl will be called (handler calls EndDialog() and this will let Execute() return), which is only done from inside SearchThread::onTerminated(). But the worker thread only terminates if it is ably to deliver search results to VCL, but it will never be able to do so because every VCL call will automatically guarded by the Office thread-unsafe environment ...

The solution was to switch to the new asyncdialog VCL Dialog execution API.

 Another solution would be to deliver the results of the SearchThread asynchronously - wouldn't it?
 That is, instead of calling InsertEntry directly, the search thread could post an asynchronous event
 to the thread currently doing the message loop, and in this event, the entry would be inserted.
 This way, only the dialog itself would need to be fixed, not all of its clients.
 (Frank Schönheit)
You mean, would have been, don't you?! ;-). Your suggested solution probably would have worked to fix this one dialog again, but would have left the following points open:
  • While a synchronous (AKA ::execute) dialog is open, no function call can enter the office over the Uno API.
  • Synchronous dialogs keep staying on the stack, therefor enforcing that the opened dialogs need to be closed in the reverse order (just try to open some dialogs in otherwise unrelated documents, dependent on the a/synchrnous nature of the involved dialogs, you need to close these in the reverse order).
  • Depending on the actual call stack, mutexes etc. may be kept locked, while the dialog is open, potentially introducing long lasting locks respectively deadlocks.
  • Last but not least: "::execute" is a blocking and potentially long lasting call, conflicting with a potential event based architecture I think we should head for.
So, basically converting all dialogs to asynchronous is the "right thing" anyway :-). Kr 13:27, 19 July 2006 (CEST)
The first item is not really convinicing, as it affects only the Uno API which is "protected" using the Solar Mutex. Other API would continue to work fine. The other items sounds more convincing :) (fs)

To DO

List of things to do in CWS asyncdialogs

General

  • Find and change all dialogs that are executed via Dialog::Execute() and that indirectly or directly spawn threads that need to call back to thread-unsafe code (for example VCL API, thread-unsafe Uno objects) in order to get the dialog finished.
    • VCL: deprecate Dialog::Execute() => changes mail!
    • Uno: deprecate css::ui::dialogs::XExecutableDialog => changes mail!

Affected dialogs

  • unopkg binary -- gui mode
    • desktop/source/deployment/gui/dp_gui_service.cxx => ServiceImpl::execute()
    • dialog creates threads.
    • dialog is a [[Uno/Term/Thread Unsafe|thread-unsafe Uno service => does not use Dialog::Execute, but Application::Execute()
      • BUG: Application::Execute() enters apartment at the beginning and remains in apartment all the time
      • dialog worker threads will never be able to enter apartment => deadlock
      • UTF2: Application::Execute() must be fixed - DONE (by KR)
      • asyncdialogs: com.sun.star.comp.deployment.ui.PackageManagerDialog service: - does no longer implement XExecutableDialog, but XAsynchronousExecutableDialog DONE: changed
  • fpicker/source/unx/gnome/asynceventnotifier.hxx: #include <osl/thread.hxx>
    • triggered by dialog - ./fpicker/source/unx/gnome/SalGtkFilePicker.cxx => SalGtkFilePicker::execute()
    • 'execute' problem must be solved
    • DONE: no change (asynceventnotifier no longer used in m124)
  • svtools/source/control/inettbc.cxx:#include <vos/thread.hxx>
    • triggered by misc dialogs using SvtURLBox => 'execute' problem must be solved
    • class XMLFilterTabPageXSLT (/framework/filter/source/xsltdialog/xmlfiltertabpagexslt.hxx)
      • @@@ todo => investigate if change needed
    • class SvxIMapDlg (/graphics/svx/inc/imapdlg.hxx)
      • @@@ todo => investigate if change needed
    • class SvxHyperURLBox : public SvtURLBox (/graphics/svx/source/dialog/hltpbase.hxx)
      • @@@ todo: callers? => investigate
    • class OFileURLControl : public SvtURLBox (/graphics/svx/source/dialog/urlcontrol.hxx)
      • @@@ todo: callers? => investigate
    • class AddInstanceDialog (/graphics/svx/source/inc/datanavi.hxx)
      • @@@ todo => investigate if change needed
    • class SvtExpFileDlg_Impl (/gsl/fpicker/source/office/iodlgimp.hxx)
      • part of implementation of class SvtFileDialog (/gsl/fpicker/source/office/iodlg.hxx)
      • lots of direct and indirect callers!
      • @@@ IN PROGRESS (Peter Burow)
    • class ScLinkedAreaDlg (/sc/sc/source/ui/inc/linkarea.hxx)
      • @@@ todo => investigate if change needed
    • class FileURLBox : public SvtURLBox (/util/svtools/inc/fileurlbox.hxx)
      • @@@ todo: callers? => investigate
    • class OFileURLControl : public SvtURLBox (/util/svtools/inc/urlcontrol.hxx)
      • @@@ todo: callers? => investigate
      • IN PROGRESS
  • sw/source/ui/inc/maildispatcher.hxx:#include <osl/thread.hxx>
    • class MailDispatcher (sw/source/ui/inc/maildispatcher.hxx) is an osl::Thread
      • Instances are created in:
        1. sw/source/ui/dbui/dbmgr.cxx
        2. sw/source/ui/dbui/mailmergechildwindow.cxx
      • MailDispatcher has interface for regsistration of Uno listeners
        1. no Dialog::Execute in any possible callstack (currently only reachable via Uno API) ==> DONE: no change needed
        2. SwMailSendDialog is a modeless dialog, does not need to be changed therfore, but is called by MailMergeWizard which has overridden Dialog::Execute()
          • MailMergeWizard and calling code must be changed ==> DONE: changed
    • DONE
  • svx/source/dialog/cuigaldlg.hxx:#include <vos/thread.hxx>
    • @@@ triggered by dialog => 'execute' problem must be solved
    • DONE: changed
Personal tools