code style, missing initializers and imports
This commit is contained in:
+12
-9
@@ -130,7 +130,7 @@ static MessageMap* s_messageMap = NULL;
|
|||||||
/** the @a MainLoop instance, or NULL. */
|
/** the @a MainLoop instance, or NULL. */
|
||||||
static MainLoop* s_mainLoop = NULL;
|
static MainLoop* s_mainLoop = NULL;
|
||||||
|
|
||||||
/** the path prefix (including trailing "/") for retrieving configuration files from local file system (empty for HTTP). */
|
/** the path prefix (including trailing "/") for retrieving configuration files from local files (empty for HTTP). */
|
||||||
static string s_configLocalPrefix;
|
static string s_configLocalPrefix;
|
||||||
|
|
||||||
/** the URI prefix (including trailing "/") for retrieving configuration files from HTTP (empty for local files). */
|
/** the URI prefix (including trailing "/") for retrieving configuration files from HTTP (empty for local files). */
|
||||||
@@ -183,7 +183,8 @@ static const struct argp_option argpoptions[] = {
|
|||||||
{"latency", O_DEVLAT, "USEC", 0, "Transfer latency in us [0 for USB, 10000 for IP]", 0 },
|
{"latency", O_DEVLAT, "USEC", 0, "Transfer latency in us [0 for USB, 10000 for IP]", 0 },
|
||||||
|
|
||||||
{NULL, 0, NULL, 0, "Message configuration options:", 2 },
|
{NULL, 0, NULL, 0, "Message configuration options:", 2 },
|
||||||
{"configpath", 'c', "PATH", 0, "Read CSV config files from PATH (local folder or HTTP URL) [" CONFIG_PATH "]", 0 },
|
{"configpath", 'c', "PATH", 0, "Read CSV config files from PATH (local folder or HTTP URL) [" CONFIG_PATH
|
||||||
|
"]", 0 },
|
||||||
{"scanconfig", 's', "ADDR", OPTION_ARG_OPTIONAL, "Pick CSV config files matching initial scan (ADDR="
|
{"scanconfig", 's', "ADDR", OPTION_ARG_OPTIONAL, "Pick CSV config files matching initial scan (ADDR="
|
||||||
"\"none\" or empty for no initial scan message, \"full\" for full scan, or a single hex address to scan, "
|
"\"none\" or empty for no initial scan message, \"full\" for full scan, or a single hex address to scan, "
|
||||||
"default is broadcast ident message). If combined with --checkconfig, you can add scan message data as "
|
"default is broadcast ident message). If combined with --checkconfig, you can add scan message data as "
|
||||||
@@ -733,12 +734,13 @@ void signalHandler(int sig) {
|
|||||||
* @return the result code.
|
* @return the result code.
|
||||||
*/
|
*/
|
||||||
static result_t collectConfigFiles(const string& relPath, const string& prefix, const string& extension,
|
static result_t collectConfigFiles(const string& relPath, const string& prefix, const string& extension,
|
||||||
vector<string>* files, const bool ignoreAddressPrefix = false, const string& query = "", vector<string>* dirs = NULL,
|
vector<string>* files, const bool ignoreAddressPrefix = false, const string& query = "",
|
||||||
bool* hasTemplates = NULL) {
|
vector<string>* dirs = NULL, bool* hasTemplates = NULL) {
|
||||||
const string relPathWithSlash = relPath.empty() ? "" : relPath + "/";
|
const string relPathWithSlash = relPath.empty() ? "" : relPath + "/";
|
||||||
if (!s_configUriPrefix.empty()) {
|
if (!s_configUriPrefix.empty()) {
|
||||||
|
string uri = s_configUriPrefix + relPathWithSlash + "?t=" + extension.substr(1) + query;
|
||||||
string names;
|
string names;
|
||||||
if (!s_configHttpClient.get(s_configUriPrefix + relPathWithSlash + "?t=" + (extension.substr(1)) + query, "", names)) {
|
if (!s_configHttpClient.get(uri, "", names)) {
|
||||||
return RESULT_ERR_NOTFOUND;
|
return RESULT_ERR_NOTFOUND;
|
||||||
}
|
}
|
||||||
istringstream stream(names);
|
istringstream stream(names);
|
||||||
@@ -929,7 +931,7 @@ void executeInstructions(MessageMap* messages, bool verbose) {
|
|||||||
result_t loadDefinitionsFromConfigPath(FileReader* reader, const string& filename, bool verbose,
|
result_t loadDefinitionsFromConfigPath(FileReader* reader, const string& filename, bool verbose,
|
||||||
map<string, string>* defaults, string* errorDescription) {
|
map<string, string>* defaults, string* errorDescription) {
|
||||||
istream* stream = NULL;
|
istream* stream = NULL;
|
||||||
time_t mtime;
|
time_t mtime = 0;
|
||||||
if (s_configUriPrefix.empty()) {
|
if (s_configUriPrefix.empty()) {
|
||||||
stream = FileReader::openFile(s_configLocalPrefix + filename, errorDescription, &mtime);
|
stream = FileReader::openFile(s_configLocalPrefix + filename, errorDescription, &mtime);
|
||||||
} else {
|
} else {
|
||||||
@@ -1046,7 +1048,8 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose
|
|||||||
// find files matching MANUFACTURER/ZZ.*csv in cfgpath
|
// find files matching MANUFACTURER/ZZ.*csv in cfgpath
|
||||||
string query;
|
string query;
|
||||||
if (!fromLocal) {
|
if (!fromLocal) {
|
||||||
out << "&a=" << addrStr << "&i=" << ident << "&h=" << dec << static_cast<unsigned>(hw) << "&s=" << dec << static_cast<unsigned>(sw);;
|
out << "&a=" << addrStr << "&i=" << ident << "&h=" << dec << static_cast<unsigned>(hw) << "&s=" << dec
|
||||||
|
<< static_cast<unsigned>(sw);;
|
||||||
query = out.str();
|
query = out.str();
|
||||||
out.str("");
|
out.str("");
|
||||||
out.clear();
|
out.clear();
|
||||||
@@ -1058,8 +1061,8 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (files.empty()) {
|
if (files.empty()) {
|
||||||
logError(lf_main, "unable to load scan config %2.2x: no file from %s with prefix %s found", address, manufStr.c_str(),
|
logError(lf_main, "unable to load scan config %2.2x: no file from %s with prefix %s found", address,
|
||||||
addrStr.c_str());
|
manufStr.c_str(), addrStr.c_str());
|
||||||
return RESULT_ERR_NOTFOUND;
|
return RESULT_ERR_NOTFOUND;
|
||||||
}
|
}
|
||||||
logDebug(lf_main, "found %d matching scan config files from %s with prefix %s: %s", files.size(), manufStr.c_str(),
|
logDebug(lf_main, "found %d matching scan config files from %s with prefix %s: %s", files.size(), manufStr.c_str(),
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <map>
|
||||||
#include "lib/ebus/data.h"
|
#include "lib/ebus/data.h"
|
||||||
#include "lib/ebus/message.h"
|
#include "lib/ebus/message.h"
|
||||||
#include "lib/ebus/result.h"
|
#include "lib/ebus/result.h"
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ MainLoop::MainLoop(const struct options& opt, Device *device, MessageMap* messag
|
|||||||
m_logRawLastSymbol = SYN;
|
m_logRawLastSymbol = SYN;
|
||||||
if (opt.aclFile[0]) {
|
if (opt.aclFile[0]) {
|
||||||
string errorDescription;
|
string errorDescription;
|
||||||
time_t mtime;
|
time_t mtime = 0;
|
||||||
istream* stream = FileReader::openFile(opt.aclFile, &errorDescription, &mtime);
|
istream* stream = FileReader::openFile(opt.aclFile, &errorDescription, &mtime);
|
||||||
if (stream) {
|
if (stream) {
|
||||||
result = m_userList.readFromStream(stream, opt.aclFile, mtime, false, NULL, &errorDescription);
|
result = m_userList.readFromStream(stream, opt.aclFile, mtime, false, NULL, &errorDescription);
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ istream* FileReader::openFile(const string& filename, string* errorDescription,
|
|||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
result_t FileReader::readFromStream(istream* stream, const string& filename, time_t& mtime, bool verbose,
|
result_t FileReader::readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose,
|
||||||
map<string, string>* defaults, string* errorDescription, size_t* hash, size_t* size) {
|
map<string, string>* defaults, string* errorDescription, size_t* hash, size_t* size) {
|
||||||
if (hash) {
|
if (hash) {
|
||||||
*hash = 0;
|
*hash = 0;
|
||||||
@@ -241,7 +241,7 @@ const string MappedFileReader::normalizeLanguage(const string& lang) {
|
|||||||
return normLang;
|
return normLang;
|
||||||
}
|
}
|
||||||
|
|
||||||
result_t MappedFileReader::readFromStream(istream* stream, const string& filename, time_t& mtime, bool verbose,
|
result_t MappedFileReader::readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose,
|
||||||
map<string, string>* defaults, string* errorDescription, size_t* hash, size_t* size) {
|
map<string, string>* defaults, string* errorDescription, size_t* hash, size_t* size) {
|
||||||
m_mutex.lock();
|
m_mutex.lock();
|
||||||
m_columnNames.clear();
|
m_columnNames.clear();
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class FileReader {
|
|||||||
* @param size optional pointer to a @a size_t value for storing the normalized size of the file, or NULL.
|
* @param size optional pointer to a @a size_t value for storing the normalized size of the file, or NULL.
|
||||||
* @return @a RESULT_OK on success, or an error code.
|
* @return @a RESULT_OK on success, or an error code.
|
||||||
*/
|
*/
|
||||||
virtual result_t readFromStream(istream* stream, const string& filename, time_t& mtime, bool verbose,
|
virtual result_t readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose,
|
||||||
map<string, string>* defaults, string* errorDescription, size_t* hash = NULL, size_t* size = NULL);
|
map<string, string>* defaults, string* errorDescription, size_t* hash = NULL, size_t* size = NULL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -204,7 +204,7 @@ class MappedFileReader : public FileReader {
|
|||||||
static const string normalizeLanguage(const string& lang);
|
static const string normalizeLanguage(const string& lang);
|
||||||
|
|
||||||
// @copydoc
|
// @copydoc
|
||||||
result_t readFromStream(istream* stream, const string& filename, time_t& mtime, bool verbose,
|
result_t readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose,
|
||||||
map<string, string>* defaults, string* errorDescription, size_t* hash = NULL, size_t* size = NULL) override;
|
map<string, string>* defaults, string* errorDescription, size_t* hash = NULL, size_t* size = NULL) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2104,7 +2104,7 @@ bool MessageMap::extractDefaultsFromFilename(const string& filename, map<string,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
result_t MessageMap::readFromStream(istream* stream, const string& filename, time_t& mtime, bool verbose,
|
result_t MessageMap::readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose,
|
||||||
map<string, string>* defaults, string* errorDescription, size_t* hash, size_t* size) {
|
map<string, string>* defaults, string* errorDescription, size_t* hash, size_t* size) {
|
||||||
size_t localHash, localSize;
|
size_t localHash, localSize;
|
||||||
if (!hash) {
|
if (!hash) {
|
||||||
@@ -2113,7 +2113,8 @@ result_t MessageMap::readFromStream(istream* stream, const string& filename, tim
|
|||||||
if (!size) {
|
if (!size) {
|
||||||
size = &localSize;
|
size = &localSize;
|
||||||
}
|
}
|
||||||
result_t result = MappedFileReader::readFromStream(stream, filename, mtime, verbose, defaults, errorDescription, hash, size);
|
result_t result = MappedFileReader::readFromStream(stream, filename, mtime, verbose, defaults, errorDescription, hash,
|
||||||
|
size);
|
||||||
if (defaults) {
|
if (defaults) {
|
||||||
string circuit = AttributedItem::pluck("circuit", defaults);
|
string circuit = AttributedItem::pluck("circuit", defaults);
|
||||||
if (!circuit.empty() && m_circuitData.find(circuit) == m_circuitData.end()) {
|
if (!circuit.empty() && m_circuitData.find(circuit) == m_circuitData.end()) {
|
||||||
|
|||||||
@@ -1261,7 +1261,7 @@ class MessageMap : public MappedFileReader {
|
|||||||
symbol_t* destAddress = NULL, unsigned int* software = NULL, unsigned int* hardware = NULL) const override;
|
symbol_t* destAddress = NULL, unsigned int* software = NULL, unsigned int* hardware = NULL) const override;
|
||||||
|
|
||||||
// @copydoc
|
// @copydoc
|
||||||
result_t readFromStream(istream* stream, const string& filename, time_t& mtime, bool verbose,
|
result_t readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose,
|
||||||
map<string, string>* defaults, string* errorDescription, size_t* hash = NULL, size_t* size = NULL) override;
|
map<string, string>* defaults, string* errorDescription, size_t* hash = NULL, size_t* size = NULL) override;
|
||||||
|
|
||||||
// @copydoc
|
// @copydoc
|
||||||
|
|||||||
@@ -215,9 +215,9 @@ bool HttpClient::request(const string& method, const string& uri, const string&
|
|||||||
if (t.tm_mday > 0 && t.tm_mon >= 0 && t.tm_year >= 0 && t.tm_hour >= 0 && t.tm_min >=0 && t.tm_sec >= 0) {
|
if (t.tm_mday > 0 && t.tm_mon >= 0 && t.tm_year >= 0 && t.tm_hour >= 0 && t.tm_min >=0 && t.tm_sec >= 0) {
|
||||||
*time = timegm(&t);
|
*time = timegm(&t);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
pos = headers.find("\r\nContent-Length: "); // 16 chars
|
}
|
||||||
|
pos = headers.find("\r\nContent-Length: ");
|
||||||
if (pos == string::npos) {
|
if (pos == string::npos) {
|
||||||
disconnect();
|
disconnect();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user