26 #define VERBOSE_COMM 0 // VERY verbose thread communication logging 38 #define YUILogComponent "ui" 42 #include "YUILoader.h" 43 #include "YUISymbols.h" 45 #include "YApplication.h" 47 #include "YButtonBox.h" 49 #include "YBuiltinCaller.h" 55 #define ENV_BUTTON_ORDER "Y2_BUTTON_ORDER" 64 static bool uiDeleted =
false;
66 extern void * start_ui_thread(
void * yui );
70 : _withThreads( withThreads )
73 , _terminate_ui_thread( false )
74 , _eventsBlocked( false )
76 yuiMilestone() <<
"This is libyui " << VERSION << std::endl;
77 yuiMilestone() <<
"Creating UI " << ( withThreads ?
"with" :
"without" ) <<
" threads" << endl;
88 yuiError() <<
"shutdownThreads() was never called!" << endl;
89 yuiError() <<
"shutting down now - this might segfault" << endl;
135 YUI_CHECK_PTR( factory );
150 YUI_CHECK_PTR( factory );
165 YUI_CHECK_PTR( app );
204 if ( fcntl(
pipe_to_ui[0], F_SETFL, arg | O_NONBLOCK ) < 0 )
206 yuiError() <<
"Couldn't set O_NONBLOCK: errno: " << errno <<
" " << strerror( errno ) << endl;
216 yuiDebug() <<
"Inter-thread communication pipes set up" << endl;
224 yuiError() <<
"pipe() failed: errno: " << errno <<
" " << strerror( errno ) << endl;
230 yuiMilestone() <<
"Running without threads" << endl;
238 pthread_attr_init( & attr );
239 int ret = pthread_create( &
_uiThread, & attr, start_ui_thread,
this );
242 yuiError() <<
"pthread_create() failed: " << errno <<
" " << strerror( errno ) << endl;
248 yuiDebug() <<
"Sending shutdown message to UI thread" << endl;
255 yuiDebug() <<
"UI thread shut down correctly" << endl;
275 static char arbitrary = 42;
276 if ( write (
pipe_to_ui[1], & arbitrary, 1 ) == -1 )
277 yuiError() <<
"Writing byte to UI thread failed" << endl;
280 yuiDebug() <<
"Wrote byte to UI thread" << endl;
292 yuiDebug() <<
"Waiting for ui thread..." << endl;
297 if ( errno == EINTR || errno == EAGAIN )
300 yuiError() <<
"waitForUIThread: errno: " << errno <<
" " << strerror( errno ) << endl;
302 }
while ( result == 0 );
305 yuiDebug() <<
"Read byte from ui thread" << endl;
315 static char arbitrary;
317 yuiError() <<
"Writing byte to YCP thread failed" << endl;
320 yuiDebug() <<
"Wrote byte to YCP thread" << endl;
332 yuiDebug() <<
"Waiting for YCP thread..." << endl;
334 result = read(
pipe_to_ui[0], & arbitrary, 1 );
337 if ( errno == EINTR || errno == EAGAIN )
340 yuiError() <<
"waitForYCPThread: errno: " << errno <<
" " << strerror( errno ) << endl;
342 }
while ( result == 0 );
345 yuiDebug() <<
"Read byte from YCP thread" << endl;
372 yuiDebug() <<
"Shutting down UI main loop" << endl;
379 yuiError() <<
"No builtinCaller set" << endl;
389 YButtonOrder oldButtonOrder = buttonOrder;
397 YEnvVar env(
"DESKTOP_SESSION" );
398 yuiDebug() << env << endl;
403 buttonOrder = YKDEButtonOrder;
406 else if ( env ==
"gnome" )
408 buttonOrder = YGnomeButtonOrder;
416 env =
YEnvVar(
"WINDOWMANAGER" );
417 yuiDebug() << env << endl;
421 buttonOrder = YGnomeButtonOrder;
426 buttonOrder = YKDEButtonOrder;
435 env =
YEnvVar( ENV_BUTTON_ORDER );
436 yuiDebug() << env << endl;
438 if ( env ==
"gnome" )
440 buttonOrder = YGnomeButtonOrder;
443 else if ( env ==
"kde" )
445 buttonOrder = YKDEButtonOrder;
448 else if ( ! env.
value().empty() )
450 yuiWarning() <<
"Ignoring unknown value of " << env << endl;
454 if ( buttonOrder != oldButtonOrder )
456 std::string buttonOrderStr;
458 switch ( buttonOrder )
460 case YKDEButtonOrder:
461 buttonOrderStr =
"KDE";
465 case YGnomeButtonOrder:
466 buttonOrderStr =
"GNOME";
473 yuiMilestone() <<
"Switching to " << buttonOrderStr
474 <<
" button order because of " << lastEnv
484 void * start_ui_thread(
void * yui )
489 yuiDebug() <<
"Starting UI thread" << endl;
int pipe_from_ui[2]
Used to synchronize data transfer with the ui thread.
void setButtonOrderFromEnvironment()
Set the button order (in YButtonBox widgets) from environment variables:
static YWidgetFactory * widgetFactory()
Return the widget factory that provides all the createXY() methods for standard (mandatory, i.e.
Abstract base class of a libYUI user interface.
void createUIThread()
Creates and launches the ui thread.
virtual YApplication * createApplication()=0
Create the YApplication object that provides global methods.
void topmostConstructorHasFinished()
Must be called after the constructor of the Qt/NCurses ui is ready.
int pipe_to_ui[2]
Used to synchronize data transfer with the ui thread.
void terminateUIThread()
Tells the ui thread that it should terminate and waits until it does so.
static void deletePlayer()
Delete the current macro player if there is one.
bool _withThreads
true if a seperate UI thread is created
std::string value() const
Return the value of the environment variable.
void signalUIThread()
Signals the ui thread by sending one byte through the pipe to it.
static void ensureUICreated()
Make sure there is a UI (with a UI plug-in) created.
virtual YOptionalWidgetFactory * createOptionalWidgetFactory()=0
Create the widget factory that provides all the createXY() methods for optional ("special") widgets a...
virtual void uiThreadDestructor()
Destructor for the UI thread.
void shutdownThreads()
Shut down multithreading.
bool waitForYCPThread()
Waits for the ycp thread to send one byte through the pipe to the ycp thread and reads this byte from...
void uiThreadMainLoop()
This method implements the UI thread in case it is existing.
static void deleteAllDialogs()
Delete all open dialogs.
Helper class to represent an environment variable and its value.
Class for application-wide values and functions.
static YOptionalWidgetFactory * optionalWidgetFactory()
Return the widget factory that provides all the createXY() methods for optional ("special") widgets a...
bool contains(const std::string &str, bool caseSensitive=false) const
Return 'true' if the environment variable is set and the value contains 'str'.
virtual void call()=0
Call the built-in.
static int openDialogsCount()
Returns the number of currently open dialogs (from 1 on), i.e., the depth of the dialog stack...
bool waitForUIThread()
Waits for the ui thread to send one byte through the pipe to the ycp thread and reads this byte from ...
void signalYCPThread()
Signals the ycp thread by sending one byte through the pipe to it.
virtual ~YUI()
Destructor.
static YApplication * app()
Return the global YApplication object.
virtual YWidgetFactory * createWidgetFactory()=0
Create the widget factory that provides all the createXY() methods for standard (mandatory, i.e.
bool _terminate_ui_thread
This is a flag that signals the ui thread that it should terminate.
YUI(bool withThreads)
Constructor.
pthread_t _uiThread
Handle to the ui thread.
static YUI * ui()
Access the global UI.
Base class for UI Exceptions.
virtual void idleLoop(int fd_ycp)=0
This virtual method is called when threads are activated in case the execution control is currently o...
static void loadUI(bool withThreads=false)
Load any of the available UI-plugins by this order and criteria:
static void deleteRecorder()
Delete the current macro recorder if there is one.
static std::stack< YDialog * > _dialogStack
Stack holding all currently existing dialogs.
YBuiltinCaller * _builtinCaller
Inter-thread communication between the YCP thread and the UI thread: The YCP thread supplies data her...