├── Debug ├── app.ini ├── log4cplus.properties ├── moc_tcphandler.cpp ├── moc_tcpserver.cpp ├── moc_tcpsocket.cpp └── moc_tcpthread.cpp ├── Release ├── Release.rar ├── app.ini └── log4cplus.properties ├── TcpCmdTransfer.pro ├── TcpCmdTransfer.sdf ├── TcpCmdTransfer.sln ├── TcpCmdTransfer.vcxproj ├── TcpCmdTransfer.vcxproj.filters ├── Win32 ├── Debug │ ├── CL.read.1.tlog │ ├── CL.write.1.tlog │ ├── TcpCmdTransfer.exe.intermediate.manifest │ ├── TcpCmdTransfer.lastbuildstate │ ├── TcpCmdTransfer.write.1.tlog │ ├── cl.command.1.tlog │ ├── custombuild.command.1.tlog │ ├── custombuild.read.1.tlog │ ├── custombuild.write.1.tlog │ ├── link.command.1.tlog │ ├── link.read.1.tlog │ ├── link.write.1.tlog │ ├── mt.command.1.tlog │ ├── mt.read.1.tlog │ └── mt.write.1.tlog └── Release │ ├── CL.read.1.tlog │ ├── CL.write.1.tlog │ ├── TcpCmdTransfer.exe.intermediate.manifest │ ├── TcpCmdTransfer.lastbuildstate │ ├── TcpCmdTransfer.write.1.tlog │ ├── cl.command.1.tlog │ ├── custombuild.command.1.tlog │ ├── custombuild.read.1.tlog │ ├── custombuild.write.1.tlog │ ├── link.command.1.tlog │ ├── link.read.1.tlog │ ├── link.write.1.tlog │ ├── mt.command.1.tlog │ ├── mt.read.1.tlog │ └── mt.write.1.tlog ├── alarmdev.cpp ├── alarmdev.h ├── app.ini ├── cmd.cpp ├── cmd.h ├── cmdbuffer.cpp ├── cmdbuffer.h ├── cmdfactory.cpp ├── cmdfactory.h ├── cmdrecv.cpp ├── cmdrecv.h ├── cmdrunnable.cpp ├── cmdrunnable.h ├── cmdtranslator.cpp ├── cmdtranslator.h ├── const.h ├── crc16.cpp ├── crc16.h ├── devcmdrecv.cpp ├── devcmdrecv.h ├── httphandler.cpp ├── httphandler.h ├── icmdhandler.cpp ├── icmdhandler.h ├── icmdrecv.cpp ├── icmdrecv.h ├── icmdtranslator.cpp ├── icmdtranslator.h ├── include ├── curl.rar ├── curl │ ├── curl.h │ ├── curlver.h │ ├── easy.h │ ├── mprintf.h │ ├── multi.h │ ├── stdcheaders.h │ └── types.h └── log4cplus │ ├── appender.h │ ├── asyncappender.h │ ├── boost │ └── deviceappender.hxx │ ├── clfsappender.h │ ├── clogger.h │ ├── config.h.cmake.in │ ├── config.h.in │ ├── config.hxx │ ├── config │ ├── defines.hxx.in │ ├── macosx.h │ ├── win32.h │ └── windowsh-inc.h │ ├── configurator.h │ ├── consoleappender.h │ ├── fileappender.h │ ├── fstreams.h │ ├── helpers │ ├── appenderattachableimpl.h │ ├── connectorthread.h │ ├── fileinfo.h │ ├── lockfile.h │ ├── loglog.h │ ├── logloguser.h │ ├── pointer.h │ ├── property.h │ ├── queue.h │ ├── sleep.h │ ├── snprintf.h │ ├── socket.h │ ├── socketbuffer.h │ ├── stringhelper.h │ ├── thread-config.h │ └── timehelper.h │ ├── hierarchy.h │ ├── hierarchylocker.h │ ├── internal │ ├── cygwin-win32.h │ ├── env.h │ ├── internal.h │ └── socket.h │ ├── layout.h │ ├── log4judpappender.h │ ├── logger.h │ ├── loggingmacros.h │ ├── loglevel.h │ ├── mdc.h │ ├── msttsappender.h │ ├── ndc.h │ ├── nteventlogappender.h │ ├── nullappender.h │ ├── qt4debugappender.h │ ├── qt5debugappender.h │ ├── socketappender.h │ ├── spi │ ├── appenderattachable.h │ ├── factory.h │ ├── filter.h │ ├── loggerfactory.h │ ├── loggerimpl.h │ ├── loggingevent.h │ ├── objectregistry.h │ └── rootlogger.h │ ├── streams.h │ ├── syslogappender.h │ ├── tchar.h │ ├── thread │ ├── impl │ │ ├── syncprims-cxx11.h │ │ ├── syncprims-impl.h │ │ ├── syncprims-pmsm.h │ │ ├── syncprims-pthreads.h │ │ ├── syncprims-win32.h │ │ ├── threads-impl.h │ │ └── tls.h │ ├── syncprims-pub-impl.h │ ├── syncprims.h │ └── threads.h │ ├── tracelogger.h │ ├── tstring.h │ ├── version.h │ ├── win32consoleappender.h │ └── win32debugappender.h ├── ipch └── tcpcmdtransfer-7c645831 │ └── tcpcmdtransfer-49b855b.ipch ├── log4cplus.properties ├── main.cpp ├── nochangetranslator.cpp ├── nochangetranslator.h ├── phonecmdrecv.cpp ├── phonecmdrecv.h ├── platformcmdrecv.cpp ├── platformcmdrecv.h ├── platformtodevhandler.cpp ├── platformtodevhandler.h ├── platformtranslator.cpp ├── platformtranslator.h ├── recvthread.cpp ├── recvthread.h ├── replytodevtranslator.cpp ├── replytodevtranslator.h ├── tcpappcmdrecv.cpp ├── tcpappcmdrecv.h ├── tcpcmdfactory.cpp ├── tcpcmdfactory.h ├── tcpcmdrecv.cpp ├── tcpcmdrecv.h ├── tcpdevcmdrecv.cpp ├── tcpdevcmdrecv.h ├── tcphandler.cpp ├── tcphandler.h ├── tcpserver.cpp ├── tcpserver.h ├── tcpsocket.cpp ├── tcpsocket.h ├── tcpthread.cpp ├── tcpthread.h ├── timerthread.cpp ├── timerthread.h ├── udpcmdrecv.cpp ├── udpcmdrecv.h ├── utils.cpp └── utils.h /Debug/app.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Debug/app.ini -------------------------------------------------------------------------------- /Debug/log4cplus.properties: -------------------------------------------------------------------------------- 1 | log4cplus.rootLogger=DEBUG,STDOUT,R 2 | 3 | log4cplus.appender.R=log4cplus::RollingFileAppender 4 | log4cplus.appender.R.MaxFileSize=20MB 5 | log4cplus.appender.R.immediateFlush=true 6 | log4cplus.appender.R.File=logs\app.log 7 | log4cplus.appender.R.layout=log4cplus::PatternLayout 8 | log4cplus.appender.R.layout.ConversionPattern=[%D{%y-%m-%d %H:%M:%S.%q}] %m%n 9 | 10 | log4cplus.appender.STDOUT=log4cplus::ConsoleAppender 11 | log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout 12 | log4cplus.appender.STDOUT.layout.ConversionPattern=[%D{%y-%m-%d %H:%M:%S.%q}] %m%n -------------------------------------------------------------------------------- /Debug/moc_tcphandler.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Meta object code from reading C++ file 'tcphandler.h' 3 | ** 4 | ** Created by: The Qt Meta Object Compiler version 67 (Qt 5.5.1) 5 | ** 6 | ** WARNING! All changes made in this file will be lost! 7 | *****************************************************************************/ 8 | 9 | #include "../tcphandler.h" 10 | #include 11 | #include 12 | #if !defined(Q_MOC_OUTPUT_REVISION) 13 | #error "The header file 'tcphandler.h' doesn't include ." 14 | #elif Q_MOC_OUTPUT_REVISION != 67 15 | #error "This file was generated using the moc from 5.5.1. It" 16 | #error "cannot be used with the include files from this version of Qt." 17 | #error "(The moc has changed too much.)" 18 | #endif 19 | 20 | QT_BEGIN_MOC_NAMESPACE 21 | struct qt_meta_stringdata_TcpHandler_t { 22 | QByteArrayData data[4]; 23 | char stringdata0[28]; 24 | }; 25 | #define QT_MOC_LITERAL(idx, ofs, len) \ 26 | Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ 27 | qptrdiff(offsetof(qt_meta_stringdata_TcpHandler_t, stringdata0) + ofs \ 28 | - idx * sizeof(QByteArrayData)) \ 29 | ) 30 | static const qt_meta_stringdata_TcpHandler_t qt_meta_stringdata_TcpHandler = { 31 | { 32 | QT_MOC_LITERAL(0, 0, 10), // "TcpHandler" 33 | QT_MOC_LITERAL(1, 11, 10), // "toSendData" 34 | QT_MOC_LITERAL(2, 22, 0), // "" 35 | QT_MOC_LITERAL(3, 23, 4) // "aCmd" 36 | 37 | }, 38 | "TcpHandler\0toSendData\0\0aCmd" 39 | }; 40 | #undef QT_MOC_LITERAL 41 | 42 | static const uint qt_meta_data_TcpHandler[] = { 43 | 44 | // content: 45 | 7, // revision 46 | 0, // classname 47 | 0, 0, // classinfo 48 | 1, 14, // methods 49 | 0, 0, // properties 50 | 0, 0, // enums/sets 51 | 0, 0, // constructors 52 | 0, // flags 53 | 1, // signalCount 54 | 55 | // signals: name, argc, parameters, tag, flags 56 | 1, 1, 19, 2, 0x06 /* Public */, 57 | 58 | // signals: parameters 59 | QMetaType::Void, QMetaType::QByteArray, 3, 60 | 61 | 0 // eod 62 | }; 63 | 64 | void TcpHandler::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) 65 | { 66 | if (_c == QMetaObject::InvokeMetaMethod) { 67 | TcpHandler *_t = static_cast(_o); 68 | Q_UNUSED(_t) 69 | switch (_id) { 70 | case 0: _t->toSendData((*reinterpret_cast< const QByteArray(*)>(_a[1]))); break; 71 | default: ; 72 | } 73 | } else if (_c == QMetaObject::IndexOfMethod) { 74 | int *result = reinterpret_cast(_a[0]); 75 | void **func = reinterpret_cast(_a[1]); 76 | { 77 | typedef void (TcpHandler::*_t)(const QByteArray & ); 78 | if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&TcpHandler::toSendData)) { 79 | *result = 0; 80 | } 81 | } 82 | } 83 | } 84 | 85 | const QMetaObject TcpHandler::staticMetaObject = { 86 | { &ICmdHandler::staticMetaObject, qt_meta_stringdata_TcpHandler.data, 87 | qt_meta_data_TcpHandler, qt_static_metacall, Q_NULLPTR, Q_NULLPTR} 88 | }; 89 | 90 | 91 | const QMetaObject *TcpHandler::metaObject() const 92 | { 93 | return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; 94 | } 95 | 96 | void *TcpHandler::qt_metacast(const char *_clname) 97 | { 98 | if (!_clname) return Q_NULLPTR; 99 | if (!strcmp(_clname, qt_meta_stringdata_TcpHandler.stringdata0)) 100 | return static_cast(const_cast< TcpHandler*>(this)); 101 | return ICmdHandler::qt_metacast(_clname); 102 | } 103 | 104 | int TcpHandler::qt_metacall(QMetaObject::Call _c, int _id, void **_a) 105 | { 106 | _id = ICmdHandler::qt_metacall(_c, _id, _a); 107 | if (_id < 0) 108 | return _id; 109 | if (_c == QMetaObject::InvokeMetaMethod) { 110 | if (_id < 1) 111 | qt_static_metacall(this, _c, _id, _a); 112 | _id -= 1; 113 | } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { 114 | if (_id < 1) 115 | *reinterpret_cast(_a[0]) = -1; 116 | _id -= 1; 117 | } 118 | return _id; 119 | } 120 | 121 | // SIGNAL 0 122 | void TcpHandler::toSendData(const QByteArray & _t1) 123 | { 124 | void *_a[] = { Q_NULLPTR, const_cast(reinterpret_cast(&_t1)) }; 125 | QMetaObject::activate(this, &staticMetaObject, 0, _a); 126 | } 127 | QT_END_MOC_NAMESPACE 128 | -------------------------------------------------------------------------------- /Debug/moc_tcpserver.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Meta object code from reading C++ file 'tcpserver.h' 3 | ** 4 | ** Created by: The Qt Meta Object Compiler version 67 (Qt 5.5.1) 5 | ** 6 | ** WARNING! All changes made in this file will be lost! 7 | *****************************************************************************/ 8 | 9 | #include "../tcpserver.h" 10 | #include 11 | #include 12 | #if !defined(Q_MOC_OUTPUT_REVISION) 13 | #error "The header file 'tcpserver.h' doesn't include ." 14 | #elif Q_MOC_OUTPUT_REVISION != 67 15 | #error "This file was generated using the moc from 5.5.1. It" 16 | #error "cannot be used with the include files from this version of Qt." 17 | #error "(The moc has changed too much.)" 18 | #endif 19 | 20 | QT_BEGIN_MOC_NAMESPACE 21 | struct qt_meta_stringdata_TcpServer_t { 22 | QByteArrayData data[1]; 23 | char stringdata0[10]; 24 | }; 25 | #define QT_MOC_LITERAL(idx, ofs, len) \ 26 | Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ 27 | qptrdiff(offsetof(qt_meta_stringdata_TcpServer_t, stringdata0) + ofs \ 28 | - idx * sizeof(QByteArrayData)) \ 29 | ) 30 | static const qt_meta_stringdata_TcpServer_t qt_meta_stringdata_TcpServer = { 31 | { 32 | QT_MOC_LITERAL(0, 0, 9) // "TcpServer" 33 | 34 | }, 35 | "TcpServer" 36 | }; 37 | #undef QT_MOC_LITERAL 38 | 39 | static const uint qt_meta_data_TcpServer[] = { 40 | 41 | // content: 42 | 7, // revision 43 | 0, // classname 44 | 0, 0, // classinfo 45 | 0, 0, // methods 46 | 0, 0, // properties 47 | 0, 0, // enums/sets 48 | 0, 0, // constructors 49 | 0, // flags 50 | 0, // signalCount 51 | 52 | 0 // eod 53 | }; 54 | 55 | void TcpServer::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) 56 | { 57 | Q_UNUSED(_o); 58 | Q_UNUSED(_id); 59 | Q_UNUSED(_c); 60 | Q_UNUSED(_a); 61 | } 62 | 63 | const QMetaObject TcpServer::staticMetaObject = { 64 | { &QTcpServer::staticMetaObject, qt_meta_stringdata_TcpServer.data, 65 | qt_meta_data_TcpServer, qt_static_metacall, Q_NULLPTR, Q_NULLPTR} 66 | }; 67 | 68 | 69 | const QMetaObject *TcpServer::metaObject() const 70 | { 71 | return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; 72 | } 73 | 74 | void *TcpServer::qt_metacast(const char *_clname) 75 | { 76 | if (!_clname) return Q_NULLPTR; 77 | if (!strcmp(_clname, qt_meta_stringdata_TcpServer.stringdata0)) 78 | return static_cast(const_cast< TcpServer*>(this)); 79 | return QTcpServer::qt_metacast(_clname); 80 | } 81 | 82 | int TcpServer::qt_metacall(QMetaObject::Call _c, int _id, void **_a) 83 | { 84 | _id = QTcpServer::qt_metacall(_c, _id, _a); 85 | if (_id < 0) 86 | return _id; 87 | return _id; 88 | } 89 | QT_END_MOC_NAMESPACE 90 | -------------------------------------------------------------------------------- /Release/Release.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Release/Release.rar -------------------------------------------------------------------------------- /Release/app.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Release/app.ini -------------------------------------------------------------------------------- /Release/log4cplus.properties: -------------------------------------------------------------------------------- 1 | log4cplus.rootLogger=DEBUG,STDOUT,R 2 | 3 | log4cplus.appender.R=log4cplus::RollingFileAppender 4 | log4cplus.appender.R.MaxFileSize=20MB 5 | log4cplus.appender.R.immediateFlush=true 6 | log4cplus.appender.R.File=logs\app.log 7 | log4cplus.appender.R.layout=log4cplus::PatternLayout 8 | log4cplus.appender.R.layout.ConversionPattern=[%D{%y-%m-%d %H:%M:%S.%q}] %m%n 9 | 10 | log4cplus.appender.STDOUT=log4cplus::ConsoleAppender 11 | log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout 12 | log4cplus.appender.STDOUT.layout.ConversionPattern=[%D{%y-%m-%d %H:%M:%S.%q}] %m%n -------------------------------------------------------------------------------- /TcpCmdTransfer.pro: -------------------------------------------------------------------------------- 1 | QT += core network 2 | QT -= gui 3 | 4 | TARGET = TcpCmdTransfer 5 | CONFIG += console 6 | CONFIG -= app_bundle 7 | 8 | INCLUDEPATH += include 9 | 10 | LIBS += lib/libcurl.lib 11 | 12 | DEFINES -= UNICODE 13 | 14 | Debug:LIBS += lib/log4cplusD.lib 15 | 16 | Release:LIBS += lib/log4cplus.lib 17 | 18 | TEMPLATE = app 19 | 20 | SOURCES += \ 21 | alarmdev.cpp \ 22 | cmd.cpp \ 23 | cmdbuffer.cpp \ 24 | cmdfactory.cpp \ 25 | cmdrecv.cpp \ 26 | cmdrunnable.cpp \ 27 | cmdtranslator.cpp \ 28 | crc16.cpp \ 29 | devcmdrecv.cpp \ 30 | httphandler.cpp \ 31 | icmdhandler.cpp \ 32 | icmdrecv.cpp \ 33 | icmdtranslator.cpp \ 34 | main.cpp \ 35 | nochangetranslator.cpp \ 36 | phonecmdrecv.cpp \ 37 | platformcmdrecv.cpp \ 38 | platformtodevhandler.cpp \ 39 | platformtranslator.cpp \ 40 | recvthread.cpp \ 41 | replytodevtranslator.cpp \ 42 | tcpappcmdrecv.cpp \ 43 | tcpcmdfactory.cpp \ 44 | tcpcmdrecv.cpp \ 45 | tcpdevcmdrecv.cpp \ 46 | tcphandler.cpp \ 47 | tcpserver.cpp \ 48 | tcpsocket.cpp \ 49 | tcpthread.cpp \ 50 | timerthread.cpp \ 51 | udpcmdrecv.cpp \ 52 | utils.cpp 53 | 54 | HEADERS += \ 55 | alarmdev.h \ 56 | cmd.h \ 57 | cmdbuffer.h \ 58 | cmdfactory.h \ 59 | cmdrecv.h \ 60 | cmdrunnable.h \ 61 | cmdtranslator.h \ 62 | const.h \ 63 | crc16.h \ 64 | devcmdrecv.h \ 65 | httphandler.h \ 66 | icmdhandler.h \ 67 | icmdrecv.h \ 68 | icmdtranslator.h \ 69 | nochangetranslator.h \ 70 | phonecmdrecv.h \ 71 | platformcmdrecv.h \ 72 | platformtodevhandler.h \ 73 | platformtranslator.h \ 74 | recvthread.h \ 75 | replytodevtranslator.h \ 76 | tcpappcmdrecv.h \ 77 | tcpcmdfactory.h \ 78 | tcpcmdrecv.h \ 79 | tcpdevcmdrecv.h \ 80 | tcphandler.h \ 81 | tcpserver.h \ 82 | tcpsocket.h \ 83 | tcpthread.h \ 84 | timerthread.h \ 85 | udpcmdrecv.h \ 86 | utils.h 87 | 88 | -------------------------------------------------------------------------------- /TcpCmdTransfer.sdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/TcpCmdTransfer.sdf -------------------------------------------------------------------------------- /TcpCmdTransfer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TcpCmdTransfer", "TcpCmdTransfer.vcxproj", "{5C42B580-1193-3BFF-9600-41210A0C3922}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {5C42B580-1193-3BFF-9600-41210A0C3922}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {5C42B580-1193-3BFF-9600-41210A0C3922}.Debug|Win32.Build.0 = Debug|Win32 14 | {5C42B580-1193-3BFF-9600-41210A0C3922}.Release|Win32.ActiveCfg = Release|Win32 15 | {5C42B580-1193-3BFF-9600-41210A0C3922}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Win32/Debug/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Debug/CL.read.1.tlog -------------------------------------------------------------------------------- /Win32/Debug/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Debug/CL.write.1.tlog -------------------------------------------------------------------------------- /Win32/Debug/TcpCmdTransfer.exe.intermediate.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Win32/Debug/TcpCmdTransfer.lastbuildstate: -------------------------------------------------------------------------------- 1 | #v4.0:v100 2 | Debug|Win32|E:\TcpCmdTransfer\| 3 | -------------------------------------------------------------------------------- /Win32/Debug/TcpCmdTransfer.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Debug/TcpCmdTransfer.write.1.tlog -------------------------------------------------------------------------------- /Win32/Debug/cl.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Debug/cl.command.1.tlog -------------------------------------------------------------------------------- /Win32/Debug/custombuild.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Debug/custombuild.command.1.tlog -------------------------------------------------------------------------------- /Win32/Debug/custombuild.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Debug/custombuild.read.1.tlog -------------------------------------------------------------------------------- /Win32/Debug/custombuild.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Debug/custombuild.write.1.tlog -------------------------------------------------------------------------------- /Win32/Debug/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Debug/link.command.1.tlog -------------------------------------------------------------------------------- /Win32/Debug/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Debug/link.read.1.tlog -------------------------------------------------------------------------------- /Win32/Debug/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Debug/link.write.1.tlog -------------------------------------------------------------------------------- /Win32/Debug/mt.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Debug/mt.command.1.tlog -------------------------------------------------------------------------------- /Win32/Debug/mt.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Debug/mt.read.1.tlog -------------------------------------------------------------------------------- /Win32/Debug/mt.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Debug/mt.write.1.tlog -------------------------------------------------------------------------------- /Win32/Release/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Release/CL.read.1.tlog -------------------------------------------------------------------------------- /Win32/Release/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Release/CL.write.1.tlog -------------------------------------------------------------------------------- /Win32/Release/TcpCmdTransfer.exe.intermediate.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Win32/Release/TcpCmdTransfer.lastbuildstate: -------------------------------------------------------------------------------- 1 | #v4.0:v100 2 | Release|Win32|E:\TcpCmdTransfer\| 3 | -------------------------------------------------------------------------------- /Win32/Release/TcpCmdTransfer.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Release/TcpCmdTransfer.write.1.tlog -------------------------------------------------------------------------------- /Win32/Release/cl.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Release/cl.command.1.tlog -------------------------------------------------------------------------------- /Win32/Release/custombuild.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Release/custombuild.command.1.tlog -------------------------------------------------------------------------------- /Win32/Release/custombuild.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Release/custombuild.read.1.tlog -------------------------------------------------------------------------------- /Win32/Release/custombuild.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Release/custombuild.write.1.tlog -------------------------------------------------------------------------------- /Win32/Release/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Release/link.command.1.tlog -------------------------------------------------------------------------------- /Win32/Release/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Release/link.read.1.tlog -------------------------------------------------------------------------------- /Win32/Release/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Release/link.write.1.tlog -------------------------------------------------------------------------------- /Win32/Release/mt.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Release/mt.command.1.tlog -------------------------------------------------------------------------------- /Win32/Release/mt.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Release/mt.read.1.tlog -------------------------------------------------------------------------------- /Win32/Release/mt.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/Win32/Release/mt.write.1.tlog -------------------------------------------------------------------------------- /alarmdev.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/alarmdev.cpp -------------------------------------------------------------------------------- /alarmdev.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/alarmdev.h -------------------------------------------------------------------------------- /app.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/app.ini -------------------------------------------------------------------------------- /cmd.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/cmd.cpp -------------------------------------------------------------------------------- /cmd.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/cmd.h -------------------------------------------------------------------------------- /cmdbuffer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/cmdbuffer.cpp -------------------------------------------------------------------------------- /cmdbuffer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/cmdbuffer.h -------------------------------------------------------------------------------- /cmdfactory.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/cmdfactory.cpp -------------------------------------------------------------------------------- /cmdfactory.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/cmdfactory.h -------------------------------------------------------------------------------- /cmdrecv.cpp: -------------------------------------------------------------------------------- 1 | #include "cmdrecv.h" 2 | 3 | CmdRecv::CmdRecv(CmdFactory *pCmdFactory) 4 | : m_pCmdFactory(pCmdFactory) 5 | { 6 | 7 | } 8 | 9 | -------------------------------------------------------------------------------- /cmdrecv.h: -------------------------------------------------------------------------------- 1 | #ifndef CMDRECV_H 2 | #define CMDRECV_H 3 | 4 | #include "icmdrecv.h" 5 | #include "cmdfactory.h" 6 | 7 | class CmdRecv : public ICmdRecv 8 | { 9 | public: 10 | CmdRecv(CmdFactory *pCmdFactory); 11 | 12 | protected: 13 | CmdFactory *m_pCmdFactory; 14 | }; 15 | 16 | #endif // CMDRECV_H 17 | -------------------------------------------------------------------------------- /cmdrunnable.cpp: -------------------------------------------------------------------------------- 1 | #include "cmdrunnable.h" 2 | 3 | CmdRunnable::CmdRunnable( Cmd *pCmd ) 4 | { 5 | m_pCmd = pCmd; 6 | } 7 | 8 | CmdRunnable::~CmdRunnable() 9 | { 10 | delete m_pCmd; 11 | } 12 | 13 | void CmdRunnable::run() 14 | { 15 | m_pCmd->handle(); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /cmdrunnable.h: -------------------------------------------------------------------------------- 1 | #ifndef CMDRUNNABLE_H 2 | #define CMDRUNNABLE_H 3 | 4 | #include 5 | #include "cmd.h" 6 | 7 | class CmdRunnable : public QRunnable 8 | { 9 | public: 10 | CmdRunnable(Cmd *pCmd); 11 | ~CmdRunnable(); 12 | void run(); 13 | 14 | private: 15 | Cmd *m_pCmd; 16 | }; 17 | 18 | #endif // CMDRUNNABLE_H 19 | -------------------------------------------------------------------------------- /cmdtranslator.cpp: -------------------------------------------------------------------------------- 1 | #include "cmdtranslator.h" 2 | 3 | CmdTranslator::CmdTranslator(const int iDirection) 4 | : m_devId(0), 5 | m_cmdId(0), 6 | m_iDirection(iDirection) 7 | { 8 | 9 | } 10 | 11 | QByteArray & CmdTranslator::translate(QByteArray &aDest, const QByteArray &aSrc) 12 | { 13 | if(FROM_DEV == m_iDirection) 14 | return fromDevCmd(aDest, aSrc); 15 | else 16 | return toDevCmd(aDest, aSrc); 17 | } 18 | 19 | QByteArray CmdTranslator::getTranslatedData() 20 | { 21 | return m_translatedData; 22 | } 23 | 24 | void CmdTranslator::setDataArea(const QByteArray &dataArea) 25 | { 26 | m_dataArea = dataArea; 27 | } 28 | 29 | void CmdTranslator::setDevId(quint32 iDevId) 30 | { 31 | m_devId = iDevId; 32 | } 33 | 34 | void CmdTranslator::setCmdId(quint16 iCmdId) 35 | { 36 | m_cmdId = iCmdId; 37 | } 38 | 39 | void CmdTranslator::setDirection(int iDirection) 40 | { 41 | m_iDirection = iDirection; 42 | } 43 | 44 | 45 | -------------------------------------------------------------------------------- /cmdtranslator.h: -------------------------------------------------------------------------------- 1 | #ifndef CMDTRANSLATOR_H 2 | #define CMDTRANSLATOR_H 3 | 4 | #include "icmdtranslator.h" 5 | 6 | class CmdTranslator : public ICmdTranslator 7 | { 8 | public: 9 | enum TranslateDirection 10 | { 11 | FROM_DEV, 12 | TO_DEV 13 | }; 14 | 15 | CmdTranslator(const int iDirection); 16 | QByteArray getTranslatedData(); 17 | void setDataArea(const QByteArray &dataArea); 18 | void setDevId(quint32 iDevId); 19 | void setCmdId(quint16 iCmdId); 20 | void setDirection(int iDirection); 21 | QByteArray & translate(QByteArray &aDest, const QByteArray &aSrc); 22 | 23 | protected: 24 | virtual QByteArray & toDevCmd(QByteArray &aDevCmd, const QByteArray &aSrcCmd) = 0; 25 | virtual QByteArray & fromDevCmd(QByteArray &aDestCmd, const QByteArray &aDevCmd) = 0; 26 | 27 | protected: 28 | QByteArray m_translatedData; 29 | quint32 m_devId; 30 | quint16 m_cmdId; 31 | QByteArray m_dataArea; 32 | int m_iDirection; 33 | }; 34 | 35 | #endif // CMDTRANSLATOR_H 36 | -------------------------------------------------------------------------------- /const.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/const.h -------------------------------------------------------------------------------- /crc16.cpp: -------------------------------------------------------------------------------- 1 | #include "crc16.h" 2 | 3 | /********************************************************* 4 | Description: CRC16的校验表 5 | Input: No 6 | Output: No 7 | Return: No 8 | Others: No 9 | **********************************************************/ 10 | const MB_U8 CRC_TABLE_H[256] = { 11 | 12 | 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40, 13 | 0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41, 14 | 0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41, 15 | 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40, 16 | 0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41, 17 | 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40, 18 | 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40, 19 | 0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41, 20 | 0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41, 21 | 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40, 22 | 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40, 23 | 0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41, 24 | 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40, 25 | 0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41, 26 | 0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41, 27 | 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40, 28 | 29 | }; 30 | 31 | const MB_U8 CRC_TABLE_L[256] = { 32 | 33 | 0x00,0xC0,0xC1,0x01,0xC3,0x03,0x02,0xC2,0xC6,0x06,0x07,0xC7,0x05,0xC5,0xC4,0x04, 34 | 0xCC,0x0C,0x0D,0xCD,0x0F,0xCF,0xCE,0x0E,0x0A,0xCA,0xCB,0x0B,0xC9,0x09,0x08,0xC8, 35 | 0xD8,0x18,0x19,0xD9,0x1B,0xDB,0xDA,0x1A,0x1E,0xDE,0xDF,0x1F,0xDD,0x1D,0x1C,0xDC, 36 | 0x14,0xD4,0xD5,0x15,0xD7,0x17,0x16,0xD6,0xD2,0x12,0x13,0xD3,0x11,0xD1,0xD0,0x10, 37 | 0xF0,0x30,0x31,0xF1,0x33,0xF3,0xF2,0x32,0x36,0xF6,0xF7,0x37,0xF5,0x35,0x34,0xF4, 38 | 0x3C,0xFC,0xFD,0x3D,0xFF,0x3F,0x3E,0xFE,0xFA,0x3A,0x3B,0xFB,0x39,0xF9,0xF8,0x38, 39 | 0x28,0xE8,0xE9,0x29,0xEB,0x2B,0x2A,0xEA,0xEE,0x2E,0x2F,0xEF,0x2D,0xED,0xEC,0x2C, 40 | 0xE4,0x24,0x25,0xE5,0x27,0xE7,0xE6,0x26,0x22,0xE2,0xE3,0x23,0xE1,0x21,0x20,0xE0, 41 | 0xA0,0x60,0x61,0xA1,0x63,0xA3,0xA2,0x62,0x66,0xA6,0xA7,0x67,0xA5,0x65,0x64,0xA4, 42 | 0x6C,0xAC,0xAD,0x6D,0xAF,0x6F,0x6E,0xAE,0xAA,0x6A,0x6B,0xAB,0x69,0xA9,0xA8,0x68, 43 | 0x78,0xB8,0xB9,0x79,0xBB,0x7B,0x7A,0xBA,0xBE,0x7E,0x7F,0xBF,0x7D,0xBD,0xBC,0x7C, 44 | 0xB4,0x74,0x75,0xB5,0x77,0xB7,0xB6,0x76,0x72,0xB2,0xB3,0x73,0xB1,0x71,0x70,0xB0, 45 | 0x50,0x90,0x91,0x51,0x93,0x53,0x52,0x92,0x96,0x56,0x57,0x97,0x55,0x95,0x94,0x54, 46 | 0x9C,0x5C,0x5D,0x9D,0x5F,0x9F,0x9E,0x5E,0x5A,0x9A,0x9B,0x5B,0x99,0x59,0x58,0x98, 47 | 0x88,0x48,0x49,0x89,0x4B,0x8B,0x8A,0x4A,0x4E,0x8E,0x8F,0x4F,0x8D,0x4D,0x4C,0x8C, 48 | 0x44,0x84,0x85,0x45,0x87,0x47,0x46,0x86,0x82,0x42,0x43,0x83,0x41,0x81,0x80,0x40, 49 | 50 | }; 51 | 52 | 53 | quint16 Utils::modbus_crc(MB_U8 *p, int n) 54 | { 55 | MB_U8 i; 56 | MB_U8 R0 = 0xff; //Set CRC16 High 57 | MB_U8 R1 = 0xff; //Set CRC16 Low 58 | 59 | do 60 | { 61 | i = *p ^ R1; 62 | p++; 63 | R1 = R0 ^ CRC_TABLE_H[i]; 64 | R0 = CRC_TABLE_L[i]; 65 | } 66 | while( --n != 0); 67 | 68 | return((((MB_U16)R0) << 8) + R1); 69 | 70 | } 71 | -------------------------------------------------------------------------------- /crc16.h: -------------------------------------------------------------------------------- 1 | #ifndef CRC16_H 2 | #define CRC16_H 3 | 4 | #include 5 | 6 | typedef quint8 MB_U8; 7 | typedef quint16 MB_U16; 8 | 9 | namespace Utils { 10 | quint16 modbus_crc(MB_U8 *p, int n); 11 | } 12 | 13 | 14 | #endif // CRC16_H 15 | 16 | -------------------------------------------------------------------------------- /devcmdrecv.cpp: -------------------------------------------------------------------------------- 1 | #include "devcmdrecv.h" 2 | #include "utils.h" 3 | 4 | static const int MAX_DEV_CMD_SIZE = 300; 5 | static char devCmdBuffer[MAX_DEV_CMD_SIZE]; 6 | 7 | DevCmdRecv::DevCmdRecv( CmdFactory *pCmdFactory, QUdpSocket *pUdpSocket ) : UDPCmdRecv(pCmdFactory, pUdpSocket) 8 | { 9 | 10 | } 11 | 12 | void DevCmdRecv::createCmd() 13 | { 14 | QHostAddress senderAddr; 15 | quint16 senderPort = 0; 16 | memset(devCmdBuffer, 0, MAX_DEV_CMD_SIZE); 17 | qint64 bytesRead = m_pUdpSocket->readDatagram(devCmdBuffer, MAX_DEV_CMD_SIZE, &senderAddr, &senderPort); 18 | if(bytesRead <= 0) 19 | return; 20 | QByteArray aDevCmd(devCmdBuffer, bytesRead); 21 | quint32 devId = Utils::getDevIdFromCmd(aDevCmd); 22 | m_pCmdFactory->createFromDevCmd(devId, aDevCmd, senderAddr, senderPort); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /devcmdrecv.h: -------------------------------------------------------------------------------- 1 | #ifndef DEVCMDRECV_H 2 | #define DEVCMDRECV_H 3 | 4 | #include "udpcmdrecv.h" 5 | 6 | class DevCmdRecv : public UDPCmdRecv 7 | { 8 | 9 | public: 10 | DevCmdRecv(CmdFactory *pCmdFactory, QUdpSocket *pUdpSocket); 11 | void createCmd(); 12 | }; 13 | 14 | #endif // DEVCMDRECV_H 15 | -------------------------------------------------------------------------------- /httphandler.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/httphandler.cpp -------------------------------------------------------------------------------- /httphandler.h: -------------------------------------------------------------------------------- 1 | #ifndef HTTPHANDLER 2 | #define HTTPHANDLER 3 | 4 | #include 5 | #include 6 | #include "icmdhandler.h" 7 | #include 8 | 9 | class HTTPHandler : public ICmdHandler 10 | { 11 | public: 12 | HTTPHandler(); 13 | ~HTTPHandler(); 14 | int handleCmd(QByteArray &aCmd); 15 | bool isIdle() const; 16 | static void readSettings(QSettings &settings); 17 | static HTTPHandler * getHttpHandler(); 18 | 19 | protected: 20 | volatile bool m_isIdle; 21 | curl_slist *m_headers; 22 | static QUrl m_serviceUrl; 23 | static QList lstHttpHandler; 24 | }; 25 | 26 | bool isHttpHandlerIdle(const HTTPHandler *pHttpHandler); 27 | 28 | #endif // HTTPHANDLER 29 | -------------------------------------------------------------------------------- /icmdhandler.cpp: -------------------------------------------------------------------------------- 1 | #include "icmdhandler.h" 2 | 3 | ICmdHandler::~ICmdHandler() 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /icmdhandler.h: -------------------------------------------------------------------------------- 1 | #ifndef ICMDHANDLER_H 2 | #define ICMDHANDLER_H 3 | 4 | #include 5 | 6 | class ICmdHandler : public QObject 7 | { 8 | public: 9 | virtual ~ICmdHandler(); 10 | virtual int handleCmd(QByteArray &aCmd) = 0; 11 | 12 | }; 13 | 14 | typedef ICmdHandler *PCmdHandler; 15 | typedef QList ListPCmdHandler; 16 | 17 | #endif // ICMDHANDLER_H 18 | -------------------------------------------------------------------------------- /icmdrecv.cpp: -------------------------------------------------------------------------------- 1 | #include "icmdrecv.h" 2 | 3 | ICmdRecv::~ICmdRecv() 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /icmdrecv.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/icmdrecv.h -------------------------------------------------------------------------------- /icmdtranslator.cpp: -------------------------------------------------------------------------------- 1 | #include "icmdtranslator.h" 2 | 3 | ICmdTranslator::~ICmdTranslator() 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /icmdtranslator.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/icmdtranslator.h -------------------------------------------------------------------------------- /include/curl.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/include/curl.rar -------------------------------------------------------------------------------- /include/curl/curlver.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_CURLVER_H 2 | #define __CURL_CURLVER_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | * $Id: curlver.h,v 1.35 2008-01-24 14:05:56 gknauf Exp $ 24 | ***************************************************************************/ 25 | 26 | /* This header file contains nothing but libcurl version info, generated by 27 | a script at release-time. This was made its own header file in 7.11.2 */ 28 | 29 | /* This is the global package copyright */ 30 | #define LIBCURL_COPYRIGHT "1996 - 2008 Daniel Stenberg, ." 31 | 32 | /* This is the version number of the libcurl package from which this header 33 | file origins: */ 34 | #define LIBCURL_VERSION "7.18.0" 35 | 36 | /* The numeric version number is also available "in parts" by using these 37 | defines: */ 38 | #define LIBCURL_VERSION_MAJOR 7 39 | #define LIBCURL_VERSION_MINOR 18 40 | #define LIBCURL_VERSION_PATCH 0 41 | 42 | /* This is the numeric version of the libcurl version number, meant for easier 43 | parsing and comparions by programs. The LIBCURL_VERSION_NUM define will 44 | always follow this syntax: 45 | 46 | 0xXXYYZZ 47 | 48 | Where XX, YY and ZZ are the main version, release and patch numbers in 49 | hexadecimal (using 8 bits each). All three numbers are always represented 50 | using two digits. 1.2 would appear as "0x010200" while version 9.11.7 51 | appears as "0x090b07". 52 | 53 | This 6-digit (24 bits) hexadecimal number does not show pre-release number, 54 | and it is always a greater number in a more recent release. It makes 55 | comparisons with greater than and less than work. 56 | */ 57 | #define LIBCURL_VERSION_NUM 0x071200 58 | 59 | /* 60 | * This is the date and time when the full source package was created. The 61 | * timestamp is not stored in CVS, as the timestamp is properly set in the 62 | * tarballs by the maketgz script. 63 | * 64 | * The format of the date should follow this template: 65 | * 66 | * "Mon Feb 12 11:35:33 UTC 2007" 67 | */ 68 | #define LIBCURL_TIMESTAMP "Mon Jan 28 17:28:54 UTC 2008" 69 | 70 | #endif /* __CURL_CURLVER_H */ 71 | -------------------------------------------------------------------------------- /include/curl/easy.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_EASY_H 2 | #define __CURL_EASY_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | * $Id: easy.h,v 1.13 2004/11/09 14:02:58 giva Exp $ 24 | ***************************************************************************/ 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | CURL_EXTERN CURL *curl_easy_init(void); 30 | CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...); 31 | CURL_EXTERN CURLcode curl_easy_perform(CURL *curl); 32 | CURL_EXTERN void curl_easy_cleanup(CURL *curl); 33 | 34 | /* 35 | * NAME curl_easy_getinfo() 36 | * 37 | * DESCRIPTION 38 | * 39 | * Request internal information from the curl session with this function. The 40 | * third argument MUST be a pointer to a long, a pointer to a char * or a 41 | * pointer to a double (as the documentation describes elsewhere). The data 42 | * pointed to will be filled in accordingly and can be relied upon only if the 43 | * function returns CURLE_OK. This function is intended to get used *AFTER* a 44 | * performed transfer, all results from this function are undefined until the 45 | * transfer is completed. 46 | */ 47 | CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...); 48 | 49 | 50 | /* 51 | * NAME curl_easy_duphandle() 52 | * 53 | * DESCRIPTION 54 | * 55 | * Creates a new curl session handle with the same options set for the handle 56 | * passed in. Duplicating a handle could only be a matter of cloning data and 57 | * options, internal state info and things like persistant connections cannot 58 | * be transfered. It is useful in multithreaded applications when you can run 59 | * curl_easy_duphandle() for each new thread to avoid a series of identical 60 | * curl_easy_setopt() invokes in every thread. 61 | */ 62 | CURL_EXTERN CURL* curl_easy_duphandle(CURL *curl); 63 | 64 | /* 65 | * NAME curl_easy_reset() 66 | * 67 | * DESCRIPTION 68 | * 69 | * Re-initializes a CURL handle to the default values. This puts back the 70 | * handle to the same state as it was in when it was just created. 71 | * 72 | * It does keep: live connections, the Session ID cache, the DNS cache and the 73 | * cookies. 74 | */ 75 | CURL_EXTERN void curl_easy_reset(CURL *curl); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /include/curl/mprintf.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_MPRINTF_H 2 | #define __CURL_MPRINTF_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | * $Id: mprintf.h,v 1.15 2007-08-07 12:44:38 patrickm Exp $ 24 | ***************************************************************************/ 25 | 26 | #include 27 | #include /* needed for FILE */ 28 | 29 | #include "curl.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | CURL_EXTERN int curl_mprintf(const char *format, ...); 36 | CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...); 37 | CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...); 38 | CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength, const char *format, ...); 39 | CURL_EXTERN int curl_mvprintf(const char *format, va_list args); 40 | CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args); 41 | CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args); 42 | CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength, const char *format, va_list args); 43 | CURL_EXTERN char *curl_maprintf(const char *format, ...); 44 | CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args); 45 | 46 | #ifdef _MPRINTF_REPLACE 47 | # undef printf 48 | # undef fprintf 49 | # undef sprintf 50 | # undef vsprintf 51 | # undef snprintf 52 | # undef vprintf 53 | # undef vfprintf 54 | # undef vsnprintf 55 | # undef aprintf 56 | # undef vaprintf 57 | # define printf curl_mprintf 58 | # define fprintf curl_mfprintf 59 | #ifdef CURLDEBUG 60 | /* When built with CURLDEBUG we define away the sprintf() functions since we 61 | don't want internal code to be using them */ 62 | # define sprintf sprintf_was_used 63 | # define vsprintf vsprintf_was_used 64 | #else 65 | # define sprintf curl_msprintf 66 | # define vsprintf curl_mvsprintf 67 | #endif 68 | # define snprintf curl_msnprintf 69 | # define vprintf curl_mvprintf 70 | # define vfprintf curl_mvfprintf 71 | # define vsnprintf curl_mvsnprintf 72 | # define aprintf curl_maprintf 73 | # define vaprintf curl_mvaprintf 74 | #endif 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif /* __CURL_MPRINTF_H */ 81 | -------------------------------------------------------------------------------- /include/curl/stdcheaders.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDC_HEADERS_H 2 | #define __STDC_HEADERS_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | * $Id: stdcheaders.h,v 1.8 2004/01/07 09:19:34 bagder Exp $ 24 | ***************************************************************************/ 25 | 26 | #include 27 | 28 | size_t fread (void *, size_t, size_t, FILE *); 29 | size_t fwrite (const void *, size_t, size_t, FILE *); 30 | 31 | int strcasecmp(const char *, const char *); 32 | int strncasecmp(const char *, const char *, size_t); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/curl/types.h: -------------------------------------------------------------------------------- 1 | /* not used */ 2 | -------------------------------------------------------------------------------- /include/log4cplus/asyncappender.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4cplus 3 | // File: asyncappender.h 4 | // Created: 1/2009 5 | // Author: Vaclav Haisman 6 | // 7 | // 8 | // Copyright (C) 2009-2015, Vaclav Haisman. All rights reserved. 9 | // 10 | // Redistribution and use in source and binary forms, with or without modifica- 11 | // tion, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, 14 | // this list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 21 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 22 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 25 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 26 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | 32 | // 33 | 34 | /** @file */ 35 | 36 | #ifndef LOG4CPLUS_ASYNCAPPENDER_H 37 | #define LOG4CPLUS_ASYNCAPPENDER_H 38 | 39 | #include 40 | 41 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 42 | #pragma once 43 | #endif 44 | 45 | #ifndef LOG4CPLUS_SINGLE_THREADED 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | 53 | namespace log4cplus 54 | { 55 | 56 | 57 | class LOG4CPLUS_EXPORT AsyncAppender 58 | : public Appender 59 | , public helpers::AppenderAttachableImpl 60 | { 61 | public: 62 | AsyncAppender (SharedAppenderPtr const & app, unsigned max_len); 63 | AsyncAppender (helpers::Properties const &); 64 | virtual ~AsyncAppender (); 65 | 66 | virtual void close (); 67 | 68 | protected: 69 | virtual void append (spi::InternalLoggingEvent const &); 70 | 71 | void init_queue_thread (unsigned); 72 | 73 | thread::AbstractThreadPtr queue_thread; 74 | thread::QueuePtr queue; 75 | 76 | private: 77 | AsyncAppender (AsyncAppender const &); 78 | AsyncAppender & operator = (AsyncAppender const &); 79 | }; 80 | 81 | 82 | typedef helpers::SharedObjectPtr AsyncAppenderPtr; 83 | 84 | 85 | } // namespace log4cplus 86 | 87 | 88 | #endif // LOG4CPLUS_SINGLE_THREADED 89 | 90 | #endif // LOG4CPLUS_ASYNCAPPENDER_H 91 | -------------------------------------------------------------------------------- /include/log4cplus/clfsappender.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4cplus 3 | // File: clfsappender.h 4 | // Created: 5/2012 5 | // Author: Vaclav Zeman 6 | // 7 | // 8 | // Copyright (C) 2012-2015, Vaclav Zeman. All rights reserved. 9 | // 10 | // Redistribution and use in source and binary forms, with or without modifica- 11 | // tion, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, 14 | // this list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 21 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 22 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 25 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 26 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | 32 | // 33 | 34 | /** @file */ 35 | 36 | #ifndef LOG4CPLUS_CLFSAPPENDER_H 37 | #define LOG4CPLUS_CLFSAPPENDER_H 38 | 39 | #include 40 | 41 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 42 | #pragma once 43 | #endif 44 | 45 | #include 46 | 47 | 48 | #if defined (LOG4CPLUS_CLFSAPPENDER_BUILD_DLL) 49 | # if defined (INSIDE_LOG4CPLUS_CLFSAPPENDER) 50 | # define LOG4CPLUS_CLFSAPPENDER_EXPORT __declspec(dllexport) 51 | # else 52 | # define LOG4CPLUS_CLFSAPPENDER_EXPORT __declspec(dllimport) 53 | # endif 54 | #else 55 | # define LOG4CPLUS_CLFSAPPENDER_EXPORT 56 | #endif 57 | 58 | 59 | namespace log4cplus 60 | { 61 | 62 | 63 | class LOG4CPLUS_CLFSAPPENDER_EXPORT CLFSAppender 64 | : public Appender 65 | { 66 | public: 67 | CLFSAppender (tstring const & logname, unsigned long logsize, 68 | unsigned long buffersize); 69 | explicit CLFSAppender (helpers::Properties const &); 70 | virtual ~CLFSAppender (); 71 | 72 | virtual void close (); 73 | 74 | static void registerAppender (); 75 | 76 | protected: 77 | virtual void append (spi::InternalLoggingEvent const &); 78 | 79 | void init (tstring const & logname, unsigned long logsize, 80 | unsigned long buffersize); 81 | 82 | struct Data; 83 | 84 | Data * data; 85 | 86 | private: 87 | CLFSAppender (CLFSAppender const &); 88 | CLFSAppender & operator = (CLFSAppender const &); 89 | }; 90 | 91 | 92 | typedef helpers::SharedObjectPtr CLFSAppenderPtr; 93 | 94 | 95 | } // namespace log4cplus 96 | 97 | 98 | #endif // LOG4CPLUS_CLFSAPPENDER_H 99 | -------------------------------------------------------------------------------- /include/log4cplus/clogger.h: -------------------------------------------------------------------------------- 1 | // -*- C -*- 2 | /** 3 | * Module: Log4CPLUS 4 | * File: clogger.h 5 | * Created: 01/2011 6 | * Author: Jens Rehsack 7 | * 8 | * 9 | * Copyright 2011-2015 Jens Rehsack & Tad E. Smith 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | /** @file 25 | * This header defines the C API for log4cplus and the logging macros. */ 26 | 27 | #ifndef LOG4CPLUS_CLOGGERHEADER_ 28 | #define LOG4CPLUS_CLOGGERHEADER_ 29 | 30 | #include 31 | 32 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 33 | #pragma once 34 | #endif 35 | 36 | 37 | #ifdef __cplusplus 38 | extern "C" 39 | { 40 | #endif 41 | 42 | // TODO UNICDE capable 43 | 44 | typedef void *logger_t; 45 | typedef int loglevel_t; 46 | 47 | #define L4CP_OFF_LOG_LEVEL 60000 48 | #define L4CP_FATAL_LOG_LEVEL 50000 49 | #define L4CP_ERROR_LOG_LEVEL 40000 50 | #define L4CP_WARN_LOG_LEVEL 30000 51 | #define L4CP_INFO_LOG_LEVEL 20000 52 | #define L4CP_DEBUG_LOG_LEVEL 10000 53 | #define L4CP_TRACE_LOG_LEVEL 0 54 | #define L4CP_ALL_LOG_LEVEL TRACE_LOG_LEVEL 55 | #define L4CP_NOT_SET_LOG_LEVEL -1 56 | 57 | #ifdef UNICODE 58 | # define LOG4CPLUS_TEXT2(STRING) L##STRING 59 | typedef wchar_t log4cplus_char_t; 60 | #else 61 | # define LOG4CPLUS_TEXT2(STRING) STRING 62 | typedef char log4cplus_char_t; 63 | #endif // UNICODE 64 | #define LOG4CPLUS_TEXT(STRING) LOG4CPLUS_TEXT2(STRING) 65 | 66 | LOG4CPLUS_EXPORT int log4cplus_file_configure(const log4cplus_char_t *pathname); 67 | LOG4CPLUS_EXPORT int log4cplus_str_configure(const log4cplus_char_t *config); 68 | LOG4CPLUS_EXPORT int log4cplus_basic_configure(void); 69 | LOG4CPLUS_EXPORT void log4cplus_shutdown(void); 70 | 71 | LOG4CPLUS_EXPORT int log4cplus_logger_exists(const log4cplus_char_t *name); 72 | LOG4CPLUS_EXPORT int log4cplus_logger_is_enabled_for( 73 | const log4cplus_char_t *name, loglevel_t ll); 74 | LOG4CPLUS_EXPORT int log4cplus_logger_log(const log4cplus_char_t *name, 75 | loglevel_t ll, const log4cplus_char_t *msgfmt, ...) 76 | LOG4CPLUS_FORMAT_ATTRIBUTE (__printf__, 3, 4); 77 | LOG4CPLUS_EXPORT int log4cplus_logger_force_log(const log4cplus_char_t *name, 78 | loglevel_t ll, const log4cplus_char_t *msgfmt, ...) 79 | LOG4CPLUS_FORMAT_ATTRIBUTE (__printf__, 3, 4); 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif /*?LOG4CPLUS_CLOGGERHEADER_*/ 86 | -------------------------------------------------------------------------------- /include/log4cplus/config/macosx.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: config-macosx.h 4 | // Created: 7/2003 5 | // Author: Christopher R. Bailey 6 | // 7 | // 8 | // Copyright 2003-2015 Christopher R. Bailey 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_CONFIG_MACOSX_HEADER_ 25 | #define LOG4CPLUS_CONFIG_MACOSX_HEADER_ 26 | 27 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 28 | #pragma once 29 | #endif 30 | 31 | #if (defined(__APPLE__) || (defined(__MWERKS__) && defined(__MACOS__))) 32 | 33 | #define LOG4CPLUS_HAVE_GETTIMEOFDAY 1 34 | #define socklen_t int 35 | 36 | #endif // MACOSX 37 | #endif // LOG4CPLUS_CONFIG_MACOSX_HEADER_ 38 | -------------------------------------------------------------------------------- /include/log4cplus/config/windowsh-inc.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: windowsh-inc.h 4 | // Created: 4/2010 5 | // Author: Vaclav Zeman 6 | // 7 | // 8 | // Copyright (C) 2010-2015, Vaclav Zeman. All rights reserved. 9 | // 10 | // Redistribution and use in source and binary forms, with or without modifica- 11 | // tion, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, 14 | // this list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 21 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 22 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 25 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 26 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // NOTE: This file is a fragment intentionally left without include guards. 32 | 33 | #if defined (_WIN32) 34 | #undef WIN32_LEAN_AND_MEAN 35 | #define WIN32_LEAN_AND_MEAN 36 | 37 | #undef NOGDICAPMASKS 38 | #define NOGDICAPMASKS 39 | 40 | #undef NOVIRTUALKEYCODES 41 | #define NOVIRTUALKEYCODES 42 | 43 | #undef NOWINMESSAGES 44 | #define NOWINMESSAGES 45 | 46 | #undef NOWINSTYLES 47 | #define NOWINSTYLES 48 | 49 | #undef NOSYSMETRICS 50 | #define NOSYSMETRICS 51 | 52 | #undef NOMENUS 53 | #define NOMENUS 54 | 55 | #undef NOICONS 56 | #define NOICONS 57 | 58 | #undef NOKEYSTATES 59 | #define NOKEYSTATES 60 | 61 | #undef NOSYSCOMMANDS 62 | #define NOSYSCOMMANDS 63 | 64 | #undef NORASTEROPS 65 | #define NORASTEROPS 66 | 67 | #undef NOSHOWWINDOW 68 | #define NOSHOWWINDOW 69 | 70 | #undef NOATOM 71 | #define NOATOM 72 | 73 | #undef NOCLIPBOARD 74 | #define NOCLIPBOARD 75 | 76 | #undef NOCOLOR 77 | #define NOCOLOR 78 | 79 | #undef NOCTLMGR 80 | #define NOCTLMGR 81 | 82 | #undef NODRAWTEXT 83 | #define NODRAWTEXT 84 | 85 | #undef NOGDI 86 | #define NOGDI 87 | 88 | #undef NOKERNEL 89 | #define NOKERNEL 90 | 91 | #undef NOUSER 92 | #define NOUSER 93 | 94 | #undef NONLS 95 | #define NONLS 96 | 97 | #undef NOMB 98 | #define NOMB 99 | 100 | #undef NOMEMMGR 101 | #define NOMEMMGR 102 | 103 | #undef NOMETAFILE 104 | #define NOMETAFILE 105 | 106 | #undef NOMINMAX 107 | #define NOMINMAX 108 | 109 | #undef NOMSG 110 | #define NOMSG 111 | 112 | #undef NOOPENFILE 113 | #define NOOPENFILE 114 | 115 | #undef NOSCROLL 116 | #define NOSCROLL 117 | 118 | #undef NOSERVICE 119 | #define NOSERVICE 120 | 121 | #undef NOSOUND 122 | #define NOSOUND 123 | 124 | #undef NOTEXTMETRIC 125 | #define NOTEXTMETRIC 126 | 127 | #undef NOWH 128 | #define NOWH 129 | 130 | #undef NOWINOFFSETS 131 | #define NOWINOFFSETS 132 | 133 | #undef NOCOMM 134 | #define NOCOMM 135 | 136 | #undef NOKANJI 137 | #define NOKANJI 138 | 139 | #undef NOHELP 140 | #define NOHELP 141 | 142 | #undef NOPROFILER 143 | #define NOPROFILER 144 | 145 | #undef NODEFERWINDOWPOS 146 | #define NODEFERWINDOWPOS 147 | 148 | #undef NOMCX 149 | #define NOMCX 150 | 151 | #include 152 | #include 153 | #include 154 | #if defined (LOG4CPLUS_HAVE_INTRIN_H) 155 | #include 156 | #endif 157 | #endif 158 | 159 | // NOTE: This file is a fragment intentionally left without include guards. 160 | -------------------------------------------------------------------------------- /include/log4cplus/consoleappender.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: consoleappender.h 4 | // Created: 6/2001 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2001-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_CONSOLE_APPENDER_HEADER_ 25 | #define LOG4CPLUS_CONSOLE_APPENDER_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | 35 | namespace log4cplus { 36 | /** 37 | * ConsoleAppender appends log events to std::cout or 38 | * std::cerr using a layout specified by the 39 | * user. The default target is std::cout. 40 | * 41 | *

