use nullptr instead of NULL
This commit is contained in:
+45
-45
@@ -109,7 +109,7 @@ bool ScanRequest::notify(result_t result, const SlaveSymbolString& slave) {
|
||||
if (result == RESULT_OK) {
|
||||
if (m_message == m_messageMap->getScanMessage()) {
|
||||
Message* message = m_messageMap->getScanMessage(dstAddress);
|
||||
if (message != NULL) {
|
||||
if (message != nullptr) {
|
||||
m_message = message;
|
||||
m_message->storeLastData(m_index, m_master); // expected to work since this is a clone
|
||||
}
|
||||
@@ -128,7 +128,7 @@ bool ScanRequest::notify(result_t result, const SlaveSymbolString& slave) {
|
||||
}
|
||||
if (result == RESULT_OK) {
|
||||
ostringstream output;
|
||||
result = m_message->decodeLastData(true, NULL, -1, 0, &output); // decode data
|
||||
result = m_message->decodeLastData(true, nullptr, -1, 0, &output); // decode data
|
||||
string str = output.str();
|
||||
m_busHandler->setScanResult(dstAddress, m_notifyIndex+m_index, str);
|
||||
}
|
||||
@@ -422,7 +422,7 @@ result_t BusHandler::handleSymbol() {
|
||||
unsigned int timeout = SYN_TIMEOUT;
|
||||
symbol_t sendSymbol = ESC;
|
||||
bool sending = false;
|
||||
BusRequest* startRequest = NULL;
|
||||
BusRequest* startRequest = nullptr;
|
||||
|
||||
// check if another symbol has to be sent and determine timeout for receive
|
||||
switch (m_state) {
|
||||
@@ -435,16 +435,16 @@ result_t BusHandler::handleSymbol() {
|
||||
break;
|
||||
|
||||
case bs_ready:
|
||||
if (m_currentRequest != NULL) {
|
||||
if (m_currentRequest != nullptr) {
|
||||
setState(bs_ready, RESULT_ERR_TIMEOUT); // just to be sure an old BusRequest is cleaned up
|
||||
} else if (m_remainLockCount == 0) {
|
||||
startRequest = m_nextRequests.peek();
|
||||
if (startRequest == NULL && m_pollInterval > 0) { // check for poll/scan
|
||||
if (startRequest == nullptr && m_pollInterval > 0) { // check for poll/scan
|
||||
time_t now;
|
||||
time(&now);
|
||||
if (m_lastPoll == 0 || difftime(now, m_lastPoll) > m_pollInterval) {
|
||||
Message* message = m_messages->getNextPoll();
|
||||
if (message != NULL) {
|
||||
if (message != nullptr) {
|
||||
m_lastPoll = now;
|
||||
PollRequest* request = new PollRequest(message);
|
||||
result_t ret = request->prepare(m_ownMasterAddress);
|
||||
@@ -458,7 +458,7 @@ result_t BusHandler::handleSymbol() {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (startRequest != NULL) { // initiate arbitration
|
||||
if (startRequest != nullptr) { // initiate arbitration
|
||||
sendSymbol = startRequest->m_master[0];
|
||||
sending = true;
|
||||
}
|
||||
@@ -488,21 +488,21 @@ result_t BusHandler::handleSymbol() {
|
||||
break;
|
||||
|
||||
case bs_sendCmd:
|
||||
if (m_currentRequest != NULL) {
|
||||
if (m_currentRequest != nullptr) {
|
||||
sendSymbol = m_currentRequest->m_master[m_nextSendPos]; // unescaped command
|
||||
sending = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case bs_sendCmdCrc:
|
||||
if (m_currentRequest != NULL) {
|
||||
if (m_currentRequest != nullptr) {
|
||||
sendSymbol = m_crc;
|
||||
sending = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case bs_sendResAck:
|
||||
if (m_currentRequest != NULL) {
|
||||
if (m_currentRequest != nullptr) {
|
||||
sendSymbol = m_crcValid ? ACK : NAK;
|
||||
sending = true;
|
||||
}
|
||||
@@ -558,7 +558,7 @@ result_t BusHandler::handleSymbol() {
|
||||
} else {
|
||||
sending = false;
|
||||
timeout = SYN_TIMEOUT;
|
||||
if (startRequest != NULL && m_nextRequests.remove(startRequest)) {
|
||||
if (startRequest != nullptr && m_nextRequests.remove(startRequest)) {
|
||||
m_currentRequest = startRequest; // force the failed request to be notified
|
||||
}
|
||||
setState(bs_skip, result);
|
||||
@@ -604,7 +604,7 @@ result_t BusHandler::handleSymbol() {
|
||||
time_t now;
|
||||
time(&now);
|
||||
if (result != RESULT_OK) {
|
||||
if (sending && startRequest != NULL && m_nextRequests.remove(startRequest)) {
|
||||
if (sending && startRequest != nullptr && m_nextRequests.remove(startRequest)) {
|
||||
m_currentRequest = startRequest; // force the failed request to be notified
|
||||
}
|
||||
if ((m_generateSynInterval != SYN_TIMEOUT && difftime(now, m_lastReceive) > 1)
|
||||
@@ -672,7 +672,7 @@ result_t BusHandler::handleSymbol() {
|
||||
return RESULT_OK;
|
||||
|
||||
case bs_ready:
|
||||
if (startRequest != NULL && sending) {
|
||||
if (startRequest != nullptr && sending) {
|
||||
if (!m_nextRequests.remove(startRequest)) {
|
||||
// request already removed (e.g. due to timeout)
|
||||
return setState(bs_skip, RESULT_ERR_TIMEOUT);
|
||||
@@ -754,7 +754,7 @@ result_t BusHandler::handleSymbol() {
|
||||
if (!m_crcValid) {
|
||||
return setState(bs_skip, RESULT_ERR_ACK);
|
||||
}
|
||||
if (m_currentRequest != NULL) {
|
||||
if (m_currentRequest != nullptr) {
|
||||
if (isMaster(m_currentRequest->m_master[1])) {
|
||||
messageCompleted();
|
||||
return setState(bs_sendSyn, RESULT_OK);
|
||||
@@ -773,7 +773,7 @@ result_t BusHandler::handleSymbol() {
|
||||
m_crc = 0;
|
||||
m_nextSendPos = 0;
|
||||
m_command.clear();
|
||||
if (m_currentRequest != NULL) {
|
||||
if (m_currentRequest != nullptr) {
|
||||
return setState(bs_sendCmd, RESULT_ERR_NAK, true);
|
||||
}
|
||||
return setState(bs_recvCmd, RESULT_ERR_NAK);
|
||||
@@ -792,18 +792,18 @@ result_t BusHandler::handleSymbol() {
|
||||
case bs_recvResCrc:
|
||||
m_crcValid = recvSymbol == m_crc;
|
||||
if (m_crcValid) {
|
||||
if (m_currentRequest != NULL) {
|
||||
if (m_currentRequest != nullptr) {
|
||||
return setState(bs_sendResAck, RESULT_OK);
|
||||
}
|
||||
return setState(bs_recvResAck, RESULT_OK);
|
||||
}
|
||||
if (m_repeat) {
|
||||
if (m_currentRequest != NULL) {
|
||||
if (m_currentRequest != nullptr) {
|
||||
return setState(bs_sendSyn, RESULT_ERR_CRC);
|
||||
}
|
||||
return setState(bs_skip, RESULT_ERR_CRC);
|
||||
}
|
||||
if (m_currentRequest != NULL) {
|
||||
if (m_currentRequest != nullptr) {
|
||||
return setState(bs_sendResAck, RESULT_ERR_CRC);
|
||||
}
|
||||
return setState(bs_recvResAck, RESULT_ERR_CRC);
|
||||
@@ -831,7 +831,7 @@ result_t BusHandler::handleSymbol() {
|
||||
return setState(bs_skip, RESULT_ERR_ACK);
|
||||
|
||||
case bs_sendCmd:
|
||||
if (!sending || m_currentRequest == NULL) {
|
||||
if (!sending || m_currentRequest == nullptr) {
|
||||
return setState(bs_skip, RESULT_ERR_INVALID_ARG);
|
||||
}
|
||||
m_nextSendPos++;
|
||||
@@ -849,7 +849,7 @@ result_t BusHandler::handleSymbol() {
|
||||
return setState(bs_recvCmdAck, RESULT_OK);
|
||||
|
||||
case bs_sendResAck:
|
||||
if (!sending || m_currentRequest == NULL) {
|
||||
if (!sending || m_currentRequest == nullptr) {
|
||||
return setState(bs_skip, RESULT_ERR_INVALID_ARG);
|
||||
}
|
||||
if (!m_crcValid) {
|
||||
@@ -886,13 +886,13 @@ result_t BusHandler::handleSymbol() {
|
||||
{
|
||||
Message* message;
|
||||
message = m_messages->find(m_command);
|
||||
if (message == NULL) {
|
||||
if (message == nullptr) {
|
||||
message = m_messages->find(m_command, true);
|
||||
if (message != NULL && message->getSrcAddress() != SYN) {
|
||||
message = NULL;
|
||||
if (message != nullptr && message->getSrcAddress() != SYN) {
|
||||
message = nullptr;
|
||||
}
|
||||
}
|
||||
if (message == NULL || message->isWrite()) {
|
||||
if (message == nullptr || message->isWrite()) {
|
||||
// don't know this request or definition has wrong direction, deny
|
||||
return setState(bs_skip, RESULT_ERR_INVALID_ARG);
|
||||
}
|
||||
@@ -936,12 +936,12 @@ result_t BusHandler::handleSymbol() {
|
||||
}
|
||||
|
||||
result_t BusHandler::setState(BusState state, result_t result, bool firstRepetition) {
|
||||
if (m_currentRequest != NULL) {
|
||||
if (m_currentRequest != nullptr) {
|
||||
if (result == RESULT_ERR_BUS_LOST && m_currentRequest->m_busLostRetries < m_busLostRetries) {
|
||||
logDebug(lf_bus, "%s during %s, retry", getResultCode(result), getStateCode(m_state));
|
||||
m_currentRequest->m_busLostRetries++;
|
||||
m_nextRequests.push(m_currentRequest); // repeat
|
||||
m_currentRequest = NULL;
|
||||
m_currentRequest = nullptr;
|
||||
} else if (state == bs_sendSyn || (result != RESULT_OK && !firstRepetition)) {
|
||||
logDebug(lf_bus, "notify request: %s", getResultCode(result));
|
||||
bool restart = m_currentRequest->notify(
|
||||
@@ -955,13 +955,13 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
|
||||
} else {
|
||||
m_finishedRequests.push(m_currentRequest);
|
||||
}
|
||||
m_currentRequest = NULL;
|
||||
m_currentRequest = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (state == bs_noSignal) { // notify all requests
|
||||
m_response.clear(); // notify with empty response
|
||||
while ((m_currentRequest = m_nextRequests.pop()) != NULL) {
|
||||
while ((m_currentRequest = m_nextRequests.pop()) != nullptr) {
|
||||
bool restart = m_currentRequest->notify(RESULT_ERR_NO_SIGNAL, m_response);
|
||||
if (restart) { // should not occur with no signal
|
||||
m_currentRequest->m_busLostRetries = 0;
|
||||
@@ -982,7 +982,7 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
|
||||
|| (result != RESULT_OK && state == bs_skip && m_state != bs_ready)) {
|
||||
logDebug(lf_bus, "%s during %s, switching to %s", getResultCode(result), getStateCode(m_state),
|
||||
getStateCode(state));
|
||||
} else if (m_currentRequest != NULL || state == bs_sendCmd || state == bs_sendCmdCrc || state == bs_sendCmdAck
|
||||
} else if (m_currentRequest != nullptr || state == bs_sendCmd || state == bs_sendCmdCrc || state == bs_sendCmdAck
|
||||
|| state == bs_sendRes || state == bs_sendResCrc || state == bs_sendResAck || state == bs_sendSyn) {
|
||||
logDebug(lf_bus, "switching from %s to %s", getStateCode(m_state), getStateCode(state));
|
||||
}
|
||||
@@ -1098,7 +1098,7 @@ void BusHandler::messageCompleted() {
|
||||
result = message->storeLastData(0, idData);
|
||||
if (result == RESULT_OK) {
|
||||
ostringstream output;
|
||||
result = message->decodeLastData(true, NULL, -1, 0, &output);
|
||||
result = message->decodeLastData(true, nullptr, -1, 0, &output);
|
||||
if (result == RESULT_OK) {
|
||||
string str = output.str();
|
||||
setScanResult(slaveAddress, 0, str);
|
||||
@@ -1118,7 +1118,7 @@ void BusHandler::messageCompleted() {
|
||||
result_t result = message->storeLastData(m_command, m_response);
|
||||
if (result == RESULT_OK) {
|
||||
ostringstream output;
|
||||
result = message->decodeLastData(true, NULL, -1, 0, &output);
|
||||
result = message->decodeLastData(true, nullptr, -1, 0, &output);
|
||||
if (result == RESULT_OK) {
|
||||
string str = output.str();
|
||||
setScanResult(dstAddress, 0, str);
|
||||
@@ -1138,7 +1138,7 @@ void BusHandler::messageCompleted() {
|
||||
}
|
||||
m_grabbedMessages[key].setLastData(m_command, m_response);
|
||||
}
|
||||
if (message == NULL) {
|
||||
if (message == nullptr) {
|
||||
if (dstAddress == BROADCAST) {
|
||||
logNotice(lf_update, "%s unknown BC cmd: %s", prefix, m_command.getStr().c_str());
|
||||
} else if (master) {
|
||||
@@ -1153,7 +1153,7 @@ void BusHandler::messageCompleted() {
|
||||
result_t result = message->storeLastData(m_command, m_response);
|
||||
ostringstream output;
|
||||
if (result == RESULT_OK) {
|
||||
result = message->decodeLastData(false, NULL, -1, 0, &output);
|
||||
result = message->decodeLastData(false, nullptr, -1, 0, &output);
|
||||
}
|
||||
if (result < RESULT_OK) {
|
||||
logError(lf_update, "unable to parse %s %s from %s / %s: %s", circuit.c_str(), name.c_str(),
|
||||
@@ -1182,7 +1182,7 @@ void BusHandler::messageCompleted() {
|
||||
result_t BusHandler::prepareScan(symbol_t slave, bool full, const string& levels, bool* reload,
|
||||
ScanRequest** request) {
|
||||
Message* scanMessage = m_messages->getScanMessage();
|
||||
if (scanMessage == NULL) {
|
||||
if (scanMessage == nullptr) {
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
}
|
||||
if (m_device->isReadOnly()) {
|
||||
@@ -1205,7 +1205,7 @@ result_t BusHandler::prepareScan(symbol_t slave, bool full, const string& levels
|
||||
slaves.push_back(slave);
|
||||
if (!*reload) {
|
||||
Message* message = m_messages->getScanMessage(slave);
|
||||
if (message == NULL || message->getLastChangeTime() == 0) {
|
||||
if (message == nullptr || message->getLastChangeTime() == 0) {
|
||||
*reload = true;
|
||||
}
|
||||
}
|
||||
@@ -1234,7 +1234,7 @@ result_t BusHandler::prepareScan(symbol_t slave, bool full, const string& levels
|
||||
result_t result = (*request)->prepare(m_ownMasterAddress);
|
||||
if (result < RESULT_OK) {
|
||||
delete *request;
|
||||
*request = NULL;
|
||||
*request = nullptr;
|
||||
return result == RESULT_ERR_EOF ? RESULT_EMPTY : result;
|
||||
}
|
||||
return RESULT_OK;
|
||||
@@ -1244,7 +1244,7 @@ result_t BusHandler::startScan(bool full, const string& levels) {
|
||||
if (m_runningScans > 0) {
|
||||
return RESULT_ERR_DUPLICATE;
|
||||
}
|
||||
ScanRequest* request = NULL;
|
||||
ScanRequest* request = nullptr;
|
||||
bool reload = true;
|
||||
result_t result = prepareScan(SYN, full, levels, &reload, &request);
|
||||
if (result != RESULT_OK) {
|
||||
@@ -1308,14 +1308,14 @@ void BusHandler::formatScanResult(ostringstream* output) const {
|
||||
for (symbol_t slave = 1; slave != 0; slave++) { // 0 is known to be a master
|
||||
if (isValidAddress(slave, false) && !isMaster(slave) && (m_seenAddresses[slave]&SCAN_DONE) != 0) {
|
||||
Message* message = m_messages->getScanMessage(slave);
|
||||
if (message != NULL && message->getLastUpdateTime() > 0) {
|
||||
if (message != nullptr && message->getLastUpdateTime() > 0) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
*output << endl;
|
||||
}
|
||||
*output << hex << setw(2) << setfill('0') << static_cast<unsigned>(slave);
|
||||
message->decodeLastData(true, NULL, -1, 0, output);
|
||||
message->decodeLastData(true, nullptr, -1, 0, output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1353,10 +1353,10 @@ void BusHandler::formatSeenInfo(ostringstream* output) const {
|
||||
if ((m_seenAddresses[address]&SCAN_DONE) != 0) {
|
||||
*output << ", scanned";
|
||||
Message* message = m_messages->getScanMessage(address);
|
||||
if (message != NULL && message->getLastUpdateTime() > 0) {
|
||||
if (message != nullptr && message->getLastUpdateTime() > 0) {
|
||||
// add detailed scan info: Manufacturer ID SW HW
|
||||
*output << " \"";
|
||||
result_t result = message->decodeLastData(false, NULL, -1, OF_NAMES, output);
|
||||
result_t result = message->decodeLastData(false, nullptr, -1, OF_NAMES, output);
|
||||
if (result != RESULT_OK) {
|
||||
*output << "\" error: " << getResultCode(result);
|
||||
} else {
|
||||
@@ -1423,9 +1423,9 @@ void BusHandler::formatUpdateInfo(ostringstream* output) const {
|
||||
}
|
||||
if ((m_seenAddresses[address]&SCAN_DONE) != 0) {
|
||||
Message* message = m_messages->getScanMessage(address);
|
||||
if (message != NULL && message->getLastUpdateTime() > 0) {
|
||||
if (message != nullptr && message->getLastUpdateTime() > 0) {
|
||||
// add detailed scan info: Manufacturer ID SW HW
|
||||
message->decodeLastData(true, NULL, -1, OF_NAMES|OF_NUMERIC|OF_JSON|OF_SHORT, output);
|
||||
message->decodeLastData(true, nullptr, -1, OF_NAMES|OF_NUMERIC|OF_JSON|OF_SHORT, output);
|
||||
}
|
||||
}
|
||||
const vector<string>& loadedFiles = m_messages->getLoadedFiles(address);
|
||||
@@ -1480,7 +1480,7 @@ result_t BusHandler::scanAndWait(symbol_t dstAddress, bool loadScanConfig, bool
|
||||
if (!isValidAddress(dstAddress, false) || isMaster(dstAddress)) {
|
||||
return RESULT_ERR_INVALID_ADDR;
|
||||
}
|
||||
ScanRequest* request = NULL;
|
||||
ScanRequest* request = nullptr;
|
||||
bool hasAdditionalScanMessages = m_messages->hasAdditionalScanMessages();
|
||||
result_t result = prepareScan(dstAddress, false, "", &reload, &request);
|
||||
if (result != RESULT_OK) {
|
||||
@@ -1498,7 +1498,7 @@ result_t BusHandler::scanAndWait(symbol_t dstAddress, bool loadScanConfig, bool
|
||||
requestExecuted = m_finishedRequests.remove(request, true);
|
||||
result = requestExecuted ? request->m_result : RESULT_ERR_TIMEOUT;
|
||||
delete request;
|
||||
request = NULL;
|
||||
request = nullptr;
|
||||
}
|
||||
if (loadScanConfig) {
|
||||
string file;
|
||||
|
||||
@@ -380,7 +380,7 @@ class BusHandler : public WaitThread {
|
||||
m_generateSynInterval(generateSyn ? SYN_TIMEOUT*getMasterNumber(ownAddress)+SYMBOL_DURATION : 0),
|
||||
m_pollInterval(pollInterval), m_symbolLatencyMin(-1), m_symbolLatencyMax(-1), m_arbitrationDelayMin(-1),
|
||||
m_arbitrationDelayMax(-1), m_lastReceive(0), m_lastPoll(0),
|
||||
m_currentRequest(NULL), m_currentAnswering(false), m_runningScans(0), m_nextSendPos(0),
|
||||
m_currentRequest(nullptr), m_currentAnswering(false), m_runningScans(0), m_nextSendPos(0),
|
||||
m_symPerSec(0), m_maxSymPerSec(0),
|
||||
m_state(bs_noSignal), m_escape(0), m_crc(0), m_crcValid(false), m_repeat(false),
|
||||
m_grabMessages(true) {
|
||||
@@ -396,17 +396,17 @@ class BusHandler : public WaitThread {
|
||||
stop();
|
||||
join();
|
||||
BusRequest* req;
|
||||
while ((req = m_finishedRequests.pop()) != NULL) {
|
||||
while ((req = m_finishedRequests.pop()) != nullptr) {
|
||||
delete req;
|
||||
}
|
||||
while ((req = m_nextRequests.pop()) != NULL) {
|
||||
while ((req = m_nextRequests.pop()) != nullptr) {
|
||||
if (req->m_deleteOnFinish) {
|
||||
delete req;
|
||||
}
|
||||
}
|
||||
if (m_currentRequest != NULL) {
|
||||
if (m_currentRequest != nullptr) {
|
||||
delete m_currentRequest;
|
||||
m_currentRequest = NULL;
|
||||
m_currentRequest = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -633,7 +633,7 @@ class BusHandler : public WaitThread {
|
||||
* @param full true for a full scan (all slaves), false for scanning only already seen slaves.
|
||||
* @param levels the current user's access levels.
|
||||
* @param reload true to force sending the scan message, false to send only if necessary (only for single slave).
|
||||
* @param request the created @a ScanRequest (may be NULL with positive result if scan is not needed).
|
||||
* @param request the created @a ScanRequest (may be nullptr with positive result if scan is not needed).
|
||||
* @return the result code.
|
||||
*/
|
||||
result_t prepareScan(symbol_t slave, bool full, const string& levels, bool* reload, ScanRequest** request);
|
||||
@@ -722,7 +722,7 @@ class BusHandler : public WaitThread {
|
||||
/** the queue of @a BusRequests that shall be handled. */
|
||||
Queue<BusRequest*> m_nextRequests;
|
||||
|
||||
/** the currently handled BusRequest, or NULL. */
|
||||
/** the currently handled BusRequest, or nullptr. */
|
||||
BusRequest* m_currentRequest;
|
||||
|
||||
/** whether currently answering a request from another participant. */
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
namespace ebusd {
|
||||
|
||||
/** the final @a argp_child structure. */
|
||||
static const struct argp_child g_last_argp_child = {NULL, 0, NULL, 0};
|
||||
static const struct argp_child g_last_argp_child = {nullptr, 0, nullptr, 0};
|
||||
|
||||
/** the list of @a argp_child structures. */
|
||||
static struct argp_child g_argp_children[
|
||||
@@ -47,7 +47,7 @@ const struct argp_child* datahandler_getargs() {
|
||||
g_argp_children[count] = g_last_argp_child;
|
||||
return g_argp_children;
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool datahandler_register(UserInfo* userInfo, BusHandler* busHandler, MessageMap* messages,
|
||||
|
||||
@@ -42,7 +42,7 @@ class DataHandler;
|
||||
|
||||
/**
|
||||
* Helper function for getting the argp definition for all known @a DataHandler instances.
|
||||
* @return a pointer to the argp_child structure, or NULL.
|
||||
* @return a pointer to the argp_child structure, or nullptr.
|
||||
*/
|
||||
const struct argp_child* datahandler_getargs();
|
||||
|
||||
|
||||
+94
-94
@@ -67,8 +67,8 @@ using std::cout;
|
||||
/** the default path of the configuration files. */
|
||||
#define CONFIG_PATH "http://ebusd.eu/config/"
|
||||
|
||||
/** the opened PID file, or NULL. */
|
||||
static FILE* pidFile = NULL;
|
||||
/** the opened PID file, or nullptr. */
|
||||
static FILE* pidFile = nullptr;
|
||||
|
||||
/** true when forked into daemon mode. */
|
||||
static bool isDaemon = false;
|
||||
@@ -125,11 +125,11 @@ static struct options opt = {
|
||||
100, // dumpSize
|
||||
};
|
||||
|
||||
/** the @a MessageMap instance, or NULL. */
|
||||
static MessageMap* s_messageMap = NULL;
|
||||
/** the @a MessageMap instance, or nullptr. */
|
||||
static MessageMap* s_messageMap = nullptr;
|
||||
|
||||
/** the @a MainLoop instance, or NULL. */
|
||||
static MainLoop* s_mainLoop = NULL;
|
||||
/** the @a MainLoop instance, or nullptr. */
|
||||
static MainLoop* s_mainLoop = nullptr;
|
||||
|
||||
/** the path prefix (including trailing "/") for retrieving configuration files from local files (empty for HTTP). */
|
||||
static string s_configLocalPrefix;
|
||||
@@ -177,72 +177,72 @@ static const char argpdoc[] =
|
||||
|
||||
/** the definition of the known program arguments. */
|
||||
static const struct argp_option argpoptions[] = {
|
||||
{NULL, 0, NULL, 0, "Device options:", 1 },
|
||||
{"device", 'd', "DEV", 0, "Use DEV as eBUS device (serial or [udp:]ip:port) [/dev/ttyUSB0]", 0 },
|
||||
{"nodevicecheck", 'n', NULL, 0, "Skip serial eBUS device test", 0 },
|
||||
{"readonly", 'r', NULL, 0, "Only read from device, never write to it", 0 },
|
||||
{"initsend", O_INISND, NULL, 0, "Send an initial escape symbol after connecting device", 0 },
|
||||
{"latency", O_DEVLAT, "USEC", 0, "Transfer latency in us [0 for USB, 10000 for IP]", 0 },
|
||||
{nullptr, 0, nullptr, 0, "Device options:", 1 },
|
||||
{"device", 'd', "DEV", 0, "Use DEV as eBUS device (serial or [udp:]ip:port) [/dev/ttyUSB0]", 0 },
|
||||
{"nodevicecheck", 'n', nullptr, 0, "Skip serial eBUS device test", 0 },
|
||||
{"readonly", 'r', nullptr, 0, "Only read from device, never write to it", 0 },
|
||||
{"initsend", O_INISND, nullptr, 0, "Send an initial escape symbol after connecting device", 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 },
|
||||
{"configpath", 'c', "PATH", 0, "Read CSV config files from PATH (local folder or HTTP URL) [" CONFIG_PATH
|
||||
{nullptr, 0, nullptr, 0, "Message configuration options:", 2 },
|
||||
{"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, "
|
||||
"default is broadcast ident message). If combined with --checkconfig, you can add scan message data as "
|
||||
"arguments for checking a particular scan configuration, e.g. \"FF08070400/0AB5454850303003277201\".", 0 },
|
||||
{"configlang", O_CFGLNG, "LANG", 0,
|
||||
{"configlang", O_CFGLNG, "LANG", 0,
|
||||
"Prefer LANG in multilingual configuration files [system default language]", 0 },
|
||||
{"checkconfig", O_CHKCFG, NULL, 0, "Check CSV config files, then stop", 0 },
|
||||
{"dumpconfig", O_DMPCFG, NULL, 0, "Check and dump CSV config files, then stop", 0 },
|
||||
{"pollinterval", O_POLINT, "SEC", 0, "Poll for data every SEC seconds (0=disable) [5]", 0 },
|
||||
{"inject", 'i', NULL, 0, "Inject remaining arguments as already seen messages (e.g. "
|
||||
{"checkconfig", O_CHKCFG, nullptr, 0, "Check CSV config files, then stop", 0 },
|
||||
{"dumpconfig", O_DMPCFG, nullptr, 0, "Check and dump CSV config files, then stop", 0 },
|
||||
{"pollinterval", O_POLINT, "SEC", 0, "Poll for data every SEC seconds (0=disable) [5]", 0 },
|
||||
{"inject", 'i', nullptr, 0, "Inject remaining arguments as already seen messages (e.g. "
|
||||
"\"FF08070400/0AB5454850303003277201\")", 0 },
|
||||
|
||||
{NULL, 0, NULL, 0, "eBUS options:", 3 },
|
||||
{"address", 'a', "ADDR", 0, "Use ADDR as own bus address [31]", 0 },
|
||||
{"answer", O_ANSWER, NULL, 0, "Actively answer to requests from other masters", 0 },
|
||||
{"acquiretimeout", O_ACQTIM, "USEC", 0, "Stop bus acquisition after USEC us [9400]", 0 },
|
||||
{"acquireretries", O_ACQRET, "COUNT", 0, "Retry bus acquisition COUNT times [3]", 0 },
|
||||
{"sendretries", O_SNDRET, "COUNT", 0, "Repeat failed sends COUNT times [2]", 0 },
|
||||
{"receivetimeout", O_RCVTIM, "USEC", 0, "Expect a slave to answer within USEC us [25000]", 0 },
|
||||
{"numbermasters", O_MASCNT, "COUNT", 0, "Expect COUNT masters on the bus, 0 for auto detection [0]", 0 },
|
||||
{"generatesyn", O_GENSYN, NULL, 0, "Enable AUTO-SYN symbol generation", 0 },
|
||||
{nullptr, 0, nullptr, 0, "eBUS options:", 3 },
|
||||
{"address", 'a', "ADDR", 0, "Use ADDR as own bus address [31]", 0 },
|
||||
{"answer", O_ANSWER, nullptr, 0, "Actively answer to requests from other masters", 0 },
|
||||
{"acquiretimeout", O_ACQTIM, "USEC", 0, "Stop bus acquisition after USEC us [9400]", 0 },
|
||||
{"acquireretries", O_ACQRET, "COUNT", 0, "Retry bus acquisition COUNT times [3]", 0 },
|
||||
{"sendretries", O_SNDRET, "COUNT", 0, "Repeat failed sends COUNT times [2]", 0 },
|
||||
{"receivetimeout", O_RCVTIM, "USEC", 0, "Expect a slave to answer within USEC us [25000]", 0 },
|
||||
{"numbermasters", O_MASCNT, "COUNT", 0, "Expect COUNT masters on the bus, 0 for auto detection [0]", 0 },
|
||||
{"generatesyn", O_GENSYN, nullptr, 0, "Enable AUTO-SYN symbol generation", 0 },
|
||||
|
||||
{NULL, 0, NULL, 0, "Daemon options:", 4 },
|
||||
{"accesslevel", O_ACLDEF, "LEVEL", 0, "Set default access level to LEVEL (\"*\" for everything) [\"\"]", 0 },
|
||||
{"aclfile", O_ACLFIL, "FILE", 0, "Read access control list from FILE", 0 },
|
||||
{"foreground", 'f', NULL, 0, "Run in foreground", 0 },
|
||||
{"enablehex", O_HEXCMD, NULL, 0, "Enable hex command", 0 },
|
||||
{"enabledefine", O_DEFCMD, NULL, 0, "Enable define command", 0 },
|
||||
{"pidfile", O_PIDFIL, "FILE", 0, "PID file name (only for daemon) [" PID_FILE_NAME "]", 0 },
|
||||
{"port", 'p', "PORT", 0, "Listen for command line connections on PORT [8888]", 0 },
|
||||
{"localhost", O_LOCAL, NULL, 0, "Listen for command line connections on 127.0.0.1 interface only", 0 },
|
||||
{"httpport", O_HTTPPT, "PORT", 0, "Listen for HTTP connections on PORT, 0 to disable [0]", 0 },
|
||||
{"htmlpath", O_HTMLPA, "PATH", 0, "Path for HTML files served by HTTP port [/var/ebusd/html]", 0 },
|
||||
{"updatecheck", O_UPDCHK, "MODE", 0, "Set automatic update check to MODE (on|off) [on]", 0 },
|
||||
{nullptr, 0, nullptr, 0, "Daemon options:", 4 },
|
||||
{"accesslevel", O_ACLDEF, "LEVEL", 0, "Set default access level to LEVEL (\"*\" for everything) [\"\"]", 0 },
|
||||
{"aclfile", O_ACLFIL, "FILE", 0, "Read access control list from FILE", 0 },
|
||||
{"foreground", 'f', nullptr, 0, "Run in foreground", 0 },
|
||||
{"enablehex", O_HEXCMD, nullptr, 0, "Enable hex command", 0 },
|
||||
{"enabledefine", O_DEFCMD, nullptr, 0, "Enable define command", 0 },
|
||||
{"pidfile", O_PIDFIL, "FILE", 0, "PID file name (only for daemon) [" PID_FILE_NAME "]", 0 },
|
||||
{"port", 'p', "PORT", 0, "Listen for command line connections on PORT [8888]", 0 },
|
||||
{"localhost", O_LOCAL, nullptr, 0, "Listen for command line connections on 127.0.0.1 interface only", 0 },
|
||||
{"httpport", O_HTTPPT, "PORT", 0, "Listen for HTTP connections on PORT, 0 to disable [0]", 0 },
|
||||
{"htmlpath", O_HTMLPA, "PATH", 0, "Path for HTML files served by HTTP port [/var/ebusd/html]", 0 },
|
||||
{"updatecheck", O_UPDCHK, "MODE", 0, "Set automatic update check to MODE (on|off) [on]", 0 },
|
||||
|
||||
{NULL, 0, NULL, 0, "Log options:", 5 },
|
||||
{"logfile", 'l', "FILE", 0, "Write log to FILE (only for daemon) [" PACKAGE_LOGFILE "]", 0 },
|
||||
{"log", O_LOG, "AREAS LEVEL", 0, "Only write log for matching AREA(S) below or equal to LEVEL"
|
||||
{nullptr, 0, nullptr, 0, "Log options:", 5 },
|
||||
{"logfile", 'l', "FILE", 0, "Write log to FILE (only for daemon) [" PACKAGE_LOGFILE "]", 0 },
|
||||
{"log", O_LOG, "AREAS LEVEL", 0, "Only write log for matching AREA(S) below or equal to LEVEL"
|
||||
" (alternative to --logareas/--logevel, may be used multiple times) [all notice]", 0 },
|
||||
{"logareas", O_LOGARE, "AREAS", 0, "Only write log for matching AREA(S): main|network|bus|update|all"
|
||||
{"logareas", O_LOGARE, "AREAS", 0, "Only write log for matching AREA(S): main|network|bus|update|all"
|
||||
" [all]", 0 },
|
||||
{"loglevel", O_LOGLEV, "LEVEL", 0, "Only write log below or equal to LEVEL: error|notice|info|debug"
|
||||
{"loglevel", O_LOGLEV, "LEVEL", 0, "Only write log below or equal to LEVEL: error|notice|info|debug"
|
||||
" [notice]", 0 },
|
||||
|
||||
{NULL, 0, NULL, 0, "Raw logging options:", 6 },
|
||||
{"lograwdata", O_RAW, "bytes", OPTION_ARG_OPTIONAL,
|
||||
{nullptr, 0, nullptr, 0, "Raw logging options:", 6 },
|
||||
{"lograwdata", O_RAW, "bytes", OPTION_ARG_OPTIONAL,
|
||||
"Log messages or all received/sent bytes on the bus", 0 },
|
||||
{"lograwdatafile", O_RAWFIL, "FILE", 0, "Write raw log to FILE [" PACKAGE_LOGFILE "]", 0 },
|
||||
{"lograwdatasize", O_RAWSIZ, "SIZE", 0, "Make raw log file no larger than SIZE kB [100]", 0 },
|
||||
{"lograwdatafile", O_RAWFIL, "FILE", 0, "Write raw log to FILE [" PACKAGE_LOGFILE "]", 0 },
|
||||
{"lograwdatasize", O_RAWSIZ, "SIZE", 0, "Make raw log file no larger than SIZE kB [100]", 0 },
|
||||
|
||||
{NULL, 0, NULL, 0, "Binary dump options:", 7 },
|
||||
{"dump", 'D', NULL, 0, "Enable binary dump of received bytes", 0 },
|
||||
{"dumpfile", O_DMPFIL, "FILE", 0, "Dump received bytes to FILE [/tmp/" PACKAGE "_dump.bin]", 0 },
|
||||
{"dumpsize", O_DMPSIZ, "SIZE", 0, "Make dump file no larger than SIZE kB [100]", 0 },
|
||||
{nullptr, 0, nullptr, 0, "Binary dump options:", 7 },
|
||||
{"dump", 'D', nullptr, 0, "Enable binary dump of received bytes", 0 },
|
||||
{"dumpfile", O_DMPFIL, "FILE", 0, "Dump received bytes to FILE [/tmp/" PACKAGE "_dump.bin]", 0 },
|
||||
{"dumpsize", O_DMPSIZ, "SIZE", 0, "Make dump file no larger than SIZE kB [100]", 0 },
|
||||
|
||||
{NULL, 0, NULL, 0, NULL, 0 },
|
||||
{nullptr, 0, nullptr, 0, nullptr, 0 },
|
||||
};
|
||||
|
||||
/** the global @a DataFieldTemplates. */
|
||||
@@ -257,7 +257,7 @@ static map<string, DataFieldTemplates*> s_templatesByPath;
|
||||
/**
|
||||
* The program argument parsing function.
|
||||
* @param key the key from @a argpoptions.
|
||||
* @param arg the option argument, or NULL.
|
||||
* @param arg the option argument, or nullptr.
|
||||
* @param state the parsing state.
|
||||
*/
|
||||
error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
@@ -267,7 +267,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
switch (key) {
|
||||
// Device options:
|
||||
case 'd': // --device=/dev/ttyUSB0
|
||||
if (arg == NULL || arg[0] == 0) {
|
||||
if (arg == nullptr || arg[0] == 0) {
|
||||
argp_error(state, "invalid device");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -301,7 +301,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
|
||||
// Message configuration options:
|
||||
case 'c': // --configpath=http://ebusd.eu/config/
|
||||
if (arg == NULL || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
if (arg == nullptr || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
argp_error(state, "invalid configpath");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -417,14 +417,14 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
|
||||
// Daemon options:
|
||||
case O_ACLDEF: // --accesslevel=*
|
||||
if (arg == NULL) {
|
||||
if (arg == nullptr) {
|
||||
argp_error(state, "invalid accesslevel");
|
||||
return EINVAL;
|
||||
}
|
||||
opt->accessLevel = arg;
|
||||
break;
|
||||
case O_ACLFIL: // --aclfile=/etc/ebusd/acl
|
||||
if (arg == NULL || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
if (arg == nullptr || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
argp_error(state, "invalid aclfile");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -440,7 +440,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
opt->enableDefine = true;
|
||||
break;
|
||||
case O_PIDFIL: // --pidfile=/var/run/ebusd.pid
|
||||
if (arg == NULL || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
if (arg == nullptr || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
argp_error(state, "invalid pidfile");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -464,14 +464,14 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
}
|
||||
break;
|
||||
case O_HTMLPA: // --htmlpath=/var/ebusd/html
|
||||
if (arg == NULL || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
if (arg == nullptr || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
argp_error(state, "invalid htmlpath");
|
||||
return EINVAL;
|
||||
}
|
||||
opt->htmlPath = arg;
|
||||
break;
|
||||
case O_UPDCHK: // --updatecheck=on
|
||||
if (arg == NULL || arg[0] == 0) {
|
||||
if (arg == nullptr || arg[0] == 0) {
|
||||
argp_error(state, "invalid updatecheck");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -487,7 +487,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
|
||||
// Log options:
|
||||
case 'l': // --logfile=/var/log/ebusd.log
|
||||
if (arg == NULL || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
if (arg == nullptr || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
argp_error(state, "invalid logfile");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -496,7 +496,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
case O_LOG: // --log=area(s) level
|
||||
{
|
||||
char* pos = strchr(arg, ' ');
|
||||
if (pos == NULL) {
|
||||
if (pos == nullptr) {
|
||||
argp_error(state, "invalid log");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -547,7 +547,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
opt->logRaw = arg && strcmp("bytes", arg) == 0 ? 2 : 1;
|
||||
break;
|
||||
case O_RAWFIL: // --lograwdatafile=/var/log/ebusd.log
|
||||
if (arg == NULL || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
if (arg == nullptr || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
argp_error(state, "invalid lograwdatafile");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -567,7 +567,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
opt->dump = true;
|
||||
break;
|
||||
case O_DMPFIL: // --dumpfile=/tmp/ebusd_dump.bin
|
||||
if (arg == NULL || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
if (arg == nullptr || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
argp_error(state, "invalid dumpfile");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -633,15 +633,15 @@ void daemonize() {
|
||||
|
||||
umask(S_IWGRP | S_IRWXO); // set permissions of newly created files to 750
|
||||
|
||||
if (pidFile != NULL) {
|
||||
setbuf(pidFile, NULL); // disable buffering
|
||||
if (pidFile != nullptr) {
|
||||
setbuf(pidFile, nullptr); // disable buffering
|
||||
if (lockf(fileno(pidFile), F_TLOCK, 0) < 0
|
||||
|| fprintf(pidFile, "%d\n", getpid()) <= 0) {
|
||||
fclose(pidFile);
|
||||
pidFile = NULL;
|
||||
pidFile = nullptr;
|
||||
}
|
||||
}
|
||||
if (pidFile == NULL) {
|
||||
if (pidFile == nullptr) {
|
||||
logError(lf_main, "can't open pidfile: %s", opt.pidFile);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -650,7 +650,7 @@ void daemonize() {
|
||||
}
|
||||
|
||||
void closePidFile() {
|
||||
if (pidFile != NULL) {
|
||||
if (pidFile != nullptr) {
|
||||
if (fclose(pidFile) != 0) {
|
||||
return;
|
||||
}
|
||||
@@ -665,11 +665,11 @@ void shutdown() {
|
||||
// stop main loop and all dependent components
|
||||
if (s_mainLoop) {
|
||||
delete s_mainLoop;
|
||||
s_mainLoop = NULL;
|
||||
s_mainLoop = nullptr;
|
||||
}
|
||||
if (s_messageMap) {
|
||||
delete s_messageMap;
|
||||
s_messageMap = NULL;
|
||||
s_messageMap = nullptr;
|
||||
}
|
||||
// free templates
|
||||
for (const auto it : s_templatesByPath) {
|
||||
@@ -735,13 +735,13 @@ void signalHandler(int sig) {
|
||||
* @param extension the filename extension the files have to match.
|
||||
* @param files the @a vector to which to add the matching files.
|
||||
* @param query the query string suffix for HTTP retrieval starting with "&", or empty.
|
||||
* @param dirs the @a vector to which to add found directories (without any name check), or NULL to ignore.
|
||||
* @param hasTemplates the bool to set when the templates file was found in the path, or NULL to ignore.
|
||||
* @param dirs the @a vector to which to add found directories (without any name check), or nullptr to ignore.
|
||||
* @param hasTemplates the bool to set when the templates file was found in the path, or nullptr to ignore.
|
||||
* @return the result code.
|
||||
*/
|
||||
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, bool* hasTemplates = NULL) {
|
||||
vector<string>* dirs = nullptr, bool* hasTemplates = nullptr) {
|
||||
const string relPathWithSlash = relPath.empty() ? "" : relPath + "/";
|
||||
if (!s_configUriPrefix.empty()) {
|
||||
string uri = s_configUriPrefix + relPathWithSlash + "?t=" + extension.substr(1) + query;
|
||||
@@ -770,11 +770,11 @@ static result_t collectConfigFiles(const string& relPath, const string& prefix,
|
||||
}
|
||||
const string path = s_configLocalPrefix + relPathWithSlash;
|
||||
DIR* dir = opendir(path.c_str());
|
||||
if (dir == NULL) {
|
||||
if (dir == nullptr) {
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
}
|
||||
dirent* d;
|
||||
while ((d = readdir(dir)) != NULL) {
|
||||
while ((d = readdir(dir)) != nullptr) {
|
||||
string name = d->d_name;
|
||||
if (name == "." || name == "..") {
|
||||
continue;
|
||||
@@ -785,7 +785,7 @@ static result_t collectConfigFiles(const string& relPath, const string& prefix,
|
||||
continue;
|
||||
}
|
||||
if (S_ISDIR(stat_buf.st_mode)) {
|
||||
if (dirs != NULL) {
|
||||
if (dirs != nullptr) {
|
||||
dirs->push_back(relPathWithSlash + name);
|
||||
}
|
||||
} else if (S_ISREG(stat_buf.st_mode) && name.length() >= extension.length()
|
||||
@@ -810,7 +810,7 @@ static result_t collectConfigFiles(const string& relPath, const string& prefix,
|
||||
DataFieldTemplates* getTemplates(const string& filename) {
|
||||
if (filename == "*") {
|
||||
unsigned long maxLength = 0;
|
||||
DataFieldTemplates* best = NULL;
|
||||
DataFieldTemplates* best = nullptr;
|
||||
for (auto it : s_templatesByPath) {
|
||||
if (it.first.size() > maxLength) {
|
||||
best = it.second;
|
||||
@@ -862,7 +862,7 @@ static bool readTemplates(const string relPath, const string extension, bool ava
|
||||
string logPath = relPath.empty() ? "/" : relPath;
|
||||
logInfo(lf_main, "reading templates %s", logPath.c_str());
|
||||
string file = (relPath.empty() ? "" : relPath + "/") + "_templates" + extension;
|
||||
result_t result = loadDefinitionsFromConfigPath(templates, file, verbose, NULL, &errorDescription, true);
|
||||
result_t result = loadDefinitionsFromConfigPath(templates, file, verbose, nullptr, &errorDescription, true);
|
||||
if (result == RESULT_OK) {
|
||||
logInfo(lf_main, "read templates in %s", logPath.c_str());
|
||||
return true;
|
||||
@@ -893,7 +893,7 @@ static result_t readConfigFiles(const string& relPath, const string& extension,
|
||||
readTemplates(relPath, extension, hasTemplates, verbose);
|
||||
for (const auto& name : files) {
|
||||
logInfo(lf_main, "reading file %s", name.c_str());
|
||||
result_t result = loadDefinitionsFromConfigPath(messages, name, verbose, NULL, errorDescription);
|
||||
result_t result = loadDefinitionsFromConfigPath(messages, name, verbose, nullptr, errorDescription);
|
||||
if (result != RESULT_OK) {
|
||||
return result;
|
||||
}
|
||||
@@ -949,7 +949,7 @@ void executeInstructions(MessageMap* messages, bool verbose) {
|
||||
|
||||
result_t loadDefinitionsFromConfigPath(FileReader* reader, const string& filename, bool verbose,
|
||||
map<string, string>* defaults, string* errorDescription, bool replace) {
|
||||
istream* stream = NULL;
|
||||
istream* stream = nullptr;
|
||||
time_t mtime = 0;
|
||||
if (s_configUriPrefix.empty()) {
|
||||
stream = FileReader::openFile(s_configLocalPrefix + filename, errorDescription, &mtime);
|
||||
@@ -978,7 +978,7 @@ result_t loadConfigFiles(MessageMap* messages, bool verbose, bool denyRecursive)
|
||||
if (it.second != &s_globalTemplates) {
|
||||
delete it.second;
|
||||
}
|
||||
it.second = NULL;
|
||||
it.second = nullptr;
|
||||
}
|
||||
s_templatesByPath.clear();
|
||||
|
||||
@@ -1012,9 +1012,9 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose
|
||||
size_t offset = 0;
|
||||
size_t field = 0;
|
||||
bool fromLocal = s_configUriPrefix.empty();
|
||||
result_t result = (*identFields)[field]->read(data, offset, false, NULL, -1, 0, -1, &out); // manufacturer name
|
||||
result_t result = (*identFields)[field]->read(data, offset, false, nullptr, -1, 0, -1, &out); // manufacturer name
|
||||
if (result == RESULT_ERR_NOTFOUND && fromLocal) {
|
||||
result = (*identFields)[field]->read(data, offset, false, NULL, -1, OF_NUMERIC, -1, &out); // manufacturer name
|
||||
result = (*identFields)[field]->read(data, offset, false, nullptr, -1, OF_NUMERIC, -1, &out); // manufacturer name
|
||||
}
|
||||
if (result == RESULT_OK) {
|
||||
manufStr = out.str();
|
||||
@@ -1025,14 +1025,14 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose
|
||||
out.str("");
|
||||
out.clear();
|
||||
offset += (*identFields)[field++]->getLength(pt_slaveData, MAX_LEN);
|
||||
result = (*identFields)[field]->read(data, offset, false, NULL, -1, 0, -1, &out); // identification string
|
||||
result = (*identFields)[field]->read(data, offset, false, nullptr, -1, 0, -1, &out); // identification string
|
||||
}
|
||||
if (result == RESULT_OK) {
|
||||
ident = out.str();
|
||||
out.str("");
|
||||
out.clear();
|
||||
offset += (*identFields)[field++]->getLength(pt_slaveData, MAX_LEN);
|
||||
result = (*identFields)[field]->read(data, offset, NULL, -1, &sw); // software version number
|
||||
result = (*identFields)[field]->read(data, offset, nullptr, -1, &sw); // software version number
|
||||
if (result == RESULT_ERR_OUT_OF_RANGE) {
|
||||
sw = (data.dataAt(offset) << 16) | data.dataAt(offset+1); // use hex value instead
|
||||
result = RESULT_OK;
|
||||
@@ -1040,7 +1040,7 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose
|
||||
}
|
||||
if (result == RESULT_OK) {
|
||||
offset += (*identFields)[field++]->getLength(pt_slaveData, MAX_LEN);
|
||||
result = (*identFields)[field]->read(data, offset, NULL, -1, &hw); // hardware version number
|
||||
result = (*identFields)[field]->read(data, offset, nullptr, -1, &hw); // hardware version number
|
||||
if (result == RESULT_ERR_OUT_OF_RANGE) {
|
||||
hw = (data.dataAt(offset) << 16) | data.dataAt(offset+1); // use hex value instead
|
||||
result = RESULT_OK;
|
||||
@@ -1073,7 +1073,7 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose
|
||||
out.str("");
|
||||
out.clear();
|
||||
}
|
||||
result = collectConfigFiles(manufStr, addrStr + ".", ".csv", &files, false, query, NULL, &hasTemplates);
|
||||
result = collectConfigFiles(manufStr, addrStr + ".", ".csv", &files, false, query, nullptr, &hasTemplates);
|
||||
if (result != RESULT_OK) {
|
||||
logError(lf_main, "unable to load scan config %2.2x: list files in %s %s", address, manufStr.c_str(),
|
||||
getResultCode(result));
|
||||
@@ -1145,7 +1145,7 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose
|
||||
}
|
||||
if (baseName.length() < 3 || baseName.find_first_of('.') != 2) { // different from the scheme "ZZ."
|
||||
string errorDescription;
|
||||
result = loadDefinitionsFromConfigPath(messages, name, verbose, NULL, &errorDescription);
|
||||
result = loadDefinitionsFromConfigPath(messages, name, verbose, nullptr, &errorDescription);
|
||||
if (result == RESULT_OK) {
|
||||
logNotice(lf_main, "read common config file %s", name.c_str());
|
||||
} else {
|
||||
@@ -1213,7 +1213,7 @@ bool parseMessage(const string& arg, bool onlyMasterSlave, MasterSymbolString* m
|
||||
* @return the exit code.
|
||||
*/
|
||||
int main(int argc, char* argv[]) {
|
||||
struct argp aargp = { argpoptions, parse_opt, NULL, argpdoc, datahandler_getargs(), NULL, NULL };
|
||||
struct argp aargp = { argpoptions, parse_opt, nullptr, argpdoc, datahandler_getargs(), nullptr, nullptr };
|
||||
int arg_index = -1;
|
||||
setenv("ARGP_HELP_FMT", "no-dup-args-note", 0);
|
||||
|
||||
@@ -1287,7 +1287,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
// open the device
|
||||
Device *device = Device::create(opt.device, !opt.noDeviceCheck, opt.readOnly, opt.initialSend);
|
||||
if (device == NULL) {
|
||||
if (device == nullptr) {
|
||||
logError(lf_main, "unable to create device %s", opt.device);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
+1
-1
@@ -128,7 +128,7 @@ void executeInstructions(MessageMap* messages, bool verbose = false);
|
||||
* @param reader the @a FileReader instance to load with the definitions.
|
||||
* @param filename the relative name of the file being read.
|
||||
* @param verbose whether to verbosely log problems.
|
||||
* @param defaults the default values by name (potentially overwritten by file name), or NULL to not use defaults.
|
||||
* @param defaults the default values by name (potentially overwritten by file name), or nullptr to not use defaults.
|
||||
* @param errorDescription a string in which to store the error description in case of error.
|
||||
* @param replace whether to replace an already existing entry.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
|
||||
+37
-37
@@ -114,14 +114,14 @@ MainLoop::MainLoop(const struct options& opt, Device *device, MessageMap* messag
|
||||
m_dumpFile = new RotateFile(opt.dumpFile, opt.dumpSize);
|
||||
m_dumpFile->setEnabled(opt.dump);
|
||||
} else {
|
||||
m_dumpFile = NULL;
|
||||
m_dumpFile = nullptr;
|
||||
}
|
||||
m_logRawEnabled = opt.logRaw != 0;
|
||||
if (opt.logRawFile[0] && strcmp(opt.logRawFile, opt.logFile) != 0) {
|
||||
m_logRawFile = new RotateFile(opt.logRawFile, opt.logRawSize, true);
|
||||
m_logRawFile->setEnabled(m_logRawEnabled);
|
||||
} else {
|
||||
m_logRawFile = NULL;
|
||||
m_logRawFile = nullptr;
|
||||
}
|
||||
m_logRawBytes = opt.logRaw == 2;
|
||||
m_logRawLastReceived = true;
|
||||
@@ -131,7 +131,7 @@ MainLoop::MainLoop(const struct options& opt, Device *device, MessageMap* messag
|
||||
time_t mtime = 0;
|
||||
istream* stream = FileReader::openFile(opt.aclFile, &errorDescription, &mtime);
|
||||
if (stream) {
|
||||
result = m_userList.readFromStream(stream, opt.aclFile, mtime, false, NULL, &errorDescription);
|
||||
result = m_userList.readFromStream(stream, opt.aclFile, mtime, false, nullptr, &errorDescription);
|
||||
delete(stream);
|
||||
} else {
|
||||
result = RESULT_ERR_NOTFOUND;
|
||||
@@ -165,7 +165,7 @@ MainLoop::MainLoop(const struct options& opt, Device *device, MessageMap* messag
|
||||
} else {
|
||||
logError(lf_main, "error registering data handlers");
|
||||
}
|
||||
m_newlyDefinedMessages = opt.enableDefine ? new MessageMap(true, "", false) : NULL;
|
||||
m_newlyDefinedMessages = opt.enableDefine ? new MessageMap(true, "", false) : nullptr;
|
||||
}
|
||||
|
||||
MainLoop::~MainLoop() {
|
||||
@@ -178,31 +178,31 @@ MainLoop::~MainLoop() {
|
||||
m_dataHandlers.clear();
|
||||
if (m_dumpFile) {
|
||||
delete m_dumpFile;
|
||||
m_dumpFile = NULL;
|
||||
m_dumpFile = nullptr;
|
||||
}
|
||||
if (m_logRawFile) {
|
||||
delete m_logRawFile;
|
||||
m_logRawFile = NULL;
|
||||
m_logRawFile = nullptr;
|
||||
}
|
||||
if (m_network != NULL) {
|
||||
if (m_network != nullptr) {
|
||||
delete m_network;
|
||||
m_network = NULL;
|
||||
m_network = nullptr;
|
||||
}
|
||||
if (m_busHandler != NULL) {
|
||||
if (m_busHandler != nullptr) {
|
||||
delete m_busHandler;
|
||||
m_busHandler = NULL;
|
||||
m_busHandler = nullptr;
|
||||
}
|
||||
if (m_device != NULL) {
|
||||
if (m_device != nullptr) {
|
||||
delete m_device;
|
||||
m_device = NULL;
|
||||
m_device = nullptr;
|
||||
}
|
||||
NetMessage* msg;
|
||||
while ((msg = m_netQueue.pop()) != NULL) {
|
||||
while ((msg = m_netQueue.pop()) != nullptr) {
|
||||
delete msg;
|
||||
}
|
||||
if (m_newlyDefinedMessages) {
|
||||
delete m_newlyDefinedMessages;
|
||||
m_newlyDefinedMessages = NULL;
|
||||
m_newlyDefinedMessages = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,7 +367,7 @@ void MainLoop::run() {
|
||||
}
|
||||
sinkSince = now;
|
||||
}
|
||||
if (netMessage == NULL) {
|
||||
if (netMessage == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (m_shutdown) {
|
||||
@@ -406,7 +406,7 @@ void MainLoop::run() {
|
||||
m_messages->findAll("", "", levels, false, true, true, true, true, true, since, now, &messages);
|
||||
for (const auto message : messages) {
|
||||
ostream << message->getCircuit() << " " << message->getName() << " = " << dec;
|
||||
message->decodeLastData(false, NULL, -1, 0, &ostream);
|
||||
message->decodeLastData(false, nullptr, -1, 0, &ostream);
|
||||
ostream << endl;
|
||||
}
|
||||
}
|
||||
@@ -791,7 +791,7 @@ result_t MainLoop::executeRead(const vector<string>& args, const string& levels,
|
||||
// find message
|
||||
Message* message = m_messages->find(master, false, true, false, false);
|
||||
|
||||
if (message == NULL) {
|
||||
if (message == nullptr) {
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
}
|
||||
if (!message->hasLevel(levels)) {
|
||||
@@ -820,7 +820,7 @@ result_t MainLoop::executeRead(const vector<string>& args, const string& levels,
|
||||
ret = message->storeLastData(master, slave);
|
||||
ostringstream result;
|
||||
if (ret == RESULT_OK) {
|
||||
ret = message->decodeLastData(false, NULL, -1, 0, &result);
|
||||
ret = message->decodeLastData(false, nullptr, -1, 0, &result);
|
||||
}
|
||||
if (ret >= RESULT_OK) {
|
||||
logInfo(lf_main, "read hex %s %s cache update: %s", message->getCircuit().c_str(), message->getName().c_str(),
|
||||
@@ -861,7 +861,7 @@ result_t MainLoop::executeRead(const vector<string>& args, const string& levels,
|
||||
string errorDescription;
|
||||
istringstream defstr("#\n" + args[argPos]); // ensure first line is not used for determining col names
|
||||
m_newlyDefinedMessages->clear();
|
||||
ret = m_newlyDefinedMessages->readFromStream(&defstr, "temporary", now, true, NULL, &errorDescription);
|
||||
ret = m_newlyDefinedMessages->readFromStream(&defstr, "temporary", now, true, nullptr, &errorDescription);
|
||||
if (ret != RESULT_OK) {
|
||||
*ostream << "ERR: bad definition: " << errorDescription;
|
||||
return RESULT_OK;
|
||||
@@ -878,13 +878,13 @@ result_t MainLoop::executeRead(const vector<string>& args, const string& levels,
|
||||
message = m_messages->find(circuit, name, levels, false);
|
||||
}
|
||||
// adjust poll priority
|
||||
if (!newDefinition && message != NULL && pollPriority > 0 && message->setPollPriority(pollPriority)) {
|
||||
if (!newDefinition && message != nullptr && pollPriority > 0 && message->setPollPriority(pollPriority)) {
|
||||
m_messages->addPollMessage(false, message);
|
||||
}
|
||||
verbosity |= valueName ? OF_VALUENAME : numeric ? OF_NUMERIC : 0;
|
||||
bool allowCache = !newDefinition && srcAddress == SYN && dstAddress == SYN && maxAge > 0 && params.length() == 0;
|
||||
Message* cacheMessage = allowCache ? m_messages->find(circuit, name, levels, false, true) : NULL;
|
||||
bool hasCache = cacheMessage != NULL;
|
||||
Message* cacheMessage = allowCache ? m_messages->find(circuit, name, levels, false, true) : nullptr;
|
||||
bool hasCache = cacheMessage != nullptr;
|
||||
if (!hasCache || (allowCache && message && message->getLastUpdateTime() > cacheMessage->getLastUpdateTime())) {
|
||||
cacheMessage = message; // message is newer/better
|
||||
}
|
||||
@@ -893,7 +893,7 @@ result_t MainLoop::executeRead(const vector<string>& args, const string& levels,
|
||||
if (verbosity & OF_NAMES) {
|
||||
*ostream << cacheMessage->getCircuit() << " " << cacheMessage->getName() << " ";
|
||||
}
|
||||
ret = cacheMessage->decodeLastData(false, fieldIndex == -2 ? NULL : fieldName.c_str(), fieldIndex, verbosity,
|
||||
ret = cacheMessage->decodeLastData(false, fieldIndex == -2 ? nullptr : fieldName.c_str(), fieldIndex, verbosity,
|
||||
ostream);
|
||||
if (ret != RESULT_OK) {
|
||||
if (ret < RESULT_OK) {
|
||||
@@ -912,7 +912,7 @@ result_t MainLoop::executeRead(const vector<string>& args, const string& levels,
|
||||
return RESULT_OK;
|
||||
} // else: read directly from bus
|
||||
|
||||
if (message == NULL) {
|
||||
if (message == nullptr) {
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
}
|
||||
if (message->getDstAddress() == SYN && dstAddress == SYN) {
|
||||
@@ -926,7 +926,7 @@ result_t MainLoop::executeRead(const vector<string>& args, const string& levels,
|
||||
if (verbosity & OF_NAMES) {
|
||||
*ostream << message->getCircuit() << " " << message->getName() << " ";
|
||||
}
|
||||
ret = message->decodeLastData(false, false, fieldIndex == -2 ? NULL : fieldName.c_str(), fieldIndex, verbosity,
|
||||
ret = message->decodeLastData(false, false, fieldIndex == -2 ? nullptr : fieldName.c_str(), fieldIndex, verbosity,
|
||||
ostream);
|
||||
if (ret < RESULT_OK) {
|
||||
logError(lf_main, "read %s %s: decode %s", message->getCircuit().c_str(), message->getName().c_str(),
|
||||
@@ -1023,7 +1023,7 @@ result_t MainLoop::executeWrite(const vector<string>& args, const string levels,
|
||||
// find message
|
||||
Message* message = m_messages->find(master, false, false, true, false);
|
||||
|
||||
if (message == NULL) {
|
||||
if (message == nullptr) {
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
}
|
||||
if (!message->hasLevel(levels)) {
|
||||
@@ -1044,7 +1044,7 @@ result_t MainLoop::executeWrite(const vector<string>& args, const string levels,
|
||||
ret = message->storeLastData(master, slave);
|
||||
ostringstream result;
|
||||
if (ret == RESULT_OK) {
|
||||
ret = message->decodeLastData(false, NULL, -1, 0, &result);
|
||||
ret = message->decodeLastData(false, nullptr, -1, 0, &result);
|
||||
}
|
||||
if (ret >= RESULT_OK) {
|
||||
logInfo(lf_main, "write hex %s %s cache update: %s", message->getCircuit().c_str(),
|
||||
@@ -1076,7 +1076,7 @@ result_t MainLoop::executeWrite(const vector<string>& args, const string levels,
|
||||
string errorDescription;
|
||||
istringstream defstr("#\n" + args[argPos]); // ensure first line is not used for determining col names
|
||||
m_newlyDefinedMessages->clear();
|
||||
ret = m_newlyDefinedMessages->readFromStream(&defstr, "temporary", now, true, NULL, &errorDescription);
|
||||
ret = m_newlyDefinedMessages->readFromStream(&defstr, "temporary", now, true, nullptr, &errorDescription);
|
||||
if (ret != RESULT_OK) {
|
||||
*ostream << "ERR: bad definition: " << errorDescription;
|
||||
return RESULT_OK;
|
||||
@@ -1092,7 +1092,7 @@ result_t MainLoop::executeWrite(const vector<string>& args, const string levels,
|
||||
message = m_messages->find(circuit, args[argPos], levels, true);
|
||||
}
|
||||
|
||||
if (message == NULL) {
|
||||
if (message == nullptr) {
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
}
|
||||
if (message->getDstAddress() == SYN && dstAddress == SYN) {
|
||||
@@ -1115,7 +1115,7 @@ result_t MainLoop::executeWrite(const vector<string>& args, const string levels,
|
||||
return RESULT_OK;
|
||||
}
|
||||
|
||||
ret = message->decodeLastData(false, false, NULL, -1, 0, ostream); // decode data
|
||||
ret = message->decodeLastData(false, false, nullptr, -1, 0, ostream); // decode data
|
||||
if (ret >= RESULT_OK && ostream->str().empty()) {
|
||||
logNotice(lf_main, "write %s %s: decode %s", message->getCircuit().c_str(), message->getName().c_str(),
|
||||
getResultCode(ret));
|
||||
@@ -1341,7 +1341,7 @@ result_t MainLoop::executeFind(const vector<string>& args, const string& levels,
|
||||
if (found) {
|
||||
*ostream << endl;
|
||||
}
|
||||
message->dump(NULL, withConditions, ostream);
|
||||
message->dump(nullptr, withConditions, ostream);
|
||||
} else if (!fieldNames.empty()) {
|
||||
if (found) {
|
||||
*ostream << endl;
|
||||
@@ -1360,7 +1360,7 @@ result_t MainLoop::executeFind(const vector<string>& args, const string& levels,
|
||||
} else if (hexFormat) {
|
||||
*ostream << message->getLastMasterData().getStr() << " / " << message->getLastSlaveData().getStr();
|
||||
} else {
|
||||
result_t ret = message->decodeLastData(false, NULL, -1, verbosity, ostream);
|
||||
result_t ret = message->decodeLastData(false, nullptr, -1, verbosity, ostream);
|
||||
if (ret != RESULT_OK) {
|
||||
*ostream << " (" << getResultCode(ret)
|
||||
<< " for " << message->getLastMasterData().getStr()
|
||||
@@ -1493,7 +1493,7 @@ result_t MainLoop::executeDefine(const vector<string>& args, ostringstream* ostr
|
||||
time(&now);
|
||||
string errorDescription;
|
||||
istringstream defstr("#\n" + args[argPos]); // ensure first line is not used for determining col names
|
||||
return m_messages->readFromStream(&defstr, "temporary", now, true, NULL, &errorDescription, replace);
|
||||
return m_messages->readFromStream(&defstr, "temporary", now, true, nullptr, &errorDescription, replace);
|
||||
}
|
||||
|
||||
|
||||
@@ -1553,7 +1553,7 @@ result_t MainLoop::executeDecode(const vector<string>& args, ostringstream* ostr
|
||||
string errorDescription;
|
||||
DataFieldTemplates* templates = getTemplates("*");
|
||||
LoadableDataFieldSet fields("", templates);
|
||||
result_t ret = fields.readFromStream(&defstr, "temporary", now, true, NULL, &errorDescription);
|
||||
result_t ret = fields.readFromStream(&defstr, "temporary", now, true, nullptr, &errorDescription);
|
||||
if (ret != RESULT_OK) {
|
||||
return ret;
|
||||
}
|
||||
@@ -1564,7 +1564,7 @@ result_t MainLoop::executeDecode(const vector<string>& args, ostringstream* ostr
|
||||
return ret;
|
||||
}
|
||||
slave.adjustHeader();
|
||||
return fields.read(slave, 0, false, NULL, -1, verbosity, -1, ostream);
|
||||
return fields.read(slave, 0, false, nullptr, -1, verbosity, -1, ostream);
|
||||
}
|
||||
|
||||
|
||||
@@ -1585,13 +1585,13 @@ result_t MainLoop::executeEncode(const vector<string>& args, ostringstream* ostr
|
||||
string errorDescription;
|
||||
DataFieldTemplates* templates = getTemplates("*");
|
||||
LoadableDataFieldSet fields("", templates);
|
||||
result_t ret = fields.readFromStream(&defstr, "temporary", now, true, NULL, &errorDescription);
|
||||
result_t ret = fields.readFromStream(&defstr, "temporary", now, true, nullptr, &errorDescription);
|
||||
if (ret != RESULT_OK) {
|
||||
return ret;
|
||||
}
|
||||
istringstream datastr(args[argPos+1]);
|
||||
SlaveSymbolString slave;
|
||||
ret = fields.write(UI_FIELD_SEPARATOR, 0, &datastr, &slave, NULL);
|
||||
ret = fields.write(UI_FIELD_SEPARATOR, 0, &datastr, &slave, nullptr);
|
||||
if (ret != RESULT_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -354,10 +354,10 @@ class MainLoop : public Thread, DeviceListener {
|
||||
/** the number of reconnects requested from the @a Device. */
|
||||
unsigned int m_reconnectCount;
|
||||
|
||||
/** the @a RotateFile for writing sent/received bytes in log format, or NULL. */
|
||||
/** the @a RotateFile for writing sent/received bytes in log format, or nullptr. */
|
||||
RotateFile* m_logRawFile;
|
||||
|
||||
/** whether raw logging to @p logNotice is enabled (only relevant if m_logRawFile is NULL). */
|
||||
/** whether raw logging to @p logNotice is enabled (only relevant if m_logRawFile is nullptr). */
|
||||
bool m_logRawEnabled;
|
||||
|
||||
/** whether to log raw bytes instead of messages with @a m_logRawEnabled. */
|
||||
@@ -372,7 +372,7 @@ class MainLoop : public Thread, DeviceListener {
|
||||
/** the last sent/received symbol.*/
|
||||
symbol_t m_logRawLastSymbol;
|
||||
|
||||
/** the @a RotateFile for dumping received data, or NULL. */
|
||||
/** the @a RotateFile for dumping received data, or nullptr. */
|
||||
RotateFile* m_dumpFile;
|
||||
|
||||
/** the @a UserList instance. */
|
||||
@@ -397,7 +397,7 @@ class MainLoop : public Thread, DeviceListener {
|
||||
/** whether to enable the hex command. */
|
||||
const bool m_enableHex;
|
||||
|
||||
/** the MessageMap for handling newly defined messages for testing (if enabled), or NULL. */
|
||||
/** the MessageMap for handling newly defined messages for testing (if enabled), or nullptr. */
|
||||
MessageMap* m_newlyDefinedMessages;
|
||||
|
||||
/** set to true to shutdown. */
|
||||
|
||||
+46
-47
@@ -43,31 +43,30 @@ using std::dec;
|
||||
|
||||
/** the definition of the MQTT arguments. */
|
||||
static const struct argp_option g_mqtt_argp_options[] = {
|
||||
{NULL, 0, NULL, 0, "MQTT options:", 1 },
|
||||
{"mqtthost", O_HOST, "HOST", 0, "Connect to MQTT broker on HOST [localhost]", 0 },
|
||||
{"mqttport", O_PORT, "PORT", 0, "Connect to MQTT broker on PORT (usually 1883), 0 to disable [0]", 0 },
|
||||
{"mqttuser", O_USER, "USER", 0, "Connect as USER to MQTT broker (no default)", 0 },
|
||||
{"mqttpass", O_PASS, "PASSWORD", 0, "Use PASSWORD when connecting to MQTT broker (no default)", 0 },
|
||||
{"mqtttopic", O_TOPI, "TOPIC", 0, "Use MQTT TOPIC (prefix before /%circuit/%name or complete format) [ebusd]",
|
||||
0 },
|
||||
{"mqttretain", O_RETA, NULL, 0, "Retain all topics instead of only selected global ones", 0 },
|
||||
{"mqttjson", O_JSON, NULL, 0, "Publish in JSON format instead of strings", 0 },
|
||||
{"mqttignoreinvalid", O_IGIN, NULL, 0, "Ignore invalid parameters during init (e.g. for DNS not resolvable yet)", 0 },
|
||||
{nullptr, 0, nullptr, 0, "MQTT options:", 1 },
|
||||
{"mqtthost", O_HOST, "HOST", 0, "Connect to MQTT broker on HOST [localhost]", 0 },
|
||||
{"mqttport", O_PORT, "PORT", 0, "Connect to MQTT broker on PORT (usually 1883), 0 to disable [0]", 0 },
|
||||
{"mqttuser", O_USER, "USER", 0, "Connect as USER to MQTT broker (no default)", 0 },
|
||||
{"mqttpass", O_PASS, "PASSWORD", 0, "Use PASSWORD when connecting to MQTT broker (no default)", 0 },
|
||||
{"mqtttopic", O_TOPI, "TOPIC", 0, "Use MQTT TOPIC (prefix before /%circuit/%name or complete format) [ebusd]", 0 },
|
||||
{"mqttretain", O_RETA, nullptr, 0, "Retain all topics instead of only selected global ones", 0 },
|
||||
{"mqttjson", O_JSON, nullptr, 0, "Publish in JSON format instead of strings", 0 },
|
||||
{"mqttignoreinvalid", O_IGIN, nullptr, 0, "Ignore invalid parameters during init (e.g. for DNS not resolvable yet)", 0 },
|
||||
|
||||
#if (LIBMOSQUITTO_MAJOR >= 1)
|
||||
{"mqttca", O_CAFI, "CA", 0, "Use CA file or dir (ending with '/') for MQTT TLS (no default)", 0 },
|
||||
{"mqttcert", O_CERT, "CERTFILE", 0, "Use CERTFILE for MQTT TLS client certificate (no default)", 0 },
|
||||
{"mqttkey", O_KEYF, "KEYFILE", 0, "Use KEYFILE for MQTT TLS client certificate (no default)", 0 },
|
||||
{"mqttkeypass", O_KEPA, "PASSWORD", 0, "Use PASSWORD for the encrypted KEYFILE (no default)", 0 },
|
||||
{"mqttca", O_CAFI, "CA", 0, "Use CA file or dir (ending with '/') for MQTT TLS (no default)", 0 },
|
||||
{"mqttcert", O_CERT, "CERTFILE", 0, "Use CERTFILE for MQTT TLS client certificate (no default)", 0 },
|
||||
{"mqttkey", O_KEYF, "KEYFILE", 0, "Use KEYFILE for MQTT TLS client certificate (no default)", 0 },
|
||||
{"mqttkeypass", O_KEPA, "PASSWORD", 0, "Use PASSWORD for the encrypted KEYFILE (no default)", 0 },
|
||||
#endif
|
||||
|
||||
{NULL, 0, NULL, 0, NULL, 0 },
|
||||
{nullptr, 0, nullptr, 0, nullptr, 0 },
|
||||
};
|
||||
|
||||
static const char* g_host = "localhost"; //!< host name of MQTT broker [localhost]
|
||||
static uint16_t g_port = 0; //!< optional port of MQTT broker, 0 to disable [0]
|
||||
static const char* g_username = NULL; //!< optional user name for MQTT broker (no default)
|
||||
static const char* g_password = NULL; //!< optional password for MQTT broker (no default)
|
||||
static const char* g_username = nullptr; //!< optional user name for MQTT broker (no default)
|
||||
static const char* g_password = nullptr; //!< optional password for MQTT broker (no default)
|
||||
/** the MQTT topic string parts. */
|
||||
static vector<string> g_topicStrs;
|
||||
/** the MQTT topic field parts. */
|
||||
@@ -77,11 +76,11 @@ static OutputFormat g_publishFormat = 0; //!< the OutputFormat for publishing m
|
||||
static bool g_ignoreInvalidParams = false; //!< ignore invalid parameters during init
|
||||
|
||||
#if (LIBMOSQUITTO_MAJOR >= 1)
|
||||
static const char* g_cafile = NULL; //!< CA file for TLS
|
||||
static const char* g_capath = NULL; //!< CA path for TLS
|
||||
static const char* g_certfile = NULL; //!< client certificate file for TLS
|
||||
static const char* g_keyfile = NULL; //!< client key file for TLS
|
||||
static const char* g_keypass = NULL; //!< client key file password for TLS
|
||||
static const char* g_cafile = nullptr; //!< CA file for TLS
|
||||
static const char* g_capath = nullptr; //!< CA path for TLS
|
||||
static const char* g_certfile = nullptr; //!< client certificate file for TLS
|
||||
static const char* g_keyfile = nullptr; //!< client key file for TLS
|
||||
static const char* g_keypass = nullptr; //!< client key file password for TLS
|
||||
#endif
|
||||
|
||||
bool parseTopic(const string& topic, vector<string>* strs, vector<string>* fields);
|
||||
@@ -89,7 +88,7 @@ bool parseTopic(const string& topic, vector<string>* strs, vector<string>* field
|
||||
/**
|
||||
* The MQTT argument parsing function.
|
||||
* @param key the key from @a g_mqtt_argp_options.
|
||||
* @param arg the option argument, or NULL.
|
||||
* @param arg the option argument, or nullptr.
|
||||
* @param state the parsing state.
|
||||
*/
|
||||
static error_t mqtt_parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
@@ -97,7 +96,7 @@ static error_t mqtt_parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
|
||||
switch (key) {
|
||||
case O_HOST: // --mqtthost=localhost
|
||||
if (arg == NULL || arg[0] == 0) {
|
||||
if (arg == nullptr || arg[0] == 0) {
|
||||
argp_error(state, "invalid mqtthost");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -113,7 +112,7 @@ static error_t mqtt_parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
break;
|
||||
|
||||
case O_USER: // --mqttuser=username
|
||||
if (arg == NULL) {
|
||||
if (arg == nullptr) {
|
||||
argp_error(state, "invalid mqttuser");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -121,7 +120,7 @@ static error_t mqtt_parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
break;
|
||||
|
||||
case O_PASS: // --mqttpass=password
|
||||
if (arg == NULL) {
|
||||
if (arg == nullptr) {
|
||||
argp_error(state, "invalid mqttpass");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -129,7 +128,7 @@ static error_t mqtt_parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
break;
|
||||
|
||||
case O_TOPI: // --mqtttopic=ebusd
|
||||
if (arg == NULL || arg[0] == 0 || strchr(arg, '#') || strchr(arg, '+') || arg[strlen(arg)-1] == '/') {
|
||||
if (arg == nullptr || arg[0] == 0 || strchr(arg, '#') || strchr(arg, '+') || arg[strlen(arg)-1] == '/') {
|
||||
argp_error(state, "invalid mqtttopic");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -152,21 +151,21 @@ static error_t mqtt_parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
|
||||
#if (LIBMOSQUITTO_MAJOR >= 1)
|
||||
case O_CAFI: // --mqttca=file or --mqttca=dir/
|
||||
if (arg == NULL || arg[0] == 0) {
|
||||
if (arg == nullptr || arg[0] == 0) {
|
||||
argp_error(state, "invalid mqttca");
|
||||
return EINVAL;
|
||||
}
|
||||
if (arg[strlen(arg)-1] == '/') {
|
||||
g_cafile = NULL;
|
||||
g_cafile = nullptr;
|
||||
g_capath = arg;
|
||||
} else {
|
||||
g_cafile = arg;
|
||||
g_capath = NULL;
|
||||
g_capath = nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case O_CERT: // --mqttcert=CERTFILE
|
||||
if (arg == NULL || arg[0] == 0) {
|
||||
if (arg == nullptr || arg[0] == 0) {
|
||||
argp_error(state, "invalid mqttcert");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -174,7 +173,7 @@ static error_t mqtt_parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
break;
|
||||
|
||||
case O_KEYF: // --mqttkey=KEYFILE
|
||||
if (arg == NULL || arg[0] == 0) {
|
||||
if (arg == nullptr || arg[0] == 0) {
|
||||
argp_error(state, "invalid mqttkey");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -182,7 +181,7 @@ static error_t mqtt_parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
break;
|
||||
|
||||
case O_KEPA: // --mqttkeypass=PASSWORD
|
||||
if (arg == NULL) {
|
||||
if (arg == nullptr) {
|
||||
argp_error(state, "invalid mqttkeypass");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -196,7 +195,7 @@ static error_t mqtt_parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct argp g_mqtt_argp = { g_mqtt_argp_options, mqtt_parse_opt, NULL, NULL, NULL, NULL, NULL };
|
||||
static const struct argp g_mqtt_argp = { g_mqtt_argp_options, mqtt_parse_opt, nullptr, nullptr, nullptr, nullptr, nullptr };
|
||||
static const struct argp_child g_mqtt_argp_child = {&g_mqtt_argp, 0, "", 1};
|
||||
|
||||
|
||||
@@ -211,7 +210,7 @@ bool mqtthandler_register(UserInfo* userInfo, BusHandler* busHandler, MessageMap
|
||||
list<DataHandler*>* handlers) {
|
||||
if (g_port > 0) {
|
||||
int major = -1;
|
||||
mosquitto_lib_version(&major, NULL, NULL);
|
||||
mosquitto_lib_version(&major, nullptr, nullptr);
|
||||
if (major != LIBMOSQUITTO_MAJOR) {
|
||||
logOtherError("mqtt", "invalid mosquitto version %d instead of %d", major, LIBMOSQUITTO_MAJOR);
|
||||
return false;
|
||||
@@ -311,7 +310,7 @@ MqttHandler::MqttHandler(UserInfo* userInfo, BusHandler* busHandler, MessageMap*
|
||||
: DataSink(userInfo, "mqtt"), DataSource(busHandler), WaitThread(), m_messages(messages), m_connected(false),
|
||||
m_initialConnectFailed(false), m_lastUpdateCheckResult(".") {
|
||||
m_publishByField = false;
|
||||
m_mosquitto = NULL;
|
||||
m_mosquitto = nullptr;
|
||||
if (g_topicFields.empty()) {
|
||||
if (g_topicStrs.empty()) {
|
||||
g_topicStrs.push_back("");
|
||||
@@ -332,8 +331,8 @@ MqttHandler::MqttHandler(UserInfo* userInfo, BusHandler* busHandler, MessageMap*
|
||||
}
|
||||
}
|
||||
}
|
||||
m_globalTopic = getTopic(NULL, "global/");
|
||||
m_mosquitto = NULL;
|
||||
m_globalTopic = getTopic(nullptr, "global/");
|
||||
m_mosquitto = nullptr;
|
||||
if (mosquitto_lib_init() != MOSQ_ERR_SUCCESS) {
|
||||
logOtherError("mqtt", "unable to initialize");
|
||||
} else {
|
||||
@@ -391,7 +390,7 @@ MqttHandler::MqttHandler(UserInfo* userInfo, BusHandler* busHandler, MessageMap*
|
||||
if (ret == MOSQ_ERR_INVAL && !g_ignoreInvalidParams) {
|
||||
logOtherError("mqtt", "unable to connect (invalid parameters)");
|
||||
mosquitto_destroy(m_mosquitto);
|
||||
m_mosquitto = NULL;
|
||||
m_mosquitto = nullptr;
|
||||
} else if (ret != MOSQ_ERR_SUCCESS) {
|
||||
m_connected = false;
|
||||
m_initialConnectFailed = g_ignoreInvalidParams;
|
||||
@@ -413,7 +412,7 @@ MqttHandler::~MqttHandler() {
|
||||
join();
|
||||
if (m_mosquitto) {
|
||||
mosquitto_destroy(m_mosquitto);
|
||||
m_mosquitto = NULL;
|
||||
m_mosquitto = nullptr;
|
||||
}
|
||||
mosquitto_lib_cleanup();
|
||||
}
|
||||
@@ -501,10 +500,10 @@ void MqttHandler::notifyTopic(const string& topic, const string& data) {
|
||||
}
|
||||
logOtherInfo("mqtt", "received topic for %s %s", circuit.c_str(), name.c_str());
|
||||
Message* message = m_messages->find(circuit, name, m_levels, isWrite);
|
||||
if (message == NULL) {
|
||||
if (message == nullptr) {
|
||||
message = m_messages->find(circuit, name, m_levels, isWrite, true);
|
||||
}
|
||||
if (message == NULL) {
|
||||
if (message == nullptr) {
|
||||
logOtherError("mqtt", "%s message %s %s not found", isWrite?"write":"read", circuit.c_str(), name.c_str());
|
||||
return;
|
||||
}
|
||||
@@ -543,8 +542,8 @@ void MqttHandler::run() {
|
||||
publishTopic(m_globalTopic+"running", "true", true);
|
||||
publishTopic(signalTopic, "false");
|
||||
mosquitto_message_callback_set(m_mosquitto, on_message);
|
||||
string subTopic = getTopic(NULL, "#");
|
||||
mosquitto_subscribe(m_mosquitto, NULL, subTopic.c_str(), 0);
|
||||
string subTopic = getTopic(nullptr, "#");
|
||||
mosquitto_subscribe(m_mosquitto, nullptr, subTopic.c_str(), 0);
|
||||
bool allowReconnect = false;
|
||||
while (isRunning()) {
|
||||
handleTraffic(allowReconnect);
|
||||
@@ -675,7 +674,7 @@ void MqttHandler::publishMessage(const Message* message, ostringstream* updates)
|
||||
if (json) {
|
||||
*updates << "{";
|
||||
}
|
||||
result_t result = message->decodeLastData(false, NULL, -1, outputFormat, updates);
|
||||
result_t result = message->decodeLastData(false, nullptr, -1, outputFormat, updates);
|
||||
if (result != RESULT_OK) {
|
||||
logOtherError("mqtt", "decode %s %s: %s", message->getCircuit().c_str(), message->getName().c_str(),
|
||||
getResultCode(result));
|
||||
@@ -692,7 +691,7 @@ void MqttHandler::publishMessage(const Message* message, ostringstream* updates)
|
||||
}
|
||||
for (size_t index = 0; index < message->getFieldCount(); index++) {
|
||||
string name = message->getFieldName(index);
|
||||
result_t result = message->decodeLastData(false, NULL, index, outputFormat, updates);
|
||||
result_t result = message->decodeLastData(false, nullptr, index, outputFormat, updates);
|
||||
if (result != RESULT_OK) {
|
||||
logOtherError("mqtt", "decode %s %s %s: %s", message->getCircuit().c_str(), message->getName().c_str(),
|
||||
name.c_str(), getResultCode(result));
|
||||
@@ -706,7 +705,7 @@ void MqttHandler::publishMessage(const Message* message, ostringstream* updates)
|
||||
|
||||
void MqttHandler::publishTopic(const string& topic, const string& data, bool retain) {
|
||||
logOtherDebug("mqtt", "publish %s %s", topic.c_str(), data.c_str());
|
||||
mosquitto_publish(m_mosquitto, NULL, topic.c_str(), (uint32_t)data.size(),
|
||||
mosquitto_publish(m_mosquitto, nullptr, topic.c_str(), (uint32_t)data.size(),
|
||||
reinterpret_cast<const uint8_t*>(data.c_str()), 0, g_retain || retain);
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ class MqttHandler : public DataSink, public DataSource, public WaitThread {
|
||||
/** whether to publish a separate topic for each message field. */
|
||||
bool m_publishByField;
|
||||
|
||||
/** the mosquitto structure if initialized, or NULL. */
|
||||
/** the mosquitto structure if initialized, or nullptr. */
|
||||
struct mosquitto* m_mosquitto;
|
||||
|
||||
/** whether the connection to the broker is established. */
|
||||
|
||||
+11
-11
@@ -111,13 +111,13 @@ void Connection::run() {
|
||||
while (!closed) {
|
||||
#ifdef HAVE_PPOLL
|
||||
// wait for new fd event
|
||||
ret = ppoll(fds, nfds, &tdiff, NULL);
|
||||
ret = ppoll(fds, nfds, &tdiff, nullptr);
|
||||
#else
|
||||
#ifdef HAVE_PSELECT
|
||||
// set readfds to inital checkfds
|
||||
fd_set readfds = checkfds;
|
||||
// wait for new fd event
|
||||
ret = pselect(maxfd + 1, &readfds, NULL, &exceptfds, &tdiff, NULL);
|
||||
ret = pselect(maxfd + 1, &readfds, nullptr, &exceptfds, &tdiff, nullptr);
|
||||
#endif
|
||||
#endif
|
||||
bool newData = false;
|
||||
@@ -184,7 +184,7 @@ void Connection::run() {
|
||||
}
|
||||
|
||||
delete m_socket;
|
||||
m_socket = NULL;
|
||||
m_socket = nullptr;
|
||||
logInfo(lf_network, "[%05d] connection closed", getID());
|
||||
}
|
||||
|
||||
@@ -193,21 +193,21 @@ Network::Network(const bool local, const uint16_t port, const uint16_t httpPort,
|
||||
: Thread(), m_netQueue(netQueue), m_listening(false) {
|
||||
m_tcpServer = new TCPServer(port, local ? "127.0.0.1" : "0.0.0.0");
|
||||
|
||||
if (m_tcpServer != NULL && m_tcpServer->start() == 0) {
|
||||
if (m_tcpServer != nullptr && m_tcpServer->start() == 0) {
|
||||
m_listening = true;
|
||||
}
|
||||
if (httpPort > 0) {
|
||||
m_httpServer = new TCPServer(httpPort, "0.0.0.0");
|
||||
m_httpServer->start();
|
||||
} else {
|
||||
m_httpServer = NULL;
|
||||
m_httpServer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Network::~Network() {
|
||||
stop();
|
||||
NetMessage* netMsg;
|
||||
while ((netMsg = m_netQueue->pop()) != NULL) {
|
||||
while ((netMsg = m_netQueue->pop()) != nullptr) {
|
||||
netMsg->setResult("ERR: shutdown", "", false, 0, true);
|
||||
}
|
||||
while (!m_connections.empty()) {
|
||||
@@ -218,10 +218,10 @@ Network::~Network() {
|
||||
delete connection;
|
||||
}
|
||||
|
||||
if (m_tcpServer != NULL) {
|
||||
if (m_tcpServer != nullptr) {
|
||||
delete m_tcpServer;
|
||||
}
|
||||
if (m_httpServer != NULL) {
|
||||
if (m_httpServer != nullptr) {
|
||||
delete m_httpServer;
|
||||
}
|
||||
join();
|
||||
@@ -276,13 +276,13 @@ void Network::run() {
|
||||
while (true) {
|
||||
#ifdef HAVE_PPOLL
|
||||
// wait for new fd event
|
||||
ret = ppoll(fds, nfds, &tdiff, NULL);
|
||||
ret = ppoll(fds, nfds, &tdiff, nullptr);
|
||||
#else
|
||||
#ifdef HAVE_PSELECT
|
||||
// set readfds to inital checkfds
|
||||
fd_set readfds = checkfds;
|
||||
// wait for new fd event
|
||||
ret = pselect(maxfd + 1, &readfds, NULL, NULL, &tdiff, NULL);
|
||||
ret = pselect(maxfd + 1, &readfds, nullptr, nullptr, &tdiff, nullptr);
|
||||
#endif
|
||||
#endif
|
||||
if (ret == 0) {
|
||||
@@ -317,7 +317,7 @@ void Network::run() {
|
||||
#endif
|
||||
if (newData) {
|
||||
TCPSocket* socket = (isHttp ? m_httpServer : m_tcpServer)->newSocket();
|
||||
if (socket == NULL) {
|
||||
if (socket == nullptr) {
|
||||
continue;
|
||||
}
|
||||
Connection* connection = new Connection(socket, isHttp, m_netQueue);
|
||||
|
||||
+4
-4
@@ -48,8 +48,8 @@ class NetMessage {
|
||||
*/
|
||||
explicit NetMessage(bool isHttp)
|
||||
: m_isHttp(isHttp), m_resultSet(false), m_disconnect(false), m_listening(false), m_listenSince(0) {
|
||||
pthread_mutex_init(&m_mutex, NULL);
|
||||
pthread_cond_init(&m_cond, NULL);
|
||||
pthread_mutex_init(&m_mutex, nullptr);
|
||||
pthread_cond_init(&m_cond, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,7 +138,7 @@ class NetMessage {
|
||||
* @param listenSince set to the start time from which to add updates (inclusive).
|
||||
* @return whether the client is in listening mode.
|
||||
*/
|
||||
bool isListening(time_t* listenSince = NULL) {
|
||||
bool isListening(time_t* listenSince = nullptr) {
|
||||
if (listenSince) {
|
||||
*listenSince = m_listenSince;
|
||||
}
|
||||
@@ -278,7 +278,7 @@ class Network : public Thread {
|
||||
/** the command line @a TCPServer instance. */
|
||||
TCPServer* m_tcpServer;
|
||||
|
||||
/** the HTTP @a TCPServer instance, or NULL. */
|
||||
/** the HTTP @a TCPServer instance, or nullptr. */
|
||||
TCPServer* m_httpServer;
|
||||
|
||||
/** @a Notify object for shutdown procedure. */
|
||||
|
||||
@@ -66,7 +66,7 @@ result_t TemParamDataType::readSymbols(size_t offset, size_t length, const Symbo
|
||||
if (outputFormat & OF_JSON) {
|
||||
*output << "null";
|
||||
} else {
|
||||
*output << NULL_VALUE;
|
||||
*output << nullptr_VALUE;
|
||||
}
|
||||
return RESULT_OK;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ result_t TemParamDataType::writeSymbols(const size_t offset, const size_t length
|
||||
unsigned int value;
|
||||
unsigned int grp, num;
|
||||
|
||||
if (input->str() == NULL_VALUE) {
|
||||
if (input->str() == nullptr_VALUE) {
|
||||
value = m_replacement; // replacement value
|
||||
} else {
|
||||
string token;
|
||||
@@ -102,24 +102,24 @@ result_t TemParamDataType::writeSymbols(const size_t offset, const size_t length
|
||||
return RESULT_ERR_EOF; // incomplete
|
||||
}
|
||||
const char* str = token.c_str();
|
||||
if (str == NULL || *str == 0) {
|
||||
if (str == nullptr || *str == 0) {
|
||||
return RESULT_ERR_EOF; // input too short
|
||||
}
|
||||
char* strEnd = NULL;
|
||||
char* strEnd = nullptr;
|
||||
grp = (unsigned int)strtoul(str, &strEnd, 10);
|
||||
if (strEnd == NULL || strEnd == str || *strEnd != 0) {
|
||||
if (strEnd == nullptr || strEnd == str || *strEnd != 0) {
|
||||
return RESULT_ERR_INVALID_NUM; // invalid value
|
||||
}
|
||||
if (input->eof() || !getline(*input, token, '-')) {
|
||||
return RESULT_ERR_EOF; // incomplete
|
||||
}
|
||||
str = token.c_str();
|
||||
if (str == NULL || *str == 0) {
|
||||
if (str == nullptr || *str == 0) {
|
||||
return RESULT_ERR_EOF; // input too short
|
||||
}
|
||||
strEnd = NULL;
|
||||
strEnd = nullptr;
|
||||
num = (unsigned int)strtoul(str, &strEnd, 10);
|
||||
if (strEnd == NULL || strEnd == str || *strEnd != 0) {
|
||||
if (strEnd == nullptr || strEnd == str || *strEnd != 0) {
|
||||
return RESULT_ERR_INVALID_NUM; // invalid value
|
||||
}
|
||||
if (grp > 0x1f || num > 0x7f) {
|
||||
|
||||
@@ -47,7 +47,7 @@ class TemParamDataType : public NumberDataType {
|
||||
* @param id the type identifier.
|
||||
*/
|
||||
explicit TemParamDataType(const string& id)
|
||||
: NumberDataType(id, 16, 0, 0xffff, 0, 0xffff, 0, NULL) {}
|
||||
: NumberDataType(id, 16, 0, 0xffff, 0, 0xffff, 0, nullptr) {}
|
||||
|
||||
// @copydoc
|
||||
result_t derive(int divisor, size_t bitCount, const NumberDataType** derived) const override;
|
||||
|
||||
@@ -53,7 +53,7 @@ class TestReader : public MappedFileReader {
|
||||
public:
|
||||
TestReader(DataFieldTemplates* templates, bool isSet, bool isMasterDest)
|
||||
: MappedFileReader::MappedFileReader(true), m_templates(templates), m_isSet(isSet), m_isMasterDest(isMasterDest),
|
||||
m_fields(NULL) {}
|
||||
m_fields(nullptr) {}
|
||||
result_t getFieldMap(const string& preferLanguage, vector<string>* row, string* errorDescription) const override {
|
||||
if (row->empty()) {
|
||||
row->push_back("*name");
|
||||
@@ -90,7 +90,7 @@ class TestReader : public MappedFileReader {
|
||||
|
||||
int main() {
|
||||
const DataType* type = DataTypeList::getInstance()->get("TEM_P");
|
||||
if (type == NULL) {
|
||||
if (type == nullptr) {
|
||||
cout << "datatype not registered" << endl;
|
||||
return 1;
|
||||
}
|
||||
@@ -118,8 +118,8 @@ int main() {
|
||||
istringstream dummystr("#");
|
||||
string errorDescription;
|
||||
vector<string> row;
|
||||
templates->readLineFromStream(&dummystr, "inline", false, &lineNo, &row, &errorDescription, false, NULL, NULL);
|
||||
const DataField* fields = NULL;
|
||||
templates->readLineFromStream(&dummystr, "inline", false, &lineNo, &row, &errorDescription, false, nullptr, nullptr);
|
||||
const DataField* fields = nullptr;
|
||||
for (unsigned int i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) {
|
||||
string check[5] = checks[i];
|
||||
istringstream isstr(check[0]);
|
||||
@@ -146,9 +146,9 @@ int main() {
|
||||
bool failedWriteMatch = flags.find('W') != string::npos;
|
||||
string item;
|
||||
|
||||
if (fields != NULL) {
|
||||
if (fields != nullptr) {
|
||||
delete fields;
|
||||
fields = NULL;
|
||||
fields = nullptr;
|
||||
}
|
||||
|
||||
string errorDescription;
|
||||
@@ -156,7 +156,7 @@ int main() {
|
||||
lineNo = 0;
|
||||
dummystr.clear();
|
||||
dummystr.str("#");
|
||||
result = reader.readLineFromStream(&dummystr, "inline", false, &lineNo, &row, &errorDescription, false, NULL, NULL);
|
||||
result = reader.readLineFromStream(&dummystr, "inline", false, &lineNo, &row, &errorDescription, false, nullptr, nullptr);
|
||||
if (result != RESULT_OK) {
|
||||
cout << "\"" << check[0] << "\": reader header error: " << getResultCode(result) << ", " << errorDescription
|
||||
<< endl;
|
||||
@@ -164,7 +164,7 @@ int main() {
|
||||
continue;
|
||||
}
|
||||
lineNo = baseLine + i;
|
||||
result = reader.readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
|
||||
result = reader.readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, nullptr, nullptr);
|
||||
fields = reader.m_fields;
|
||||
|
||||
if (result != RESULT_OK) {
|
||||
@@ -172,8 +172,8 @@ int main() {
|
||||
error = true;
|
||||
continue;
|
||||
}
|
||||
if (fields == NULL) {
|
||||
cout << "\"" << check[0] << "\": create error: NULL" << endl;
|
||||
if (fields == nullptr) {
|
||||
cout << "\"" << check[0] << "\": create error: nullptr" << endl;
|
||||
error = true;
|
||||
continue;
|
||||
}
|
||||
@@ -194,9 +194,9 @@ int main() {
|
||||
cout << " parse \"" << sstr.getStr().substr(0, 2) << "\" error: " << getResultCode(result) << endl;
|
||||
error = true;
|
||||
}
|
||||
result = fields->read(mstr, 0, false, NULL, -1, 0, -1, &output);
|
||||
result = fields->read(mstr, 0, false, nullptr, -1, 0, -1, &output);
|
||||
if (result >= RESULT_OK) {
|
||||
result = fields->read(sstr, 0, !output.str().empty(), NULL, -1, 0, -1, &output);
|
||||
result = fields->read(sstr, 0, !output.str().empty(), nullptr, -1, 0, -1, &output);
|
||||
}
|
||||
if (failedRead) {
|
||||
if (result >= RESULT_OK) {
|
||||
@@ -217,9 +217,9 @@ int main() {
|
||||
}
|
||||
|
||||
istringstream input(expectStr);
|
||||
result = fields->write(UI_FIELD_SEPARATOR, 0, &input, &writeMstr, NULL);
|
||||
result = fields->write(UI_FIELD_SEPARATOR, 0, &input, &writeMstr, nullptr);
|
||||
if (result >= RESULT_OK) {
|
||||
result = fields->write(UI_FIELD_SEPARATOR, 0, &input, &writeSstr, NULL);
|
||||
result = fields->write(UI_FIELD_SEPARATOR, 0, &input, &writeSstr, nullptr);
|
||||
}
|
||||
if (failedWrite) {
|
||||
if (result >= RESULT_OK) {
|
||||
@@ -240,7 +240,7 @@ int main() {
|
||||
writeMstr.getStr() + " " + writeSstr.getStr());
|
||||
}
|
||||
delete fields;
|
||||
fields = NULL;
|
||||
fields = nullptr;
|
||||
}
|
||||
|
||||
delete templates;
|
||||
|
||||
+25
-25
@@ -84,7 +84,7 @@ void AttributedItem::appendJson(bool prependFieldSeparator, const string& name,
|
||||
plain = value == "false" || value == "true";
|
||||
if (!plain) {
|
||||
const char* str = value.c_str();
|
||||
char* strEnd = NULL;
|
||||
char* strEnd = nullptr;
|
||||
strtod(str, &strEnd);
|
||||
plain = strEnd && !*strEnd;
|
||||
}
|
||||
@@ -269,7 +269,7 @@ result_t DataField::create(bool isWriteMessage, bool isTemplate, bool isBroadcas
|
||||
while (getline(stream, token, VALUE_SEPARATOR)) {
|
||||
FileReader::trim(&token);
|
||||
const char* str = token.c_str();
|
||||
char* strEnd = NULL;
|
||||
char* strEnd = nullptr;
|
||||
unsigned long id;
|
||||
if (strncasecmp(str, "0x", 2) == 0) {
|
||||
str += 2;
|
||||
@@ -277,7 +277,7 @@ result_t DataField::create(bool isWriteMessage, bool isTemplate, bool isBroadcas
|
||||
} else {
|
||||
id = strtoul(str, &strEnd, 10); // decimal
|
||||
}
|
||||
if (strEnd == NULL || strEnd == str || id > MAX_VALUE) {
|
||||
if (strEnd == nullptr || strEnd == str || id > MAX_VALUE) {
|
||||
*errorDescription = "value "+token+" in field "+formatInt(fieldIndex);
|
||||
result = RESULT_ERR_INVALID_LIST;
|
||||
break;
|
||||
@@ -307,10 +307,10 @@ result_t DataField::create(bool isWriteMessage, bool isTemplate, bool isBroadcas
|
||||
FileReader::trim(&token);
|
||||
const DataField* templ = templates->get(token);
|
||||
size_t pos = token.find(LENGTH_SEPARATOR);
|
||||
if (templ == NULL && pos != string::npos) {
|
||||
if (templ == nullptr && pos != string::npos) {
|
||||
templ = templates->get(token.substr(0, pos));
|
||||
}
|
||||
if (templ == NULL) { // basetype[:len]
|
||||
if (templ == nullptr) { // basetype[:len]
|
||||
size_t length;
|
||||
string typeName;
|
||||
if (pos == string::npos) {
|
||||
@@ -334,10 +334,10 @@ result_t DataField::create(bool isWriteMessage, bool isTemplate, bool isBroadcas
|
||||
result = RESULT_ERR_NOTFOUND;
|
||||
*errorDescription = "field type "+typeName+" in field "+formatInt(fieldIndex);
|
||||
} else {
|
||||
SingleDataField* add = NULL;
|
||||
SingleDataField* add = nullptr;
|
||||
result = SingleDataField::create(firstType ? name : "", row, dataType, partType, length, divisor,
|
||||
constantValue, verifyValue, &values, &add);
|
||||
if (add != NULL) {
|
||||
if (add != nullptr) {
|
||||
fields.push_back(add);
|
||||
} else {
|
||||
if (result == RESULT_OK) {
|
||||
@@ -509,7 +509,7 @@ result_t SingleDataField::read(const SymbolString& data, size_t offset,
|
||||
if (offset + (remainder?1:m_length) > data.getDataSize()) {
|
||||
return RESULT_ERR_INVALID_POS;
|
||||
}
|
||||
if (isIgnored() || (fieldName != NULL && m_name != fieldName) || fieldIndex > 0) {
|
||||
if (isIgnored() || (fieldName != nullptr && m_name != fieldName) || fieldIndex > 0) {
|
||||
return RESULT_EMPTY;
|
||||
}
|
||||
result_t res = m_dataType->readRawValue(offset, m_length, data, output);
|
||||
@@ -529,7 +529,7 @@ result_t SingleDataField::read(const SymbolString& data, size_t offset,
|
||||
if (offset + (remainder?1:m_length) > data.getDataSize()) {
|
||||
return RESULT_ERR_INVALID_POS;
|
||||
}
|
||||
if (isIgnored() || (fieldName != NULL && m_name != fieldName) || fieldIndex > 0) {
|
||||
if (isIgnored() || (fieldName != nullptr && m_name != fieldName) || fieldIndex > 0) {
|
||||
return RESULT_EMPTY;
|
||||
}
|
||||
bool shortFormat = outputFormat & OF_SHORT;
|
||||
@@ -636,7 +636,7 @@ result_t SingleDataField::derive(const string& name, PartType partType, int divi
|
||||
|
||||
bool SingleDataField::hasField(const char* fieldName, bool numeric) const {
|
||||
bool numericType = m_dataType->isNumeric();
|
||||
return numeric == numericType && (fieldName == NULL || fieldName == m_name);
|
||||
return numeric == numericType && (fieldName == nullptr || fieldName == m_name);
|
||||
}
|
||||
|
||||
size_t SingleDataField::getLength(PartType partType, size_t maxLength) const {
|
||||
@@ -663,7 +663,7 @@ bool SingleDataField::hasFullByteOffset(bool after) const {
|
||||
}
|
||||
|
||||
size_t SingleDataField::getCount(PartType partType, const char* fieldName) const {
|
||||
return isIgnored() || (partType != pt_any && partType != m_partType) || (fieldName != NULL && m_name != fieldName)
|
||||
return isIgnored() || (partType != pt_any && partType != m_partType) || (fieldName != nullptr && m_name != fieldName)
|
||||
? 0 : 1;
|
||||
}
|
||||
|
||||
@@ -742,7 +742,7 @@ result_t ValueListDataField::readSymbols(const SymbolString& input, size_t offse
|
||||
if (outputFormat & OF_JSON) {
|
||||
*output << "null";
|
||||
} else if (value == m_dataType->getReplacement()) {
|
||||
*output << NULL_VALUE;
|
||||
*output << nullptr_VALUE;
|
||||
}
|
||||
} else if (outputFormat & OF_NUMERIC) {
|
||||
*output << setw(0) << dec << value;
|
||||
@@ -765,7 +765,7 @@ result_t ValueListDataField::readSymbols(const SymbolString& input, size_t offse
|
||||
result_t ValueListDataField::writeSymbols(size_t offset, istringstream* input,
|
||||
SymbolString* output, size_t* usedLength) const {
|
||||
const NumberDataType* numType = reinterpret_cast<const NumberDataType*>(m_dataType);
|
||||
if (isIgnored() || input->str() == NULL_VALUE) {
|
||||
if (isIgnored() || input->str() == nullptr_VALUE) {
|
||||
// replacement value
|
||||
return numType->writeRawValue(numType->getReplacement(), offset, m_length, output, usedLength);
|
||||
}
|
||||
@@ -776,10 +776,10 @@ result_t ValueListDataField::writeSymbols(size_t offset, istringstream* input,
|
||||
return numType->writeRawValue(it->first, offset, m_length, output, usedLength);
|
||||
}
|
||||
}
|
||||
char* strEnd = NULL; // fall back to raw value in input
|
||||
char* strEnd = nullptr; // fall back to raw value in input
|
||||
unsigned int value;
|
||||
value = (unsigned int)strtoul(str, &strEnd, 10);
|
||||
if (strEnd == NULL || strEnd == str || (*strEnd != 0 && *strEnd != '.')) {
|
||||
if (strEnd == nullptr || strEnd == str || (*strEnd != 0 && *strEnd != '.')) {
|
||||
return RESULT_ERR_INVALID_NUM; // invalid value
|
||||
}
|
||||
if (m_values.find(value) != m_values.end()) {
|
||||
@@ -851,10 +851,10 @@ result_t ConstantDataField::writeSymbols(size_t offset, istringstream* input,
|
||||
}
|
||||
|
||||
|
||||
DataFieldSet* DataFieldSet::s_identFields = NULL;
|
||||
DataFieldSet* DataFieldSet::s_identFields = nullptr;
|
||||
|
||||
DataFieldSet* DataFieldSet::getIdentFields() {
|
||||
if (s_identFields == NULL) {
|
||||
if (s_identFields == nullptr) {
|
||||
const NumberDataType* uchDataType = reinterpret_cast<const NumberDataType*>(
|
||||
DataTypeList::getInstance()->get("UCH"));
|
||||
const StringDataType* stringDataType = reinterpret_cast<const StringDataType*>(
|
||||
@@ -936,7 +936,7 @@ size_t DataFieldSet::getLength(PartType partType, size_t maxLength) const {
|
||||
}
|
||||
|
||||
size_t DataFieldSet::getCount(PartType partType, const char* fieldName) const {
|
||||
if (partType == pt_any && fieldName == NULL) {
|
||||
if (partType == pt_any && fieldName == nullptr) {
|
||||
return m_fields.size() - m_ignoredCount;
|
||||
}
|
||||
size_t count = 0;
|
||||
@@ -1027,7 +1027,7 @@ result_t DataFieldSet::read(const SymbolString& data, size_t offset,
|
||||
if (result != RESULT_EMPTY) {
|
||||
found = true;
|
||||
}
|
||||
if (findFieldIndex && !field->isIgnored() && (fieldName == NULL || fieldName == field->getName(-1))) {
|
||||
if (findFieldIndex && !field->isIgnored() && (fieldName == nullptr || fieldName == field->getName(-1))) {
|
||||
if (fieldIndex == 0) {
|
||||
if (!found) {
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
@@ -1074,7 +1074,7 @@ result_t DataFieldSet::read(const SymbolString& data, size_t offset,
|
||||
found = true;
|
||||
leadingSeparator = true;
|
||||
}
|
||||
if (findFieldIndex && !field->isIgnored() && (fieldName == NULL || fieldName == field->getName(-1))) {
|
||||
if (findFieldIndex && !field->isIgnored() && (fieldName == nullptr || fieldName == field->getName(-1))) {
|
||||
if (fieldIndex == 0) {
|
||||
if (!found) {
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
@@ -1127,7 +1127,7 @@ result_t DataFieldSet::write(char separator, size_t offset, istringstream* input
|
||||
previousFullByteOffset = field->hasFullByteOffset(true);
|
||||
}
|
||||
|
||||
if (usedLength != NULL) {
|
||||
if (usedLength != nullptr) {
|
||||
*usedLength = offset-baseOffset;
|
||||
}
|
||||
return RESULT_OK;
|
||||
@@ -1201,7 +1201,7 @@ result_t LoadableDataFieldSet::getFieldMap(const string& preferLanguage, vector<
|
||||
|
||||
result_t LoadableDataFieldSet::addFromFile(const string& filename, unsigned int lineNo, map<string, string>* row,
|
||||
vector< map<string, string> >* subRows, string* errorDescription, bool replace) {
|
||||
const DataField* field = NULL;
|
||||
const DataField* field = nullptr;
|
||||
result_t result = DataField::create(false, false, false, MAX_POS, m_templates, subRows, errorDescription, &field);
|
||||
if (result != RESULT_OK) {
|
||||
return result;
|
||||
@@ -1262,7 +1262,7 @@ DataFieldTemplates::DataFieldTemplates(const DataFieldTemplates& other)
|
||||
void DataFieldTemplates::clear() {
|
||||
for (auto it : m_fieldsByName) {
|
||||
delete it.second;
|
||||
it.second = NULL;
|
||||
it.second = nullptr;
|
||||
}
|
||||
m_fieldsByName.clear();
|
||||
}
|
||||
@@ -1383,7 +1383,7 @@ result_t DataFieldTemplates::addFromFile(const string& filename, unsigned int li
|
||||
firstFieldName = name.substr(colon+1);
|
||||
name = name.substr(0, colon);
|
||||
}
|
||||
const DataField* field = NULL;
|
||||
const DataField* field = nullptr;
|
||||
if (!subRows->empty()) {
|
||||
map<string, string>::iterator it = (*subRows)[0].find("name");
|
||||
if (it == (*subRows)[0].end() || it->second.empty()) {
|
||||
@@ -1407,7 +1407,7 @@ result_t DataFieldTemplates::addFromFile(const string& filename, unsigned int li
|
||||
const DataField* DataFieldTemplates::get(const string& name) const {
|
||||
const auto ref = m_fieldsByName.find(name);
|
||||
if (ref == m_fieldsByName.end()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return ref->second;
|
||||
}
|
||||
|
||||
+13
-13
@@ -215,7 +215,7 @@ class DataField : public AttributedItem {
|
||||
* @param isTemplate true for creating a template @a DataField.
|
||||
* @param isBroadcastOrMasterDestination true if the destination bus address is @a BRODCAST or a master address.
|
||||
* @param maxFieldLength the maximum allowed length of a single field (e.g. @a MAX_POS).
|
||||
* @param templates the @a DataFieldTemplates to be referenced by name, or NULL.
|
||||
* @param templates the @a DataFieldTemplates to be referenced by name, or nullptr.
|
||||
* @param rows the mapped field definition rows (may be modified).
|
||||
* @param errorDescription a string in which to store the error description in case of error.
|
||||
* @param returnField the variable in which to store the created instance.
|
||||
@@ -258,10 +258,10 @@ class DataField : public AttributedItem {
|
||||
/**
|
||||
* Get the field count (excluding ignored fields).
|
||||
* @param partType the optional part to count, or @ pt_any.
|
||||
* @param fieldName the optional field name to count, or NULL.
|
||||
* @param fieldName the optional field name to count, or nullptr.
|
||||
* @return the field count (excluding ignored fields).
|
||||
*/
|
||||
virtual size_t getCount(PartType partType = pt_any, const char* fieldName = NULL) const = 0;
|
||||
virtual size_t getCount(PartType partType = pt_any, const char* fieldName = nullptr) const = 0;
|
||||
|
||||
/**
|
||||
* Get the specified field name.
|
||||
@@ -280,7 +280,7 @@ class DataField : public AttributedItem {
|
||||
|
||||
/**
|
||||
* Return whether the field is available.
|
||||
* @param fieldName the name of the field to find, or NULL for any.
|
||||
* @param fieldName the name of the field to find, or nullptr for any.
|
||||
* @param numeric true for a numeric field, false for a string field.
|
||||
* @return true if the field is available.
|
||||
*/
|
||||
@@ -290,7 +290,7 @@ class DataField : public AttributedItem {
|
||||
* Reads the numeric value from the @a SymbolString.
|
||||
* @param data the data @a SymbolString for reading binary data.
|
||||
* @param offset the additional offset to add for reading binary data.
|
||||
* @param fieldName the name of the field to read, or NULL for the first field.
|
||||
* @param fieldName the name of the field to read, or nullptr for the first field.
|
||||
* @param fieldIndex the optional index of the field (either named or overall), or -1.
|
||||
* @param output the variable in which to store the numeric value.
|
||||
* @return @a RESULT_OK on success,
|
||||
@@ -325,7 +325,7 @@ class DataField : public AttributedItem {
|
||||
* @param separator the separator character between multiple fields.
|
||||
* @param offset the additional offset to add for writing binary data.
|
||||
* @param data the data @a SymbolString to write binary data to.
|
||||
* @param usedLength the variable in which to store the used length in bytes, or NULL.
|
||||
* @param usedLength the variable in which to store the used length in bytes, or nullptr.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t write(char separator, size_t offset, istringstream* input,
|
||||
@@ -407,7 +407,7 @@ class SingleDataField : public DataField {
|
||||
bool hasFullByteOffset(bool after) const;
|
||||
|
||||
// @copydoc
|
||||
size_t getCount(PartType partType = pt_any, const char* fieldName = NULL) const override;
|
||||
size_t getCount(PartType partType = pt_any, const char* fieldName = nullptr) const override;
|
||||
|
||||
// @copydoc
|
||||
virtual string getName(ssize_t fieldIndex) const {
|
||||
@@ -466,7 +466,7 @@ class SingleDataField : public DataField {
|
||||
* @param input the @a istringstream to parse the formatted value from.
|
||||
* @param offset the offset in the @a SymbolString.
|
||||
* @param output the @a SymbolString to write the binary value to.
|
||||
* @param usedLength the variable in which to store the used length in bytes, or NULL.
|
||||
* @param usedLength the variable in which to store the used length in bytes, or nullptr.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t writeSymbols(size_t offset, istringstream* input,
|
||||
@@ -650,7 +650,7 @@ class DataFieldSet : public DataField {
|
||||
size_t getLength(PartType partType, size_t maxLength) const override;
|
||||
|
||||
// @copydoc
|
||||
size_t getCount(PartType partType = pt_any, const char* fieldName = NULL) const override;
|
||||
size_t getCount(PartType partType = pt_any, const char* fieldName = nullptr) const override;
|
||||
|
||||
// @copydoc
|
||||
string getName(ssize_t fieldIndex) const override;
|
||||
@@ -663,11 +663,11 @@ class DataFieldSet : public DataField {
|
||||
/**
|
||||
* Returns the @a SingleDataField at the specified index.
|
||||
* @param index the index of the @a SingleDataField to return.
|
||||
* @return the @a SingleDataField at the specified index, or NULL.
|
||||
* @return the @a SingleDataField at the specified index, or nullptr.
|
||||
*/
|
||||
const SingleDataField* operator[](size_t index) const {
|
||||
if (index >= m_fields.size()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return m_fields[index];
|
||||
}
|
||||
@@ -699,7 +699,7 @@ class DataFieldSet : public DataField {
|
||||
|
||||
|
||||
private:
|
||||
/** the @a DataFieldSet containing the ident message @a SingleDataField instances, or NULL. */
|
||||
/** the @a DataFieldSet containing the ident message @a SingleDataField instances, or nullptr. */
|
||||
static DataFieldSet* s_identFields;
|
||||
|
||||
protected:
|
||||
@@ -788,7 +788,7 @@ class DataFieldTemplates : public MappedFileReader {
|
||||
/**
|
||||
* Gets the template @a DataField instance with the specified name.
|
||||
* @param name the name of the template to get.
|
||||
* @return the template @a DataField instance, or NULL.
|
||||
* @return the template @a DataField instance, or nullptr.
|
||||
* Note: the caller may not free the returned instance.
|
||||
*/
|
||||
const DataField* get(const string& name) const;
|
||||
|
||||
+54
-54
@@ -142,7 +142,7 @@ result_t StringDataType::writeSymbols(size_t offset, size_t length, istringstrea
|
||||
for (size_t index = start, i = 0; i < count; index += incr, i++) {
|
||||
output->dataAt(offset + index) = (symbol_t)m_replacement; // fill up with replacement
|
||||
}
|
||||
if (usedLength != NULL) {
|
||||
if (usedLength != nullptr) {
|
||||
*usedLength = count;
|
||||
}
|
||||
return RESULT_OK;
|
||||
@@ -197,7 +197,7 @@ result_t StringDataType::writeSymbols(size_t offset, size_t length, istringstrea
|
||||
if (!remainder && i < count) {
|
||||
return RESULT_ERR_EOF; // input too short
|
||||
}
|
||||
if (usedLength != NULL) {
|
||||
if (usedLength != nullptr) {
|
||||
*usedLength = (index-start)*incr;
|
||||
}
|
||||
return RESULT_OK;
|
||||
@@ -243,13 +243,13 @@ result_t DateTimeDataType::readSymbols(size_t offset, size_t length, const Symbo
|
||||
case 2: // date only
|
||||
if (!hasFlag(REQ) && symbol == m_replacement) {
|
||||
if (i + 1 != length) {
|
||||
*output << NULL_VALUE << ".";
|
||||
*output << nullptr_VALUE << ".";
|
||||
break;
|
||||
} else if (last == m_replacement) {
|
||||
if (length == 2) { // number of days since 01.01.1900
|
||||
*output << NULL_VALUE << ".";
|
||||
*output << nullptr_VALUE << ".";
|
||||
}
|
||||
*output << NULL_VALUE;
|
||||
*output << nullptr_VALUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -282,13 +282,13 @@ result_t DateTimeDataType::readSymbols(size_t offset, size_t length, const Symbo
|
||||
case 1: // time only
|
||||
if (!hasFlag(REQ) && symbol == m_replacement) {
|
||||
if (length == 1) { // truncated time
|
||||
*output << NULL_VALUE << ":" << NULL_VALUE;
|
||||
*output << nullptr_VALUE << ":" << nullptr_VALUE;
|
||||
break;
|
||||
}
|
||||
if (i > 0) {
|
||||
*output << ":";
|
||||
}
|
||||
*output << NULL_VALUE;
|
||||
*output << nullptr_VALUE;
|
||||
break;
|
||||
}
|
||||
if (hasFlag(SPE)) { // minutes since midnight
|
||||
@@ -359,7 +359,7 @@ result_t DateTimeDataType::writeSymbols(size_t offset, size_t length, istringstr
|
||||
for (size_t index = start, i = 0; i < count; index += incr, i++) {
|
||||
output->dataAt(offset + index) = (symbol_t)m_replacement; // fill up with replacement
|
||||
}
|
||||
if (usedLength != NULL) {
|
||||
if (usedLength != nullptr) {
|
||||
*usedLength = count;
|
||||
}
|
||||
return RESULT_OK;
|
||||
@@ -378,7 +378,7 @@ result_t DateTimeDataType::writeSymbols(size_t offset, size_t length, istringstr
|
||||
if (input->eof() || !getline(*input, token, '.')) {
|
||||
return RESULT_ERR_EOF; // incomplete
|
||||
}
|
||||
if (!hasFlag(REQ) && token == NULL_VALUE) {
|
||||
if (!hasFlag(REQ) && token == nullptr_VALUE) {
|
||||
value = m_replacement;
|
||||
break;
|
||||
}
|
||||
@@ -431,7 +431,7 @@ result_t DateTimeDataType::writeSymbols(size_t offset, size_t length, istringstr
|
||||
if (input->eof() || !getline(*input, token, LENGTH_SEPARATOR)) {
|
||||
return RESULT_ERR_EOF; // incomplete
|
||||
}
|
||||
if (!hasFlag(REQ) && token == NULL_VALUE) {
|
||||
if (!hasFlag(REQ) && token == nullptr_VALUE) {
|
||||
value = m_replacement;
|
||||
if (length == 1) { // truncated time
|
||||
if (i == 0) {
|
||||
@@ -493,7 +493,7 @@ result_t DateTimeDataType::writeSymbols(size_t offset, size_t length, istringstr
|
||||
if (!remainder && i < count) {
|
||||
return RESULT_ERR_EOF; // input too short
|
||||
}
|
||||
if (usedLength != NULL) {
|
||||
if (usedLength != nullptr) {
|
||||
*usedLength = (index-start)*incr;
|
||||
}
|
||||
return RESULT_OK;
|
||||
@@ -654,7 +654,7 @@ result_t NumberDataType::readSymbols(size_t offset, size_t length, const SymbolS
|
||||
if (outputFormat & OF_JSON) {
|
||||
*output << "null";
|
||||
} else {
|
||||
*output << NULL_VALUE;
|
||||
*output << nullptr_VALUE;
|
||||
}
|
||||
return RESULT_OK;
|
||||
}
|
||||
@@ -787,7 +787,7 @@ result_t NumberDataType::writeRawValue(unsigned int value, size_t offset, size_t
|
||||
output->dataAt(offset + index) = symbol;
|
||||
}
|
||||
}
|
||||
if (usedLength != NULL) {
|
||||
if (usedLength != nullptr) {
|
||||
*usedLength = length;
|
||||
}
|
||||
return RESULT_OK;
|
||||
@@ -797,15 +797,15 @@ result_t NumberDataType::writeSymbols(size_t offset, size_t length, istringstrea
|
||||
SymbolString* output, size_t* usedLength) const {
|
||||
unsigned int value;
|
||||
|
||||
if (!hasFlag(REQ) && (isIgnored() || input->str() == NULL_VALUE)) {
|
||||
if (!hasFlag(REQ) && (isIgnored() || input->str() == nullptr_VALUE)) {
|
||||
value = m_replacement; // replacement value
|
||||
} else if (input->str().empty()) {
|
||||
return RESULT_ERR_EOF; // input too short
|
||||
} else if (hasFlag(EXP)) { // IEEE 754 binary32
|
||||
const char* str = input->str().c_str();
|
||||
char* strEnd = NULL;
|
||||
char* strEnd = nullptr;
|
||||
double dvalue = strtod(str, &strEnd);
|
||||
if (strEnd == NULL || strEnd == str || *strEnd != 0) {
|
||||
if (strEnd == nullptr || strEnd == str || *strEnd != 0) {
|
||||
return RESULT_ERR_INVALID_NUM; // invalid value
|
||||
}
|
||||
if (m_divisor < 0) {
|
||||
@@ -842,7 +842,7 @@ result_t NumberDataType::writeSymbols(size_t offset, size_t length, istringstrea
|
||||
#endif
|
||||
} else {
|
||||
const char* str = input->str().c_str();
|
||||
char* strEnd = NULL;
|
||||
char* strEnd = nullptr;
|
||||
if (m_divisor == 1) {
|
||||
if (hasFlag(SIG)) {
|
||||
long signedValue = strtol(str, &strEnd, 10);
|
||||
@@ -854,12 +854,12 @@ result_t NumberDataType::writeSymbols(size_t offset, size_t length, istringstrea
|
||||
} else {
|
||||
value = (unsigned int)strtoul(str, &strEnd, 10);
|
||||
}
|
||||
if (strEnd == NULL || strEnd == str || (*strEnd != 0 && *strEnd != '.')) {
|
||||
if (strEnd == nullptr || strEnd == str || (*strEnd != 0 && *strEnd != '.')) {
|
||||
return RESULT_ERR_INVALID_NUM; // invalid value
|
||||
}
|
||||
} else {
|
||||
double dvalue = strtod(str, &strEnd);
|
||||
if (strEnd == NULL || strEnd == str || *strEnd != 0) {
|
||||
if (strEnd == nullptr || strEnd == str || *strEnd != 0) {
|
||||
return RESULT_ERR_INVALID_NUM; // invalid value
|
||||
}
|
||||
if (m_divisor < 0) {
|
||||
@@ -912,8 +912,8 @@ bool DataTypeList::s_contrib_initialized = libebus_contrib_register();
|
||||
DataTypeList::DataTypeList() {
|
||||
add(new StringDataType("STR", MAX_LEN*8, ADJ, ' ')); // >= 1 byte character string filled up with space
|
||||
// unsigned decimal in BCD, 0000 - 9999 (fixed length)
|
||||
add(new NumberDataType("PIN", 16, FIX|BCD|REV, 0xffff, 0, 0x9999, 1, NULL));
|
||||
add(new NumberDataType("UCH", 8, 0, 0xff, 0, 0xfe, 1, NULL)); // unsigned integer, 0 - 254
|
||||
add(new NumberDataType("PIN", 16, FIX|BCD|REV, 0xffff, 0, 0x9999, 1, nullptr));
|
||||
add(new NumberDataType("UCH", 8, 0, 0xff, 0, 0xfe, 1, nullptr)); // unsigned integer, 0 - 254
|
||||
add(new StringDataType("IGN", MAX_LEN*8, IGN|ADJ, 0)); // >= 1 byte ignored data
|
||||
// >= 1 byte character string filled up with 0x00 (null terminated string)
|
||||
add(new StringDataType("NTS", MAX_LEN*8, ADJ, 0));
|
||||
@@ -951,56 +951,56 @@ DataTypeList::DataTypeList() {
|
||||
add(new DateTimeDataType("TTH", 6, 0, 0, false, true, 30));
|
||||
// truncated time (only multiple of 15 minutes), 00:00 - 24:00 (minutes div 15 + hour * 4 as integer)
|
||||
add(new DateTimeDataType("TTQ", 7, 0, 0, false, true, 15));
|
||||
add(new NumberDataType("BDY", 8, DAY, 0x07, 0, 6, 1, NULL)); // weekday, "Mon" - "Sun" (0x00 - 0x06) [eBUS type]
|
||||
add(new NumberDataType("HDY", 8, DAY, 0x00, 1, 7, 1, NULL)); // weekday, "Mon" - "Sun" (0x01 - 0x07) [Vaillant type]
|
||||
add(new NumberDataType("BCD", 8, BCD, 0xff, 0, 99, 1, NULL)); // unsigned decimal in BCD, 0 - 99
|
||||
add(new NumberDataType("BCD", 16, BCD, 0xffff, 0, 9999, 1, NULL)); // unsigned decimal in BCD, 0 - 9999
|
||||
add(new NumberDataType("BCD", 24, BCD, 0xffffff, 0, 999999, 1, NULL)); // unsigned decimal in BCD, 0 - 999999
|
||||
add(new NumberDataType("BCD", 32, BCD, 0xffffffff, 0, 99999999, 1, NULL)); // unsigned decimal in BCD, 0 - 99999999
|
||||
add(new NumberDataType("HCD", 32, HCD|BCD|REQ, 0, 0, 99999999, 1, NULL)); // unsigned decimal in HCD, 0 - 99999999
|
||||
add(new NumberDataType("HCD", 8, HCD|BCD|REQ, 0, 0, 99, 1, NULL)); // unsigned decimal in HCD, 0 - 99
|
||||
add(new NumberDataType("HCD", 16, HCD|BCD|REQ, 0, 0, 9999, 1, NULL)); // unsigned decimal in HCD, 0 - 9999
|
||||
add(new NumberDataType("HCD", 24, HCD|BCD|REQ, 0, 0, 999999, 1, NULL)); // unsigned decimal in HCD, 0 - 999999
|
||||
add(new NumberDataType("SCH", 8, SIG, 0x80, 0x81, 0x7f, 1, NULL)); // signed integer, -127 - +127
|
||||
add(new NumberDataType("D1B", 8, SIG, 0x80, 0x81, 0x7f, 1, NULL)); // signed integer, -127 - +127
|
||||
add(new NumberDataType("BDY", 8, DAY, 0x07, 0, 6, 1, nullptr)); // weekday, "Mon" - "Sun" (0x00 - 0x06) [eBUS type]
|
||||
add(new NumberDataType("HDY", 8, DAY, 0x00, 1, 7, 1, nullptr)); // weekday, "Mon" - "Sun" (0x01 - 0x07) [Vaillant type]
|
||||
add(new NumberDataType("BCD", 8, BCD, 0xff, 0, 99, 1, nullptr)); // unsigned decimal in BCD, 0 - 99
|
||||
add(new NumberDataType("BCD", 16, BCD, 0xffff, 0, 9999, 1, nullptr)); // unsigned decimal in BCD, 0 - 9999
|
||||
add(new NumberDataType("BCD", 24, BCD, 0xffffff, 0, 999999, 1, nullptr)); // unsigned decimal in BCD, 0 - 999999
|
||||
add(new NumberDataType("BCD", 32, BCD, 0xffffffff, 0, 99999999, 1, nullptr)); // unsigned decimal in BCD, 0 - 99999999
|
||||
add(new NumberDataType("HCD", 32, HCD|BCD|REQ, 0, 0, 99999999, 1, nullptr)); // unsigned decimal in HCD, 0 - 99999999
|
||||
add(new NumberDataType("HCD", 8, HCD|BCD|REQ, 0, 0, 99, 1, nullptr)); // unsigned decimal in HCD, 0 - 99
|
||||
add(new NumberDataType("HCD", 16, HCD|BCD|REQ, 0, 0, 9999, 1, nullptr)); // unsigned decimal in HCD, 0 - 9999
|
||||
add(new NumberDataType("HCD", 24, HCD|BCD|REQ, 0, 0, 999999, 1, nullptr)); // unsigned decimal in HCD, 0 - 999999
|
||||
add(new NumberDataType("SCH", 8, SIG, 0x80, 0x81, 0x7f, 1, nullptr)); // signed integer, -127 - +127
|
||||
add(new NumberDataType("D1B", 8, SIG, 0x80, 0x81, 0x7f, 1, nullptr)); // signed integer, -127 - +127
|
||||
// unsigned number (fraction 1/2), 0 - 100 (0x00 - 0xc8, replacement 0xff)
|
||||
add(new NumberDataType("D1C", 8, 0, 0xff, 0x00, 0xc8, 2, NULL));
|
||||
add(new NumberDataType("D1C", 8, 0, 0xff, 0x00, 0xc8, 2, nullptr));
|
||||
// signed number (fraction 1/256), -127.99 - +127.99
|
||||
add(new NumberDataType("D2B", 16, SIG, 0x8000, 0x8001, 0x7fff, 256, NULL));
|
||||
add(new NumberDataType("D2B", 16, SIG, 0x8000, 0x8001, 0x7fff, 256, nullptr));
|
||||
// signed number (fraction 1/16), -2047.9 - +2047.9
|
||||
add(new NumberDataType("D2C", 16, SIG, 0x8000, 0x8001, 0x7fff, 16, NULL));
|
||||
add(new NumberDataType("D2C", 16, SIG, 0x8000, 0x8001, 0x7fff, 16, nullptr));
|
||||
// signed number (fraction 1/1000), -32.767 - +32.767, little endian
|
||||
add(new NumberDataType("FLT", 16, SIG, 0x8000, 0x8001, 0x7fff, 1000, NULL));
|
||||
add(new NumberDataType("FLT", 16, SIG, 0x8000, 0x8001, 0x7fff, 1000, nullptr));
|
||||
// signed number (fraction 1/1000), -32.767 - +32.767, big endian
|
||||
add(new NumberDataType("FLR", 16, SIG|REV, 0x8000, 0x8001, 0x7fff, 1000, NULL));
|
||||
add(new NumberDataType("FLR", 16, SIG|REV, 0x8000, 0x8001, 0x7fff, 1000, nullptr));
|
||||
// signed number (IEEE 754 binary32: 1 bit sign, 8 bits exponent, 23 bits significand), little endian
|
||||
add(new NumberDataType("EXP", 32, SIG|EXP, 0x7f800000, 0x00000000, 0xffffffff, 1, NULL));
|
||||
add(new NumberDataType("EXP", 32, SIG|EXP, 0x7f800000, 0x00000000, 0xffffffff, 1, nullptr));
|
||||
// signed number (IEEE 754 binary32: 1 bit sign, 8 bits exponent, 23 bits significand), big endian
|
||||
add(new NumberDataType("EXR", 32, SIG|EXP|REV, 0x7f800000, 0x00000000, 0xffffffff, 1, NULL));
|
||||
add(new NumberDataType("EXR", 32, SIG|EXP|REV, 0x7f800000, 0x00000000, 0xffffffff, 1, nullptr));
|
||||
// unsigned integer, 0 - 65534, little endian
|
||||
add(new NumberDataType("UIN", 16, 0, 0xffff, 0, 0xfffe, 1, NULL));
|
||||
add(new NumberDataType("UIN", 16, 0, 0xffff, 0, 0xfffe, 1, nullptr));
|
||||
// unsigned integer, 0 - 65534, big endian
|
||||
add(new NumberDataType("UIR", 16, REV, 0xffff, 0, 0xfffe, 1, NULL));
|
||||
add(new NumberDataType("UIR", 16, REV, 0xffff, 0, 0xfffe, 1, nullptr));
|
||||
// signed integer, -32767 - +32767, little endian
|
||||
add(new NumberDataType("SIN", 16, SIG, 0x8000, 0x8001, 0x7fff, 1, NULL));
|
||||
add(new NumberDataType("SIN", 16, SIG, 0x8000, 0x8001, 0x7fff, 1, nullptr));
|
||||
// signed integer, -32767 - +32767, big endian
|
||||
add(new NumberDataType("SIR", 16, SIG|REV, 0x8000, 0x8001, 0x7fff, 1, NULL));
|
||||
add(new NumberDataType("SIR", 16, SIG|REV, 0x8000, 0x8001, 0x7fff, 1, nullptr));
|
||||
// unsigned 3 bytes int, 0 - 16777214, little endian
|
||||
add(new NumberDataType("U3N", 24, 0, 0xffffff, 0, 0xfffffe, 1, NULL));
|
||||
add(new NumberDataType("U3N", 24, 0, 0xffffff, 0, 0xfffffe, 1, nullptr));
|
||||
// unsigned 3 bytes int, 0 - 16777214, big endian
|
||||
add(new NumberDataType("U3R", 24, REV, 0xffffff, 0, 0xfffffe, 1, NULL));
|
||||
add(new NumberDataType("U3R", 24, REV, 0xffffff, 0, 0xfffffe, 1, nullptr));
|
||||
// signed 3 bytes int, -8388607 - +8388607, little endian
|
||||
add(new NumberDataType("S3N", 24, SIG, 0x800000, 0x800001, 0xffffff, 1, NULL));
|
||||
add(new NumberDataType("S3N", 24, SIG, 0x800000, 0x800001, 0xffffff, 1, nullptr));
|
||||
// signed 3 bytes int, -8388607 - +8388607, big endian
|
||||
add(new NumberDataType("S3R", 24, SIG|REV, 0x800000, 0x800001, 0xffffff, 1, NULL));
|
||||
add(new NumberDataType("S3R", 24, SIG|REV, 0x800000, 0x800001, 0xffffff, 1, nullptr));
|
||||
// unsigned integer, 0 - 4294967294, little endian
|
||||
add(new NumberDataType("ULG", 32, 0, 0xffffffff, 0, 0xfffffffe, 1, NULL));
|
||||
add(new NumberDataType("ULG", 32, 0, 0xffffffff, 0, 0xfffffffe, 1, nullptr));
|
||||
// unsigned integer, 0 - 4294967294, big endian
|
||||
add(new NumberDataType("ULR", 32, REV, 0xffffffff, 0, 0xfffffffe, 1, NULL));
|
||||
add(new NumberDataType("ULR", 32, REV, 0xffffffff, 0, 0xfffffffe, 1, nullptr));
|
||||
// signed integer, -2147483647 - +2147483647, little endian
|
||||
add(new NumberDataType("SLG", 32, SIG, 0x80000000, 0x80000001, 0xffffffff, 1, NULL));
|
||||
add(new NumberDataType("SLG", 32, SIG, 0x80000000, 0x80000001, 0xffffffff, 1, nullptr));
|
||||
// signed integer, -2147483647 - +2147483647, big endian
|
||||
add(new NumberDataType("SLR", 32, SIG|REV, 0x80000000, 0x80000001, 0xffffffff, 1, NULL));
|
||||
add(new NumberDataType("SLR", 32, SIG|REV, 0x80000000, 0x80000001, 0xffffffff, 1, nullptr));
|
||||
add(new NumberDataType("BI0", 7, ADJ|REQ, 0, 0, 1)); // bit 0 (up to 7 bits until bit 6)
|
||||
add(new NumberDataType("BI1", 7, ADJ|REQ, 0, 1, 1)); // bit 1 (up to 7 bits until bit 7)
|
||||
add(new NumberDataType("BI2", 6, ADJ|REQ, 0, 2, 1)); // bit 2 (up to 6 bits until bit 7)
|
||||
@@ -1056,10 +1056,10 @@ const DataType* DataTypeList::get(const string& id, size_t length) const {
|
||||
}
|
||||
auto it = m_typesById.find(id);
|
||||
if (it == m_typesById.end()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
if (length > 0 && !it->second->isAdjustableLength()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ using std::ostringstream;
|
||||
#define LENGTH_SEPARATOR ':'
|
||||
|
||||
/** the replacement string for undefined values (in UI and CSV). */
|
||||
#define NULL_VALUE "-"
|
||||
#define nullptr_VALUE "-"
|
||||
|
||||
/** the separator character used between fields (in UI only). */
|
||||
#define UI_FIELD_SEPARATOR ';'
|
||||
@@ -134,7 +134,7 @@ enum PartType {
|
||||
/** bit flag for @a DataType: fixed width formatting. */
|
||||
#define FIX 0x20
|
||||
|
||||
/** bit flag for @a DataType: value may not be NULL. */
|
||||
/** bit flag for @a DataType: value may not be nullptr. */
|
||||
#define REQ 0x40
|
||||
|
||||
/** bit flag for @a DataType: binary representation is hex converted to decimal and interpreted as 2 digits
|
||||
@@ -256,7 +256,7 @@ class DataType {
|
||||
* @param length the number of symbols to write, or @a REMAIN_LEN.
|
||||
* @param input the @a istringstream to parse the formatted value from.
|
||||
* @param output the @a SymbolString to write the binary value to.
|
||||
* @param usedLength the variable in which to store the used length in bytes, or NULL.
|
||||
* @param usedLength the variable in which to store the used length in bytes, or nullptr.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t writeSymbols(size_t offset, size_t length, istringstream* input,
|
||||
@@ -399,7 +399,7 @@ class NumberDataType : public DataType {
|
||||
* @param minValue the minimum raw value.
|
||||
* @param maxValue the maximum raw value.
|
||||
* @param divisor the divisor (negative for reciprocal).
|
||||
* @param baseType the base @a NumberDataType for derived instances, or NULL.
|
||||
* @param baseType the base @a NumberDataType for derived instances, or nullptr.
|
||||
*/
|
||||
NumberDataType(const string& id, size_t bitCount, uint16_t flags, unsigned int replacement,
|
||||
unsigned int minValue, unsigned int maxValue, int divisor,
|
||||
@@ -415,10 +415,10 @@ class NumberDataType : public DataType {
|
||||
* @param replacement the replacement value (no replacement if zero).
|
||||
* @param firstBit the offset to the first bit.
|
||||
* @param divisor the divisor (negative for reciprocal).
|
||||
* @param baseType the base @a NumberDataType for derived instances, or NULL.
|
||||
* @param baseType the base @a NumberDataType for derived instances, or nullptr.
|
||||
*/
|
||||
NumberDataType(const string& id, size_t bitCount, uint16_t flags, unsigned int replacement,
|
||||
int16_t firstBit, int divisor, const NumberDataType* baseType = NULL)
|
||||
int16_t firstBit, int divisor, const NumberDataType* baseType = nullptr)
|
||||
: DataType(id, bitCount, flags|NUM, replacement), m_minValue(0), m_maxValue((1 << bitCount)-1), m_divisor(divisor),
|
||||
m_precision(0), m_firstBit(firstBit), m_baseType(baseType) {}
|
||||
|
||||
@@ -490,7 +490,7 @@ class NumberDataType : public DataType {
|
||||
* @param length the number of symbols to write, or @a REMAIN_LEN.
|
||||
* @param output the @a SymbolString to write the binary value to.
|
||||
* @param usedLength the variable in which to store the used length in bytes,
|
||||
* or NULL.
|
||||
* or nullptr.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
result_t writeRawValue(unsigned int value, size_t offset, size_t length,
|
||||
@@ -568,7 +568,7 @@ class DataTypeList {
|
||||
* Gets the @a DataType instance with the specified ID.
|
||||
* @param id the ID string (excluding optional length suffix).
|
||||
* @param length the length in bytes, or 0 for default.
|
||||
* @return the @a DataType instance, or NULL if not available.
|
||||
* @return the @a DataType instance, or nullptr if not available.
|
||||
* Note: the caller may not free the instance.
|
||||
*/
|
||||
const DataType* get(const string& id, size_t length = 0) const;
|
||||
|
||||
+10
-10
@@ -52,7 +52,7 @@ Device::~Device() {
|
||||
}
|
||||
|
||||
Device* Device::create(const char* name, bool checkDevice, bool readOnly, bool initialSend) {
|
||||
if (strchr(name, '/') == NULL && strchr(name, ':') != NULL) {
|
||||
if (strchr(name, '/') == nullptr && strchr(name, ':') != nullptr) {
|
||||
char* in = strdup(name);
|
||||
bool udp = false;
|
||||
char* addrpos = in;
|
||||
@@ -61,24 +61,24 @@ Device* Device::create(const char* name, bool checkDevice, bool readOnly, bool i
|
||||
addrpos += 4;
|
||||
portpos = strchr(addrpos, ':');
|
||||
}
|
||||
if (portpos == NULL) {
|
||||
if (portpos == nullptr) {
|
||||
free(in);
|
||||
return NULL; // invalid protocol or missing port
|
||||
return nullptr; // invalid protocol or missing port
|
||||
}
|
||||
result_t result = RESULT_OK;
|
||||
unsigned int port = parseInt(portpos+1, 10, 1, 65535, &result);
|
||||
if (result != RESULT_OK) {
|
||||
free(in);
|
||||
return NULL; // invalid port
|
||||
return nullptr; // invalid port
|
||||
}
|
||||
struct sockaddr_in address;
|
||||
memset(reinterpret_cast<char*>(&address), 0, sizeof(address));
|
||||
*portpos = 0;
|
||||
if (inet_aton(addrpos, &address.sin_addr) == 0) {
|
||||
struct hostent* h = gethostbyname(addrpos);
|
||||
if (h == NULL) {
|
||||
if (h == nullptr) {
|
||||
free(in);
|
||||
return NULL; // invalid host
|
||||
return nullptr; // invalid host
|
||||
}
|
||||
memcpy(&address.sin_addr, h->h_addr_list[0], h->h_length);
|
||||
}
|
||||
@@ -114,7 +114,7 @@ result_t Device::send(symbol_t value) {
|
||||
if (m_readOnly || write(value) != 1) {
|
||||
return RESULT_ERR_SEND;
|
||||
}
|
||||
if (m_listener != NULL) {
|
||||
if (m_listener != nullptr) {
|
||||
m_listener->notifyDeviceData(value, false);
|
||||
}
|
||||
return RESULT_OK;
|
||||
@@ -140,7 +140,7 @@ result_t Device::recv(unsigned int timeout, symbol_t* value) {
|
||||
|
||||
fds[0].fd = m_fd;
|
||||
fds[0].events = POLLIN | POLLERR | POLLHUP | POLLRDHUP;
|
||||
ret = ppoll(fds, nfds, &tdiff, NULL);
|
||||
ret = ppoll(fds, nfds, &tdiff, nullptr);
|
||||
if (ret >= 0 && fds[0].revents & (POLLERR | POLLHUP | POLLRDHUP)) {
|
||||
ret = -1;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ result_t Device::recv(unsigned int timeout, symbol_t* value) {
|
||||
FD_ZERO(&exceptfds);
|
||||
FD_SET(m_fd, &readfds);
|
||||
|
||||
ret = pselect(m_fd + 1, &readfds, NULL, &exceptfds, &tdiff, NULL);
|
||||
ret = pselect(m_fd + 1, &readfds, nullptr, &exceptfds, &tdiff, nullptr);
|
||||
if (ret >= 1 && FD_ISSET(m_fd, &exceptfds)) {
|
||||
ret = -1;
|
||||
}
|
||||
@@ -178,7 +178,7 @@ result_t Device::recv(unsigned int timeout, symbol_t* value) {
|
||||
close();
|
||||
return RESULT_ERR_DEVICE;
|
||||
}
|
||||
if (m_listener != NULL) {
|
||||
if (m_listener != nullptr) {
|
||||
m_listener->notifyDeviceData(*value, true);
|
||||
}
|
||||
return RESULT_OK;
|
||||
|
||||
@@ -72,7 +72,7 @@ class Device {
|
||||
*/
|
||||
Device(const char* name, bool checkDevice, bool readOnly, bool initialSend)
|
||||
: m_name(name), m_checkDevice(checkDevice), m_readOnly(readOnly), m_initialSend(initialSend), m_fd(-1),
|
||||
m_listener(NULL) {}
|
||||
m_listener(nullptr) {}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
@@ -85,7 +85,7 @@ class Device {
|
||||
* @param checkDevice whether to regularly check the device availability (only for serial devices).
|
||||
* @param readOnly whether to allow read access to the device only.
|
||||
* @param initialSend whether to send an initial @a ESC symbol in @a open().
|
||||
* @return the new @a Device, or NULL on error.
|
||||
* @return the new @a Device, or nullptr on error.
|
||||
* Note: the caller needs to free the created instance.
|
||||
*/
|
||||
static Device* create(const char* name, bool checkDevice = true, bool readOnly = false,
|
||||
@@ -191,7 +191,7 @@ class Device {
|
||||
|
||||
|
||||
private:
|
||||
/** the @a DeviceListener, or NULL. */
|
||||
/** the @a DeviceListener, or nullptr. */
|
||||
DeviceListener* m_listener;
|
||||
};
|
||||
|
||||
@@ -243,7 +243,7 @@ class NetworkDevice : public Device {
|
||||
NetworkDevice(const char* name, const struct sockaddr_in& address, bool readOnly, bool initialSend,
|
||||
bool udp)
|
||||
: Device(name, true, readOnly, initialSend), m_address(address), m_udp(udp),
|
||||
m_buffer(NULL), m_bufSize(0), m_bufLen(0), m_bufPos(0) {}
|
||||
m_buffer(nullptr), m_bufSize(0), m_bufLen(0), m_bufPos(0) {}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
@@ -284,7 +284,7 @@ class NetworkDevice : public Device {
|
||||
/** true for UDP, false to TCP. */
|
||||
const bool m_udp;
|
||||
|
||||
/** the buffer memory, or NULL. */
|
||||
/** the buffer memory, or nullptr. */
|
||||
symbol_t* m_buffer;
|
||||
|
||||
/** the buffer size. */
|
||||
|
||||
@@ -40,18 +40,18 @@ istream* FileReader::openFile(const string& filename, string* errorDescription,
|
||||
struct stat st;
|
||||
if (stat(filename.c_str(), &st) != 0) {
|
||||
*errorDescription = filename;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
*errorDescription = filename+" is a directory";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
ifstream* stream = new ifstream();
|
||||
stream->open(filename.c_str(), ifstream::in);
|
||||
if (!stream->is_open()) {
|
||||
*errorDescription = filename;
|
||||
delete(stream);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
if (time) {
|
||||
*time = st.st_mtime;
|
||||
|
||||
+19
-19
@@ -79,10 +79,10 @@ class FileReader {
|
||||
* Open a file as stream for reading.
|
||||
* @param filename the name of the file being read.
|
||||
* @param errorDescription a string in which to store the error description in case of error.
|
||||
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or NULL.
|
||||
* @return the opened @a istream on success, or NULL on error.
|
||||
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or nullptr.
|
||||
* @return the opened @a istream on success, or nullptr on error.
|
||||
*/
|
||||
static istream* openFile(const string& filename, string* errorDescription, time_t* time = NULL);
|
||||
static istream* openFile(const string& filename, string* errorDescription, time_t* time = nullptr);
|
||||
|
||||
/**
|
||||
* Read the definitions from a stream.
|
||||
@@ -90,16 +90,16 @@ class FileReader {
|
||||
* @param filename the relative name of the file being read.
|
||||
* @param mtime a @a time_t value with the modification time of the file.
|
||||
* @param verbose whether to verbosely log problems.
|
||||
* @param defaults the default values by name (potentially overwritten by file name), or NULL to not use defaults.
|
||||
* @param defaults the default values by name (potentially overwritten by file name), or nullptr to not use defaults.
|
||||
* @param errorDescription a string in which to store the error description in case of error.
|
||||
* @param replace whether to replace an already existing entry.
|
||||
* @param hash optional pointer to a @a size_t value for storing the hash 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.
|
||||
* @param hash optional pointer to a @a size_t value for storing the hash of the file, or nullptr.
|
||||
* @param size optional pointer to a @a size_t value for storing the normalized size of the file, or nullptr.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose,
|
||||
map<string, string>* defaults, string* errorDescription, bool replace = false, size_t* hash = NULL,
|
||||
size_t* size = NULL);
|
||||
map<string, string>* defaults, string* errorDescription, bool replace = false, size_t* hash = nullptr,
|
||||
size_t* size = nullptr);
|
||||
|
||||
/**
|
||||
* Read a single line definition from the stream.
|
||||
@@ -110,8 +110,8 @@ class FileReader {
|
||||
* @param row the definition row to clear and update with the read data (for performance reasons only).
|
||||
* @param errorDescription a string in which to store the error description in case of error.
|
||||
* @param replace whether to replace an already existing entry.
|
||||
* @param hash optional pointer to a @a size_t value for updating with the hash of the line, or NULL.
|
||||
* @param size optional pointer to a @a size_t value for updating with the normalized length of the line, or NULL.
|
||||
* @param hash optional pointer to a @a size_t value for updating with the hash of the line, or nullptr.
|
||||
* @param size optional pointer to a @a size_t value for updating with the normalized length of the line, or nullptr.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t readLineFromStream(istream* stream, const string& filename, bool verbose,
|
||||
@@ -146,12 +146,12 @@ class FileReader {
|
||||
* @param stream the @a istream to read from.
|
||||
* @param row the @a vector to which to add the fields. This will be empty for completely empty and comment lines.
|
||||
* @param lineNo the current line number (incremented with each line read).
|
||||
* @param hash optional pointer to a @a size_t value for combining the hash of the line with, or NULL.
|
||||
* @param size optional pointer to a @a size_t value to add the trimmed line length to, or NULL.
|
||||
* @param hash optional pointer to a @a size_t value for combining the hash of the line with, or nullptr.
|
||||
* @param size optional pointer to a @a size_t value to add the trimmed line length to, or nullptr.
|
||||
* @return true if there are more lines to read, false when there are no more lines left.
|
||||
*/
|
||||
static bool splitFields(istream* stream, vector<string>* row, unsigned int* lineNo,
|
||||
size_t* hash = NULL, size_t* size = NULL);
|
||||
size_t* hash = nullptr, size_t* size = nullptr);
|
||||
|
||||
/**
|
||||
* Format the specified hash as 8 hex digits to the output stream.
|
||||
@@ -209,20 +209,20 @@ class MappedFileReader : public FileReader {
|
||||
|
||||
// @copydoc
|
||||
result_t readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose,
|
||||
map<string, string>* defaults, string* errorDescription, bool replace = false, size_t* hash = NULL,
|
||||
size_t* size = NULL) override;
|
||||
map<string, string>* defaults, string* errorDescription, bool replace = false, size_t* hash = nullptr,
|
||||
size_t* size = nullptr) override;
|
||||
|
||||
/**
|
||||
* Extract default values from the file name.
|
||||
* @param filename the name of the file (without path)
|
||||
* @param defaults the default values by name to add to.
|
||||
* @param destAddress optional pointer to a variable in which to store the numeric destination address, or NULL.
|
||||
* @param software optional pointer to a in which to store the numeric software version, or NULL.
|
||||
* @param hardware optional pointer to a in which to store the numeric hardware version, or NULL.
|
||||
* @param destAddress optional pointer to a variable in which to store the numeric destination address, or nullptr.
|
||||
* @param software optional pointer to a in which to store the numeric software version, or nullptr.
|
||||
* @param hardware optional pointer to a in which to store the numeric hardware version, or nullptr.
|
||||
* @return true if the minimum parts were extracted, false otherwise.
|
||||
*/
|
||||
virtual bool extractDefaultsFromFilename(const string& filename, map<string, string>* defaults,
|
||||
symbol_t* destAddress = NULL, unsigned int* software = NULL, unsigned int* hardware = NULL) const {
|
||||
symbol_t* destAddress = nullptr, unsigned int* software = nullptr, unsigned int* hardware = nullptr) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+55
-55
@@ -115,7 +115,7 @@ Message::Message(const string& circuit, const string& level, const string& name,
|
||||
m_id({pb, sb}), m_key(createKey(pb, sb, broadcast)),
|
||||
m_data(data), m_deleteData(deleteData),
|
||||
m_pollPriority(0),
|
||||
m_usedByCondition(false), m_isScanMessage(true), m_condition(NULL),
|
||||
m_usedByCondition(false), m_isScanMessage(true), m_condition(nullptr),
|
||||
m_lastUpdateTime(0), m_lastChangeTime(0), m_pollCount(0), m_lastPollTime(0) {
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ Message::Message(const string& circuit, const string& level, const string& name,
|
||||
/**
|
||||
* Helper method for getting a default if the value is empty.
|
||||
* @param value the value to check.
|
||||
* @param defaults a @a vector of defaults, or NULL.
|
||||
* @param defaults a @a vector of defaults, or nullptr.
|
||||
* @param pos the position in defaults.
|
||||
* @param replaceStar whether to replace a star in the default with the value.
|
||||
* If there is no star in the default and the value is empty, use the complete
|
||||
@@ -433,7 +433,7 @@ result_t Message::create(const string& filename, const DataFieldTemplates* templ
|
||||
if (subIt != subRowDefaults.end()) {
|
||||
subRows->insert(subRows->begin(), subIt->second.begin(), subIt->second.end());
|
||||
}
|
||||
const DataField* data = NULL;
|
||||
const DataField* data = nullptr;
|
||||
if (subRows->empty()) {
|
||||
vector<const SingleDataField*> fields;
|
||||
data = new DataFieldSet("", fields);
|
||||
@@ -610,7 +610,7 @@ void Message::setUsedByCondition() {
|
||||
}
|
||||
|
||||
bool Message::isAvailable() {
|
||||
return (m_condition == NULL) || m_condition->isTrue();
|
||||
return (m_condition == nullptr) || m_condition->isTrue();
|
||||
}
|
||||
|
||||
bool Message::hasField(const char* fieldName, bool numeric) const {
|
||||
@@ -653,7 +653,7 @@ result_t Message::prepareMasterPart(size_t index, char separator, istringstream*
|
||||
for (size_t i = 2; i < m_id.size(); i++) {
|
||||
master->push_back(m_id[i]);
|
||||
}
|
||||
result_t result = m_data->write(separator, getIdLength(), input, master, NULL);
|
||||
result_t result = m_data->write(separator, getIdLength(), input, master, nullptr);
|
||||
if (result != RESULT_OK) {
|
||||
return result;
|
||||
}
|
||||
@@ -667,7 +667,7 @@ result_t Message::prepareSlave(istringstream* input, SlaveSymbolString* slave) {
|
||||
}
|
||||
slave->clear();
|
||||
slave->push_back(0); // length, will be set later
|
||||
result_t result = m_data->write(UI_FIELD_SEPARATOR, 0, input, slave, NULL);
|
||||
result_t result = m_data->write(UI_FIELD_SEPARATOR, 0, input, slave, nullptr);
|
||||
if (result != RESULT_OK) {
|
||||
return result;
|
||||
}
|
||||
@@ -730,7 +730,7 @@ result_t Message::decodeLastData(bool master, bool leadingSeparator, const char*
|
||||
if (result < RESULT_OK) {
|
||||
return result;
|
||||
}
|
||||
if (result == RESULT_EMPTY && (fieldName != NULL || fieldIndex >= 0)) {
|
||||
if (result == RESULT_EMPTY && (fieldName != nullptr || fieldIndex >= 0)) {
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
}
|
||||
return result;
|
||||
@@ -763,7 +763,7 @@ result_t Message::decodeLastData(bool leadingSeparator, const char* fieldName,
|
||||
result = RESULT_OK; // OK if at least one part was non-empty
|
||||
}
|
||||
}
|
||||
if (result == RESULT_EMPTY && (fieldName != NULL || fieldIndex >= 0)) {
|
||||
if (result == RESULT_EMPTY && (fieldName != nullptr || fieldIndex >= 0)) {
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
}
|
||||
return result;
|
||||
@@ -808,7 +808,7 @@ bool Message::isLessPollWeight(const Message* other) const {
|
||||
|
||||
void Message::dumpHeader(const vector<string>* fieldNames, ostream* output) {
|
||||
bool first = true;
|
||||
if (fieldNames == NULL) {
|
||||
if (fieldNames == nullptr) {
|
||||
for (const auto& fieldName : defaultMessageFieldMap) {
|
||||
if (first) {
|
||||
first = false;
|
||||
@@ -831,7 +831,7 @@ void Message::dumpHeader(const vector<string>* fieldNames, ostream* output) {
|
||||
|
||||
void Message::dump(const vector<string>* fieldNames, bool withConditions, ostream* output) const {
|
||||
bool first = true;
|
||||
if (fieldNames == NULL) {
|
||||
if (fieldNames == nullptr) {
|
||||
for (const auto& fieldName : knownFieldNamesFull) {
|
||||
if (fieldName == FIELNAME_LEVEL) {
|
||||
continue; // access level not included in default dump format
|
||||
@@ -857,7 +857,7 @@ void Message::dump(const vector<string>* fieldNames, bool withConditions, ostrea
|
||||
|
||||
void Message::dumpField(const string& fieldName, bool withConditions, ostream* output) const {
|
||||
if (fieldName == "type") {
|
||||
if (withConditions && m_condition != NULL) {
|
||||
if (withConditions && m_condition != nullptr) {
|
||||
m_condition->dump(false, output);
|
||||
}
|
||||
if (m_isPassive) {
|
||||
@@ -976,7 +976,7 @@ void Message::decodeJson(bool leadingSeparator, bool appendDirection, bool addRa
|
||||
}
|
||||
size_t pos = (size_t)output->tellp();
|
||||
*output << ",\n \"fields\": {";
|
||||
result_t dret = decodeLastData(false, NULL, -1, outputFormat, output);
|
||||
result_t dret = decodeLastData(false, nullptr, -1, outputFormat, output);
|
||||
if (dret == RESULT_OK) {
|
||||
*output << "\n }";
|
||||
} else {
|
||||
@@ -1023,9 +1023,9 @@ ChainedMessage::ChainedMessage(const string& circuit, const string& level, const
|
||||
ChainedMessage::~ChainedMessage() {
|
||||
for (size_t index = 0; index < m_ids.size(); index++) {
|
||||
delete m_lastMasterDatas[index];
|
||||
m_lastMasterDatas[index] = NULL;
|
||||
m_lastMasterDatas[index] = nullptr;
|
||||
delete m_lastSlaveDatas[index];
|
||||
m_lastSlaveDatas[index] = NULL;
|
||||
m_lastSlaveDatas[index] = nullptr;
|
||||
}
|
||||
free(m_lastMasterDatas);
|
||||
free(m_lastSlaveDatas);
|
||||
@@ -1113,7 +1113,7 @@ result_t ChainedMessage::prepareMasterPart(size_t index, char separator, istring
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
}
|
||||
MasterSymbolString allData;
|
||||
result_t result = m_data->write(separator, 0, input, &allData, NULL);
|
||||
result_t result = m_data->write(separator, 0, input, &allData, nullptr);
|
||||
if (result != RESULT_OK) {
|
||||
return result;
|
||||
}
|
||||
@@ -1271,14 +1271,14 @@ void ChainedMessage::dumpField(const string& fieldName, bool withConditions, ost
|
||||
Message* getFirstAvailable(const vector<Message*>& messages, const MasterSymbolString* sameIdExtAs,
|
||||
const bool onlyAvailable = true) {
|
||||
for (auto message : messages) {
|
||||
if (sameIdExtAs && !message->checkId(*sameIdExtAs, NULL)) {
|
||||
if (sameIdExtAs && !message->checkId(*sameIdExtAs, nullptr)) {
|
||||
continue;
|
||||
}
|
||||
if (!onlyAvailable || message->isAvailable()) {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1288,7 +1288,7 @@ Message* getFirstAvailable(const vector<Message*>& messages, const MasterSymbolS
|
||||
* @param onlyAvailable true to include only available messages (default true), false to also include messages that
|
||||
* are currently not available (e.g. due to unresolved or false conditions).
|
||||
*/
|
||||
Message* getFirstAvailable(const vector<Message*>& messages, const Message* sameIdExtAs = NULL,
|
||||
Message* getFirstAvailable(const vector<Message*>& messages, const Message* sameIdExtAs = nullptr,
|
||||
const bool onlyAvailable = true) {
|
||||
for (auto message : messages) {
|
||||
if (sameIdExtAs && !message->checkId(*sameIdExtAs)) {
|
||||
@@ -1298,7 +1298,7 @@ Message* getFirstAvailable(const vector<Message*>& messages, const Message* same
|
||||
return message;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1445,7 +1445,7 @@ result_t Condition::create(const string& condName, const map<string, string>& ro
|
||||
|
||||
SimpleCondition* SimpleCondition::derive(const string& valueList) const {
|
||||
if (valueList.empty()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
string useValueList = valueList;
|
||||
string name = m_condName+useValueList;
|
||||
@@ -1458,18 +1458,18 @@ SimpleCondition* SimpleCondition::derive(const string& valueList) const {
|
||||
vector<string> values;
|
||||
result = splitValues(useValueList, &values);
|
||||
if (result != RESULT_OK) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return new SimpleStringCondition(name, m_refName, m_circuit, m_level, m_name, m_dstAddress, m_field, values);
|
||||
}
|
||||
// numbers
|
||||
if (!isNumeric()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
vector<unsigned int> valueRanges;
|
||||
result = splitValues(useValueList, &valueRanges);
|
||||
if (result != RESULT_OK) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return new SimpleNumericCondition(name, m_refName, m_circuit, m_level, m_name, m_dstAddress, m_field, valueRanges);
|
||||
}
|
||||
@@ -1496,7 +1496,7 @@ CombinedCondition* SimpleCondition::combineAnd(Condition* other) {
|
||||
|
||||
result_t SimpleCondition::resolve(void (*readMessageFunc)(Message* message), MessageMap* messages,
|
||||
ostringstream* errorMessage) {
|
||||
if (m_message == NULL) {
|
||||
if (m_message == nullptr) {
|
||||
Message* message;
|
||||
if (m_name.length() == 0) {
|
||||
message = messages->getScanMessage(m_dstAddress);
|
||||
@@ -1525,12 +1525,12 @@ result_t SimpleCondition::resolve(void (*readMessageFunc)(Message* message), Mes
|
||||
// clone the message with dedicated dstAddress if necessary
|
||||
uint64_t key = message->getDerivedKey(m_dstAddress);
|
||||
const vector<Message*>* derived = messages->getByKey(key);
|
||||
if (derived == NULL) {
|
||||
if (derived == nullptr) {
|
||||
message = message->derive(m_dstAddress, true);
|
||||
messages->add(true, message);
|
||||
} else {
|
||||
Message* first = getFirstAvailable(*derived, message);
|
||||
if (first == NULL) {
|
||||
if (first == nullptr) {
|
||||
*errorMessage << ": conditional derived message " << message->getCircuit() << "." << message->getName()
|
||||
<< " for " << hex << setw(2) << setfill('0') << static_cast<unsigned>(m_dstAddress) << " not found";
|
||||
return RESULT_ERR_INVALID_ARG;
|
||||
@@ -1540,7 +1540,7 @@ result_t SimpleCondition::resolve(void (*readMessageFunc)(Message* message), Mes
|
||||
}
|
||||
|
||||
if (m_hasValues) {
|
||||
if (!message->hasField(m_field.length() > 0 ? m_field.c_str() : NULL, isNumeric())) {
|
||||
if (!message->hasField(m_field.length() > 0 ? m_field.c_str() : nullptr, isNumeric())) {
|
||||
*errorMessage << (isNumeric() ? ": numeric field " : ": string field ") << m_field << " not found";
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
}
|
||||
@@ -1551,7 +1551,7 @@ result_t SimpleCondition::resolve(void (*readMessageFunc)(Message* message), Mes
|
||||
messages->addPollMessage(true, message);
|
||||
}
|
||||
}
|
||||
if (m_message->getLastUpdateTime() == 0 && readMessageFunc != NULL) {
|
||||
if (m_message->getLastUpdateTime() == 0 && readMessageFunc != nullptr) {
|
||||
(*readMessageFunc)(m_message);
|
||||
}
|
||||
return RESULT_OK;
|
||||
@@ -1575,7 +1575,7 @@ bool SimpleCondition::isTrue() {
|
||||
|
||||
bool SimpleNumericCondition::checkValue(const Message* message, const string& field) {
|
||||
unsigned int value = 0;
|
||||
result_t result = message->decodeLastDataNumField(field.length() == 0 ? NULL : field.c_str(), -1, &value);
|
||||
result_t result = message->decodeLastDataNumField(field.length() == 0 ? nullptr : field.c_str(), -1, &value);
|
||||
if (result == RESULT_OK) {
|
||||
for (size_t i = 0; i+1 < m_valueRanges.size(); i+=2) {
|
||||
if (m_valueRanges[i] <= value && value <= m_valueRanges[i+1]) {
|
||||
@@ -1590,7 +1590,7 @@ bool SimpleNumericCondition::checkValue(const Message* message, const string& fi
|
||||
|
||||
bool SimpleStringCondition::checkValue(const Message* message, const string& field) {
|
||||
ostringstream output;
|
||||
result_t result = message->decodeLastData(false, field.length() == 0 ? NULL : field.c_str(), -1, 0, &output);
|
||||
result_t result = message->decodeLastData(false, field.length() == 0 ? nullptr : field.c_str(), -1, 0, &output);
|
||||
if (result == RESULT_OK) {
|
||||
string value = output.str();
|
||||
for (size_t i = 0; i < m_values.size(); i++) {
|
||||
@@ -1755,7 +1755,7 @@ result_t MessageMap::add(bool storeByName, Message* message, bool replace) {
|
||||
}
|
||||
} else {
|
||||
Message *other = getFirstAvailable(keyIt->second, message);
|
||||
if (other != NULL && (!conditional || !other->isConditional())) {
|
||||
if (other != nullptr && (!conditional || !other->isConditional())) {
|
||||
unlock();
|
||||
return RESULT_ERR_DUPLICATE; // duplicate key
|
||||
}
|
||||
@@ -1838,7 +1838,7 @@ result_t MessageMap::add(bool storeByName, Message* message, bool replace) {
|
||||
}
|
||||
|
||||
void MessageMap::remove(Message* message) {
|
||||
if (message == NULL) {
|
||||
if (message == nullptr) {
|
||||
return;
|
||||
}
|
||||
lock();
|
||||
@@ -2010,9 +2010,9 @@ result_t MessageMap::addDefaultFromFile(const string& filename, unsigned int lin
|
||||
*errorDescription = "condition "+type+" already defined";
|
||||
return RESULT_ERR_DUPLICATE_NAME;
|
||||
}
|
||||
SimpleCondition* condition = NULL;
|
||||
SimpleCondition* condition = nullptr;
|
||||
result_t result = Condition::create(type, defaults, row, &condition);
|
||||
if (condition == NULL || result != RESULT_OK) {
|
||||
if (condition == nullptr || result != RESULT_OK) {
|
||||
*errorDescription = "invalid condition";
|
||||
return result;
|
||||
}
|
||||
@@ -2077,12 +2077,12 @@ result_t MessageMap::readConditions(const string& filename, string* types, strin
|
||||
types->erase(0, pos+1);
|
||||
} else {
|
||||
bool store = false;
|
||||
*condition = NULL;
|
||||
*condition = nullptr;
|
||||
while ((pos=types->find(']')) != string::npos) {
|
||||
// simple condition
|
||||
string key = filename+":"+types->substr(1, pos-1);
|
||||
it = m_conditions.find(key);
|
||||
Condition* add = NULL;
|
||||
Condition* add = nullptr;
|
||||
if (it == m_conditions.end()) {
|
||||
// check for on-the-fly condition
|
||||
size_t sep = key.find_first_of("=<>", filename.length()+1);
|
||||
@@ -2091,14 +2091,14 @@ result_t MessageMap::readConditions(const string& filename, string* types, strin
|
||||
if (it != m_conditions.end()) {
|
||||
// derive from another condition
|
||||
add = it->second->derive(key.substr(sep));
|
||||
if (add == NULL) {
|
||||
if (add == nullptr) {
|
||||
*errorDescription = "derive condition with values "+key.substr(sep)+" failed";
|
||||
return RESULT_ERR_INVALID_ARG;
|
||||
}
|
||||
m_conditions[key] = add; // store derived condition
|
||||
}
|
||||
}
|
||||
if (add == NULL) {
|
||||
if (add == nullptr) {
|
||||
// shared condition not available
|
||||
*errorDescription = "condition "+types->substr(1, pos-1)+" not defined";
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
@@ -2229,7 +2229,7 @@ result_t MessageMap::readFromStream(istream* stream, const string& filename, con
|
||||
|
||||
result_t MessageMap::addFromFile(const string& filename, unsigned int lineNo, map<string, string>* row,
|
||||
vector< map<string, string> >* subRows, string* errorDescription, bool replace) {
|
||||
Condition* condition = NULL;
|
||||
Condition* condition = nullptr;
|
||||
string types = AttributedItem::pluck("type", row);
|
||||
result_t result = readConditions(filename, &types, errorDescription, &condition);
|
||||
if (result != RESULT_OK) {
|
||||
@@ -2242,9 +2242,9 @@ result_t MessageMap::addFromFile(const string& filename, unsigned int lineNo, ma
|
||||
return RESULT_ERR_INVALID_ARG;
|
||||
}
|
||||
types = types.substr(1);
|
||||
Instruction* instruction = NULL;
|
||||
Instruction* instruction = nullptr;
|
||||
result = Instruction::create(filename, types, condition, *row, getDefaults()[""], &instruction);
|
||||
if (instruction == NULL || result != RESULT_OK) {
|
||||
if (instruction == nullptr || result != RESULT_OK) {
|
||||
*errorDescription = "invalid instruction";
|
||||
return result;
|
||||
}
|
||||
@@ -2308,11 +2308,11 @@ Message* MessageMap::getScanMessage(symbol_t dstAddress) {
|
||||
return m_broadcastScanMessage;
|
||||
}
|
||||
if (!isValidAddress(dstAddress, true) || isMaster(dstAddress)) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
uint64_t key = m_scanMessage->getDerivedKey(dstAddress);
|
||||
const vector<Message*>* msgs = getByKey(key);
|
||||
if (msgs != NULL) {
|
||||
if (msgs != nullptr) {
|
||||
return msgs->front();
|
||||
}
|
||||
Message* message = m_scanMessage->derive(dstAddress, true);
|
||||
@@ -2324,7 +2324,7 @@ result_t MessageMap::resolveConditions(bool verbose, string* errorDescription) {
|
||||
result_t overallResult = RESULT_OK;
|
||||
for (const auto& it : m_conditions) {
|
||||
Condition* condition = it.second;
|
||||
result_t result = resolveCondition(NULL, condition, errorDescription);
|
||||
result_t result = resolveCondition(nullptr, condition, errorDescription);
|
||||
if (result != RESULT_OK) {
|
||||
overallResult = result;
|
||||
}
|
||||
@@ -2361,10 +2361,10 @@ result_t MessageMap::executeInstructions(void (*readMessageFunc)(Message* messag
|
||||
continue;
|
||||
}
|
||||
Condition* condition = instruction->getCondition();
|
||||
bool execute = m_addAll || condition == NULL;
|
||||
bool execute = m_addAll || condition == nullptr;
|
||||
if (!execute) {
|
||||
string errorDescription;
|
||||
result_t result = resolveCondition(instruction->isSingleton()?readMessageFunc:NULL, condition,
|
||||
result_t result = resolveCondition(instruction->isSingleton()?readMessageFunc:nullptr, condition,
|
||||
&errorDescription);
|
||||
if (result != RESULT_OK) {
|
||||
overallResult = result;
|
||||
@@ -2474,7 +2474,7 @@ const vector<Message*>* MessageMap::getByKey(uint64_t key) const {
|
||||
if (it != m_messagesByKey.end()) {
|
||||
return &it->second;
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Message* MessageMap::find(const string& circuit, const string& name, const string& levels, bool isWrite,
|
||||
@@ -2501,7 +2501,7 @@ Message* MessageMap::find(const string& circuit, const string& name, const strin
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MessageMap::findAll(const string& circuit, const string& name, const string& levels,
|
||||
@@ -2574,7 +2574,7 @@ Message* MessageMap::find(const MasterSymbolString& master, bool anyDestination,
|
||||
uint64_t baseKey = Message::createKey(master,
|
||||
anyDestination || master[1] != BROADCAST ? m_maxIdLength : m_maxBroadcastIdLength, anyDestination);
|
||||
if (baseKey == INVALID_KEY) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
size_t maxIdLength = Message::getKeyLength(baseKey);
|
||||
for (size_t idLength = maxIdLength; true; idLength--) {
|
||||
@@ -2636,7 +2636,7 @@ Message* MessageMap::find(const MasterSymbolString& master, bool anyDestination,
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MessageMap::invalidateCache(Message* message) {
|
||||
@@ -2656,7 +2656,7 @@ void MessageMap::invalidateCache(Message* message) {
|
||||
}
|
||||
|
||||
void MessageMap::addPollMessage(bool toFront, Message* message) {
|
||||
if (message != NULL && message->getPollPriority() > 0) {
|
||||
if (message != nullptr && message->getPollPriority() > 0) {
|
||||
lock();
|
||||
message->m_lastPollTime = toFront ? 0 : m_pollMessages.size();
|
||||
m_pollMessages.push(message);
|
||||
@@ -2749,7 +2749,7 @@ void MessageMap::clear() {
|
||||
|
||||
Message* MessageMap::getNextPoll() {
|
||||
if (m_pollMessages.empty()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
Message* ret = m_pollMessages.top();
|
||||
m_pollMessages.pop();
|
||||
@@ -2761,7 +2761,7 @@ Message* MessageMap::getNextPoll() {
|
||||
|
||||
void MessageMap::dump(bool withConditions, ostream* output) const {
|
||||
bool first = true;
|
||||
Message::dumpHeader(NULL, output);
|
||||
Message::dumpHeader(nullptr, output);
|
||||
*output << endl;
|
||||
for (const auto it : m_messagesByName) {
|
||||
if (it.first[0] == FIELD_SEPARATOR) { // skip instances stored multiple times (key starting with "-")
|
||||
@@ -2777,7 +2777,7 @@ void MessageMap::dump(bool withConditions, ostream* output) const {
|
||||
} else {
|
||||
*output << endl;
|
||||
}
|
||||
message->dump(NULL, withConditions, output);
|
||||
message->dump(nullptr, withConditions, output);
|
||||
}
|
||||
} else {
|
||||
Message* message = getFirstAvailable(it.second);
|
||||
@@ -2789,7 +2789,7 @@ void MessageMap::dump(bool withConditions, ostream* output) const {
|
||||
} else {
|
||||
*output << endl;
|
||||
}
|
||||
message->dump(NULL, withConditions, output);
|
||||
message->dump(nullptr, withConditions, output);
|
||||
}
|
||||
}
|
||||
if (!first) {
|
||||
|
||||
+36
-36
@@ -90,7 +90,7 @@ class Message : public AttributedItem {
|
||||
* @param data the @a DataField for encoding/decoding the message.
|
||||
* @param deleteData whether to delete the @a DataField during destruction.
|
||||
* @param pollPriority the priority for polling, or 0 for no polling at all.
|
||||
* @param condition the @a Condition for this message, or NULL.
|
||||
* @param condition the @a Condition for this message, or nullptr.
|
||||
*/
|
||||
Message(const string& circuit, const string& level, const string& name,
|
||||
bool isWrite, bool isPassive, const map<string, string>& attributes,
|
||||
@@ -98,7 +98,7 @@ class Message : public AttributedItem {
|
||||
const vector<symbol_t>& id,
|
||||
const DataField* data, bool deleteData,
|
||||
size_t pollPriority = 0,
|
||||
Condition* condition = NULL);
|
||||
Condition* condition = nullptr);
|
||||
|
||||
|
||||
private:
|
||||
@@ -173,11 +173,11 @@ class Message : public AttributedItem {
|
||||
/**
|
||||
* Factory method for creating new instances.
|
||||
* @param filename the name of the file being read.
|
||||
* @param templates the @a DataFieldTemplates to be referenced by name, or NULL.
|
||||
* @param templates the @a DataFieldTemplates to be referenced by name, or nullptr.
|
||||
* @param rowDefaults the mapped message definition defaults.
|
||||
* @param subRowDefaults the mapped field definition defaults.
|
||||
* @param typeStr the single type of message to create.
|
||||
* @param condition the @a Condition instance for the message, or NULL.
|
||||
* @param condition the @a Condition instance for the message, or nullptr.
|
||||
* @param row the mapped message definition row (may be modified).
|
||||
* @param subRows the mapped field definition rows (may be modified).
|
||||
* @param errorDescription a string in which to store the error description in case of error.
|
||||
@@ -333,7 +333,7 @@ class Message : public AttributedItem {
|
||||
/**
|
||||
* Check the ID against the master @a SymbolString data.
|
||||
* @param master the @a MasterSymbolString to check against.
|
||||
* @param index the variable in which to store the message part index, or NULL to ignore.
|
||||
* @param index the variable in which to store the message part index, or nullptr to ignore.
|
||||
* @return true if the ID matches, false otherwise.
|
||||
*/
|
||||
virtual bool checkId(const MasterSymbolString& master, size_t* index) const;
|
||||
@@ -380,7 +380,7 @@ class Message : public AttributedItem {
|
||||
* Return whether this @a Message depends on a @a Condition.
|
||||
* @return true when this @a Message depends on a @a Condition.
|
||||
*/
|
||||
bool isConditional() const { return m_condition != NULL; }
|
||||
bool isConditional() const { return m_condition != nullptr; }
|
||||
|
||||
/**
|
||||
* Return whether this @a Message is available (optionally depending on a @a Condition evaluation).
|
||||
@@ -390,7 +390,7 @@ class Message : public AttributedItem {
|
||||
|
||||
/**
|
||||
* Return whether the field is available.
|
||||
* @param fieldName the name of the field to find, or NULL for any.
|
||||
* @param fieldName the name of the field to find, or nullptr for any.
|
||||
* @param numeric true for a numeric field, false for a string field.
|
||||
* @return true if the field is available.
|
||||
*/
|
||||
@@ -487,7 +487,7 @@ class Message : public AttributedItem {
|
||||
|
||||
/**
|
||||
* Decode a particular numeric field value from the last stored data.
|
||||
* @param fieldName the name of the field to decode, or NULL for the first field.
|
||||
* @param fieldName the name of the field to decode, or nullptr for the first field.
|
||||
* @param fieldIndex the optional index of the field (either named or overall), or -1.
|
||||
* @param output the variable in which to store the value.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
@@ -533,14 +533,14 @@ class Message : public AttributedItem {
|
||||
|
||||
/**
|
||||
* Write the message definition header or parts of it to the @a ostream.
|
||||
* @param fieldNames the list of field names to write, or NULL for all.
|
||||
* @param fieldNames the list of field names to write, or nullptr for all.
|
||||
* @param output the @a ostream to append the formatted value to.
|
||||
*/
|
||||
static void dumpHeader(const vector<string>* fieldNames, ostream* output);
|
||||
|
||||
/**
|
||||
* Write the message definition or parts of it to the @a ostream.
|
||||
* @param fieldNames the list of field names to write, or NULL for all.
|
||||
* @param fieldNames the list of field names to write, or nullptr for all.
|
||||
* @param withConditions whether to include the optional conditions prefix.
|
||||
* @param output the @a ostream to append the formatted value to.
|
||||
*/
|
||||
@@ -626,7 +626,7 @@ class Message : public AttributedItem {
|
||||
/** whether this is a special scanning @a Message instance. */
|
||||
bool m_isScanMessage;
|
||||
|
||||
/** the @a Condition for this message, or NULL. */
|
||||
/** the @a Condition for this message, or nullptr. */
|
||||
Condition* m_condition;
|
||||
|
||||
/** the last seen @a MasterSymbolString. */
|
||||
@@ -669,7 +669,7 @@ class ChainedMessage : public Message {
|
||||
* @param data the @a DataField for encoding/decoding the chained message.
|
||||
* @param deleteData whether to delete the @a DataField during destruction.
|
||||
* @param pollPriority the priority for polling, or 0 for no polling at all.
|
||||
* @param condition the @a Condition for this message, or NULL.
|
||||
* @param condition the @a Condition for this message, or nullptr.
|
||||
*/
|
||||
ChainedMessage(const string& circuit, const string& level, const string& name,
|
||||
bool isWrite, const map<string, string>& attributes,
|
||||
@@ -678,7 +678,7 @@ class ChainedMessage : public Message {
|
||||
const vector< vector<symbol_t> >& ids, const vector<size_t>& lengths,
|
||||
const DataField* data, bool deleteData,
|
||||
size_t pollPriority = 0,
|
||||
Condition* condition = NULL);
|
||||
Condition* condition = nullptr);
|
||||
|
||||
virtual ~ChainedMessage();
|
||||
|
||||
@@ -827,9 +827,9 @@ class Condition {
|
||||
/**
|
||||
* Derive a new @a SimpleCondition from this condition.
|
||||
* @param valueList the @a string with the new list of values.
|
||||
* @return the derived @a SimpleCondition instance, or NULL if the value list is invalid.
|
||||
* @return the derived @a SimpleCondition instance, or nullptr if the value list is invalid.
|
||||
*/
|
||||
virtual SimpleCondition* derive(const string& valueList) const { return NULL; }
|
||||
virtual SimpleCondition* derive(const string& valueList) const { return nullptr; }
|
||||
|
||||
/**
|
||||
* Write the condition definition or resolved expression to the @a ostream.
|
||||
@@ -848,7 +848,7 @@ class Condition {
|
||||
/**
|
||||
* Resolve the referred @a Message instance(s) and field index(es).
|
||||
* @param messages the @a MessageMap instance for resolving.
|
||||
* @param readMessageFunc the function to call for immediate reading of a @a Message from the bus, or NULL.
|
||||
* @param readMessageFunc the function to call for immediate reading of a @a Message from the bus, or nullptr.
|
||||
* @param errorMessage a @a ostringstream to which to add optional error messages.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
@@ -892,7 +892,7 @@ class SimpleCondition : public Condition {
|
||||
const string& name, symbol_t dstAddress, const string& field, bool hasValues = false)
|
||||
: Condition(),
|
||||
m_condName(condName), m_refName(refName), m_circuit(circuit), m_level(level), m_name(name),
|
||||
m_dstAddress(dstAddress), m_field(field), m_hasValues(hasValues), m_message(NULL) { }
|
||||
m_dstAddress(dstAddress), m_field(field), m_hasValues(hasValues), m_message(nullptr) { }
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
@@ -961,7 +961,7 @@ class SimpleCondition : public Condition {
|
||||
/** whether a value has to be checked against. */
|
||||
const bool m_hasValues;
|
||||
|
||||
/** the resolved @a Message instance, or NULL. */
|
||||
/** the resolved @a Message instance, or nullptr. */
|
||||
Message* m_message;
|
||||
};
|
||||
|
||||
@@ -1105,7 +1105,7 @@ class Instruction {
|
||||
* Factory method for creating a new instance.
|
||||
* @param relPath the relative path and/or filename context being loaded.
|
||||
* @param type the type of the instruction.
|
||||
* @param condition the @a Condition for the instruction, or NULL.
|
||||
* @param condition the @a Condition for the instruction, or nullptr.
|
||||
* @param row the definition row by field name.
|
||||
* @param defaults the default values by name.
|
||||
* @param returnValue the variable in which to store the created instance.
|
||||
@@ -1233,11 +1233,11 @@ class MessageMap : public MappedFileReader {
|
||||
clear();
|
||||
if (m_scanMessage) {
|
||||
delete m_scanMessage;
|
||||
m_scanMessage = NULL;
|
||||
m_scanMessage = nullptr;
|
||||
}
|
||||
if (m_broadcastScanMessage) {
|
||||
delete m_broadcastScanMessage;
|
||||
m_broadcastScanMessage = NULL;
|
||||
m_broadcastScanMessage = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1276,12 +1276,12 @@ class MessageMap : public MappedFileReader {
|
||||
|
||||
// @copydoc
|
||||
bool extractDefaultsFromFilename(const string& filename, map<string, string>* defaults,
|
||||
symbol_t* destAddress = NULL, unsigned int* software = NULL, unsigned int* hardware = NULL) const override;
|
||||
symbol_t* destAddress = nullptr, unsigned int* software = nullptr, unsigned int* hardware = nullptr) const override;
|
||||
|
||||
// @copydoc
|
||||
result_t readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose,
|
||||
map<string, string>* defaults, string* errorDescription, bool replace = false, size_t* hash = NULL,
|
||||
size_t* size = NULL) override;
|
||||
map<string, string>* defaults, string* errorDescription, bool replace = false, size_t* hash = nullptr,
|
||||
size_t* size = nullptr) override;
|
||||
|
||||
// @copydoc
|
||||
result_t addFromFile(const string& filename, unsigned int lineNo, map<string, string>* row,
|
||||
@@ -1290,7 +1290,7 @@ class MessageMap : public MappedFileReader {
|
||||
/**
|
||||
* Get the scan @a Message instance for the specified address.
|
||||
* @param dstAddress the destination address, or @a SYN for the base scan @a Message.
|
||||
* @return the scan @a Message instance, or NULL if the dstAddress is no slave.
|
||||
* @return the scan @a Message instance, or nullptr if the dstAddress is no slave.
|
||||
*/
|
||||
Message* getScanMessage(const symbol_t dstAddress = SYN);
|
||||
|
||||
@@ -1310,7 +1310,7 @@ class MessageMap : public MappedFileReader {
|
||||
|
||||
/**
|
||||
* Resolve a @a Condition.
|
||||
* @param readMessageFunc the function to call for immediate reading of a @a Message from the bus, or NULL.
|
||||
* @param readMessageFunc the function to call for immediate reading of a @a Message from the bus, or nullptr.
|
||||
* @param condition the @a Condition to resolve.
|
||||
* @param errorDescription a string in which to store the error description in case of error.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
@@ -1321,7 +1321,7 @@ class MessageMap : public MappedFileReader {
|
||||
/**
|
||||
* Run all executable @a Instruction instances.
|
||||
* @param readMessageFunc the function to call for immediate reading of a
|
||||
* @a Message values from the bus required for singleton instructions, or NULL.
|
||||
* @a Message values from the bus required for singleton instructions, or nullptr.
|
||||
* @param log the @a ostringstream to log success messages to (if necessary).
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
@@ -1352,18 +1352,18 @@ class MessageMap : public MappedFileReader {
|
||||
* Get the infos for a loaded file.
|
||||
* @param filename the name of the configuration file (including relative path).
|
||||
* @param comment a string in which the comment is stored.
|
||||
* @param hash optional pointer to a @a size_t value for storing the hash 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.
|
||||
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or NULL.
|
||||
* @param hash optional pointer to a @a size_t value for storing the hash of the file, or nullptr.
|
||||
* @param size optional pointer to a @a size_t value for storing the normalized size of the file, or nullptr.
|
||||
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or nullptr.
|
||||
* @return true if the file info was found, false otherwise.
|
||||
*/
|
||||
bool getLoadedFileInfo(const string& filename, string* comment, size_t* hash = NULL, size_t* size = NULL,
|
||||
time_t* time = NULL) const;
|
||||
bool getLoadedFileInfo(const string& filename, string* comment, size_t* hash = nullptr, size_t* size = nullptr,
|
||||
time_t* time = nullptr) const;
|
||||
|
||||
/**
|
||||
* Get the stored @a Message instances for the key.
|
||||
* @param key the key of the @a Message.
|
||||
* @return the found @a Message instances, or NULL.
|
||||
* @return the found @a Message instances, or nullptr.
|
||||
* Note: the caller may not free the returned instances.
|
||||
*/
|
||||
const vector<Message*>* getByKey(uint64_t key) const;
|
||||
@@ -1375,7 +1375,7 @@ class MessageMap : public MappedFileReader {
|
||||
* @param levels the access levels to match.
|
||||
* @param isWrite whether this is a write message.
|
||||
* @param isPassive whether this is a passive message.
|
||||
* @return the @a Message instance, or NULL.
|
||||
* @return the @a Message instance, or nullptr.
|
||||
* Note: the caller may not free the returned instance.
|
||||
*/
|
||||
Message* find(const string& circuit, const string& name, const string& levels, bool isWrite,
|
||||
@@ -1415,7 +1415,7 @@ class MessageMap : public MappedFileReader {
|
||||
* @param withPassive true to include passive messages (default true).
|
||||
* @param onlyAvailable true to include only available messages (default true), false to also include messages that
|
||||
* are currently not available (e.g. due to unresolved or false conditions).
|
||||
* @return the @a Message instance, or NULL.
|
||||
* @return the @a Message instance, or nullptr.
|
||||
* Note: the caller may not free the returned instance.
|
||||
*/
|
||||
Message* find(const MasterSymbolString& master, bool anyDestination = false, bool withRead = true,
|
||||
@@ -1484,7 +1484,7 @@ class MessageMap : public MappedFileReader {
|
||||
|
||||
/**
|
||||
* Get the next @a Message to poll.
|
||||
* @return the next @a Message to poll, or NULL.
|
||||
* @return the next @a Message to poll, or nullptr.
|
||||
* Note: the caller may not free the returned instance.
|
||||
*/
|
||||
Message* getNextPoll();
|
||||
|
||||
@@ -56,11 +56,11 @@ static const symbol_t CRC_LOOKUP_TABLE[] = {
|
||||
|
||||
unsigned int parseInt(const char* str, int base, unsigned int minValue, unsigned int maxValue,
|
||||
result_t* result, size_t* length) {
|
||||
char* strEnd = NULL;
|
||||
char* strEnd = nullptr;
|
||||
|
||||
unsigned long ret = strtoul(str, &strEnd, base);
|
||||
|
||||
if (strEnd == NULL || strEnd == str || *strEnd != 0) {
|
||||
if (strEnd == nullptr || strEnd == str || *strEnd != 0) {
|
||||
*result = RESULT_ERR_INVALID_NUM; // invalid value
|
||||
return 0;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ unsigned int parseInt(const char* str, int base, unsigned int minValue, unsigned
|
||||
*result = RESULT_ERR_OUT_OF_RANGE; // invalid value
|
||||
return 0;
|
||||
}
|
||||
if (length != NULL) {
|
||||
if (length != nullptr) {
|
||||
*length = (unsigned int)(strEnd - str);
|
||||
}
|
||||
*result = RESULT_OK;
|
||||
@@ -78,11 +78,11 @@ unsigned int parseInt(const char* str, int base, unsigned int minValue, unsigned
|
||||
|
||||
int parseSignedInt(const char* str, int base, int minValue, int maxValue,
|
||||
result_t* result, size_t* length) {
|
||||
char* strEnd = NULL;
|
||||
char* strEnd = nullptr;
|
||||
|
||||
long ret = strtol(str, &strEnd, base);
|
||||
|
||||
if (strEnd == NULL || *strEnd != 0) {
|
||||
if (strEnd == nullptr || *strEnd != 0) {
|
||||
*result = RESULT_ERR_INVALID_NUM; // invalid value
|
||||
return 0;
|
||||
}
|
||||
@@ -91,7 +91,7 @@ int parseSignedInt(const char* str, int base, int minValue, int maxValue,
|
||||
*result = RESULT_ERR_OUT_OF_RANGE; // invalid value
|
||||
return 0;
|
||||
}
|
||||
if (length != NULL) {
|
||||
if (length != nullptr) {
|
||||
*length = (unsigned int)(strEnd - str);
|
||||
}
|
||||
*result = RESULT_OK;
|
||||
|
||||
@@ -97,7 +97,7 @@ typedef unsigned char symbol_t;
|
||||
* @return the parsed value.
|
||||
*/
|
||||
unsigned int parseInt(const char* str, int base, unsigned int minValue, unsigned int maxValue,
|
||||
result_t* result, size_t* length = NULL);
|
||||
result_t* result, size_t* length = nullptr);
|
||||
|
||||
/**
|
||||
* Parse a signed int value.
|
||||
@@ -110,7 +110,7 @@ unsigned int parseInt(const char* str, int base, unsigned int minValue, unsigned
|
||||
* @return the parsed value.
|
||||
*/
|
||||
int parseSignedInt(const char* str, int base, int minValue, int maxValue,
|
||||
result_t* result, size_t* length = NULL);
|
||||
result_t* result, size_t* length = nullptr);
|
||||
|
||||
/**
|
||||
* A string of unescaped bus symbols.
|
||||
|
||||
@@ -52,7 +52,7 @@ class TestReader : public MappedFileReader {
|
||||
public:
|
||||
TestReader(DataFieldTemplates* templates, bool isSet, bool isMasterDest)
|
||||
: MappedFileReader::MappedFileReader(true), m_templates(templates), m_isSet(isSet), m_isMasterDest(isMasterDest),
|
||||
m_fields(NULL) {}
|
||||
m_fields(nullptr) {}
|
||||
result_t getFieldMap(const string& preferLanguage, vector<string>* row, string* errorDescription) const override {
|
||||
if (row->empty()) {
|
||||
row->push_back("*name");
|
||||
@@ -512,8 +512,8 @@ int main() {
|
||||
istringstream dummystr("#");
|
||||
string errorDescription;
|
||||
vector<string> row;
|
||||
templates->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
|
||||
const DataField* fields = NULL;
|
||||
templates->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, false, nullptr, nullptr);
|
||||
const DataField* fields = nullptr;
|
||||
for (unsigned int i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) {
|
||||
string check[5] = checks[i];
|
||||
istringstream isstr(check[0]);
|
||||
@@ -539,7 +539,7 @@ int main() {
|
||||
bool failedReadMatch = flags.find('R') != string::npos;
|
||||
bool failedWrite = flags.find('w') != string::npos;
|
||||
bool failedWriteMatch = flags.find('W') != string::npos;
|
||||
const char* findName = flags.find('I') == string::npos ? NULL : "x";
|
||||
const char* findName = flags.find('I') == string::npos ? nullptr : "x";
|
||||
ssize_t findIndex = -1;
|
||||
if (flags.find('i') != string::npos) {
|
||||
findIndex = parseSignedInt(flags.substr(flags.find('i')+1).c_str(), 10, 0, 9, &result);
|
||||
@@ -561,13 +561,13 @@ int main() {
|
||||
bool isTemplate = flags.find('t') != string::npos;
|
||||
string item;
|
||||
|
||||
if (fields != NULL) {
|
||||
if (fields != nullptr) {
|
||||
delete fields;
|
||||
fields = NULL;
|
||||
fields = nullptr;
|
||||
}
|
||||
if (isTemplate) {
|
||||
lineNo = baseLine + i;
|
||||
result = templates->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
|
||||
result = templates->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, nullptr, nullptr);
|
||||
if (result != RESULT_OK) {
|
||||
cout << "\"" << check[0] << "\": template read error: " << getResultCode(result) << ", "
|
||||
<< errorDescription << endl;
|
||||
@@ -579,7 +579,7 @@ int main() {
|
||||
lineNo = 0;
|
||||
dummystr.clear();
|
||||
dummystr.str("#");
|
||||
result = reader.readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
|
||||
result = reader.readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, false, nullptr, nullptr);
|
||||
if (result != RESULT_OK) {
|
||||
cout << "\"" << check[0] << "\": read header error: " << getResultCode(result) << ", " << errorDescription
|
||||
<< endl;
|
||||
@@ -587,7 +587,7 @@ int main() {
|
||||
continue;
|
||||
}
|
||||
lineNo = baseLine + i;
|
||||
result = reader.readLineFromStream(&isstr, "", false, &lineNo, &row, &errorDescription, false, NULL, NULL);
|
||||
result = reader.readLineFromStream(&isstr, "", false, &lineNo, &row, &errorDescription, false, nullptr, nullptr);
|
||||
fields = reader.m_fields;
|
||||
if (failedCreate) {
|
||||
if (result == RESULT_OK) {
|
||||
@@ -603,8 +603,8 @@ int main() {
|
||||
error = true;
|
||||
continue;
|
||||
}
|
||||
if (fields == NULL) {
|
||||
cout << "\"" << check[0] << "\": create error: NULL" << endl;
|
||||
if (fields == nullptr) {
|
||||
cout << "\"" << check[0] << "\": create error: nullptr" << endl;
|
||||
error = true;
|
||||
continue;
|
||||
}
|
||||
@@ -649,9 +649,9 @@ int main() {
|
||||
|
||||
if (verbosity == 0) {
|
||||
istringstream input(expectStr);
|
||||
result = fields->write(UI_FIELD_SEPARATOR, 0, &input, &writeMstr, NULL);
|
||||
result = fields->write(UI_FIELD_SEPARATOR, 0, &input, &writeMstr, nullptr);
|
||||
if (result >= RESULT_OK) {
|
||||
result = fields->write(UI_FIELD_SEPARATOR, 0, &input, &writeSstr, NULL);
|
||||
result = fields->write(UI_FIELD_SEPARATOR, 0, &input, &writeSstr, nullptr);
|
||||
}
|
||||
if (failedWrite) {
|
||||
if (result >= RESULT_OK) {
|
||||
@@ -673,7 +673,7 @@ int main() {
|
||||
}
|
||||
}
|
||||
delete fields;
|
||||
fields = NULL;
|
||||
fields = nullptr;
|
||||
}
|
||||
|
||||
delete templates;
|
||||
|
||||
@@ -25,7 +25,7 @@ using namespace ebusd;
|
||||
|
||||
int main() {
|
||||
Device* device = Device::create("/dev/ttyUSB20", true, false, false);
|
||||
if (device == NULL) {
|
||||
if (device == nullptr) {
|
||||
cout << "unable to create device" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ int main(int argc, char** argv) {
|
||||
if (!stream) {
|
||||
result = RESULT_ERR_NOTFOUND;
|
||||
} else {
|
||||
result = reader.readFromStream(stream, argv[argpos], time, false, NULL, &errorDescription, false, &hash, &size);
|
||||
result = reader.readFromStream(stream, argv[argpos], time, false, nullptr, &errorDescription, false, &hash, &size);
|
||||
}
|
||||
cout << argv[argpos] << " ";
|
||||
if (result != RESULT_OK) {
|
||||
|
||||
@@ -50,7 +50,7 @@ void verify(bool expectFailMatch, string type, string input,
|
||||
}
|
||||
}
|
||||
|
||||
DataFieldTemplates* templates = NULL;
|
||||
DataFieldTemplates* templates = nullptr;
|
||||
|
||||
namespace ebusd {
|
||||
|
||||
@@ -186,14 +186,14 @@ int main() {
|
||||
istringstream dummystr("#");
|
||||
string errorDescription;
|
||||
vector<string> row;
|
||||
templates->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
|
||||
templates->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, false, nullptr, nullptr);
|
||||
lineNo = 0;
|
||||
MessageMap* messages = new MessageMap("");
|
||||
dummystr.clear();
|
||||
dummystr.str("#");
|
||||
messages->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
|
||||
messages->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, false, nullptr, nullptr);
|
||||
vector< vector<string> > defaultsRows;
|
||||
Message* message = NULL;
|
||||
Message* message = nullptr;
|
||||
vector<MasterSymbolString*> mstrs;
|
||||
vector<SlaveSymbolString*> sstrs;
|
||||
mstrs.resize(1);
|
||||
@@ -222,7 +222,7 @@ int main() {
|
||||
lineNo = baseLine + i;
|
||||
cout << "line " << (lineNo+1) << " ";
|
||||
if (isTemplate) {
|
||||
result = templates->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
|
||||
result = templates->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, nullptr, nullptr);
|
||||
if (result != RESULT_OK) {
|
||||
cout << "\"" << check[0] << "\": template read error: " << getResultCode(result) << ", " << errorDescription
|
||||
<< endl;
|
||||
@@ -236,7 +236,7 @@ int main() {
|
||||
}
|
||||
if (isstr.peek() == '*') {
|
||||
// store defaults or condition
|
||||
result = messages->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
|
||||
result = messages->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, nullptr, nullptr);
|
||||
if (result != RESULT_OK) {
|
||||
cout << "\"" << check[0] << "\": default read error: " << getResultCode(result) << ", " << errorDescription << endl;
|
||||
error = true;
|
||||
@@ -252,7 +252,7 @@ int main() {
|
||||
while (getline(stream, token, VALUE_SEPARATOR)) {
|
||||
if (pos >= mstrs.size()) {
|
||||
mstrs.resize(pos+1);
|
||||
} else if (mstrs[pos] != NULL) {
|
||||
} else if (mstrs[pos] != nullptr) {
|
||||
delete mstrs[pos];
|
||||
}
|
||||
mstrs[pos] = new MasterSymbolString();
|
||||
@@ -270,7 +270,7 @@ int main() {
|
||||
while (getline(stream, token, VALUE_SEPARATOR)) {
|
||||
if (pos >= sstrs.size()) {
|
||||
sstrs.resize(pos+1);
|
||||
} else if (sstrs[pos] != NULL) {
|
||||
} else if (sstrs[pos] != nullptr) {
|
||||
delete sstrs[pos];
|
||||
}
|
||||
sstrs[pos] = new SlaveSymbolString();
|
||||
@@ -287,7 +287,7 @@ int main() {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (mstrs[0] != NULL) {
|
||||
if (mstrs[0] != nullptr) {
|
||||
delete mstrs[0];
|
||||
}
|
||||
mstrs[0] = new MasterSymbolString();
|
||||
@@ -297,7 +297,7 @@ int main() {
|
||||
error = true;
|
||||
continue;
|
||||
}
|
||||
if (sstrs[0] != NULL) {
|
||||
if (sstrs[0] != nullptr) {
|
||||
delete sstrs[0];
|
||||
}
|
||||
sstrs[0] = new SlaveSymbolString();
|
||||
@@ -311,14 +311,14 @@ int main() {
|
||||
|
||||
if (isstr.peek() == EOF) {
|
||||
message = messages->find(*mstrs[0]);
|
||||
if (message == NULL) {
|
||||
cout << "\"" << check[2] << "\": find error: NULL" << endl;
|
||||
if (message == nullptr) {
|
||||
cout << "\"" << check[2] << "\": find error: nullptr" << endl;
|
||||
error = true;
|
||||
continue;
|
||||
}
|
||||
cout << "\"" << check[2] << "\": find OK" << endl;
|
||||
} else {
|
||||
result = messages->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
|
||||
result = messages->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, nullptr, nullptr);
|
||||
if (failedCreate) {
|
||||
if (result == RESULT_OK) {
|
||||
cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl;
|
||||
@@ -334,7 +334,7 @@ int main() {
|
||||
continue;
|
||||
}
|
||||
if (messages->size() == 0) {
|
||||
cout << "\"" << check[0] << "\": create error: NULL" << endl;
|
||||
cout << "\"" << check[0] << "\": create error: nullptr" << endl;
|
||||
error = true;
|
||||
continue;
|
||||
}
|
||||
@@ -355,7 +355,7 @@ int main() {
|
||||
deque<Message*> msgs;
|
||||
messages->findAll("", "", "*", false, true, true, true, true, false, 0, 0, &msgs);
|
||||
if (msgs.empty()) {
|
||||
message = NULL;
|
||||
message = nullptr;
|
||||
cout << "\"" << check[0] << "\": create error: message not found" << endl;
|
||||
error = true;
|
||||
continue;
|
||||
@@ -364,7 +364,7 @@ int main() {
|
||||
Message* foundMessage = messages->find(*mstrs[0], false, true, true, true, false);
|
||||
if (foundMessage == message) {
|
||||
cout << " find OK" << endl;
|
||||
} else if (foundMessage == NULL) {
|
||||
} else if (foundMessage == nullptr) {
|
||||
cout << " find error: message not found by master " << mstrs[0]->getStr() << endl;
|
||||
error = true;
|
||||
continue;
|
||||
@@ -399,11 +399,11 @@ int main() {
|
||||
output.str("");
|
||||
output << str;
|
||||
} else {
|
||||
message->dump(NULL, true, &output);
|
||||
message->dump(nullptr, true, &output);
|
||||
}
|
||||
output << ": ";
|
||||
}
|
||||
result = message->decodeLastData(false, NULL, -1,
|
||||
result = message->decodeLastData(false, nullptr, -1,
|
||||
(decodeVerbose?OF_NAMES|OF_UNITS|OF_COMMENTS:0)|(decodeJson?OF_NAMES|OF_JSON:0), &output);
|
||||
if (result != RESULT_OK) {
|
||||
cout << " \"" << check[2] << "\" / \"" << check[3] << "\": decode error: "
|
||||
|
||||
@@ -58,9 +58,9 @@ bool HttpClient::parseUrl(const string& url, string& proto, string& host, uint16
|
||||
}
|
||||
port = 80;
|
||||
if (pos != string::npos) {
|
||||
char* strEnd = NULL;
|
||||
char* strEnd = nullptr;
|
||||
unsigned long value = strtoul(host.c_str()+pos+1, &strEnd, 10);
|
||||
if (strEnd == NULL || *strEnd != '\0' || value < 1 || value > 65535) {
|
||||
if (strEnd == nullptr || *strEnd != '\0' || value < 1 || value > 65535) {
|
||||
return false;
|
||||
}
|
||||
port = static_cast<uint16_t>(value);
|
||||
@@ -182,30 +182,30 @@ bool HttpClient::request(const string& method, const string& uri, const string&
|
||||
// Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT
|
||||
struct tm t;
|
||||
pos += strlen("\r\nLast-Modified: ") + 5;
|
||||
char* strEnd = NULL;
|
||||
char* strEnd = nullptr;
|
||||
t.tm_mday = (int)strtol(hdrs + pos, &strEnd, 10);
|
||||
if (strEnd != hdrs + pos + 2 || t.tm_mday < 1 || t.tm_mday > 31) {
|
||||
t.tm_mday = -1;
|
||||
}
|
||||
t.tm_mon = indexToMonth[((hdrs[pos+4]&0x10)>>1) | (hdrs[pos+5]&0x17)] - 1;
|
||||
strEnd = NULL;
|
||||
strEnd = nullptr;
|
||||
t.tm_year = (int)strtol(hdrs + pos + 7, &strEnd, 10);
|
||||
if (strEnd != hdrs + pos + 11 || t.tm_year < 1970 || t.tm_year >= 3000) {
|
||||
t.tm_year = -1;
|
||||
} else {
|
||||
t.tm_year -= 1900;
|
||||
}
|
||||
strEnd = NULL;
|
||||
strEnd = nullptr;
|
||||
t.tm_hour = (int)strtol(hdrs + pos + 12, &strEnd, 10);
|
||||
if (strEnd != hdrs + pos + 14 || t.tm_hour > 23) {
|
||||
t.tm_hour = -1;
|
||||
}
|
||||
strEnd = NULL;
|
||||
strEnd = nullptr;
|
||||
t.tm_min = (int)strtol(hdrs + pos + 15, &strEnd, 10);
|
||||
if (strEnd != hdrs + pos + 17 || t.tm_min > 59) {
|
||||
t.tm_min = -1;
|
||||
}
|
||||
strEnd = NULL;
|
||||
strEnd = nullptr;
|
||||
t.tm_sec = (int)strtol(hdrs + pos + 18, &strEnd, 10);
|
||||
if (strEnd != hdrs + pos + 20 || t.tm_sec > 59) {
|
||||
t.tm_sec = -1;
|
||||
@@ -220,9 +220,9 @@ bool HttpClient::request(const string& method, const string& uri, const string&
|
||||
disconnect();
|
||||
return true;
|
||||
}
|
||||
char* strEnd = NULL;
|
||||
char* strEnd = nullptr;
|
||||
unsigned long length = strtoul(hdrs + pos + strlen("\r\nContent-Length: "), &strEnd, 10);
|
||||
if (strEnd == NULL || *strEnd != '\r') {
|
||||
if (strEnd == nullptr || *strEnd != '\r') {
|
||||
disconnect();
|
||||
response = "invalid content length ";
|
||||
return false;
|
||||
|
||||
@@ -100,10 +100,10 @@ class HttpClient {
|
||||
* @param uri the URI string.
|
||||
* @param body the optional body to send.
|
||||
* @param response the response body from the server (or the HTTP header on error).
|
||||
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or NULL.
|
||||
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or nullptr.
|
||||
* @return true on success, false on error.
|
||||
*/
|
||||
bool get(const string& uri, const string& body, string& response, time_t* time = NULL);
|
||||
bool get(const string& uri, const string& body, string& response, time_t* time = nullptr);
|
||||
|
||||
/**
|
||||
* Execute a POST request.
|
||||
@@ -119,10 +119,10 @@ class HttpClient {
|
||||
* @param uri the URI string.
|
||||
* @param body the optional body to send.
|
||||
* @param response the response body from the server (or the HTTP header on error).
|
||||
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or NULL.
|
||||
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or nullptr.
|
||||
* @return true on success, false on error.
|
||||
*/
|
||||
bool request(const string& method, const string& uri, const string& body, string& response, time_t* time = NULL);
|
||||
bool request(const string& method, const string& uri, const string& body, string& response, time_t* time = nullptr);
|
||||
|
||||
private:
|
||||
/**
|
||||
|
||||
@@ -39,7 +39,7 @@ static const char *facilityNames[] = {
|
||||
"update",
|
||||
"other",
|
||||
"all",
|
||||
NULL
|
||||
nullptr
|
||||
};
|
||||
|
||||
/** the name of each @a LogLevel. */
|
||||
@@ -49,7 +49,7 @@ static const char* levelNames[] = {
|
||||
"notice",
|
||||
"info",
|
||||
"debug",
|
||||
NULL
|
||||
nullptr
|
||||
};
|
||||
|
||||
/** the current log level by log facility. */
|
||||
@@ -63,7 +63,7 @@ LogFacility parseLogFacility(const char* facility) {
|
||||
return lf_COUNT;
|
||||
}
|
||||
char *input = strdup(facility);
|
||||
char *opt = reinterpret_cast<char*>(input), *value = NULL;
|
||||
char *opt = reinterpret_cast<char*>(input), *value = nullptr;
|
||||
int val = getsubopt(&opt, (char *const *)facilityNames, &value);
|
||||
if (val < 0 || val >= lf_COUNT || value || *opt) {
|
||||
free(input);
|
||||
@@ -75,7 +75,7 @@ LogFacility parseLogFacility(const char* facility) {
|
||||
|
||||
int parseLogFacilities(const char* facilities) {
|
||||
char *input = strdup(facilities);
|
||||
char *opt = reinterpret_cast<char*>(input), *value = NULL;
|
||||
char *opt = reinterpret_cast<char*>(input), *value = nullptr;
|
||||
int newFacilites = 0;
|
||||
while (*opt) {
|
||||
int val = getsubopt(&opt, (char *const *)facilityNames, &value);
|
||||
@@ -98,7 +98,7 @@ LogLevel parseLogLevel(const char* level) {
|
||||
return ll_COUNT;
|
||||
}
|
||||
char *input = strdup(level);
|
||||
char *opt = reinterpret_cast<char*>(input), *value = NULL;
|
||||
char *opt = reinterpret_cast<char*>(input), *value = nullptr;
|
||||
int val = getsubopt(&opt, (char *const *)levelNames, &value);
|
||||
if (val < 0 || val >= ll_COUNT || value || *opt) {
|
||||
free(input);
|
||||
@@ -133,7 +133,7 @@ LogLevel getFacilityLogLevel(LogFacility facility) {
|
||||
|
||||
bool setLogFile(const char* filename) {
|
||||
FILE* newFile = fopen(filename, "a");
|
||||
if (newFile == NULL) {
|
||||
if (newFile == nullptr) {
|
||||
return false;
|
||||
}
|
||||
closeLogFile();
|
||||
@@ -142,11 +142,11 @@ bool setLogFile(const char* filename) {
|
||||
}
|
||||
|
||||
void closeLogFile() {
|
||||
if (s_logFile != NULL) {
|
||||
if (s_logFile != nullptr) {
|
||||
if (s_logFile != stdout) {
|
||||
fclose(s_logFile);
|
||||
}
|
||||
s_logFile = NULL;
|
||||
s_logFile = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ bool needsLog(const LogFacility facility, const LogLevel level) {
|
||||
}
|
||||
|
||||
void logWrite(const char* facility, const char* level, const char* message, va_list ap) {
|
||||
if (s_logFile == NULL) {
|
||||
if (s_logFile == nullptr) {
|
||||
return;
|
||||
}
|
||||
struct timespec ts;
|
||||
|
||||
@@ -41,8 +41,8 @@ class Queue {
|
||||
* Constructor.
|
||||
*/
|
||||
Queue() {
|
||||
pthread_mutex_init(&m_mutex, NULL);
|
||||
pthread_cond_init(&m_cond, NULL);
|
||||
pthread_mutex_init(&m_mutex, nullptr);
|
||||
pthread_cond_init(&m_cond, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,7 +77,7 @@ class Queue {
|
||||
/**
|
||||
* Remove the first item from the queue optionally waiting for the queue being non-empty.
|
||||
* @param timeout the maximum time in seconds to wait for the queue being filled, or 0 for no wait.
|
||||
* @return the item, or NULL if no item is available within the specified time.
|
||||
* @return the item, or nullptr if no item is available within the specified time.
|
||||
*/
|
||||
T pop(int timeout = 0) {
|
||||
T item;
|
||||
@@ -93,7 +93,7 @@ class Queue {
|
||||
}
|
||||
}
|
||||
if (m_queue.empty()) {
|
||||
item = NULL;
|
||||
item = nullptr;
|
||||
} else {
|
||||
item = m_queue.front();
|
||||
m_queue.pop_front();
|
||||
@@ -137,13 +137,13 @@ class Queue {
|
||||
|
||||
/**
|
||||
* Return the first item in the queue without removing it.
|
||||
* @return the item, or NULL if no item is available.
|
||||
* @return the item, or nullptr if no item is available.
|
||||
*/
|
||||
T peek() {
|
||||
T item;
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
if (m_queue.empty()) {
|
||||
item = NULL;
|
||||
item = nullptr;
|
||||
} else {
|
||||
item = m_queue.front();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ using std::streamsize;
|
||||
RotateFile::~RotateFile() {
|
||||
if (m_stream) {
|
||||
fclose(m_stream);
|
||||
m_stream = NULL;
|
||||
m_stream = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ bool RotateFile::setEnabled(bool enabled) {
|
||||
m_enabled = enabled;
|
||||
if (m_stream) {
|
||||
fclose(m_stream);
|
||||
m_stream = NULL;
|
||||
m_stream = nullptr;
|
||||
}
|
||||
if (enabled) {
|
||||
m_stream = fopen(m_fileName.c_str(), m_textMode ? "w" : "wb");
|
||||
|
||||
+12
-12
@@ -54,14 +54,14 @@ TCPSocket* TCPClient::connect(const string& server, const uint16_t& port, int ti
|
||||
struct hostent* he;
|
||||
|
||||
he = gethostbyname(server.c_str());
|
||||
if (he == NULL) {
|
||||
return NULL;
|
||||
if (he == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
memcpy(&address.sin_addr, he->h_addr_list[0], he->h_length);
|
||||
} else {
|
||||
ret = inet_aton(server.c_str(), &address.sin_addr);
|
||||
if (ret == 0) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ TCPSocket* TCPClient::connect(const string& server, const uint16_t& port, int ti
|
||||
|
||||
int sfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sfd < 0) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
#ifndef HAVE_PPOLL
|
||||
#ifndef HAVE_PSELECT
|
||||
@@ -79,13 +79,13 @@ TCPSocket* TCPClient::connect(const string& server, const uint16_t& port, int ti
|
||||
#endif
|
||||
if (timeout > 0 && fcntl(sfd, F_SETFL, O_NONBLOCK) < 0) { // set non-blocking
|
||||
close(sfd);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
ret = ::connect(sfd, (struct sockaddr *) &address, sizeof(address));
|
||||
if (ret != 0) {
|
||||
if (ret < 0 && (timeout <= 0 || errno != EINPROGRESS)) {
|
||||
close(sfd);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
if (timeout > 0) {
|
||||
struct timespec tdiff;
|
||||
@@ -97,7 +97,7 @@ TCPSocket* TCPClient::connect(const string& server, const uint16_t& port, int ti
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = sfd;
|
||||
fds[0].events = POLLIN|POLLOUT;
|
||||
ret = ppoll(fds, nfds, &tdiff, NULL);
|
||||
ret = ppoll(fds, nfds, &tdiff, nullptr);
|
||||
if (ret == 1 && fds[0].revents & POLLERR) {
|
||||
ret = -1;
|
||||
}
|
||||
@@ -107,20 +107,20 @@ TCPSocket* TCPClient::connect(const string& server, const uint16_t& port, int ti
|
||||
FD_ZERO(&writefds);
|
||||
FD_ZERO(&exceptfds);
|
||||
FD_SET(sfd, &readfds);
|
||||
ret = pselect(sfd + 1, &readfds, &writefds, &exceptfds, &tdiff, NULL);
|
||||
ret = pselect(sfd + 1, &readfds, &writefds, &exceptfds, &tdiff, nullptr);
|
||||
if (ret >= 1 && FD_ISSET(sfd, &exceptfds)) {
|
||||
ret = -1;
|
||||
}
|
||||
#endif
|
||||
if (ret == -1 || ret == 0) {
|
||||
close(sfd);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (timeout > 0 && fcntl(sfd, F_SETFL, 0) < 0) { // set blocking again
|
||||
close(sfd);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
TCPSocket* s = new TCPSocket(sfd, &address);
|
||||
if (timeout > 0) {
|
||||
@@ -164,7 +164,7 @@ int TCPServer::start() {
|
||||
|
||||
TCPSocket* TCPServer::newSocket() {
|
||||
if (!m_listening) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
socketaddress address;
|
||||
socklen_t len = sizeof(address);
|
||||
@@ -173,7 +173,7 @@ TCPSocket* TCPServer::newSocket() {
|
||||
|
||||
int sfd = accept(m_lfd, (struct sockaddr*) &address, &len);
|
||||
if (sfd < 0) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return new TCPSocket(sfd, &address);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace ebusd {
|
||||
|
||||
void* Thread::runThread(void* arg) {
|
||||
reinterpret_cast<Thread*>(arg)->enter();
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Thread::~Thread() {
|
||||
@@ -38,7 +38,7 @@ Thread::~Thread() {
|
||||
}
|
||||
|
||||
bool Thread::start(const char* name) {
|
||||
int result = pthread_create(&m_threadid, NULL, runThread, this);
|
||||
int result = pthread_create(&m_threadid, nullptr, runThread, this);
|
||||
if (result == 0) {
|
||||
#ifdef HAVE_PTHREAD_SETNAME_NP
|
||||
#ifndef __MACH__
|
||||
@@ -55,7 +55,7 @@ bool Thread::join() {
|
||||
int result = -1;
|
||||
if (m_started) {
|
||||
m_stopped = true;
|
||||
result = pthread_join(m_threadid, NULL);
|
||||
result = pthread_join(m_threadid, nullptr);
|
||||
if (result == 0) {
|
||||
m_started = false;
|
||||
}
|
||||
@@ -72,8 +72,8 @@ void Thread::enter() {
|
||||
|
||||
WaitThread::WaitThread()
|
||||
: Thread() {
|
||||
pthread_mutex_init(&m_mutex, NULL);
|
||||
pthread_cond_init(&m_cond, NULL);
|
||||
pthread_mutex_init(&m_mutex, nullptr);
|
||||
pthread_cond_init(&m_cond, nullptr);
|
||||
}
|
||||
|
||||
WaitThread::~WaitThread() {
|
||||
|
||||
@@ -43,7 +43,7 @@ class Thread {
|
||||
/**
|
||||
* Thread entry helper for pthread_create.
|
||||
* @param arg pointer to the @a Thread.
|
||||
* @return NULL.
|
||||
* @return nullptr.
|
||||
*/
|
||||
static void* runThread(void* arg);
|
||||
|
||||
|
||||
+18
-18
@@ -56,7 +56,7 @@ static struct options opt = {
|
||||
8888, // port
|
||||
0, // timeout
|
||||
|
||||
NULL, // args
|
||||
nullptr, // args
|
||||
0 // argCount
|
||||
};
|
||||
|
||||
@@ -78,28 +78,28 @@ static char argpargsdoc[] = "\nCOMMAND [CMDOPT...]";
|
||||
|
||||
/** the definition of the known program arguments. */
|
||||
static const struct argp_option argpoptions[] = {
|
||||
{NULL, 0, NULL, 0, "Options:", 1 },
|
||||
{"server", 's', "HOST", 0, "Connect to " PACKAGE " on HOST (name or IP) [localhost]", 0 },
|
||||
{"port", 'p', "PORT", 0, "Connect to " PACKAGE " on PORT [8888]", 0 },
|
||||
{"timeout", 't', "SECS", 0, "Timeout for connection to " PACKAGE ", 0 for none [0]", 0 },
|
||||
{nullptr, 0, nullptr, 0, "Options:", 1 },
|
||||
{"server", 's', "HOST", 0, "Connect to " PACKAGE " on HOST (name or IP) [localhost]", 0 },
|
||||
{"port", 'p', "PORT", 0, "Connect to " PACKAGE " on PORT [8888]", 0 },
|
||||
{"timeout", 't', "SECS", 0, "Timeout for connection to " PACKAGE ", 0 for none [0]", 0 },
|
||||
|
||||
{NULL, 0, NULL, 0, NULL, 0 },
|
||||
{nullptr, 0, nullptr, 0, nullptr, 0 },
|
||||
};
|
||||
|
||||
/**
|
||||
* The program argument parsing function.
|
||||
* @param key the key from @a argpoptions.
|
||||
* @param arg the option argument, or NULL.
|
||||
* @param arg the option argument, or nullptr.
|
||||
* @param state the parsing state.
|
||||
*/
|
||||
error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
struct options *opt = (struct options*)state->input;
|
||||
char* strEnd = NULL;
|
||||
char* strEnd = nullptr;
|
||||
unsigned int value;
|
||||
switch (key) {
|
||||
// Device settings:
|
||||
case 's': // --server=localhost
|
||||
if (arg == NULL || arg[0] == 0) {
|
||||
if (arg == nullptr || arg[0] == 0) {
|
||||
argp_error(state, "invalid server");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -107,7 +107,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
break;
|
||||
case 'p': // --port=8888
|
||||
value = strtoul(arg, &strEnd, 10);
|
||||
if (strEnd == NULL || strEnd == arg || *strEnd != 0 || value < 1 || value > 65535) {
|
||||
if (strEnd == nullptr || strEnd == arg || *strEnd != 0 || value < 1 || value > 65535) {
|
||||
argp_error(state, "invalid port");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -115,7 +115,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
break;
|
||||
case 't': // --timeout=10
|
||||
value = strtoul(arg, &strEnd, 10);
|
||||
if (strEnd == NULL || strEnd == arg || *strEnd != 0 || value < 1 || value > 3600) {
|
||||
if (strEnd == nullptr || strEnd == arg || *strEnd != 0 || value < 1 || value > 3600) {
|
||||
argp_error(state, "invalid timeout");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -173,13 +173,13 @@ string fetchData(ebusd::TCPSocket* socket, bool listening) {
|
||||
while (true) {
|
||||
#ifdef HAVE_PPOLL
|
||||
// wait for new fd event
|
||||
ret = ppoll(fds, nfds, &tdiff, NULL);
|
||||
ret = ppoll(fds, nfds, &tdiff, nullptr);
|
||||
#else
|
||||
#ifdef HAVE_PSELECT
|
||||
// set readfds to inital checkfds
|
||||
fd_set readfds = checkfds;
|
||||
// wait for new fd event
|
||||
ret = pselect(maxfd + 1, &readfds, NULL, NULL, &tdiff, NULL);
|
||||
ret = pselect(maxfd + 1, &readfds, nullptr, nullptr, &tdiff, nullptr);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -248,8 +248,8 @@ bool connect(const char* host, uint16_t port, int timeout, char* const *args, in
|
||||
TCPSocket* socket = client->connect(host, port, timeout);
|
||||
bool ret;
|
||||
|
||||
bool once = args != NULL && argCount > 0;
|
||||
ret = socket != NULL;
|
||||
bool once = args != nullptr && argCount > 0;
|
||||
ret = socket != nullptr;
|
||||
if (ret) {
|
||||
string message, sendmessage;
|
||||
do {
|
||||
@@ -263,7 +263,7 @@ bool connect(const char* host, uint16_t port, int timeout, char* const *args, in
|
||||
if (i > 0) {
|
||||
message += " ";
|
||||
}
|
||||
bool quote = strchr(args[i], ' ') != NULL && strchr(args[i], '"') == NULL;
|
||||
bool quote = strchr(args[i], ' ') != nullptr && strchr(args[i], '"') == nullptr;
|
||||
if (quote) {
|
||||
message += "\"";
|
||||
}
|
||||
@@ -314,9 +314,9 @@ bool connect(const char* host, uint16_t port, int timeout, char* const *args, in
|
||||
* @return the exit code.
|
||||
*/
|
||||
int main(int argc, char* argv[]) {
|
||||
struct argp argp = { argpoptions, parse_opt, argpargsdoc, argpdoc, NULL, NULL, NULL };
|
||||
struct argp argp = { argpoptions, parse_opt, argpargsdoc, argpdoc, nullptr, nullptr, nullptr };
|
||||
setenv("ARGP_HELP_FMT", "no-dup-args-note", 0);
|
||||
if (argp_parse(&argp, argc, argv, ARGP_IN_ORDER, NULL, &opt) != 0) {
|
||||
if (argp_parse(&argp, argc, argv, ARGP_IN_ORDER, nullptr, &opt) != 0) {
|
||||
return EINVAL;
|
||||
}
|
||||
bool success = connect(opt.server, opt.port, opt.timeout, opt.args, opt.argCount);
|
||||
|
||||
+12
-12
@@ -83,25 +83,25 @@ static char argpargsdoc[] = "[DUMPFILE]";
|
||||
|
||||
/** the definition of the known program arguments. */
|
||||
static const struct argp_option argpoptions[] = {
|
||||
{"device", 'd', "DEV", 0, "Write to DEV (serial device) [/dev/ttyUSB60]", 0 },
|
||||
{"time", 't', "USEC", 0, "Delay each byte by USEC us [10000]", 0 },
|
||||
{"device", 'd', "DEV", 0, "Write to DEV (serial device) [/dev/ttyUSB60]", 0 },
|
||||
{"time", 't', "USEC", 0, "Delay each byte by USEC us [10000]", 0 },
|
||||
|
||||
{NULL, 0, NULL, 0, NULL, 0 },
|
||||
{nullptr, 0, nullptr, 0, nullptr, 0 },
|
||||
};
|
||||
|
||||
/**
|
||||
* The program argument parsing function.
|
||||
* @param key the key from @a argpoptions.
|
||||
* @param arg the option argument, or NULL.
|
||||
* @param arg the option argument, or nullptr.
|
||||
* @param state the parsing state.
|
||||
*/
|
||||
error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
struct options *opt = (struct options*)state->input;
|
||||
char* strEnd = NULL;
|
||||
char* strEnd = nullptr;
|
||||
switch (key) {
|
||||
// Device settings:
|
||||
case 'd': // --device=/dev/ttyUSB60
|
||||
if (arg == NULL || arg[0] == 0) {
|
||||
if (arg == nullptr || arg[0] == 0) {
|
||||
argp_error(state, "invalid device");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -109,14 +109,14 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
break;
|
||||
case 't': // --time=10000
|
||||
opt->time = (unsigned int)strtoul(arg, &strEnd, 10);
|
||||
if (strEnd == NULL || strEnd == arg || *strEnd != 0 || opt->time < 1000 || opt->time > 100000000) {
|
||||
if (strEnd == nullptr || strEnd == arg || *strEnd != 0 || opt->time < 1000 || opt->time > 100000000) {
|
||||
argp_error(state, "invalid time");
|
||||
return EINVAL;
|
||||
}
|
||||
break;
|
||||
case ARGP_KEY_ARG:
|
||||
if (state->arg_num == 0) {
|
||||
if (arg == NULL || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
if (arg == nullptr || arg[0] == 0 || strcmp("/", arg) == 0) {
|
||||
argp_error(state, "invalid dumpfile");
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -139,13 +139,13 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
* @return the exit code.
|
||||
*/
|
||||
int main(int argc, char* argv[]) {
|
||||
struct argp argp = { argpoptions, parse_opt, argpargsdoc, argpdoc, NULL, NULL, NULL };
|
||||
struct argp argp = { argpoptions, parse_opt, argpargsdoc, argpdoc, nullptr, nullptr, nullptr };
|
||||
setenv("ARGP_HELP_FMT", "no-dup-args-note", 0);
|
||||
if (argp_parse(&argp, argc, argv, ARGP_IN_ORDER, NULL, &opt) != 0) {
|
||||
if (argp_parse(&argp, argc, argv, ARGP_IN_ORDER, nullptr, &opt) != 0) {
|
||||
return EINVAL;
|
||||
}
|
||||
Device* device = Device::create(opt.device, false, false, NULL);
|
||||
if (device == NULL) {
|
||||
Device* device = Device::create(opt.device, false, false, false);
|
||||
if (device == nullptr) {
|
||||
cout << "unable to create device " << opt.device << endl;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user