libyui  3.12.1
YUILoader.h
1 /*
2  Copyright (C) 2000-2017 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YUILoader.h
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YUILoader_h
27 #define YUILoader_h
28 
29 
30 #include <string>
31 
32 #include "YUI.h"
33 #include "YExternalWidgets.h"
34 
35 
36 
37 #define YUIPlugin_Qt "qt"
38 #define YUIPlugin_NCurses "ncurses"
39 #define YUIPlugin_Gtk "gtk"
40 
41 #define YUIPlugin_RestAPI "rest-api"
42 #define YUIPlugin_Ncurses_RestAPI "ncurses-rest-api"
43 #define YUIPlugin_Qt_RestAPI "qt-rest-api"
44 
45 /**
46  * Class to load one of the concrete UI plug-ins: Qt, NCurses, Gtk;
47  * or one of the corresponding REST APIs used for automated testing.
48  **/
49 class YUILoader
50 {
51 public:
52  /**
53  * Load any of the available UI-plugins by this order and criteria:
54  *
55  * - Qt:
56  * - if $DISPLAY is set
57  * - NCurses is user-selected and stdout is *not* a TTY
58  *
59  * - Gtk:
60  * - if $DISPLAY is set and Qt is not available,
61  * - a GTK-based desktop environment is detected
62  * from the environment variable XDG_CURRENT_DESKTOP
63  * - any of the above pre-conditions are met and
64  * NCurses is user-selected, but stdout is *not* a TTY
65  *
66  * - NCurses:
67  * - if $DISPLAY is *not* set and stdout is a TTY
68  * - Qt and Gtk are not available and stdout is a TTY
69  *
70  * This can be overridden by either:
71  *
72  * - specifing one of the switches on the
73  * command-line of the program
74  * - '--gtk',
75  * - '--ncurses', or
76  * - '--qt'
77  *
78  * - setting the environment variable
79  * YUI_PREFERED_BACKEND to one of
80  * - 'gtk',
81  * - 'ncurses', or
82  * - 'qt'
83  *
84  * If a command-line switch is given to the program, the
85  * setting from the environment variable will be overridden
86  * by the UI-plugin chosen with the switch.
87  *
88  * If the user-selected UI-plugin is not installed on the
89  * system, an installed UI-plugin will be chosen by the
90  * above criteria.
91  **/
92  static void loadUI( bool withThreads = false );
93 
94  /**
95  * This will make sure the UI singleton is deleted.
96  * If the UI is already destroyed, it will do nothing. If
97  * there still is a UI object, it will be deleted.
98  *
99  * This is particularly important for the NCurses UI so that
100  * the terminal settings are properly restored.
101  **/
102  static void deleteUI();
103 
104  /**
105  * Method handles loading integration test framework and load underlying GUI
106  * using hints from loadUI.
107  **/
108  static void loadRestAPIPlugin( const std::string & wantedGUI, bool withThreads = false );
109 
110  /**
111  * Load a UI plug-in. 'name' is one of the YUIPlugin_ -defines above.
112  *
113  * This might throw exceptions.
114  **/
115  static void loadPlugin( const std::string & name, bool withThreads = false );
116 
117  /**
118  * Check if a plug-in exists.
119  **/
120  static bool pluginExists( const std::string & pluginBaseName );
121 
122  /**
123  * Load the given External Widgets plugin followed by its graphical extension implementation
124  * in the following order in the same way as loadUI:
125  * - Qt, Gtk or NCurses
126  *
127  * 'name' is the user defined plugin name, graphical extension implementations have to
128  * be called 'name'-qt, 'name'-gtk and 'name'-ncurses. Following this rule plugin
129  * file names are as libyui-XX-YY.so.VER where:
130  * XX is the user defined name
131  * YY is the UI used (ncurses, gtk, qt)
132  * VER is the libyui so version
133  * 'symbol' is the function symbol to be loaded, e.g. YExternalWidgets* 'symbol'(void)
134  * (e.g. default YExternalWidgets* createExternalWidgets(const char *)
135  * see createEWFunction_t definition)
136  **/
137  static void loadExternalWidgets( const std::string & name,
138  const std::string & symbol = "_Z21createExternalWidgetsPKc" );
139 
140 private:
141  YUILoader() {}
142  ~YUILoader() {}
143 
144  /**
145  * Used by loadExternalWidgets to load the graphical plugin specialization.
146  *
147  * 'name' is the original plugin name (e.g. the one passed to loadExternalWidgets)
148  * 'plugin_name' is the graphical plugin specialization name (e.g. 'name'-[gtk|ncurses|qt])
149  * 'symbol' is the function symbol to be loaded and executed (e.g. the one passed loadExternalWidgets)
150  *
151  * This might throw exceptions:
152  * YUIPluginException if the plugin has not been loaded
153  * specific exception can be thrown by funtion invoked (param symbol)
154  **/
155  static void loadExternalWidgetsPlugin( const std::string & name,
156  const std::string & plugin_name,
157  const std::string & symbol );
158 };
159 
160 
161 /**
162  * Every UI plug-in has to provide a function
163  *
164  * YUI * createUI( bool withThreads )
165  *
166  * that creates a UI of that specific type upon the first call and returns that
167  * singleton for all subsequent calls.
168  **/
169 typedef YUI * (*createUIFunction_t)( bool );
170 
171 /**
172  * Every WE extension plug-in has to provide a function
173  *
174  * YExternalWidgets * createWE( )
175  *
176  * that creates a WE of that specific type upon the first call and returns that
177  * singleton for all subsequent calls.
178  **/
179 typedef YExternalWidgets * (*createEWFunction_t)( const char * );
180 
181 /**
182  * For integration testing, YUI has separate framework which allows to have
183  * control over UI using REST API. The server has to be started after testing
184  * if the framework plugin is loaded, which is done by the method which creates
185  * the server instance. To avoid having to include additional type, we define
186  * it as 'void' here.
187  **/
188 typedef void (*getServerFunction_t)();
189 
190 
191 #endif // YUILoader_h
YUI
Abstract base class of a libYUI user interface.
Definition: YUI.h:49
YUILoader::loadUI
static void loadUI(bool withThreads=false)
Load any of the available UI-plugins by this order and criteria:
Definition: YUILoader.cc:51
YUILoader::loadRestAPIPlugin
static void loadRestAPIPlugin(const std::string &wantedGUI, bool withThreads=false)
Method handles loading integration test framework and load underlying GUI using hints from loadUI.
Definition: YUILoader.cc:180
YUILoader
Class to load one of the concrete UI plug-ins: Qt, NCurses, Gtk; or one of the corresponding REST API...
Definition: YUILoader.h:50
YUILoader::loadPlugin
static void loadPlugin(const std::string &name, bool withThreads=false)
Load a UI plug-in.
Definition: YUILoader.cc:241
YUILoader::pluginExists
static bool pluginExists(const std::string &pluginBaseName)
Check if a plug-in exists.
Definition: YUILoader.cc:323
YExternalWidgets
Abstract base class of a libYUI Widget Extension interface.
Definition: YExternalWidgets.h:30
YUILoader::deleteUI
static void deleteUI()
This will make sure the UI singleton is deleted.
Definition: YUILoader.cc:230
YUILoader::loadExternalWidgets
static void loadExternalWidgets(const std::string &name, const std::string &symbol="_Z21createExternalWidgetsPKc")
Load the given External Widgets plugin followed by its graphical extension implementation in the foll...
Definition: YUILoader.cc:295