Properties

42 | *
43 | *
logToStdErr
44 | *
When it is set true, the output stream will be 45 | * std::cerr instead of std::cout.
46 | * 47 | *
ImmediateFlush
48 | *
When it is set true, output stream will be flushed after 49 | * each appended event.
50 | * 51 | *
52 | * \sa Appender 53 | */ 54 | class LOG4CPLUS_EXPORT ConsoleAppender : public Appender { 55 | public: 56 | // Ctors 57 | ConsoleAppender(bool logToStdErr = false, bool immediateFlush = false); 58 | ConsoleAppender(const log4cplus::helpers::Properties & properties); 59 | 60 | // Dtor 61 | ~ConsoleAppender(); 62 | 63 | // Methods 64 | virtual void close(); 65 | 66 | //! This mutex is used by ConsoleAppender and helpers::LogLog 67 | //! classes to synchronize output to console. 68 | static log4cplus::thread::Mutex const & getOutputMutex(); 69 | 70 | protected: 71 | virtual void append(const spi::InternalLoggingEvent& event); 72 | 73 | // Data 74 | bool logToStdErr; 75 | /** 76 | * Immediate flush means that the underlying output stream 77 | * will be flushed at the end of each append operation. 78 | */ 79 | bool immediateFlush; 80 | }; 81 | 82 | } // end namespace log4cplus 83 | 84 | #endif // LOG4CPLUS_CONSOLE_APPENDER_HEADER_ 85 | 86 | -------------------------------------------------------------------------------- /include/log4cplus/fstreams.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: fstreams.h 4 | // Created: 4/2003 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2003-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_FSTREAMS_HEADER_ 25 | #define LOG4CPLUS_FSTREAMS_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | #include 35 | 36 | 37 | namespace log4cplus 38 | { 39 | 40 | 41 | typedef std::basic_ofstream tofstream; 42 | typedef std::basic_ifstream tifstream; 43 | 44 | //! \def LOG4CPLUS_FSTREAM_PREFERED_FILE_NAME(X) 45 | //! \brief Expands into expression that picks the right type for 46 | //! std::fstream file name parameter. 47 | #if defined (LOG4CPLUS_FSTREAM_ACCEPTS_WCHAR_T) && defined (UNICODE) 48 | # define LOG4CPLUS_FSTREAM_PREFERED_FILE_NAME(X) (X) 49 | #else 50 | # define LOG4CPLUS_FSTREAM_PREFERED_FILE_NAME(X) (LOG4CPLUS_TSTRING_TO_STRING(X)) 51 | #endif 52 | 53 | 54 | } 55 | 56 | #endif // LOG4CPLUS_FSTREAMS_HEADER_ 57 | -------------------------------------------------------------------------------- /include/log4cplus/helpers/appenderattachableimpl.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: appenderattachableimpl.h 4 | // Created: 6/2001 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2001-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_HELPERS_APPENDER_ATTACHABLE_IMPL_HEADER_ 25 | #define LOG4CPLUS_HELPERS_APPENDER_ATTACHABLE_IMPL_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | 42 | namespace log4cplus { 43 | namespace helpers { 44 | 45 | /** 46 | * This Interface is for attaching Appenders to objects. 47 | */ 48 | class LOG4CPLUS_EXPORT AppenderAttachableImpl 49 | : public log4cplus::spi::AppenderAttachable 50 | { 51 | public: 52 | // Data 53 | thread::Mutex appender_list_mutex; 54 | 55 | // Ctors 56 | AppenderAttachableImpl(); 57 | 58 | // Dtor 59 | virtual ~AppenderAttachableImpl(); 60 | 61 | // Methods 62 | /** 63 | * Add an appender. If the appender is already in the list in 64 | * won't be added again. 65 | */ 66 | virtual void addAppender(SharedAppenderPtr newAppender); 67 | 68 | /** 69 | * Get all previously added appenders as an vectory. 70 | */ 71 | virtual SharedAppenderPtrList getAllAppenders(); 72 | 73 | /** 74 | * Look for an attached appender named as name. 75 | * 76 | * Return the appender with that name if in the list. Return null 77 | * otherwise. 78 | */ 79 | virtual SharedAppenderPtr getAppender(const log4cplus::tstring& name); 80 | 81 | /** 82 | * Remove all previously added appenders. 83 | */ 84 | virtual void removeAllAppenders(); 85 | 86 | /** 87 | * Remove the appender passed as parameter from the list of appenders. 88 | */ 89 | virtual void removeAppender(SharedAppenderPtr appender); 90 | 91 | /** 92 | * Remove the appender with the name passed as parameter from the 93 | * list of appenders. 94 | */ 95 | virtual void removeAppender(const log4cplus::tstring& name); 96 | 97 | /** 98 | * Call the doAppend method on all attached appenders. 99 | */ 100 | int appendLoopOnAppenders(const spi::InternalLoggingEvent& event) const; 101 | 102 | protected: 103 | // Types 104 | typedef std::vector ListType; 105 | 106 | // Data 107 | /** Array of appenders. */ 108 | ListType appenderList; 109 | 110 | private: 111 | AppenderAttachableImpl(AppenderAttachableImpl const &); 112 | AppenderAttachableImpl & operator = (AppenderAttachableImpl const &); 113 | }; // end class AppenderAttachableImpl 114 | 115 | } // end namespace helpers 116 | } // end namespace log4cplus 117 | 118 | #endif // LOG4CPLUS_HELPERS_APPENDER_ATTACHABLE_IMPL_HEADER_ 119 | 120 | -------------------------------------------------------------------------------- /include/log4cplus/helpers/connectorthread.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Copyright (C) 2013-2015, Vaclav Zeman. All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modifica- 5 | // tion, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 15 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 17 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 19 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 20 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #ifndef LOG4CPLUS_HELPERS_CONNECTORTHREAD_H 26 | #define LOG4CPLUS_HELPERS_CONNECTORTHREAD_H 27 | 28 | #include 29 | 30 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 31 | #pragma once 32 | #endif 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | #if ! defined (LOG4CPLUS_SINGLE_THREADED) 40 | 41 | namespace log4cplus { namespace helpers { 42 | 43 | 44 | class LOG4CPLUS_EXPORT ConnectorThread; 45 | 46 | //! Interface implemented by users of ConnectorThread. 47 | class LOG4CPLUS_EXPORT IConnectorThreadClient 48 | { 49 | protected: 50 | virtual ~IConnectorThreadClient (); 51 | 52 | //! \return Mutex for synchronization between ConnectorThread and 53 | //! its client object. This is usually SharedObject::access_mutex. 54 | virtual thread::Mutex const & ctcGetAccessMutex () const = 0; 55 | 56 | //! \return Socket variable in ConnectorThread client to maintain. 57 | virtual helpers::Socket & ctcGetSocket () = 0; 58 | 59 | //! \return ConnectorThread client's function returning connected 60 | //! socket. 61 | virtual helpers::Socket ctcConnect () = 0; 62 | 63 | //! Sets connected flag to true in ConnectorThread's client. 64 | virtual void ctcSetConnected () = 0; 65 | 66 | friend class LOG4CPLUS_EXPORT ConnectorThread; 67 | }; 68 | 69 | 70 | //! This class is used by SocketAppender and (remote) SysLogAppender 71 | //! to provide asynchronous re-connection. 72 | class LOG4CPLUS_EXPORT ConnectorThread 73 | : public thread::AbstractThread 74 | { 75 | public: 76 | //! \param client reference to ConnectorThread's client object 77 | ConnectorThread (IConnectorThreadClient & client); 78 | virtual ~ConnectorThread (); 79 | 80 | virtual void run(); 81 | 82 | //! Call this function to terminate ConnectorThread. The function 83 | //! sets `exit_flag` and then triggers `trigger_ev` to wake up the 84 | //! ConnectorThread. 85 | void terminate (); 86 | 87 | //! This function triggers (`trigger_ev`) connection check and 88 | //! attempt to re-connect a broken connection, when necessary. 89 | void trigger (); 90 | 91 | protected: 92 | //! reference to ConnectorThread's client 93 | IConnectorThreadClient & ctc; 94 | 95 | //! This event is the re-connection trigger. 96 | thread::ManualResetEvent trigger_ev; 97 | 98 | //! When this variable set to true when ConnectorThread is signaled to 99 | bool exit_flag; 100 | }; 101 | 102 | 103 | } } // namespace log4cplus { namespace helpers { 104 | 105 | #endif // ! defined (LOG4CPLUS_SINGLE_THREADED) 106 | 107 | #endif // LOG4CPLUS_HELPERS_CONNECTORTHREAD_H 108 | -------------------------------------------------------------------------------- /include/log4cplus/helpers/fileinfo.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // 3 | // Copyright (C) 2012-2015, Vaclav Zeman. All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modifica- 6 | // tion, are permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, 9 | // this list of conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 16 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 17 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 18 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 19 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 20 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 21 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | #if ! defined (LOG4CPLUS_HELPERS_FILEINFO_H) 27 | #define LOG4CPLUS_HELPERS_FILEINFO_H 28 | 29 | #include 30 | 31 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 32 | #pragma once 33 | #endif 34 | 35 | #include 36 | #ifdef LOG4CPLUS_HAVE_SYS_TYPES_H 37 | #include 38 | #endif 39 | 40 | 41 | namespace log4cplus { namespace helpers { 42 | 43 | //! FileInfo structure is OS independent abstraction of the 44 | //! stat() function. 45 | struct LOG4CPLUS_EXPORT FileInfo 46 | { 47 | helpers::Time mtime; 48 | bool is_link; 49 | off_t size; 50 | }; 51 | 52 | 53 | //! OS independent abstraction of stat() function. 54 | LOG4CPLUS_EXPORT int getFileInfo (FileInfo * fi, tstring const & name); 55 | 56 | 57 | } } // namespace log4cplus { namespace helpers { 58 | 59 | #endif // LOG4CPLUS_HELPERS_FILEINFO_H 60 | -------------------------------------------------------------------------------- /include/log4cplus/helpers/lockfile.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // 3 | // Copyright (C) 2012-2015, Vaclav Zeman. All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modifica- 6 | // tion, are permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, 9 | // this list of conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 16 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 17 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 18 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 19 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 20 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 21 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | #if ! defined (LOG4CPLUS_HELPERS_LOCKFILE_H) 27 | #define LOG4CPLUS_HELPERS_LOCKFILE_H 28 | 29 | #include 30 | 31 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 32 | #pragma once 33 | #endif 34 | 35 | #include 36 | #include 37 | 38 | 39 | namespace log4cplus { namespace helpers { 40 | 41 | 42 | class LOG4CPLUS_EXPORT LockFile 43 | { 44 | public: 45 | LockFile (tstring const & lock_file, bool create_dirs = false); 46 | ~LockFile (); 47 | 48 | void lock () const; 49 | void unlock () const; 50 | 51 | private: 52 | void open (int) const; 53 | void close () const; 54 | 55 | struct Impl; 56 | 57 | tstring lock_file_name; 58 | Impl * data; 59 | bool create_dirs; 60 | }; 61 | 62 | 63 | typedef log4cplus::thread::SyncGuard LockFileGuard; 64 | 65 | 66 | } } // namespace log4cplus { namespace helpers { 67 | 68 | 69 | #endif // LOG4CPLUS_HELPERS_LOCKFILE_H 70 | -------------------------------------------------------------------------------- /include/log4cplus/helpers/loglog.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: loglog.h 4 | // Created: 6/2001 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2001-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_HELPERS_LOGLOG 25 | #define LOG4CPLUS_HELPERS_LOGLOG 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | 38 | namespace log4cplus { 39 | namespace helpers { 40 | 41 | /** 42 | * This class used to output log statements from within the log4cplus package. 43 | * 44 | * Log4cplus components cannot make log4cplus logging calls. However, it is 45 | * sometimes useful for the user to learn about what log4cplus is 46 | * doing. You can enable log4cplus internal logging by defining the 47 | * log4cplus.configDebug variable. 48 | * 49 | * All log4cplus internal debug calls go to cout 50 | * where as internal error messages are sent to 51 | * cerr. All internal messages are prepended with 52 | * the string "log4clus: ". 53 | */ 54 | class LOG4CPLUS_EXPORT LogLog 55 | { 56 | public: 57 | //! Return type of getLogLog(). 58 | typedef LogLog * Ptr; 59 | 60 | /** 61 | * Returns a reference to the LogLog singleton. 62 | */ 63 | static Ptr getLogLog(); 64 | 65 | 66 | /** 67 | * Allows to enable/disable log4cplus internal logging. 68 | */ 69 | void setInternalDebugging(bool enabled); 70 | 71 | /** 72 | * In quite mode no LogLog generates strictly no output, not even 73 | * for errors. 74 | * 75 | * @param quietMode A true for not 76 | */ 77 | void setQuietMode(bool quietMode); 78 | 79 | /** 80 | * This method is used to output log4cplus internal debug 81 | * statements. Output goes to std::cout. 82 | */ 83 | void debug(const log4cplus::tstring& msg) const; 84 | void debug(tchar const * msg) const; 85 | 86 | /** 87 | * This method is used to output log4cplus internal error 88 | * statements. There is no way to disable error 89 | * statements. Output goes to 90 | * std::cerr. Optionally, this method can 91 | * throw std::runtime_error exception too. 92 | */ 93 | void error(const log4cplus::tstring& msg, bool throw_flag = false) const; 94 | void error(tchar const * msg, bool throw_flag = false) const; 95 | 96 | /** 97 | * This method is used to output log4cplus internal warning 98 | * statements. There is no way to disable warning statements. 99 | * Output goes to std::cerr. 100 | */ 101 | void warn(const log4cplus::tstring& msg) const; 102 | void warn(tchar const * msg) const; 103 | 104 | // Public ctor and dtor to be used only by internal::DefaultContext. 105 | LogLog(); 106 | virtual ~LogLog(); 107 | 108 | private: 109 | enum TriState 110 | { 111 | TriUndef = -1, 112 | TriFalse, 113 | TriTrue 114 | }; 115 | 116 | template 117 | LOG4CPLUS_PRIVATE 118 | void logging_worker (tostream & os, 119 | bool (LogLog:: * cond) () const, tchar const *, 120 | StringType const &, bool throw_flag = false) const; 121 | 122 | LOG4CPLUS_PRIVATE static void set_tristate_from_env (TriState *, 123 | tchar const * envvar); 124 | 125 | LOG4CPLUS_PRIVATE bool get_quiet_mode () const; 126 | LOG4CPLUS_PRIVATE bool get_not_quiet_mode () const; 127 | LOG4CPLUS_PRIVATE bool get_debug_mode () const; 128 | 129 | // Data 130 | mutable TriState debugEnabled; 131 | mutable TriState quietMode; 132 | thread::Mutex mutex; 133 | 134 | LOG4CPLUS_PRIVATE LogLog(const LogLog&); 135 | LOG4CPLUS_PRIVATE LogLog & operator = (LogLog const &); 136 | }; 137 | 138 | LOG4CPLUS_EXPORT LogLog & getLogLog (); 139 | 140 | } // end namespace helpers 141 | } // end namespace log4cplus 142 | 143 | 144 | #endif // LOG4CPLUS_HELPERS_LOGLOG 145 | 146 | -------------------------------------------------------------------------------- /include/log4cplus/helpers/logloguser.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: logloguser.h 4 | // Created: 6/2003 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2003-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_HELPERS_LOGLOG_USER 25 | #define LOG4CPLUS_HELPERS_LOGLOG_USER 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | 34 | namespace log4cplus { 35 | namespace helpers { 36 | // forward declarations 37 | class LogLog; 38 | 39 | /** 40 | * This class used to simplify the use of the LogLog class. Any class 41 | * that uses the LogLog class should extend this class and retrieve 42 | * their reference to LogLog using the method provided. 43 | */ 44 | class LOG4CPLUS_EXPORT LogLogUser 45 | { 46 | public: 47 | // ctor and dtor 48 | LogLogUser(); 49 | LogLogUser(const LogLogUser&); 50 | virtual ~LogLogUser(); 51 | 52 | // public methods 53 | LogLog& getLogLog() const; 54 | 55 | // operators 56 | LogLogUser& operator=(const LogLogUser& rhs); 57 | }; 58 | 59 | } // end namespace helpers 60 | } // end namespace log4cplus 61 | 62 | 63 | #endif // LOG4CPLUS_HELPERS_LOGLOG_USER 64 | 65 | -------------------------------------------------------------------------------- /include/log4cplus/helpers/sleep.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: sleep.h 4 | // Created: 5/2003 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2003-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_HELPERS_SLEEP_HEADER_ 25 | #define LOG4CPLUS_HELPERS_SLEEP_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | 34 | namespace log4cplus { 35 | namespace helpers { 36 | LOG4CPLUS_EXPORT void sleep(unsigned long secs, 37 | unsigned long nanosecs = 0); 38 | LOG4CPLUS_EXPORT void sleepmillis(unsigned long millis); 39 | } // end namespace helpers 40 | } // end namespace log4cplus 41 | 42 | #endif // LOG4CPLUS_HELPERS_SLEEP_HEADER_ 43 | 44 | -------------------------------------------------------------------------------- /include/log4cplus/helpers/snprintf.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Copyright (C) 2010-2015, Vaclav Zeman. All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modifica- 5 | // tion, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 15 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 17 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 19 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 20 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #ifndef LOG4CPLUS_HELPERS_SNPRINTF_H 26 | #define LOG4CPLUS_HELPERS_SNPRINTF_H 27 | 28 | #include 29 | 30 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 31 | #pragma once 32 | #endif 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | namespace log4cplus { namespace helpers { 40 | 41 | 42 | class LOG4CPLUS_EXPORT snprintf_buf 43 | { 44 | public: 45 | snprintf_buf (); 46 | 47 | tchar const * print (tchar const * fmt, ...) 48 | LOG4CPLUS_FORMAT_ATTRIBUTE (__printf__, 2, 3); 49 | 50 | int print_va_list (tchar const * & str, tchar const * fmt, std::va_list) 51 | LOG4CPLUS_FORMAT_ATTRIBUTE (__printf__, 3, 0); 52 | 53 | private: 54 | std::vector buf; 55 | }; 56 | 57 | 58 | } } // namespace log4cplus { namespace helpers 59 | 60 | 61 | 62 | #endif // LOG4CPLUS_HELPERS_SNPRINTF_H 63 | -------------------------------------------------------------------------------- /include/log4cplus/helpers/socket.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: socket.h 4 | // Created: 4/2003 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2003-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_HELPERS_SOCKET_HEADER_ 25 | #define LOG4CPLUS_HELPERS_SOCKET_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | #include 35 | 36 | 37 | namespace log4cplus { 38 | namespace helpers { 39 | 40 | enum SocketState { ok, 41 | not_opened, 42 | bad_address, 43 | connection_failed, 44 | broken_pipe, 45 | invalid_access_mode, 46 | message_truncated, 47 | accept_interrupted 48 | }; 49 | 50 | typedef std::ptrdiff_t SOCKET_TYPE; 51 | 52 | extern LOG4CPLUS_EXPORT SOCKET_TYPE const INVALID_SOCKET_VALUE; 53 | 54 | class LOG4CPLUS_EXPORT AbstractSocket { 55 | public: 56 | // ctor and dtor 57 | AbstractSocket(); 58 | AbstractSocket(SOCKET_TYPE sock, SocketState state, int err); 59 | AbstractSocket(const AbstractSocket&); 60 | virtual ~AbstractSocket() = 0; 61 | 62 | // methods 63 | /// Close socket 64 | virtual void close(); 65 | virtual bool isOpen() const; 66 | virtual void shutdown(); 67 | AbstractSocket& operator=(const AbstractSocket& rhs); 68 | 69 | protected: 70 | // Methods 71 | virtual void copy(const AbstractSocket& rhs); 72 | 73 | // Data 74 | SOCKET_TYPE sock; 75 | SocketState state; 76 | int err; 77 | }; 78 | 79 | 80 | 81 | /** 82 | * This class implements client sockets (also called just "sockets"). 83 | * A socket is an endpoint for communication between two machines. 84 | */ 85 | class LOG4CPLUS_EXPORT Socket : public AbstractSocket { 86 | public: 87 | // ctor and dtor 88 | Socket(); 89 | Socket(SOCKET_TYPE sock, SocketState state, int err); 90 | Socket(const tstring& address, unsigned short port, bool udp = false); 91 | virtual ~Socket(); 92 | 93 | // methods 94 | virtual bool read(SocketBuffer& buffer); 95 | virtual bool write(const SocketBuffer& buffer); 96 | virtual bool write(const std::string & buffer); 97 | }; 98 | 99 | 100 | 101 | /** 102 | * This class implements server sockets. A server socket waits for 103 | * requests to come in over the network. It performs some operation 104 | * based on that request, and then possibly returns a result to the 105 | * requester. 106 | */ 107 | class LOG4CPLUS_EXPORT ServerSocket : public AbstractSocket { 108 | public: 109 | // ctor and dtor 110 | ServerSocket(unsigned short port); 111 | virtual ~ServerSocket(); 112 | 113 | Socket accept(); 114 | void interruptAccept (); 115 | 116 | protected: 117 | std::ptrdiff_t interruptHandles[2]; 118 | }; 119 | 120 | 121 | LOG4CPLUS_EXPORT SOCKET_TYPE openSocket(unsigned short port, SocketState& state); 122 | LOG4CPLUS_EXPORT SOCKET_TYPE connectSocket(const log4cplus::tstring& hostn, 123 | unsigned short port, bool udp, 124 | SocketState& state); 125 | LOG4CPLUS_EXPORT SOCKET_TYPE acceptSocket(SOCKET_TYPE sock, SocketState& state); 126 | LOG4CPLUS_EXPORT int closeSocket(SOCKET_TYPE sock); 127 | LOG4CPLUS_EXPORT int shutdownSocket(SOCKET_TYPE sock); 128 | 129 | LOG4CPLUS_EXPORT long read(SOCKET_TYPE sock, SocketBuffer& buffer); 130 | LOG4CPLUS_EXPORT long write(SOCKET_TYPE sock, 131 | const SocketBuffer& buffer); 132 | LOG4CPLUS_EXPORT long write(SOCKET_TYPE sock, 133 | const std::string & buffer); 134 | 135 | LOG4CPLUS_EXPORT tstring getHostname (bool fqdn); 136 | LOG4CPLUS_EXPORT int setTCPNoDelay (SOCKET_TYPE, bool); 137 | 138 | } // end namespace helpers 139 | } // end namespace log4cplus 140 | 141 | #endif // LOG4CPLUS_HELPERS_SOCKET_HEADER_ 142 | -------------------------------------------------------------------------------- /include/log4cplus/helpers/socketbuffer.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: socketbuffer.h 4 | // Created: 5/2003 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2003-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_HELPERS_SOCKET_BUFFER_HEADER_ 25 | #define LOG4CPLUS_HELPERS_SOCKET_BUFFER_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | 35 | 36 | namespace log4cplus { 37 | namespace helpers { 38 | 39 | /** 40 | * 41 | */ 42 | class LOG4CPLUS_EXPORT SocketBuffer 43 | { 44 | public: 45 | explicit SocketBuffer(std::size_t max); 46 | virtual ~SocketBuffer(); 47 | 48 | char *getBuffer() const { return buffer; } 49 | std::size_t getMaxSize() const { return maxsize; } 50 | std::size_t getSize() const { return size; } 51 | void setSize(std::size_t s) { size = s; } 52 | std::size_t getPos() const { return pos; } 53 | 54 | unsigned char readByte(); 55 | unsigned short readShort(); 56 | unsigned int readInt(); 57 | tstring readString(unsigned char sizeOfChar); 58 | 59 | void appendByte(unsigned char val); 60 | void appendShort(unsigned short val); 61 | void appendInt(unsigned int val); 62 | void appendString(const tstring& str); 63 | void appendBuffer(const SocketBuffer& buffer); 64 | 65 | private: 66 | // Data 67 | std::size_t maxsize; 68 | std::size_t size; 69 | std::size_t pos; 70 | char *buffer; 71 | 72 | SocketBuffer(SocketBuffer const & rhs); 73 | SocketBuffer& operator= (SocketBuffer const& rhs); 74 | }; 75 | 76 | } // end namespace helpers 77 | } // end namespace log4cplus 78 | 79 | #endif // LOG4CPLUS_HELPERS_SOCKET_HEADER_ 80 | -------------------------------------------------------------------------------- /include/log4cplus/helpers/thread-config.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: thread-config.h 4 | // Created: 4/2003 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2003-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | /** @file */ 22 | 23 | #ifndef LOG4CPLUS_HELPERS_THREAD_CONFIG_HEADER_ 24 | #define LOG4CPLUS_HELPERS_THREAD_CONFIG_HEADER_ 25 | 26 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 27 | #pragma once 28 | #endif 29 | 30 | #if defined (LOG4CPLUS_USE_PTHREADS) 31 | # if defined (__APPLE__) 32 | # define LOG4CPLUS_USE_NAMED_POSIX_SEMAPHORE 33 | # endif 34 | 35 | #elif defined(LOG4CPLUS_USE_WIN32_THREADS) 36 | # if defined (_WIN32_WINNT) && _WIN32_WINNT >= 0x0600 37 | # define LOG4CPLUS_USE_SRW_LOCK 38 | # else 39 | # define LOG4CPLUS_POOR_MANS_SHAREDMUTEX 40 | # endif 41 | # undef LOG4CPLUS_HAVE_TLS_SUPPORT 42 | # undef LOG4CPLUS_THREAD_LOCAL_VAR 43 | # if defined (_MSC_VER) && _WIN32_WINNT >= 0x0600 44 | // The __declspec(thread) functionality is not compatible with LoadLibrary(). 45 | // For more information why see and "Windows and TLS" note in README. 46 | // . 47 | # define LOG4CPLUS_HAVE_TLS_SUPPORT 1 48 | # define LOG4CPLUS_THREAD_LOCAL_VAR __declspec(thread) 49 | # endif 50 | 51 | #elif defined(LOG4CPLUS_SINGLE_THREADED) 52 | # undef LOG4CPLUS_HAVE_TLS_SUPPORT 53 | # undef LOG4CPLUS_THREAD_LOCAL_VAR 54 | 55 | #else 56 | # error "You Must define a Threading model" 57 | 58 | #endif 59 | 60 | 61 | #endif // LOG4CPLUS_HELPERS_THREAD_CONFIG_HEADER_ 62 | -------------------------------------------------------------------------------- /include/log4cplus/hierarchylocker.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: hierarchylocker.h 4 | // Created: 8/2003 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2003-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_HIERARCHY_LOCKER_HEADER_ 25 | #define LOG4CPLUS_HIERARCHY_LOCKER_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | 38 | namespace log4cplus 39 | { 40 | 41 | class Hierarchy; 42 | 43 | 44 | /** 45 | * This is used to lock a Hierarchy. The dtor unlocks the Hierarchy. 46 | */ 47 | class LOG4CPLUS_EXPORT HierarchyLocker { 48 | public: 49 | // ctor & dtor 50 | HierarchyLocker(Hierarchy& h); 51 | ~HierarchyLocker(); 52 | 53 | /** 54 | * Calls the resetConfiguration() method on the locked Hierarchy. 55 | */ 56 | void resetConfiguration(); 57 | 58 | /** 59 | * Calls the getInstance() method on the locked Hierarchy. 60 | */ 61 | Logger getInstance(const log4cplus::tstring& name); 62 | 63 | /** 64 | * Calls the getInstance() method on the locked Hierarchy. 65 | */ 66 | Logger getInstance(const log4cplus::tstring& name, spi::LoggerFactory& factory); 67 | 68 | void addAppender(Logger &logger, log4cplus::SharedAppenderPtr& appender); 69 | 70 | private: 71 | // Data 72 | Hierarchy& h; 73 | log4cplus::thread::MutexGuard hierarchyLocker; 74 | LoggerList loggerList; 75 | }; 76 | 77 | } // end namespace log4cplus 78 | 79 | #endif // LOG4CPLUS_HIERARCHY_LOCKER_HEADER_ 80 | 81 | -------------------------------------------------------------------------------- /include/log4cplus/internal/cygwin-win32.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: cygwin-win32.h 4 | // Created: 7/2011 5 | // Author: Vaclav Zeman 6 | // 7 | // Copyright (C) 2011-2015, Vaclav Zeman. All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without modifica- 10 | // tion, are permitted provided that the following conditions are met: 11 | // 12 | // 1. Redistributions of source code must retain the above copyright notice, 13 | // this list of conditions and the following disclaimer. 14 | // 15 | // 2. Redistributions in binary form must reproduce the above copyright notice, 16 | // this list of conditions and the following disclaimer in the documentation 17 | // and/or other materials provided with the distribution. 18 | // 19 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 20 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 21 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 23 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 24 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 25 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #if ! defined (LOG4CPLUS_CONFIG_CYGWIN_WIN32_H) 31 | #define LOG4CPLUS_CONFIG_CYGWIN_WIN32_H 32 | 33 | #include 34 | 35 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 36 | #pragma once 37 | #endif 38 | 39 | #if defined (__CYGWIN__) 40 | 41 | #if ! defined (INSIDE_LOG4CPLUS) 42 | # error "This header must not be be used outside log4cplus' implementation files." 43 | #endif 44 | 45 | 46 | namespace log4cplus { namespace cygwin { 47 | 48 | unsigned long get_current_win32_thread_id (); 49 | void output_debug_stringW (wchar_t const *); 50 | 51 | } } // namespace log4cplus { namespace cygwin { 52 | 53 | 54 | #endif // defined (__CYGWIN__) 55 | #endif // LOG4CPLUS_CONFIG_CYGWIN_WIN32_H 56 | -------------------------------------------------------------------------------- /include/log4cplus/internal/env.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: env.h 4 | // Created: 7/2010 5 | // Author: Vaclav Haisman 6 | // 7 | // 8 | // Copyright (C) 2010-2015, Vaclav Haisman. All rights reserved. 9 | // 10 | // Redistribution and use in source and binary forms, with or without modifica- 11 | // tion, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, 14 | // this list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 21 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 22 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 25 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 26 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef LOG4CPLUS_INTERNAL_ENV_H 32 | #define LOG4CPLUS_INTERNAL_ENV_H 33 | 34 | #include 35 | 36 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 37 | #pragma once 38 | #endif 39 | 40 | #include 41 | #include 42 | 43 | #if defined (_WIN32) 44 | #include 45 | #endif 46 | #ifdef LOG4CPLUS_HAVE_SYS_TYPES_H 47 | #include 48 | #endif 49 | #ifdef LOG4CPLUS_HAVE_UNISTD_H 50 | #include 51 | #endif 52 | 53 | 54 | namespace log4cplus { namespace internal { 55 | 56 | 57 | //! Get environment variable value. 58 | bool get_env_var (tstring & value, tstring const & name); 59 | 60 | //! Parse a string as a boolean value. 61 | bool parse_bool (bool & val, tstring const & str); 62 | 63 | //! Parse a path into path components. 64 | bool split_path (std::vector & components, std::size_t & special, 65 | tstring const & path); 66 | 67 | //! Makes directories leading to file. 68 | void make_dirs (tstring const & file_path); 69 | 70 | inline 71 | #if defined (_WIN32) 72 | DWORD 73 | get_process_id () 74 | { 75 | return GetCurrentProcessId (); 76 | } 77 | 78 | #elif defined (LOG4CPLUS_HAVE_GETPID) 79 | pid_t 80 | get_process_id () 81 | { 82 | return getpid (); 83 | } 84 | 85 | #else 86 | int 87 | get_process_id () 88 | { 89 | return 0; 90 | } 91 | 92 | #endif 93 | 94 | 95 | } } // namespace log4cplus { namespace internal { 96 | 97 | 98 | #endif // LOG4CPLUS_INTERNAL_ENV_H 99 | -------------------------------------------------------------------------------- /include/log4cplus/log4judpappender.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: LOG4CPLUS 3 | // File: log4judpappender.h 4 | // Created: 7/2012 5 | // Author: Siva Chandran P 6 | // 7 | // 8 | // Copyright 2012-2015 Siva Chandran P 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_LOG4J_UDP_APPENDER_HEADER_ 25 | #define LOG4CPLUS_LOG4J_UDP_APPENDER_HEADER_ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace log4cplus { 32 | 33 | /** 34 | * Sends log events as Log4j XML to a remote a log server. 35 | * 36 | * The Log4jUdpAppender has the following properties: 37 | * 38 | *
    39 | *
  • Remote logging is non-intrusive as far as the log event 40 | * is concerned. In other words, the event will be logged with 41 | * the same time stamp, NDC, location info as if it were logged 42 | * locally by the client.
  • 43 | * 44 | *
  • Remote logging uses the UDP protocol.
  • 45 | *
46 | * 47 | *

Properties

48 | *
49 | *
host
50 | *
Remote host name to connect and send events to.
51 | * 52 | *
port
53 | *
Port on remote host to send events to.
54 | * 55 | *
56 | */ 57 | class LOG4CPLUS_EXPORT Log4jUdpAppender : public Appender { 58 | public: 59 | // Ctors 60 | Log4jUdpAppender(const log4cplus::tstring& host, int port); 61 | Log4jUdpAppender(const log4cplus::helpers::Properties & properties); 62 | 63 | // Dtor 64 | ~Log4jUdpAppender(); 65 | 66 | // Methods 67 | virtual void close(); 68 | 69 | protected: 70 | void openSocket(); 71 | virtual void append(const spi::InternalLoggingEvent& event); 72 | 73 | // Data 74 | log4cplus::helpers::Socket socket; 75 | log4cplus::tstring host; 76 | int port; 77 | 78 | private: 79 | // Disallow copying of instances of this class 80 | Log4jUdpAppender(const Log4jUdpAppender&); 81 | Log4jUdpAppender& operator=(const Log4jUdpAppender&); 82 | }; 83 | } // end namespace log4cplus 84 | 85 | #endif // LOG4CPLUS_LOG4J_UDP_APPENDER_HEADER_ 86 | 87 | -------------------------------------------------------------------------------- /include/log4cplus/mdc.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Copyright (C) 2010-2015, Vaclav Haisman. All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modifica- 5 | // tion, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 15 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 17 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 19 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 20 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #ifndef LOG4CPLUS_MDC_H_HEADER 26 | #define LOG4CPLUS_MDC_H_HEADER 27 | 28 | #include 29 | 30 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 31 | #pragma once 32 | #endif 33 | 34 | #include 35 | 36 | #include 37 | 38 | 39 | namespace log4cplus 40 | { 41 | 42 | 43 | typedef std::map MappedDiagnosticContextMap; 44 | 45 | 46 | class LOG4CPLUS_EXPORT MDC 47 | { 48 | public: 49 | /** 50 | * Clear any nested diagnostic information if any. This method is 51 | * useful in cases where the same thread can be potentially used 52 | * over and over in different unrelated contexts. 53 | */ 54 | void clear(); 55 | 56 | void put (tstring const & key, tstring const & value); 57 | bool get (tstring * value, tstring const & key) const; 58 | void remove (tstring const & key); 59 | 60 | MappedDiagnosticContextMap const & getContext () const; 61 | 62 | // Public ctor and dtor but only to be used by internal::DefaultContext. 63 | MDC (); 64 | virtual ~MDC (); 65 | 66 | private: 67 | LOG4CPLUS_PRIVATE static MappedDiagnosticContextMap * getPtr (); 68 | }; 69 | 70 | 71 | LOG4CPLUS_EXPORT MDC & getMDC (); 72 | 73 | 74 | } // namespace log4cplus 75 | 76 | 77 | #endif // LOG4CPLUS_MDC_H_HEADER 78 | -------------------------------------------------------------------------------- /include/log4cplus/msttsappender.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4cplus 3 | // File: msttsappender.h 4 | // Created: 10/2012 5 | // Author: Vaclav Zeman 6 | // 7 | // 8 | // Copyright (C) 2012-2015, Vaclav Zeman. All rights reserved. 9 | // 10 | // Redistribution and use in source and binary forms, with or without modifica- 11 | // tion, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, 14 | // this list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 21 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 22 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 25 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 26 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | 32 | // 33 | 34 | /** @file */ 35 | 36 | #ifndef LOG4CPLUS_MSTTSAPPENDER_H 37 | #define LOG4CPLUS_MSTTSAPPENDER_H 38 | 39 | #include 40 | 41 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 42 | #pragma once 43 | #endif 44 | 45 | #include 46 | 47 | 48 | #if defined (_WIN32) 49 | #if defined (log4cplusqt4debugappender_EXPORTS) \ 50 | || defined (log4cplusqt4debugappenderU_EXPORTS) \ 51 | || defined (DLL_EXPORT) 52 | #undef LOG4CPLUS_MSTTSAPPENDER_BUILD_DLL 53 | #define LOG4CPLUS_MSTTSAPPENDER_BUILD_DLL 54 | #endif 55 | #if defined (LOG4CPLUS_MSTTSAPPENDER_BUILD_DLL) 56 | #if defined (INSIDE_LOG4CPLUS_MSTTSAPPENDER) 57 | #define LOG4CPLUS_MSTTSAPPENDER_EXPORT __declspec(dllexport) 58 | #else 59 | #define LOG4CPLUS_MSTTSAPPENDER_EXPORT __declspec(dllimport) 60 | #endif 61 | #else 62 | #define LOG4CPLUS_MSTTSAPPENDER_EXPORT 63 | #endif 64 | #else 65 | #if defined (INSIDE_LOG4CPLUS_MSTTSAPPENDER) 66 | #define LOG4CPLUS_MSTTSAPPENDER_EXPORT LOG4CPLUS_DECLSPEC_EXPORT 67 | #else 68 | #define LOG4CPLUS_MSTTSAPPENDER_EXPORT LOG4CPLUS_DECLSPEC_IMPORT 69 | #endif // defined (INSIDE_LOG4CPLUS_MSTTSAPPENDER) 70 | #endif // !_WIN32 71 | 72 | 73 | namespace log4cplus 74 | { 75 | 76 | 77 | class LOG4CPLUS_MSTTSAPPENDER_EXPORT MSTTSAppender 78 | : public Appender 79 | { 80 | public: 81 | MSTTSAppender (); 82 | explicit MSTTSAppender (helpers::Properties const &); 83 | virtual ~MSTTSAppender (); 84 | 85 | virtual void close (); 86 | 87 | static void registerAppender (); 88 | 89 | protected: 90 | virtual void append (spi::InternalLoggingEvent const &); 91 | 92 | struct Data; 93 | 94 | Data * data; 95 | 96 | private: 97 | LOG4CPLUS_PRIVATE void init (long const * rate = 0, 98 | unsigned long const * volume = 0, bool speak_punc = false, 99 | bool async = false); 100 | 101 | MSTTSAppender (MSTTSAppender const &); 102 | MSTTSAppender & operator = (MSTTSAppender const &); 103 | }; 104 | 105 | 106 | typedef helpers::SharedObjectPtr MSTTSAppenderPtr; 107 | 108 | 109 | } // namespace log4cplus 110 | 111 | 112 | #endif // LOG4CPLUS_MSTTSAPPENDER_H 113 | -------------------------------------------------------------------------------- /include/log4cplus/nteventlogappender.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: nteventlogappender.h 4 | // Created: 4/2003 5 | // Author: Michael CATANZARITI 6 | // 7 | // Copyright 2003-2015 Michael CATANZARITI 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | 21 | /** @file */ 22 | 23 | #ifndef LOG4CPLUS_NT_EVENT_LOG_APPENDER_HEADER_ 24 | #define LOG4CPLUS_NT_EVENT_LOG_APPENDER_HEADER_ 25 | 26 | #include 27 | 28 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 29 | #pragma once 30 | #endif 31 | 32 | #if defined (LOG4CPLUS_HAVE_NT_EVENT_LOG) 33 | 34 | #include 35 | #include 36 | 37 | 38 | namespace log4cplus { 39 | 40 | /** 41 | * Appends log events to NT EventLog. 42 | */ 43 | class LOG4CPLUS_EXPORT NTEventLogAppender : public Appender { 44 | public: 45 | // ctors 46 | NTEventLogAppender(const log4cplus::tstring& server, 47 | const log4cplus::tstring& log, 48 | const log4cplus::tstring& source); 49 | NTEventLogAppender(const log4cplus::helpers::Properties & properties); 50 | 51 | // dtor 52 | virtual ~NTEventLogAppender(); 53 | 54 | // public Methods 55 | virtual void close(); 56 | 57 | protected: 58 | virtual void append(const spi::InternalLoggingEvent& event); 59 | virtual WORD getEventType(const spi::InternalLoggingEvent& event); 60 | virtual WORD getEventCategory(const spi::InternalLoggingEvent& event); 61 | void init(); 62 | 63 | /* 64 | * Add this source with appropriate configuration keys to the registry. 65 | */ 66 | void addRegistryInfo(); 67 | 68 | // Data 69 | log4cplus::tstring server; 70 | log4cplus::tstring log; 71 | log4cplus::tstring source; 72 | HANDLE hEventLog; 73 | SID* pCurrentUserSID; 74 | 75 | private: 76 | // Disallow copying of instances of this class 77 | NTEventLogAppender(const NTEventLogAppender&); 78 | NTEventLogAppender& operator=(const NTEventLogAppender&); 79 | }; 80 | 81 | } // end namespace log4cplus 82 | 83 | #endif // LOG4CPLUS_HAVE_NT_EVENT_LOG 84 | #endif //LOG4CPLUS_NT_EVENT_LOG_APPENDER_HEADER_ 85 | -------------------------------------------------------------------------------- /include/log4cplus/nullappender.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: nullappender.h 4 | // Created: 6/2003 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2003-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_NULL_APPENDER_HEADER_ 25 | #define LOG4CPLUS_NULL_APPENDER_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | 35 | 36 | namespace log4cplus { 37 | 38 | /** 39 | * Appends log events to a file. 40 | */ 41 | class LOG4CPLUS_EXPORT NullAppender : public Appender { 42 | public: 43 | // Ctors 44 | NullAppender(); 45 | NullAppender(const log4cplus::helpers::Properties&); 46 | 47 | // Dtor 48 | virtual ~NullAppender(); 49 | 50 | // Methods 51 | virtual void close(); 52 | 53 | protected: 54 | virtual void append(const log4cplus::spi::InternalLoggingEvent& event); 55 | 56 | private: 57 | // Disallow copying of instances of this class 58 | NullAppender(const NullAppender&); 59 | NullAppender& operator=(const NullAppender&); 60 | }; 61 | 62 | } // end namespace log4cplus 63 | 64 | #endif // LOG4CPLUS_NULL_APPENDER_HEADER_ 65 | 66 | -------------------------------------------------------------------------------- /include/log4cplus/qt4debugappender.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4cplus 3 | // File: qt4debugappender.h 4 | // Created: 5/2012 5 | // Author: Vaclav Zeman 6 | // 7 | // 8 | // Copyright (C) 2012-2015, Vaclav Zeman. All rights reserved. 9 | // 10 | // Redistribution and use in source and binary forms, with or without modifica- 11 | // tion, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, 14 | // this list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 21 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 22 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 25 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 26 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | 32 | // 33 | 34 | /** @file */ 35 | 36 | #ifndef LOG4CPLUS_QT4DEBUGAPPENDER_H 37 | #define LOG4CPLUS_QT4DEBUGAPPENDER_H 38 | 39 | #include 40 | 41 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 42 | #pragma once 43 | #endif 44 | 45 | #include 46 | 47 | #if defined (_WIN32) 48 | #if defined (log4cplusqt4debugappender_EXPORTS) \ 49 | || defined (log4cplusqt4debugappenderU_EXPORTS) \ 50 | || defined (DLL_EXPORT) 51 | #undef LOG4CPLUS_QT4DEBUGAPPENDER_BUILD_DLL 52 | #define LOG4CPLUS_QT4DEBUGAPPENDER_BUILD_DLL 53 | #endif 54 | #if defined (LOG4CPLUS_QT4DEBUGAPPENDER_BUILD_DLL) 55 | #if defined (INSIDE_LOG4CPLUS_QT4DEBUGAPPENDER) 56 | #define LOG4CPLUS_QT4DEBUGAPPENDER_EXPORT __declspec(dllexport) 57 | #else 58 | #define LOG4CPLUS_QT4DEBUGAPPENDER_EXPORT __declspec(dllimport) 59 | #endif 60 | #else 61 | #define LOG4CPLUS_QT4DEBUGAPPENDER_EXPORT 62 | #endif 63 | #else 64 | #if defined (INSIDE_LOG4CPLUS_QT4DEBUGAPPENDER) 65 | #define LOG4CPLUS_QT4DEBUGAPPENDER_EXPORT LOG4CPLUS_DECLSPEC_EXPORT 66 | #else 67 | #define LOG4CPLUS_QT4DEBUGAPPENDER_EXPORT LOG4CPLUS_DECLSPEC_IMPORT 68 | #endif // defined (INSIDE_LOG4CPLUS_QT4DEBUGAPPENDER) 69 | #endif // !_WIN32 70 | 71 | 72 | namespace log4cplus 73 | { 74 | 75 | 76 | class LOG4CPLUS_QT4DEBUGAPPENDER_EXPORT Qt4DebugAppender 77 | : public Appender 78 | { 79 | public: 80 | Qt4DebugAppender (); 81 | explicit Qt4DebugAppender (helpers::Properties const &); 82 | virtual ~Qt4DebugAppender (); 83 | 84 | virtual void close (); 85 | 86 | static void registerAppender (); 87 | 88 | protected: 89 | virtual void append (spi::InternalLoggingEvent const &); 90 | 91 | private: 92 | Qt4DebugAppender (Qt4DebugAppender const &); 93 | Qt4DebugAppender & operator = (Qt4DebugAppender const &); 94 | }; 95 | 96 | 97 | typedef helpers::SharedObjectPtr Qt4DebugAppenderPtr; 98 | 99 | 100 | } // namespace log4cplus 101 | 102 | 103 | #endif // LOG4CPLUS_QT4DEBUGAPPENDER_H 104 | -------------------------------------------------------------------------------- /include/log4cplus/qt5debugappender.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4cplus 3 | // File: qt5debugappender.h 4 | // Created: 4/2013 5 | // Author: Vaclav Zeman 6 | // 7 | // 8 | // Copyright (C) 2013-2015, Vaclav Zeman. All rights reserved. 9 | // 10 | // Redistribution and use in source and binary forms, with or without modifica- 11 | // tion, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, 14 | // this list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 21 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 22 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 25 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 26 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | 32 | // 33 | 34 | /** @file */ 35 | 36 | #ifndef LOG4CPLUS_QT5DEBUGAPPENDER_H 37 | #define LOG4CPLUS_QT5DEBUGAPPENDER_H 38 | 39 | #include 40 | 41 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 42 | #pragma once 43 | #endif 44 | 45 | #include 46 | 47 | #if defined (_WIN32) 48 | #if defined (log4cplusqt5debugappender_EXPORTS) \ 49 | || defined (log4cplusqt5debugappenderU_EXPORTS) \ 50 | || defined (DLL_EXPORT) 51 | #undef LOG4CPLUS_QT5DEBUGAPPENDER_BUILD_DLL 52 | #define LOG4CPLUS_QT5DEBUGAPPENDER_BUILD_DLL 53 | #endif 54 | #if defined (LOG4CPLUS_QT5DEBUGAPPENDER_BUILD_DLL) 55 | #if defined (INSIDE_LOG4CPLUS_QT5DEBUGAPPENDER) 56 | #define LOG4CPLUS_QT5DEBUGAPPENDER_EXPORT __declspec(dllexport) 57 | #else 58 | #define LOG4CPLUS_QT5DEBUGAPPENDER_EXPORT __declspec(dllimport) 59 | #endif 60 | #else 61 | #define LOG4CPLUS_QT5DEBUGAPPENDER_EXPORT 62 | #endif 63 | #else 64 | #if defined (INSIDE_LOG4CPLUS_QT5DEBUGAPPENDER) 65 | #define LOG4CPLUS_QT5DEBUGAPPENDER_EXPORT LOG4CPLUS_DECLSPEC_EXPORT 66 | #else 67 | #define LOG4CPLUS_QT5DEBUGAPPENDER_EXPORT LOG4CPLUS_DECLSPEC_IMPORT 68 | #endif // defined (INSIDE_LOG4CPLUS_QT5DEBUGAPPENDER) 69 | #endif // !_WIN32 70 | 71 | 72 | namespace log4cplus 73 | { 74 | 75 | 76 | class LOG4CPLUS_QT5DEBUGAPPENDER_EXPORT Qt5DebugAppender 77 | : public Appender 78 | { 79 | public: 80 | Qt5DebugAppender (); 81 | explicit Qt5DebugAppender (helpers::Properties const &); 82 | virtual ~Qt5DebugAppender (); 83 | 84 | virtual void close (); 85 | 86 | static void registerAppender (); 87 | 88 | protected: 89 | virtual void append (spi::InternalLoggingEvent const &); 90 | 91 | private: 92 | Qt5DebugAppender (Qt5DebugAppender const &); 93 | Qt5DebugAppender & operator = (Qt5DebugAppender const &); 94 | }; 95 | 96 | 97 | typedef helpers::SharedObjectPtr Qt5DebugAppenderPtr; 98 | 99 | 100 | } // namespace log4cplus 101 | 102 | 103 | #endif // LOG4CPLUS_QT5DEBUGAPPENDER_H 104 | -------------------------------------------------------------------------------- /include/log4cplus/spi/appenderattachable.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: appenderattachable.h 4 | // Created: 6/2001 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2001-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_SPI_APPENDER_ATTACHABLE_HEADER_ 25 | #define LOG4CPLUS_SPI_APPENDER_ATTACHABLE_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | namespace log4cplus { 39 | // Forward Declarations 40 | typedef helpers::SharedObjectPtr SharedAppenderPtr; 41 | typedef std::vector SharedAppenderPtrList; 42 | 43 | namespace spi { 44 | 45 | /** 46 | * This Interface is for attaching Appenders to objects. 47 | */ 48 | class LOG4CPLUS_EXPORT AppenderAttachable { 49 | public: 50 | // Methods 51 | /** 52 | * Add an appender. 53 | */ 54 | virtual void addAppender(SharedAppenderPtr newAppender) = 0; 55 | 56 | /** 57 | * Get all previously added appenders as an Enumeration. 58 | */ 59 | virtual SharedAppenderPtrList getAllAppenders() = 0; 60 | 61 | /** 62 | * Get an appender by name. 63 | */ 64 | virtual SharedAppenderPtr getAppender(const log4cplus::tstring& name) = 0; 65 | 66 | /** 67 | * Remove all previously added appenders. 68 | */ 69 | virtual void removeAllAppenders() = 0; 70 | 71 | /** 72 | * Remove the appender passed as parameter from the list of appenders. 73 | */ 74 | virtual void removeAppender(SharedAppenderPtr appender) = 0; 75 | 76 | /** 77 | * Remove the appender with the name passed as parameter from the 78 | * list of appenders. 79 | */ 80 | virtual void removeAppender(const log4cplus::tstring& name) = 0; 81 | 82 | // Dtor 83 | virtual ~AppenderAttachable() = 0; 84 | }; 85 | 86 | } // end namespace spi 87 | } // end namespace log4cplus 88 | 89 | #endif // LOG4CPLUS_SPI_APPENDER_ATTACHABLE_HEADER_ 90 | 91 | -------------------------------------------------------------------------------- /include/log4cplus/spi/loggerfactory.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: loggerfactory.h 4 | // Created: 6/2001 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2001-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_SPI_LOGGER_FACTORY_HEADER 25 | #define LOG4CPLUS_SPI_LOGGER_FACTORY_HEADER 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | 35 | 36 | namespace log4cplus { 37 | // Forward Declarations 38 | class Logger; 39 | class Hierarchy; 40 | 41 | namespace spi { 42 | /** 43 | * Implement this interface to create new instances of Logger or 44 | * a sub-class of Logger. 45 | */ 46 | class LOG4CPLUS_EXPORT LoggerFactory { 47 | public: 48 | /** 49 | * Creates a new Logger object. 50 | */ 51 | virtual Logger makeNewLoggerInstance(const log4cplus::tstring& name, 52 | Hierarchy& h) = 0; 53 | virtual ~LoggerFactory() = 0; 54 | }; 55 | 56 | } // end namespace spi 57 | } // end namespace log4cplus 58 | 59 | #endif // LOG4CPLUS_SPI_LOGGER_FACTORY_HEADER 60 | 61 | -------------------------------------------------------------------------------- /include/log4cplus/spi/objectregistry.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: objectregistry.h 4 | // Created: 3/2003 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2003-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_SPI_OBJECT_REGISTRY_HEADER_ 25 | #define LOG4CPLUS_SPI_OBJECT_REGISTRY_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | 40 | namespace log4cplus { 41 | namespace spi { 42 | 43 | /** 44 | * This is the base class used to implement the functionality required 45 | * by the ObjectRegistry template class. 46 | */ 47 | class LOG4CPLUS_EXPORT ObjectRegistryBase { 48 | public: 49 | // public methods 50 | /** 51 | * Tests to see whether or not an object is bound in the 52 | * registry as name. 53 | */ 54 | bool exists(const log4cplus::tstring& name) const; 55 | 56 | /** 57 | * Returns the names of all registered objects. 58 | */ 59 | std::vector getAllNames() const; 60 | 61 | //! This function is internal implementation detail. 62 | //! It is related to work-around needed for initialization when 63 | //! using C++11 threads and mutexes. 64 | void _enableLocking (bool); 65 | 66 | protected: 67 | // Ctor and Dtor 68 | ObjectRegistryBase(); 69 | virtual ~ObjectRegistryBase(); 70 | 71 | // protected methods 72 | /** 73 | * Used to enter an object into the registry. (The registry now 74 | * owns object.) 75 | */ 76 | bool putVal(const log4cplus::tstring& name, void* object); 77 | 78 | /** 79 | * Used to retrieve an object from the registry. (The registry 80 | * owns the returned pointer.) 81 | */ 82 | void* getVal(const log4cplus::tstring& name) const; 83 | 84 | /** 85 | * Deletes object. 86 | */ 87 | virtual void deleteObject(void *object) const = 0; 88 | 89 | /** 90 | * Deletes all objects from this registry. 91 | */ 92 | virtual void clear(); 93 | 94 | // Types 95 | typedef std::map ObjectMap; 96 | 97 | // Data 98 | thread::Mutex mutex; 99 | ObjectMap data; 100 | 101 | private: 102 | ObjectRegistryBase (ObjectRegistryBase const &); 103 | ObjectRegistryBase & operator = (ObjectRegistryBase const &); 104 | 105 | bool volatile locking; 106 | }; 107 | 108 | } 109 | } 110 | 111 | 112 | #endif // LOG4CPLUS_SPI_OBJECT_REGISTRY_HEADER_ 113 | 114 | -------------------------------------------------------------------------------- /include/log4cplus/spi/rootlogger.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: rootlogger.h 4 | // Created: 6/2001 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2001-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_SPI_ROOT_LOGGER_HEADER_ 25 | #define LOG4CPLUS_SPI_ROOT_LOGGER_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | 35 | namespace log4cplus { 36 | namespace spi { 37 | 38 | /** 39 | * RootLogger sits at the top of the logger hierachy. It is a 40 | * regular logger except that it provides several guarantees. 41 | * 42 | * First, it cannot be assigned a NOT_SET_LOG_LEVEL 43 | * LogLevel. Second, since root logger cannot have a parent, the 44 | * getChainedLogLevel method always returns the value of the 45 | * ll field without walking the hierarchy. 46 | */ 47 | class LOG4CPLUS_EXPORT RootLogger : public LoggerImpl { 48 | public: 49 | // Ctors 50 | /** 51 | * The root logger names itself as "root". However, the root 52 | * logger cannot be retrieved by name. 53 | */ 54 | RootLogger(Hierarchy& h, LogLevel ll); 55 | 56 | // Methods 57 | /** 58 | * Return the assigned LogLevel value without walking the logger 59 | * hierarchy. 60 | */ 61 | virtual LogLevel getChainedLogLevel() const; 62 | 63 | /** 64 | * Setting a NOT_SET_LOG_LEVEL value to the LogLevel of the root logger 65 | * may have catastrophic results. We prevent this here. 66 | */ 67 | void setLogLevel(LogLevel ll); 68 | 69 | }; 70 | 71 | } // end namespace spi 72 | } // end namespace log4cplus 73 | 74 | #endif // LOG4CPLUS_SPI_ROOT_LOGGER_HEADER_ 75 | 76 | -------------------------------------------------------------------------------- /include/log4cplus/streams.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: streams.h 4 | // Created: 4/2003 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2003-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_STREAMS_HEADER_ 25 | #define LOG4CPLUS_STREAMS_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | 35 | #include 36 | 37 | 38 | namespace log4cplus 39 | { 40 | typedef std::basic_ostream tostream; 41 | typedef std::basic_istream tistream; 42 | typedef std::basic_ostringstream tostringstream; 43 | typedef std::basic_istringstream tistringstream; 44 | extern LOG4CPLUS_EXPORT tostream & tcout; 45 | extern LOG4CPLUS_EXPORT tostream & tcerr; 46 | } 47 | 48 | #if defined (UNICODE) && defined (LOG4CPLUS_ENABLE_GLOBAL_C_STRING_STREAM_INSERTER) 49 | 50 | LOG4CPLUS_EXPORT log4cplus::tostream& operator <<(log4cplus::tostream&, const char* psz ); 51 | 52 | #endif 53 | 54 | #endif // LOG4CPLUS_STREAMS_HEADER_ 55 | 56 | -------------------------------------------------------------------------------- /include/log4cplus/syslogappender.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: syslogappender.h 4 | // Created: 6/2001 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2001-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_SYSLOG_APPENDER_HEADER_ 25 | #define LOG4CPLUS_SYSLOG_APPENDER_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | 38 | namespace log4cplus 39 | { 40 | 41 | /** 42 | * Appends log events to a file. 43 | * 44 | *

Properties

45 | *
46 | *
ident
47 | *
First argument to openlog(), a string that 48 | * will be prepended to every message.
49 | * 50 | *
facility
51 | *
Facility is used in combination with syslog level in first 52 | * argument to syslog(). It can be one of the supported facility 53 | * names (case insensitive), e.g. auth, cron, kern, mail, news 54 | * etc.
55 | * 56 | *
host
57 | *
Destination syslog host. When this property is specified, 58 | * messages are sent using UDP to destination host, otherwise 59 | * messages are logged to local syslog.
60 | * 61 | *
port
62 | *
Destination port of syslog service on host specified by the 63 | * host property. The default value is port 514.
64 | *
65 | * 66 | *
udp
When the syslog is remote, this 67 | * property picks the IP protocol. When the value is true, UDP is 68 | * used. When the value is false, TCP is used. The default value 69 | * is true.
70 | * 71 | * \note Messages sent to remote syslog using UDP are conforming 72 | * to RFC5424. Messages sent to remote syslog using TCP are 73 | * using octet counting as described in RFC6587. 74 | */ 75 | class LOG4CPLUS_EXPORT SysLogAppender 76 | : public Appender 77 | #if ! defined (LOG4CPLUS_SINGLE_THREADED) 78 | , protected virtual helpers::IConnectorThreadClient 79 | #endif 80 | { 81 | public: 82 | //! Remote syslog IP protocol type. 83 | enum RemoteSyslogType 84 | { 85 | RSTUdp, 86 | RSTTcp 87 | }; 88 | 89 | // Ctors 90 | #if defined (LOG4CPLUS_HAVE_SYSLOG_H) 91 | SysLogAppender(const tstring& ident); 92 | #endif 93 | SysLogAppender(const tstring& ident, const tstring & host, 94 | int port = 514, const tstring & facility = tstring (), 95 | RemoteSyslogType remoteSyslogType = RSTUdp); 96 | SysLogAppender(const log4cplus::helpers::Properties & properties); 97 | 98 | // Dtor 99 | virtual ~SysLogAppender(); 100 | 101 | // Methods 102 | virtual void close(); 103 | 104 | protected: 105 | virtual int getSysLogLevel(const LogLevel& ll) const; 106 | virtual void append(const spi::InternalLoggingEvent& event); 107 | #if defined (LOG4CPLUS_HAVE_SYSLOG_H) 108 | //! Local syslog (served by `syslog()`) worker function. 109 | void appendLocal(const spi::InternalLoggingEvent& event); 110 | #endif 111 | //! Remote syslog worker function. 112 | void appendRemote(const spi::InternalLoggingEvent& event); 113 | 114 | // Data 115 | tstring ident; 116 | int facility; 117 | 118 | typedef void (SysLogAppender:: * AppendFuncType) ( 119 | const spi::InternalLoggingEvent&); 120 | AppendFuncType appendFunc; 121 | 122 | tstring host; 123 | int port; 124 | RemoteSyslogType remoteSyslogType; 125 | helpers::Socket syslogSocket; 126 | bool connected; 127 | 128 | static tstring const remoteTimeFormat; 129 | 130 | void initConnector (); 131 | void openSocket (); 132 | 133 | #if ! defined (LOG4CPLUS_SINGLE_THREADED) 134 | virtual thread::Mutex const & ctcGetAccessMutex () const; 135 | virtual helpers::Socket & ctcGetSocket (); 136 | virtual helpers::Socket ctcConnect (); 137 | virtual void ctcSetConnected (); 138 | 139 | helpers::SharedObjectPtr connector; 140 | #endif 141 | 142 | private: 143 | // Disallow copying of instances of this class 144 | SysLogAppender(const SysLogAppender&); 145 | SysLogAppender& operator=(const SysLogAppender&); 146 | 147 | std::string identStr; 148 | tstring hostname; 149 | }; 150 | 151 | } // end namespace log4cplus 152 | 153 | 154 | #endif // LOG4CPLUS_SYSLOG_APPENDER_HEADER_ 155 | -------------------------------------------------------------------------------- /include/log4cplus/tchar.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Copyright (C) 2010-2015, Vaclav Haisman. All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modifica- 5 | // tion, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 15 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 17 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 19 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 20 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | /** @file */ 26 | 27 | #ifndef LOG4CPLUS_TCHAR_HEADER_ 28 | #define LOG4CPLUS_TCHAR_HEADER_ 29 | 30 | #include 31 | 32 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 33 | #pragma once 34 | #endif 35 | 36 | #if defined (_WIN32) 37 | #include 38 | #endif 39 | 40 | 41 | #ifdef UNICODE 42 | # define LOG4CPLUS_TEXT2(STRING) L##STRING 43 | #else 44 | # define LOG4CPLUS_TEXT2(STRING) STRING 45 | #endif // UNICODE 46 | #define LOG4CPLUS_TEXT(STRING) LOG4CPLUS_TEXT2(STRING) 47 | 48 | 49 | namespace log4cplus 50 | { 51 | 52 | #if defined (UNICODE) 53 | typedef wchar_t tchar; 54 | 55 | #else 56 | typedef char tchar; 57 | 58 | #endif 59 | 60 | } // namespace log4cplus 61 | 62 | 63 | #endif // LOG4CPLUS_TCHAR_HEADER_ 64 | -------------------------------------------------------------------------------- /include/log4cplus/thread/impl/syncprims-pmsm.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Copyright (C) 2010-2015, Vaclav Haisman. All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modifica- 5 | // tion, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 15 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 17 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 19 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 20 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | //! @file 26 | //! This file contains implementations of reader-writer locking 27 | //! primitive using other primitives, IOW poor man's rwlock. 28 | //! It does not contain any include guards because it is only a fragment 29 | //! to be included by syncprims-{pthreads,win32}.h. 30 | 31 | 32 | #if ! defined (INSIDE_LOG4CPLUS) 33 | # error "This header must not be be used outside log4cplus' implementation files." 34 | #endif 35 | 36 | 37 | // This implements algorithm described in "Concurrent Control with "Readers" 38 | // and "Writers"; P.J. Courtois, F. Heymans, and D.L. Parnas; 39 | // MBLE Research Laboratory; Brussels, Belgium" 40 | 41 | 42 | inline 43 | SharedMutex::SharedMutex () 44 | : m1 (log4cplus::thread::Mutex::DEFAULT) 45 | , m2 (log4cplus::thread::Mutex::DEFAULT) 46 | , m3 (log4cplus::thread::Mutex::DEFAULT) 47 | , w (1, 1) 48 | , writer_count (0) 49 | , r (1, 1) 50 | , reader_count (0) 51 | { } 52 | 53 | 54 | inline 55 | SharedMutex::~SharedMutex () 56 | { } 57 | 58 | 59 | inline 60 | void 61 | SharedMutex::rdlock () const 62 | { 63 | MutexGuard m3_guard (m3); 64 | SemaphoreGuard r_guard (r); 65 | MutexGuard m1_guard (m1); 66 | if (reader_count + 1 == 1) 67 | w.lock (); 68 | 69 | reader_count += 1; 70 | } 71 | 72 | 73 | inline 74 | void 75 | SharedMutex::rdunlock () const 76 | { 77 | MutexGuard m1_guard (m1); 78 | if (reader_count - 1 == 0) 79 | w.unlock (); 80 | 81 | reader_count -= 1; 82 | } 83 | 84 | 85 | inline 86 | void 87 | SharedMutex::wrlock () const 88 | { 89 | { 90 | MutexGuard m2_guard (m2); 91 | if (writer_count + 1 == 1) 92 | r.lock (); 93 | 94 | writer_count += 1; 95 | } 96 | try 97 | { 98 | w.lock (); 99 | } 100 | catch (...) 101 | { 102 | MutexGuard m2_guard (m2); 103 | writer_count -= 1; 104 | throw; 105 | } 106 | } 107 | 108 | 109 | inline 110 | void 111 | SharedMutex::wrunlock () const 112 | { 113 | w.unlock (); 114 | MutexGuard m2_guard (m2); 115 | if (writer_count - 1 == 0) 116 | r.unlock (); 117 | 118 | writer_count -= 1; 119 | } 120 | -------------------------------------------------------------------------------- /include/log4cplus/thread/impl/threads-impl.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: threads.h 4 | // Created: 6/2001 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2001-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_IMPL_THREADS_IMPL_HEADER_ 25 | #define LOG4CPLUS_IMPL_THREADS_IMPL_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #if defined (_WIN32) 34 | #include 35 | #endif 36 | #include 37 | #include 38 | #include 39 | 40 | #if ! defined (INSIDE_LOG4CPLUS) 41 | # error "This header must not be be used outside log4cplus' implementation files." 42 | #endif 43 | 44 | 45 | namespace log4cplus { namespace thread { namespace impl { 46 | 47 | 48 | #if defined (LOG4CPLUS_USE_PTHREADS) 49 | 50 | typedef pthread_t os_handle_type; 51 | typedef pthread_t os_id_type; 52 | 53 | 54 | inline 55 | pthread_t 56 | getCurrentThreadId () 57 | { 58 | return pthread_self (); 59 | } 60 | 61 | 62 | #elif defined (LOG4CPLUS_USE_WIN32_THREADS) 63 | 64 | typedef HANDLE os_handle_type; 65 | typedef DWORD os_id_type; 66 | 67 | 68 | inline 69 | DWORD 70 | getCurrentThreadId () 71 | { 72 | return GetCurrentThreadId (); 73 | } 74 | 75 | 76 | #elif defined (LOG4CPLUS_SINGLE_THREADED) 77 | 78 | typedef void * os_handle_type; 79 | typedef int os_id_type; 80 | 81 | 82 | inline 83 | int 84 | getCurrentThreadId () 85 | { 86 | return 1; 87 | } 88 | 89 | 90 | #endif 91 | 92 | 93 | #ifndef LOG4CPLUS_SINGLE_THREADED 94 | 95 | 96 | struct ThreadStart 97 | { 98 | # ifdef LOG4CPLUS_USE_PTHREADS 99 | static void* threadStartFuncWorker(void *); 100 | # elif defined(LOG4CPLUS_USE_WIN32_THREADS) 101 | static unsigned threadStartFuncWorker(void *); 102 | # endif 103 | }; 104 | 105 | 106 | /** 107 | * There are many cross-platform C++ Threading libraries. The goal of 108 | * this class is not to replace (or match in functionality) those 109 | * libraries. The goal of this class is to provide a simple Threading 110 | * class with basic functionality. 111 | */ 112 | class Thread 113 | : public ThreadImplBase 114 | { 115 | public: 116 | Thread(); 117 | bool isRunning() const; 118 | os_id_type getThreadId() const; 119 | os_handle_type getThreadHandle () const; 120 | void start(); 121 | void join (); 122 | 123 | protected: 124 | // Force objects to be constructed on the heap 125 | virtual ~Thread(); 126 | virtual void run() = 0; 127 | 128 | private: 129 | // Friends. 130 | friend struct ThreadStart; 131 | 132 | enum Flags 133 | { 134 | fRUNNING = 0x01, 135 | fJOINED = 0x02 136 | }; 137 | 138 | unsigned flags; 139 | 140 | os_handle_type handle; 141 | 142 | # if defined(LOG4CPLUS_USE_WIN32_THREADS) 143 | unsigned thread_id; 144 | # endif 145 | 146 | // Disallow copying of instances of this class. 147 | Thread(const Thread&); 148 | Thread& operator=(const Thread&); 149 | }; 150 | 151 | typedef helpers::SharedObjectPtr ThreadPtr; 152 | 153 | 154 | #endif // LOG4CPLUS_SINGLE_THREADED 155 | 156 | 157 | } } } // namespace log4cplus { namespace thread { namespace impl { 158 | 159 | 160 | #endif // LOG4CPLUS_IMPL_THREADS_IMPL_HEADER_ 161 | -------------------------------------------------------------------------------- /include/log4cplus/thread/impl/tls.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Copyright (C) 2010-2015, Vaclav Haisman. All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modifica- 5 | // tion, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 15 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 17 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 19 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 20 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #ifndef LOG4CPLUS_THREAD_IMPL_TLS_H 26 | #define LOG4CPLUS_THREAD_IMPL_TLS_H 27 | 28 | #include 29 | 30 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 31 | #pragma once 32 | #endif 33 | 34 | #include 35 | #include 36 | 37 | #if ! defined (INSIDE_LOG4CPLUS) 38 | # error "This header must not be be used outside log4cplus' implementation files." 39 | #endif 40 | 41 | #ifdef LOG4CPLUS_USE_PTHREADS 42 | # include 43 | 44 | #elif defined (LOG4CPLUS_USE_WIN32_THREADS) 45 | # include 46 | 47 | #elif defined (LOG4CPLUS_SINGLE_THREADED) 48 | # include 49 | 50 | #endif 51 | 52 | 53 | namespace log4cplus { namespace thread { namespace impl { 54 | 55 | 56 | typedef void * tls_value_type; 57 | typedef void (* tls_init_cleanup_func_type)(void *); 58 | 59 | #ifdef LOG4CPLUS_USE_PTHREADS 60 | typedef pthread_key_t * tls_key_type; 61 | 62 | #elif defined (LOG4CPLUS_USE_WIN32_THREADS) 63 | typedef DWORD tls_key_type; 64 | 65 | #elif defined (LOG4CPLUS_SINGLE_THREADED) 66 | typedef std::size_t tls_key_type; 67 | 68 | #endif 69 | 70 | 71 | inline tls_key_type tls_init (tls_init_cleanup_func_type); 72 | inline tls_value_type tls_get_value (tls_key_type); 73 | inline void tls_set_value (tls_key_type, tls_value_type); 74 | inline void tls_cleanup (tls_key_type); 75 | 76 | 77 | #if defined (LOG4CPLUS_USE_PTHREADS) 78 | tls_key_type 79 | tls_init (tls_init_cleanup_func_type cleanupfunc) 80 | { 81 | pthread_key_t * key = new pthread_key_t; 82 | pthread_key_create (key, cleanupfunc); 83 | return key; 84 | } 85 | 86 | 87 | tls_value_type 88 | tls_get_value (tls_key_type key) 89 | { 90 | return pthread_getspecific (*key); 91 | } 92 | 93 | 94 | void 95 | tls_set_value (tls_key_type key, tls_value_type value) 96 | { 97 | pthread_setspecific(*key, value); 98 | } 99 | 100 | 101 | void 102 | tls_cleanup (tls_key_type key) 103 | { 104 | pthread_key_delete (*key); 105 | delete key; 106 | } 107 | 108 | 109 | #elif defined (LOG4CPLUS_USE_WIN32_THREADS) 110 | tls_key_type 111 | tls_init (tls_init_cleanup_func_type) 112 | { 113 | return TlsAlloc (); 114 | } 115 | 116 | 117 | tls_value_type tls_get_value (tls_key_type k) 118 | { 119 | return TlsGetValue (k); 120 | } 121 | 122 | 123 | void 124 | tls_set_value (tls_key_type k, tls_value_type value) 125 | { 126 | TlsSetValue (k, value); 127 | } 128 | 129 | 130 | void 131 | tls_cleanup (tls_key_type k) 132 | { 133 | TlsFree (k); 134 | } 135 | 136 | 137 | #elif defined (LOG4CPLUS_SINGLE_THREADED) 138 | extern std::vector * tls_single_threaded_values; 139 | 140 | 141 | tls_key_type 142 | tls_init (tls_init_cleanup_func_type) 143 | { 144 | if (! tls_single_threaded_values) 145 | tls_single_threaded_values = new std::vector; 146 | tls_key_type key = tls_single_threaded_values->size (); 147 | tls_single_threaded_values->resize (key + 1); 148 | return key; 149 | } 150 | 151 | 152 | tls_value_type 153 | tls_get_value (tls_key_type k) 154 | { 155 | assert (k < tls_single_threaded_values->size ()); 156 | return (*tls_single_threaded_values)[k]; 157 | } 158 | 159 | 160 | void 161 | tls_set_value (tls_key_type k, tls_value_type val) 162 | { 163 | assert (k < tls_single_threaded_values->size ()); 164 | (*tls_single_threaded_values)[k] = val; 165 | } 166 | 167 | 168 | void 169 | tls_cleanup (tls_key_type k) 170 | { 171 | assert (k < tls_single_threaded_values->size ()); 172 | (*tls_single_threaded_values)[k] = 0; 173 | } 174 | 175 | #endif 176 | 177 | 178 | } } } // namespace log4cplus { namespace thread { namespace impl { 179 | 180 | #endif // LOG4CPLUS_THREAD_IMPL_TLS_H 181 | -------------------------------------------------------------------------------- /include/log4cplus/thread/threads.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: threads.h 4 | // Created: 6/2001 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2001-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_THREADS_HEADER_ 25 | #define LOG4CPLUS_THREADS_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | #include 35 | 36 | 37 | namespace log4cplus { namespace thread { 38 | 39 | 40 | LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName(); 41 | LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName2(); 42 | LOG4CPLUS_EXPORT void setCurrentThreadName(const log4cplus::tstring & name); 43 | LOG4CPLUS_EXPORT void setCurrentThreadName2(const log4cplus::tstring & name); 44 | LOG4CPLUS_EXPORT void yield(); 45 | LOG4CPLUS_EXPORT void blockAllSignals(); 46 | 47 | 48 | #ifndef LOG4CPLUS_SINGLE_THREADED 49 | 50 | class ThreadImplBase 51 | : public virtual log4cplus::helpers::SharedObject 52 | { 53 | protected: 54 | virtual ~ThreadImplBase (); 55 | }; 56 | 57 | 58 | /** 59 | * There are many cross-platform C++ Threading libraries. The goal of 60 | * this class is not to replace (or match in functionality) those 61 | * libraries. The goal of this class is to provide a simple Threading 62 | * class with basic functionality. 63 | */ 64 | class LOG4CPLUS_EXPORT AbstractThread 65 | : public virtual log4cplus::helpers::SharedObject 66 | { 67 | public: 68 | AbstractThread(); 69 | bool isRunning() const; 70 | virtual void start(); 71 | void join () const; 72 | virtual void run() = 0; 73 | 74 | protected: 75 | // Force objects to be constructed on the heap 76 | virtual ~AbstractThread(); 77 | 78 | private: 79 | helpers::SharedObjectPtr thread; 80 | 81 | // Disallow copying of instances of this class. 82 | AbstractThread(const AbstractThread&); 83 | AbstractThread& operator=(const AbstractThread&); 84 | }; 85 | 86 | typedef helpers::SharedObjectPtr AbstractThreadPtr; 87 | 88 | 89 | #endif // LOG4CPLUS_SINGLE_THREADED 90 | 91 | 92 | } } // namespace log4cplus { namespace thread { 93 | 94 | 95 | #endif // LOG4CPLUS_THREADS_HEADER_ 96 | 97 | -------------------------------------------------------------------------------- /include/log4cplus/tracelogger.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: tracelogger.h 4 | // Created: 1/2009 5 | // Author: Vaclav Haisman 6 | // 7 | // 8 | // Copyright 2009-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_TRACELOGGER_H 25 | #define LOG4CPLUS_TRACELOGGER_H 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | 35 | 36 | namespace log4cplus 37 | { 38 | 39 | 40 | /** 41 | * This class is used to produce "Trace" logging. When an instance of 42 | * this class is created, it will log a "ENTER: " + msg 43 | * log message if TRACE_LOG_LEVEL is enabled for logger. 44 | * When an instance of this class is destroyed, it will log a 45 | * "ENTER: " + msg log message if TRACE_LOG_LEVEL is enabled 46 | * for logger. 47 | *

48 | * @see LOG4CPLUS_TRACE 49 | */ 50 | class TraceLogger 51 | { 52 | public: 53 | TraceLogger(const Logger& l, const log4cplus::tstring& _msg, 54 | const char* _file = LOG4CPLUS_CALLER_FILE (), 55 | int _line = LOG4CPLUS_CALLER_LINE (), 56 | char const * _function = LOG4CPLUS_CALLER_FUNCTION ()) 57 | : logger(l), msg(_msg), file(_file), function(_function), line(_line) 58 | { 59 | if(logger.isEnabledFor(TRACE_LOG_LEVEL)) 60 | logger.forcedLog(TRACE_LOG_LEVEL, LOG4CPLUS_TEXT("ENTER: ") + msg, 61 | file, line, function); 62 | } 63 | 64 | ~TraceLogger() 65 | { 66 | if(logger.isEnabledFor(TRACE_LOG_LEVEL)) 67 | logger.forcedLog(TRACE_LOG_LEVEL, LOG4CPLUS_TEXT("EXIT: ") + msg, 68 | file, line, function); 69 | } 70 | 71 | private: 72 | TraceLogger (TraceLogger const &); 73 | TraceLogger & operator = (TraceLogger const &); 74 | 75 | Logger logger; 76 | log4cplus::tstring msg; 77 | const char* file; 78 | const char* function; 79 | int line; 80 | }; 81 | 82 | 83 | } // log4cplus 84 | 85 | 86 | #endif // LOG4CPLUS_TRACELOGGER_H 87 | -------------------------------------------------------------------------------- /include/log4cplus/tstring.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: tstring.h 4 | // Created: 4/2003 5 | // Author: Tad E. Smith 6 | // 7 | // 8 | // Copyright 2003-2015 Tad E. Smith 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_TSTRING_HEADER_ 25 | #define LOG4CPLUS_TSTRING_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #include 34 | #include 35 | 36 | namespace log4cplus 37 | { 38 | 39 | typedef std::basic_string tstring; 40 | 41 | 42 | namespace helpers 43 | { 44 | 45 | inline 46 | std::string 47 | tostring (char const * str) 48 | { 49 | return std::string (str); 50 | } 51 | 52 | inline 53 | std::string 54 | tostring (std::string const & str) 55 | { 56 | return str; 57 | } 58 | 59 | inline 60 | std::string const & 61 | tostring (std::string & str) 62 | { 63 | return str; 64 | } 65 | 66 | #ifdef LOG4CPLUS_HAVE_RVALUE_REFS 67 | inline 68 | std::string 69 | tostring (std::string && str) 70 | { 71 | return std::move (str); 72 | } 73 | 74 | #endif 75 | 76 | 77 | 78 | inline 79 | std::wstring 80 | towstring (wchar_t const * str) 81 | { 82 | return std::wstring (str); 83 | } 84 | 85 | inline 86 | std::wstring 87 | towstring (std::wstring const & str) 88 | { 89 | return str; 90 | } 91 | 92 | inline 93 | std::wstring const & 94 | towstring (std::wstring & str) 95 | { 96 | return str; 97 | } 98 | 99 | #ifdef LOG4CPLUS_HAVE_RVALUE_REFS 100 | inline 101 | std::wstring 102 | towstring (std::wstring && str) 103 | { 104 | return std::move (str); 105 | } 106 | 107 | #endif 108 | 109 | LOG4CPLUS_EXPORT std::string tostring(const std::wstring&); 110 | LOG4CPLUS_EXPORT std::string tostring(wchar_t const *); 111 | 112 | LOG4CPLUS_EXPORT std::wstring towstring(const std::string&); 113 | LOG4CPLUS_EXPORT std::wstring towstring(char const *); 114 | 115 | } // namespace helpers 116 | 117 | #ifdef UNICODE 118 | 119 | #define LOG4CPLUS_C_STR_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING) 120 | #define LOG4CPLUS_STRING_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING) 121 | #define LOG4CPLUS_TSTRING_TO_STRING(STRING) log4cplus::helpers::tostring(STRING) 122 | 123 | #else // UNICODE 124 | 125 | #define LOG4CPLUS_C_STR_TO_TSTRING(STRING) (std::string(STRING)) 126 | #define LOG4CPLUS_STRING_TO_TSTRING(STRING) STRING 127 | #define LOG4CPLUS_TSTRING_TO_STRING(STRING) STRING 128 | 129 | #endif // UNICODE 130 | 131 | } // namespace log4cplus 132 | 133 | 134 | #endif // LOG4CPLUS_TSTRING_HEADER_ 135 | -------------------------------------------------------------------------------- /include/log4cplus/version.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Copyright (C) 2010-2015, Vaclav Haisman. All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modifica- 5 | // tion, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 15 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 17 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 19 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 20 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | 26 | #if ! defined (LOG4CPLUS_VERSION_H) 27 | #define LOG4CPLUS_VERSION_H 28 | 29 | #include 30 | 31 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 32 | #pragma once 33 | #endif 34 | 35 | #define LOG4CPLUS_MAKE_VERSION(major, minor, point) \ 36 | (major * 1000 * 1000u + minor * 1000u + point) 37 | 38 | #define LOG4CPLUS_MAKE_VERSION_STR(major, minor, point) \ 39 | #major "." #minor "." #point 40 | 41 | //! This is log4cplus version number as unsigned integer. This must 42 | //! be kept on a single line. It is used by Autotool and CMake build 43 | //! systems to parse version number. 44 | #define LOG4CPLUS_VERSION LOG4CPLUS_MAKE_VERSION(1, 2, 0) 45 | 46 | //! This is log4cplus version number as a string. 47 | #define LOG4CPLUS_VERSION_STR LOG4CPLUS_MAKE_VERSION_STR(1, 2, 0) 48 | 49 | 50 | namespace log4cplus 51 | { 52 | 53 | extern LOG4CPLUS_EXPORT unsigned const version; 54 | extern LOG4CPLUS_EXPORT char const versionStr[]; 55 | 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/log4cplus/win32consoleappender.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Copyright (C) 2009-2015, Vaclav Haisman. All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modifica- 5 | // tion, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 15 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 17 | // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 19 | // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 20 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #ifndef LOG4CPLUS_WIN32CONSOLEAPPENDER_H 26 | #define LOG4CPLUS_WIN32CONSOLEAPPENDER_H 27 | 28 | #include 29 | 30 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 31 | #pragma once 32 | #endif 33 | 34 | #if defined(_WIN32) && defined (LOG4CPLUS_HAVE_WIN32_CONSOLE) 35 | 36 | #include 37 | 38 | 39 | namespace log4cplus 40 | { 41 | 42 | /** 43 | * Prints events to Win32 console. 44 | * 45 | *

Properties

46 | *
47 | *
AllocConsole
48 | *
This boolean property specifies whether or not this appender 49 | * will try to allocate new console using the 50 | * AllocConsole() Win32 function.
51 | * 52 | *
logToStdErr
53 | *
When it is set true, the output will be into 54 | * STD_ERROR_HANDLE instead of STD_OUTPUT_HANDLE. 55 | *
56 | * 57 | *
TextColor
58 | *
See MSDN documentation for 59 | * 60 | * Character Attributes. 61 | *
62 | */ 63 | class LOG4CPLUS_EXPORT Win32ConsoleAppender 64 | : public Appender 65 | { 66 | public: 67 | explicit Win32ConsoleAppender (bool allocConsole = true, 68 | bool logToStdErr = false, unsigned int textColor = 0); 69 | Win32ConsoleAppender (helpers::Properties const & properties); 70 | virtual ~Win32ConsoleAppender (); 71 | 72 | virtual void close (); 73 | 74 | protected: 75 | virtual void append (spi::InternalLoggingEvent const &); 76 | 77 | void write_handle (void *, tchar const *, std::size_t); 78 | void write_console (void *, tchar const *, std::size_t); 79 | 80 | bool alloc_console; 81 | bool log_to_std_err; 82 | unsigned int text_color; 83 | 84 | private: 85 | Win32ConsoleAppender (Win32ConsoleAppender const &); 86 | Win32ConsoleAppender & operator = (Win32ConsoleAppender const &); 87 | }; 88 | 89 | } // namespace log4cplus 90 | 91 | #endif 92 | 93 | #endif // LOG4CPLUS_WIN32CONSOLEAPPENDER_H 94 | -------------------------------------------------------------------------------- /include/log4cplus/win32debugappender.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Module: Log4CPLUS 3 | // File: win32debugappender.h 4 | // Created: 12/2003 5 | // Author: Eduardo Francos, Odalio SARL 6 | // 7 | // 8 | // Copyright 2003-2015 Odalio SARL 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | 22 | /** @file */ 23 | 24 | #ifndef LOG4CPLUS_WIN32DEBUG_APPENDER_HEADER_ 25 | #define LOG4CPLUS_WIN32DEBUG_APPENDER_HEADER_ 26 | 27 | #include 28 | 29 | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 | #pragma once 31 | #endif 32 | 33 | #if defined (LOG4CPLUS_HAVE_OUTPUTDEBUGSTRING) 34 | 35 | #include 36 | 37 | 38 | namespace log4cplus { 39 | 40 | /** 41 | * Prints log events using OutputDebugString(). 42 | */ 43 | class LOG4CPLUS_EXPORT Win32DebugAppender 44 | : public Appender 45 | { 46 | public: 47 | // Ctors 48 | Win32DebugAppender(); 49 | Win32DebugAppender(const log4cplus::helpers::Properties& properties); 50 | 51 | // Dtor 52 | virtual ~Win32DebugAppender(); 53 | 54 | // Methods 55 | virtual void close(); 56 | 57 | protected: 58 | virtual void append(const log4cplus::spi::InternalLoggingEvent& event); 59 | 60 | private: 61 | // Disallow copying of instances of this class 62 | Win32DebugAppender(const Win32DebugAppender&); 63 | Win32DebugAppender& operator=(const Win32DebugAppender&); 64 | }; 65 | 66 | } // end namespace log4cplus 67 | 68 | #endif // LOG4CPLUS_HAVE_OUTPUTDEBUGSTRING 69 | #endif // LOG4CPLUS_WIN32DEBUG_APPENDER_HEADER_ 70 | -------------------------------------------------------------------------------- /ipch/tcpcmdtransfer-7c645831/tcpcmdtransfer-49b855b.ipch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/ipch/tcpcmdtransfer-7c645831/tcpcmdtransfer-49b855b.ipch -------------------------------------------------------------------------------- /log4cplus.properties: -------------------------------------------------------------------------------- 1 | log4cplus.rootLogger=WARN,STDOUT,R 2 | 3 | log4cplus.appender.R=log4cplus::RollingFileAppender 4 | log4cplus.appender.R.MaxFileSize=20MB 5 | log4cplus.appender.R.immediateFlush=true 6 | log4cplus.appender.R.File=logs\app.log 7 | log4cplus.appender.R.layout=log4cplus::PatternLayout 8 | log4cplus.appender.R.layout.ConversionPattern=[%D{%y-%m-%d %H:%M:%S.%q}] %m%n 9 | 10 | log4cplus.appender.STDOUT=log4cplus::ConsoleAppender 11 | log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout 12 | log4cplus.appender.STDOUT.layout.ConversionPattern=[%D{%y-%m-%d %H:%M:%S.%q}] %m%n -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/main.cpp -------------------------------------------------------------------------------- /nochangetranslator.cpp: -------------------------------------------------------------------------------- 1 | #include "nochangetranslator.h" 2 | #include "utils.h" 3 | #include 4 | 5 | NoChangeTranslator::NoChangeTranslator(const int iDirection) 6 | : CmdTranslator(iDirection) 7 | { 8 | 9 | } 10 | 11 | 12 | 13 | QByteArray &NoChangeTranslator::toDevCmd(QByteArray &aDevCmd, const QByteArray &aSrcCmd) 14 | { 15 | Utils::logCmd(Const::APP_TO_DEV, aSrcCmd); 16 | aDevCmd = aSrcCmd; 17 | aDevCmd.push_front(QByteArray(Const::FRAME_START_FLAG, Const::CMD_FRAME_START_FLAG_SIZE)); 18 | return aDevCmd; 19 | } 20 | 21 | QByteArray &NoChangeTranslator::fromDevCmd(QByteArray &aDestCmd, const QByteArray &aDevCmd) 22 | { 23 | Utils::logCmd(Const::TRANSLATE_TO_APP, aDevCmd); 24 | aDestCmd = aDevCmd; 25 | aDestCmd.push_front(QByteArray(Const::FRAME_START_FLAG, Const::CMD_FRAME_START_FLAG_SIZE)); 26 | return aDestCmd; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /nochangetranslator.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/nochangetranslator.h -------------------------------------------------------------------------------- /phonecmdrecv.cpp: -------------------------------------------------------------------------------- 1 | #include "phonecmdrecv.h" 2 | #include "utils.h" 3 | 4 | static const int MAX_PHONE_CMD_SIZE = 300; 5 | static char phoneCmdBuffer[MAX_PHONE_CMD_SIZE]; 6 | 7 | PhoneCmdRecv::PhoneCmdRecv( CmdFactory *pCmdFactory, QUdpSocket *pUdpSocket ) : UDPCmdRecv(pCmdFactory, pUdpSocket) 8 | { 9 | 10 | } 11 | 12 | void PhoneCmdRecv::createCmd() 13 | { 14 | QHostAddress senderAddr; 15 | quint16 senderPort = 0; 16 | memset(phoneCmdBuffer, 0, MAX_PHONE_CMD_SIZE); 17 | qint64 bytesRead = m_pUdpSocket->readDatagram(phoneCmdBuffer, MAX_PHONE_CMD_SIZE, &senderAddr, &senderPort); 18 | if(bytesRead <= 0) 19 | return; 20 | QByteArray aPhoneCmd(phoneCmdBuffer, bytesRead); 21 | quint32 devId = Utils::getDevIdFromCmd(aPhoneCmd); 22 | m_pCmdFactory->createFromAppCmd(devId, aPhoneCmd, senderAddr, senderPort); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /phonecmdrecv.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/phonecmdrecv.h -------------------------------------------------------------------------------- /platformcmdrecv.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/platformcmdrecv.cpp -------------------------------------------------------------------------------- /platformcmdrecv.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/platformcmdrecv.h -------------------------------------------------------------------------------- /platformtodevhandler.cpp: -------------------------------------------------------------------------------- 1 | #include "platformtodevhandler.h" 2 | #include "utils.h" 3 | #include "platformtranslator.h" 4 | #include "alarmdev.h" 5 | #include "const.h" 6 | #include "crc16.h" 7 | #include 8 | 9 | static const int WAIT_TIME_FOR_DEV_RET = 5000; // 5s 10 | 11 | PlatformToDevHandler::PlatformToDevHandler() 12 | : m_platformRecvSocket(0), 13 | m_toDevSocket(0) 14 | { 15 | } 16 | 17 | int PlatformToDevHandler::handleCmd(QByteArray &aCmd) 18 | { 19 | QDataStream is(aCmd); 20 | is.skipRawData(1); 21 | quint32 devId = 0; 22 | quint16 cmdId = 0; 23 | is >> devId >> cmdId; 24 | AlarmDev *pAlarmDev = AlarmDev::getAlarmDevByDevId(devId); 25 | QJsonObject retJsonObj; 26 | int retCode = Const::CMD_DEV_OFFLINE; 27 | if(Utils::isAllBufangCmdId(cmdId) || Utils::isAllCFangCmdId(cmdId)) 28 | { 29 | if(!pAlarmDev) 30 | { 31 | retCode = Const::CMD_DEV_NOT_EXIST; 32 | } 33 | else if(false == pAlarmDev->onlineStatus) 34 | { 35 | retCode = Const::CMD_DEV_OFFLINE; 36 | } 37 | else 38 | { 39 | if(m_toDevSocket) 40 | { 41 | Utils::logCmd(Const::REPLY_TO_DEV, aCmd); 42 | m_toDevSocket->writeDatagram(aCmd, pAlarmDev->hostAddr, pAlarmDev->port); 43 | pAlarmDev->startCmdTiming(); 44 | while(!pAlarmDev->isCmdTimeout() && pAlarmDev->isCmdExecing()); 45 | if(pAlarmDev->isCmdTimeout()) 46 | { 47 | retCode = Const::CMD_TIMEOUT; 48 | } 49 | else 50 | { 51 | retCode = Const::CMD_SECCESS; 52 | } 53 | pAlarmDev->endCmdExecing(); 54 | } 55 | } 56 | if(Utils::isAllBufangCmdId(cmdId)) 57 | cmdId = Const::CMD_ID_ALL_BUFANG_RTN; 58 | else if(Utils::isAllCFangCmdId(cmdId)) 59 | cmdId = Const::CMD_ID_ALL_CFANG_RTN; 60 | jsonCmdRetToPlatform(retJsonObj, devId, cmdId, retCode); 61 | } 62 | 63 | 64 | QJsonDocument retJsonDoc(retJsonObj); 65 | m_platformRecvSocket->writeDatagram(retJsonDoc.toJson(QJsonDocument::Compact), *m_platformHostAddr, m_platformPort); 66 | return 0; 67 | } 68 | 69 | void PlatformToDevHandler::setPlatformHostAddr( const QHostAddress &platformHostAddr ) 70 | { 71 | m_platformHostAddr = new QHostAddress(platformHostAddr); 72 | } 73 | 74 | void PlatformToDevHandler::setToDevSocket(QUdpSocket *pToDevSocket) 75 | { 76 | m_toDevSocket = pToDevSocket; 77 | } 78 | 79 | void PlatformToDevHandler::setPlatformRecvSocket(QUdpSocket *pPlatformRecvSocket) 80 | { 81 | m_platformRecvSocket = pPlatformRecvSocket; 82 | } 83 | 84 | void PlatformToDevHandler::setPlatformPort(const quint16 port) 85 | { 86 | m_platformPort = port; 87 | } 88 | 89 | PlatformToDevHandler::~PlatformToDevHandler() 90 | { 91 | delete m_platformHostAddr; 92 | } 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /platformtodevhandler.h: -------------------------------------------------------------------------------- 1 | #ifndef TOPLATFORMHANDLER_H 2 | #define TOPLATFORMHANDLER_H 3 | 4 | #include "icmdhandler.h" 5 | #include "httphandler.h" 6 | #include 7 | 8 | class PlatformToDevHandler : public ICmdHandler 9 | { 10 | public: 11 | PlatformToDevHandler(); 12 | ~PlatformToDevHandler(); 13 | int handleCmd(QByteArray &aCmd); 14 | void setPlatformHostAddr(const QHostAddress &platformHostAddr); 15 | void setPlatformPort(const quint16 port); 16 | void setToDevSocket(QUdpSocket *pToDevSocket); 17 | void setPlatformRecvSocket(QUdpSocket *pPlatformRecvSocket); 18 | 19 | protected: 20 | ICmdHandler *findDevHandler(quint32 devId); 21 | 22 | private: 23 | QHostAddress *m_platformHostAddr; 24 | quint16 m_platformPort; 25 | QUdpSocket *m_platformRecvSocket; 26 | QUdpSocket *m_toDevSocket; 27 | }; 28 | 29 | #endif // TOPLATFORMHANDLER_H 30 | -------------------------------------------------------------------------------- /platformtranslator.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/platformtranslator.cpp -------------------------------------------------------------------------------- /platformtranslator.h: -------------------------------------------------------------------------------- 1 | #ifndef PLATFORMTRANSLATOR_H 2 | #define PLATFORMTRANSLATOR_H 3 | 4 | #include 5 | #include "cmdtranslator.h" 6 | 7 | static const char KEY_DEV_ID[] = "dev_id"; 8 | static const char KEY_CMD_ID[] = "cmd_id"; 9 | static const char KEY_BUFANG[] = "bufang"; 10 | static const char KEY_BUFANGTIME[] = "bufangtime"; 11 | static const char KEY_GPRS[] = "gprs"; 12 | static const char KEY_MINGDI[] = "mingdi"; 13 | static const char KEY_NETIO[] = "netio"; 14 | static const char KEY_SHEBEI[] = "shebei"; 15 | static const char KEY_ZIG315[] = "zig315"; 16 | static const char KEY_DEVTYPE[] = "devtype"; 17 | static const char KEY_STATUS[] = "status"; 18 | static const char KEY_ZIGBEE[] = "zigbee"; 19 | static const char KEY_ALARM_ID[] = "alarmid"; 20 | static const char KEY_ZONEID[] = "zoneid"; 21 | static const char KEY_ZONETYPE[] = "zonetype"; 22 | static const char KEY_PARAM1[] = "param1"; 23 | static const char KEY_PARAM2[] = "param2"; 24 | static const char KEY_RETURN[] = "return"; 25 | 26 | using namespace std; 27 | 28 | struct Alarm 29 | { 30 | quint8 alarmid; 31 | quint8 zonetype; 32 | quint8 zoneid; 33 | }; 34 | 35 | struct zone_315 36 | { 37 | zone_315() 38 | : devtype(0), 39 | status(0), 40 | bufang(0) 41 | { 42 | 43 | } 44 | quint8 devtype; //设备类型:参考设备类型对应表 45 | quint8 status; //防区状态:0:正常 1:低电量 2:异常报警 3:设备掉线 46 | quint8 bufang; //是否布防:0:撤防 1:布防 (在报警板设为选择布撤防时标记各个防区布撤防状态) 47 | }; 48 | 49 | struct zone_zigbee 50 | { 51 | zone_zigbee() 52 | : devtype(0), 53 | param1(0), 54 | param2(0), 55 | status(0), 56 | bufang(0) 57 | { 58 | 59 | } 60 | quint8 devtype; //设备类型:参考设备类型对应表 61 | quint8 param1; //上报数据:根据设备类型定夺,温湿度类型时此数据去为温度,PM2.5采集仪时定义该数据去为PM2.5的值 62 | quint8 param2; //上报数据:根据设备类型定夺,温湿度类型时此数据去为湿度,PM2.5采集仪时定义该数据区为空 63 | quint8 status; //防区状态:0:正常 1:低电量 2:异常报警 3:设备掉线 64 | quint8 bufang; //是否布防:0:撤防 1:布防(在报警板设为选择布撤防时标记各个防区布撤防状态) 65 | }; 66 | 67 | struct board_status 68 | { 69 | board_status() 70 | : netio(0), 71 | gprs(0), 72 | mingdi(0), 73 | shebei(0), 74 | bufang(0) 75 | { 76 | 77 | } 78 | quint8 netio; //每块报警板上有两个网络IO口,这个值为0:全部关闭,1:1号口打开,2: 2号口打开,3:两个IO口同时打开。 79 | quint8 gprs; //报警板GPRS信号:值从0~100,值越大,信号越强 80 | quint8 mingdi; //鸣笛状态:1 打开 0关闭 81 | quint8 shebei; // 1 充电状态 2电池供电 3低电量提醒 82 | quint8 bufang; // 0:撤防 1:全部布防 2:选择布撤防 83 | vector zigbee; 84 | vector zig315; 85 | }; 86 | 87 | 88 | class PlatformTranslator : public CmdTranslator 89 | { 90 | public: 91 | PlatformTranslator(const int iDirection); 92 | 93 | protected: 94 | QByteArray & toDevCmd(QByteArray &aDevCmd, const QByteArray &aSrcCmd); 95 | QByteArray & fromDevCmd(QByteArray &aDestCmd, const QByteArray &aDevCmd); 96 | 97 | private: 98 | static quint16 curBoardCrc; 99 | }; 100 | 101 | QDataStream &operator >>(QDataStream &s, zone_315 &zone315); 102 | QDataStream &operator >>(QDataStream &s, zone_zigbee &zoneZigbee); 103 | QDataStream &operator >>(QDataStream &s, board_status &boardStatus); 104 | QDataStream &operator >>(QDataStream &s, Alarm &alarm); 105 | 106 | QDataStream &operator <<(QDataStream &s, const zone_315 &zone315); 107 | QDataStream &operator <<(QDataStream &s, const zone_zigbee &zoneZigbee); 108 | QDataStream &operator <<(QDataStream &s, const board_status &boardStatus); 109 | 110 | int toJsonObject(QJsonObject &destJson, const zone_315 &zone315); 111 | int toJsonObject(QJsonObject &destJson, const zone_zigbee &zoneZigbee); 112 | int toJsonObject(QJsonObject &destJson, const board_status &boardStatus); 113 | int toJsonObject(QJsonObject &destJson, const Alarm &alarm); 114 | 115 | int jsonCmdRetToPlatform( 116 | QJsonObject &destJson, 117 | quint32 devId, 118 | quint16 cmdId, 119 | int returnCode 120 | ); 121 | 122 | 123 | 124 | #endif // PLATFORMTRANSLATOR_H 125 | -------------------------------------------------------------------------------- /recvthread.cpp: -------------------------------------------------------------------------------- 1 | #include "recvthread.h" 2 | #include "icmdhandler.h" 3 | #include "cmdfactory.h" 4 | #include "recvthread.h" 5 | #include "devcmdrecv.h" 6 | #include "phonecmdrecv.h" 7 | #include "httphandler.h" 8 | #include "platformcmdrecv.h" 9 | #include "timerthread.h" 10 | #include "const.h" 11 | 12 | static char KEY_PLAT_BIND_PORT[] = "PlatformBindPort"; 13 | 14 | RecvThread::RecvThread() 15 | : m_bStartToEnd(false), 16 | m_pCmdFactory(NULL), 17 | m_pPlatformRecvSocket(NULL) 18 | { 19 | 20 | } 21 | 22 | void RecvThread::addCmdRecv(PICmdRecv pCmdRecv) 23 | { 24 | m_lstPICmdRecv.append(pCmdRecv); 25 | } 26 | 27 | void RecvThread::start( Priority /*= InheritPriority*/ ) 28 | { 29 | QSettings settings(Const::CONFIG_FILE_NAME, QSettings::IniFormat); 30 | bool isOk = false; 31 | quint16 platBindPort = settings.value(KEY_PLAT_BIND_PORT).toInt(&isOk); 32 | //Q_ASSERT(isOk); 33 | m_pPlatformRecvSocket = new QUdpSocket(); 34 | m_pPlatformRecvSocket->bind(platBindPort); 35 | PlatformCmdRecv *pPlatCmdRecv = new PlatformCmdRecv(m_pCmdFactory, m_pPlatformRecvSocket); 36 | QObject::connect(m_pPlatformRecvSocket, &QUdpSocket::readyRead, pPlatCmdRecv, &PlatformCmdRecv::createCmd); 37 | addCmdRecv(pPlatCmdRecv); 38 | m_pPlatformRecvSocket->moveToThread(this); 39 | QThread::start(); 40 | } 41 | 42 | void RecvThread::setCmdFactory(CmdFactory *pCmdFactory) 43 | { 44 | m_pCmdFactory = pCmdFactory; 45 | } 46 | 47 | RecvThread::~RecvThread() 48 | { 49 | delete m_pPlatformRecvSocket; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /recvthread.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/recvthread.h -------------------------------------------------------------------------------- /replytodevtranslator.cpp: -------------------------------------------------------------------------------- 1 | #include "replytodevtranslator.h" 2 | #include "const.h" 3 | #include "utils.h" 4 | #include "crc16.h" 5 | #include 6 | 7 | ReplyToDevTranslator::ReplyToDevTranslator() 8 | { 9 | 10 | } 11 | 12 | QByteArray &ReplyToDevTranslator::translate(QByteArray &aDest, const QByteArray &aSrc) 13 | { 14 | QDataStream is(aSrc); 15 | aDest.clear(); 16 | QDataStream os(&aDest, QIODevice::WriteOnly); 17 | quint8 devType = Const::DEVTYPE_BOARD; 18 | quint32 devId = 0; 19 | quint16 cmdId = 0; 20 | quint16 mid = 0; 21 | quint16 dataLen = 0; 22 | is.skipRawData(1); 23 | is >> devId >> cmdId >> mid; 24 | if(Utils::isHeartbeatCmdId(cmdId)) 25 | { 26 | cmdId = Const::CMD_ID_HEART_REPLY; 27 | } 28 | else if(Utils::isAlarmReportCmdId(cmdId)) 29 | { 30 | cmdId = Const::CMD_ID_ALARM_REPLY; 31 | } 32 | else 33 | { 34 | return aDest; 35 | } 36 | os.writeRawData(Const::FRAME_START_FLAG, Const::CMD_FRAME_START_FLAG_SIZE); 37 | os << devType << devId; 38 | cmdId = Const::CMD_ID_HEART_REPLY; 39 | os << cmdId << mid << dataLen; 40 | quint16 crc16Checksum = Utils::modbus_crc((quint8 *)aDest.data(), aDest.size()); 41 | os << crc16Checksum; 42 | Utils::logCmd(Const::REPLY_TO_DEV, aDest); 43 | return aDest; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /replytodevtranslator.h: -------------------------------------------------------------------------------- 1 | #ifndef REPLYTODEVTRANSLATOR_H 2 | #define REPLYTODEVTRANSLATOR_H 3 | 4 | #include "icmdtranslator.h" 5 | 6 | class ReplyToDevTranslator : public ICmdTranslator 7 | { 8 | public: 9 | ReplyToDevTranslator(); 10 | 11 | QByteArray & translate(QByteArray &aDest, const QByteArray &aSrc); 12 | 13 | }; 14 | 15 | #endif // REPLYTODEVTRANSLATOR_H 16 | -------------------------------------------------------------------------------- /tcpappcmdrecv.cpp: -------------------------------------------------------------------------------- 1 | #include "tcpappcmdrecv.h" 2 | #include "tcpsocket.h" 3 | 4 | TcpAppCmdRecv::TcpAppCmdRecv( CmdFactory *pCmdFactory ) : TcpCmdRecv(pCmdFactory) 5 | { 6 | 7 | } 8 | 9 | void TcpAppCmdRecv::handleCmd( quint32 devId, TcpSocket * tcpSocket, QByteArray data ) 10 | { 11 | m_pCmdFactory->createFromAppCmd( 12 | devId, 13 | data, 14 | tcpSocket->localAddress(), 15 | tcpSocket->localPort() 16 | ); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /tcpappcmdrecv.h: -------------------------------------------------------------------------------- 1 | #ifndef TCPAPPCMDRECV_H 2 | #define TCPAPPCMDRECV_H 3 | 4 | #include "tcpcmdrecv.h" 5 | 6 | class TcpAppCmdRecv : public TcpCmdRecv 7 | { 8 | public: 9 | TcpAppCmdRecv(CmdFactory *pCmdFactory); 10 | 11 | void handleCmd(quint32 devId, TcpSocket * tcpSocket, QByteArray data); 12 | }; 13 | 14 | #endif // TCPAPPCMDRECV_H 15 | -------------------------------------------------------------------------------- /tcpcmdfactory.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/tcpcmdfactory.cpp -------------------------------------------------------------------------------- /tcpcmdfactory.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizk/TcpCmdTransfer/8d6103bdbb6595cb211f622f5fb86bef2a1e36c1/tcpcmdfactory.h -------------------------------------------------------------------------------- /tcpcmdrecv.cpp: -------------------------------------------------------------------------------- 1 | #include "tcpcmdrecv.h" 2 | #include "tcpserver.h" 3 | 4 | TcpCmdRecv::TcpCmdRecv(CmdFactory *pCmdFactory) 5 | : CmdRecv(pCmdFactory) 6 | { 7 | } 8 | 9 | bool TcpCmdRecv::hasCmdData() 10 | { 11 | return true; 12 | } 13 | 14 | void TcpCmdRecv::createCmd() 15 | { 16 | return; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /tcpcmdrecv.h: -------------------------------------------------------------------------------- 1 | #ifndef TCPCMDRECV_H 2 | #define TCPCMDRECV_H 3 | 4 | #include "cmdrecv.h" 5 | #include 6 | 7 | class TcpServer; 8 | class TcpSocket; 9 | 10 | class TcpCmdRecv : public CmdRecv 11 | { 12 | public: 13 | TcpCmdRecv(CmdFactory *pCmdFactory); 14 | //void handleCmdReady(quint32 devId, TcpSocket * tcpSocket, QByteArray data); 15 | virtual void handleCmd(quint32 devId, TcpSocket * tcpSocket, QByteArray data) = 0; 16 | bool hasCmdData(); 17 | void createCmd(); 18 | 19 | protected: 20 | TcpServer *m_pTcpServer; 21 | quint16 m_listenPort; 22 | 23 | }; 24 | 25 | #endif // TCPCMDRECV_H 26 | -------------------------------------------------------------------------------- /tcpdevcmdrecv.cpp: -------------------------------------------------------------------------------- 1 | #include "tcpdevcmdrecv.h" 2 | #include "utils.h" 3 | #include "tcpsocket.h" 4 | 5 | TcpDevCmdRecv::TcpDevCmdRecv( CmdFactory *pCmdFactory ) : TcpCmdRecv(pCmdFactory) 6 | { 7 | 8 | } 9 | 10 | void TcpDevCmdRecv::handleCmd(quint32 devId, TcpSocket * tcpSocket, QByteArray data ) 11 | { 12 | m_pCmdFactory->createFromDevCmd( 13 | devId, 14 | data, 15 | tcpSocket->localAddress(), 16 | tcpSocket->localPort() 17 | ); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /tcpdevcmdrecv.h: -------------------------------------------------------------------------------- 1 | #ifndef TCPDEVCMDRECV_H 2 | #define TCPDEVCMDRECV_H 3 | 4 | #include "tcpcmdrecv.h" 5 | 6 | class TcpDevCmdRecv : public TcpCmdRecv 7 | { 8 | public: 9 | TcpDevCmdRecv(CmdFactory *pCmdFactory); 10 | 11 | void handleCmd(quint32 devId, TcpSocket * tcpSocket, QByteArray data); 12 | }; 13 | 14 | #endif // TCPDEVCMDRECV_H 15 | -------------------------------------------------------------------------------- /tcphandler.cpp: -------------------------------------------------------------------------------- 1 | #include "tcphandler.h" 2 | #include "const.h" 3 | 4 | TcpHandler::TcpHandler(TcpSocket *pTcpSocket) 5 | : m_pTcpSocket(NULL), 6 | m_isValid(false) 7 | { 8 | if(pTcpSocket) 9 | { 10 | m_pTcpSocket = pTcpSocket; 11 | QObject::connect(this, &TcpHandler::toSendData, m_pTcpSocket, &TcpSocket::sendData); 12 | } 13 | } 14 | 15 | TcpHandler::~TcpHandler() 16 | { 17 | 18 | } 19 | 20 | int TcpHandler::handleCmd(QByteArray &aCmd) 21 | { 22 | if(!m_isValid || !m_pTcpSocket) 23 | return Const::RTN_ERROR; 24 | //QMetaObject::invokeMethod(m_pTcpSocket, "sendData", Qt::AutoConnection, Q_ARG(QByteArray, aCmd)); 25 | emit toSendData(aCmd); 26 | return 0; 27 | } 28 | 29 | void TcpHandler::setValid( bool isValid ) 30 | { 31 | m_isValid = isValid; 32 | if(!isValid) 33 | m_pTcpSocket = NULL; 34 | } 35 | 36 | TcpSocket * TcpHandler::getTcpSocket() 37 | { 38 | return m_pTcpSocket; 39 | } 40 | 41 | bool TcpHandler::isValid() 42 | { 43 | return m_isValid; 44 | } 45 | 46 | void TcpHandler::setTcpSocket( TcpSocket *pTcpSocket ) 47 | { 48 | Q_ASSERT(pTcpSocket); 49 | if(pTcpSocket) 50 | { 51 | m_pTcpSocket = pTcpSocket; 52 | QObject::connect(this, &TcpHandler::toSendData, m_pTcpSocket, &TcpSocket::sendData); 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /tcphandler.h: -------------------------------------------------------------------------------- 1 | #ifndef TCPHANDLER_H 2 | #define TCPHANDLER_H 3 | 4 | #include "icmdhandler.h" 5 | #include "tcpsocket.h" 6 | 7 | class TcpHandler : public ICmdHandler 8 | { 9 | Q_OBJECT 10 | public: 11 | TcpHandler(TcpSocket *pTcpSocket); 12 | ~TcpHandler(); 13 | int handleCmd(QByteArray &aCmd); 14 | TcpSocket *getTcpSocket(); 15 | 16 | void setTcpSocket(TcpSocket *pTcpSocket); 17 | void setValid(bool isValid); 18 | bool isValid(); 19 | 20 | signals: 21 | void toSendData(const QByteArray &aCmd); 22 | 23 | private: 24 | TcpSocket *m_pTcpSocket; 25 | volatile bool m_isValid; 26 | 27 | }; 28 | 29 | #endif // TCPHANDLER_H 30 | -------------------------------------------------------------------------------- /tcpserver.cpp: -------------------------------------------------------------------------------- 1 | #include "tcpserver.h" 2 | #include "tcpcmdrecv.h" 3 | #include "tcpsocket.h" 4 | #include "tcpthread.h" 5 | #include "const.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace log4cplus; 15 | 16 | TcpServer::TcpServer() 17 | : m_listenPort(0), 18 | m_isDev(false) 19 | { 20 | } 21 | 22 | void TcpServer::setTcpCmdRecv( TcpCmdRecv *pTcpCmdRecv ) 23 | { 24 | m_pTcpCmdRecv = pTcpCmdRecv; 25 | } 26 | 27 | void TcpServer::incomingConnection(qintptr socketDescriptor) 28 | { 29 | static int iThread = 0; 30 | if(Const::MAX_TCP_THREAD == iThread) 31 | { 32 | iThread = 0; 33 | } 34 | TcpThread *pTcpThread = m_lstTcpThread[iThread++]; 35 | QMetaObject::invokeMethod( 36 | pTcpThread, 37 | "handleNewSocketDescriptor", 38 | Qt::QueuedConnection, 39 | Q_ARG(qintptr, socketDescriptor) 40 | ); 41 | } 42 | 43 | void TcpServer::createTcpThread() 44 | { 45 | for(int i = 0; i < Const::MAX_TCP_THREAD; ++i) 46 | { 47 | TcpThread *pNewTcpThread = new TcpThread(); 48 | pNewTcpThread->setIsDev(m_isDev); 49 | pNewTcpThread->setTcpCmdRecv(m_pTcpCmdRecv); 50 | pNewTcpThread->setTcpCmdFactory(m_pTcpCmdFactory); 51 | pNewTcpThread->start(); 52 | pNewTcpThread->moveToThread(pNewTcpThread); 53 | m_lstTcpThread.append(pNewTcpThread); 54 | } 55 | } 56 | 57 | void TcpServer::setListenPort( quint16 listenPort ) 58 | { 59 | m_listenPort = listenPort; 60 | } 61 | 62 | bool TcpServer::startListen() 63 | { 64 | bool rtn = this->listen(QHostAddress::Any, m_listenPort); 65 | if(rtn) 66 | { 67 | LOG4CPLUS_INFO_FMT( 68 | Logger::getRoot(), 69 | LOG4CPLUS_TEXT("listening success on %d"), 70 | m_listenPort 71 | ); 72 | } 73 | else 74 | { 75 | LOG4CPLUS_INFO_FMT( 76 | Logger::getRoot(), 77 | LOG4CPLUS_TEXT("listen failed on %d"), 78 | m_listenPort 79 | ); 80 | } 81 | return rtn; 82 | } 83 | 84 | TcpServer::~TcpServer() 85 | { 86 | 87 | } 88 | 89 | void TcpServer::setTcpCmdFactory( TcpCmdFactory *pTcpCmdFactory ) 90 | { 91 | m_pTcpCmdFactory = pTcpCmdFactory; 92 | } 93 | 94 | void TcpServer::setIsDev( bool isDev ) 95 | { 96 | m_isDev = isDev; 97 | } 98 | 99 | bool TcpServer::isDev() 100 | { 101 | return m_isDev; 102 | } 103 | 104 | 105 | -------------------------------------------------------------------------------- /tcpserver.h: -------------------------------------------------------------------------------- 1 | #ifndef TCPSERVER_H 2 | #define TCPSERVER_H 3 | 4 | #include 5 | 6 | class TcpCmdRecv; 7 | class TcpSocket; 8 | class TcpThread; 9 | class TcpCmdFactory; 10 | 11 | class TcpServer : public QTcpServer 12 | { 13 | Q_OBJECT 14 | public: 15 | TcpServer(); 16 | ~TcpServer(); 17 | void setTcpCmdRecv(TcpCmdRecv *pTcpCmdRecv); 18 | void setTcpCmdFactory(TcpCmdFactory *pTcpCmdFactory); 19 | //static TcpSocket *getTcpSocketByDevId(quint32 devId); 20 | int addDevIdTcpSock(quint32 devId, TcpSocket *pTcpSocket); 21 | void createTcpThread(); 22 | void setListenPort(quint16 listenPort); 23 | bool startListen(); 24 | void setIsDev(bool isDev); 25 | bool isDev(); 26 | 27 | protected: 28 | //TcpSocket *createTcpSocket(); 29 | void incomingConnection(qintptr socketDescriptor); 30 | 31 | protected: 32 | QList m_lstTcpThread; 33 | QList m_lstPTcpSocket; 34 | TcpCmdRecv *m_pTcpCmdRecv; 35 | TcpCmdFactory *m_pTcpCmdFactory; 36 | quint16 m_listenPort; 37 | bool m_isDev; 38 | 39 | }; 40 | 41 | #endif // TCPSERVER_H 42 | -------------------------------------------------------------------------------- /tcpsocket.cpp: -------------------------------------------------------------------------------- 1 | #include "tcpsocket.h" 2 | #include "tcpserver.h" 3 | #include "utils.h" 4 | #include "const.h" 5 | #include 6 | 7 | using namespace log4cplus; 8 | 9 | QSet TcpSocket::setTcpSocket; 10 | QReadWriteLock TcpSocket::setLock; 11 | 12 | TcpSocket::TcpSocket() 13 | : m_isDevIdGot(false), 14 | m_isDev(false), 15 | m_noDataTimes(0), 16 | m_devId(0) 17 | { 18 | QObject::connect(this, &QTcpSocket::readyRead, this, &TcpSocket::handleReadyRead); 19 | QObject::connect(this, &QTcpSocket::disconnected, this, &TcpSocket::handleDisconnected); 20 | } 21 | 22 | quint32 TcpSocket::getDevId() 23 | { 24 | return m_devId; 25 | } 26 | 27 | void TcpSocket::handleReadyRead() 28 | { 29 | this->setDataTimingStart(); 30 | QByteArray data = this->readAll(); 31 | Utils::logByteArray(data, true); 32 | m_CmdBuffer.putData(data); 33 | QByteArray cmd; 34 | forever{ 35 | cmd = m_CmdBuffer.nextCompleteCmd(); 36 | if(cmd.isNull()) 37 | break; 38 | if(!m_isDevIdGot) 39 | { 40 | m_devId = Utils::getDevIdFromCmd(cmd); 41 | LOG4CPLUS_INFO_FMT( 42 | Logger::getRoot(), 43 | LOG4CPLUS_TEXT("%s %u on %s:%d"), 44 | m_isDev ? Const::STR_DEV : Const::STR_APP, 45 | m_devId, 46 | this->peerAddress().toString().toUtf8().data(), 47 | this->peerPort() 48 | ); 49 | m_isDevIdGot = true; 50 | } 51 | emit dataReady(m_devId, this, cmd); 52 | } 53 | } 54 | 55 | void TcpSocket::sendData( const QByteArray &dataToSend ) 56 | { 57 | //QByteArray dataToSend(Const::FRAME_START_FLAG, Const::CMD_FRAME_START_FLAG_SIZE); 58 | //dataToSend.append(data); 59 | int bytesWrite = write(dataToSend); 60 | if(-1 == bytesWrite) 61 | { 62 | LOG4CPLUS_DEBUG_FMT( 63 | Logger::getRoot(), 64 | LOG4CPLUS_TEXT("Send to %s %u error"), 65 | m_isDev ? Const::STR_DEV : Const::STR_APP, 66 | m_devId 67 | ); 68 | return; 69 | } 70 | Utils::logByteArray(dataToSend, false); 71 | /*LOG4CPLUS_DEBUG_FMT( 72 | Logger::getRoot(), 73 | LOG4CPLUS_TEXT("Send %d bytes to %s %u : %s"), 74 | bytesWrite, 75 | m_isDev ? Const::STR_DEV : Const::STR_APP, 76 | m_devId, 77 | Utils::toReadableCmd(dataToSend.toHex()).data() 78 | );*/ 79 | } 80 | 81 | void TcpSocket::handleDisconnected() 82 | { 83 | emit disconnect(m_devId, this); 84 | } 85 | 86 | void TcpSocket::setIsDev( bool isDev ) 87 | { 88 | m_isDev = isDev; 89 | } 90 | 91 | bool TcpSocket::isDev() 92 | { 93 | return m_isDev; 94 | } 95 | 96 | int TcpSocket::insertTcpSocketToSet( TcpSocket *pTcpSocket ) 97 | { 98 | QWriteLocker locker(&setLock); 99 | setTcpSocket.insert(pTcpSocket); 100 | return 0; 101 | } 102 | 103 | void TcpSocket::removeFromTcpSocketSet( TcpSocket *pTcpSocket ) 104 | { 105 | QWriteLocker locker(&setLock); 106 | setTcpSocket.remove(pTcpSocket); 107 | } 108 | 109 | void TcpSocket::incrementAllTimer() 110 | { 111 | QReadLocker locker(&setLock); 112 | foreach(TcpSocket *pTcpSocket, setTcpSocket) 113 | { 114 | pTcpSocket->incrementNoDataTimes(); 115 | } 116 | } 117 | 118 | void TcpSocket::incrementNoDataTimes() 119 | { 120 | if(Const::TCP_NO_DATA_TIME == ++m_noDataTimes) 121 | { 122 | m_noDataTimes = 0; 123 | emit toDisconnect(this); 124 | } 125 | } 126 | 127 | void TcpSocket::setDataTimingStart() 128 | { 129 | m_noDataTimes = 0; 130 | } 131 | 132 | -------------------------------------------------------------------------------- /tcpsocket.h: -------------------------------------------------------------------------------- 1 | #ifndef TCPSOCKET_H 2 | #define TCPSOCKET_H 3 | 4 | #include 5 | #include "tcpserver.h" 6 | #include "cmdbuffer.h" 7 | 8 | class TcpSocket : public QTcpSocket 9 | { 10 | Q_OBJECT 11 | public: 12 | TcpSocket(); 13 | quint32 getDevId(); 14 | void setIsDev(bool isDev); 15 | void setIsActive(bool isActive); 16 | bool isDev(); 17 | bool isActive(); 18 | static int insertTcpSocketToSet(TcpSocket *pTcpSocket); 19 | static void removeFromTcpSocketSet(TcpSocket *pTcpSocket); 20 | static void incrementAllTimer(); 21 | void incrementNoDataTimes(); 22 | inline void setDataTimingStart(); 23 | 24 | signals: 25 | void dataReady(quint32 devId, TcpSocket * pTcpSocket, QByteArray data); 26 | void disconnect(quint32 devId, TcpSocket * pTcpSocket); 27 | void toDisconnect(TcpSocket * pTcpSocket); 28 | 29 | public slots: 30 | void handleReadyRead(); 31 | void sendData(const QByteArray &dataToSend); 32 | void handleDisconnected(); 33 | 34 | protected: 35 | //int registerDevIdToTcpServer(); 36 | 37 | private: 38 | quint32 m_devId; 39 | TcpServer *m_pTcpServer; 40 | bool m_isDevIdGot; 41 | CmdBuffer m_CmdBuffer; 42 | bool m_isDev; 43 | volatile int m_noDataTimes; 44 | 45 | static QSet setTcpSocket; 46 | static QReadWriteLock setLock; 47 | }; 48 | 49 | #endif // TCPSOCKET_H 50 | -------------------------------------------------------------------------------- /tcpthread.cpp: -------------------------------------------------------------------------------- 1 | #include "tcpthread.h" 2 | #include "const.h" 3 | #include "utils.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace log4cplus; 12 | 13 | TcpThread::TcpThread() 14 | { 15 | 16 | } 17 | 18 | void TcpThread::setTcpCmdFactory(TcpCmdFactory *pTcpCmdFactory) 19 | { 20 | m_pTcpCmdFactory = pTcpCmdFactory; 21 | } 22 | 23 | TcpSocket *TcpThread::getTcpSocketByDevId(const quint32 devId) 24 | { 25 | return m_mapDevIdToTcpSocket.value(devId); 26 | } 27 | 28 | void TcpThread::setTcpCmdRecv(TcpCmdRecv *pTcpCmdRecv) 29 | { 30 | m_pTcpCmdRecv = pTcpCmdRecv; 31 | } 32 | 33 | void TcpThread::handleNewSocketDescriptor(qintptr socketDescriptor) 34 | { 35 | TcpSocket *pNewTcpSock = new TcpSocket(); 36 | pNewTcpSock->setSocketDescriptor(socketDescriptor); 37 | pNewTcpSock->setIsDev(m_isDev); 38 | LOG4CPLUS_WARN_FMT( 39 | Logger::getRoot(), 40 | LOG4CPLUS_TEXT("new Connection from %s %s:%d"), 41 | m_isDev ? Const::STR_DEV : Const::STR_APP, 42 | pNewTcpSock->peerAddress().toString().toUtf8().data(), 43 | pNewTcpSock->peerPort() 44 | ); 45 | QObject::connect(pNewTcpSock, &TcpSocket::dataReady, this, &TcpThread::handleCmdReady, Qt::DirectConnection); 46 | QObject::connect(pNewTcpSock, &TcpSocket::disconnect, this, &TcpThread::handleSocketDisconnect, Qt::DirectConnection); 47 | QObject::connect(pNewTcpSock, &TcpSocket::toDisconnect, this, &TcpThread::handleToDisconnect, Qt::QueuedConnection); 48 | QObject::connect(pNewTcpSock, &TcpSocket::disconnect, m_pTcpCmdFactory, &TcpCmdFactory::handleSocketDisconnect, Qt::DirectConnection); 49 | m_lstTcpSocket.append(pNewTcpSock); 50 | TcpSocket::insertTcpSocketToSet(pNewTcpSock); 51 | } 52 | 53 | void TcpThread::handleCmdReady(quint32 devId, TcpSocket * pTcpSocket, QByteArray data) 54 | { 55 | if(!m_mapDevIdToTcpSocket.contains(devId)) 56 | { 57 | m_mapDevIdToTcpSocket.insert(devId, pTcpSocket); 58 | } 59 | else 60 | { 61 | TcpSocket *pCurTcpSocket = m_mapDevIdToTcpSocket[devId]; 62 | if(pCurTcpSocket && pCurTcpSocket != pTcpSocket) 63 | { 64 | pCurTcpSocket->disconnectFromHost(); 65 | m_mapDevIdToTcpSocket[devId] = pTcpSocket; 66 | } 67 | } 68 | m_pTcpCmdRecv->handleCmd(devId, pTcpSocket, data); 69 | } 70 | 71 | TcpThread::~TcpThread() 72 | { 73 | 74 | } 75 | 76 | void TcpThread::handleSocketDisconnect( quint32 devId, TcpSocket *pTcpSocket ) 77 | { 78 | 79 | if(devId) 80 | { 81 | if(pTcpSocket->isDev()) 82 | Utils::remoteWinAlarm(devId); 83 | LOG4CPLUS_WARN_FMT( 84 | Logger::getRoot(), 85 | LOG4CPLUS_TEXT("%s %u disconnect %s:%d"), 86 | pTcpSocket->isDev() ? Const::STR_DEV : Const::STR_APP, 87 | devId, 88 | pTcpSocket->peerAddress().toString().toUtf8().data(), 89 | pTcpSocket->peerPort() 90 | ); 91 | } 92 | else 93 | { 94 | LOG4CPLUS_WARN_FMT( 95 | Logger::getRoot(), 96 | LOG4CPLUS_TEXT("%s disconnect %s:%d"), 97 | pTcpSocket->isDev() ? Const::STR_DEV : Const::STR_APP, 98 | pTcpSocket->peerAddress().toString().toUtf8().data(), 99 | pTcpSocket->peerPort() 100 | ); 101 | } 102 | TcpSocket *pCurTcpSocket = m_mapDevIdToTcpSocket[devId]; 103 | if(pTcpSocket == pCurTcpSocket) 104 | { 105 | m_mapDevIdToTcpSocket.remove(devId); 106 | } 107 | TcpSocket::removeFromTcpSocketSet(pTcpSocket); 108 | pTcpSocket->deleteLater(); 109 | } 110 | 111 | void TcpThread::setIsDev( bool isDev ) 112 | { 113 | m_isDev = isDev; 114 | } 115 | 116 | bool TcpThread::isDev() 117 | { 118 | return m_isDev; 119 | } 120 | 121 | void TcpThread::handleToDisconnect( TcpSocket *pTcpSocket ) 122 | { 123 | pTcpSocket->disconnectFromHost(); 124 | } 125 | 126 | -------------------------------------------------------------------------------- /tcpthread.h: -------------------------------------------------------------------------------- 1 | #ifndef TCPTHREAD_H 2 | #define TCPTHREAD_H 3 | 4 | #include 5 | #include "tcpcmdfactory.h" 6 | #include "tcpcmdrecv.h" 7 | #include "tcpsocket.h" 8 | 9 | class TcpThread : public QThread 10 | { 11 | Q_OBJECT 12 | public: 13 | TcpThread(); 14 | ~TcpThread(); 15 | void setTcpCmdFactory(TcpCmdFactory *pTcpCmdFactory); 16 | TcpSocket *getTcpSocketByDevId(const quint32 devId); 17 | void setTcpCmdRecv(TcpCmdRecv * pTcpCmdRecv); 18 | void setIsDev(bool isDev); 19 | bool isDev(); 20 | 21 | public slots: 22 | void handleNewSocketDescriptor(qintptr socketDescriptor); 23 | 24 | protected slots: 25 | void handleCmdReady(quint32 devId, TcpSocket *pTcpSocket, QByteArray data); 26 | void handleSocketDisconnect(quint32 devId, TcpSocket *pTcpSocket); 27 | void handleToDisconnect(TcpSocket *pTcpSocket); 28 | 29 | protected: 30 | QList m_lstSocketDescriptor; 31 | QList m_lstTcpSocket; 32 | QMap m_mapDevIdToTcpSocket; 33 | TcpCmdFactory *m_pTcpCmdFactory; 34 | TcpCmdRecv *m_pTcpCmdRecv; 35 | bool m_isDev; 36 | }; 37 | 38 | #endif // TCPTHREAD_H 39 | -------------------------------------------------------------------------------- /timerthread.cpp: -------------------------------------------------------------------------------- 1 | #include "timerthread.h" 2 | #include "alarmdev.h" 3 | #include "const.h" 4 | #include "tcpsocket.h" 5 | 6 | 7 | TimerThread::TimerThread() 8 | : m_bStartToEnd(false), 9 | m_pTimer(NULL), 10 | m_iTcpTimer(0) 11 | { 12 | } 13 | 14 | void TimerThread::run() 15 | { 16 | m_pTimer = new QTimer(); 17 | m_pTimer->moveToThread(this); 18 | m_pTimer->setSingleShot(false); 19 | m_pTimer->setInterval(Const::TIMER_INTERVAL); 20 | QObject::connect(m_pTimer, &QTimer::timeout, this, &TimerThread::incrementAlarmDevAllTimer); 21 | m_pTimer->start(); 22 | QThread::run(); 23 | } 24 | 25 | void TimerThread::end() 26 | { 27 | } 28 | 29 | TimerThread::~TimerThread() 30 | { 31 | 32 | } 33 | 34 | void TimerThread::quit() 35 | { 36 | m_pTimer->deleteLater(); 37 | QThread::quit(); 38 | } 39 | 40 | void TimerThread::incrementAlarmDevAllTimer() 41 | { 42 | AlarmDev::incrementAllTimer(); 43 | if(Const::TCP_CHECK_INTERVAL == ++m_iTcpTimer) 44 | { 45 | TcpSocket::incrementAllTimer(); 46 | m_iTcpTimer = 0; 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /timerthread.h: -------------------------------------------------------------------------------- 1 | #ifndef TIMERTHREAD_H 2 | #define TIMERTHREAD_H 3 | 4 | #include 5 | 6 | class TimerThread : public QThread 7 | { 8 | public: 9 | TimerThread(); 10 | ~TimerThread(); 11 | 12 | void run(); 13 | void end(); 14 | void quit(); 15 | 16 | protected: 17 | void incrementAlarmDevAllTimer(); 18 | 19 | private: 20 | volatile bool m_bStartToEnd; 21 | //QElapsedTimer *m_pTimer; 22 | QTimer *m_pTimer; 23 | volatile quint64 m_iTcpTimer; 24 | }; 25 | 26 | #endif // TIMERTHREAD_H 27 | -------------------------------------------------------------------------------- /udpcmdrecv.cpp: -------------------------------------------------------------------------------- 1 | #include "udpcmdrecv.h" 2 | 3 | UDPCmdRecv::UDPCmdRecv(CmdFactory *pCmdFactory, QUdpSocket *pUdpSocket) 4 | : CmdRecv(pCmdFactory), 5 | m_pUdpSocket(pUdpSocket) 6 | { 7 | 8 | } 9 | 10 | bool UDPCmdRecv::hasCmdData() 11 | { 12 | return m_pUdpSocket->hasPendingDatagrams(); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /udpcmdrecv.h: -------------------------------------------------------------------------------- 1 | #ifndef UDPCMDRECV_H 2 | #define UDPCMDRECV_H 3 | 4 | #include "cmdrecv.h" 5 | #include 6 | 7 | class UDPCmdRecv : public CmdRecv 8 | { 9 | public: 10 | UDPCmdRecv(CmdFactory *pCmdFactory, QUdpSocket *pUdpSocket); 11 | bool hasCmdData(); 12 | 13 | protected: 14 | QUdpSocket *m_pUdpSocket; 15 | }; 16 | 17 | #endif // UDPCMDRECV_H 18 | -------------------------------------------------------------------------------- /utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | #include "platformtranslator.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace log4cplus; 14 | 15 | static log4cplus::thread::Mutex mutex; 16 | 17 | bool Utils::isAllBufangCmd(const QByteArray &cmd ) 18 | { 19 | quint16 cmdId = getCmdIdFromCmd(cmd); 20 | return isAllBufangCmdId(cmdId); 21 | } 22 | 23 | bool Utils::isAllBufangRetCmd(const QByteArray &cmd ) 24 | { 25 | quint16 cmdId = getCmdIdFromCmd(cmd); 26 | return isAllBufangRetCmdId(cmdId); 27 | } 28 | 29 | quint16 Utils::getCmdIdFromCmd(const QByteArray &cmd ) 30 | { 31 | QDataStream is(cmd); 32 | is.skipRawData(5); 33 | quint16 cmdId = 0; 34 | is >> cmdId; 35 | return cmdId; 36 | } 37 | 38 | quint32 Utils::getDevIdFromCmd( const QByteArray &cmd ) 39 | { 40 | QDataStream is(cmd); 41 | is.skipRawData(1); 42 | quint32 devId = 0; 43 | is >> devId; 44 | return devId; 45 | } 46 | 47 | quint16 Utils::getMidFromCmd( const QByteArray &cmd ) 48 | { 49 | QDataStream is(cmd); 50 | is.skipRawData(7); 51 | quint16 mid = 0; 52 | is >> mid; 53 | return mid; 54 | } 55 | 56 | quint32 Utils::getDevIdFromJsonCmd( const QByteArray &cmd ) 57 | { 58 | QJsonDocument jsonDoc = QJsonDocument::fromJson(cmd); 59 | QJsonObject jsonCmdObj = jsonDoc.object(); 60 | double dDevId = jsonCmdObj[KEY_DEV_ID].toDouble(); 61 | return quint32(dDevId); 62 | } 63 | 64 | QByteArray Utils::toReadableCmd(const QByteArray &aCmd ) 65 | { 66 | QByteArray cmd; 67 | int size = 0, i = 0, j = 0; 68 | size = aCmd.size(); 69 | if('f' == aCmd[i]) 70 | j = 8; 71 | else 72 | j = 0; 73 | for(i = j; i < size; ++i) 74 | { 75 | cmd.append(aCmd.at(i)); 76 | if(j + 1 == i) 77 | { 78 | cmd.append(' '); 79 | } 80 | else if(j + 9 == i) 81 | { 82 | cmd.append(' '); 83 | } 84 | else if(j + 13 == i) 85 | { 86 | cmd.append(' '); 87 | } 88 | else if(j + 17 == i) 89 | { 90 | cmd.append(' '); 91 | } 92 | else if(j + 21 == i) 93 | { 94 | cmd.append(' '); 95 | } 96 | else if(j + size - 5 == i) 97 | { 98 | cmd.append(' '); 99 | } 100 | } 101 | return cmd; 102 | } 103 | 104 | 105 | void Utils::logCmd( const char *direction, const QByteArray &cmd, CMD_FORMAT cmdFormat /*= BYTEARRAY_CMD*/ ) 106 | { 107 | LOG4CPLUS_DEBUG_FMT( 108 | Logger::getRoot(), 109 | LOG4CPLUS_TEXT("%s : %s"), 110 | direction, 111 | CMD_FORMAT::BYTEARRAY_CMD == cmdFormat ? 112 | toReadableCmd(cmd.toHex()).data() 113 | : 114 | cmd.data() 115 | ); 116 | } 117 | 118 | void Utils::remoteWinAlarm( quint32 devId ) 119 | { 120 | QScopedPointer pUdpSocket(new QUdpSocket()); 121 | pUdpSocket->writeDatagram(QString("tcp %1").arg(devId).toUtf8(), QHostAddress::LocalHost, 4444); 122 | } 123 | 124 | void Utils::logByteArray( const QByteArray &byteArray, bool isRecv ) 125 | { 126 | LOG4CPLUS_WARN_FMT( 127 | Logger::getRoot(), 128 | LOG4CPLUS_TEXT("%s : %s"), 129 | isRecv ? "Recv" : "Send", 130 | toReadableByteArray(byteArray).constData() 131 | ); 132 | } 133 | 134 | QByteArray Utils::toReadableByteArray( const QByteArray &byteArray ) 135 | { 136 | QByteArray readableArray; 137 | QByteArray hexArray = byteArray.toHex(); 138 | for(int i = 0; i < hexArray.size(); ++i) 139 | { 140 | readableArray.append(hexArray.at(i)); 141 | if(i % 2 != 0) 142 | readableArray.append(' '); 143 | } 144 | return readableArray; 145 | } 146 | 147 | 148 | -------------------------------------------------------------------------------- /utils.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_H 2 | #define UTILS_H 3 | 4 | #include 5 | #include "const.h" 6 | 7 | namespace Utils { 8 | 9 | typedef enum { 10 | BYTEARRAY_CMD, 11 | JSON_CMD 12 | }CMD_FORMAT; 13 | 14 | 15 | inline bool isAllBufangCmdId(quint16 cmdId) 16 | { 17 | return Const::CMD_ID_ALL_BUFANG == cmdId; 18 | } 19 | 20 | inline bool isAllBufangRetCmdId(quint16 cmdId) 21 | { 22 | return Const::CMD_ID_ALL_BUFANG_RTN == cmdId; 23 | } 24 | 25 | inline bool isAllCFangCmdId(quint16 cmdId) 26 | { 27 | return Const::CMD_ID_ALL_CFANG == cmdId; 28 | } 29 | 30 | inline bool isAllCFangRetCmdId(quint16 cmdId) 31 | { 32 | return Const::CMD_ID_ALL_CFANG_RTN == cmdId; 33 | } 34 | 35 | 36 | inline bool isHeartbeatCmdId(quint16 cmdId) 37 | { 38 | return Const::CMD_ID_HEARTBEAT == cmdId; 39 | } 40 | 41 | inline bool isAlarmReportCmdId(quint16 cmdId) 42 | { 43 | return Const::CMD_ID_ALARM_REPORT == cmdId; 44 | } 45 | 46 | inline bool isAlarmConfirmCmdId(quint16 cmdId) 47 | { 48 | return 0x0801 == cmdId; 49 | } 50 | 51 | inline bool isOnlineCmdId(quint16 cmdId) 52 | { 53 | return Const::CMD_ID_ONLINE == cmdId; 54 | } 55 | 56 | inline bool isAppHeart(quint16 cmdId) 57 | { 58 | return Const::CMD_ID_APP_HEART == cmdId; 59 | } 60 | 61 | inline bool isAppHeartReply(quint16 cmdId) 62 | { 63 | return Const::CMD_ID_APP_HEART_REPLY == cmdId; 64 | } 65 | 66 | inline bool isRecvDataError(quint16 cmdId) 67 | { 68 | return Const::CMD_ID_RECV_DATA_ERROR == cmdId; 69 | } 70 | 71 | bool isAllBufangCmd(const QByteArray &cmd); 72 | bool isAllBufangRetCmd(const QByteArray &cmd); 73 | 74 | quint16 getCmdIdFromCmd(const QByteArray &cmd); 75 | quint16 getMidFromCmd(const QByteArray &cmd); 76 | quint32 getDevIdFromCmd(const QByteArray &cmd); 77 | quint32 getDevIdFromJsonCmd(const QByteArray &cmd); 78 | 79 | inline quint64 toIpPort(quint32 ipAddr, quint16 port) 80 | { 81 | quint64 ipPort = ipAddr; 82 | ipPort = ipPort << 16; 83 | ipPort += port; 84 | return ipPort; 85 | } 86 | 87 | QByteArray toReadableCmd(const QByteArray &aCmd); 88 | 89 | void logCmd(const char *direction, const QByteArray &cmd, CMD_FORMAT cmdFormat = BYTEARRAY_CMD); 90 | void remoteWinAlarm(quint32 devId); 91 | void logByteArray(const QByteArray &byteArray, bool isRecv); 92 | QByteArray toReadableByteArray(const QByteArray &byteArray); 93 | } 94 | 95 | #endif // UTILS_H 96 | --------------------------------------------------------------------------------