Author: sh-sh-sh
Date: Fri Feb 8 16:55:33 2008
New Revision: 44301
URL: http://svn.opensuse.org/viewcvs/yast?rev=44301&view=rev
Log:
Moved last YCPValue out of YUI:
Now using abstract YBuiltinCaller class,
YCP part is now in YCPBuiltinCaller and in Y2UINamespace
Added:
trunk/core/libyui/src/YBuiltinCaller.h
trunk/core/libyui/src/YCPBuiltinCaller.cc
trunk/core/libyui/src/YCPBuiltinCaller.h
Modified:
trunk/core/libyui/src/Makefile.am
trunk/core/libyui/src/Y2UINamespace.cc
trunk/core/libyui/src/YUI.cc
trunk/core/libyui/src/YUI.h
Modified: trunk/core/libyui/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/Makefile.am?rev=44301&r1=44300&r2=44301&view=diff
==============================================================================
--- trunk/core/libyui/src/Makefile.am (original)
+++ trunk/core/libyui/src/Makefile.am Fri Feb 8 16:55:33 2008
@@ -16,6 +16,7 @@
Y2CCUI.cc \
YUI.cc \
YCP_UI.cc \
+ YCPBuiltinCaller.cc \
YCPDialogParser.cc \
YCPErrorDialog.cc \
YCPEvent.cc \
@@ -111,6 +112,7 @@
YBothDim.h \
YColor.h \
YCP_UI.h \
+ YCPBuiltinCaller.h \
YCPDialogParser.h \
YCPErrorDialog.h \
YCPEvent.h \
@@ -149,6 +151,7 @@
YUILog.h \
YUIPlugin.h \
YUISymbols.h \
+ YBuiltinCaller.h \
YWidget.h \
YWidgetFactory.h \
YWidgetID.h \
Modified: trunk/core/libyui/src/Y2UINamespace.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/Y2UINamespace.cc?rev=44301&r1=44300&r2=44301&view=diff
==============================================================================
--- trunk/core/libyui/src/Y2UINamespace.cc (original)
+++ trunk/core/libyui/src/Y2UINamespace.cc Fri Feb 8 16:55:33 2008
@@ -34,6 +34,7 @@
#include "YUISymbols.h"
#include "YUIComponent.h"
#include "Y2UINamespace.h"
+#include "YCPBuiltinCaller.h"
#include "YMacro.h"
#define VERBOSE_UI_CALLS 0
@@ -703,18 +704,30 @@
YCPValue ret = YCPVoid();
- if ( m_comp->ui()-> runningWithThreads() )
+ if ( m_comp->ui()->runningWithThreads() )
{
- m_comp->ui()->_builtinCallData.function = this;
+ YCPBuiltinCaller * builtinCaller =
+ dynamic_cast (m_comp->ui()->builtinCaller() );
- m_comp->ui()->signalUIThread();
+ if ( ! builtinCaller )
+ {
+ builtinCaller = new YCPBuiltinCaller();
+ m_comp->ui()->setBuiltinCaller( builtinCaller );
+ }
+
+ if ( builtinCaller )
+ {
+ builtinCaller->setFunction( this );
- while ( ! m_comp->ui()->waitForUIThread() )
- {
- // NOP
- }
+ m_comp->ui()->signalUIThread();
- ret = m_comp->ui()->_builtinCallData.result;
+ while ( ! m_comp->ui()->waitForUIThread() )
+ {
+ // NOP
+ }
+
+ ret = builtinCaller->result();
+ }
}
else
{
Added: trunk/core/libyui/src/YBuiltinCaller.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YBuiltinCaller.h?rev=44301&view=auto
==============================================================================
--- trunk/core/libyui/src/YBuiltinCaller.h (added)
+++ trunk/core/libyui/src/YBuiltinCaller.h Fri Feb 8 16:55:33 2008
@@ -0,0 +1,52 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YBuiltinCaller.h
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+#ifndef YBuiltinCaller_h
+#define YBuiltinCaller_h
+
+
+/**
+ * Abstract base class for transparently calling a built-in function.
+ * Derived classes will want to add some methods to store the function to be
+ * called, arguments to that function and its result and to retrieve the result
+ * when needed.
+ *
+ * See YCPBuiltinCaller.h for an implementation.
+ **/
+class YBuiltinCaller
+{
+protected:
+ YBuiltinCaller() {}
+
+public:
+ virtual ~YBuiltinCaller() {}
+
+ /**
+ * Call the built-in. This will be called in the UI thread with appropriate
+ * syncing between the threads.
+ *
+ * Derived classes might want to store the result of the call in a member
+ * variable in this class so it can later be queried.
+ *
+ * Derived classes are required to implement this method.
+ **/
+ virtual void call() = 0;
+};
+
+
+#endif // YBuiltinCaller_h
Added: trunk/core/libyui/src/YCPBuiltinCaller.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YCPBuiltinCaller.cc?rev=44301&view=auto
==============================================================================
--- trunk/core/libyui/src/YCPBuiltinCaller.cc (added)
+++ trunk/core/libyui/src/YCPBuiltinCaller.cc Fri Feb 8 16:55:33 2008
@@ -0,0 +1,32 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YCPBuiltinCaller.cc
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+
+#include "YCPBuiltinCaller.h"
+#include "Y2UINamespace.h"
+
+
+void
+YCPBuiltinCaller::call()
+{
+ if ( _function )
+ {
+ _result = _function->evaluateCall_int();
+ _function = 0; // make sure this function is only called once
+ }
+}
Added: trunk/core/libyui/src/YCPBuiltinCaller.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YCPBuiltinCaller.h?rev=44301&view=auto
==============================================================================
--- trunk/core/libyui/src/YCPBuiltinCaller.h (added)
+++ trunk/core/libyui/src/YCPBuiltinCaller.h Fri Feb 8 16:55:33 2008
@@ -0,0 +1,65 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YCPBuiltinCaller.h
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+#ifndef YCPBuiltinCaller_h
+#define YCPBuiltinCaller_h
+
+#include "YBuiltinCaller.h"
+#include "ycp/YCPValue.h"
+
+class Y2UIFunction;
+
+
+/**
+ * Helper class for transparently calling a built-in function, passing back and
+ * forth YCPValues.
+ **/
+class YCPBuiltinCaller: public YBuiltinCaller
+{
+public:
+ YCPBuiltinCaller()
+ : _function(0)
+ {}
+
+ virtual ~YCPBuiltinCaller() {}
+
+ /**
+ * Set the built-in function to be called.
+ **/
+ void setFunction( Y2UIFunction * function ) { _function = function; }
+
+ /**
+ * Call the built-in.
+ *
+ * Implemented from YBuiltinCaller.
+ **/
+ virtual void call();
+
+ /**
+ * Return the result of the last call.
+ **/
+ YCPValue result() const { return _result; }
+
+private:
+
+ Y2UIFunction * _function;
+ YCPValue _result;
+};
+
+
+#endif // YCPBuiltinCaller_h
Modified: trunk/core/libyui/src/YUI.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YUI.cc?rev=44301&r1=44300&r2=44301&view=diff
==============================================================================
--- trunk/core/libyui/src/YUI.cc (original)
+++ trunk/core/libyui/src/YUI.cc Fri Feb 8 16:55:33 2008
@@ -32,14 +32,13 @@
#define YUILogComponent "ui"
#include "YUILog.h"
-#include
-
#include "Y2UINamespace.h"
#include "YUI.h"
#include "YUISymbols.h"
#include "YDialog.h"
#include "YApplication.h"
#include "YMacro.h"
+#include "YBuiltinCaller.h"
@@ -51,6 +50,8 @@
YUI::YUI( bool withThreads )
: _withThreads( withThreads )
, _uiThread( 0 )
+ , _builtinCaller( 0 )
+ , _terminate_ui_thread( false )
, _eventsBlocked( false )
{
_yui = this;
@@ -69,6 +70,9 @@
if ( YDialog::openDialogsCount() > 0 )
yuiError() << YDialog::openDialogsCount() << " open dialogs left over" << endl;
+ if ( _builtinCaller )
+ delete _builtinCaller;
+
YDialog::deleteAllDialogs();
YMacro::deleteRecorder();
@@ -156,7 +160,7 @@
}
else
{
- terminate_ui_thread = false;
+ _terminate_ui_thread = false;
createUIThread();
}
}
@@ -183,7 +187,7 @@
void YUI::terminateUIThread()
{
- terminate_ui_thread = true;
+ _terminate_ui_thread = true;
signalUIThread();
waitForUIThread();
pthread_join( _uiThread, 0 );
@@ -286,14 +290,17 @@
if ( ! waitForYCPThread () )
continue;
- if ( terminate_ui_thread )
+ if ( _terminate_ui_thread )
{
signalYCPThread();
yuiDebug() << "Shutting down UI main loop" << endl;
return;
}
- _builtinCallData.result = _builtinCallData.function->evaluateCall_int();
+ if ( _builtinCaller )
+ _builtinCaller->call();
+ else
+ yuiError() << "No builtinCaller set" << endl;
signalYCPThread();
}
Modified: trunk/core/libyui/src/YUI.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YUI.h?rev=44301&r1=44300&r2=44301&view=diff
==============================================================================
--- trunk/core/libyui/src/YUI.h (original)
+++ trunk/core/libyui/src/YUI.h Fri Feb 8 16:55:33 2008
@@ -22,37 +22,20 @@
#include
#include <string>
-using std::string;
-
-#include
-
#include "YTypes.h"
#include "YWidgetOpt.h"
+using std::string;
class YApplication;
class YWidget;
class YWidgetFactory;
class YOptionalWidgetFactory;
class YEvent;
+class YBuiltinCaller;
class YDialog;
class YMacroPlayer;
class YMacroRecorder;
-class Y2UIFunction;
-class YUIBuiltinCallData;
-
-
-struct YUIBuiltinCallData
-{
- Y2UIFunction * function;
- YCPValue result;
-
- YUIBuiltinCallData()
- : result( YCPVoid() )
- {
- function = 0;
- }
-};
/**
@@ -60,14 +43,14 @@
**/
class YUI
{
+ friend class Y2UIFunction;
+
protected:
/**
* Constructor.
**/
YUI( bool withThreads );
- friend class Y2UIFunction;
-
public:
/**
@@ -199,6 +182,19 @@
void uiThreadMainLoop();
/**
+ * Return the transparent inter-thread communication.
+ * This will return 0 until set from the outside.
+ **/
+ YBuiltinCaller * builtinCaller() const { return _builtinCaller; }
+
+ /**
+ * Set the transparent inter-thread communication.
+ * Built-ins are only really called if there is a valid YBuiltinCaller set.
+ **/
+ void setBuiltinCaller( YBuiltinCaller * caller )
+ { _builtinCaller = caller; }
+
+ /**
* UI-specific runPkgSelection method.
*
* Derived classes are required to implement this.
@@ -294,7 +290,7 @@
* the result here and signals the YCP thread that waits until
* the result is available.
**/
- YUIBuiltinCallData _builtinCallData;
+ YBuiltinCaller * _builtinCaller;
/**
* Used to synchronize data transfer with the ui thread.
@@ -316,7 +312,7 @@
* thread replies by setting the flag back to false directly
* after terminating itself.
**/
- bool terminate_ui_thread;
+ bool _terminate_ui_thread;
/**
* Flag that keeps track of blocked events.
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org