summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2020-01-10 14:50:07 -0600
committerHarsh Sharma <harsh.sharma@multitech.com>2020-01-10 14:50:07 -0600
commitbfc20a0ee14c841c75eeb6878dc5e3eced7d8e2d (patch)
treef406cbff1ee59fb944733f3ea10a09e018ce7ed6 /src
parentb69c7514fbad36e25dbf3ea263eb49f1f28d3653 (diff)
downloadmts-io-sysfs-bfc20a0ee14c841c75eeb6878dc5e3eced7d8e2d.tar.gz
mts-io-sysfs-bfc20a0ee14c841c75eeb6878dc5e3eced7d8e2d.tar.bz2
mts-io-sysfs-bfc20a0ee14c841c75eeb6878dc5e3eced7d8e2d.zip
Refectoring
Diffstat (limited to 'src')
-rw-r--r--src/Device/Device.cpp33
-rw-r--r--src/Version.cpp2
2 files changed, 18 insertions, 17 deletions
diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp
index e92ea6e..2498edd 100644
--- a/src/Device/Device.cpp
+++ b/src/Device/Device.cpp
@@ -34,11 +34,24 @@ std::map<std::string, bool> Device::capabilityList = {{"adc", false},{"battery",
{"nodeRed", false},{"rs232", false},{"rs422", false},{"rs485", false},{"serial", false},
{"wifi", false}};
+std::map<std::string, std::string> Device::deviceInfoList = {{"deviceId", ""},{"hardwareVersion", ""},
+ {"imei", ""},{"macAddress", "00:00:00:00:00:00"},{"macBluetooth", "00:00:00:00:00:00"},
+ {"macWifi", "00:00:00:00:00:00"},{"productId", ""},{"uuid", ""},{"vendorId", ""}};
+
Device::Device() {
isRoot = !getuid();
verbose = false;
}
+bool Device::isAccessoryCard(const char * d_name, const char * dir_name) {
+ return std::binary_search(apIdentifiers.begin(), apIdentifiers.end(), dir_name) && !regex_match(d_name, apFilters);
+}
+
+bool Device::isValidDirectory(const struct dirent * entry, std::string fullPath, const char * d_name) {
+ std::string path = fullPath + "/" + std::string(d_name);
+ return (entry->d_type & DT_DIR) && strcmp (d_name, "..") != 0 && strcmp (d_name, ".") != 0 && (path.length() <= PATH_MAX);
+}
+
void Device::getSystemTreeJson(const char * dir_name) {
std::string fullPath = SYSFS_PLATFORM + std::string(dir_name);
DIR * d = opendir (fullPath.c_str());
@@ -57,7 +70,7 @@ void Device::getSystemTreeJson(const char * dir_name) {
if (!(entry->d_type & DT_DIR) && (MTS::System::readFile(fullPath + "/" + std::string(d_name), fileData) == 0)) {
fileData = MTS::Text::trim(fileData);
if (strlen(dir_name) > 0) {
- if (std::binary_search(apIdentifiers.begin(), apIdentifiers.end(), dir_name) && !regex_match(d_name, apFilters)) {
+ if (isAccessoryCard(d_name, dir_name)) {
if (accessoryCard.IsNull()) {
accessoryCard.SetObject();
} else if (accessoryCard.HasMember(d_name)) {
@@ -93,15 +106,8 @@ void Device::getSystemTreeJson(const char * dir_name) {
}
}
}
- if (entry->d_type & DT_DIR) { /* Check that the directory is not "d" or d's parent. */
- if (strcmp (d_name, "..") != 0 && strcmp (d_name, ".") != 0) {
- std::string path = fullPath + "/" + std::string(d_name);
- if (path.length() >= PATH_MAX) {
- logError("Path length has got too long.\n");
- exitHandler(99);
- }
- getSystemTreeJson(d_name); /* Recursively call with the new path */
- }
+ if (isValidDirectory(entry, fullPath, d_name)) { /* Check that the directory is not "d" or d's parent. */
+ getSystemTreeJson(d_name); /* Recursively call with the new path */
}
}
if (closedir (d)) { /* After going through all the entries, close the directory. */
@@ -215,12 +221,7 @@ void Device::printDir(const std::string dir_name, std::vector<std::string> &resu
result.append(d_name);
results.push_back(result);
}
- if ((entry->d_type & DT_DIR) && strcmp (d_name, "..") != 0 && strcmp (d_name, ".") != 0) {
- std::string path = fullPath + "/" + std::string(d_name);
- if (path.length() >= PATH_MAX) {
- logError("Path length has got too long.\n");
- exitHandler(99);
- }
+ if (isValidDirectory(entry, fullPath, d_name)) { /* Check that the directory is not "d" or d's parent. */
printDir(d_name, results);
}
}
diff --git a/src/Version.cpp b/src/Version.cpp
index 393f305..b963c93 100644
--- a/src/Version.cpp
+++ b/src/Version.cpp
@@ -1,4 +1,4 @@
//Pre-Build Auto-Generated Source
#include "Version.h"
-const std::string Version::version("v1.0.0-9-g8c7856e");
+const std::string Version::version("v1.0.0-10-gb69c751");