use own namespace

This commit is contained in:
john30
2017-01-14 16:41:54 +01:00
parent 7bd9446f13
commit 774e01e937
43 changed files with 196 additions and 48 deletions
+8 -1
View File
@@ -34,7 +34,12 @@
#include "symbol.h"
#include "log.h"
using namespace std;
namespace ebusd {
using std::dec;
using std::hex;
using std::setfill;
using std::setw;
// the string used for answering to a scan request (07h 04h)
#define SCAN_ANSWER ("ebusd.eu;" PACKAGE_NAME ";" SCAN_VERSION ";100")
@@ -1141,3 +1146,5 @@ void BusHandler::setScanConfigLoaded(unsigned char address, string file) {
m_messages->addLoadedFile(address, file, "");
}
}
} // namespace ebusd
+5 -1
View File
@@ -40,7 +40,9 @@
* @image html states.png "ebusd BusHandler states"
*/
using namespace std;
namespace ebusd {
using std::string;
/** the default time [us] for retrieving a symbol from an addressed slave. */
#define SLAVE_RECV_TIMEOUT 15000
@@ -650,4 +652,6 @@ class BusHandler : public WaitThread {
map<unsigned long long, GrabbedMessage> m_grabbedMessages;
};
} // namespace ebusd
#endif // EBUSD_BUSHANDLER_H_
+5 -1
View File
@@ -26,7 +26,9 @@
# include "mqtthandler.h"
#endif
using namespace std;
namespace ebusd {
using std::string;
/** the final @a argp_child structure. */
static const struct argp_child g_last_argp_child = {NULL, 0, NULL, 0};
@@ -67,3 +69,5 @@ bool datahandler_register(BusHandler* busHandler, MessageMap* messages, list<Dat
void DataSink::notifyUpdate(Message* message) {
m_updatedMessages[message]++;
}
} // namespace ebusd
+6 -1
View File
@@ -31,7 +31,10 @@
* the bus.
*/
using namespace std;
namespace ebusd {
using std::list;
using std::map;
class DataHandler;
@@ -142,4 +145,6 @@ class DataSource : virtual public DataHandler {
BusHandler* m_busHandler;
};
} // namespace ebusd
#endif // EBUSD_DATAHANDLER_H_
+12
View File
@@ -38,6 +38,14 @@
#include "log.h"
#include "rotatefile.h"
namespace ebusd {
using std::dec;
using std::hex;
using std::setfill;
using std::setw;
using std::nouppercase;
/** the path and name of the PID file. */
#ifdef PACKAGE_PIDFILE
#define PID_FILE_NAME PACKAGE_PIDFILE
@@ -935,6 +943,9 @@ result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SymbolS
return RESULT_OK;
}
} // namespace ebusd
using namespace ebusd;
/**
* Main method.
@@ -1033,4 +1044,5 @@ int main(int argc, char* argv[]) {
// shutdown
shutdown();
return 0;
}
+4
View File
@@ -27,6 +27,8 @@
/** \file main.h */
namespace ebusd {
/** A structure holding all program options. */
struct options {
const char* device; //!< eBUS device (serial device or [udp:]ip:port) [/dev/ttyUSB0]
@@ -96,4 +98,6 @@ result_t loadConfigFiles(MessageMap* messages, bool verbose = false, bool denyRe
*/
result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SymbolString& data, string& relativeFile, bool verbose = false);
} // namespace ebusd
#endif // EBUSD_MAIN_H_
+8 -1
View File
@@ -27,7 +27,12 @@
#include "log.h"
#include "data.h"
using namespace std;
namespace ebusd {
using std::dec;
using std::hex;
using std::setfill;
using std::setw;
/** the number of seconds of permanent missing signal after which to reconnect the device. */
#define RECONNECT_MISSING_SIGNAL 60
@@ -1534,3 +1539,5 @@ string MainLoop::executeGet(vector<string> &args, bool& connected) {
connected = false;
return result.str();
}
} // namespace ebusd
+3 -1
View File
@@ -30,7 +30,7 @@
/** \file mainloop.h */
using namespace std;
namespace ebusd {
/**
* The main loop handling requests from connected clients.
@@ -252,4 +252,6 @@ class MainLoop : public Thread, DeviceListener {
list<DataHandler*> m_dataHandlers;
};
} // namespace ebusd
#endif // EBUSD_MAINLOOP_H_
+5 -1
View File
@@ -23,7 +23,9 @@
#include "mqtthandler.h"
#include "log.h"
using namespace std;
namespace ebusd {
using std::dec;
/** the definition of the MQTT arguments. */
static const struct argp_option g_mqtt_argp_options[] = {
@@ -455,3 +457,5 @@ void MqttHandler::publishTopic(string topic, 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(), (uint8_t*)(data.c_str()), 0, retain);
}
} // namespace ebusd
+8 -2
View File
@@ -20,9 +20,9 @@
#define EBUSD_MQTTHANDLER_H_
#include <mosquitto.h>
#include <map>
#include <string>
#include <vector>
#include <map>
#include "datahandler.h"
#include "bushandler.h"
#include "message.h"
@@ -31,7 +31,11 @@
* A data handler enabling MQTT support via mosquitto.
*/
using namespace std;
namespace ebusd {
using std::map;
using std::string;
using std::vector;
/**
* Helper function for getting the argp definition for MQTT.
@@ -128,4 +132,6 @@ class MqttHandler : public DataSink, public DataSource, public Thread {
struct mosquitto* m_mosquitto;
};
} // namespace ebusd
#endif // EBUSD_MQTTHANDLER_H_
+2 -1
View File
@@ -27,7 +27,7 @@
#include <cstring>
#include "log.h"
using namespace std;
namespace ebusd {
int Connection::m_ids = 0;
@@ -299,3 +299,4 @@ void Network::cleanConnections() {
}
}
} // namespace ebusd
+3 -2
View File
@@ -30,7 +30,7 @@
/** \file network.h */
using namespace std;
namespace ebusd {
/** Forward declaration for @a Connection. */
class Connection;
@@ -306,5 +306,6 @@ class Network : public Thread {
void cleanConnections();
};
#endif // EBUSD_NETWORK_H_
} // namespace ebusd
#endif // EBUSD_NETWORK_H_
+3 -1
View File
@@ -19,9 +19,11 @@
#include "contrib.h"
#include "tem.h"
using namespace std;
namespace ebusd {
bool libebus_contrib_register() {
contrib_tem_register();
return true;
}
} // namespace ebusd
+3 -1
View File
@@ -24,7 +24,7 @@
* configure switch: --without-contrib
*/
using namespace std;
namespace ebusd {
/**
* Registration function that is called once during initialization.
@@ -32,4 +32,6 @@ using namespace std;
*/
bool libebus_contrib_register();
} // namespace ebusd
#endif // LIB_EBUS_CONTRIB_CONTRIB_H_
+7 -1
View File
@@ -29,7 +29,11 @@
#include <cstring>
#include "datatype.h"
using namespace std;
namespace ebusd {
using std::setfill;
using std::setw;
using std::dec;
void contrib_tem_register() {
DataTypeList::getInstance()->add(new TemParamDataType("TEM_P"));
@@ -135,3 +139,5 @@ result_t TemParamDataType::writeSymbols(istringstream& input,
}
return writeRawValue(value, offset, length, output, usedLength);
}
} // namespace ebusd
+3 -1
View File
@@ -34,7 +34,7 @@
* Contributed data types for TEM devices not part of regular releases.
*/
using namespace std;
namespace ebusd {
/**
* A special variant of @a NumberDataType for TEM/Dungs ParamID in master/slave
@@ -68,4 +68,6 @@ class TemParamDataType : public NumberDataType {
*/
void contrib_tem_register();
} // namespace ebusd
#endif // LIB_EBUS_CONTRIB_TEM_H_
+1 -1
View File
@@ -23,7 +23,7 @@
#include "tem.h"
#include "data.h"
using namespace std;
using namespace ebusd;
static bool error = false;
+7 -1
View File
@@ -29,7 +29,11 @@
#include <cstring>
#include <algorithm>
using namespace std;
namespace ebusd {
using std::dec;
using std::hex;
using std::setw;
/** the week day names. */
static const char* dayNames[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
@@ -1057,3 +1061,5 @@ DataField* DataFieldTemplates::get(const string name) {
}
return ref->second;
}
} // namespace ebusd
+4 -1
View File
@@ -45,7 +45,8 @@
* instances from configuration files by inheriting the @a FileReader template
* class.
*/
using namespace std;
namespace ebusd {
class DataFieldTemplates;
class SingleDataField;
@@ -656,4 +657,6 @@ class DataFieldTemplates : public FileReader {
map<string, DataField*> m_fieldsByName;
};
} // namespace ebusd
#endif // LIB_EBUS_DATA_H_
+10 -1
View File
@@ -31,7 +31,14 @@
# include "contrib/contrib.h"
#endif
using namespace std;
namespace ebusd {
using std::dec;
using std::hex;
using std::fixed;
using std::setfill;
using std::setprecision;
using std::setw;
unsigned int parseInt(const char* str, int base, const unsigned int minValue, const unsigned int maxValue, result_t& result, unsigned int* length) {
char* strEnd = NULL;
@@ -1073,3 +1080,5 @@ DataType* DataTypeList::get(const string id, const unsigned char length) {
}
return dataType;
}
} // namespace ebusd
+6 -1
View File
@@ -46,7 +46,10 @@
* an @a istringstream to a @a SymbolString (see @a DataType#writeSymbols()).
*/
using namespace std;
namespace ebusd {
using std::map;
using std::list;
/** the separator character used between base type name and length (in CSV only). */
#define LENGTH_SEPARATOR ':'
@@ -584,4 +587,6 @@ class DataTypeList {
#endif
};
} // namespace ebusd
#endif // LIB_EBUS_DATATYPE_H_
+3 -1
View File
@@ -36,7 +36,7 @@
#include <fstream>
#include "data.h"
using namespace std;
namespace ebusd {
Device::~Device() {
close();
@@ -323,3 +323,5 @@ ssize_t NetworkDevice::read(unsigned char& value) {
}
return Device::read(value);
}
} // namespace ebusd
+3 -1
View File
@@ -36,7 +36,7 @@
* to a file and/or forwarding it to a logging function.
*/
using namespace std;
namespace ebusd {
/**
* Interface for listening to data received on/sent to a device.
@@ -284,4 +284,6 @@ class NetworkDevice : public Device {
unsigned char m_bufPos;
};
} // namespace ebusd
#endif // LIB_EBUS_DEVICE_H_
+12 -1
View File
@@ -39,7 +39,16 @@
* with a "*" symbol.
*/
using namespace std;
namespace ebusd {
using std::string;
using std::ostream;
using std::ostringstream;
using std::istream;
using std::istringstream;
using std::ifstream;
using std::cout;
using std::endl;
/** the separator character used between fields. */
#define FIELD_SEPARATOR ','
@@ -376,4 +385,6 @@ class FileReader {
string m_lastError;
};
} // namespace ebusd
#endif // LIB_EBUS_FILEREADER_H_
+9 -1
View File
@@ -27,7 +27,13 @@
#include "result.h"
#include "symbol.h"
using namespace std;
namespace ebusd {
using std::dec;
using std::hex;
using std::nouppercase;
using std::setfill;
using std::setw;
/** the maximum length of the command ID bytes (in addition to PB/SB) for which the key is distinct. */
#define MAX_ID_KEYLEN 4
@@ -2197,3 +2203,5 @@ void MessageMap::dump(ostream& output, bool withConditions) {
output << endl;
}
}
} // namespace ebusd
+8 -2
View File
@@ -56,7 +56,11 @@
* template class.
*/
using namespace std;
namespace ebusd {
using std::binary_function;
using std::priority_queue;
using std::deque;
class Condition;
class SimpleCondition;
@@ -702,7 +706,7 @@ class ChainedMessage : public Message {
/**
* A function that compares the weighted poll priority of two @a Message instances.
*/
struct compareMessagePriority : binary_function <Message*, Message*, bool> {
struct compareMessagePriority : binary_function<Message*, Message*, bool> {
/**
* Compare the weighted poll priority of the two @a Message instances.
* @param x the first @a Message.
@@ -1377,4 +1381,6 @@ class MessageMap : public FileReader {
map<string, vector<Instruction*> > m_instructions;
};
} // namespace ebusd
#endif // LIB_EBUS_MESSAGE_H_
+2 -1
View File
@@ -19,7 +19,7 @@
#include "result.h"
#include <iostream>
using namespace std;
namespace ebusd {
const char* getResultCode(result_t resultCode) {
switch (resultCode) {
@@ -58,3 +58,4 @@ const char* getResultCode(result_t resultCode) {
}
}
} // namespace ebusd
+4
View File
@@ -27,6 +27,8 @@
* whereas negative values indicate failure.
*/
namespace ebusd {
/** type for result code. */
enum result_t {
RESULT_OK = 0, //!< success
@@ -70,4 +72,6 @@ enum result_t {
*/
const char* getResultCode(result_t resultCode);
} // namespace ebusd
#endif // LIB_EBUS_RESULT_H_
+9 -2
View File
@@ -23,7 +23,13 @@
#include <vector>
#include "result.h"
using namespace std;
namespace ebusd {
using std::ostringstream;
using std::nouppercase;
using std::setw;
using std::hex;
using std::setfill;
/**
* CRC8 lookup table for the polynom 0x9b = x^8 + x^7 + x^4 + x^3 + x^1 + 1.
@@ -83,7 +89,7 @@ result_t SymbolString::parseHex(const string& str, const bool isEscaped) {
}
const string SymbolString::getDataStr(const bool unescape, const bool skipLastSymbol) {
stringstream sstr;
ostringstream sstr;
bool previousEscape = false;
for (size_t i = 0; i < m_data.size(); i++) {
@@ -255,3 +261,4 @@ bool isValidAddress(unsigned char addr, bool allowBroadcast) {
return addr != SYN && addr != ESC && (allowBroadcast || addr != BROADCAST);
}
} // namespace ebusd
+7 -2
View File
@@ -27,8 +27,6 @@
#include <vector>
#include "result.h"
using namespace std;
/** @file symbol.h
* Classes, functions, and constants related to symbols on the eBUS.
*
@@ -65,6 +63,11 @@ using namespace std;
* non-acknowledge, the receiving slave has to repeat its data once.
*/
namespace ebusd {
using std::string;
using std::vector;
static const unsigned char ESC = 0xA9; //!< escape symbol, either followed by 0x00 for the value 0xA9, or 0x01 for the value 0xAA
static const unsigned char SYN = 0xAA; //!< synchronization symbol
static const unsigned char ACK = 0x00; //!< positive acknowledge
@@ -257,4 +260,6 @@ unsigned char getMasterNumber(unsigned char addr);
*/
bool isValidAddress(unsigned char addr, bool allowBroadcast = true);
} // namespace ebusd
#endif // LIB_EBUS_SYMBOL_H_
+1 -1
View File
@@ -22,7 +22,7 @@
#include <vector>
#include "data.h"
using namespace std;
using namespace ebusd;
static bool error = false;
+1 -1
View File
@@ -20,7 +20,7 @@
#include <iomanip>
#include "device.h"
using namespace std;
using namespace ebusd;
int main() {
Device* device = Device::create("/dev/ttyUSB20", true, false, false);
+1
View File
@@ -23,6 +23,7 @@
#include "filereader.h"
using namespace std;
using namespace ebusd;
static bool error = false;
+3 -1
View File
@@ -24,7 +24,7 @@
#include <map>
#include "message.h"
using namespace std;
using namespace ebusd;
void verify(bool expectFailMatch, string type, string input,
bool match, string expectStr, string gotStr) {
@@ -45,12 +45,14 @@ void verify(bool expectFailMatch, string type, string input,
DataFieldTemplates* templates = NULL;
namespace ebusd {
DataFieldTemplates* getTemplates(const string filename) {
if (filename == "") { // avoid compiler warning
return templates;
}
return templates;
}
}
int main() {
// message: [type],[circuit],name,[comment],[QQ[;QQ]*],[ZZ],[PBSB],[ID],fields...
+1 -1
View File
@@ -21,7 +21,7 @@
#include <string>
#include "symbol.h"
using namespace std;
using namespace ebusd;
static bool error = false;
-2
View File
@@ -25,8 +25,6 @@
#include <string.h>
#include "clock.h"
using namespace std;
/** the name of each @a LogFacility. */
static const char *facilityNames[] = {
"main",
+1 -1
View File
@@ -26,7 +26,7 @@
/** \file queue.h */
using namespace std;
using std::list;
/**
* Thread safe template class for queuing items.
+1 -1
View File
@@ -27,7 +27,7 @@
#include <string>
#include "clock.h"
using namespace std;
using std::streamsize;
RotateFile::~RotateFile() {
if (m_stream) {
+1 -1
View File
@@ -28,7 +28,7 @@
* Helpers for writing to rotating files.
*/
using namespace std;
using std::string;
/**
* Helper class for writing to a rotating file with maximum size.
-2
View File
@@ -23,8 +23,6 @@
#include <string.h>
#include <cstdlib>
using namespace std;
TCPSocket::TCPSocket(int sfd, struct sockaddr_in* address) : m_sfd(sfd) {
char ip[17];
inet_ntop(AF_INET, (struct in_addr*)&(address->sin_addr.s_addr), ip, (socklen_t)sizeof(ip)-1);
+1 -1
View File
@@ -26,7 +26,7 @@
/** \file tcpsocket.h */
using namespace std;
using std::string;
#ifdef __MACH__
#ifndef MSG_NOSIGNAL
+4 -2
View File
@@ -32,8 +32,10 @@
#include <string>
#include "tcpsocket.h"
using namespace std;
using std::ostringstream;
using std::cin;
using std::cout;
using std::endl;
/** A structure holding all program options. */
struct options {
+11 -2
View File
@@ -28,8 +28,17 @@
#include <fstream>
#include <iomanip>
#include "device.h"
#include "result.h"
using namespace std;
using std::hex;
using std::fstream;
using std::cout;
using std::endl;
using std::setw;
using std::setfill;
using std::ios;
using ebusd::result_t;
using ebusd::Device;
/** A structure holding all program options. */
struct options {
@@ -133,7 +142,7 @@ int main(int argc, char* argv[]) {
return EINVAL;
}
result_t result = device->open();
if (result != RESULT_OK) {
if (result != ebusd::RESULT_OK) {
cout << "unable to open " << opt.device << ": " << getResultCode(result) << endl;
}
if (!device->isValid()) {