From 46155942c18394f59ff407285b6b0c6005f573c9 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Sun, 6 Jun 2021 19:11:11 +0200 Subject: [PATCH] Misc: Rename namespace ZM to zm We had a mixture of both spellings. Unify it according to our code-style. --- src/zm_comms.cpp | 104 +++++++++++++++++----------------- src/zm_comms.h | 2 +- src/zm_crypto_generics.h | 2 +- src/zm_image.cpp | 12 ++-- src/zm_monitor.cpp | 25 ++++---- src/zm_remote_camera_rtsp.cpp | 2 +- src/zm_rtp_ctrl.cpp | 12 ++-- src/zm_rtp_data.cpp | 12 ++-- src/zm_rtsp.cpp | 4 +- src/zm_rtsp.h | 4 +- src/zm_utils.cpp | 2 +- src/zm_utils.h | 4 +- tests/zm_comms.cpp | 32 +++++------ tests/zm_utils.cpp | 6 +- 14 files changed, 112 insertions(+), 111 deletions(-) diff --git a/src/zm_comms.cpp b/src/zm_comms.cpp index e3855bdea..17fdf8501 100644 --- a/src/zm_comms.cpp +++ b/src/zm_comms.cpp @@ -34,7 +34,7 @@ #include // define FIONREAD #endif -int ZM::CommsBase::readV(int iovcnt, /* const void *, int, */ ...) { +int zm::CommsBase::readV(int iovcnt, /* const void *, int, */ ...) { va_list arg_ptr; std::vector iov(iovcnt); @@ -52,7 +52,7 @@ int ZM::CommsBase::readV(int iovcnt, /* const void *, int, */ ...) { return nBytes; } -int ZM::CommsBase::writeV(int iovcnt, /* const void *, int, */ ...) { +int zm::CommsBase::writeV(int iovcnt, /* const void *, int, */ ...) { va_list arg_ptr; std::vector iov(iovcnt); @@ -70,7 +70,7 @@ int ZM::CommsBase::writeV(int iovcnt, /* const void *, int, */ ...) { return nBytes; } -bool ZM::Pipe::open() { +bool zm::Pipe::open() { if (::pipe(mFd) < 0) { Error("pipe(), errno = %d, error = %s", errno, strerror(errno)); return false; @@ -79,7 +79,7 @@ bool ZM::Pipe::open() { return true; } -bool ZM::Pipe::close() { +bool zm::Pipe::close() { if (mFd[0] > -1) { ::close(mFd[0]); } @@ -91,7 +91,7 @@ bool ZM::Pipe::close() { return true; } -bool ZM::Pipe::setBlocking(bool blocking) { +bool zm::Pipe::setBlocking(bool blocking) { int flags; /* Now set it for non-blocking I/O */ @@ -112,7 +112,7 @@ bool ZM::Pipe::setBlocking(bool blocking) { return true; } -ZM::SockAddr *ZM::SockAddr::newSockAddr(const sockaddr &addr, socklen_t len) { +zm::SockAddr *zm::SockAddr::newSockAddr(const sockaddr &addr, socklen_t len) { if ((addr.sa_family == AF_INET) && (len == SockAddrInet::addrSize())) { return new SockAddrInet((const sockaddr_in *) &addr); } else if ((addr.sa_family == AF_UNIX) && (len == SockAddrUnix::addrSize())) { @@ -123,7 +123,7 @@ ZM::SockAddr *ZM::SockAddr::newSockAddr(const sockaddr &addr, socklen_t len) { return nullptr; } -ZM::SockAddr *ZM::SockAddr::newSockAddr(const SockAddr *addr) { +zm::SockAddr *zm::SockAddr::newSockAddr(const SockAddr *addr) { if (!addr) { return nullptr; } @@ -138,7 +138,7 @@ ZM::SockAddr *ZM::SockAddr::newSockAddr(const SockAddr *addr) { return nullptr; } -bool ZM::SockAddrInet::resolve(const char *host, const char *serv, const char *proto) { +bool zm::SockAddrInet::resolve(const char *host, const char *serv, const char *proto) { memset(&mAddrIn, 0, sizeof(mAddrIn)); hostent *hostent = nullptr; @@ -160,7 +160,7 @@ bool ZM::SockAddrInet::resolve(const char *host, const char *serv, const char *p return true; } -bool ZM::SockAddrInet::resolve(const char *host, int port, const char *proto) { +bool zm::SockAddrInet::resolve(const char *host, int port, const char *proto) { memset(&mAddrIn, 0, sizeof(mAddrIn)); hostent *hostent = nullptr; @@ -175,7 +175,7 @@ bool ZM::SockAddrInet::resolve(const char *host, int port, const char *proto) { return true; } -bool ZM::SockAddrInet::resolve(const char *serv, const char *proto) { +bool zm::SockAddrInet::resolve(const char *serv, const char *proto) { memset(&mAddrIn, 0, sizeof(mAddrIn)); servent *servent = nullptr; @@ -191,7 +191,7 @@ bool ZM::SockAddrInet::resolve(const char *serv, const char *proto) { return true; } -bool ZM::SockAddrInet::resolve(int port, const char *proto) { +bool zm::SockAddrInet::resolve(int port, const char *proto) { memset(&mAddrIn, 0, sizeof(mAddrIn)); mAddrIn.sin_port = htons(port); @@ -201,7 +201,7 @@ bool ZM::SockAddrInet::resolve(int port, const char *proto) { return true; } -bool ZM::SockAddrUnix::resolve(const char *path, const char *proto) { +bool zm::SockAddrUnix::resolve(const char *path, const char *proto) { memset(&mAddrUn, 0, sizeof(mAddrUn)); strncpy(mAddrUn.sun_path, path, sizeof(mAddrUn.sun_path)); @@ -211,7 +211,7 @@ bool ZM::SockAddrUnix::resolve(const char *path, const char *proto) { return true; } -bool ZM::Socket::socket() { +bool zm::Socket::socket() { if (mSd >= 0) { return true; } @@ -230,7 +230,7 @@ bool ZM::Socket::socket() { return true; } -bool ZM::Socket::connect() { +bool zm::Socket::connect() { if (!socket()) { return false; } @@ -245,7 +245,7 @@ bool ZM::Socket::connect() { return true; } -bool ZM::Socket::bind() { +bool zm::Socket::bind() { if (!socket()) { return false; } @@ -258,7 +258,7 @@ bool ZM::Socket::bind() { return true; } -bool ZM::Socket::listen() { +bool zm::Socket::listen() { if (::listen(mSd, SOMAXCONN) == -1) { Error("listen(), errno = %d, error = %s", errno, strerror(errno)); close(); @@ -269,7 +269,7 @@ bool ZM::Socket::listen() { return true; } -bool ZM::Socket::accept() { +bool zm::Socket::accept() { sockaddr rem_addr = {}; socklen_t rem_addr_size = getAddrSize(); @@ -287,7 +287,7 @@ bool ZM::Socket::accept() { return true; } -bool ZM::Socket::accept(int &newSd) { +bool zm::Socket::accept(int &newSd) { sockaddr rem_addr = {}; socklen_t rem_addr_size = getAddrSize(); @@ -301,7 +301,7 @@ bool ZM::Socket::accept(int &newSd) { return true; } -bool ZM::Socket::close() { +bool zm::Socket::close() { if (mSd > -1) { ::close(mSd); } @@ -311,7 +311,7 @@ bool ZM::Socket::close() { return true; } -int ZM::Socket::bytesToRead() const { +int zm::Socket::bytesToRead() const { int bytes_to_read = 0; if (ioctl(mSd, FIONREAD, &bytes_to_read) < 0) { @@ -321,7 +321,7 @@ int ZM::Socket::bytesToRead() const { return bytes_to_read; } -bool ZM::Socket::getBlocking(bool &blocking) { +bool zm::Socket::getBlocking(bool &blocking) { int flags; if ((flags = fcntl(mSd, F_GETFL)) < 0) { @@ -332,7 +332,7 @@ bool ZM::Socket::getBlocking(bool &blocking) { return true; } -bool ZM::Socket::setBlocking(bool blocking) { +bool zm::Socket::setBlocking(bool blocking) { int flags; /* Now set it for non-blocking I/O */ @@ -353,7 +353,7 @@ bool ZM::Socket::setBlocking(bool blocking) { return true; } -int ZM::Socket::getSendBufferSize(int &buffersize) const { +int zm::Socket::getSendBufferSize(int &buffersize) const { socklen_t optlen = sizeof(buffersize); if (getsockopt(mSd, SOL_SOCKET, SO_SNDBUF, &buffersize, &optlen) < 0) { Error("getsockopt(), errno = %d, error = %s", errno, strerror(errno)); @@ -362,7 +362,7 @@ int ZM::Socket::getSendBufferSize(int &buffersize) const { return buffersize; } -int ZM::Socket::getRecvBufferSize(int &buffersize) const { +int zm::Socket::getRecvBufferSize(int &buffersize) const { socklen_t optlen = sizeof(buffersize); if (getsockopt(mSd, SOL_SOCKET, SO_RCVBUF, &buffersize, &optlen) < 0) { Error("getsockopt(), errno = %d, error = %s", errno, strerror(errno)); @@ -371,7 +371,7 @@ int ZM::Socket::getRecvBufferSize(int &buffersize) const { return buffersize; } -bool ZM::Socket::setSendBufferSize(int buffersize) { +bool zm::Socket::setSendBufferSize(int buffersize) { if (setsockopt(mSd, SOL_SOCKET, SO_SNDBUF, (char *) &buffersize, sizeof(buffersize)) < 0) { Error("setsockopt(), errno = %d, error = %s", errno, strerror(errno)); return false; @@ -379,7 +379,7 @@ bool ZM::Socket::setSendBufferSize(int buffersize) { return true; } -bool ZM::Socket::setRecvBufferSize(int buffersize) { +bool zm::Socket::setRecvBufferSize(int buffersize) { if (setsockopt(mSd, SOL_SOCKET, SO_RCVBUF, (char *) &buffersize, sizeof(buffersize)) < 0) { Error("setsockopt(), errno = %d, error = %s", errno, strerror(errno)); return false; @@ -387,7 +387,7 @@ bool ZM::Socket::setRecvBufferSize(int buffersize) { return true; } -bool ZM::Socket::getRouting(bool &route) const { +bool zm::Socket::getRouting(bool &route) const { int dontRoute; socklen_t optlen = sizeof(dontRoute); if (getsockopt(mSd, SOL_SOCKET, SO_DONTROUTE, &dontRoute, &optlen) < 0) { @@ -398,7 +398,7 @@ bool ZM::Socket::getRouting(bool &route) const { return true; } -bool ZM::Socket::setRouting(bool route) { +bool zm::Socket::setRouting(bool route) { int dontRoute = !route; if (setsockopt(mSd, SOL_SOCKET, SO_DONTROUTE, (char *) &dontRoute, sizeof(dontRoute)) < 0) { Error("setsockopt(), errno = %d, error = %s", errno, strerror(errno)); @@ -407,7 +407,7 @@ bool ZM::Socket::setRouting(bool route) { return true; } -bool ZM::Socket::getNoDelay(bool &nodelay) const { +bool zm::Socket::getNoDelay(bool &nodelay) const { int int_nodelay; socklen_t optlen = sizeof(int_nodelay); if (getsockopt(mSd, IPPROTO_TCP, TCP_NODELAY, &int_nodelay, &optlen) < 0) { @@ -418,7 +418,7 @@ bool ZM::Socket::getNoDelay(bool &nodelay) const { return true; } -bool ZM::Socket::setNoDelay(bool nodelay) { +bool zm::Socket::setNoDelay(bool nodelay) { int int_nodelay = nodelay; if (setsockopt(mSd, IPPROTO_TCP, TCP_NODELAY, (char *) &int_nodelay, sizeof(int_nodelay)) < 0) { @@ -428,7 +428,7 @@ bool ZM::Socket::setNoDelay(bool nodelay) { return true; } -bool ZM::InetSocket::connect(const char *host, const char *serv) { +bool zm::InetSocket::connect(const char *host, const char *serv) { addrinfo hints; addrinfo *result, *rp; int s; @@ -500,14 +500,14 @@ bool ZM::InetSocket::connect(const char *host, const char *serv) { return true; } -bool ZM::InetSocket::connect(const char *host, int port) { +bool zm::InetSocket::connect(const char *host, int port) { char serv[8]; snprintf(serv, sizeof(serv), "%d", port); return connect(host, serv); } -bool ZM::InetSocket::bind(const char *host, const char *serv) { +bool zm::InetSocket::bind(const char *host, const char *serv) { addrinfo hints; memset(&hints, 0, sizeof(addrinfo)); @@ -565,33 +565,33 @@ bool ZM::InetSocket::bind(const char *host, const char *serv) { return true; } -bool ZM::InetSocket::bind(const char *serv) { +bool zm::InetSocket::bind(const char *serv) { return bind(nullptr, serv); } -bool ZM::InetSocket::bind(const char *host, int port) { +bool zm::InetSocket::bind(const char *host, int port) { char serv[8]; snprintf(serv, sizeof(serv), "%d", port); return bind(host, serv); } -bool ZM::InetSocket::bind(int port) { +bool zm::InetSocket::bind(int port) { char serv[8]; snprintf(serv, sizeof(serv), "%d", port); return bind(nullptr, serv); } -bool ZM::TcpInetServer::listen() { +bool zm::TcpInetServer::listen() { return Socket::listen(); } -bool ZM::TcpInetServer::accept() { +bool zm::TcpInetServer::accept() { return Socket::accept(); } -bool ZM::TcpInetServer::accept(TcpInetSocket *&newSocket) { +bool zm::TcpInetServer::accept(TcpInetSocket *&newSocket) { int newSd = -1; newSocket = nullptr; @@ -603,7 +603,7 @@ bool ZM::TcpInetServer::accept(TcpInetSocket *&newSocket) { return true; } -bool ZM::TcpUnixServer::accept(TcpUnixSocket *&newSocket) { +bool zm::TcpUnixServer::accept(TcpUnixSocket *&newSocket) { int newSd = -1; newSocket = nullptr; @@ -615,28 +615,28 @@ bool ZM::TcpUnixServer::accept(TcpUnixSocket *&newSocket) { return true; } -void ZM::Select::setTimeout(int timeout) { +void zm::Select::setTimeout(int timeout) { mTimeout.tv_sec = timeout; mTimeout.tv_usec = 0; mHasTimeout = true; } -void ZM::Select::setTimeout(double timeout) { +void zm::Select::setTimeout(double timeout) { mTimeout.tv_sec = int(timeout); mTimeout.tv_usec = suseconds_t((timeout - mTimeout.tv_sec) * 1000000.0); mHasTimeout = true; } -void ZM::Select::setTimeout(timeval timeout) { +void zm::Select::setTimeout(timeval timeout) { mTimeout = timeout; mHasTimeout = true; } -void ZM::Select::clearTimeout() { +void zm::Select::clearTimeout() { mHasTimeout = false; } -void ZM::Select::calcMaxFd() { +void zm::Select::calcMaxFd() { mMaxFd = -1; for (CommsSet::iterator iter = mReaders.begin(); iter != mReaders.end(); ++iter) { if ((*iter)->getMaxDesc() > mMaxFd) @@ -648,7 +648,7 @@ void ZM::Select::calcMaxFd() { } } -bool ZM::Select::addReader(CommsBase *comms) { +bool zm::Select::addReader(CommsBase *comms) { if (!comms->isOpen()) { Error("Unable to add closed reader"); return false; @@ -662,7 +662,7 @@ bool ZM::Select::addReader(CommsBase *comms) { return result.second; } -bool ZM::Select::deleteReader(CommsBase *comms) { +bool zm::Select::deleteReader(CommsBase *comms) { if (!comms->isOpen()) { Error("Unable to add closed reader"); return false; @@ -674,12 +674,12 @@ bool ZM::Select::deleteReader(CommsBase *comms) { return false; } -void ZM::Select::clearReaders() { +void zm::Select::clearReaders() { mReaders.clear(); mMaxFd = -1; } -bool ZM::Select::addWriter(CommsBase *comms) { +bool zm::Select::addWriter(CommsBase *comms) { std::pair result = mWriters.insert(comms); if (result.second) { if (comms->getMaxDesc() > mMaxFd) { @@ -689,7 +689,7 @@ bool ZM::Select::addWriter(CommsBase *comms) { return result.second; } -bool ZM::Select::deleteWriter(CommsBase *comms) { +bool zm::Select::deleteWriter(CommsBase *comms) { if (mWriters.erase(comms)) { calcMaxFd(); return true; @@ -697,12 +697,12 @@ bool ZM::Select::deleteWriter(CommsBase *comms) { return false; } -void ZM::Select::clearWriters() { +void zm::Select::clearWriters() { mWriters.clear(); mMaxFd = -1; } -int ZM::Select::wait() { +int zm::Select::wait() { timeval tempTimeout = mTimeout; timeval *selectTimeout = mHasTimeout ? &tempTimeout : nullptr; diff --git a/src/zm_comms.h b/src/zm_comms.h index 070ed5395..af6459ca2 100644 --- a/src/zm_comms.h +++ b/src/zm_comms.h @@ -35,7 +35,7 @@ #include #endif -namespace ZM { +namespace zm { class CommsException : public Exception { public: diff --git a/src/zm_crypto_generics.h b/src/zm_crypto_generics.h index ce5fb090f..9661d4b61 100644 --- a/src/zm_crypto_generics.h +++ b/src/zm_crypto_generics.h @@ -77,7 +77,7 @@ class GenericHash { } template void UpdateData(Container const &c) { - UpdateData(ZM::data(c), ZM::size(c)); + UpdateData(zm::data(c), zm::size(c)); } void Finalize() { diff --git a/src/zm_image.cpp b/src/zm_image.cpp index 1d007d926..550acccdd 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -2023,8 +2023,8 @@ void Image::Annotate( // Calculate initial coordinates of annotation so that everything is displayed even if the // user set coordinates would prevent that. - uint32 x0 = ZM::clamp(static_cast(coord.x_), 0u, x0_max); - uint32 y0 = ZM::clamp(static_cast(coord.y_), 0u, y0_max); + uint32 x0 = zm::clamp(static_cast(coord.x_), 0u, x0_max); + uint32 y0 = zm::clamp(static_cast(coord.y_), 0u, y0_max); uint32 y = y0; for (const std::string &line : lines) { @@ -2382,10 +2382,10 @@ void Image::Outline( Rgb colour, const Polygon &polygon ) { const Vector2 &p2 = polygon.GetVertices()[j]; // The last pixel we can draw is width/height - 1. Clamp to that value. - int x1 = ZM::clamp(p1.x_, 0, static_cast(width - 1)); - int x2 = ZM::clamp(p2.x_, 0, static_cast(width - 1)); - int y1 = ZM::clamp(p1.y_, 0, static_cast(height - 1)); - int y2 = ZM::clamp(p2.y_, 0, static_cast(height - 1)); + int x1 = zm::clamp(p1.x_, 0, static_cast(width - 1)); + int x2 = zm::clamp(p2.x_, 0, static_cast(width - 1)); + int y1 = zm::clamp(p1.y_, 0, static_cast(height - 1)); + int y2 = zm::clamp(p2.y_, 0, static_cast(height - 1)); double dx = x2 - x1; double dy = y2 - y1; diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index bedc02788..74093859e 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -685,7 +685,7 @@ void Monitor::LoadCamera() { #if ZM_HAS_V4L int extras = (deinterlacing >> 24) & 0xff; - camera = ZM::make_unique(this, + camera = zm::make_unique(this, device, channel, format, @@ -711,7 +711,7 @@ void Monitor::LoadCamera() { } case REMOTE: { if (protocol == "http") { - camera = ZM::make_unique(this, + camera = zm::make_unique(this, method, host, port, @@ -728,7 +728,7 @@ void Monitor::LoadCamera() { ); } else if (protocol == "rtsp") { - camera = ZM::make_unique(this, + camera = zm::make_unique(this, method, host, // Host port, // Port @@ -751,7 +751,7 @@ void Monitor::LoadCamera() { break; } case FILE: { - camera = ZM::make_unique(this, + camera = zm::make_unique(this, path.c_str(), camera_width, camera_height, @@ -766,7 +766,7 @@ void Monitor::LoadCamera() { break; } case FFMPEG: { - camera = ZM::make_unique(this, + camera = zm::make_unique(this, path, second_path, method, @@ -786,7 +786,7 @@ void Monitor::LoadCamera() { break; } case NVSOCKET: { - camera = ZM::make_unique(this, + camera = zm::make_unique(this, host.c_str(), port.c_str(), path.c_str(), @@ -804,7 +804,7 @@ void Monitor::LoadCamera() { } case LIBVLC: { #if HAVE_LIBVLC - camera = ZM::make_unique(this, + camera = zm::make_unique(this, path.c_str(), method, options, @@ -825,7 +825,7 @@ void Monitor::LoadCamera() { } case CURL: { #if HAVE_LIBCURL - camera = ZM::make_unique(this, + camera = zm::make_unique(this, path.c_str(), user.c_str(), pass.c_str(), @@ -846,7 +846,7 @@ void Monitor::LoadCamera() { } case VNC: { #if HAVE_LIBVNC - camera = ZM::make_unique(this, + camera = zm::make_unique(this, host.c_str(), port.c_str(), user.c_str(), @@ -899,7 +899,8 @@ bool Monitor::connect() { if (purpose != CAPTURE) { map_fd = open(mem_file.c_str(), O_RDWR); } else { - map_fd = open(mem_file.c_str(), O_RDWR|O_CREAT, (mode_t)0660); + umask(0); + map_fd = open(mem_file.c_str(), O_RDWR|O_CREAT, (mode_t)0666); } if (map_fd < 0) { @@ -3034,7 +3035,7 @@ int Monitor::PrimeCapture() { if (!decoder_it) decoder_it = packetqueue.get_video_it(false); if (!decoder) { Debug(1, "Creating decoder thread"); - decoder = ZM::make_unique(this); + decoder = zm::make_unique(this); } else { Debug(1, "Restartg decoder thread"); decoder->Start(); @@ -3049,7 +3050,7 @@ int Monitor::PrimeCapture() { } if (!analysis_thread) { Debug(1, "Starting an analysis thread for monitor (%d)", id); - analysis_thread = ZM::make_unique(this); + analysis_thread = zm::make_unique(this); } else { Debug(1, "Restarting analysis thread for monitor (%d)", id); analysis_thread->Start(); diff --git a/src/zm_remote_camera_rtsp.cpp b/src/zm_remote_camera_rtsp.cpp index 0519987e2..0055be86c 100644 --- a/src/zm_remote_camera_rtsp.cpp +++ b/src/zm_remote_camera_rtsp.cpp @@ -111,7 +111,7 @@ void RemoteCameraRtsp::Terminate() { } int RemoteCameraRtsp::Connect() { - rtspThread = ZM::make_unique(monitor->Id(), method, protocol, host, port, path, auth, rtsp_describe); + rtspThread = zm::make_unique(monitor->Id(), method, protocol, host, port, path, auth, rtsp_describe); return 0; } diff --git a/src/zm_rtp_ctrl.cpp b/src/zm_rtp_ctrl.cpp index 954ea2fd4..2d1c8f303 100644 --- a/src/zm_rtp_ctrl.cpp +++ b/src/zm_rtp_ctrl.cpp @@ -248,10 +248,10 @@ int RtpCtrlThread::recvPackets( unsigned char *buffer, ssize_t nBytes ) { void RtpCtrlThread::Run() { Debug( 2, "Starting control thread %x on port %d", mRtpSource.getSsrc(), mRtpSource.getLocalCtrlPort() ); - ZM::SockAddrInet localAddr, remoteAddr; + zm::SockAddrInet localAddr, remoteAddr; bool sendReports; - ZM::UdpInetSocket rtpCtrlServer; + zm::UdpInetSocket rtpCtrlServer; if ( mRtpSource.getLocalHost() != "" ) { if ( !rtpCtrlServer.bind( mRtpSource.getLocalHost().c_str(), mRtpSource.getLocalCtrlPort() ) ) Fatal( "Failed to bind RTCP server" ); @@ -269,7 +269,7 @@ void RtpCtrlThread::Run() { // The only reason I can think of why we would have a timeout period is so that we can regularly send RR packets. // Why 10 seconds? If anything I think this should be whatever timeout value was given in the DESCRIBE response - ZM::Select select( 10 ); + zm::Select select(10 ); select.addReader( &rtpCtrlServer ); unsigned char buffer[ZM_NETWORK_BUFSIZ]; @@ -279,7 +279,7 @@ void RtpCtrlThread::Run() { while (!mTerminate && select.wait() >= 0) { time_t now = time(nullptr); - ZM::Select::CommsList readable = select.getReadable(); + zm::Select::CommsList readable = select.getReadable(); if ( readable.size() == 0 ) { if ( ! timeout ) { // With this code here, we will send an SDES and RR packet every 10 seconds @@ -302,8 +302,8 @@ void RtpCtrlThread::Run() { timeout = false; last_receive = time(nullptr); } - for ( ZM::Select::CommsList::iterator iter = readable.begin(); iter != readable.end(); ++iter ) { - if ( ZM::UdpInetSocket *socket = dynamic_cast(*iter) ) { + for (zm::Select::CommsList::iterator iter = readable.begin(); iter != readable.end(); ++iter ) { + if ( zm::UdpInetSocket *socket = dynamic_cast(*iter) ) { ssize_t nBytes = socket->recv( buffer, sizeof(buffer) ); Debug( 4, "Read %zd bytes on sd %d", nBytes, socket->getReadDesc() ); diff --git a/src/zm_rtp_data.cpp b/src/zm_rtp_data.cpp index 744abd21f..3fcd558f8 100644 --- a/src/zm_rtp_data.cpp +++ b/src/zm_rtp_data.cpp @@ -63,8 +63,8 @@ void RtpDataThread::Run() { Debug(2, "Starting data thread %d on port %d", mRtpSource.getSsrc(), mRtpSource.getLocalDataPort()); - ZM::SockAddrInet localAddr; - ZM::UdpInetServer rtpDataSocket; + zm::SockAddrInet localAddr; + zm::UdpInetServer rtpDataSocket; if ( mRtpSource.getLocalHost() != "" ) { if ( !rtpDataSocket.bind(mRtpSource.getLocalHost().c_str(), mRtpSource.getLocalDataPort()) ) Fatal("Failed to bind RTP server"); @@ -76,19 +76,19 @@ void RtpDataThread::Run() { } Debug(3, "Bound to %s:%d", mRtpSource.getLocalHost().c_str(), mRtpSource.getLocalDataPort()); - ZM::Select select(3); + zm::Select select(3); select.addReader(&rtpDataSocket); unsigned char buffer[ZM_NETWORK_BUFSIZ]; while ( !zm_terminate && !mTerminate && (select.wait() >= 0) ) { - ZM::Select::CommsList readable = select.getReadable(); + zm::Select::CommsList readable = select.getReadable(); if ( readable.size() == 0 ) { Error("RTP timed out"); Stop(); break; } - for ( ZM::Select::CommsList::iterator iter = readable.begin(); iter != readable.end(); ++iter ) { - if ( ZM::UdpInetServer *socket = dynamic_cast(*iter) ) { + for (zm::Select::CommsList::iterator iter = readable.begin(); iter != readable.end(); ++iter ) { + if ( zm::UdpInetServer *socket = dynamic_cast(*iter) ) { int nBytes = socket->recv(buffer, sizeof(buffer)); Debug(4, "Got %d bytes on sd %d", nBytes, socket->getReadDesc()); if ( nBytes ) { diff --git a/src/zm_rtsp.cpp b/src/zm_rtsp.cpp index a8bdc22b6..6eebd34e3 100644 --- a/src/zm_rtsp.cpp +++ b/src/zm_rtsp.cpp @@ -621,14 +621,14 @@ void RtspThread::Run() { RtpDataThread rtpDataThread( *this, *source ); RtpCtrlThread rtpCtrlThread( *this, *source ); - ZM::Select select( double(config.http_timeout)/1000.0 ); + zm::Select select(double(config.http_timeout)/1000.0 ); select.addReader( &mRtspSocket ); Buffer buffer( ZM_NETWORK_BUFSIZ ); std::string keepaliveMessage = "OPTIONS "+mUrl+" RTSP/1.0\r\n"; std::string keepaliveResponse = "RTSP/1.0 200 OK\r\n"; while (!mTerminate && select.wait() >= 0) { - ZM::Select::CommsList readable = select.getReadable(); + zm::Select::CommsList readable = select.getReadable(); if ( readable.size() == 0 ) { Error( "RTSP timed out" ); break; diff --git a/src/zm_rtsp.h b/src/zm_rtsp.h index 6cb88d091..96906e209 100644 --- a/src/zm_rtsp.h +++ b/src/zm_rtsp.h @@ -68,8 +68,8 @@ private: std::string mHttpSession; ///< Only for RTSP over HTTP sessions - ZM::TcpInetClient mRtspSocket; - ZM::TcpInetClient mRtspSocket2; + zm::TcpInetClient mRtspSocket; + zm::TcpInetClient mRtspSocket2; SourceMap mSources; diff --git a/src/zm_utils.cpp b/src/zm_utils.cpp index 890b288e4..1a7085364 100644 --- a/src/zm_utils.cpp +++ b/src/zm_utils.cpp @@ -367,7 +367,7 @@ QueryString::QueryString(std::istream &input) { auto foundItr = parameters_.find(name); if (foundItr == parameters_.end()) { - std::unique_ptr newParam = ZM::make_unique(name); + std::unique_ptr newParam = zm::make_unique(name); if (!value.empty()) { newParam->addValue(value); } diff --git a/src/zm_utils.h b/src/zm_utils.h index 2d5ffb58e..3962aa5ef 100644 --- a/src/zm_utils.h +++ b/src/zm_utils.h @@ -86,7 +86,7 @@ void *sse2_aligned_memcpy(void *dest, const void *src, size_t bytes); void touch(const char *pathname); -namespace ZM { +namespace zm { // C++14 std::make_unique (TODO: remove this once C++14 is supported) template inline auto make_unique(Args &&...args) -> @@ -109,7 +109,7 @@ constexpr const T &clamp(const T &v, const T &lo, const T &hi, Compare comp) { } template constexpr const T &clamp(const T &v, const T &lo, const T &hi) { - return ZM::clamp(v, lo, hi, std::less{}); + return zm::clamp(v, lo, hi, std::less{}); } // C++17 std::data (TODO: remove this once C++17 is supported) diff --git a/tests/zm_comms.cpp b/tests/zm_comms.cpp index f23e8c987..5a0c41207 100644 --- a/tests/zm_comms.cpp +++ b/tests/zm_comms.cpp @@ -21,7 +21,7 @@ #include TEST_CASE("ZM::Pipe basics") { - ZM::Pipe pipe; + zm::Pipe pipe; SECTION("setBlocking on non-opened") { REQUIRE(pipe.setBlocking(true) == false); @@ -64,7 +64,7 @@ TEST_CASE("ZM::Pipe basics") { } TEST_CASE("ZM::Pipe read/write") { - ZM::Pipe pipe; + zm::Pipe pipe; std::array msg = {'a', 'b', 'c'}; std::array rcv{}; @@ -93,7 +93,7 @@ TEST_CASE("ZM::Pipe read/write") { } TEST_CASE("ZM::SockAddrInet") { - ZM::SockAddrInet addr; + zm::SockAddrInet addr; REQUIRE(addr.getAddrSize() == sizeof(sockaddr_in)); SECTION("resolve") { @@ -101,7 +101,7 @@ TEST_CASE("ZM::SockAddrInet") { REQUIRE(addr.getDomain() == AF_INET); SECTION("newSockAddr from resolved addr") { - ZM::SockAddr *addr2 = ZM::SockAddr::newSockAddr(&addr); + zm::SockAddr *addr2 = zm::SockAddr::newSockAddr(&addr); REQUIRE(addr2->getDomain() == AF_INET); REQUIRE(addr2->getAddrSize() == sizeof(sockaddr_in)); } @@ -109,7 +109,7 @@ TEST_CASE("ZM::SockAddrInet") { } TEST_CASE("ZM::SockAddrUnix") { - ZM::SockAddrUnix addr; + zm::SockAddrUnix addr; REQUIRE(addr.getAddrSize() == sizeof(sockaddr_un)); SECTION("resovle") { @@ -117,7 +117,7 @@ TEST_CASE("ZM::SockAddrUnix") { REQUIRE(addr.getDomain() == AF_UNIX); SECTION("newSockAddr from resolved addr") { - ZM::SockAddr *addr2 = ZM::SockAddr::newSockAddr(&addr); + zm::SockAddr *addr2 = zm::SockAddr::newSockAddr(&addr); REQUIRE(addr2->getDomain() == AF_UNIX); REQUIRE(addr2->getAddrSize() == sizeof(sockaddr_un)); } @@ -125,7 +125,7 @@ TEST_CASE("ZM::SockAddrUnix") { } TEST_CASE("ZM::UdpInetSocket basics") { - ZM::UdpInetSocket socket; + zm::UdpInetSocket socket; REQUIRE(socket.isClosed() == true); REQUIRE(socket.isOpen() == false); REQUIRE(socket.isConnected() == false); @@ -161,8 +161,8 @@ TEST_CASE("ZM::UdpInetSocket basics") { } TEST_CASE("ZM::UdpInetSocket send/recv") { - ZM::UdpInetSocket srv_socket; - ZM::UdpInetSocket client_socket; + zm::UdpInetSocket srv_socket; + zm::UdpInetSocket client_socket; std::array msg = {'a', 'b', 'c'}; std::array rcv{}; @@ -190,7 +190,7 @@ TEST_CASE("ZM::UdpUnixSocket basics") { std::string sock_path = "/tmp/zm.unittest.sock"; unlink(sock_path.c_str()); // make sure the socket file does not exist - ZM::UdpUnixSocket socket; + zm::UdpUnixSocket socket; REQUIRE(socket.isClosed() == true); REQUIRE(socket.isOpen() == false); REQUIRE(socket.isConnected() == false); @@ -221,8 +221,8 @@ TEST_CASE("ZM::UdpUnixSocket send/recv") { std::string sock_path = "/tmp/zm.unittest.sock"; unlink(sock_path.c_str()); // make sure the socket file does not exist - ZM::UdpUnixSocket srv_socket; - ZM::UdpUnixSocket client_socket; + zm::UdpUnixSocket srv_socket; + zm::UdpUnixSocket client_socket; SECTION("send/recv byte buffer") { std::array msg = {'a', 'b', 'c'}; @@ -266,7 +266,7 @@ TEST_CASE("ZM::UdpUnixSocket send/recv") { } TEST_CASE("ZM::TcpInetClient basics") { - ZM::TcpInetClient client; + zm::TcpInetClient client; REQUIRE(client.isClosed() == true); REQUIRE(client.isOpen() == false); REQUIRE(client.isConnected() == false); @@ -280,7 +280,7 @@ TEST_CASE("ZM::TcpInetClient basics") { } TEST_CASE("ZM::TcpInetServer basics", "[notCI]") { - ZM::TcpInetServer server; + zm::TcpInetServer server; REQUIRE(server.isClosed() == true); REQUIRE(server.isOpen() == false); REQUIRE(server.isConnected() == false); @@ -306,8 +306,8 @@ TEST_CASE("ZM::TcpInetServer basics", "[notCI]") { } TEST_CASE("ZM::TcpInetClient/Server send/recv", "[notCI]") { - ZM::TcpInetServer server; - ZM::TcpInetClient client; + zm::TcpInetServer server; + zm::TcpInetClient client; std::array msg = {'a', 'b', 'c'}; std::array rcv{}; diff --git a/tests/zm_utils.cpp b/tests/zm_utils.cpp index dcb2a6d07..43b6a4a71 100644 --- a/tests/zm_utils.cpp +++ b/tests/zm_utils.cpp @@ -163,9 +163,9 @@ TEST_CASE("Base64Encode") { } TEST_CASE("ZM::clamp") { - REQUIRE(ZM::clamp(1, 0, 2) == 1); - REQUIRE(ZM::clamp(3, 0, 2) == 2); - REQUIRE(ZM::clamp(-1, 0, 2) == 0); + REQUIRE(zm::clamp(1, 0, 2) == 1); + REQUIRE(zm::clamp(3, 0, 2) == 2); + REQUIRE(zm::clamp(-1, 0, 2) == 0); } TEST_CASE("UriDecode") {