Commit f22aaa84 authored by Manjaro Linux's avatar Manjaro Linux

Merge pull request #8 from manjaro/development

Merge Development into Master
parents 4ba524aa bdf698fa
*~
build
CMakeLists.txt.user
libmhwd/cmake_install.cmake
libmhwd/libmhwd.so
src/cmake_install.cmake
src/mhwd
cmake_install.cmake
CMakeCache.txt
CMakeFiles
Makefile
*.o
*settings
*project
bin/*
cmake_minimum_required (VERSION 2.6)
project(mhwd)
SET(CMAKE_INSTALL_PREFIX "/usr/")
set(EXECUTABLE_OUTPUT_PATH ${mhwd_SOURCE_DIR}/bin)
add_definitions(-Wall)
set(CMAKE_INSTALL_PREFIX "/usr/")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -Wall -Wextra -Werror")
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunreachable-code")
endif()
add_subdirectory(libmhwd)
add_subdirectory(mhwd)
add_subdirectory(src)
add_subdirectory(scripts)
include_directories(. vita)
include_directories(. vita ${mhwd_SOURCE_DIR}/src)
###
### mhwd library
###
set( LIB_HEADERS
mhwd.h
mhwd_p.h
const.h
vita/string.hpp
)
set( LIB_SOURCES
mhwd.cpp
vita/string.cpp
)
......@@ -26,6 +23,3 @@ target_link_libraries(mhwd ${LIB_LIBS})
INSTALL(TARGETS mhwd
LIBRARY DESTINATION lib
)
INSTALL(FILES mhwd.h
DESTINATION /usr/include)
This diff is collapsed.
/*
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MHWD_H
#define MHWD_H
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
namespace mhwd {
//#############//
//### Enums ###//
//#############//
enum TYPE { TYPE_PCI, TYPE_USB };
enum STATUS { STATUS_SUCCESS, STATUS_ERROR_CONFLICTS, STATUS_ERROR_REQUIREMENTS, STATUS_ERROR_NOT_INSTALLED, STATUS_ERROR_ALREADY_INSTALLED, STATUS_ERROR_NO_MATCH_LOCAL_CONFIG, STATUS_ERROR_SCRIPT_FAILED, STATUS_ERROR_SET_DATABASE };
enum MESSAGETYPE { MESSAGETYPE_CONSOLE_OUTPUT, MESSAGETYPE_INSTALLDEPENDENCY_START, MESSAGETYPE_INSTALLDEPENDENCY_END, MESSAGETYPE_INSTALL_START, MESSAGETYPE_INSTALL_END, MESSAGETYPE_REMOVE_START, MESSAGETYPE_REMOVE_END };
//####################//
//### Data Structs ###//
//####################//
struct Config {
struct HardwareIDs {
std::vector<std::string> classIDs, vendorIDs, deviceIDs;
std::vector<std::string> blacklistedClassIDs, blacklistedVendorIDs, blacklistedDeviceIDs;
};
TYPE type;
std::string basePath, configPath, name, info, version;
bool freedriver;
int priority;
std::vector<HardwareIDs> hwdIDs;
std::vector<std::string> conflicts, dependencies;
};
struct Device {
TYPE type;
std::string className, deviceName, vendorName, classID, deviceID, vendorID, sysfsBusID, sysfsID;
std::vector<mhwd::Config*> availableConfigs, installedConfigs;
};
struct Data {
struct Environment {
std::string PMCachePath, PMConfigPath, PMRootPath;
bool syncPackageManagerDatabase;
void (*messageFunc)(mhwd::MESSAGETYPE, std::string);
};
std::vector<mhwd::Device*> USBDevices, PCIDevices;
std::vector<mhwd::Config*> installedUSBConfigs, installedPCIConfigs, allUSBConfigs, allPCIConfigs, invalidConfigs;
Environment environment;
};
struct Transaction {
enum TYPE { TYPE_INSTALL, TYPE_REMOVE };
TYPE type;
bool allowReinstallation;
mhwd::Config* config;
std::vector<mhwd::Config*> dependencyConfigs, conflictedConfigs, requiredByConfigs;
};
//#################//
//### Functions ###//
//#################//
void initData(mhwd::Data *data);
void fillData(mhwd::Data *data);
void freeData(mhwd::Data *data);
std::string checkEnvironment();
void updateConfigData(mhwd::Data *data);
void updateInstalledConfigData(mhwd::Data *data);
bool fillConfig(mhwd::Config *config, std::string configPath, mhwd::TYPE type);
void printDeviceDetails(mhwd::TYPE type, FILE *f = stdout);
mhwd::Config* getInstalledConfig(mhwd::Data *data, const std::string configName, const TYPE configType);
mhwd::Config* getDatabaseConfig(mhwd::Data *data, const std::string configName, const TYPE configType);
mhwd::Config* getAvailableConfig(mhwd::Data *data, const std::string configName, const TYPE configType);
std::vector<mhwd::Config*> getAllDependenciesToInstall(mhwd::Data *data, mhwd::Config *config);
std::vector<mhwd::Config*> getAllLocalConflicts(mhwd::Data *data, mhwd::Config *config);
std::vector<mhwd::Config*> getAllLocalRequirements(mhwd::Data *data, mhwd::Config *config);
mhwd::Transaction createTransaction(mhwd::Data *data, mhwd::Config* config, mhwd::Transaction::TYPE type, bool allowReinstallation = false);
mhwd::STATUS performTransaction(mhwd::Data *data, mhwd::Transaction *transaction);
}
#else
namespace mhwd {
extern void initData(mhwd::Data *data);
extern void fillData(mhwd::Data *data);
extern void freeData(mhwd::Data *data);
extern std::string checkEnvironment();
extern void updateConfigData(mhwd::Data *data);
extern void updateInstalledConfigData(mhwd::Data *data);
extern void printDeviceDetails(mhwd::TYPE type, FILE *f = stdout);
extern mhwd::Config* getInstalledConfig(mhwd::Data *data, const std::string configName, const TYPE configType);
extern mhwd::Config* getDatabaseConfig(mhwd::Data *data, const std::string configName, const TYPE configType);
extern mhwd::Config* getAvailableConfig(mhwd::Data *data, const std::string configName, const TYPE configType);
extern std::vector<mhwd::Config*> getAllDependenciesToInstall(mhwd::Data *data, mhwd::Config *config);
extern std::vector<mhwd::Config*> getAllLocalConflicts(mhwd::Data *data, mhwd::Config *config);
extern std::vector<mhwd::Config*> getAllLocalRequirements(mhwd::Data *data, mhwd::Config *config);
extern mhwd::Transaction createTransaction(mhwd::Data *data, mhwd::Config* config, mhwd::Transaction::TYPE type, bool allowReinstallation = false);
extern mhwd::STATUS performTransaction(mhwd::Data *data, mhwd::Transaction *transaction);
}
#endif // MHWD_H
/*
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MHWD_P_H
#define MHWD_P_H
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <fstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#include <vector>
#include <string>
#include <hd.h>
#include "const.h"
#include "vita/string.hpp"
namespace mhwd {
//###############//
//### Devices ###//
//###############//
void fillDevices(mhwd::Data *data, mhwd::TYPE type);
Vita::string from_Hex(uint16_t hexnum, int fill);
int hexToInt(std::string hex);
Vita::string from_CharArray(char* c);
//###############//
//### Configs ###//
//###############//
void fillInstalledConfigs(mhwd::Data *data, mhwd::TYPE type);
void fillAllConfigs(mhwd::Data *data, mhwd::TYPE type);
void getAllDevicesOfConfig(mhwd::Data *data, mhwd::Config *config, std::vector<mhwd::Device*>* foundDevices);
void getAllDevicesOfConfig(std::vector<mhwd::Device*>* devices, mhwd::Config *config, std::vector<mhwd::Device*>* foundDevices);
void setMatchingConfigs(std::vector<mhwd::Device*>* devices, std::vector<mhwd::Config*>* configs, bool setAsInstalled);
void setMatchingConfig(mhwd::Config* config, std::vector<mhwd::Device*>* devices, bool setAsInstalled);
void addConfigSorted(std::vector<mhwd::Config*>* configs, mhwd::Config* config);
bool readConfigFile(mhwd::Config *config, std::string configPath);
std::vector<std::string> splitValue(Vita::string str, Vita::string onlyEnding = "");
Vita::string getRightConfigPath(Vita::string str, Vita::string baseConfigPath);
void _getAllDependenciesToInstall(mhwd::Data *data, mhwd::Config *config, std::vector<mhwd::Config*>* installedConfigs, std::vector<mhwd::Config*> *depends);
//#####################################//
//### Directory and File Operations ###//
//#####################################//
std::vector<std::string> getRecursiveDirectoryFileList(const std::string directoryPath, std::string onlyFilename = "");
bool copyDirectory(const std::string source, const std::string destination);
bool copyFile(const std::string source, const std::string destination, const mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH);
bool removeDirectory(const std::string directory);
bool checkExist(const std::string path);
bool createDir(const std::string path, const mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH | S_IXGRP | S_IXOTH);
//###########################//
//### Script & Operations ###//
//###########################//
void emitMessageFunc(mhwd::Data *data, mhwd::MESSAGETYPE type, std::string str);
mhwd::STATUS installConfig(mhwd::Data *data, mhwd::Config *config);
mhwd::STATUS uninstallConfig(mhwd::Data *data, mhwd::Config *config);
bool runScript(mhwd::Data *data, mhwd::Config *config, mhwd::Transaction::TYPE operationType);
}
#endif // MHWD_P_H
......@@ -12,89 +12,89 @@
namespace Vita {
string string::toLower() const {
string result;
for (size_t i = 0; i < this->length(); i++) {
result += tolower((*this)[i]);
}
return result;
}
string string::toUpper() const {
string result;
for (size_t i = 0; i < this->length(); i++) {
result += toupper((*this)[i]);
}
return result;
}
string string::ucfirst() const {
string result = *this;
result[0] = toupper(result[0]);
return result;
}
string string::lcfirst() const {
string result = *this;
result[0] = tolower(result[0]);
return result;
}
string string::operator+(int operand) const {
return (*this) + string::toStr<int>(operand);
}
string string::operator+(long int operand) const {
return (*this) + string::toStr<long int>(operand);
}
string string::operator+(double operand) const {
return (*this) + string::toStr<double>(operand);
}
string string::operator+(float operand) const {
return (*this) + string::toStr<float>(operand);
}
string string::replace(const string& search, const string& replace, size_t limit) const {
string result;
size_t previous = 0, current;
current = this->find(search);
while (current != npos && limit) {
result += this->substr(previous, current - previous);
result += replace;
previous = current + search.length();
current = this->find(search, previous);
limit--;
}
result += this->substr(previous);
return result;
}
std::vector<string> string::explode(const string& delimiter) const {
std::vector<string> result;
size_t previous = 0, current;
current = this->find(delimiter);
while (current != npos) {
result.push_back(this->substr(previous, current - previous));
previous = current + delimiter.length();
current = this->find(delimiter, previous);
}
result.push_back(this->substr(previous));
return result;
}
string string::trim(const string& what) const {
string result = *this;
size_t pos = result.find_first_not_of(what);
result.erase(0, pos);
pos = result.find_last_not_of(what);
result.erase(pos + 1);
return result;
}
string string::toLower() const {
string result;
for (size_t i = 0; i < this->length(); i++) {
result += tolower((*this)[i]);
}
return result;
}
string string::toUpper() const {
string result;
for (size_t i = 0; i < this->length(); i++) {
result += toupper((*this)[i]);
}
return result;
}
string string::ucfirst() const {
string result = *this;
result[0] = toupper(result[0]);
return result;
}
string string::lcfirst() const {
string result = *this;
result[0] = tolower(result[0]);
return result;
}
string string::operator+(int operand) const {
return (*this) + string::toStr<int>(operand);
}
string string::operator+(long int operand) const {
return (*this) + string::toStr<long int>(operand);
}
string string::operator+(double operand) const {
return (*this) + string::toStr<double>(operand);
}
string string::operator+(float operand) const {
return (*this) + string::toStr<float>(operand);
}
string string::replace(const string& search, const string& replace, size_t limit) const {
string result;
size_t previous = 0, current;
current = this->find(search);
while (current != npos && limit) {
result += this->substr(previous, current - previous);
result += replace;
previous = current + search.length();
current = this->find(search, previous);
--limit;
}
result += this->substr(previous);
return result;
}
std::vector<string> string::explode(const string& delimiter) const {
std::vector<string> result;
size_t previous = 0, current;
current = this->find(delimiter);
while (current != npos) {
result.push_back(this->substr(previous, current - previous));
previous = current + delimiter.length();
current = this->find(delimiter, previous);
}
result.push_back(this->substr(previous));
return result;
}
string string::trim(const string& what) const {
string result = *this;
size_t pos = result.find_first_not_of(what);
result.erase(0, pos);
pos = result.find_last_not_of(what);
result.erase(pos + 1);
return result;
}
} // namespace Vita
......@@ -11,164 +11,164 @@
#ifndef INC_VITA_STRING_HPP
#define INC_VITA_STRING_HPP
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
namespace Vita {
/**
* Slightly enhanced version of std::string.
*/
class string : public std::string {
public:
/**
* Directly call <tt>std::string::string()</tt>.
*/
explicit string():std::string() {};
/**
* Directly call <tt>std::string::string(const char*)</tt>.
*/
string(const char* cstr):std::string(cstr) {};
/**
* Directly call <tt>std::string::string(const char*, size_t)</tt>.
*/
string(const char* cstr, size_t n):std::string(cstr, n) {};
/**
* Directly call <tt>std::string::string(const std::string&)</tt>.
*/
string(const std::string& str):std::string(str) {};
/**
* Directly call <tt>std::string::string(const std::string&, size_t, size_t)</tt>.
*/
string(const std::string& str, size_t pos, size_t n = npos):std::string(str, pos, n) {};
/**
* Directly call <tt>std::string::string(size_t, char)</tt>.
*/
string(size_t n, char c):std::string(n, c) {};
/**
* Convert all characters to lower case.
*/
string toLower() const;
/**
* Convert all characters to upper case.
*/
string toUpper() const;
/**
* Make the first character uppercase.
*/
string ucfirst() const;
/**
* Make the first character lowercase.
*/
string lcfirst() const;
/**
* Convert the operand to string and append it.
*
* This overrides the behavior of std::string.
*
* @param operand The number to be appended.
* @return The string with @a operand appended.
*/
string operator+(int operand) const;
/**
* Convert the operand to string and append it.
*
* This overrides the behavior of std::string.
*
* @param operand The number to be appended.
* @return The string with @a operand appended.
*/
string operator+(long int operand) const;
/**
* Convert the operand to string and append it.
*
* This overrides the behavior of std::string.
*
* @param operand The number to be appended.
* @return The string with @a operand appended.
*/
string operator+(double operand) const;
/**
* Convert the operand to string and append it.
*
* This overrides the behavior of std::string.
*
* @param operand The number to be appended.
* @return The string with @a operand appended.
*/
string operator+(float operand) const;
/**
* Replace all occurences of a certain substring in the string.
*
* @param search The substring that will be replaced.
* @param replace The replacement.
* @param limit How many replacements should be done. Set to Vita::string::npos to disable the limit.
* @return String with the replacement(s) in place.
*/
string replace(const string& search, const string& replace, size_t limit = npos) const;
/**
* Split the string by another string.
*
* This method is similar to the <tt>explode</tt> function known from PHP.
*
* @param delimiter The boundary string.
* @return A vector of strings, each of which is a substring of the original.
*/
std::vector<string> explode(const string& delimiter) const;
/**
* Trim unwanted characters from the beginning and the end of the string.
*
* @param what The characters to trim. Defaults to whitespace (ASCII #9, #10, #13, #32).
* @return The trimmed string.
*/
string trim(const string& what = "\x9\xa\xd\x20") const;
/**
* Convert a generic data type to string.
*
* The conversion is done via std::ostringstream.
*
* @param source The value to convert.
* @return string
*/
template<class T> static string toStr(const T& source) {
std::ostringstream stream;
stream << source;
return string(stream.str());
}
/**
* Convert the string to a generic data type.
*
* The conversion is done via std::istringstream.
*
* @return The converted string.
*/
template<class T> T convert() const {
std::istringstream stream(*this);
T result;
stream >> result;
return result;
}
};