Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members

init.cpp

00001 /**************
00002 FILE          : init.cpp
00003 ***************
00004 PROJECT       : SaX2 - library interface
00005               :
00006 AUTHOR        : Marcus Schäfer <ms@suse.de>
00007               :
00008 BELONGS TO    : SaX2 - SuSE advanced X11 configuration 
00009               : 
00010               :
00011 DESCRIPTION   : native C++ class library to access SaX2
00012               : functionality. Easy to use interface for
00013               : //.../
00014               : - importing/exporting X11 configurations
00015               : - modifying/creating X11 configurations 
00016               : ---
00017               :
00018               :
00019 STATUS        : Status: Development
00020 **************/
00021 #include <hd.h>
00022 #include "init.h"
00023 
00024 namespace SaX {
00025 //====================================
00026 // Constructor...
00027 //------------------------------------
00028 SaXInit::SaXInit ( QList<char> opt ) {
00029         // .../
00034         // ----
00035         mOptions.append ("--quiet");
00036         mOptions.append ("no");
00037         QListIterator<char> it (opt);
00038         for (; it.current(); ++it) {
00039                 mOptions.append ( it.current() );
00040         }
00041 }
00042 
00043 //====================================
00044 // Constructor...
00045 //------------------------------------
00046 SaXInit::SaXInit ( void ) {
00047         // .../
00051         // ----
00052         mOptions.append ("--quiet");
00053         mOptions.append ("no");
00054 }
00055 
00056 //====================================
00057 // needInit...
00058 //------------------------------------
00059 bool SaXInit::needInit (void) {
00060         // .../
00064         // ----
00065         if (! setLock()) {
00066                 return false;
00067         }
00068         QFileInfo info (CACHE_CONFIG);
00069         if (! info.exists()) {
00070                 unsetLock();
00071                 return true;
00072         }
00073         #if 0
00074         // .../
00075         // disabled libhd hardware flags check, this will be
00076         // changed in the future and needs adaption
00077         // ---
00078         if (needUpdate()) {
00079                 unsetLock();
00080                 return true;
00081         }
00082         #endif
00083         unsetLock();
00084         return false;
00085 }
00086 
00087 //====================================
00088 // ignoreProfile...
00089 //------------------------------------
00090 void SaXInit::ignoreProfile (void) {
00091         // .../
00095         // ----
00096         mOptions.append ("-i");
00097 }
00098 
00099 //====================================
00100 // doInit...
00101 //------------------------------------
00102 void SaXInit::doInit (void) {
00103         // .../
00106         // ----
00107         if (! havePrivileges()) {
00108                 excPermissionDenied();
00109                 qError (errorString(),EXC_PERMISSIONDENIED);
00110                 return;
00111         }
00112         if (setenv ("HW_UPDATE","1",1) != 0) {
00113                 excInvalidArgument ( errno );
00114                 qError (errorString(),EXC_INVALIDARGUMENT);
00115                 return;
00116         }
00117         SaXProcessCall* proc = new SaXProcessCall ();
00118         proc -> addArgument ( SAX_INIT );
00119         QListIterator<char> it (mOptions);
00120         for (; it.current(); ++it) {
00121                 proc -> addArgument ( it.current() );
00122         }
00123         if ( ! proc -> start() ) {
00124                 excProcessFailed();
00125                 qError (errorString(),EXC_PROCESSFAILED);
00126                 return;
00127         }
00128 }
00129 
00130 //====================================
00131 // needUpdate...
00132 //------------------------------------
00133 bool SaXInit::needUpdate (void) {
00134         // .../
00138         // ----
00139         if (! havePrivileges()) {
00140                 excPermissionDenied();
00141                 qError (errorString(),EXC_PERMISSIONDENIED);
00142                 return false;
00143         }
00144         return scanHDstatus();
00145 }
00146 
00147 //====================================
00148 // scanHDstatus...
00149 //------------------------------------
00150 bool SaXInit::scanHDstatus (bool save) {
00151         // .../
00155         // ----
00156         hd_t* hd;
00157         hd_data_t* hd_data;
00158         hd_status_t status;
00159         status.invalid    = 0;
00160         status.reconfig   = 0;
00161         status.configured = 0;
00162         status.available  = 0;
00163         status.needed     = 0;
00164         hd_hw_item_t scanItem[] = {
00165                 hw_display,
00166                 hw_monitor,
00167                 hw_mouse
00168         };
00169         bool needNewConfig = false;
00170         for (int item=0;item<3;item++) {
00171                 //===============================================
00172                 // scan for hardware identified by item and
00173                 // write it into the hardware database
00174                 //-----------------------------------------------
00175                 hd_data = (hd_data_t*)calloc (1,sizeof *hd_data);
00176                 hd_data -> flags.list_all = 1;
00177                 hd_data -> flags.fast = 1;
00178                 hd = hd_list (
00179                         hd_data, scanItem[item], 1, 0
00180                 );
00181                 for (hd_t* hd1 = hd; hd1; hd1 = hd1->next) {
00182                         int err = hd_write_config (hd_data, hd1);
00183                         if (err) {
00184                                 return false;
00185                         }
00186                 }
00187                 hd = hd_free_hd_list (hd);
00188                 //===============================================
00189                 // 1) search for new hardware and set it to
00190                 //    configured and available
00191                 //-----------------------------------------------
00192                 status.configured = status_new;
00193                 hd = hd_list_with_status (hd_data, scanItem[item], status);
00194                 if (hd) {
00195                         needNewConfig = true;
00196                         if (save) {
00197                         for (hd_t* hd1 = hd; hd1; hd1 = hd1->next) {
00198                                 saveHDstatus (1,"yes",hd1->unique_id);
00199                                 saveHDstatus (3,"yes",hd1->unique_id);
00200                         }
00201                         }
00202                 }
00203                 //===============================================
00204                 // 2) search for configured hardware which is not
00205                 //    available. This is a state which is not
00206                 //    possible and we will set the flag to "no"
00207                 //-----------------------------------------------
00208                 status.configured = status_yes;
00209                 status.available  = status_no;
00210                 hd = hd_list_with_status (hd_data, scanItem[item], status);
00211                 if (hd) {
00212                         needNewConfig = true;
00213                         if (save) {
00214                         for (hd_t* hd1 = hd; hd1; hd1 = hd1->next) {
00215                                 saveHDstatus (1,"no",hd1->unique_id);
00216                         }
00217                         }
00218                 }
00219                 //===============================================
00220                 // 3) search for unconfigured hardware which is
00221                 //    available. This hardware is tagged as
00222                 //    configured = "yes" using this program will
00223                 //    never lead to this case, so we will setup a
00224                 //    clean base if there is such a hardware found
00225                 //-----------------------------------------------
00226                 status.configured = status_no;
00227                 status.available  = status_yes;
00228                 hd = hd_list_with_status (hd_data, scanItem[item], status);
00229                 if (hd) {
00230                         needNewConfig = true;
00231                         if (save) {
00232                         for (hd_t* hd1 = hd; hd1; hd1 = hd1->next) {
00233                                 saveHDstatus (1,"yes",hd1->unique_id);
00234                                 saveHDstatus (3,"yes",hd1->unique_id);
00235                         }
00236                         }
00237                 }
00238                 //===============================================
00239                 // 4) search for hardware which is not configured
00240                 //    and not available and set the need flag to no.
00241                 //    This is needed to prevent hwscan from
00242                 //    starting YaST2 again
00243                 //-----------------------------------------------
00244                 status.configured = status_no;
00245                 status.available  = status_no;
00246                 hd = hd_list_with_status (hd_data, scanItem[item], status);
00247                 if (hd) {
00248                         if (save) {
00249                         for (hd_t* hd1 = hd; hd1; hd1 = hd1->next) {
00250                                 saveHDstatus (3,"no",hd1->unique_id);
00251                         }
00252                         }
00253                 }
00254                 hd = hd_free_hd_list (hd);
00255                 hd_free_hd_data (hd_data);
00256                 free (hd_data);
00257         }
00258         return needNewConfig;
00259 }
00260 
00261 //====================================
00262 // saveHDstatus...
00263 //------------------------------------
00264 bool SaXInit::saveHDstatus (int type, char* val, char* id) {
00265         // .../
00268         // ----
00269         hd_t* hd;
00270         hd_data_t* hd_data;
00271         hd_status_value_t status = (hd_status_value_t)0;
00272         hd_data = (hd_data_t*)calloc(1, sizeof *hd_data);
00273         hd = hd_read_config(hd_data, id);
00274         if (! hd) {
00275                 return false;
00276         }
00277         for (int i = 1; i < 8; i++) {
00278                 char* s = hd_status_value_name ((hd_status_value_t)i);
00279                 if (s && !strcmp(val, s)) {
00280                         status = (hd_status_value_t)i;
00281                         break;
00282                 }
00283         }
00284         if ( ! status ) {
00285                 return false;
00286         } else {
00287                 switch(type) {
00288                 case 1:
00289                         hd->status.configured = status;
00290                 break;
00291                 case 2:
00292                         hd->status.available = status;
00293                 break;
00294                 case 3:
00295                         hd->status.needed = status;
00296                 break;
00297                 }
00298                 hd_write_config (hd_data, hd);
00299         }
00300         hd = hd_free_hd_list (hd);
00301         hd_free_hd_data (hd_data);
00302         free (hd_data);
00303         return true;
00304 }
00305 } // end namespace

Generated on Wed Sep 14 10:27:01 2005 for libsax by  doxygen 1.4.4