|
libsax 7.2
|
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 "init.h" 00022 00023 namespace SaX { 00024 //==================================== 00025 // Constructor... 00026 //------------------------------------ 00027 SaXInit::SaXInit ( QList<const char*> opt ) { 00028 // .../ 00033 // ---- 00034 mOptions.append ((const char*)"--quiet"); 00035 mOptions.append ((const char*)"no"); 00036 const char* it; 00037 foreach (it,opt) { 00038 mOptions.append ( it ); 00039 } 00040 } 00041 00042 //==================================== 00043 // Constructor... 00044 //------------------------------------ 00045 SaXInit::SaXInit ( void ) { 00046 // .../ 00050 // ---- 00051 mOptions.append ((const char*)"--quiet"); 00052 mOptions.append ((const char*)"no"); 00053 } 00054 00055 //==================================== 00056 // needInit... 00057 //------------------------------------ 00058 bool SaXInit::needInit (void) { 00059 // .../ 00063 // ---- 00064 if (! setLock()) { 00065 return false; 00066 } 00067 QFileInfo info (CACHE_CONFIG); 00068 if (! info.exists()) { 00069 unsetLock(); 00070 return true; 00071 } 00072 unsetLock(); 00073 return false; 00074 } 00075 00076 //==================================== 00077 // ignoreProfile... 00078 //------------------------------------ 00079 void SaXInit::ignoreProfile (void) { 00080 // .../ 00084 // ---- 00085 mOptions.append ((const char*)"-i"); 00086 } 00087 00088 //==================================== 00089 // setValidBusID... 00090 //------------------------------------ 00091 void SaXInit::setValidBusID (void) { 00092 // .../ 00096 // ---- 00097 SaXProcessCall* proc = new SaXProcessCall (); 00098 QString sysp = "/usr/sbin/sysp -c | wc -l"; 00099 proc -> addArgument ( GET_BASH ); 00100 proc -> addArgument ( "-c" ); 00101 proc -> addArgument ( sysp.ascii() ); 00102 if ( ! proc -> start() ) { 00103 excProcessFailed(); 00104 qError (errorString(),EXC_PROCESSFAILED); 00105 return; 00106 } 00107 QString optc; 00108 QString data = proc->readStdout().at(0); 00109 int count = data.toInt(); 00110 if (count < 2) { 00111 mOptions.append ((const char*)"-b"); 00112 mOptions.append ((const char*)"nobus"); 00113 } 00114 } 00115 00116 //==================================== 00117 // setPrimaryChip... 00118 //------------------------------------ 00119 void SaXInit::setPrimaryChip (void) { 00120 // .../ 00125 // ---- 00126 SaXProcessCall* proc = new SaXProcessCall (); 00127 proc -> addArgument ( GET_PRIMARY ); 00128 if ( ! proc -> start() ) { 00129 excProcessFailed(); 00130 qError (errorString(),EXC_PROCESSFAILED); 00131 return; 00132 } 00133 QString* optc = new QString; 00134 QString data = proc->readStdout().at(0); 00135 int id = data.toInt(); 00136 QTextOStream (optc) << id; 00137 mOptions.append ((const char*)"-c"); 00138 mOptions.append ((const char*)optc->ascii()); 00139 setValidBusID(); 00140 } 00141 00142 //==================================== 00143 // doInit... 00144 //------------------------------------ 00145 void SaXInit::doInit (void) { 00146 // .../ 00149 // ---- 00150 if (! havePrivileges()) { 00151 excPermissionDenied(); 00152 qError (errorString(),EXC_PERMISSIONDENIED); 00153 return; 00154 } 00155 if (setenv ("HW_UPDATE","1",1) != 0) { 00156 excInvalidArgument ( errno ); 00157 qError (errorString(),EXC_INVALIDARGUMENT); 00158 return; 00159 } 00160 SaXProcessCall* proc = new SaXProcessCall (); 00161 proc -> addArgument ( SAX_INIT ); 00162 const char* it; 00163 foreach (it,mOptions) { 00164 proc -> addArgument ( it ); 00165 } 00166 if ( ! proc -> start() ) { 00167 excProcessFailed(); 00168 qError (errorString(),EXC_PROCESSFAILED); 00169 return; 00170 } 00171 } 00172 } // end namespace
1.7.3