pmt: fix some minor typo issues and including problems etc. (more)
This commit is contained in:
3
.vscode/c_cpp_properties.json
vendored
3
.vscode/c_cpp_properties.json
vendored
@@ -4,7 +4,8 @@
|
|||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/srclib/libhelper/include",
|
"${workspaceFolder}/srclib/libhelper/include",
|
||||||
"${workspaceFolder}/srclib/libpartition_map/include",
|
"${workspaceFolder}/srclib/libpartition_map/include",
|
||||||
"${workspaceFolder}/include"
|
"${workspaceFolder}/include",
|
||||||
|
"${workspaceFolder}/src/functions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -29,36 +29,41 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
#include <libhelper/lib.hpp>
|
#include <libhelper/lib.hpp>
|
||||||
#include <libpartition_map/lib.hpp>
|
#include <libpartition_map/lib.hpp>
|
||||||
|
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignore "-Wdeprecated-declarations"
|
||||||
|
#include <CLI/CLI11.hpp>
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
#define PMT "libpmt"
|
#define PMT "libpmt"
|
||||||
#define PMTE "pmt"
|
#define PMTE "pmt"
|
||||||
#define PMTF "libpmt-function-manager"
|
#define PMTF "libpmt-function-manager"
|
||||||
|
|
||||||
#ifdef NEED_BASIC_FUNCTION_CLASSES
|
|
||||||
#include <memory>
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignore "-Wdeprecated-declarations"
|
|
||||||
#include <CLI/CLI11.hpp>
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif // #ifdef NEED_BASIC_FUNCTION_CLASSES
|
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
|
|
||||||
class basic_function {
|
|
||||||
/**
|
/**
|
||||||
* Example variables for writing your function:
|
* basic_function
|
||||||
* public:
|
* --------------
|
||||||
* CLI::App cmd* = nullptr;
|
* All function classes must inherit from this class.
|
||||||
*/
|
*/
|
||||||
|
class basic_function {
|
||||||
public:
|
public:
|
||||||
|
CLI::App* cmd = nullptr;
|
||||||
|
|
||||||
virtual bool init(CLI::App& _app) = 0;
|
virtual bool init(CLI::App& _app) = 0;
|
||||||
virtual bool run() = 0;
|
virtual bool run() = 0;
|
||||||
virtual const char* name() = 0;
|
virtual const char* name() = 0;
|
||||||
virtual ~basic_function() = default;
|
virtual ~basic_function() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* basic_function_manager
|
||||||
|
* ----------------------
|
||||||
|
* A class for function management.
|
||||||
|
*/
|
||||||
class basic_function_manager {
|
class basic_function_manager {
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<basic_function>> _functions;
|
std::vector<std::unique_ptr<basic_function>> _functions;
|
||||||
@@ -93,7 +98,7 @@ VariableTable* Variables;
|
|||||||
int Main(int argc, char** argv);
|
int Main(int argc, char** argv);
|
||||||
|
|
||||||
std::string getLibVersion();
|
std::string getLibVersion();
|
||||||
std::string getAppVersion(); // Not Android app version (an Android app is planned!), tells pmt and libs versions.
|
std::string getAppVersion(); // Not Android app version (an Android app is planned!), tells pmt version.
|
||||||
|
|
||||||
} // namespace PartitionManager
|
} // namespace PartitionManager
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <libpmt/lib.hpp>
|
#include <PartitionManager/lib.hpp>
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
|
|
||||||
|
|||||||
41
src/Lib.cpp
41
src/Lib.cpp
@@ -17,17 +17,18 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <libpmt/lib.hpp>
|
#include <PartitionManager/lib.hpp>
|
||||||
|
#include <generated/buildInfo.hpp>
|
||||||
#include "functions/functions.hpp"
|
#include "functions/functions.hpp"
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
|
|
||||||
VariableTable::VariableTable() : PartMap(),
|
basic_variables::basic_variables() : PartMap(),
|
||||||
searchPath(""),
|
searchPath(""),
|
||||||
onLogical(false),
|
onLogical(false),
|
||||||
silentProcess(false),
|
silentProcess(false),
|
||||||
verboseMode(false),
|
verboseMode(false),
|
||||||
viewVersion(false)
|
viewVersion(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
VariableTable* Variables = new VariableTable();
|
VariableTable* Variables = new VariableTable();
|
||||||
@@ -44,10 +45,10 @@ try { // try-catch start
|
|||||||
AppMain.add_flag("-V,--verbose", Variables->verboseMode, "Detailed information is written on the screen while the transaction is being carried out");
|
AppMain.add_flag("-V,--verbose", Variables->verboseMode, "Detailed information is written on the screen while the transaction is being carried out");
|
||||||
AppMain.add_flag("-v,--version", Variables->viewVersion, "Print version and exit");
|
AppMain.add_flag("-v,--version", Variables->viewVersion, "Print version and exit");
|
||||||
|
|
||||||
FuncManager.registerFunction(std::make_unique<backupFunction>, AppMain);
|
FuncManager.registerFunction(std::make_unique<backupFunction>(), AppMain);
|
||||||
FuncManager.registerFunction(std::make_unique<flashFunction>, AppMain);
|
FuncManager.registerFunction(std::make_unique<flashFunction>(), AppMain);
|
||||||
FuncManager.registerFunction(std::make_unique<eraseFunction>, AppMain);
|
FuncManager.registerFunction(std::make_unique<eraseFunction>(), AppMain);
|
||||||
FuncManager.registerFunction(std::make_unique<partitionSizeFunction>, AppMain);
|
FuncManager.registerFunction(std::make_unique<partitionSizeFunction>(), AppMain);
|
||||||
|
|
||||||
CLI11_PARSE(AppMain, argc, argv);
|
CLI11_PARSE(AppMain, argc, argv);
|
||||||
|
|
||||||
@@ -56,7 +57,7 @@ try { // try-catch start
|
|||||||
LOGN(PMTE, INFO) << "used command: " << used << std::endl;
|
LOGN(PMTE, INFO) << "used command: " << used << std::endl;
|
||||||
|
|
||||||
if (!Variables->searchPath.empty())
|
if (!Variables->searchPath.empty())
|
||||||
Variables->PartMap(searchPath);
|
Variables->PartMap(Variables->searchPath);
|
||||||
|
|
||||||
if (!Variables->PartMap) {
|
if (!Variables->PartMap) {
|
||||||
if (Variables->searchPath.empty())
|
if (Variables->searchPath.empty())
|
||||||
@@ -67,7 +68,7 @@ try { // try-catch start
|
|||||||
|
|
||||||
} catch (Helper::Error &error) { // catch Helper::Error
|
} catch (Helper::Error &error) { // catch Helper::Error
|
||||||
|
|
||||||
if (!Variables->silentProcess) fprintf(stde9rr, "%s: %s.\n", argv[0], error.what());
|
if (!Variables->silentProcess) fprintf(stderr, "%s: %s.\n", argv[0], error.what());
|
||||||
delete Variables;
|
delete Variables;
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -79,4 +80,18 @@ try { // try-catch start
|
|||||||
} // try-catch block end
|
} // try-catch block end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string getLibVersion()
|
||||||
|
{
|
||||||
|
char vinfo[512];
|
||||||
|
sprintf(vinfo, MKVERSION("libpmt"));
|
||||||
|
return std::string(vinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getAppVersion()
|
||||||
|
{
|
||||||
|
char vinfo[512];
|
||||||
|
sprintf(vinfo, MKVERSION("pmt"));
|
||||||
|
return std::string(vinfo);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace PartitionManager
|
} // namespace PartitionManager
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <libpmt/lib.hpp>
|
#include <PartitionManager/lib.hpp>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <libpmt/lib.hpp>
|
#include <PartitionManager/lib.hpp>
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ void set(std::string_view name, std::string_view file);
|
|||||||
void setProgramName(std::string_view name);
|
void setProgramName(std::string_view name);
|
||||||
void setLogFile(std::string_view file);
|
void setLogFile(std::string_view file);
|
||||||
void setPrinting(int state);
|
void setPrinting(int state);
|
||||||
void setLoggingState(int state); // Disable/enable logginf
|
void setLoggingState(int state); // Disable/enable logging
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
} // namespace LoggingProperties
|
} // namespace LoggingProperties
|
||||||
@@ -196,4 +196,7 @@ std::string getLibVersion();
|
|||||||
#define LOGNF_IF(name, file, level, condition) \
|
#define LOGNF_IF(name, file, level, condition) \
|
||||||
if (condition) Helper::Logger(level, __func__, file, name, __FILE__, __LINE__)
|
if (condition) Helper::Logger(level, __func__, file, name, __FILE__, __LINE__)
|
||||||
|
|
||||||
|
#define MKVERSION(name) \
|
||||||
|
"%s %s [%s %s]\nBuildType: %s\nCMakeVersion: %s\nCompilerVersion: %s\nBuildFlags: %s\n", name, BUILD_VERSION, BUILD_DATE, BUILD_TIME, BUILD_TYPE, BUILD_CMAKE_VERSION, BUILD_COMPILER_VERSION, BUILD_FLAGS
|
||||||
|
|
||||||
#endif // #ifndef LIBHELPER_LIB_HPP
|
#endif // #ifndef LIBHELPER_LIB_HPP
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ std::string pathDirname(const std::string_view entry)
|
|||||||
std::string getLibVersion()
|
std::string getLibVersion()
|
||||||
{
|
{
|
||||||
char vinfo[512];
|
char vinfo[512];
|
||||||
sprintf(vinfo, "libhelper %s [%s %s]\nBuildType: %s\nCMakeVersion: %s\nCompilerVersion: %s\nBuildFlags: %s\n", BUILD_VERSION, BUILD_DATE, BUILD_TIME, BUILD_TYPE, BUILD_CMAKE_VERSION, BUILD_COMPILER_VERSION, BUILD_FLAGS);
|
sprintf(vinfo, MKVERSION("libhelper"));
|
||||||
return std::string(vinfo);
|
return std::string(vinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ struct _entry {
|
|||||||
} props;
|
} props;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* basic_partition_map
|
||||||
|
* -------------------
|
||||||
|
* The main type of the library. The Builder class is designed
|
||||||
|
* to be easily manipulated and modified only on this class.
|
||||||
|
*/
|
||||||
class basic_partition_map {
|
class basic_partition_map {
|
||||||
private:
|
private:
|
||||||
void _resize_map();
|
void _resize_map();
|
||||||
@@ -139,16 +145,14 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Secondary constructor
|
* Secondary constructor
|
||||||
* ---------------------
|
* ---------------------
|
||||||
* It has two arguments:
|
* It has one arguments:
|
||||||
* - Directory path to search
|
* - Directory path to search
|
||||||
*/
|
*/
|
||||||
basic_partition_map_builder(const std::string_view path);
|
basic_partition_map_builder(const std::string_view path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getAll()
|
* getAll()
|
||||||
* ------
|
* --------
|
||||||
* WARNING: Learn about std::optional before using this function.
|
|
||||||
*
|
|
||||||
* Returns the current list content in Map_t type.
|
* Returns the current list content in Map_t type.
|
||||||
* If no list is created, returns std::nullopt.
|
* If no list is created, returns std::nullopt.
|
||||||
*/
|
*/
|
||||||
@@ -304,10 +308,17 @@ public:
|
|||||||
/**
|
/**
|
||||||
* ! operator
|
* ! operator
|
||||||
* ----------
|
* ----------
|
||||||
* Returns true if the object creation failed (i.e., there's a problem),
|
* Returns true if the object creation failed (i.e., there's a problem),
|
||||||
* and false if the object is correctly created.
|
* and false if the object is correctly created.
|
||||||
*/
|
*/
|
||||||
bool operator!() const;
|
bool operator!() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* () operator
|
||||||
|
* -----------
|
||||||
|
* Build map with input path. Implementation of readDirectory().
|
||||||
|
*/
|
||||||
|
bool operator()(const std::string_view path);
|
||||||
};
|
};
|
||||||
|
|
||||||
using Error = Helper::Error;
|
using Error = Helper::Error;
|
||||||
|
|||||||
@@ -211,10 +211,16 @@ bool basic_partition_map_builder::operator!() const
|
|||||||
return this->_any_generating_error;
|
return this->_any_generating_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool basic_partition_map_builder::operator()(const std::string_view path)
|
||||||
|
{
|
||||||
|
LOGN(MAP, INFO) << "calling readDirectory() for building map with " << path << std::endl;
|
||||||
|
return readDirectory(path);
|
||||||
|
}
|
||||||
|
|
||||||
std::string getLibVersion()
|
std::string getLibVersion()
|
||||||
{
|
{
|
||||||
char vinfo[512];
|
char vinfo[512];
|
||||||
sprintf(vinfo, "libpartition_map %s [%s %s]\nBuildType: %s\nCMakeVersion: %s\nCompilerVersion: %s\nBuildFlags: %s\n", BUILD_VERSION, BUILD_DATE, BUILD_TIME, BUILD_TYPE, BUILD_CMAKE_VERSION, BUILD_COMPILER_VERSION, BUILD_FLAGS);
|
sprintf(vinfo, MKVERSION("libpartition_map"));
|
||||||
return std::string(vinfo);
|
return std::string(vinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user