Apply clang-tidy fixes

This commit is contained in:
Andrew Nelless 2017-11-26 16:42:00 +00:00
parent 5fbada9424
commit 75b2cd0b41
170 changed files with 2312 additions and 2405 deletions

View File

@ -17,17 +17,17 @@
*/
#include "core/ClientApp.h"
#include "core/ServerApp.h"
#include "arch/Arch.h"
#include "base/Log.h"
#include "base/EventQueue.h"
#include "base/Log.h"
#include "core/ServerApp.h"
#include <iostream>
int
main(int argc, char** argv)
{
// TODO: use existing arg parse code
// TODO(andrew): use existing arg parse code
bool server, client;
if (argc > 1) {
server = std::string(argv[1]) == "--server";
@ -49,12 +49,12 @@ main(int argc, char** argv)
ServerApp app(&events);
return app.run(argc, argv);
}
else if (client) {
if (client) {
ClientApp app(&events);
return app.run(argc, argv);
}
else {
// TODO: use common error code
// TODO(andrew): use common error code
std::cerr << "error: use --client or --server args" << std::endl;
return 1;
}

View File

@ -18,8 +18,8 @@
#include "core/ClientApp.h"
#include "arch/Arch.h"
#include "base/Log.h"
#include "base/EventQueue.h"
#include "base/Log.h"
#include <iostream>

View File

@ -18,8 +18,8 @@
#include "core/ServerApp.h"
#include "arch/Arch.h"
#include "base/Log.h"
#include "base/EventQueue.h"
#include "base/Log.h"
#include <iostream>

View File

@ -22,7 +22,7 @@
// Arch
//
Arch* Arch::s_instance = NULL;
Arch* Arch::s_instance = nullptr;
Arch::Arch()
{

View File

@ -24,10 +24,11 @@
void
ArchConsoleStd::writeConsole(ELevel level, const char* str)
{
if ((level >= kFATAL) && (level <= kWARNING))
if ((level >= kFATAL) && (level <= kWARNING)) {
std::cerr << str << std::endl;
else
} else {
std::cout << str << std::endl;
}
std::cout.flush();
}

View File

@ -33,17 +33,17 @@ ArchDaemonNone::~ArchDaemonNone()
}
void
ArchDaemonNone::installDaemon(const char*,
const char*,
const char*,
const char*,
const char*)
ArchDaemonNone::installDaemon(const char* /*name*/,
const char* /*description*/,
const char* /*pathname*/,
const char* /*commandLine*/,
const char* /*dependencies*/)
{
// do nothing
}
void
ArchDaemonNone::uninstallDaemon(const char*)
ArchDaemonNone::uninstallDaemon(const char* /*name*/)
{
// do nothing
}
@ -57,13 +57,13 @@ ArchDaemonNone::daemonize(const char* name, DaemonFunc func)
}
bool
ArchDaemonNone::canInstallDaemon(const char*)
ArchDaemonNone::canInstallDaemon(const char* /*name*/)
{
return false;
}
bool
ArchDaemonNone::isDaemonInstalled(const char*)
ArchDaemonNone::isDaemonInstalled(const char* /*name*/)
{
return false;
}

View File

@ -21,10 +21,10 @@
#include "common/common.h"
#include <climits>
#include <cstring>
#include <cstdlib>
#include <cstring>
static ArchMutex s_mutex = NULL;
static ArchMutex s_mutex = nullptr;
//
// use C library non-reentrant multibyte conversion with mutex
@ -32,9 +32,9 @@ static ArchMutex s_mutex = NULL;
IArchString::~IArchString()
{
if (s_mutex != NULL) {
if (s_mutex != nullptr) {
ARCH->closeMutex(s_mutex);
s_mutex = NULL;
s_mutex = nullptr;
}
}
@ -45,17 +45,17 @@ IArchString::convStringWCToMB(char* dst,
ptrdiff_t len = 0;
bool dummyErrors;
if (errors == NULL) {
if (errors == nullptr) {
errors = &dummyErrors;
}
if (s_mutex == NULL) {
if (s_mutex == nullptr) {
s_mutex = ARCH->newMutex();
}
ARCH->lockMutex(s_mutex);
if (dst == NULL) {
if (dst == nullptr) {
char dummy[MB_LEN_MAX];
for (const wchar_t* scan = src; n > 0; ++scan, --n) {
ptrdiff_t mblen = wctomb(dummy, *scan);
@ -102,17 +102,17 @@ IArchString::convStringMBToWC(wchar_t* dst,
wchar_t dummy;
bool dummyErrors;
if (errors == NULL) {
if (errors == nullptr) {
errors = &dummyErrors;
}
if (s_mutex == NULL) {
if (s_mutex == nullptr) {
s_mutex = ARCH->newMutex();
}
ARCH->lockMutex(s_mutex);
if (dst == NULL) {
if (dst == nullptr) {
for (const char* scan = src; n > 0; ) {
ptrdiff_t mblen = mbtowc(&dummy, scan, n);
switch (mblen) {
@ -155,7 +155,7 @@ IArchString::convStringMBToWC(wchar_t* dst,
case -2:
// incomplete character. convert to unknown character.
*errors = true;
*dst = (wchar_t)0xfffd;
*dst = static_cast<wchar_t>(0xfffd);
n = 0;
break;
@ -163,13 +163,13 @@ IArchString::convStringMBToWC(wchar_t* dst,
// invalid character. count one unknown character and
// start at the next byte.
*errors = true;
*dst = (wchar_t)0xfffd;
*dst = static_cast<wchar_t>(0xfffd);
scan += 1;
n -= 1;
break;
case 0:
*dst = (wchar_t)0x0000;
*dst = static_cast<wchar_t>(0x0000);
scan += 1;
n -= 1;
break;

View File

@ -18,6 +18,6 @@
#include "arch/unix/ArchConsoleUnix.h"
ArchConsoleUnix::ArchConsoleUnix() { }
ArchConsoleUnix::ArchConsoleUnix() = default;
ArchConsoleUnix::~ArchConsoleUnix() { }
ArchConsoleUnix::~ArchConsoleUnix() = default;

View File

@ -21,12 +21,12 @@
#include "arch/unix/XArchUnix.h"
#include "base/Log.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <cstdlib>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
//
// ArchDaemonUnix
@ -96,11 +96,12 @@ ArchDaemonUnix::daemonize(const char* name, DaemonFunc func)
#ifndef __APPLE__
// NB: don't run chdir on apple; causes strange behaviour.
// chdir to root so we don't keep mounted filesystems points busy
// TODO: this is a bit of a hack - can we find a better solution?
// TODO(andrew): this is a bit of a hack - can we find a better solution?
int chdirErr = chdir("/");
if (chdirErr)
if (chdirErr != 0) {
// NB: file logging actually isn't working at this point!
LOG((CLOG_ERR "chdir error: %i", chdirErr));
}
#endif
// mask off permissions for any but owner
@ -113,8 +114,8 @@ ArchDaemonUnix::daemonize(const char* name, DaemonFunc func)
// attach file descriptors 0, 1, 2 to /dev/null so inadvertent use
// of standard I/O safely goes in the bit bucket.
open("/dev/null", O_RDONLY);
open("/dev/null", O_RDWR);
open("/dev/null", O_RDONLY | O_CLOEXEC);
open("/dev/null", O_RDWR | O_CLOEXEC);
int dupErr = dup(1);

View File

@ -18,11 +18,11 @@
#include "arch/unix/ArchFileUnix.h"
#include <stdio.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>
#include <cstring>
#include <pwd.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
//
// ArchFileUnix
@ -41,26 +41,26 @@ ArchFileUnix::~ArchFileUnix()
const char*
ArchFileUnix::getBasename(const char* pathname)
{
if (pathname == NULL) {
return NULL;
if (pathname == nullptr) {
return nullptr;
}
const char* basename = strrchr(pathname, '/');
if (basename != NULL) {
if (basename != nullptr) {
return basename + 1;
}
else {
return pathname;
}
}
std::string
ArchFileUnix::getUserDirectory()
{
char* buffer = NULL;
char* buffer = nullptr;
std::string dir;
#if HAVE_GETPWUID_R
struct passwd pwent;
struct passwd pwent{};
struct passwd* pwentp;
#if defined(_SC_GETPW_R_SIZE_MAX)
long size = sysconf(_SC_GETPW_R_SIZE_MAX);
@ -75,7 +75,7 @@ ArchFileUnix::getUserDirectory()
#else
struct passwd* pwentp = getpwuid(getuid());
#endif
if (pwentp != NULL && pwentp->pw_dir != NULL) {
if (pwentp != nullptr && pwentp->pw_dir != nullptr) {
dir = pwentp->pw_dir;
}
delete[] buffer;
@ -143,7 +143,7 @@ ArchFileUnix::concatPath(const std::string& prefix,
std::string path;
path.reserve(prefix.size() + 1 + suffix.size());
path += prefix;
if (path.size() == 0 || path[path.size() - 1] != '/') {
if (path.empty() || path[path.size() - 1] != '/') {
path += '/';
}
path += suffix;

View File

@ -18,11 +18,11 @@
#include "arch/unix/ArchInternetUnix.h"
#include "arch/XArch.h"
#include "common/Version.h"
#include "base/Log.h"
#include "common/Version.h"
#include <sstream>
#include <curl/curl.h>
#include <sstream>
class CurlFacade {
public:
@ -60,12 +60,12 @@ ArchInternetUnix::urlEncode(const String& url)
static size_t
curlWriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
(static_cast<std::string*>(userp))->append(static_cast<char*>(contents), size * nmemb);
return size * nmemb;
}
CurlFacade::CurlFacade() :
m_curl(NULL)
m_curl(nullptr)
{
CURLcode init = curl_global_init(CURL_GLOBAL_ALL);
if (init != CURLE_OK) {
@ -73,14 +73,14 @@ CurlFacade::CurlFacade() :
}
m_curl = curl_easy_init();
if (m_curl == NULL) {
if (m_curl == nullptr) {
throw XArch("CURL easy init failed.");
}
}
CurlFacade::~CurlFacade()
{
if (m_curl != NULL) {
if (m_curl != nullptr) {
curl_easy_cleanup(m_curl);
}
@ -115,7 +115,7 @@ CurlFacade::urlEncode(const String& url)
{
char* resultCStr = curl_easy_escape(m_curl, url.c_str(), 0);
if (resultCStr == NULL) {
if (resultCStr == nullptr) {
throw XArch("CURL escape failed.");
}

View File

@ -47,7 +47,7 @@ ArchLogUnix::closeLog()
}
void
ArchLogUnix::showLog(bool)
ArchLogUnix::showLog(bool /*showIfEmpty*/)
{
// do nothing
}

View File

@ -21,10 +21,10 @@
#include "arch/Arch.h"
#include "arch/XArch.h"
#include <signal.h>
#include <csignal>
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
# include <ctime>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
@ -67,28 +67,23 @@ public:
ArchThreadImpl();
public:
int m_refCount;
IArchMultithread::ThreadID m_id;
pthread_t m_thread;
int m_refCount{1};
IArchMultithread::ThreadID m_id{0};
pthread_t m_thread{};
IArchMultithread::ThreadFunc m_func;
void* m_userData;
bool m_cancel;
bool m_cancelling;
bool m_exited;
bool m_cancel{false};
bool m_cancelling{false};
bool m_exited{false};
void* m_result;
void* m_networkData;
};
ArchThreadImpl::ArchThreadImpl() :
m_refCount(1),
m_id(0),
m_func(NULL),
m_userData(NULL),
m_cancel(false),
m_cancelling(false),
m_exited(false),
m_result(NULL),
m_networkData(NULL)
m_func(nullptr),
m_userData(nullptr),
m_result(nullptr),
m_networkData(nullptr)
{
// do nothing
}
@ -98,7 +93,7 @@ ArchThreadImpl::ArchThreadImpl() :
// ArchMultithreadPosix
//
ArchMultithreadPosix* ArchMultithreadPosix::s_instance = NULL;
ArchMultithreadPosix* ArchMultithreadPosix::s_instance = nullptr;
ArchMultithreadPosix::ArchMultithreadPosix() :
m_newThreadCalled(false),
@ -110,8 +105,8 @@ ArchMultithreadPosix::ArchMultithreadPosix() :
// no signal handlers
for (size_t i = 0; i < kNUM_SIGNALS; ++i) {
m_signalFunc[i] = NULL;
m_signalUserData[i] = NULL;
m_signalFunc[i] = nullptr;
m_signalUserData[i] = nullptr;
}
// create mutex for thread list
@ -128,7 +123,7 @@ ArchMultithreadPosix::ArchMultithreadPosix() :
// to wake up immediately if it's blocked in a system call. we
// won't need this until another thread is created but it's fine
// to install it now.
struct sigaction act;
struct sigaction act{};
sigemptyset(&act.sa_mask);
# if defined(SA_INTERRUPT)
act.sa_flags = SA_INTERRUPT;
@ -136,17 +131,17 @@ ArchMultithreadPosix::ArchMultithreadPosix() :
act.sa_flags = 0;
# endif
act.sa_handler = &threadCancel;
sigaction(SIGWAKEUP, &act, NULL);
sigaction(SIGWAKEUP, &act, nullptr);
// set desired signal dispositions. let SIGWAKEUP through but
// ignore SIGPIPE (we'll handle EPIPE).
sigset_t sigset;
sigset_t sigset{};
sigemptyset(&sigset);
sigaddset(&sigset, SIGWAKEUP);
pthread_sigmask(SIG_UNBLOCK, &sigset, NULL);
pthread_sigmask(SIG_UNBLOCK, &sigset, nullptr);
sigemptyset(&sigset);
sigaddset(&sigset, SIGPIPE);
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
pthread_sigmask(SIG_BLOCK, &sigset, nullptr);
}
ArchMultithreadPosix::~ArchMultithreadPosix()
@ -154,7 +149,7 @@ ArchMultithreadPosix::~ArchMultithreadPosix()
assert(s_instance != NULL);
closeMutex(m_threadMutex);
s_instance = NULL;
s_instance = nullptr;
}
void
@ -184,8 +179,8 @@ ArchMultithreadPosix::getInstance()
ArchCond
ArchMultithreadPosix::newCondVar()
{
ArchCondImpl* cond = new ArchCondImpl;
int status = pthread_cond_init(&cond->m_cond, NULL);
auto* cond = new ArchCondImpl;
int status = pthread_cond_init(&cond->m_cond, nullptr);
(void)status;
assert(status == 0);
return cond;
@ -237,13 +232,13 @@ ArchMultithreadPosix::waitCondVar(ArchCond cond,
testCancelThread();
// get final time
struct timeval now;
gettimeofday(&now, NULL);
struct timespec finalTime;
struct timeval now{};
gettimeofday(&now, nullptr);
struct timespec finalTime{};
finalTime.tv_sec = now.tv_sec;
finalTime.tv_nsec = now.tv_usec * 1000;
long timeout_sec = (long)timeout;
long timeout_nsec = (long)(1.0e+9 * (timeout - timeout_sec));
auto timeout_sec = static_cast<long>(timeout);
auto timeout_nsec = static_cast<long>(1.0e+9 * (timeout - timeout_sec));
finalTime.tv_sec += timeout_sec;
finalTime.tv_nsec += timeout_nsec;
if (finalTime.tv_nsec >= 1000000000) {
@ -275,10 +270,10 @@ ArchMultithreadPosix::waitCondVar(ArchCond cond,
ArchMutex
ArchMultithreadPosix::newMutex()
{
pthread_mutexattr_t attr;
pthread_mutexattr_t attr{};
int status = pthread_mutexattr_init(&attr);
assert(status == 0);
ArchMutexImpl* mutex = new ArchMutexImpl;
auto* mutex = new ArchMutexImpl;
status = pthread_mutex_init(&mutex->m_mutex, &attr);
assert(status == 0);
return mutex;
@ -359,13 +354,13 @@ ArchMultithreadPosix::newThread(ThreadFunc func, void* data)
lockMutex(m_threadMutex);
// create thread impl for new thread
ArchThreadImpl* thread = new ArchThreadImpl;
auto* thread = new ArchThreadImpl;
thread->m_func = func;
thread->m_userData = data;
// create the thread. pthread_create() on RedHat 7.2 smp fails
// if passed a NULL attr so use a default attr.
pthread_attr_t attr;
pthread_attr_t attr{};
int status = pthread_attr_init(&attr);
if (status == 0) {
status = pthread_create(&thread->m_thread, &attr,
@ -377,7 +372,7 @@ ArchMultithreadPosix::newThread(ThreadFunc func, void* data)
if (status != 0) {
// failed to start thread so clean up
delete thread;
thread = NULL;
thread = nullptr;
}
else {
// add thread to list
@ -411,7 +406,7 @@ ArchMultithreadPosix::closeThread(ArchThread thread)
// decrement ref count and clean up thread if no more references
if (--thread->m_refCount == 0) {
// detach from thread (unless it's the main thread)
if (thread->m_func != NULL) {
if (thread->m_func != nullptr) {
pthread_detach(thread->m_thread);
}
@ -454,7 +449,7 @@ ArchMultithreadPosix::cancelThread(ArchThread thread)
}
void
ArchMultithreadPosix::setPriorityOfThread(ArchThread thread, int /*n*/)
ArchMultithreadPosix::setPriorityOfThread(ArchThread /*thread*/, int /*n*/)
{
assert(thread != NULL);
@ -573,7 +568,7 @@ void
ArchMultithreadPosix::raiseSignal(ESignal signal)
{
lockMutex(m_threadMutex);
if (m_signalFunc[signal] != NULL) {
if (m_signalFunc[signal] != nullptr) {
m_signalFunc[signal](signal, m_signalUserData[signal]);
pthread_kill(m_mainThread->m_thread, SIGWAKEUP);
}
@ -588,7 +583,7 @@ ArchMultithreadPosix::startSignalHandler()
{
// set signal mask. the main thread blocks these signals and
// the signal handler thread will listen for them.
sigset_t sigset, oldsigset;
sigset_t sigset{}, oldsigset{};
setSignalSet(&sigset);
pthread_sigmask(SIG_BLOCK, &sigset, &oldsigset);
@ -596,18 +591,18 @@ ArchMultithreadPosix::startSignalHandler()
// instead arrange to catch and handle these signals but
// we'd be unable to cancel the main thread since no pthread
// calls are allowed in a signal handler.
pthread_attr_t attr;
pthread_attr_t attr{};
int status = pthread_attr_init(&attr);
if (status == 0) {
status = pthread_create(&m_signalThread, &attr,
&ArchMultithreadPosix::threadSignalHandler,
NULL);
nullptr);
pthread_attr_destroy(&attr);
}
if (status != 0) {
// can't create thread to wait for signal so don't block
// the signals.
pthread_sigmask(SIG_UNBLOCK, &oldsigset, NULL);
pthread_sigmask(SIG_UNBLOCK, &oldsigset, nullptr);
}
}
@ -615,7 +610,7 @@ ArchThreadImpl*
ArchMultithreadPosix::find(pthread_t thread)
{
ArchThreadImpl* impl = findNoRef(thread);
if (impl != NULL) {
if (impl != nullptr) {
refThread(impl);
}
return impl;
@ -631,7 +626,7 @@ ArchMultithreadPosix::findNoRef(pthread_t thread)
return *index;
}
}
return NULL;
return nullptr;
}
void
@ -655,7 +650,7 @@ ArchMultithreadPosix::insert(ArchThreadImpl* thread)
void
ArchMultithreadPosix::erase(ArchThreadImpl* thread)
{
for (ThreadList::iterator index = m_threadList.begin();
for (auto index = m_threadList.begin();
index != m_threadList.end(); ++index) {
if (*index == thread) {
m_threadList.erase(index);
@ -697,17 +692,17 @@ void*
ArchMultithreadPosix::threadFunc(void* vrep)
{
// get the thread
ArchThreadImpl* thread = static_cast<ArchThreadImpl*>(vrep);
auto* thread = static_cast<ArchThreadImpl*>(vrep);
// setup pthreads
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, nullptr);
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, nullptr);
// run thread
s_instance->doThreadFunc(thread);
// terminate the thread
return NULL;
return nullptr;
}
void
@ -720,7 +715,7 @@ ArchMultithreadPosix::doThreadFunc(ArchThread thread)
lockMutex(m_threadMutex);
unlockMutex(m_threadMutex);
void* result = NULL;
void* result = nullptr;
try {
// go
result = (*thread->m_func)(thread->m_userData);
@ -749,19 +744,19 @@ ArchMultithreadPosix::doThreadFunc(ArchThread thread)
}
void
ArchMultithreadPosix::threadCancel(int)
ArchMultithreadPosix::threadCancel(int /*unused*/)
{
// do nothing
}
void*
ArchMultithreadPosix::threadSignalHandler(void*)
ArchMultithreadPosix::threadSignalHandler(void* /*unused*/)
{
// detach
pthread_detach(pthread_self());
// add signal to mask
sigset_t sigset;
sigset_t sigset{};
setSignalSet(&sigset);
// also wait on SIGABRT. on linux (others?) this thread (process)
@ -808,5 +803,5 @@ ArchMultithreadPosix::threadSignalHandler(void*)
}
}
return NULL;
return nullptr;
}

View File

@ -89,8 +89,8 @@ private:
void insert(ArchThreadImpl* thread);
void erase(ArchThreadImpl* thread);
void refThread(ArchThreadImpl* rep);
void testCancelThreadImpl(ArchThreadImpl* rep);
void refThread(ArchThreadImpl* thread);
void testCancelThreadImpl(ArchThreadImpl* thread);
void doThreadFunc(ArchThread thread);
static void* threadFunc(void* vrep);
@ -109,7 +109,7 @@ private:
ThreadList m_threadList;
ThreadID m_nextID;
pthread_t m_signalThread;
SignalFunc m_signalFunc[kNUM_SIGNALS];
void* m_signalUserData[kNUM_SIGNALS];
pthread_t m_signalThread{};
SignalFunc m_signalFunc[kNUM_SIGNALS]{};
void* m_signalUserData[kNUM_SIGNALS]{};
};

View File

@ -18,22 +18,22 @@
#include "arch/unix/ArchNetworkBSD.h"
#include "arch/Arch.h"
#include "arch/unix/ArchMultithreadPosix.h"
#include "arch/unix/XArchUnix.h"
#include "arch/Arch.h"
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <netinet/in.h>
#include <netdb.h>
#include <netinet/in.h>
#if !defined(TCP_NODELAY)
# include <netinet/tcp.h>
#endif
#include <arpa/inet.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <cstring>
#if HAVE_POLL
# include <poll.h>
@ -87,8 +87,7 @@ inet_aton(const char* cp, struct in_addr* inp)
//
ArchNetworkBSD::ArchNetworkBSD()
{
}
= default;
ArchNetworkBSD::~ArchNetworkBSD()
{
@ -119,7 +118,7 @@ ArchNetworkBSD::newSocket(EAddressFamily family, ESocketType type)
}
// allocate socket object
ArchSocketImpl* newSocket = new ArchSocketImpl;
auto* newSocket = new ArchSocketImpl;
newSocket->m_fd = fd;
newSocket->m_refCount = 1;
return newSocket;
@ -214,25 +213,25 @@ ArchNetworkBSD::acceptSocket(ArchSocket s, ArchNetAddress* addr)
// if user passed NULL in addr then use scratch space
ArchNetAddress dummy;
if (addr == NULL) {
if (addr == nullptr) {
addr = &dummy;
}
// create new socket and address
ArchSocketImpl* newSocket = new ArchSocketImpl;
auto* newSocket = new ArchSocketImpl;
*addr = new ArchNetAddressImpl;
// accept on socket
ACCEPT_TYPE_ARG3 len = (ACCEPT_TYPE_ARG3)((*addr)->m_len);
auto len = ((*addr)->m_len);
int fd = accept(s->m_fd, &(*addr)->m_addr, &len);
(*addr)->m_len = (socklen_t)len;
(*addr)->m_len = len;
if (fd == -1) {
int err = errno;
delete newSocket;
delete *addr;
*addr = NULL;
*addr = nullptr;
if (err == EAGAIN) {
return NULL;
return nullptr;
}
throwError(err);
}
@ -244,7 +243,7 @@ ArchNetworkBSD::acceptSocket(ArchSocket s, ArchNetAddress* addr)
close(fd);
delete newSocket;
delete *addr;
*addr = NULL;
*addr = nullptr;
throw;
}
@ -294,11 +293,11 @@ ArchNetworkBSD::pollSocket(PollEntry pe[], int num, double timeout)
}
// allocate space for translated query
struct pollfd* pfd = new struct pollfd[1 + num];
auto* pfd = new struct pollfd[1 + num];
// translate query
for (int i = 0; i < num; ++i) {
pfd[i].fd = (pe[i].m_socket == NULL) ? -1 : pe[i].m_socket->m_fd;
pfd[i].fd = (pe[i].m_socket == nullptr) ? -1 : pe[i].m_socket->m_fd;
pfd[i].events = 0;
if ((pe[i].m_events & kPOLLIN) != 0) {
pfd[i].events |= POLLIN;
@ -311,7 +310,7 @@ ArchNetworkBSD::pollSocket(PollEntry pe[], int num, double timeout)
// add the unblock pipe
const int* unblockPipe = getUnblockPipe();
if (unblockPipe != NULL) {
if (unblockPipe != nullptr) {
pfd[n].fd = unblockPipe[0];
pfd[n].events = POLLIN;
++n;
@ -324,7 +323,7 @@ ArchNetworkBSD::pollSocket(PollEntry pe[], int num, double timeout)
n = poll(pfd, n, t);
// reset the unblock pipe
if (n > 0 && unblockPipe != NULL && (pfd[num].revents & POLLIN) != 0) {
if (n > 0 && unblockPipe != nullptr && (pfd[num].revents & POLLIN) != 0) {
// the unblock event was signalled. flush the pipe.
char dummy[100];
int ignore;
@ -500,7 +499,7 @@ void
ArchNetworkBSD::unblockPollSocket(ArchThread thread)
{
const int* unblockPipe = getUnblockPipeForThread(thread);
if (unblockPipe != NULL) {
if (unblockPipe != nullptr) {
char dummy = 0;
int ignore;
@ -545,9 +544,9 @@ ArchNetworkBSD::throwErrorOnSocket(ArchSocket s)
// get the error from the socket layer
int err = 0;
socklen_t size = (socklen_t)sizeof(err);
auto size = static_cast<socklen_t>(sizeof(err));
if (getsockopt(s->m_fd, SOL_SOCKET, SO_ERROR,
(optval_t*)&err, &size) == -1) {
reinterpret_cast<optval_t*>(&err), &size) == -1) {
err = errno;
}
@ -584,16 +583,16 @@ ArchNetworkBSD::setNoDelayOnSocket(ArchSocket s, bool noDelay)
// get old state
int oflag;
socklen_t size = (socklen_t)sizeof(oflag);
auto size = static_cast<socklen_t>(sizeof(oflag));
if (getsockopt(s->m_fd, IPPROTO_TCP, TCP_NODELAY,
(optval_t*)&oflag, &size) == -1) {
reinterpret_cast<optval_t*>(&oflag), &size) == -1) {
throwError(errno);
}
int flag = noDelay ? 1 : 0;
size = (socklen_t)sizeof(flag);
size = static_cast<socklen_t>(sizeof(flag));
if (setsockopt(s->m_fd, IPPROTO_TCP, TCP_NODELAY,
(optval_t*)&flag, size) == -1) {
reinterpret_cast<optval_t*>(&flag), size) == -1) {
throwError(errno);
}
@ -607,16 +606,16 @@ ArchNetworkBSD::setReuseAddrOnSocket(ArchSocket s, bool reuse)
// get old state
int oflag;
socklen_t size = (socklen_t)sizeof(oflag);
auto size = static_cast<socklen_t>(sizeof(oflag));
if (getsockopt(s->m_fd, SOL_SOCKET, SO_REUSEADDR,
(optval_t*)&oflag, &size) == -1) {
reinterpret_cast<optval_t*>(&oflag), &size) == -1) {
throwError(errno);
}
int flag = reuse ? 1 : 0;
size = (socklen_t)sizeof(flag);
size = static_cast<socklen_t>(sizeof(flag));
if (setsockopt(s->m_fd, SOL_SOCKET, SO_REUSEADDR,
(optval_t*)&flag, size) == -1) {
reinterpret_cast<optval_t*>(&flag), size) == -1) {
throwError(errno);
}
@ -640,17 +639,17 @@ ArchNetAddress
ArchNetworkBSD::newAnyAddr(EAddressFamily family)
{
// allocate address
ArchNetAddressImpl* addr = new ArchNetAddressImpl;
auto* addr = new ArchNetAddressImpl;
// fill it in
switch (family) {
case kINET: {
struct sockaddr_in* ipAddr =
auto* ipAddr =
reinterpret_cast<struct sockaddr_in*>(&addr->m_addr);
ipAddr->sin_family = AF_INET;
ipAddr->sin_port = 0;
ipAddr->sin_addr.s_addr = INADDR_ANY;
addr->m_len = (socklen_t)sizeof(struct sockaddr_in);
addr->m_len = static_cast<socklen_t>(sizeof(struct sockaddr_in));
break;
}
@ -675,14 +674,14 @@ ArchNetAddress
ArchNetworkBSD::nameToAddr(const std::string& name)
{
// allocate address
ArchNetAddressImpl* addr = new ArchNetAddressImpl;
auto* addr = new ArchNetAddressImpl;
// try to convert assuming an IPv4 dot notation address
struct sockaddr_in inaddr;
struct sockaddr_in inaddr{};
memset(&inaddr, 0, sizeof(inaddr));
if (inet_aton(name.c_str(), &inaddr.sin_addr) != 0) {
// it's a dot notation address
addr->m_len = (socklen_t)sizeof(struct sockaddr_in);
addr->m_len = static_cast<socklen_t>(sizeof(struct sockaddr_in));
inaddr.sin_family = AF_INET;
inaddr.sin_port = 0;
memcpy(&addr->m_addr, &inaddr, addr->m_len);
@ -692,7 +691,7 @@ ArchNetworkBSD::nameToAddr(const std::string& name)
// mutexed address lookup (ugh)
ARCH->lockMutex(m_mutex);
struct hostent* info = gethostbyname(name.c_str());
if (info == NULL) {
if (info == nullptr) {
ARCH->unlockMutex(m_mutex);
delete addr;
throwNameError(h_errno);
@ -700,7 +699,7 @@ ArchNetworkBSD::nameToAddr(const std::string& name)
// copy over address (only IPv4 currently supported)
if (info->h_addrtype == AF_INET) {
addr->m_len = (socklen_t)sizeof(struct sockaddr_in);
addr->m_len = static_cast<socklen_t>(sizeof(struct sockaddr_in));
inaddr.sin_family = info->h_addrtype;
inaddr.sin_port = 0;
memcpy(&inaddr.sin_addr, info->h_addr_list[0],
@ -739,7 +738,7 @@ ArchNetworkBSD::addrToName(ArchNetAddress addr)
ARCH->lockMutex(m_mutex);
struct hostent* info = gethostbyaddr(&addr->m_addr,
addr->m_len, addr->m_addr.sa_family);
if (info == NULL) {
if (info == nullptr) {
ARCH->unlockMutex(m_mutex);
throwNameError(h_errno);
}
@ -760,7 +759,7 @@ ArchNetworkBSD::addrToString(ArchNetAddress addr)
switch (getAddrFamily(addr)) {
case kINET: {
struct sockaddr_in* ipAddr =
auto* ipAddr =
reinterpret_cast<struct sockaddr_in*>(&addr->m_addr);
ARCH->lockMutex(m_mutex);
std::string s = inet_ntoa(ipAddr->sin_addr);
@ -795,7 +794,7 @@ ArchNetworkBSD::setAddrPort(ArchNetAddress addr, int port)
switch (getAddrFamily(addr)) {
case kINET: {
struct sockaddr_in* ipAddr =
auto* ipAddr =
reinterpret_cast<struct sockaddr_in*>(&addr->m_addr);
ipAddr->sin_port = htons(port);
break;
@ -814,7 +813,7 @@ ArchNetworkBSD::getAddrPort(ArchNetAddress addr)
switch (getAddrFamily(addr)) {
case kINET: {
struct sockaddr_in* ipAddr =
auto* ipAddr =
reinterpret_cast<struct sockaddr_in*>(&addr->m_addr);
return ntohs(ipAddr->sin_port);
}
@ -832,10 +831,10 @@ ArchNetworkBSD::isAnyAddr(ArchNetAddress addr)
switch (getAddrFamily(addr)) {
case kINET: {
struct sockaddr_in* ipAddr =
auto* ipAddr =
reinterpret_cast<struct sockaddr_in*>(&addr->m_addr);
return (ipAddr->sin_addr.s_addr == INADDR_ANY &&
addr->m_len == (socklen_t)sizeof(struct sockaddr_in));
addr->m_len == static_cast<socklen_t>(sizeof(struct sockaddr_in)));
}
default:
@ -865,8 +864,8 @@ const int*
ArchNetworkBSD::getUnblockPipeForThread(ArchThread thread)
{
ArchMultithreadPosix* mt = ArchMultithreadPosix::getInstance();
int* unblockPipe = (int*)mt->getNetworkDataForThread(thread);
if (unblockPipe == NULL) {
auto* unblockPipe = static_cast<int*>(mt->getNetworkDataForThread(thread));
if (unblockPipe == nullptr) {
unblockPipe = new int[2];
if (pipe(unblockPipe) != -1) {
try {
@ -875,12 +874,12 @@ ArchNetworkBSD::getUnblockPipeForThread(ArchThread thread)
}
catch (...) {
delete[] unblockPipe;
unblockPipe = NULL;
unblockPipe = nullptr;
}
}
else {
delete[] unblockPipe;
unblockPipe = NULL;
unblockPipe = nullptr;
}
}
return unblockPipe;

View File

@ -70,7 +70,7 @@ public:
virtual void bindSocket(ArchSocket s, ArchNetAddress addr);
virtual void listenOnSocket(ArchSocket s);
virtual ArchSocket acceptSocket(ArchSocket s, ArchNetAddress* addr);
virtual bool connectSocket(ArchSocket s, ArchNetAddress name);
virtual bool connectSocket(ArchSocket s, ArchNetAddress addr);
virtual int pollSocket(PollEntry[], int num, double timeout);
virtual void unblockPollSocket(ArchThread thread);
virtual size_t readSocket(ArchSocket s, void* buf, size_t len);
@ -100,5 +100,5 @@ private:
void throwNameError(int);
private:
ArchMutex m_mutex;
ArchMutex m_mutex{};
};

View File

@ -22,7 +22,7 @@
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
# include <ctime>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
@ -66,13 +66,14 @@ ArchSleepUnix::sleep(double timeout)
#if HAVE_NANOSLEEP
// prep timeout
struct timespec t;
t.tv_sec = (long)timeout;
t.tv_nsec = (long)(1.0e+9 * (timeout - (double)t.tv_sec));
struct timespec t{};
t.tv_sec = static_cast<long>(timeout);
t.tv_nsec = static_cast<long>(1.0e+9 * (timeout - static_cast<double>(t.tv_sec)));
// wait
while (nanosleep(&t, &t) < 0)
while (nanosleep(&t, &t) < 0) {
ARCH->testCancelThread();
}
#else
/* emulate nanosleep() with select() */
double startTime = ARCH->time();

View File

@ -18,7 +18,7 @@
#include "arch/unix/ArchStringUnix.h"
#include <stdio.h>
#include <cstdio>
//
// ArchStringUnix
@ -28,12 +28,10 @@
#include "arch/vsnprintf.h"
ArchStringUnix::ArchStringUnix()
{
}
= default;
ArchStringUnix::~ArchStringUnix()
{
}
= default;
IArchString::EWideCharEncoding
ArchStringUnix::getWideCharEncoding()

View File

@ -38,7 +38,7 @@ std::string
ArchSystemUnix::getOSName() const
{
#if defined(HAVE_SYS_UTSNAME_H)
struct utsname info;
struct utsname info{};
if (uname(&info) == 0) {
std::string msg;
msg += info.sysname;
@ -54,7 +54,7 @@ std::string
ArchSystemUnix::getPlatformName() const
{
#if defined(HAVE_SYS_UTSNAME_H)
struct utsname info;
struct utsname info{};
if (uname(&info) == 0) {
return std::string(info.machine);
}
@ -63,18 +63,18 @@ ArchSystemUnix::getPlatformName() const
}
std::string
ArchSystemUnix::setting(const std::string&) const
ArchSystemUnix::setting(const std::string& /*valueName*/) const
{
return "";
}
void
ArchSystemUnix::setting(const std::string&, const std::string&) const
ArchSystemUnix::setting(const std::string& /*valueName*/, const std::string& /*valueString*/) const
{
}
std::string
ArchSystemUnix::getLibsUsed(void) const
ArchSystemUnix::getLibsUsed() const
{
return "not implemented.\nuse lsof on shell";
}

View File

@ -20,7 +20,7 @@
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
# include <ctime>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
@ -46,7 +46,7 @@ ArchTimeUnix::~ArchTimeUnix()
double
ArchTimeUnix::time()
{
struct timeval t;
gettimeofday(&t, NULL);
return (double)t.tv_sec + 1.0e-6 * (double)t.tv_usec;
struct timeval t{};
gettimeofday(&t, nullptr);
return static_cast<double>(t.tv_sec) + 1.0e-6 * static_cast<double>(t.tv_usec);
}

View File

@ -25,8 +25,8 @@
Event::Event() :
m_type(kUnknown),
m_target(NULL),
m_data(NULL),
m_target(nullptr),
m_data(nullptr),
m_flags(0),
m_dataObject(nullptr)
{

View File

@ -18,15 +18,15 @@
#include "base/EventQueue.h"
#include "mt/Mutex.h"
#include "mt/Lock.h"
#include "arch/Arch.h"
#include "base/EventTypes.h"
#include "base/IEventJob.h"
#include "base/Log.h"
#include "base/SimpleEventQueueBuffer.h"
#include "base/Stopwatch.h"
#include "base/IEventJob.h"
#include "base/EventTypes.h"
#include "base/Log.h"
#include "base/XBase.h"
#include "mt/Lock.h"
#include "mt/Mutex.h"
EVENT_TYPE_ACCESSOR(Client)
EVENT_TYPE_ACCESSOR(IStream)
@ -52,9 +52,9 @@ EVENT_TYPE_ACCESSOR(File)
// interrupt handler. this just adds a quit event to the queue.
static
void
interrupt(Arch::ESignal, void* data)
interrupt(Arch::ESignal /*unused*/, void* data)
{
EventQueue* events = static_cast<EventQueue*>(data);
auto* events = static_cast<EventQueue*>(data);
events->addEvent(Event(Event::kQuit));
}
@ -66,26 +66,26 @@ interrupt(Arch::ESignal, void* data)
EventQueue::EventQueue() :
m_systemTarget(0),
m_nextType(Event::kLast),
m_typesForClient(NULL),
m_typesForIStream(NULL),
m_typesForIpcClient(NULL),
m_typesForIpcClientProxy(NULL),
m_typesForIpcServer(NULL),
m_typesForIpcServerProxy(NULL),
m_typesForIDataSocket(NULL),
m_typesForIListenSocket(NULL),
m_typesForISocket(NULL),
m_typesForOSXScreen(NULL),
m_typesForClientListener(NULL),
m_typesForClientProxy(NULL),
m_typesForClientProxyUnknown(NULL),
m_typesForServer(NULL),
m_typesForServerApp(NULL),
m_typesForIKeyState(NULL),
m_typesForIPrimaryScreen(NULL),
m_typesForIScreen(NULL),
m_typesForClipboard(NULL),
m_typesForFile(NULL),
m_typesForClient(nullptr),
m_typesForIStream(nullptr),
m_typesForIpcClient(nullptr),
m_typesForIpcClientProxy(nullptr),
m_typesForIpcServer(nullptr),
m_typesForIpcServerProxy(nullptr),
m_typesForIDataSocket(nullptr),
m_typesForIListenSocket(nullptr),
m_typesForISocket(nullptr),
m_typesForOSXScreen(nullptr),
m_typesForClientListener(nullptr),
m_typesForClientProxy(nullptr),
m_typesForClientProxyUnknown(nullptr),
m_typesForServer(nullptr),
m_typesForServerApp(nullptr),
m_typesForIKeyState(nullptr),
m_typesForIPrimaryScreen(nullptr),
m_typesForIScreen(nullptr),
m_typesForClipboard(nullptr),
m_typesForFile(nullptr),
m_readyMutex(new Mutex),
m_readyCondVar(new CondVar<bool>(m_readyMutex, false))
{
@ -101,8 +101,8 @@ EventQueue::~EventQueue()
delete m_readyCondVar;
delete m_readyMutex;
ARCH->setSignalHandler(Arch::kINTERRUPT, NULL, NULL);
ARCH->setSignalHandler(Arch::kTERMINATE, NULL, NULL);
ARCH->setSignalHandler(Arch::kINTERRUPT, nullptr, nullptr);
ARCH->setSignalHandler(Arch::kTERMINATE, nullptr, nullptr);
ARCH->closeMutex(m_mutex);
}
@ -166,9 +166,9 @@ EventQueue::getTypeName(Event::Type type)
if (i == m_typeMap.end()) {
return "<unknown>";
}
else {
return i->second;
}
}
}
@ -179,7 +179,7 @@ EventQueue::adoptBuffer(IEventQueueBuffer* buffer)
LOG((CLOG_DEBUG "adopting new buffer"));
if (m_events.size() != 0) {
if (!m_events.empty()) {
// this can come as a nasty surprise to programmers expecting
// their events to be raised, only to have them deleted.
LOG((CLOG_DEBUG "discarding %d event(s)", m_events.size()));
@ -187,15 +187,15 @@ EventQueue::adoptBuffer(IEventQueueBuffer* buffer)
// discard old buffer and old events
delete m_buffer;
for (EventTable::iterator i = m_events.begin(); i != m_events.end(); ++i) {
Event::deleteData(i->second);
for (auto & m_event : m_events) {
Event::deleteData(m_event.second);
}
m_events.clear();
m_oldEventIDs.clear();
// use new buffer
m_buffer = buffer;
if (m_buffer == NULL) {
if (m_buffer == nullptr) {
m_buffer = new SimpleEventQueueBuffer;
}
}
@ -264,10 +264,10 @@ EventQueue::dispatchEvent(const Event& event)
{
void* target = event.getTarget();
IEventJob* job = getHandler(event.getType(), target);
if (job == NULL) {
if (job == nullptr) {
job = getHandler(Event::kUnknown, target);
}
if (job != NULL) {
if (job != nullptr) {
job->run(event);
return true;
}
@ -322,7 +322,7 @@ EventQueue::newTimer(double duration, void* target)
assert(duration > 0.0);
EventQueueTimer* timer = m_buffer->newTimer(duration, false);
if (target == NULL) {
if (target == nullptr) {
target = timer;
}
ArchMutexLock lock(m_mutex);
@ -341,7 +341,7 @@ EventQueue::newOneShotTimer(double duration, void* target)
assert(duration > 0.0);
EventQueueTimer* timer = m_buffer->newTimer(duration, true);
if (target == NULL) {
if (target == nullptr) {
target = timer;
}
ArchMutexLock lock(m_mutex);
@ -358,14 +358,14 @@ void
EventQueue::deleteTimer(EventQueueTimer* timer)
{
ArchMutexLock lock(m_mutex);
for (TimerQueue::iterator index = m_timerQueue.begin();
for (auto index = m_timerQueue.begin();
index != m_timerQueue.end(); ++index) {
if (index->getTimer() == timer) {
m_timerQueue.erase(index);
break;
}
}
Timers::iterator index = m_timers.find(timer);
auto index = m_timers.find(timer);
if (index != m_timers.end()) {
m_timers.erase(index);
}
@ -384,13 +384,13 @@ EventQueue::adoptHandler(Event::Type type, void* target, IEventJob* handler)
void
EventQueue::removeHandler(Event::Type type, void* target)
{
IEventJob* handler = NULL;
IEventJob* handler = nullptr;
{
ArchMutexLock lock(m_mutex);
HandlerTable::iterator index = m_handlers.find(target);
auto index = m_handlers.find(target);
if (index != m_handlers.end()) {
TypeHandlerTable& typeHandlers = index->second;
TypeHandlerTable::iterator index2 = typeHandlers.find(type);
auto index2 = typeHandlers.find(type);
if (index2 != typeHandlers.end()) {
handler = index2->second;
typeHandlers.erase(index2);
@ -406,22 +406,20 @@ EventQueue::removeHandlers(void* target)
std::vector<IEventJob*> handlers;
{
ArchMutexLock lock(m_mutex);
HandlerTable::iterator index = m_handlers.find(target);
auto index = m_handlers.find(target);
if (index != m_handlers.end()) {
// copy to handlers array and clear table for target
TypeHandlerTable& typeHandlers = index->second;
for (TypeHandlerTable::iterator index2 = typeHandlers.begin();
index2 != typeHandlers.end(); ++index2) {
handlers.push_back(index2->second);
for (auto & typeHandler : typeHandlers) {
handlers.push_back(typeHandler.second);
}
typeHandlers.clear();
}
}
// delete handlers
for (std::vector<IEventJob*>::iterator index = handlers.begin();
index != handlers.end(); ++index) {
delete *index;
for (auto & handler : handlers) {
delete handler;
}
}
@ -435,15 +433,15 @@ IEventJob*
EventQueue::getHandler(Event::Type type, void* target) const
{
ArchMutexLock lock(m_mutex);
HandlerTable::const_iterator index = m_handlers.find(target);
auto index = m_handlers.find(target);
if (index != m_handlers.end()) {
const TypeHandlerTable& typeHandlers = index->second;
TypeHandlerTable::const_iterator index2 = typeHandlers.find(type);
auto index2 = typeHandlers.find(type);
if (index2 != typeHandlers.end()) {
return index2->second;
}
}
return NULL;
return nullptr;
}
UInt32
@ -470,9 +468,9 @@ Event
EventQueue::removeEvent(UInt32 eventID)
{
// look up id
EventTable::iterator index = m_events.find(eventID);
auto index = m_events.find(eventID);
if (index == m_events.end()) {
return Event();
return {};
}
// get data
@ -500,9 +498,8 @@ EventQueue::hasTimerExpired(Event& event)
m_time.reset();
// countdown elapsed time
for (TimerQueue::iterator index = m_timerQueue.begin();
index != m_timerQueue.end(); ++index) {
(*index) -= time;
for (auto & index : m_timerQueue) {
index -= time;
}
// done if no timers are expired
@ -545,9 +542,10 @@ EventQueue::getNextTimerTimeout() const
Event::Type
EventQueue::getRegisteredType(const String& name) const
{
NameMap::const_iterator found = m_nameMap.find(name);
if (found != m_nameMap.end())
auto found = m_nameMap.find(name);
if (found != m_nameMap.end()) {
return found->second;
}
return Event::kUnknown;
}

View File

@ -130,7 +130,7 @@ private:
Stopwatch m_time;
Timers m_timers;
TimerQueue m_timerQueue;
TimerEvent m_timerEvent;
TimerEvent m_timerEvent{};
// event handlers
HandlerTable m_handlers;

View File

@ -18,11 +18,11 @@
#include "base/EventTypes.h"
#include "base/IEventQueue.h"
#include <assert.h>
#include <stddef.h>
#include <cassert>
#include <cstddef>
EventTypes::EventTypes() :
m_events(NULL)
m_events(nullptr)
{
}

View File

@ -38,7 +38,7 @@ FunctionEventJob::~FunctionEventJob()
void
FunctionEventJob::run(const Event& event)
{
if (m_func != NULL) {
if (m_func != nullptr) {
m_func(event, m_arg);
}
}

View File

@ -37,7 +37,7 @@ FunctionJob::~FunctionJob()
void
FunctionJob::run()
{
if (m_func != NULL) {
if (m_func != nullptr) {
m_func(m_arg);
}
}

View File

@ -25,8 +25,8 @@
#include <cstdio>
#include <cstring>
#include <iostream>
#include <ctime>
#include <iostream>
// names of priorities
static const char* g_priority[] = {
@ -44,7 +44,7 @@ static const char* g_priority[] = {
};
// number of priorities
static const int g_numPriority = (int)(sizeof(g_priority) / sizeof(g_priority[0]));
static const int g_numPriority = static_cast<int>(sizeof(g_priority) / sizeof(g_priority[0]));
// the default priority
#ifndef NDEBUG
@ -57,7 +57,7 @@ static const int g_defaultMaxPriority = kINFO;
// Log
//
Log* Log::s_log = NULL;
Log* Log::s_log = nullptr;
Log::Log()
{
@ -82,13 +82,11 @@ Log::Log(Log* src)
Log::~Log()
{
// clean up
for (OutputterList::iterator index = m_outputters.begin();
index != m_outputters.end(); ++index) {
delete *index;
for (auto & m_outputter : m_outputters) {
delete m_outputter;
}
for (OutputterList::iterator index = m_alwaysOutputters.begin();
index != m_alwaysOutputters.end(); ++index) {
delete *index;
for (auto & m_alwaysOutputter : m_alwaysOutputters) {
delete m_alwaysOutputter;
}
ARCH->closeMutex(m_mutex);
}
@ -116,7 +114,7 @@ Log::getFilterName(int level) const
}
void
Log::print(const char* file, int line, const char* fmt, ...)
Log::print(const char* /*file*/, int /*line*/, const char* fmt, ...)
{
// check if fmt begins with a priority argument
ELevel priority = kINFO;
@ -125,7 +123,7 @@ Log::print(const char* file, int line, const char* fmt, ...)
// 060 in octal is 0 (48 in decimal), so subtracting this converts ascii
// number it a true number. we could use atoi instead, but this is how
// it was done originally.
priority = (ELevel)(fmt[2] - '\060');
priority = static_cast<ELevel>(fmt[2] - '\060');
// move the pointer on past the debug priority char
fmt += 3;
@ -145,7 +143,7 @@ Log::print(const char* file, int line, const char* fmt, ...)
// print to buffer, leaving space for a newline at the end and prefix
// at the beginning.
char* buffer = stack;
int len = (int)(sizeof(stack) / sizeof(stack[0]));
auto len = static_cast<int>(sizeof(stack) / sizeof(stack[0]));
while (true) {
// try printing into the buffer
va_list args;
@ -154,7 +152,7 @@ Log::print(const char* file, int line, const char* fmt, ...)
va_end(args);
// if the buffer wasn't big enough then make it bigger and try again
if (n < 0 || n > (int)len) {
if (n < 0 || n > len) {
if (buffer != stack) {
delete[] buffer;
}
@ -189,7 +187,7 @@ Log::print(const char* file, int line, const char* fmt, ...)
// assume there is no file contains over 100k lines of code
size += 6;
#endif
char* message = new char[size];
auto* message = new char[size];
#ifndef NDEBUG
sprintf(message, "[%s] %s: %s\n\t%s,%d", timestamp, g_priority[priority], buffer, file, line);
@ -256,7 +254,7 @@ Log::pop_front(bool alwaysAtHead)
bool
Log::setFilter(const char* maxPriority)
{
if (maxPriority != NULL) {
if (maxPriority != nullptr) {
for (int i = 0; i < g_numPriority; ++i) {
if (strcmp(maxPriority, g_priority[i]) == 0) {
setFilter(i);
@ -287,7 +285,8 @@ Log::output(ELevel priority, char* msg)
{
assert(priority >= -1 && priority < g_numPriority);
assert(msg != NULL);
if (!msg) return;
if (msg == nullptr) { return;
}
ArchMutexLock lock(m_mutex);

View File

@ -62,7 +62,7 @@ public:
By default, the logger has one outputter installed which writes to
the console.
*/
void insert(ILogOutputter* adopted,
void insert(ILogOutputter* outputter,
bool alwaysAtHead = false);
//! Remove an outputter from the list
@ -71,7 +71,7 @@ public:
outputter list. It does nothing if the outputter is not in the
list. The outputter is not deleted.
*/
void remove(ILogOutputter* orphaned);
void remove(ILogOutputter* outputter);
//! Remove the outputter from the head of the list
/*!
@ -89,7 +89,7 @@ public:
true if the priority \c name was recognized; if \c name is NULL
then it simply returns true.
*/
bool setFilter(const char* name);
bool setFilter(const char* maxPriority);
//! Set the minimum priority filter (by ordinal).
void setFilter(int);
@ -105,7 +105,7 @@ public:
neither the file nor the line are printed.
*/
void print(const char* file, int line,
const char* format, ...);
const char* fmt, ...);
//! Get the minimum priority level.
int getFilter() const;
@ -132,11 +132,11 @@ private:
static Log* s_log;
ArchMutex m_mutex;
ArchMutex m_mutex{};
OutputterList m_outputters;
OutputterList m_alwaysOutputters;
int m_maxNewlineLength;
int m_maxPriority;
int m_maxNewlineLength{};
int m_maxPriority{};
};
/*!

View File

@ -17,8 +17,8 @@
*/
#include "base/SimpleEventQueueBuffer.h"
#include "base/Stopwatch.h"
#include "arch/Arch.h"
#include "base/Stopwatch.h"
class EventQueueTimer { };
@ -57,7 +57,7 @@ SimpleEventQueueBuffer::waitForEvent(double timeout)
}
IEventQueueBuffer::Type
SimpleEventQueueBuffer::getEvent(Event&, UInt32& dataID)
SimpleEventQueueBuffer::getEvent(Event& /*event*/, UInt32& dataID)
{
ArchMutexLock lock(m_queueMutex);
if (!m_queueReady) {
@ -89,7 +89,7 @@ SimpleEventQueueBuffer::isEmpty() const
}
EventQueueTimer*
SimpleEventQueueBuffer::newTimer(double, bool) const
SimpleEventQueueBuffer::newTimer(double /*duration*/, bool /*oneShot*/) const
{
return new EventQueueTimer;
}

View File

@ -46,12 +46,12 @@ Stopwatch::reset()
m_mark = 0.0;
return dt;
}
else {
const double t = ARCH->time();
const double dt = t - m_mark;
m_mark = t;
return dt;
}
}
void
@ -94,7 +94,7 @@ Stopwatch::getTime()
start();
return dt;
}
else if (m_stopped) {
if (m_stopped) {
return m_mark;
}
else {
@ -119,9 +119,9 @@ Stopwatch::getTime() const
if (m_stopped) {
return m_mark;
}
else {
return ARCH->time() - m_mark;
}
}
Stopwatch::operator double() const

View File

@ -20,17 +20,17 @@
#include "common/common.h"
#include "common/stdvector.h"
#include <algorithm>
#include <algorithm>
#include <cctype>
#include <cerrno>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stdio.h>
#include <cstdarg>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cerrno>
#include <sstream>
#include <stdio.h>
namespace synergy {
namespace string {
@ -59,7 +59,7 @@ vformat(const char* fmt, va_list args)
if (*scan == '\0') {
break;
}
else if (*scan == '%') {
if (*scan == '%') {
// literal
index.push_back(0);
pos.push_back(static_cast<size_t>((scan - 1) - fmt));
@ -104,7 +104,7 @@ vformat(const char* fmt, va_list args)
// compute final length
size_t resultLength = strlen(fmt);
const int n = static_cast<int>(pos.size());
const auto n = static_cast<int>(pos.size());
for (int i = 0; i < n; ++i) {
resultLength -= width[i];
resultLength += length[index[i]];
@ -129,9 +129,9 @@ sprintf(const char* fmt, ...)
{
char tmp[1024];
char* buffer = tmp;
int len = (int)(sizeof(tmp) / sizeof(tmp[0]));
auto len = static_cast<int>(sizeof(tmp) / sizeof(tmp[0]));
String result;
while (buffer != NULL) {
while (buffer != nullptr) {
// try printing into the buffer
va_list args;
va_start(args, fmt);
@ -153,7 +153,7 @@ sprintf(const char* fmt, ...)
if (buffer != tmp) {
delete[] buffer;
}
buffer = NULL;
buffer = nullptr;
}
}
@ -190,8 +190,8 @@ toHex(String& subject, int width, const char fill)
{
std::stringstream ss;
ss << std::hex;
for (unsigned int i = 0; i < subject.length(); i++) {
ss << std::setw(width) << std::setfill(fill) << (int)(unsigned char)subject[i];
for (char i : subject) {
ss << std::setw(width) << std::setfill(fill) << static_cast<int>(static_cast<unsigned char>(i));
}
subject = ss.str();
@ -218,7 +218,7 @@ sizeTypeToString(size_t n)
}
size_t
stringToSizeType(String string)
stringToSizeType(const String& string)
{
std::istringstream iss(string);
size_t value;
@ -227,7 +227,7 @@ stringToSizeType(String string)
}
std::vector<String>
splitString(String string, const char c)
splitString(const String& string, const char c)
{
std::vector<String> results;
@ -291,5 +291,5 @@ CaselessCmp::operator()(const String& a, const String& b) const
return less(a, b);
}
}
}
} // namespace string
} // namespace synergy

View File

@ -99,13 +99,13 @@ String sizeTypeToString(size_t n);
/*!
Convert an a \c string to an size type
*/
size_t stringToSizeType(String string);
size_t stringToSizeType(const String& string);
//! Split a string into substrings
/*!
Split a \c string that separated by a \c c into substrings
*/
std::vector<String> splitString(String string, const char c);
std::vector<String> splitString(const String& string, const char c);
//! Case-insensitive comparisons
/*!

View File

@ -33,7 +33,7 @@ decode16(const UInt8* n, bool byteSwapped)
union x16 {
UInt8 n8[2];
UInt16 n16;
} c;
} c{};
if (byteSwapped) {
c.n8[0] = n[1];
c.n8[1] = n[0];
@ -53,7 +53,7 @@ decode32(const UInt8* n, bool byteSwapped)
union x32 {
UInt8 n8[4];
UInt32 n32;
} c;
} c{};
if (byteSwapped) {
c.n8[0] = n[3];
c.n8[1] = n[2];
@ -74,7 +74,7 @@ static
void
resetError(bool* errors)
{
if (errors != NULL) {
if (errors != nullptr) {
*errors = false;
}
}
@ -84,7 +84,7 @@ static
void
setError(bool* errors)
{
if (errors != NULL) {
if (errors != nullptr) {
*errors = true;
}
}
@ -101,8 +101,8 @@ bool
Unicode::isUTF8(const String& src)
{
// convert and test each character
const UInt8* data = reinterpret_cast<const UInt8*>(src.c_str());
for (UInt32 n = (UInt32)src.size(); n > 0; ) {
const auto* data = reinterpret_cast<const UInt8*>(src.c_str());
for (auto n = static_cast<UInt32>(src.size()); n > 0; ) {
if (fromUTF8(data, n) == s_invalid) {
return false;
}
@ -117,12 +117,12 @@ Unicode::UTF8ToUCS2(const String& src, bool* errors)
resetError(errors);
// get size of input string and reserve some space in output
UInt32 n = (UInt32)src.size();
auto n = static_cast<UInt32>(src.size());
String dst;
dst.reserve(2 * n);
// convert each character
const UInt8* data = reinterpret_cast<const UInt8*>(src.c_str());
const auto* data = reinterpret_cast<const UInt8*>(src.c_str());
while (n > 0) {
UInt32 c = fromUTF8(data, n);
if (c == s_invalid) {
@ -132,7 +132,7 @@ Unicode::UTF8ToUCS2(const String& src, bool* errors)
setError(errors);
c = s_replacement;
}
UInt16 ucs2 = static_cast<UInt16>(c);
auto ucs2 = static_cast<UInt16>(c);
dst.append(reinterpret_cast<const char*>(&ucs2), 2);
}
@ -146,12 +146,12 @@ Unicode::UTF8ToUCS4(const String& src, bool* errors)
resetError(errors);
// get size of input string and reserve some space in output
UInt32 n = (UInt32)src.size();
auto n = static_cast<UInt32>(src.size());
String dst;
dst.reserve(4 * n);
// convert each character
const UInt8* data = reinterpret_cast<const UInt8*>(src.c_str());
const auto* data = reinterpret_cast<const UInt8*>(src.c_str());
while (n > 0) {
UInt32 c = fromUTF8(data, n);
if (c == s_invalid) {
@ -170,12 +170,12 @@ Unicode::UTF8ToUTF16(const String& src, bool* errors)
resetError(errors);
// get size of input string and reserve some space in output
UInt32 n = (UInt32)src.size();
auto n = static_cast<UInt32>(src.size());
String dst;
dst.reserve(2 * n);
// convert each character
const UInt8* data = reinterpret_cast<const UInt8*>(src.c_str());
const auto* data = reinterpret_cast<const UInt8*>(src.c_str());
while (n > 0) {
UInt32 c = fromUTF8(data, n);
if (c == s_invalid) {
@ -186,13 +186,13 @@ Unicode::UTF8ToUTF16(const String& src, bool* errors)
c = s_replacement;
}
if (c < 0x00010000) {
UInt16 ucs2 = static_cast<UInt16>(c);
auto ucs2 = static_cast<UInt16>(c);
dst.append(reinterpret_cast<const char*>(&ucs2), 2);
}
else {
c -= 0x00010000;
UInt16 utf16h = static_cast<UInt16>((c >> 10) + 0xd800);
UInt16 utf16l = static_cast<UInt16>((c & 0x03ff) + 0xdc00);
auto utf16h = static_cast<UInt16>((c >> 10) + 0xd800);
auto utf16l = static_cast<UInt16>((c & 0x03ff) + 0xdc00);
dst.append(reinterpret_cast<const char*>(&utf16h), 2);
dst.append(reinterpret_cast<const char*>(&utf16l), 2);
}
@ -208,12 +208,12 @@ Unicode::UTF8ToUTF32(const String& src, bool* errors)
resetError(errors);
// get size of input string and reserve some space in output
UInt32 n = (UInt32)src.size();
auto n = static_cast<UInt32>(src.size());
String dst;
dst.reserve(4 * n);
// convert each character
const UInt8* data = reinterpret_cast<const UInt8*>(src.c_str());
const auto* data = reinterpret_cast<const UInt8*>(src.c_str());
while (n > 0) {
UInt32 c = fromUTF8(data, n);
if (c == s_invalid) {
@ -240,8 +240,8 @@ Unicode::UTF8ToText(const String& src, bool* errors)
wchar_t* tmp = UTF8ToWideChar(src, size, errors);
// convert string to multibyte
int len = ARCH->convStringWCToMB(NULL, tmp, size, errors);
char* mbs = new char[len + 1];
int len = ARCH->convStringWCToMB(nullptr, tmp, size, errors);
auto* mbs = new char[len + 1];
ARCH->convStringWCToMB(mbs, tmp, size, errors);
String text(mbs, len);
@ -259,7 +259,7 @@ Unicode::UCS2ToUTF8(const String& src, bool* errors)
resetError(errors);
// convert
UInt32 n = (UInt32)src.size() >> 1;
UInt32 n = static_cast<UInt32>(src.size()) >> 1;
return doUCS2ToUTF8(reinterpret_cast<const UInt8*>(src.data()), n, errors);
}
@ -270,7 +270,7 @@ Unicode::UCS4ToUTF8(const String& src, bool* errors)
resetError(errors);
// convert
UInt32 n = (UInt32)src.size() >> 2;
UInt32 n = static_cast<UInt32>(src.size()) >> 2;
return doUCS4ToUTF8(reinterpret_cast<const UInt8*>(src.data()), n, errors);
}
@ -281,7 +281,7 @@ Unicode::UTF16ToUTF8(const String& src, bool* errors)
resetError(errors);
// convert
UInt32 n = (UInt32)src.size() >> 1;
UInt32 n = static_cast<UInt32>(src.size()) >> 1;
return doUTF16ToUTF8(reinterpret_cast<const UInt8*>(src.data()), n, errors);
}
@ -292,7 +292,7 @@ Unicode::UTF32ToUTF8(const String& src, bool* errors)
resetError(errors);
// convert
UInt32 n = (UInt32)src.size() >> 2;
UInt32 n = static_cast<UInt32>(src.size()) >> 2;
return doUTF32ToUTF8(reinterpret_cast<const UInt8*>(src.data()), n, errors);
}
@ -303,9 +303,9 @@ Unicode::textToUTF8(const String& src, bool* errors)
resetError(errors);
// convert string to wide characters
UInt32 n = (UInt32)src.size();
int len = ARCH->convStringMBToWC(NULL, src.c_str(), n, errors);
wchar_t* wcs = new wchar_t[len + 1];
auto n = static_cast<UInt32>(src.size());
int len = ARCH->convStringMBToWC(nullptr, src.c_str(), n, errors);
auto* wcs = new wchar_t[len + 1];
ARCH->convStringMBToWC(wcs, src.c_str(), n, errors);
// convert to UTF8
@ -325,22 +325,22 @@ Unicode::UTF8ToWideChar(const String& src, UInt32& size, bool* errors)
switch (ARCH->getWideCharEncoding()) {
case IArchString::kUCS2:
tmp = UTF8ToUCS2(src, errors);
size = (UInt32)tmp.size() >> 1;
size = static_cast<UInt32>(tmp.size()) >> 1;
break;
case IArchString::kUCS4:
tmp = UTF8ToUCS4(src, errors);
size = (UInt32)tmp.size() >> 2;
size = static_cast<UInt32>(tmp.size()) >> 2;
break;
case IArchString::kUTF16:
tmp = UTF8ToUTF16(src, errors);
size = (UInt32)tmp.size() >> 1;
size = static_cast<UInt32>(tmp.size()) >> 1;
break;
case IArchString::kUTF32:
tmp = UTF8ToUTF32(src, errors);
size = (UInt32)tmp.size() >> 2;
size = static_cast<UInt32>(tmp.size()) >> 2;
break;
default:
@ -348,7 +348,7 @@ Unicode::UTF8ToWideChar(const String& src, UInt32& size, bool* errors)
}
// copy to a wchar_t array
wchar_t* dst = new wchar_t[size];
auto* dst = new wchar_t[size];
::memcpy(dst, tmp.data(), sizeof(wchar_t) * size);
return dst;
}
@ -486,7 +486,7 @@ Unicode::doUTF16ToUTF8(const UInt8* data, UInt32 n, bool* errors)
else if (n == 1) {
// error -- missing second word
setError(errors);
toUTF8(dst, s_replacement, NULL);
toUTF8(dst, s_replacement, nullptr);
}
else if (c >= 0x0000d800 && c <= 0x0000dbff) {
UInt32 c2 = decode16(data, byteSwapped);
@ -495,7 +495,7 @@ Unicode::doUTF16ToUTF8(const UInt8* data, UInt32 n, bool* errors)
if (c2 < 0x0000dc00 || c2 > 0x0000dfff) {
// error -- [d800,dbff] not followed by [dc00,dfff]
setError(errors);
toUTF8(dst, s_replacement, NULL);
toUTF8(dst, s_replacement, nullptr);
}
else {
c = (((c - 0x0000d800) << 10) | (c2 - 0x0000dc00)) + 0x00010000;
@ -505,7 +505,7 @@ Unicode::doUTF16ToUTF8(const UInt8* data, UInt32 n, bool* errors)
else {
// error -- [dc00,dfff] without leading [d800,dbff]
setError(errors);
toUTF8(dst, s_replacement, NULL);
toUTF8(dst, s_replacement, nullptr);
}
}

View File

@ -129,13 +129,13 @@ private:
UInt32 size, bool* errors);
// internal conversion to UTF8
static String doUCS2ToUTF8(const UInt8* src, UInt32 n, bool* errors);
static String doUCS4ToUTF8(const UInt8* src, UInt32 n, bool* errors);
static String doUTF16ToUTF8(const UInt8* src, UInt32 n, bool* errors);
static String doUTF32ToUTF8(const UInt8* src, UInt32 n, bool* errors);
static String doUCS2ToUTF8(const UInt8* data, UInt32 n, bool* errors);
static String doUCS4ToUTF8(const UInt8* data, UInt32 n, bool* errors);
static String doUTF16ToUTF8(const UInt8* data, UInt32 n, bool* errors);
static String doUTF32ToUTF8(const UInt8* data, UInt32 n, bool* errors);
// convert characters to/from UTF8
static UInt32 fromUTF8(const UInt8*& src, UInt32& size);
static UInt32 fromUTF8(const UInt8*& data, UInt32& n);
static void toUTF8(String& dst, UInt32 c, bool* errors);
private:

View File

@ -38,13 +38,13 @@ XBase::XBase(const String& msg) :
// do nothing
}
XBase::~XBase() _NOEXCEPT
XBase::~XBase() noexcept
{
// do nothing
}
const char*
XBase::what() const _NOEXCEPT
XBase::what() const noexcept
{
const char* what = std::runtime_error::what();
if (strlen(what) == 0) {
@ -55,7 +55,7 @@ XBase::what() const _NOEXCEPT
}
String
XBase::format(const char* /*id*/, const char* fmt, ...) const throw()
XBase::format(const char* /*id*/, const char* fmt, ...) const noexcept
{
// FIXME -- lookup message string using id as an index. set
// fmt to that string if it exists.

View File

@ -47,7 +47,7 @@ protected:
the format string and returns the result.
*/
virtual String format(const char* id,
const char* defaultFormat, ...) const throw();
const char* fmt, ...) const throw();
private:
mutable String m_what;
};

View File

@ -17,8 +17,8 @@
*/
#include "base/log_outputters.h"
#include "base/TMethodJob.h"
#include "arch/Arch.h"
#include "base/TMethodJob.h"
#include <fstream>
@ -41,7 +41,7 @@ StopLogOutputter::~StopLogOutputter()
}
void
StopLogOutputter::open(const char*)
StopLogOutputter::open(const char* /*title*/)
{
// do nothing
}
@ -53,13 +53,13 @@ StopLogOutputter::close()
}
void
StopLogOutputter::show(bool)
StopLogOutputter::show(bool /*showIfEmpty*/)
{
// do nothing
}
bool
StopLogOutputter::write(ELevel, const char*)
StopLogOutputter::write(ELevel /*level*/, const char* /*message*/)
{
return false;
}
@ -70,12 +70,10 @@ StopLogOutputter::write(ELevel, const char*)
//
ConsoleLogOutputter::ConsoleLogOutputter()
{
}
= default;
ConsoleLogOutputter::~ConsoleLogOutputter()
{
}
= default;
void
ConsoleLogOutputter::open(const char* title)
@ -153,7 +151,7 @@ SystemLogOutputter::write(ELevel level, const char* msg)
//
SystemLogger::SystemLogger(const char* title, bool blockConsole) :
m_stop(NULL)
m_stop(nullptr)
{
// redirect log messages
if (blockConsole) {
@ -169,7 +167,7 @@ SystemLogger::~SystemLogger()
{
CLOG->remove(m_syslog);
delete m_syslog;
if (m_stop != NULL) {
if (m_stop != nullptr) {
CLOG->remove(m_stop);
delete m_stop;
}
@ -204,7 +202,7 @@ BufferedLogOutputter::end() const
}
void
BufferedLogOutputter::open(const char*)
BufferedLogOutputter::open(const char* /*title*/)
{
// do nothing
}
@ -217,18 +215,18 @@ BufferedLogOutputter::close()
}
void
BufferedLogOutputter::show(bool)
BufferedLogOutputter::show(bool /*showIfEmpty*/)
{
// do nothing
}
bool
BufferedLogOutputter::write(ELevel, const char* message)
BufferedLogOutputter::write(ELevel /*level*/, const char* message)
{
while (m_buffer.size() >= m_maxBufferSize) {
m_buffer.pop_front();
}
m_buffer.push_back(String(message));
m_buffer.emplace_back(message);
return true;
}
@ -243,8 +241,7 @@ FileLogOutputter::FileLogOutputter(const char* logFile)
}
FileLogOutputter::~FileLogOutputter()
{
}
= default;
void
FileLogOutputter::setLogFilename(const char* logFile)
@ -254,13 +251,13 @@ FileLogOutputter::setLogFilename(const char* logFile)
}
bool
FileLogOutputter::write(ELevel level, const char *message)
FileLogOutputter::write(ELevel /*level*/, const char *message)
{
bool moveFile = false;
std::ofstream m_handle;
m_handle.open(m_fileName.c_str(), std::fstream::app);
if (m_handle.is_open() && m_handle.fail() != true) {
if (m_handle.is_open() && !m_handle.fail()) {
m_handle << message << std::endl;
// when file size exceeds limits, move to 'old log' filename.
@ -281,13 +278,13 @@ FileLogOutputter::write(ELevel level, const char *message)
}
void
FileLogOutputter::open(const char *title) {}
FileLogOutputter::open(const char * /*title*/) {}
void
FileLogOutputter::close() {}
void
FileLogOutputter::show(bool showIfEmpty) {}
FileLogOutputter::show(bool /*showIfEmpty*/) {}
//
// MesssageBoxLogOutputter
@ -304,7 +301,7 @@ MesssageBoxLogOutputter::~MesssageBoxLogOutputter()
}
void
MesssageBoxLogOutputter::open(const char* title)
MesssageBoxLogOutputter::open(const char* /*title*/)
{
// do nothing
}
@ -316,13 +313,13 @@ MesssageBoxLogOutputter::close()
}
void
MesssageBoxLogOutputter::show(bool showIfEmpty)
MesssageBoxLogOutputter::show(bool /*showIfEmpty*/)
{
// do nothing
}
bool
MesssageBoxLogOutputter::write(ELevel level, const char* msg)
MesssageBoxLogOutputter::write(ELevel level, const char* /*msg*/)
{
// don't spam user with messages.
if (level > kERROR) {

View File

@ -59,7 +59,7 @@ public:
virtual void open(const char* title);
virtual void close();
virtual void show(bool showIfEmpty);
virtual bool write(ELevel level, const char* message);
virtual bool write(ELevel level, const char* msg);
virtual void flush();
};
@ -80,7 +80,7 @@ public:
virtual void show(bool showIfEmpty);
virtual bool write(ELevel level, const char* message);
void setLogFilename(const char* title);
void setLogFilename(const char* logFile);
private:
std::string m_fileName;
@ -99,7 +99,7 @@ public:
virtual void open(const char* title);
virtual void close();
virtual void show(bool showIfEmpty);
virtual bool write(ELevel level, const char* message);
virtual bool write(ELevel level, const char* msg);
};
//! Write log to system log only

View File

@ -18,31 +18,32 @@
#include "client/Client.h"
#include "client/ServerProxy.h"
#include "core/Screen.h"
#include "core/FileChunk.h"
#include "core/DropHelper.h"
#include "core/PacketStreamFilter.h"
#include "core/ProtocolUtil.h"
#include "core/protocol_types.h"
#include "core/XSynergy.h"
#include "core/StreamChunker.h"
#include "core/IPlatformScreen.h"
#include "mt/Thread.h"
#include "net/TCPSocket.h"
#include "net/IDataSocket.h"
#include "net/ISocketFactory.h"
#include "arch/Arch.h"
#include "base/Log.h"
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "base/TMethodJob.h"
#include "client/ServerProxy.h"
#include "common/stdexcept.h"
#include "core/DropHelper.h"
#include "core/FileChunk.h"
#include "core/IPlatformScreen.h"
#include "core/PacketStreamFilter.h"
#include "core/ProtocolUtil.h"
#include "core/Screen.h"
#include "core/StreamChunker.h"
#include "core/XSynergy.h"
#include "core/protocol_types.h"
#include "mt/Thread.h"
#include "net/IDataSocket.h"
#include "net/ISocketFactory.h"
#include "net/TCPSocket.h"
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <fstream>
#include <sstream>
#include <utility>
//
// Client
@ -50,27 +51,27 @@
Client::Client(
IEventQueue* events,
const String& name, const NetworkAddress& address,
String name, const NetworkAddress& address,
ISocketFactory* socketFactory,
synergy::Screen* screen,
ClientArgs const& args) :
ClientArgs args) :
m_mock(false),
m_name(name),
m_name(std::move(name)),
m_serverAddress(address),
m_socketFactory(socketFactory),
m_screen(screen),
m_stream(NULL),
m_timer(NULL),
m_server(NULL),
m_stream(nullptr),
m_timer(nullptr),
m_server(nullptr),
m_ready(false),
m_active(false),
m_suspended(false),
m_connectOnResume(false),
m_events(events),
m_sendFileThread(NULL),
m_writeToDropDirThread(NULL),
m_socket(NULL),
m_args(args),
m_sendFileThread(nullptr),
m_writeToDropDirThread(nullptr),
m_socket(nullptr),
m_args(std::move(args)),
m_enableClipboard(true)
{
assert(m_socketFactory != NULL);
@ -119,7 +120,7 @@ Client::~Client()
void
Client::connect()
{
if (m_stream != NULL) {
if (m_stream != nullptr) {
return;
}
if (m_suspended) {
@ -136,7 +137,7 @@ Client::connect()
m_serverAddress.resolve();
// m_serverAddress will be null if the hostname address is not reolved
if (m_serverAddress.getAddress() != NULL) {
if (m_serverAddress.getAddress() != nullptr) {
// to help users troubleshoot, show server host name (issue: 60)
LOG((CLOG_NOTE "connecting to '%s': %s:%i",
m_serverAddress.getHostname().c_str(),
@ -176,11 +177,11 @@ Client::disconnect(const char* msg)
cleanupScreen();
cleanupConnecting();
cleanupConnection();
if (msg != NULL) {
if (msg != nullptr) {
sendConnectionFailedEvent(msg);
}
else {
sendEvent(m_events->forClient().disconnected(), NULL);
sendEvent(m_events->forClient().disconnected(), nullptr);
}
}
@ -189,19 +190,19 @@ Client::handshakeComplete()
{
m_ready = true;
m_screen->enable();
sendEvent(m_events->forClient().connected(), NULL);
sendEvent(m_events->forClient().connected(), nullptr);
}
bool
Client::isConnected() const
{
return (m_server != NULL);
return (m_server != nullptr);
}
bool
Client::isConnecting() const
{
return (m_timer != NULL);
return (m_timer != nullptr);
}
NetworkAddress
@ -235,15 +236,15 @@ Client::getCursorPos(SInt32& x, SInt32& y) const
}
void
Client::enter(SInt32 xAbs, SInt32 yAbs, UInt32, KeyModifierMask mask, bool)
Client::enter(SInt32 xAbs, SInt32 yAbs, UInt32 /*seqNum*/, KeyModifierMask mask, bool /*forScreensaver*/)
{
m_active = true;
m_screen->mouseMove(xAbs, yAbs);
m_screen->enter(mask);
if (m_sendFileThread != NULL) {
if (m_sendFileThread != nullptr) {
StreamChunker::interruptFile();
m_sendFileThread = NULL;
m_sendFileThread = nullptr;
}
}
@ -283,7 +284,7 @@ Client::grabClipboard(ClipboardID id)
}
void
Client::setClipboardDirty(ClipboardID, bool)
Client::setClipboardDirty(ClipboardID /*unused*/, bool /*dirty*/)
{
assert(0 && "shouldn't be called");
}
@ -352,7 +353,7 @@ Client::resetOptions()
void
Client::setOptions(const OptionsList& options)
{
for (OptionsList::const_iterator index = options.begin();
for (auto index = options.begin();
index != options.end(); ++index) {
const OptionID id = *index;
if (id == kOptionClipboardSharing) {
@ -360,7 +361,7 @@ Client::setOptions(const OptionsList& options)
if (*index == static_cast<OptionValue>(false)) {
LOG((CLOG_NOTE "clipboard sharing is disabled"));
}
m_enableClipboard = *index;
m_enableClipboard = (*index != 0u);
break;
}
@ -419,7 +420,7 @@ Client::sendEvent(Event::Type type, void* data)
void
Client::sendConnectionFailedEvent(const char* msg)
{
FailInfo* info = new FailInfo(msg);
auto* info = new FailInfo(msg);
info->m_retry = true;
Event event(m_events->forClient().connectionFailed(), getEventTarget(), info, Event::kDontFreeData);
m_events->addEvent(event);
@ -428,7 +429,7 @@ Client::sendConnectionFailedEvent(const char* msg)
void
Client::sendFileChunk(const void* data)
{
FileChunk* chunk = static_cast<FileChunk*>(const_cast<void*>(data));
auto* chunk = static_cast<FileChunk*>(const_cast<void*>(data));
LOG((CLOG_DEBUG1 "send file chunk"));
assert(m_server != NULL);
@ -505,7 +506,7 @@ Client::setupTimer()
{
assert(m_timer == NULL);
m_timer = m_events->newOneShotTimer(15.0, NULL);
m_timer = m_events->newOneShotTimer(15.0, nullptr);
m_events->adoptHandler(Event::kTimer, m_timer,
new TMethodEventJob<Client>(this,
&Client::handleConnectTimeout));
@ -514,7 +515,7 @@ Client::setupTimer()
void
Client::cleanupConnecting()
{
if (m_stream != NULL) {
if (m_stream != nullptr) {
m_events->removeHandler(m_events->forIDataSocket().connected(),
m_stream->getEventTarget());
m_events->removeHandler(m_events->forIDataSocket().connectionFailed(),
@ -525,7 +526,7 @@ Client::cleanupConnecting()
void
Client::cleanupConnection()
{
if (m_stream != NULL) {
if (m_stream != nullptr) {
m_events->removeHandler(m_events->forIStream().inputReady(),
m_stream->getEventTarget());
m_events->removeHandler(m_events->forIStream().outputError(),
@ -545,7 +546,7 @@ Client::cleanupConnection()
void
Client::cleanupScreen()
{
if (m_server != NULL) {
if (m_server != nullptr) {
if (m_ready) {
m_screen->disable();
m_ready = false;
@ -555,17 +556,17 @@ Client::cleanupScreen()
m_events->removeHandler(m_events->forClipboard().clipboardGrabbed(),
getEventTarget());
delete m_server;
m_server = NULL;
m_server = nullptr;
}
}
void
Client::cleanupTimer()
{
if (m_timer != NULL) {
if (m_timer != nullptr) {
m_events->removeHandler(Event::kTimer, m_timer);
m_events->deleteTimer(m_timer);
m_timer = NULL;
m_timer = nullptr;
}
}
@ -573,11 +574,11 @@ void
Client::cleanupStream()
{
delete m_stream;
m_stream = NULL;
m_stream = nullptr;
}
void
Client::handleConnected(const Event&, void*)
Client::handleConnected(const Event& /*unused*/, void* /*unused*/)
{
LOG((CLOG_DEBUG1 "connected; wait for hello"));
cleanupConnecting();
@ -592,9 +593,9 @@ Client::handleConnected(const Event&, void*)
}
void
Client::handleConnectionFailed(const Event& event, void*)
Client::handleConnectionFailed(const Event& event, void* /*unused*/)
{
IDataSocket::ConnectionFailedInfo* info =
auto* info =
static_cast<IDataSocket::ConnectionFailedInfo*>(event.getData());
cleanupTimer();
@ -606,7 +607,7 @@ Client::handleConnectionFailed(const Event& event, void*)
}
void
Client::handleConnectTimeout(const Event&, void*)
Client::handleConnectTimeout(const Event& /*unused*/, void* /*unused*/)
{
cleanupTimer();
cleanupConnecting();
@ -617,40 +618,40 @@ Client::handleConnectTimeout(const Event&, void*)
}
void
Client::handleOutputError(const Event&, void*)
Client::handleOutputError(const Event& /*unused*/, void* /*unused*/)
{
cleanupTimer();
cleanupScreen();
cleanupConnection();
LOG((CLOG_WARN "error sending to server"));
sendEvent(m_events->forClient().disconnected(), NULL);
sendEvent(m_events->forClient().disconnected(), nullptr);
}
void
Client::handleDisconnected(const Event&, void*)
Client::handleDisconnected(const Event& /*unused*/, void* /*unused*/)
{
cleanupTimer();
cleanupScreen();
cleanupConnection();
LOG((CLOG_DEBUG1 "disconnected"));
sendEvent(m_events->forClient().disconnected(), NULL);
sendEvent(m_events->forClient().disconnected(), nullptr);
}
void
Client::handleShapeChanged(const Event&, void*)
Client::handleShapeChanged(const Event& /*unused*/, void* /*unused*/)
{
LOG((CLOG_DEBUG "resolution changed"));
m_server->onInfoChanged();
}
void
Client::handleClipboardGrabbed(const Event& event, void*)
Client::handleClipboardGrabbed(const Event& event, void* /*unused*/)
{
if (!m_enableClipboard) {
return;
}
const IScreen::ClipboardInfo* info =
const auto* info =
static_cast<const IScreen::ClipboardInfo*>(event.getData());
// grab ownership
@ -669,7 +670,7 @@ Client::handleClipboardGrabbed(const Event& event, void*)
}
void
Client::handleHello(const Event&, void*)
Client::handleHello(const Event& /*unused*/, void* /*unused*/)
{
SInt16 major, minor;
if (!ProtocolUtil::readf(m_stream, kMsgHello, &major, &minor)) {
@ -709,17 +710,17 @@ Client::handleHello(const Event&, void*)
}
void
Client::handleSuspend(const Event&, void*)
Client::handleSuspend(const Event& /*unused*/, void* /*unused*/)
{
LOG((CLOG_INFO "suspend"));
m_suspended = true;
bool wasConnected = isConnected();
disconnect(NULL);
disconnect(nullptr);
m_connectOnResume = wasConnected;
}
void
Client::handleResume(const Event&, void*)
Client::handleResume(const Event& /*unused*/, void* /*unused*/)
{
LOG((CLOG_INFO "resume"));
m_suspended = false;
@ -730,13 +731,13 @@ Client::handleResume(const Event&, void*)
}
void
Client::handleFileChunkSending(const Event& event, void*)
Client::handleFileChunkSending(const Event& event, void* /*unused*/)
{
sendFileChunk(event.getData());
}
void
Client::handleFileRecieveCompleted(const Event& event, void*)
Client::handleFileRecieveCompleted(const Event& /*event*/, void* /*unused*/)
{
onFileRecieveCompleted();
}
@ -752,13 +753,13 @@ Client::onFileRecieveCompleted()
}
void
Client::handleStopRetry(const Event&, void*)
Client::handleStopRetry(const Event& /*unused*/, void* /*unused*/)
{
m_args.m_restartable = false;
}
void
Client::writeToDropDirThread(void*)
Client::writeToDropDirThread(void* /*unused*/)
{
LOG((CLOG_DEBUG "starting write to drop dir thread"));
@ -773,13 +774,13 @@ Client::writeToDropDirThread(void*)
void
Client::dragInfoReceived(UInt32 fileNum, String data)
{
// TODO: fix duplicate function from CServer
// TODO(andrew): fix duplicate function from CServer
if (!m_args.m_enableDragDrop) {
LOG((CLOG_DEBUG "drag drop not enabled, ignoring drag info."));
return;
}
DragInformation::parseDragInfo(m_dragFileList, fileNum, data);
DragInformation::parseDragInfo(m_dragFileList, fileNum, std::move(data));
m_screen->startDraggingFiles(m_dragFileList);
}
@ -793,7 +794,7 @@ Client::isReceivedFileSizeValid()
void
Client::sendFileToServer(const char* filename)
{
if (m_sendFileThread != NULL) {
if (m_sendFileThread != nullptr) {
StreamChunker::interruptFile();
}
@ -807,14 +808,14 @@ void
Client::sendFileThread(void* filename)
{
try {
char* name = static_cast<char*>(filename);
auto* name = static_cast<char*>(filename);
StreamChunker::sendFile(name, m_events, this);
}
catch (std::runtime_error& error) {
LOG((CLOG_ERR "failed sending file chunks: %s", error.what()));
}
m_sendFileThread = NULL;
m_sendFileThread = nullptr;
}
void

View File

@ -57,9 +57,9 @@ public:
as its name and \p address as the server's address and \p factory
to create the socket. \p screen is the local screen.
*/
Client(IEventQueue* events, const String& name,
Client(IEventQueue* events, String name,
const NetworkAddress& address, ISocketFactory* socketFactory,
synergy::Screen* screen, ClientArgs const& args);
synergy::Screen* screen, ClientArgs args);
~Client();
@ -137,7 +137,7 @@ public:
virtual void* getEventTarget() const;
virtual bool getClipboard(ClipboardID id, IClipboard*) const;
virtual void getShape(SInt32& x, SInt32& y,
SInt32& width, SInt32& height) const;
SInt32& w, SInt32& h) const;
virtual void getCursorPos(SInt32& x, SInt32& y) const;
// IClient overrides
@ -154,8 +154,8 @@ public:
virtual void keyUp(KeyID, KeyModifierMask, KeyButton);
virtual void mouseDown(ButtonID);
virtual void mouseUp(ButtonID);
virtual void mouseMove(SInt32 xAbs, SInt32 yAbs);
virtual void mouseRelativeMove(SInt32 xRel, SInt32 yRel);
virtual void mouseMove(SInt32 x, SInt32 y);
virtual void mouseRelativeMove(SInt32 dx, SInt32 dy);
virtual void mouseWheel(SInt32 xDelta, SInt32 yDelta);
virtual void screensaver(bool activate);
virtual void resetOptions();
@ -209,12 +209,12 @@ private:
bool m_active;
bool m_suspended;
bool m_connectOnResume;
bool m_ownClipboard[kClipboardEnd];
bool m_sentClipboard[kClipboardEnd];
IClipboard::Time m_timeClipboard[kClipboardEnd];
bool m_ownClipboard[kClipboardEnd]{};
bool m_sentClipboard[kClipboardEnd]{};
IClipboard::Time m_timeClipboard[kClipboardEnd]{};
String m_dataClipboard[kClipboardEnd];
IEventQueue* m_events;
std::size_t m_expectedFileSize;
std::size_t m_expectedFileSize{};
String m_receivedFileData;
DragFileList m_dragFileList;
String m_dragFileExt;

View File

@ -18,19 +18,19 @@
#include "client/ServerProxy.h"
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "base/XBase.h"
#include "client/Client.h"
#include "core/FileChunk.h"
#include "core/ClipboardChunk.h"
#include "core/StreamChunker.h"
#include "core/Clipboard.h"
#include "core/ClipboardChunk.h"
#include "core/FileChunk.h"
#include "core/ProtocolUtil.h"
#include "core/StreamChunker.h"
#include "core/option_types.h"
#include "core/protocol_types.h"
#include "io/IStream.h"
#include "base/Log.h"
#include "base/IEventQueue.h"
#include "base/TMethodEventJob.h"
#include "base/XBase.h"
#include <memory>
@ -50,7 +50,7 @@ ServerProxy::ServerProxy(Client* client, synergy::IStream* stream, IEventQueue*
m_dyMouse(0),
m_ignoreMouse(false),
m_keepAliveAlarm(0.0),
m_keepAliveAlarmTimer(NULL),
m_keepAliveAlarmTimer(nullptr),
m_parser(&ServerProxy::parseHandshakeMessage),
m_events(events)
{
@ -58,8 +58,9 @@ ServerProxy::ServerProxy(Client* client, synergy::IStream* stream, IEventQueue*
assert(m_stream != NULL);
// initialize modifier translation table
for (KeyModifierID id = 0; id < kKeyModifierIDLast; ++id)
for (KeyModifierID id = 0; id < kKeyModifierIDLast; ++id) {
m_modifierTranslationTable[id] = id;
}
// handle data on stream
m_events->adoptHandler(m_events->forIStream().inputReady(),
@ -86,14 +87,14 @@ ServerProxy::~ServerProxy()
void
ServerProxy::resetKeepAliveAlarm()
{
if (m_keepAliveAlarmTimer != NULL) {
if (m_keepAliveAlarmTimer != nullptr) {
m_events->removeHandler(Event::kTimer, m_keepAliveAlarmTimer);
m_events->deleteTimer(m_keepAliveAlarmTimer);
m_keepAliveAlarmTimer = NULL;
m_keepAliveAlarmTimer = nullptr;
}
if (m_keepAliveAlarm > 0.0) {
m_keepAliveAlarmTimer =
m_events->newOneShotTimer(m_keepAliveAlarm, NULL);
m_events->newOneShotTimer(m_keepAliveAlarm, nullptr);
m_events->adoptHandler(Event::kTimer, m_keepAliveAlarmTimer,
new TMethodEventJob<ServerProxy>(this,
&ServerProxy::handleKeepAliveAlarm));
@ -108,7 +109,7 @@ ServerProxy::setKeepAliveRate(double rate)
}
void
ServerProxy::handleData(const Event&, void*)
ServerProxy::handleData(const Event& /*unused*/, void* /*unused*/)
{
// handle messages until there are no more. first read message code.
UInt8 code[4];
@ -179,7 +180,7 @@ ServerProxy::parseHandshakeMessage(const UInt8* code)
else if (memcmp(code, kMsgCClose, 4) == 0) {
// server wants us to hangup
LOG((CLOG_DEBUG1 "recv close"));
m_client->disconnect(NULL);
m_client->disconnect(nullptr);
return kDisconnect;
}
@ -307,7 +308,7 @@ ServerProxy::parseMessage(const UInt8* code)
else if (memcmp(code, kMsgCClose, 4) == 0) {
// server wants us to hangup
LOG((CLOG_DEBUG1 "recv close"));
m_client->disconnect(NULL);
m_client->disconnect(nullptr);
return kDisconnect;
}
else if (memcmp(code, kMsgEBad, 4) == 0) {
@ -332,7 +333,7 @@ ServerProxy::parseMessage(const UInt8* code)
}
void
ServerProxy::handleKeepAliveAlarm(const Event&, void*)
ServerProxy::handleKeepAliveAlarm(const Event& /*unused*/, void* /*unused*/)
{
LOG((CLOG_NOTE "server is dead"));
m_client->disconnect("server is not responding");
@ -466,9 +467,9 @@ ServerProxy::translateKey(KeyID id) const
if (id2 != kKeyModifierIDNull) {
return s_translationTable[m_modifierTranslationTable[id2]][side];
}
else {
return id;
}
}
KeyModifierMask
@ -605,8 +606,9 @@ ServerProxy::keyDown()
KeyModifierMask mask2 = translateModifierMask(
static_cast<KeyModifierMask>(mask));
if (id2 != static_cast<KeyID>(id) ||
mask2 != static_cast<KeyModifierMask>(mask))
mask2 != static_cast<KeyModifierMask>(mask)) {
LOG((CLOG_DEBUG1 "key down translated to id=0x%08x, mask=0x%04x", id2, mask2));
}
// forward
m_client->keyDown(id2, mask2, button);
@ -629,8 +631,9 @@ ServerProxy::keyRepeat()
KeyModifierMask mask2 = translateModifierMask(
static_cast<KeyModifierMask>(mask));
if (id2 != static_cast<KeyID>(id) ||
mask2 != static_cast<KeyModifierMask>(mask))
mask2 != static_cast<KeyModifierMask>(mask)) {
LOG((CLOG_DEBUG1 "key repeat translated to id=0x%08x, mask=0x%04x", id2, mask2));
}
// forward
m_client->keyRepeat(id2, mask2, count, button);
@ -652,8 +655,9 @@ ServerProxy::keyUp()
KeyModifierMask mask2 = translateModifierMask(
static_cast<KeyModifierMask>(mask));
if (id2 != static_cast<KeyID>(id) ||
mask2 != static_cast<KeyModifierMask>(mask))
mask2 != static_cast<KeyModifierMask>(mask)) {
LOG((CLOG_DEBUG1 "key up translated to id=0x%08x, mask=0x%04x", id2, mask2));
}
// forward
m_client->keyUp(id2, mask2, button);
@ -809,7 +813,7 @@ ServerProxy::setOptions()
m_client->setOptions(options);
// update modifier table
for (UInt32 i = 0, n = (UInt32)options.size(); i < n; i += 2) {
for (UInt32 i = 0, n = static_cast<UInt32>(options.size()); i < n; i += 2) {
KeyModifierID id = kKeyModifierIDNull;
if (options[i] == kOptionModifierMapForShift) {
id = kKeyModifierIDShift;
@ -845,7 +849,7 @@ ServerProxy::setOptions()
void
ServerProxy::queryInfo()
{
ClientInfo info;
ClientInfo info{};
m_client->getShape(info.m_x, info.m_y, info.m_w, info.m_h);
m_client->getCursorPos(info.m_mx, info.m_my);
sendInfo(info);
@ -870,7 +874,7 @@ ServerProxy::fileChunkReceived()
m_events->addEvent(Event(m_events->forFile().fileRecieveCompleted(), m_client));
}
else if (result == kStart) {
if (m_client->getDragFileList().size() > 0) {
if (!m_client->getDragFileList().empty()) {
String filename = m_client->getDragFileList().at(0).getFilename();
LOG((CLOG_DEBUG "start receiving %s", filename.c_str()));
}
@ -889,7 +893,7 @@ ServerProxy::dragInfoReceived()
}
void
ServerProxy::handleClipboardSendingEvent(const Event& event, void*)
ServerProxy::handleClipboardSendingEvent(const Event& event, void* /*unused*/)
{
ClipboardChunk::send(m_stream, event.getData());
}

View File

@ -123,7 +123,7 @@ private:
bool m_ignoreMouse;
KeyModifierID m_modifierTranslationTable[kKeyModifierIDLast];
KeyModifierID m_modifierTranslationTable[kKeyModifierIDLast]{};
double m_keepAliveAlarm;
EventQueueTimer* m_keepAliveAlarmTimer;

View File

@ -18,23 +18,23 @@
#include "core/App.h"
#include "base/Log.h"
#include "common/Version.h"
#include "core/protocol_types.h"
#include "arch/Arch.h"
#include "base/XBase.h"
#include "arch/XArch.h"
#include "base/log_outputters.h"
#include "core/XSynergy.h"
#include "core/ArgsBase.h"
#include "ipc/IpcServerProxy.h"
#include "base/TMethodEventJob.h"
#include "ipc/IpcMessage.h"
#include "ipc/Ipc.h"
#include "base/EventQueue.h"
#include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "base/XBase.h"
#include "base/log_outputters.h"
#include "common/Version.h"
#include "core/ArgsBase.h"
#include "core/XSynergy.h"
#include "core/protocol_types.h"
#include "ipc/Ipc.h"
#include "ipc/IpcMessage.h"
#include "ipc/IpcServerProxy.h"
#include <iostream>
#include <stdio.h>
#include <cstdio>
#if SYSAPI_WIN32
#include "arch/win32/ArchMiscWindows.h"
@ -137,7 +137,7 @@ App::run(int argc, char** argv)
}
int
App::daemonMainLoop(int, const char**)
App::daemonMainLoop(int /*unused*/, const char** /*unused*/)
{
#if SYSAPI_WIN32
SystemLogger sysLogger(daemonName(), false);
@ -150,7 +150,7 @@ App::daemonMainLoop(int, const char**)
void
App::setupFileLogging()
{
if (argsBase().m_logFile != NULL) {
if (argsBase().m_logFile != nullptr) {
m_fileLog = new FileLogOutputter(argsBase().m_logFile);
CLOG->insert(m_fileLog);
LOG((CLOG_DEBUG1 "logging to file (%s) enabled", argsBase().m_logFile));
@ -161,7 +161,7 @@ void
App::loggingFilterWarning()
{
if (CLOG->getFilter() > CLOG->getConsoleMaxLevel()) {
if (argsBase().m_logFile == NULL) {
if (argsBase().m_logFile == nullptr) {
LOG((CLOG_WARN "log messages above %s are NOT sent to console (use file logging)",
CLOG->getFilterName(CLOG->getConsoleMaxLevel())));
}
@ -179,7 +179,7 @@ App::initApp(int argc, const char** argv)
// this is a simple way to allow the core process to talk to X. this avoids
// the "WARNING: primary screen unavailable: unable to open screen" error.
// a better way would be to use xauth cookie and dbus to get access to X.
if (!argsBase().m_runAsUid != -1) {
if (static_cast<int>((!(argsBase().m_runAsUid) == 0 != -1))) {
if (setuid(argsBase().m_runAsUid) == 0) {
LOG((CLOG_DEBUG "process uid was set to: %d", argsBase().m_runAsUid));
}
@ -231,9 +231,9 @@ App::cleanupIpcClient()
}
void
App::handleIpcMessage(const Event& e, void*)
App::handleIpcMessage(const Event& e, void* /*unused*/)
{
IpcMessage* m = static_cast<IpcMessage*>(e.getDataObject());
auto* m = dynamic_cast<IpcMessage*>(e.getDataObject());
if (m->type() == kIpcShutdown) {
LOG((CLOG_INFO "got ipc shutdown message"));
m_events->addEvent(Event(Event::kQuit));
@ -241,7 +241,7 @@ App::handleIpcMessage(const Event& e, void*)
}
void
App::runEventsLoop(void*)
App::runEventsLoop(void* /*unused*/)
{
m_events->loop();
@ -257,24 +257,23 @@ App::runEventsLoop(void*)
//
MinimalApp::MinimalApp() :
App(NULL, new ArgsBase())
App(nullptr, new ArgsBase())
{
m_arch.init();
setEvents(m_events);
}
MinimalApp::~MinimalApp()
{
}
= default;
int
MinimalApp::standardStartup(int argc, char** argv)
MinimalApp::standardStartup(int /*argc*/, char** /*argv*/)
{
return 0;
}
int
MinimalApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup)
MinimalApp::runInner(int /*argc*/, char** /*argv*/, ILogOutputter* /*outputter*/, StartupFunc /*startup*/)
{
return 0;
}
@ -291,7 +290,7 @@ MinimalApp::mainLoop()
}
int
MinimalApp::foregroundStartup(int argc, char** argv)
MinimalApp::foregroundStartup(int /*argc*/, char** /*argv*/)
{
return 0;
}
@ -299,7 +298,7 @@ MinimalApp::foregroundStartup(int argc, char** argv)
synergy::Screen*
MinimalApp::createScreen()
{
return NULL;
return nullptr;
}
void
@ -308,7 +307,7 @@ MinimalApp::loadConfig()
}
bool
MinimalApp::loadConfig(const String& pathname)
MinimalApp::loadConfig(const String& /*pathname*/)
{
return false;
}
@ -326,6 +325,6 @@ MinimalApp::daemonName() const
}
void
MinimalApp::parseArgs(int argc, const char* const* argv)
MinimalApp::parseArgs(int /*argc*/, const char* const* /*argv*/)
{
}

View File

@ -27,8 +27,7 @@ m_app(nullptr)
}
AppUtil::~AppUtil()
{
}
= default;
void
AppUtil::adoptApp(IApp* app)

View File

@ -17,20 +17,20 @@
#include "core/ArgParser.h"
#include "core/StreamChunker.h"
#include "core/App.h"
#include "core/ServerArgs.h"
#include "core/ClientArgs.h"
#include "core/ToolArgs.h"
#include "core/ArgsBase.h"
#include "base/Log.h"
#include "base/String.h"
#include "core/App.h"
#include "core/ArgsBase.h"
#include "core/ClientArgs.h"
#include "core/ServerArgs.h"
#include "core/StreamChunker.h"
#include "core/ToolArgs.h"
#ifdef WINAPI_MSWINDOWS
#include <VersionHelpers.h>
#endif
ArgsBase* ArgParser::m_argsBase = NULL;
ArgsBase* ArgParser::m_argsBase = nullptr;
ArgParser::ArgParser(App* app) :
m_app(app)
@ -47,7 +47,7 @@ ArgParser::parseServerArgs(ServerArgs& args, int argc, const char* const* argv)
if (parsePlatformArg(args, argc, argv, i)) {
continue;
}
else if (parseGenericArgs(argc, argv, i)) {
if (parseGenericArgs(argc, argv, i)) {
continue;
}
else if (parseDeprecatedArgs(argc, argv, i)) {
@ -70,11 +70,7 @@ ArgParser::parseServerArgs(ServerArgs& args, int argc, const char* const* argv)
}
}
if (checkUnexpectedArgs()) {
return false;
}
return true;
return !checkUnexpectedArgs();
}
bool
@ -88,19 +84,19 @@ ArgParser::parseClientArgs(ClientArgs& args, int argc, const char* const* argv)
if (parsePlatformArg(args, argc, argv, i)) {
continue;
}
else if (parseGenericArgs(argc, argv, i)) {
if (parseGenericArgs(argc, argv, i)) {
continue;
}
else if (parseDeprecatedArgs(argc, argv, i)) {
continue;
}
else if (isArg(i, argc, argv, NULL, "--camp")) {
else if (isArg(i, argc, argv, nullptr, "--camp")) {
// ignore -- included for backwards compatibility
}
else if (isArg(i, argc, argv, NULL, "--no-camp")) {
else if (isArg(i, argc, argv, nullptr, "--no-camp")) {
// ignore -- included for backwards compatibility
}
else if (isArg(i, argc, argv, NULL, "--yscroll", 1)) {
else if (isArg(i, argc, argv, nullptr, "--yscroll", 1)) {
// define scroll
args.m_yscroll = atoi(argv[++i]);
}
@ -122,11 +118,7 @@ ArgParser::parseClientArgs(ClientArgs& args, int argc, const char* const* argv)
return false;
}
if (checkUnexpectedArgs()) {
return false;
}
return true;
return !checkUnexpectedArgs();
}
bool
@ -155,7 +147,7 @@ ArgParser::parsePlatformArg(ArgsBase& argsBase, const int& argc, const char* con
argsBase.m_display = argv[++i];
}
else if (isArg(i, argc, argv, NULL, "--no-xinitthreads")) {
else if (isArg(i, argc, argv, nullptr, "--no-xinitthreads")) {
argsBase.m_disableXInitThreads = true;
}
@ -175,31 +167,31 @@ bool
ArgParser::parseToolArgs(ToolArgs& args, int argc, const char* const* argv)
{
for (int i = 1; i < argc; ++i) {
if (isArg(i, argc, argv, NULL, "--get-active-desktop", 0)) {
if (isArg(i, argc, argv, nullptr, "--get-active-desktop", 0)) {
args.m_printActiveDesktopName = true;
return true;
}
else if (isArg(i, argc, argv, NULL, "--login-auth", 0)) {
if (isArg(i, argc, argv, nullptr, "--login-auth", 0)) {
args.m_loginAuthenticate = true;
return true;
}
else if (isArg(i, argc, argv, NULL, "--get-installed-dir", 0)) {
else if (isArg(i, argc, argv, nullptr, "--get-installed-dir", 0)) {
args.m_getInstalledDir = true;
return true;
}
else if (isArg(i, argc, argv, NULL, "--get-profile-dir", 0)) {
else if (isArg(i, argc, argv, nullptr, "--get-profile-dir", 0)) {
args.m_getProfileDir = true;
return true;
}
else if (isArg(i, argc, argv, NULL, "--get-arch", 0)) {
else if (isArg(i, argc, argv, nullptr, "--get-arch", 0)) {
args.m_getArch = true;
return true;
}
else if (isArg(i, argc, argv, NULL, "--notify-activation", 0)) {
else if (isArg(i, argc, argv, nullptr, "--notify-activation", 0)) {
args.m_notifyActivation = true;
return true;
}
else if (isArg(i, argc, argv, NULL, "--notify-update", 0)) {
else if (isArg(i, argc, argv, nullptr, "--notify-update", 0)) {
args.m_notifyUpdate = true;
return true;
}
@ -225,7 +217,7 @@ ArgParser::parseGenericArgs(int argc, const char* const* argv, int& i)
// not a daemon
argsBase().m_daemon = false;
}
else if (isArg(i, argc, argv, NULL, "--daemon")) {
else if (isArg(i, argc, argv, nullptr, "--daemon")) {
// daemonize
argsBase().m_daemon = true;
}
@ -237,38 +229,38 @@ ArgParser::parseGenericArgs(int argc, const char* const* argv, int& i)
// don't try to restart
argsBase().m_restartable = false;
}
else if (isArg(i, argc, argv, NULL, "--restart")) {
else if (isArg(i, argc, argv, nullptr, "--restart")) {
// try to restart
argsBase().m_restartable = true;
}
else if (isArg(i, argc, argv, "-z", NULL)) {
else if (isArg(i, argc, argv, "-z", nullptr)) {
argsBase().m_backend = true;
}
else if (isArg(i, argc, argv, NULL, "--no-hooks")) {
else if (isArg(i, argc, argv, nullptr, "--no-hooks")) {
argsBase().m_noHooks = true;
}
else if (isArg(i, argc, argv, "-h", "--help")) {
if (m_app) {
if (m_app != nullptr) {
m_app->help();
}
argsBase().m_shouldExit = true;
}
else if (isArg(i, argc, argv, NULL, "--version")) {
if (m_app) {
else if (isArg(i, argc, argv, nullptr, "--version")) {
if (m_app != nullptr) {
m_app->version();
}
argsBase().m_shouldExit = true;
}
else if (isArg(i, argc, argv, NULL, "--ipc")) {
else if (isArg(i, argc, argv, nullptr, "--ipc")) {
argsBase().m_enableIpc = true;
}
else if (isArg(i, argc, argv, NULL, "--server")) {
else if (isArg(i, argc, argv, nullptr, "--server")) {
// supress error when --server is used
}
else if (isArg(i, argc, argv, NULL, "--client")) {
else if (isArg(i, argc, argv, nullptr, "--client")) {
// supress error when --client is used
}
else if (isArg(i, argc, argv, NULL, "--enable-drag-drop")) {
else if (isArg(i, argc, argv, nullptr, "--enable-drag-drop")) {
bool useDragDrop = true;
#ifdef WINAPI_XWINDOWS
@ -290,18 +282,18 @@ ArgParser::parseGenericArgs(int argc, const char* const* argv, int& i)
argsBase().m_enableDragDrop = true;
}
}
else if (isArg(i, argc, argv, NULL, "--enable-crypto")) {
else if (isArg(i, argc, argv, nullptr, "--enable-crypto")) {
LOG((CLOG_INFO "--enable-crypto ignored, TLS is no longer supported in Synergy Core"));
return false;
}
else if (isArg(i, argc, argv, NULL, "--profile-dir", 1)) {
else if (isArg(i, argc, argv, nullptr, "--profile-dir", 1)) {
argsBase().m_profileDirectory = argv[++i];
}
else if (isArg(i, argc, argv, NULL, "--plugin-dir", 1)) {
else if (isArg(i, argc, argv, nullptr, "--plugin-dir", 1)) {
argsBase().m_pluginDirectory = argv[++i];
}
#if WINAPI_XWINDOWS
else if (isArg(i, argc, argv, NULL, "--run-as-uid", 1)) {
else if (isArg(i, argc, argv, nullptr, "--run-as-uid", 1)) {
argsBase().m_runAsUid = std::stoi(argv[++i]);
}
#endif
@ -316,27 +308,27 @@ ArgParser::parseGenericArgs(int argc, const char* const* argv, int& i)
bool
ArgParser::parseDeprecatedArgs(int argc, const char* const* argv, int& i)
{
if (isArg(i, argc, argv, NULL, "--crypto-pass")) {
if (isArg(i, argc, argv, nullptr, "--crypto-pass")) {
LOG((CLOG_NOTE "--crypto-pass is deprecated"));
i++;
return true;
}
else if (isArg(i, argc, argv, NULL, "--res-w")) {
if (isArg(i, argc, argv, nullptr, "--res-w")) {
LOG((CLOG_NOTE "--res-w is deprecated"));
i++;
return true;
}
else if (isArg(i, argc, argv, NULL, "--res-h")) {
else if (isArg(i, argc, argv, nullptr, "--res-h")) {
LOG((CLOG_NOTE "--res-h is deprecated"));
i++;
return true;
}
else if (isArg(i, argc, argv, NULL, "--prm-wc")) {
else if (isArg(i, argc, argv, nullptr, "--prm-wc")) {
LOG((CLOG_NOTE "--prm-wc is deprecated"));
i++;
return true;
}
else if (isArg(i, argc, argv, NULL, "--prm-hc")) {
else if (isArg(i, argc, argv, nullptr, "--prm-hc")) {
LOG((CLOG_NOTE "--prm-hc is deprecated"));
i++;
return true;
@ -351,8 +343,8 @@ ArgParser::isArg(
const char* name1, const char* name2,
int minRequiredParameters)
{
if ((name1 != NULL && strcmp(argv[argi], name1) == 0) ||
(name2 != NULL && strcmp(argv[argi], name2) == 0)) {
if ((name1 != nullptr && strcmp(argv[argi], name1) == 0) ||
(name2 != nullptr && strcmp(argv[argi], name2) == 0)) {
// match. check args left.
if (argi + minRequiredParameters >= argc) {
LOG((CLOG_PRINT "%s: missing arguments for `%s'" BYE,
@ -379,7 +371,7 @@ ArgParser::splitCommandString(String& command, std::vector<String>& argv)
searchDoubleQuotes(command, leftDoubleQuote, rightDoubleQuote);
size_t startPos = 0;
size_t space = command.find(" ", startPos);
size_t space = command.find(' ', startPos);
while (space != String::npos) {
bool ignoreThisSpace = false;
@ -401,11 +393,11 @@ ArgParser::splitCommandString(String& command, std::vector<String>& argv)
// find next space
if (ignoreThisSpace) {
space = command.find(" ", rightDoubleQuote + 1);
space = command.find(' ', rightDoubleQuote + 1);
}
else {
startPos = space + 1;
space = command.find(" ", startPos);
space = command.find(' ', startPos);
}
}
@ -421,9 +413,9 @@ ArgParser::searchDoubleQuotes(String& command, size_t& left, size_t& right, size
left = String::npos;
right = String::npos;
left = command.find("\"", startPos);
left = command.find('\"', startPos);
if (left != String::npos) {
right = command.find("\"", left + 1);
right = command.find('\"', left + 1);
if (right != String::npos) {
result = true;
}
@ -456,7 +448,7 @@ ArgParser::getArgv(std::vector<String>& argsArray)
// we use the c string pointers from argsArray and assign
// them to the inner array. So caller only need to use
// delete[] to delete the outer array
const char** argv = new const char*[argc];
const auto** argv = new const char*[argc];
for (size_t i = 0; i < argc; i++) {
argv[i] = argsArray[i].c_str();
@ -466,12 +458,12 @@ ArgParser::getArgv(std::vector<String>& argsArray)
}
String
ArgParser::assembleCommand(std::vector<String>& argsArray, String ignoreArg, int parametersRequired)
ArgParser::assembleCommand(std::vector<String>& argsArray, const String& ignoreArg, int parametersRequired)
{
String result;
for (std::vector<String>::iterator it = argsArray.begin(); it != argsArray.end(); ++it) {
if (it->compare(ignoreArg) == 0) {
for (auto it = argsArray.begin(); it != argsArray.end(); ++it) {
if (*it == ignoreArg) {
it = it + parametersRequired;
continue;
}

View File

@ -48,7 +48,7 @@ public:
static void removeDoubleQuotes(String& arg);
static const char** getArgv(std::vector<String>& argsArray);
static String assembleCommand(std::vector<String>& argsArray,
String ignoreArg = "", int parametersRequired = 0);
const String& ignoreArg = "", int parametersRequired = 0);
private:
void updateCommonArgs(const char* const* argv);

View File

@ -34,19 +34,17 @@ m_runAsUid(-1),
m_backend(false),
m_restartable(true),
m_noHooks(false),
m_pname(NULL),
m_logFilter(NULL),
m_logFile(NULL),
m_display(NULL),
m_pname(nullptr),
m_logFilter(nullptr),
m_logFile(nullptr),
m_display(nullptr),
m_enableIpc(false),
m_enableDragDrop(false),
m_shouldExit(false),
m_synergyAddress(),
m_profileDirectory(""),
m_pluginDirectory("")
{
}
ArgsBase::~ArgsBase()
{
}
= default;

View File

@ -18,28 +18,28 @@
#include "core/ClientApp.h"
#include "arch/Arch.h"
#include "arch/IArchTaskBarReceiver.h"
#include "base/Event.h"
#include "base/EventQueue.h"
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "base/String.h"
#include "base/TMethodEventJob.h"
#include "base/TMethodJob.h"
#include "base/log_outputters.h"
#include "client/Client.h"
#include "common/Version.h"
#include "core/ArgParser.h"
#include "core/protocol_types.h"
#include "core/ClientArgs.h"
#include "core/Screen.h"
#include "core/XScreen.h"
#include "core/ClientArgs.h"
#include "net/NetworkAddress.h"
#include "net/TCPSocketFactory.h"
#include "net/SocketMultiplexer.h"
#include "net/XSocket.h"
#include "core/protocol_types.h"
#include "mt/Thread.h"
#include "arch/IArchTaskBarReceiver.h"
#include "arch/Arch.h"
#include "base/String.h"
#include "base/Event.h"
#include "base/IEventQueue.h"
#include "base/TMethodEventJob.h"
#include "base/log_outputters.h"
#include "base/EventQueue.h"
#include "base/TMethodJob.h"
#include "base/Log.h"
#include "common/Version.h"
#include "net/NetworkAddress.h"
#include "net/SocketMultiplexer.h"
#include "net/TCPSocketFactory.h"
#include "net/XSocket.h"
#if SYSAPI_WIN32
#include "arch/win32/ArchMiscWindows.h"
@ -58,21 +58,20 @@
#endif
#include <iostream>
#include <stdio.h>
#include <cstdio>
#define RETRY_TIME 1.0
ClientApp::ClientApp(IEventQueue* events) :
App(events, new ClientArgs()),
m_client(NULL),
m_clientScreen(NULL),
m_serverAddress(NULL)
m_client(nullptr),
m_clientScreen(nullptr),
m_serverAddress(nullptr)
{
}
ClientApp::~ClientApp()
{
}
= default;
void
ClientApp::parseArgs(int argc, const char* const* argv)
@ -192,7 +191,7 @@ ClientApp::updateStatus()
void
ClientApp::updateStatus(const String& msg)
ClientApp::updateStatus(const String& /*msg*/)
{
}
@ -229,7 +228,7 @@ ClientApp::nextRestartTimeout()
void
ClientApp::handleScreenError(const Event&, void*)
ClientApp::handleScreenError(const Event& /*unused*/, void* /*unused*/)
{
LOG((CLOG_CRIT "error on screen"));
m_events->addEvent(Event(Event::kQuit));
@ -252,7 +251,7 @@ ClientApp::openClientScreen()
void
ClientApp::closeClientScreen(synergy::Screen* screen)
{
if (screen != NULL) {
if (screen != nullptr) {
m_events->removeHandler(m_events->forIScreen().error(),
screen->getEventTarget());
delete screen;
@ -261,10 +260,10 @@ ClientApp::closeClientScreen(synergy::Screen* screen)
void
ClientApp::handleClientRestart(const Event&, void* vtimer)
ClientApp::handleClientRestart(const Event& /*unused*/, void* vtimer)
{
// discard old timer
EventQueueTimer* timer = static_cast<EventQueueTimer*>(vtimer);
auto* timer = static_cast<EventQueueTimer*>(vtimer);
m_events->deleteTimer(timer);
m_events->removeHandler(Event::kTimer, timer);
@ -278,14 +277,14 @@ ClientApp::scheduleClientRestart(double retryTime)
{
// install a timer and handler to retry later
LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime));
EventQueueTimer* timer = m_events->newOneShotTimer(retryTime, NULL);
EventQueueTimer* timer = m_events->newOneShotTimer(retryTime, nullptr);
m_events->adoptHandler(Event::kTimer, timer,
new TMethodEventJob<ClientApp>(this, &ClientApp::handleClientRestart, timer));
}
void
ClientApp::handleClientConnected(const Event&, void*)
ClientApp::handleClientConnected(const Event& /*unused*/, void* /*unused*/)
{
LOG((CLOG_NOTE "connected to server"));
resetRestartTimeout();
@ -294,9 +293,9 @@ ClientApp::handleClientConnected(const Event&, void*)
void
ClientApp::handleClientFailed(const Event& e, void*)
ClientApp::handleClientFailed(const Event& e, void* /*unused*/)
{
Client::FailInfo* info =
auto* info =
static_cast<Client::FailInfo*>(e.getData());
updateStatus(String("Failed to connect to server: ") + info->m_what);
@ -315,7 +314,7 @@ ClientApp::handleClientFailed(const Event& e, void*)
void
ClientApp::handleClientDisconnected(const Event&, void*)
ClientApp::handleClientDisconnected(const Event& /*unused*/, void* /*unused*/)
{
LOG((CLOG_NOTE "disconnected from server"));
if (!args().m_restartable) {
@ -331,7 +330,7 @@ Client*
ClientApp::openClient(const String& name, const NetworkAddress& address,
synergy::Screen* screen)
{
Client* client = new Client(
auto* client = new Client(
m_events,
name,
address,
@ -367,7 +366,7 @@ ClientApp::openClient(const String& name, const NetworkAddress& address,
void
ClientApp::closeClient(Client* client)
{
if (client == NULL) {
if (client == nullptr) {
return;
}
@ -390,9 +389,9 @@ bool
ClientApp::startClient()
{
double retryTime;
synergy::Screen* clientScreen = NULL;
synergy::Screen* clientScreen = nullptr;
try {
if (m_clientScreen == NULL) {
if (m_clientScreen == nullptr) {
clientScreen = openClientScreen();
m_client = openClient(args().m_name,
*m_serverAddress, clientScreen);
@ -426,10 +425,10 @@ ClientApp::startClient()
scheduleClientRestart(retryTime);
return true;
}
else {
// don't try again
return false;
}
}
@ -438,8 +437,8 @@ ClientApp::stopClient()
{
closeClient(m_client);
closeClientScreen(m_clientScreen);
m_client = NULL;
m_clientScreen = NULL;
m_client = nullptr;
m_clientScreen = nullptr;
}
@ -513,9 +512,9 @@ ClientApp::standardStartup(int argc, char** argv)
if (args().m_daemon) {
return ARCH->daemonize(daemonName(), &daemonMainLoopStatic);
}
else {
return mainLoop();
}
}
int
@ -526,7 +525,7 @@ ClientApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc
args().m_pname = ARCH->getBasename(argv[0]);
// install caller's output filter
if (outputter != NULL) {
if (outputter != nullptr) {
CLOG->insert(outputter);
}

View File

@ -17,12 +17,12 @@
*/
#include "core/ClientTaskBarReceiver.h"
#include "client/Client.h"
#include "mt/Lock.h"
#include "base/String.h"
#include "base/IEventQueue.h"
#include "arch/Arch.h"
#include "base/IEventQueue.h"
#include "base/String.h"
#include "client/Client.h"
#include "common/Version.h"
#include "mt/Lock.h"
//
// ClientTaskBarReceiver
@ -46,7 +46,7 @@ ClientTaskBarReceiver::updateStatus(Client* client, const String& errorMsg)
{
// update our status
m_errorMessage = errorMsg;
if (client == NULL) {
if (client == nullptr) {
if (m_errorMessage.empty()) {
m_state = kNotRunning;
}
@ -95,7 +95,7 @@ ClientTaskBarReceiver::quit()
}
void
ClientTaskBarReceiver::onStatusChanged(Client*)
ClientTaskBarReceiver::onStatusChanged(Client* /*unused*/)
{
// do nothing
}

View File

@ -63,9 +63,9 @@ public:
private:
mutable bool m_open;
mutable Time m_time;
mutable Time m_time{};
bool m_owner;
Time m_timeOwned;
bool m_added[kNumFormats];
Time m_timeOwned{};
bool m_added[kNumFormats]{};
String m_data[kNumFormats];
};

View File

@ -17,10 +17,10 @@
#include "core/ClipboardChunk.h"
#include "base/Log.h"
#include "core/ProtocolUtil.h"
#include "core/protocol_types.h"
#include "io/IStream.h"
#include "base/Log.h"
#include <cstring>
size_t ClipboardChunk::s_expectedSize = 0;
@ -38,7 +38,7 @@ ClipboardChunk::start(
const String& size)
{
size_t sizeLength = size.size();
ClipboardChunk* start = new ClipboardChunk(sizeLength + CLIPBOARD_CHUNK_META_SIZE);
auto* start = new ClipboardChunk(sizeLength + CLIPBOARD_CHUNK_META_SIZE);
char* chunk = start->m_chunk;
chunk[0] = id;
@ -57,7 +57,7 @@ ClipboardChunk::data(
const String& data)
{
size_t dataSize = data.size();
ClipboardChunk* chunk = new ClipboardChunk(dataSize + CLIPBOARD_CHUNK_META_SIZE);
auto* chunk = new ClipboardChunk(dataSize + CLIPBOARD_CHUNK_META_SIZE);
char* chunkData = chunk->m_chunk;
chunkData[0] = id;
@ -72,7 +72,7 @@ ClipboardChunk::data(
ClipboardChunk*
ClipboardChunk::end(ClipboardID id, UInt32 sequence)
{
ClipboardChunk* end = new ClipboardChunk(CLIPBOARD_CHUNK_META_SIZE);
auto* end = new ClipboardChunk(CLIPBOARD_CHUNK_META_SIZE);
char* chunk = end->m_chunk;
chunk[0] = id;
@ -102,7 +102,7 @@ ClipboardChunk::assemble(synergy::IStream* stream,
dataCached.clear();
return kStart;
}
else if (mark == kDataChunk) {
if (mark == kDataChunk) {
dataCached.append(data);
return kNotFinish;
}
@ -111,7 +111,7 @@ ClipboardChunk::assemble(synergy::IStream* stream,
if (id >= kClipboardEnd) {
return kError;
}
else if (s_expectedSize != dataCached.size()) {
if (s_expectedSize != dataCached.size()) {
LOG((CLOG_ERR "corrupted clipboard data, expected size=%d actual size=%d", s_expectedSize, dataCached.size()));
return kError;
}
@ -125,7 +125,7 @@ ClipboardChunk::assemble(synergy::IStream* stream,
void
ClipboardChunk::send(synergy::IStream* stream, void* data)
{
ClipboardChunk* clipboardData = static_cast<ClipboardChunk*>(data);
auto* clipboardData = static_cast<ClipboardChunk*>(data);
LOG((CLOG_DEBUG1 "sending clipboard chunk"));

View File

@ -16,26 +16,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// TODO: split this class into windows and unix to get rid
// TODO(andrew): split this class into windows and unix to get rid
// of all the #ifdefs!
#include "core/DaemonApp.h"
#include "arch/XArch.h"
#include "base/EventQueue.h"
#include "base/Log.h"
#include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "base/TMethodJob.h"
#include "base/log_outputters.h"
#include "core/App.h"
#include "core/ArgParser.h"
#include "core/ServerArgs.h"
#include "core/ClientArgs.h"
#include "core/ServerArgs.h"
#include "ipc/IpcClientProxy.h"
#include "ipc/IpcMessage.h"
#include "ipc/IpcLogOutputter.h"
#include "ipc/IpcMessage.h"
#include "net/SocketMultiplexer.h"
#include "arch/XArch.h"
#include "base/Log.h"
#include "base/TMethodJob.h"
#include "base/TMethodEventJob.h"
#include "base/EventQueue.h"
#include "base/log_outputters.h"
#include "base/Log.h"
#if SYSAPI_WIN32
@ -52,13 +52,13 @@
#endif
#include <string>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
DaemonApp* DaemonApp::s_instance = NULL;
DaemonApp* DaemonApp::s_instance = nullptr;
int
mainLoopStatic()
@ -68,7 +68,7 @@ mainLoopStatic()
}
int
unixMainLoopStatic(int, const char**)
unixMainLoopStatic(int /*unused*/, const char** /*unused*/)
{
return mainLoopStatic();
}
@ -94,8 +94,7 @@ DaemonApp::DaemonApp() :
}
DaemonApp::~DaemonApp()
{
}
= default;
int
DaemonApp::run(int argc, char** argv)
@ -122,8 +121,9 @@ DaemonApp::run(int argc, char** argv)
// default log level to system setting.
string logLevel = arch.setting("LogLevel");
if (logLevel != "")
if (!logLevel.empty()) {
log.setFilter(logLevel.c_str());
}
bool foreground = false;
@ -170,7 +170,7 @@ DaemonApp::run(int argc, char** argv)
catch (XArch& e) {
String message = e.what();
if (uninstall && (message.find("The service has not been started") != String::npos)) {
// TODO: if we're keeping this use error code instead (what is it?!).
// TODO(andrew): if we're keeping this use error code instead (what is it?!).
// HACK: this message happens intermittently, not sure where from but
// it's quite misleading for the user. they thing something has gone
// horribly wrong, but it's just the service manager reporting a false
@ -288,12 +288,12 @@ DaemonApp::logFilename()
}
void
DaemonApp::handleIpcMessage(const Event& e, void*)
DaemonApp::handleIpcMessage(const Event& e, void* /*unused*/)
{
IpcMessage* m = static_cast<IpcMessage*>(e.getDataObject());
auto* m = dynamic_cast<IpcMessage*>(e.getDataObject());
switch (m->type()) {
case kIpcCommand: {
IpcCommandMessage* cm = static_cast<IpcCommandMessage*>(m);
auto* cm = dynamic_cast<IpcCommandMessage*>(m);
String command = cm->command();
// if empty quotes, clear.
@ -306,13 +306,13 @@ DaemonApp::handleIpcMessage(const Event& e, void*)
std::vector<String> argsArray;
ArgParser::splitCommandString(command, argsArray);
ArgParser argParser(NULL);
ArgParser argParser(nullptr);
const char** argv = argParser.getArgv(argsArray);
ServerArgs serverArgs;
ClientArgs clientArgs;
int argc = static_cast<int>(argsArray.size());
bool server = argsArray[0].find("synergys") != String::npos ? true : false;
ArgsBase* argBase = NULL;
auto argc = static_cast<int>(argsArray.size());
bool server = argsArray[0].find("synergys") != String::npos;
ArgsBase* argBase = nullptr;
if (server) {
argParser.parseServerArgs(serverArgs, argc, argv);
@ -364,7 +364,7 @@ DaemonApp::handleIpcMessage(const Event& e, void*)
// next starts.
ARCH->setting("Command", command);
// TODO: it would be nice to store bools/ints...
// TODO(andrew): it would be nice to store bools/ints...
ARCH->setting("Elevate", String(cm->elevate() ? "1" : "0"));
}
catch (XArch& e) {
@ -381,7 +381,7 @@ DaemonApp::handleIpcMessage(const Event& e, void*)
}
case kIpcHello:
IpcHelloMessage* hm = static_cast<IpcHelloMessage*>(m);
auto* hm = dynamic_cast<IpcHelloMessage*>(m);
String type;
switch (hm->clientType()) {
case kIpcClientGui: type = "gui"; break;

View File

@ -25,20 +25,19 @@
using namespace std;
DragInformation::DragInformation() :
m_filename(),
m_filesize(0)
{
}
void
DragInformation::parseDragInfo(DragFileList& dragFileList, UInt32 fileNum, String data)
DragInformation::parseDragInfo(DragFileList& dragFileList, UInt32 fileNum, const String& data)
{
size_t startPos = 0;
size_t findResult1 = 0;
size_t findResult2 = 0;
dragFileList.clear();
String slash("\\");
if (data.find("/", startPos) != string::npos) {
if (data.find('/', startPos) != string::npos) {
slash = "/";
}
@ -48,7 +47,7 @@ DragInformation::parseDragInfo(DragFileList& dragFileList, UInt32 fileNum, Strin
findResult2 = data.find_last_of(slash, findResult1);
if (findResult1 == startPos) {
//TODO: file number does not match, something goes wrong
// TODO(andrew): file number does not match, something goes wrong
break;
}
@ -86,22 +85,22 @@ DragInformation::parseDragInfo(DragFileList& dragFileList, UInt32 fileNum, Strin
}
String
DragInformation::getDragFileExtension(String filename)
DragInformation::getDragFileExtension(const String& filename)
{
size_t findResult = string::npos;
findResult = filename.find_last_of(".", filename.size());
findResult = filename.find_last_of('.', filename.size());
if (findResult != string::npos) {
return filename.substr(findResult + 1, filename.size() - findResult - 1);
}
else {
return "";
}
}
int
DragInformation::setupDragInfo(DragFileList& fileList, String& output)
{
int size = static_cast<int>(fileList.size());
auto size = static_cast<int>(fileList.size());
for (int i = 0; i < size; ++i) {
output.append(fileList.at(i).getFilename());
output.append(",");
@ -113,7 +112,7 @@ DragInformation::setupDragInfo(DragFileList& fileList, String& output)
}
bool
DragInformation::isFileValid(String filename)
DragInformation::isFileValid(const String& filename)
{
bool result = false;
std::fstream file(filename.c_str(), ios::in|ios::binary);
@ -130,7 +129,7 @@ DragInformation::isFileValid(String filename)
size_t
DragInformation::stringToNum(String& str)
{
istringstream iss(str.c_str());
istringstream iss(str);
size_t size;
iss >> size;
return size;
@ -147,7 +146,7 @@ DragInformation::getFileSize(String& filename)
// check file size
file.seekg (0, std::ios::end);
size_t size = (size_t)file.tellg();
auto size = (size_t)file.tellg();
stringstream ss;
ss << size;

View File

@ -34,14 +34,14 @@ public:
size_t getFilesize() { return m_filesize; }
void setFilesize(size_t size) { m_filesize = size; }
static void parseDragInfo(DragFileList& dragFileList, UInt32 fileNum, String data);
static String getDragFileExtension(String filename);
static void parseDragInfo(DragFileList& dragFileList, UInt32 fileNum, const String& data);
static String getDragFileExtension(const String& filename);
// helper function to setup drag info
// example: filename1,filesize1,filename2,filesize2,
// return file count
static int setupDragInfo(DragFileList& fileList, String& output);
static bool isFileValid(String filename);
static bool isFileValid(const String& filename);
private:
static size_t stringToNum(String& str);

View File

@ -26,7 +26,7 @@ DropHelper::writeToDir(const String& destination, DragFileList& fileList, String
{
LOG((CLOG_DEBUG "dropping file, files=%i target=%s", fileList.size(), destination.c_str()));
if (!destination.empty() && fileList.size() > 0) {
if (!destination.empty() && !fileList.empty()) {
std::fstream file;
String dropTarget = destination;
#ifdef SYSAPI_WIN32

View File

@ -17,11 +17,11 @@
#include "core/FileChunk.h"
#include "base/Log.h"
#include "base/Stopwatch.h"
#include "core/ProtocolUtil.h"
#include "core/protocol_types.h"
#include "io/IStream.h"
#include "base/Stopwatch.h"
#include "base/Log.h"
static const UInt16 kIntervalThreshold = 1;
@ -35,7 +35,7 @@ FileChunk*
FileChunk::start(const String& size)
{
size_t sizeLength = size.size();
FileChunk* start = new FileChunk(sizeLength + FILE_CHUNK_META_SIZE);
auto* start = new FileChunk(sizeLength + FILE_CHUNK_META_SIZE);
char* chunk = start->m_chunk;
chunk[0] = kDataStart;
memcpy(&chunk[1], size.c_str(), sizeLength);
@ -47,7 +47,7 @@ FileChunk::start(const String& size)
FileChunk*
FileChunk::data(UInt8* data, size_t dataSize)
{
FileChunk* chunk = new FileChunk(dataSize + FILE_CHUNK_META_SIZE);
auto* chunk = new FileChunk(dataSize + FILE_CHUNK_META_SIZE);
char* chunkData = chunk->m_chunk;
chunkData[0] = kDataChunk;
memcpy(&chunkData[1], data, dataSize);
@ -59,7 +59,7 @@ FileChunk::data(UInt8* data, size_t dataSize)
FileChunk*
FileChunk::end()
{
FileChunk* end = new FileChunk(FILE_CHUNK_META_SIZE);
auto* end = new FileChunk(FILE_CHUNK_META_SIZE);
char* chunk = end->m_chunk;
chunk[0] = kDataEnd;
chunk[1] = '\0';

View File

@ -36,7 +36,7 @@ public:
static FileChunk* end();
static int assemble(
synergy::IStream* stream,
String& dataCached,
String& dataReceived,
size_t& expectedSize);
static void send(
synergy::IStream* stream,

View File

@ -41,7 +41,7 @@ IClipboard::unmarshall(IClipboard* clipboard, const String& data, Time time)
// read each format
for (UInt32 i = 0; i < numFormats; ++i) {
// get the format id
IClipboard::EFormat format =
auto format =
static_cast<IClipboard::EFormat>(readUInt32(index));
index += 4;
@ -90,7 +90,7 @@ IClipboard::marshall(const IClipboard* clipboard)
++numFormats;
formatData[format] =
clipboard->get(static_cast<IClipboard::EFormat>(format));
size += 4 + 4 + (UInt32)formatData[format].size();
size += 4 + 4 + static_cast<UInt32>(formatData[format].size());
}
}
@ -102,7 +102,7 @@ IClipboard::marshall(const IClipboard* clipboard)
for (UInt32 format = 0; format != IClipboard::kNumFormats; ++format) {
if (clipboard->has(static_cast<IClipboard::EFormat>(format))) {
writeUInt32(&data, format);
writeUInt32(&data, (UInt32)formatData[format].size());
writeUInt32(&data, static_cast<UInt32>(formatData[format].size()));
data += formatData[format];
}
}
@ -133,7 +133,7 @@ IClipboard::copy(IClipboard* dst, const IClipboard* src, Time time)
if (dst->empty()) {
for (SInt32 format = 0;
format != IClipboard::kNumFormats; ++format) {
IClipboard::EFormat eFormat = (IClipboard::EFormat)format;
auto eFormat = static_cast<IClipboard::EFormat>(format);
if (src->has(eFormat)) {
dst->add(eFormat, src->get(eFormat));
}
@ -151,7 +151,7 @@ IClipboard::copy(IClipboard* dst, const IClipboard* src, Time time)
UInt32
IClipboard::readUInt32(const char* buf)
{
const unsigned char* ubuf = reinterpret_cast<const unsigned char*>(buf);
const auto* ubuf = reinterpret_cast<const unsigned char*>(buf);
return (static_cast<UInt32>(ubuf[0]) << 24) |
(static_cast<UInt32>(ubuf[1]) << 16) |
(static_cast<UInt32>(ubuf[2]) << 8) |

View File

@ -19,14 +19,14 @@
#include "core/IKeyState.h"
#include "base/EventQueue.h"
#include <cstring>
#include <cstdlib>
#include <cstring>
//
// IKeyState
//
IKeyState::IKeyState(IEventQueue* events)
IKeyState::IKeyState(IEventQueue* /*events*/)
{
}
@ -38,12 +38,12 @@ IKeyState::KeyInfo*
IKeyState::KeyInfo::alloc(KeyID id,
KeyModifierMask mask, KeyButton button, SInt32 count)
{
KeyInfo* info = (KeyInfo*)malloc(sizeof(KeyInfo));
auto* info = static_cast<KeyInfo*>(malloc(sizeof(KeyInfo)));
info->m_key = id;
info->m_mask = mask;
info->m_button = button;
info->m_count = count;
info->m_screens = NULL;
info->m_screens = nullptr;
info->m_screensBuffer[0] = '\0';
return info;
}
@ -56,7 +56,7 @@ IKeyState::KeyInfo::alloc(KeyID id,
String screens = join(destinations);
// build structure
KeyInfo* info = (KeyInfo*)malloc(sizeof(KeyInfo) + screens.size());
auto* info = static_cast<KeyInfo*>(malloc(sizeof(KeyInfo) + screens.size()));
info->m_key = id;
info->m_mask = mask;
info->m_button = button;
@ -69,13 +69,13 @@ IKeyState::KeyInfo::alloc(KeyID id,
IKeyState::KeyInfo*
IKeyState::KeyInfo::alloc(const KeyInfo& x)
{
KeyInfo* info = (KeyInfo*)malloc(sizeof(KeyInfo) +
strlen(x.m_screensBuffer));
auto* info = static_cast<KeyInfo*>(malloc(sizeof(KeyInfo) +
strlen(x.m_screensBuffer)));
info->m_key = x.m_key;
info->m_mask = x.m_mask;
info->m_button = x.m_button;
info->m_count = x.m_count;
info->m_screens = x.m_screens ? info->m_screensBuffer : NULL;
info->m_screens = x.m_screens != nullptr ? info->m_screensBuffer : nullptr;
strcpy(info->m_screensBuffer, x.m_screensBuffer);
return info;
}
@ -83,7 +83,7 @@ IKeyState::KeyInfo::alloc(const KeyInfo& x)
bool
IKeyState::KeyInfo::isDefault(const char* screens)
{
return (screens == NULL || screens[0] == '\0');
return (screens == nullptr || screens[0] == '\0');
}
bool
@ -103,7 +103,7 @@ IKeyState::KeyInfo::contains(const char* screens, const String& name)
match += ":";
match += name;
match += ":";
return (strstr(screens, match.c_str()) != NULL);
return (strstr(screens, match.c_str()) != nullptr);
}
bool
@ -123,19 +123,18 @@ IKeyState::KeyInfo::join(const std::set<String>& destinations)
// which makes searching easy. the string is empty if there are no
// destinations and "*" means all destinations.
String screens;
for (std::set<String>::const_iterator i = destinations.begin();
i != destinations.end(); ++i) {
if (*i == "*") {
for (const auto & destination : destinations) {
if (destination == "*") {
screens = "*";
break;
}
else {
if (screens.empty()) {
screens = ":";
}
screens += *i;
screens += destination;
screens += ":";
}
}
return screens;
}

View File

@ -18,7 +18,7 @@
#include "core/IPlatformScreen.h"
bool
IPlatformScreen::fakeMediaKey(KeyID id)
IPlatformScreen::fakeMediaKey(KeyID /*id*/)
{
return false;
}

View File

@ -28,7 +28,7 @@
IPrimaryScreen::ButtonInfo*
IPrimaryScreen::ButtonInfo::alloc(ButtonID id, KeyModifierMask mask)
{
ButtonInfo* info = (ButtonInfo*)malloc(sizeof(ButtonInfo));
auto* info = static_cast<ButtonInfo*>(malloc(sizeof(ButtonInfo)));
info->m_button = id;
info->m_mask = mask;
return info;
@ -37,7 +37,7 @@ IPrimaryScreen::ButtonInfo::alloc(ButtonID id, KeyModifierMask mask)
IPrimaryScreen::ButtonInfo*
IPrimaryScreen::ButtonInfo::alloc(const ButtonInfo& x)
{
ButtonInfo* info = (ButtonInfo*)malloc(sizeof(ButtonInfo));
auto* info = static_cast<ButtonInfo*>(malloc(sizeof(ButtonInfo)));
info->m_button = x.m_button;
info->m_mask = x.m_mask;
return info;
@ -57,7 +57,7 @@ IPrimaryScreen::ButtonInfo::equal(const ButtonInfo* a, const ButtonInfo* b)
IPrimaryScreen::MotionInfo*
IPrimaryScreen::MotionInfo::alloc(SInt32 x, SInt32 y)
{
MotionInfo* info = (MotionInfo*)malloc(sizeof(MotionInfo));
auto* info = static_cast<MotionInfo*>(malloc(sizeof(MotionInfo)));
info->m_x = x;
info->m_y = y;
return info;
@ -71,7 +71,7 @@ IPrimaryScreen::MotionInfo::alloc(SInt32 x, SInt32 y)
IPrimaryScreen::WheelInfo*
IPrimaryScreen::WheelInfo::alloc(SInt32 xDelta, SInt32 yDelta)
{
WheelInfo* info = (WheelInfo*)malloc(sizeof(WheelInfo));
auto* info = static_cast<WheelInfo*>(malloc(sizeof(WheelInfo)));
info->m_xDelta = xDelta;
info->m_yDelta = yDelta;
return info;
@ -85,7 +85,7 @@ IPrimaryScreen::WheelInfo::alloc(SInt32 xDelta, SInt32 yDelta)
IPrimaryScreen::HotKeyInfo*
IPrimaryScreen::HotKeyInfo::alloc(UInt32 id)
{
HotKeyInfo* info = (HotKeyInfo*)malloc(sizeof(HotKeyInfo));
auto* info = static_cast<HotKeyInfo*>(malloc(sizeof(HotKeyInfo)));
info->m_id = id;
return info;
}

View File

@ -17,19 +17,19 @@
*/
#include "core/KeyMap.h"
#include "core/key_types.h"
#include "base/Log.h"
#include "core/key_types.h"
#include <assert.h>
#include <cassert>
#include <cctype>
#include <cstdlib>
namespace synergy {
KeyMap::NameToKeyMap* KeyMap::s_nameToKeyMap = NULL;
KeyMap::NameToModifierMap* KeyMap::s_nameToModifierMap = NULL;
KeyMap::KeyToNameMap* KeyMap::s_keyToNameMap = NULL;
KeyMap::ModifierToNameMap* KeyMap::s_modifierToNameMap = NULL;
KeyMap::NameToKeyMap* KeyMap::s_nameToKeyMap = nullptr;
KeyMap::NameToModifierMap* KeyMap::s_nameToModifierMap = nullptr;
KeyMap::KeyToNameMap* KeyMap::s_keyToNameMap = nullptr;
KeyMap::ModifierToNameMap* KeyMap::s_modifierToNameMap = nullptr;
KeyMap::KeyMap() :
m_numGroups(0),
@ -97,8 +97,8 @@ KeyMap::addKeyEntry(const KeyItem& item)
// see if we already have this item; just return if so
KeyEntryList& entries = groupTable[item.m_group];
for (size_t i = 0, n = entries.size(); i < n; ++i) {
if (entries[i].size() == 1 && newItem == entries[i][0]) {
for (auto & entrie : entries) {
if (entrie.size() == 1 && newItem == entrie[0]) {
return;
}
}
@ -118,7 +118,7 @@ KeyMap::addKeyAliasEntry(KeyID targetID, SInt32 group,
{
// if we can already generate the target as desired then we're done.
if (findCompatibleKey(targetID, group, targetRequired,
targetSensitive) != NULL) {
targetSensitive) != nullptr) {
return;
}
@ -128,7 +128,7 @@ KeyMap::addKeyAliasEntry(KeyID targetID, SInt32 group,
const KeyItemList* sourceEntry =
findCompatibleKey(sourceID, eg,
sourceRequired, sourceSensitive);
if (sourceEntry != NULL && sourceEntry->size() == 1) {
if (sourceEntry != nullptr && sourceEntry->size() == 1) {
KeyMap::KeyItem targetItem = sourceEntry->back();
targetItem.m_id = targetID;
targetItem.m_group = eg;
@ -173,17 +173,17 @@ KeyMap::addKeyCombinationEntry(KeyID id, SInt32 group,
// groups for keys, otherwise search just the given group.
SInt32 n = 1;
if (m_composeAcrossGroups) {
n = (SInt32)groupTable.size();
n = static_cast<SInt32>(groupTable.size());
}
bool found = false;
for (SInt32 gd = 0; gd < n && !found; ++gd) {
SInt32 eg = (group + gd) % getNumGroups();
const KeyEntryList& entries = groupTable[eg];
for (size_t j = 0; j < entries.size(); ++j) {
if (entries[j].size() == 1) {
for (const auto & entrie : entries) {
if (entrie.size() == 1) {
found = true;
items.push_back(entries[j][0]);
items.push_back(entrie[0]);
break;
}
}
@ -229,9 +229,8 @@ KeyMap::finish()
m_numGroups = findNumGroups();
// make sure every key has the same number of groups
for (KeyIDMap::iterator i = m_keyIDMap.begin();
i != m_keyIDMap.end(); ++i) {
i->second.resize(m_numGroups);
for (auto & i : m_keyIDMap) {
i.second.resize(m_numGroups);
}
// compute keys that generate each modifier
@ -241,16 +240,14 @@ KeyMap::finish()
void
KeyMap::foreachKey(ForeachKeyCallback cb, void* userData)
{
for (KeyIDMap::iterator i = m_keyIDMap.begin();
i != m_keyIDMap.end(); ++i) {
KeyGroupTable& groupTable = i->second;
for (auto & i : m_keyIDMap) {
KeyGroupTable& groupTable = i.second;
for (size_t group = 0; group < groupTable.size(); ++group) {
KeyEntryList& entryList = groupTable[group];
for (size_t j = 0; j < entryList.size(); ++j) {
KeyItemList& itemList = entryList[j];
for (size_t k = 0; k < itemList.size(); ++k) {
(*cb)(i->first, static_cast<SInt32>(group),
itemList[k], userData);
for (auto & itemList : entryList) {
for (auto & k : itemList) {
(*cb)(i.first, static_cast<SInt32>(group),
k, userData);
}
}
}
@ -268,12 +265,12 @@ KeyMap::mapKey(Keystrokes& keys, KeyID id, SInt32 group,
// handle group change
if (id == kKeyNextGroup) {
keys.push_back(Keystroke(1, false, false));
return NULL;
keys.emplace_back(1, false, false);
return nullptr;
}
else if (id == kKeyPrevGroup) {
keys.push_back(Keystroke(-1, false, false));
return NULL;
if (id == kKeyPrevGroup) {
keys.emplace_back(-1, false, false);
return nullptr;
}
const KeyItem* item;
@ -300,7 +297,7 @@ KeyMap::mapKey(Keystrokes& keys, KeyID id, SInt32 group,
if (!keysForModifierState(0, group, activeModifiers, currentState,
desiredMask, desiredMask, 0, keys)) {
LOG((CLOG_DEBUG1 "unable to set modifiers %04x", desiredMask));
return NULL;
return nullptr;
}
return &m_modifierKeyItem;
@ -309,7 +306,7 @@ KeyMap::mapKey(Keystrokes& keys, KeyID id, SInt32 group,
currentState & ~desiredMask,
desiredMask, 0, keys)) {
LOG((CLOG_DEBUG1 "unable to clear modifiers %04x", desiredMask));
return NULL;
return nullptr;
}
return &m_modifierKeyItem;
@ -325,7 +322,7 @@ KeyMap::mapKey(Keystrokes& keys, KeyID id, SInt32 group,
break;
}
if (item != NULL) {
if (item != nullptr) {
LOG((CLOG_DEBUG1 "mapped to %03x, new state %04x", item->m_button, currentState));
}
return item;
@ -349,21 +346,21 @@ KeyMap::findCompatibleKey(KeyID id, SInt32 group,
{
assert(group >= 0 && group < getNumGroups());
KeyIDMap::const_iterator i = m_keyIDMap.find(id);
auto i = m_keyIDMap.find(id);
if (i == m_keyIDMap.end()) {
return NULL;
return nullptr;
}
const KeyEntryList& entries = i->second[group];
for (size_t j = 0; j < entries.size(); ++j) {
if ((entries[j].back().m_sensitive & sensitive) == 0 ||
(entries[j].back().m_required & sensitive) ==
for (const auto & entrie : entries) {
if ((entrie.back().m_sensitive & sensitive) == 0 ||
(entrie.back().m_required & sensitive) ==
(required & sensitive)) {
return &entries[j];
return &entrie;
}
}
return NULL;
return nullptr;
}
bool
@ -395,9 +392,8 @@ void
KeyMap::collectButtons(const ModifierToKeys& mods, ButtonToKeyMap& keys)
{
keys.clear();
for (ModifierToKeys::const_iterator i = mods.begin();
i != mods.end(); ++i) {
keys.insert(std::make_pair(i->second.m_button, &i->second));
for (const auto & mod : mods) {
keys.insert(std::make_pair(mod.second.m_button, &mod.second));
}
}
@ -461,10 +457,9 @@ SInt32
KeyMap::findNumGroups() const
{
size_t max = 0;
for (KeyIDMap::const_iterator i = m_keyIDMap.begin();
i != m_keyIDMap.end(); ++i) {
if (i->second.size() > max) {
max = i->second.size();
for (const auto & i : m_keyIDMap) {
if (i.second.size() > max) {
max = i.second.size();
}
}
return static_cast<SInt32>(max);
@ -480,14 +475,14 @@ KeyMap::setModifierKeys()
const KeyGroupTable& groupTable = i->second;
for (size_t g = 0; g < groupTable.size(); ++g) {
const KeyEntryList& entries = groupTable[g];
for (size_t j = 0; j < entries.size(); ++j) {
for (const auto & entrie : entries) {
// skip multi-key sequences
if (entries[j].size() != 1) {
if (entrie.size() != 1) {
continue;
}
// skip keys that don't generate a modifier
const KeyItem& item = entries[j].back();
const KeyItem& item = entrie.back();
if (item.m_generates == 0) {
continue;
}
@ -496,7 +491,7 @@ KeyMap::setModifierKeys()
for (SInt32 b = 0; b < kKeyModifierNumBits; ++b) {
// skip if item doesn't generate bit b
if (((1u << b) & item.m_generates) != 0) {
SInt32 mIndex = (SInt32)g * kKeyModifierNumBits + b;
SInt32 mIndex = static_cast<SInt32>(g) * kKeyModifierNumBits + b;
m_modifierKeys[mIndex].push_back(&item);
}
}
@ -515,22 +510,22 @@ KeyMap::mapCommandKey(Keystrokes& keys, KeyID id, SInt32 group,
static const KeyModifierMask s_overrideModifiers = 0xffffu;
// find KeySym in table
KeyIDMap::const_iterator i = m_keyIDMap.find(id);
auto i = m_keyIDMap.find(id);
if (i == m_keyIDMap.end()) {
// unknown key
LOG((CLOG_DEBUG1 "key %04x is not on keyboard", id));
return NULL;
return nullptr;
}
const KeyGroupTable& keyGroupTable = i->second;
// find the first key that generates this KeyID
const KeyItem* keyItem = NULL;
const KeyItem* keyItem = nullptr;
SInt32 numGroups = getNumGroups();
for (SInt32 groupOffset = 0; groupOffset < numGroups; ++groupOffset) {
SInt32 effectiveGroup = getEffectiveGroup(group, groupOffset);
const KeyEntryList& entryList = keyGroupTable[effectiveGroup];
for (size_t i = 0; i < entryList.size(); ++i) {
if (entryList[i].size() != 1) {
for (const auto & i : entryList) {
if (i.size() != 1) {
// ignore multikey entries
continue;
}
@ -540,7 +535,7 @@ KeyMap::mapCommandKey(Keystrokes& keys, KeyID id, SInt32 group,
// after the right button not the right character.
// we'll use desiredMask as-is, overriding the key's required
// modifiers, when synthesizing this button.
const KeyItem& item = entryList[i].back();
const KeyItem& item = i.back();
KeyModifierMask desiredShiftMask = KeyModifierShift & desiredMask;
KeyModifierMask requiredIgnoreShiftMask = item.m_required & ~KeyModifierShift;
if ((item.m_required & desiredShiftMask) == (item.m_sensitive & desiredShiftMask) &&
@ -550,14 +545,14 @@ KeyMap::mapCommandKey(Keystrokes& keys, KeyID id, SInt32 group,
break;
}
}
if (keyItem != NULL) {
if (keyItem != nullptr) {
break;
}
}
if (keyItem == NULL) {
if (keyItem == nullptr) {
// no mapping for this keysym
LOG((CLOG_DEBUG1 "no mapping for key %04x", id));
return NULL;
return nullptr;
}
// make working copy of modifiers
@ -575,7 +570,7 @@ KeyMap::mapCommandKey(Keystrokes& keys, KeyID id, SInt32 group,
s_overrideModifiers, isAutoRepeat, keys)) {
LOG((CLOG_DEBUG1 "can't map key"));
keys.clear();
return NULL;
return nullptr;
}
// add keystrokes to restore modifier keys
@ -583,12 +578,12 @@ KeyMap::mapCommandKey(Keystrokes& keys, KeyID id, SInt32 group,
activeModifiers, keys)) {
LOG((CLOG_DEBUG1 "failed to restore modifiers"));
keys.clear();
return NULL;
return nullptr;
}
// add keystrokes to restore group
if (newGroup != group) {
keys.push_back(Keystroke(group, true, true));
keys.emplace_back(group, true, true);
}
// save new modifiers
@ -606,11 +601,11 @@ KeyMap::mapCharacterKey(Keystrokes& keys, KeyID id, SInt32 group,
bool isAutoRepeat) const
{
// find KeySym in table
KeyIDMap::const_iterator i = m_keyIDMap.find(id);
auto i = m_keyIDMap.find(id);
if (i == m_keyIDMap.end()) {
// unknown key
LOG((CLOG_DEBUG1 "key %04x is not on keyboard", id));
return NULL;
return nullptr;
}
const KeyGroupTable& keyGroupTable = i->second;
@ -631,14 +626,14 @@ KeyMap::mapCharacterKey(Keystrokes& keys, KeyID id, SInt32 group,
if (keyIndex == -1) {
// no mapping for this keysym
LOG((CLOG_DEBUG1 "no mapping for key %04x", id));
return NULL;
return nullptr;
}
// get keys to press for key
SInt32 effectiveGroup = getEffectiveGroup(group, groupOffset);
const KeyItemList& itemList = keyGroupTable[effectiveGroup][keyIndex];
if (itemList.empty()) {
return NULL;
return nullptr;
}
const KeyItem& keyItem = itemList.back();
@ -648,13 +643,13 @@ KeyMap::mapCharacterKey(Keystrokes& keys, KeyID id, SInt32 group,
SInt32 newGroup = group;
// add each key
for (size_t j = 0; j < itemList.size(); ++j) {
if (!keysForKeyItem(itemList[j], newGroup, newModifiers,
for (const auto & j : itemList) {
if (!keysForKeyItem(j, newGroup, newModifiers,
newState, desiredMask,
0, isAutoRepeat, keys)) {
LOG((CLOG_DEBUG1 "can't map key"));
keys.clear();
return NULL;
return nullptr;
}
}
@ -663,12 +658,12 @@ KeyMap::mapCharacterKey(Keystrokes& keys, KeyID id, SInt32 group,
activeModifiers, keys)) {
LOG((CLOG_DEBUG1 "failed to restore modifiers"));
keys.clear();
return NULL;
return nullptr;
}
// add keystrokes to restore group
if (newGroup != group) {
keys.push_back(Keystroke(group, true, true));
keys.emplace_back(group, true, true);
}
// save new modifiers
@ -695,7 +690,7 @@ KeyMap::findBestKey(const KeyEntryList& entryList,
KeyModifierMask desiredState) const
{
// check for an item that can accommodate the desiredState exactly
for (SInt32 i = 0; i < (SInt32)entryList.size(); ++i) {
for (SInt32 i = 0; i < static_cast<SInt32>(entryList.size()); ++i) {
const KeyItem& item = entryList[i].back();
if ((item.m_required & desiredState) == item.m_required &&
(item.m_required & desiredState) == (item.m_sensitive & desiredState)) {
@ -707,7 +702,7 @@ KeyMap::findBestKey(const KeyEntryList& entryList,
// choose the item that requires the fewest modifier changes
SInt32 bestCount = 32;
SInt32 bestIndex = -1;
for (SInt32 i = 0; i < (SInt32)entryList.size(); ++i) {
for (SInt32 i = 0; i < static_cast<SInt32>(entryList.size()); ++i) {
const KeyItem& item = entryList[i].back();
KeyModifierMask change =
((item.m_required ^ desiredState) & item.m_sensitive);
@ -740,13 +735,12 @@ KeyMap::keyForModifier(KeyButton button, SInt32 group,
// must use the other shift button to do the shifting.
const ModifierKeyItemList& items =
m_modifierKeys[group * kKeyModifierNumBits + modifierBit];
for (ModifierKeyItemList::const_iterator i = items.begin();
i != items.end(); ++i) {
if ((*i)->m_button != button) {
return (*i);
for (auto item : items) {
if (item->m_button != button) {
return item;
}
}
return NULL;
return nullptr;
}
bool
@ -763,7 +757,7 @@ KeyMap::keysForKeyItem(const KeyItem& keyItem, SInt32& group,
// add keystrokes to adjust the group
if (group != keyItem.m_group) {
group = keyItem.m_group;
keystrokes.push_back(Keystroke(group, true, false));
keystrokes.emplace_back(group, true, false);
}
EKeystroke type;
@ -823,7 +817,7 @@ KeyMap::keysForKeyItem(const KeyItem& keyItem, SInt32& group,
}
bool
KeyMap::keysToRestoreModifiers(const KeyItem& keyItem, SInt32,
KeyMap::keysToRestoreModifiers(const KeyItem& keyItem, SInt32 /*unused*/,
ModifierToKeys& activeModifiers,
KeyModifierMask& currentState,
const ModifierToKeys& desiredModifiers,
@ -853,15 +847,14 @@ KeyMap::keysToRestoreModifiers(const KeyItem& keyItem, SInt32,
}
// press wanted keys
for (ModifierToKeys::const_iterator i = desiredModifiers.begin();
i != desiredModifiers.end(); ++i) {
KeyButton button = i->second.m_button;
for (const auto & desiredModifier : desiredModifiers) {
KeyButton button = desiredModifier.second.m_button;
if (button != keyItem.m_button && oldKeys.count(button) == 0) {
EKeystroke type = kKeystrokePress;
if (i->second.m_lock) {
if (desiredModifier.second.m_lock) {
type = kKeystrokeModify;
}
addKeystrokes(type, i->second,
addKeystrokes(type, desiredModifier.second,
activeModifiers, currentState, keystrokes);
}
}
@ -908,14 +901,14 @@ KeyMap::keysForModifierState(KeyButton button, SInt32 group,
// get the KeyItem for the modifier in the group
const KeyItem* keyItem = keyForModifier(button, group, bit);
if (keyItem == NULL) {
if (keyItem == nullptr) {
if ((mask & notRequiredMask) == 0) {
LOG((CLOG_DEBUG1 "no key for modifier %04x", mask));
return false;
}
else {
continue;
}
}
// if this modifier is sensitive to modifiers then adjust those
@ -940,7 +933,7 @@ KeyMap::keysForModifierState(KeyButton button, SInt32 group,
notRequiredMask, keystrokes)) {
return false;
}
else if (!active) {
if (!active) {
// release the modifier
// XXX -- this doesn't work! if Alt and Meta are mapped
// to one key and we want to release Meta we can't do
@ -974,7 +967,7 @@ KeyMap::addKeystrokes(EKeystroke type, const KeyItem& keyItem,
UInt32 data = keyItem.m_client;
switch (type) {
case kKeystrokePress:
keystrokes.push_back(Keystroke(button, true, false, data));
keystrokes.emplace_back(button, true, false, data);
if (keyItem.m_generates != 0) {
if (!keyItem.m_lock || (currentState & keyItem.m_generates) == 0) {
// add modifier key and activate modifier
@ -991,13 +984,13 @@ KeyMap::addKeystrokes(EKeystroke type, const KeyItem& keyItem,
break;
case kKeystrokeRelease:
keystrokes.push_back(Keystroke(button, false, false, data));
keystrokes.emplace_back(button, false, false, data);
if (keyItem.m_generates != 0 && !keyItem.m_lock) {
// remove key from active modifiers
std::pair<ModifierToKeys::iterator,
ModifierToKeys::iterator> range =
activeModifiers.equal_range(keyItem.m_generates);
for (ModifierToKeys::iterator i = range.first;
for (auto i = range.first;
i != range.second; ++i) {
if (i->second.m_button == button) {
activeModifiers.erase(i);
@ -1013,14 +1006,14 @@ KeyMap::addKeystrokes(EKeystroke type, const KeyItem& keyItem,
break;
case kKeystrokeRepeat:
keystrokes.push_back(Keystroke(button, false, true, data));
keystrokes.push_back(Keystroke(button, true, true, data));
keystrokes.emplace_back(button, false, true, data);
keystrokes.emplace_back(button, true, true, data);
// no modifier changes on key repeat
break;
case kKeystrokeClick:
keystrokes.push_back(Keystroke(button, true, false, data));
keystrokes.push_back(Keystroke(button, false, false, data));
keystrokes.emplace_back(button, true, false, data);
keystrokes.emplace_back(button, false, false, data);
// no modifier changes on key click
break;
@ -1031,22 +1024,22 @@ KeyMap::addKeystrokes(EKeystroke type, const KeyItem& keyItem,
if (m_halfDuplex.count(button) > 0) {
if (type == kKeystrokeModify) {
// turn half-duplex toggle on (press)
keystrokes.push_back(Keystroke(button, true, false, data));
keystrokes.emplace_back(button, true, false, data);
}
else {
// turn half-duplex toggle off (release)
keystrokes.push_back(Keystroke(button, false, false, data));
keystrokes.emplace_back(button, false, false, data);
}
}
else {
// toggle (click)
keystrokes.push_back(Keystroke(button, true, false, data));
keystrokes.push_back(Keystroke(button, false, false, data));
keystrokes.emplace_back(button, true, false, data);
keystrokes.emplace_back(button, false, false, data);
}
}
else if (type == kKeystrokeModify) {
// press modifier
keystrokes.push_back(Keystroke(button, true, false, data));
keystrokes.emplace_back(button, true, false, data);
}
else {
// release all the keys that generate the modifier that are
@ -1054,10 +1047,10 @@ KeyMap::addKeystrokes(EKeystroke type, const KeyItem& keyItem,
std::pair<ModifierToKeys::const_iterator,
ModifierToKeys::const_iterator> range =
activeModifiers.equal_range(keyItem.m_generates);
for (ModifierToKeys::const_iterator i = range.first;
for (auto i = range.first;
i != range.second; ++i) {
keystrokes.push_back(Keystroke(i->second.m_button,
false, false, i->second.m_client));
keystrokes.emplace_back(i->second.m_button,
false, false, i->second.m_client);
}
}
@ -1170,7 +1163,7 @@ KeyMap::formatKey(KeyID key, KeyModifierMask mask)
}
// XXX -- we're assuming ASCII here
else if (key >= 33 && key < 127) {
x += (char)key;
x += static_cast<char>(key);
}
else {
x += synergy::string::sprintf("\\u%04x", key);
@ -1196,16 +1189,16 @@ KeyMap::parseKey(const String& x, KeyID& key)
}
// XXX -- we're assuming ASCII encoding here
else if (x.size() == 1) {
if (!isgraph(x[0])) {
if (isgraph(x[0]) == 0) {
// unknown key
return false;
}
key = (KeyID)x[0];
key = static_cast<KeyID>(x[0]);
}
else if (x.size() == 6 && x[0] == '\\' && x[1] == 'u') {
// escaped unicode (\uXXXX where XXXX is a hex number)
char* end;
key = (KeyID)strtol(x.c_str() + 2, &end, 16);
key = static_cast<KeyID>(strtol(x.c_str() + 2, &end, 16));
if (*end != '\0') {
return false;
}
@ -1280,19 +1273,19 @@ void
KeyMap::initKeyNameMaps()
{
// initialize tables
if (s_nameToKeyMap == NULL) {
if (s_nameToKeyMap == nullptr) {
s_nameToKeyMap = new NameToKeyMap;
s_keyToNameMap = new KeyToNameMap;
for (const KeyNameMapEntry* i = kKeyNameMap; i->m_name != NULL; ++i) {
for (const KeyNameMapEntry* i = kKeyNameMap; i->m_name != nullptr; ++i) {
(*s_nameToKeyMap)[i->m_name] = i->m_id;
(*s_keyToNameMap)[i->m_id] = i->m_name;
}
}
if (s_nameToModifierMap == NULL) {
if (s_nameToModifierMap == nullptr) {
s_nameToModifierMap = new NameToModifierMap;
s_modifierToNameMap = new ModifierToNameMap;
for (const KeyModifierNameMapEntry* i = kModifierNameMap;
i->m_name != NULL; ++i) {
i->m_name != nullptr; ++i) {
(*s_nameToModifierMap)[i->m_name] = i->m_mask;
(*s_modifierToNameMap)[i->m_mask] = i->m_name;
}
@ -1341,4 +1334,4 @@ KeyMap::Keystroke::Keystroke(SInt32 group, bool absolute, bool restore) :
m_data.m_group.m_restore = restore;
}
}
} // namespace synergy

View File

@ -82,7 +82,7 @@ public:
kGroup //!< Set new group
};
Keystroke(KeyButton, bool press, bool repeat, UInt32 clientData);
Keystroke(KeyButton, bool press, bool repeat, UInt32 data);
Keystroke(SInt32 group, bool absolute, bool restore);
public:
@ -106,7 +106,7 @@ public:
};
EType m_type;
Data m_data;
Data m_data{};
};
//! A sequence of keystrokes
@ -278,7 +278,7 @@ public:
/*!
Put all the keys in \p modifiers into \p keys.
*/
static void collectButtons(const ModifierToKeys& modifiers,
static void collectButtons(const ModifierToKeys& mods,
ButtonToKeyMap& keys);
//! Set modifier key state
@ -500,7 +500,7 @@ private:
KeySet m_halfDuplexMods; // half-duplex set by user
// dummy KeyItem for changing modifiers
KeyItem m_modifierKeyItem;
KeyItem m_modifierKeyItem{};
// parsing/formatting tables
static NameToKeyMap* s_nameToKeyMap;

View File

@ -19,12 +19,12 @@
#include "core/KeyState.h"
#include "base/Log.h"
#include <cstring>
#include <algorithm>
#include <cstring>
#include <iterator>
#include <list>
static const KeyButton kButtonMask = (KeyButton)(IKeyState::kNumButtons - 1);
static const KeyButton kButtonMask = static_cast<KeyButton>(IKeyState::kNumButtons - 1);
static const KeyID s_decomposeTable[] = {
// spacing version of dead keys
@ -395,7 +395,7 @@ KeyState::KeyState(IEventQueue* events) :
KeyState::KeyState(IEventQueue* events, synergy::KeyMap& keyMap) :
IKeyState(events),
m_keyMapPtr(0),
m_keyMapPtr(nullptr),
m_keyMap(keyMap),
m_mask(0),
m_events(events)
@ -405,8 +405,7 @@ KeyState::KeyState(IEventQueue* events, synergy::KeyMap& keyMap) :
KeyState::~KeyState()
{
if (m_keyMapPtr)
delete m_keyMapPtr;
delete m_keyMapPtr;
}
void
@ -503,9 +502,8 @@ KeyState::updateKeyState()
// get the current keyboard state
KeyButtonSet keysDown;
pollPressedKeys(keysDown);
for (KeyButtonSet::const_iterator i = keysDown.begin();
i != keysDown.end(); ++i) {
m_keys[*i] = 1;
for (unsigned short i : keysDown) {
m_keys[i] = 1;
}
// get the current modifier state
@ -520,10 +518,10 @@ KeyState::updateKeyState()
}
void
KeyState::addActiveModifierCB(KeyID, SInt32 group,
KeyState::addActiveModifierCB(KeyID /*unused*/, SInt32 group,
synergy::KeyMap::KeyItem& keyItem, void* vcontext)
{
AddActiveModifierContext* context =
auto* context =
static_cast<AddActiveModifierContext*>(vcontext);
if (group == context->m_activeGroup &&
(keyItem.m_generates & context->m_mask) != 0) {
@ -570,7 +568,7 @@ KeyState::fakeKeyDown(KeyID id, KeyModifierMask mask, KeyButton serverID)
const synergy::KeyMap::KeyItem* keyItem =
m_keyMap.mapKey(keys, id, pollActiveGroup(), m_activeModifiers,
getActiveModifiersRValue(), mask, false);
if (keyItem == NULL) {
if (keyItem == nullptr) {
// a media key won't be mapped on mac, so we need to fake it in a
// special way
if (id == kKeyAudioDown || id == kKeyAudioUp ||
@ -585,7 +583,7 @@ KeyState::fakeKeyDown(KeyID id, KeyModifierMask mask, KeyButton serverID)
return;
}
KeyButton localID = (KeyButton)(keyItem->m_button & kButtonMask);
auto localID = static_cast<KeyButton>(keyItem->m_button & kButtonMask);
updateModifierKeyState(localID, oldActiveModifiers, m_activeModifiers);
if (localID != 0) {
// note keys down
@ -618,10 +616,10 @@ KeyState::fakeKeyRepeat(
const synergy::KeyMap::KeyItem* keyItem =
m_keyMap.mapKey(keys, id, pollActiveGroup(), m_activeModifiers,
getActiveModifiersRValue(), mask, true);
if (keyItem == NULL) {
if (keyItem == nullptr) {
return false;
}
KeyButton localID = (KeyButton)(keyItem->m_button & kButtonMask);
auto localID = static_cast<KeyButton>(keyItem->m_button & kButtonMask);
if (localID == 0) {
return false;
}
@ -635,11 +633,10 @@ KeyState::fakeKeyRepeat(
if (localID != oldLocalID) {
// replace key up with previous KeyButton but leave key down
// alone so it uses the new KeyButton.
for (Keystrokes::iterator index = keys.begin();
index != keys.end(); ++index) {
if (index->m_type == Keystroke::kButton &&
index->m_data.m_button.m_button == localID) {
index->m_data.m_button.m_button = oldLocalID;
for (auto & key : keys) {
if (key.m_type == Keystroke::kButton &&
key.m_data.m_button.m_button == localID) {
key.m_data.m_button.m_button = oldLocalID;
break;
}
}
@ -672,7 +669,7 @@ KeyState::fakeKeyUp(KeyButton serverID)
// get the sequence of keys to simulate key release
Keystrokes keys;
keys.push_back(Keystroke(localID, false, false, m_keyClientData[localID]));
keys.emplace_back(localID, false, false, m_keyClientData[localID]);
// note keys down
--m_keys[localID];
@ -680,13 +677,13 @@ KeyState::fakeKeyUp(KeyButton serverID)
m_serverKeys[serverID] = 0;
// check if this is a modifier
ModifierToKeys::iterator i = m_activeModifiers.begin();
auto i = m_activeModifiers.begin();
while (i != m_activeModifiers.end()) {
if (i->second.m_button == localID && !i->second.m_lock) {
// modifier is no longer down
KeyModifierMask mask = i->first;
ModifierToKeys::iterator tmp = i;
auto tmp = i;
++i;
m_activeModifiers.erase(tmp);
@ -712,7 +709,7 @@ KeyState::fakeAllKeysUp()
Keystrokes keys;
for (KeyButton i = 0; i < IKeyState::kNumButtons; ++i) {
if (m_syntheticKeys[i] > 0) {
keys.push_back(Keystroke(i, false, false, m_keyClientData[i]));
keys.emplace_back(i, false, false, m_keyClientData[i]);
m_keys[i] = 0;
m_syntheticKeys[i] = 0;
}
@ -724,7 +721,7 @@ KeyState::fakeAllKeysUp()
}
bool
KeyState::fakeMediaKey(KeyID id)
KeyState::fakeMediaKey(KeyID /*id*/)
{
return false;
}
@ -754,7 +751,7 @@ KeyState::getEffectiveGroup(SInt32 group, SInt32 offset) const
}
bool
KeyState::isIgnoredKey(KeyID key, KeyModifierMask) const
KeyState::isIgnoredKey(KeyID key, KeyModifierMask /*unused*/) const
{
switch (key) {
case kKeyCapsLock:
@ -772,12 +769,12 @@ KeyState::getButton(KeyID id, SInt32 group) const
{
const synergy::KeyMap::KeyItemList* items =
m_keyMap.findCompatibleKey(id, group, 0, 0);
if (items == NULL) {
if (items == nullptr) {
return 0;
}
else {
return items->back().m_button;
}
}
void
@ -849,11 +846,11 @@ KeyState::fakeKeys(const Keystrokes& keys, UInt32 count)
// generate key events
LOG((CLOG_DEBUG1 "keystrokes:"));
for (Keystrokes::const_iterator k = keys.begin(); k != keys.end(); ) {
for (auto k = keys.begin(); k != keys.end(); ) {
if (k->m_type == Keystroke::kButton && k->m_data.m_button.m_repeat) {
// repeat from here up to but not including the next key
// with m_repeat == false count times.
Keystrokes::const_iterator start = k;
auto start = k;
while (count-- > 0) {
// send repeating events
for (k = start; k != keys.end() &&
@ -883,13 +880,11 @@ KeyState::updateModifierKeyState(KeyButton button,
{
// get the pressed modifier buttons before and after
synergy::KeyMap::ButtonToKeyMap oldKeys, newKeys;
for (ModifierToKeys::const_iterator i = oldModifiers.begin();
i != oldModifiers.end(); ++i) {
oldKeys.insert(std::make_pair(i->second.m_button, &i->second));
for (const auto & oldModifier : oldModifiers) {
oldKeys.insert(std::make_pair(oldModifier.second.m_button, &oldModifier.second));
}
for (ModifierToKeys::const_iterator i = newModifiers.begin();
i != newModifiers.end(); ++i) {
newKeys.insert(std::make_pair(i->second.m_button, &i->second));
for (const auto & newModifier : newModifiers) {
newKeys.insert(std::make_pair(newModifier.second.m_button, &newModifier.second));
}
// get the modifier buttons that were pressed or released

View File

@ -67,10 +67,10 @@ public:
virtual void updateKeyState();
virtual void setHalfDuplexMask(KeyModifierMask);
virtual void fakeKeyDown(KeyID id, KeyModifierMask mask,
KeyButton button);
KeyButton serverID);
virtual bool fakeKeyRepeat(KeyID id, KeyModifierMask mask,
SInt32 count, KeyButton button);
virtual bool fakeKeyUp(KeyButton button);
SInt32 count, KeyButton serverID);
virtual bool fakeKeyUp(KeyButton serverID);
virtual void fakeAllKeysUp();
virtual bool fakeCtrlAltDel() = 0;
virtual bool fakeMediaKey(KeyID id);
@ -213,20 +213,20 @@ private:
// current keyboard state (> 0 if pressed, 0 otherwise). this is
// initialized to the keyboard state according to the system then
// it tracks synthesized events.
SInt32 m_keys[kNumButtons];
SInt32 m_keys[kNumButtons]{};
// synthetic keyboard state (> 0 if pressed, 0 otherwise). this
// tracks the synthesized keyboard state. if m_keys[n] > 0 but
// m_syntheticKeys[n] == 0 then the key was pressed locally and
// not synthesized yet.
SInt32 m_syntheticKeys[kNumButtons];
SInt32 m_syntheticKeys[kNumButtons]{};
// client data for each pressed key
UInt32 m_keyClientData[kNumButtons];
UInt32 m_keyClientData[kNumButtons]{};
// server keyboard state. an entry is 0 if not the key isn't pressed
// otherwise it's the local KeyButton synthesized for the server key.
KeyButton m_serverKeys[kNumButtons];
KeyButton m_serverKeys[kNumButtons]{};
IEventQueue* m_events;
};

View File

@ -18,8 +18,8 @@
#include "core/PacketStreamFilter.h"
#include "base/IEventQueue.h"
#include "mt/Lock.h"
#include "base/TMethodEventJob.h"
#include "mt/Lock.h"
#include <cstring>
#include <memory>
@ -71,7 +71,7 @@ PacketStreamFilter::read(void* buffer, UInt32 n)
}
// read it
if (buffer != NULL) {
if (buffer != nullptr) {
memcpy(buffer, m_buffer.peek(n), n);
}
m_buffer.pop(n);
@ -83,7 +83,7 @@ PacketStreamFilter::read(void* buffer, UInt32 n)
if (m_inputShutdown && m_size == 0) {
m_events->addEvent(Event(m_events->forIStream().inputShutdown(),
getEventTarget(), NULL));
getEventTarget(), nullptr));
}
return n;
@ -94,10 +94,10 @@ PacketStreamFilter::write(const void* buffer, UInt32 count)
{
// write the length of the payload
UInt8 length[4];
length[0] = (UInt8)((count >> 24) & 0xff);
length[1] = (UInt8)((count >> 16) & 0xff);
length[2] = (UInt8)((count >> 8) & 0xff);
length[3] = (UInt8)( count & 0xff);
length[0] = static_cast<UInt8>((count >> 24) & 0xff);
length[1] = static_cast<UInt8>((count >> 16) & 0xff);
length[2] = static_cast<UInt8>((count >> 8) & 0xff);
length[3] = static_cast<UInt8>( count & 0xff);
getStream()->write(length, sizeof(length));
// write the payload
@ -142,10 +142,10 @@ PacketStreamFilter::readPacketSize()
UInt8 buffer[4];
memcpy(buffer, m_buffer.peek(sizeof(buffer)), sizeof(buffer));
m_buffer.pop(sizeof(buffer));
m_size = ((UInt32)buffer[0] << 24) |
((UInt32)buffer[1] << 16) |
((UInt32)buffer[2] << 8) |
(UInt32)buffer[3];
m_size = (static_cast<UInt32>(buffer[0]) << 24) |
(static_cast<UInt32>(buffer[1]) << 16) |
(static_cast<UInt32>(buffer[2]) << 8) |
static_cast<UInt32>(buffer[3]);
}
}

View File

@ -36,7 +36,7 @@ public:
// IStream overrides
virtual void close();
virtual UInt32 read(void* buffer, UInt32 n);
virtual void write(const void* buffer, UInt32 n);
virtual void write(const void* buffer, UInt32 count);
virtual void shutdownInput();
virtual bool isReady() const;
virtual UInt32 getSize() const;

View File

@ -17,11 +17,11 @@
*/
#include "core/PortableTaskBarReceiver.h"
#include "mt/Lock.h"
#include "base/String.h"
#include "base/IEventQueue.h"
#include "arch/Arch.h"
#include "base/IEventQueue.h"
#include "base/String.h"
#include "common/Version.h"
#include "mt/Lock.h"
//
// PortableTaskBarReceiver
@ -45,7 +45,7 @@ PortableTaskBarReceiver::updateStatus(INode* node, const String& errorMsg)
{
// update our status
m_errorMessage = errorMsg;
if (node == NULL) {
if (node == nullptr) {
if (m_errorMessage.empty()) {
m_state = kNotRunning;
}
@ -84,7 +84,7 @@ PortableTaskBarReceiver::quit()
}
void
PortableTaskBarReceiver::onStatusChanged(INode*)
PortableTaskBarReceiver::onStatusChanged(INode* /*unused*/)
{
// do nothing
}

View File

@ -17,9 +17,9 @@
*/
#include "core/ProtocolUtil.h"
#include "io/IStream.h"
#include "base/Log.h"
#include "common/stdvector.h"
#include "io/IStream.h"
#include <cctype>
#include <cstring>
@ -78,7 +78,7 @@ ProtocolUtil::vwritef(synergy::IStream* stream,
}
// fill buffer
UInt8* buffer = new UInt8[size];
auto* buffer = new UInt8[size];
writef(buffer, fmt, args);
try {
@ -101,7 +101,7 @@ ProtocolUtil::vreadf(synergy::IStream* stream, const char* fmt, va_list args)
assert(fmt != NULL);
// begin scanning
while (*fmt) {
while (*fmt != 0) {
if (*fmt == '%') {
// format specifier. determine argument size.
++fmt;
@ -234,7 +234,7 @@ ProtocolUtil::vreadf(synergy::IStream* stream, const char* fmt, va_list args)
// save the data
String* dst = va_arg(args, String*);
dst->assign((const char*)sBuffer, len);
dst->assign(reinterpret_cast<const char*>(sBuffer), len);
// release the buffer
if (!useFixed) {
@ -275,7 +275,7 @@ UInt32
ProtocolUtil::getLength(const char* fmt, va_list args)
{
UInt32 n = 0;
while (*fmt) {
while (*fmt != 0) {
if (*fmt == '%') {
// format specifier. determine argument size.
++fmt;
@ -290,22 +290,22 @@ ProtocolUtil::getLength(const char* fmt, va_list args)
assert(len == 1 || len == 2 || len == 4);
switch (len) {
case 1:
len = (UInt32)(va_arg(args, std::vector<UInt8>*))->size() + 4;
len = static_cast<UInt32>((va_arg(args, std::vector<UInt8>*))->size()) + 4;
break;
case 2:
len = 2 * (UInt32)(va_arg(args, std::vector<UInt16>*))->size() + 4;
len = 2 * static_cast<UInt32>((va_arg(args, std::vector<UInt16>*))->size()) + 4;
break;
case 4:
len = 4 * (UInt32)(va_arg(args, std::vector<UInt32>*))->size() + 4;
len = 4 * static_cast<UInt32>((va_arg(args, std::vector<UInt32>*))->size()) + 4;
break;
}
break;
case 's':
assert(len == 0);
len = (UInt32)(va_arg(args, String*))->size() + 4;
len = static_cast<UInt32>((va_arg(args, String*))->size()) + 4;
(void)va_arg(args, UInt8*);
break;
@ -340,9 +340,9 @@ ProtocolUtil::getLength(const char* fmt, va_list args)
void
ProtocolUtil::writef(void* buffer, const char* fmt, va_list args)
{
UInt8* dst = static_cast<UInt8*>(buffer);
auto* dst = static_cast<UInt8*>(buffer);
while (*fmt) {
while (*fmt != 0) {
if (*fmt == '%') {
// format specifier. determine argument size.
++fmt;
@ -383,7 +383,7 @@ ProtocolUtil::writef(void* buffer, const char* fmt, va_list args)
// 1 byte integers
const std::vector<UInt8>* list =
va_arg(args, const std::vector<UInt8>*);
const UInt32 n = (UInt32)list->size();
const auto n = static_cast<UInt32>(list->size());
*dst++ = static_cast<UInt8>((n >> 24) & 0xff);
*dst++ = static_cast<UInt8>((n >> 16) & 0xff);
*dst++ = static_cast<UInt8>((n >> 8) & 0xff);
@ -398,7 +398,7 @@ ProtocolUtil::writef(void* buffer, const char* fmt, va_list args)
// 2 byte integers
const std::vector<UInt16>* list =
va_arg(args, const std::vector<UInt16>*);
const UInt32 n = (UInt32)list->size();
const auto n = static_cast<UInt32>(list->size());
*dst++ = static_cast<UInt8>((n >> 24) & 0xff);
*dst++ = static_cast<UInt8>((n >> 16) & 0xff);
*dst++ = static_cast<UInt8>((n >> 8) & 0xff);
@ -415,7 +415,7 @@ ProtocolUtil::writef(void* buffer, const char* fmt, va_list args)
// 4 byte integers
const std::vector<UInt32>* list =
va_arg(args, const std::vector<UInt32>*);
const UInt32 n = (UInt32)list->size();
const auto n = static_cast<UInt32>(list->size());
*dst++ = static_cast<UInt8>((n >> 24) & 0xff);
*dst++ = static_cast<UInt8>((n >> 16) & 0xff);
*dst++ = static_cast<UInt8>((n >> 8) & 0xff);
@ -440,7 +440,7 @@ ProtocolUtil::writef(void* buffer, const char* fmt, va_list args)
case 's': {
assert(len == 0);
const String* src = va_arg(args, String*);
const UInt32 len = (src != NULL) ? (UInt32)src->size() : 0;
const UInt32 len = (src != nullptr) ? static_cast<UInt32>(src->size()) : 0;
*dst++ = static_cast<UInt8>((len >> 24) & 0xff);
*dst++ = static_cast<UInt8>((len >> 16) & 0xff);
*dst++ = static_cast<UInt8>((len >> 8) & 0xff);
@ -515,7 +515,7 @@ ProtocolUtil::read(synergy::IStream* stream, void* vbuffer, UInt32 count)
assert(stream != NULL);
assert(vbuffer != NULL);
UInt8* buffer = static_cast<UInt8*>(vbuffer);
auto* buffer = static_cast<UInt8*>(vbuffer);
while (count > 0) {
// read more
UInt32 n = stream->read(buffer, count);
@ -538,7 +538,7 @@ ProtocolUtil::read(synergy::IStream* stream, void* vbuffer, UInt32 count)
//
String
XIOReadMismatch::getWhat() const throw()
XIOReadMismatch::getWhat() const noexcept
{
return format("XIOReadMismatch", "ProtocolUtil::readf() mismatch");
}

View File

@ -80,7 +80,7 @@ private:
static UInt32 getLength(const char* fmt, va_list);
static void writef(void*, const char* fmt, va_list);
static UInt32 eatLength(const char** fmt);
static UInt32 eatLength(const char** pfmt);
static void read(synergy::IStream*, void*, UInt32);
};

View File

@ -17,12 +17,12 @@
*/
#include "core/Screen.h"
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "core/IPlatformScreen.h"
#include "core/protocol_types.h"
#include "base/Log.h"
#include "base/IEventQueue.h"
#include "server/ClientProxy.h"
#include "base/TMethodEventJob.h"
namespace synergy {
@ -172,7 +172,7 @@ Screen::setClipboard(ClipboardID id, const IClipboard* clipboard)
void
Screen::grabClipboard(ClipboardID id)
{
m_screen->setClipboard(id, NULL);
m_screen->setClipboard(id, nullptr);
}
void
@ -210,7 +210,7 @@ Screen::keyRepeat(KeyID id,
}
void
Screen::keyUp(KeyID, KeyModifierMask, KeyButton button)
Screen::keyUp(KeyID /*unused*/, KeyModifierMask /*unused*/, KeyButton button)
{
m_screen->fakeKeyUp(button);
}
@ -272,7 +272,7 @@ Screen::setOptions(const OptionsList& options)
{
// update options
bool oldScreenSaverSync = m_screenSaverSync;
for (UInt32 i = 0, n = (UInt32)options.size(); i < n; i += 2) {
for (UInt32 i = 0, n = static_cast<UInt32>(options.size()); i < n; i += 2) {
if (options[i] == kOptionScreenSaverSync) {
m_screenSaverSync = (options[i + 1] != 0);
LOG((CLOG_DEBUG1 "screen saver synchronization %s", m_screenSaverSync ? "on" : "off"));
@ -378,11 +378,11 @@ Screen::isLockedToScreen() const
}
if (m_enableDragDrop) {
return (buttonID == kButtonLeft) ? false : true;
return buttonID != kButtonLeft;
}
else {
return true;
}
}
// not locked
@ -395,9 +395,9 @@ Screen::getJumpZoneSize() const
if (!m_isPrimary) {
return 0;
}
else {
return m_screen->getJumpZoneSize();
}
}
void
@ -535,7 +535,7 @@ Screen::enterPrimary()
}
void
Screen::enterSecondary(KeyModifierMask)
Screen::enterSecondary(KeyModifierMask /*unused*/)
{
// do nothing
}
@ -556,4 +556,4 @@ Screen::leaveSecondary()
m_screen->fakeAllKeysUp();
}
}
} // namespace synergy

View File

@ -143,27 +143,27 @@ public:
/*!
Synthesize mouse events to generate a press of mouse button \c id.
*/
void mouseDown(ButtonID id);
void mouseDown(ButtonID button);
//! Notify of mouse release
/*!
Synthesize mouse events to generate a release of mouse button \c id.
*/
void mouseUp(ButtonID id);
void mouseUp(ButtonID button);
//! Notify of mouse motion
/*!
Synthesize mouse events to generate mouse motion to the absolute
screen position \c xAbs,yAbs.
*/
void mouseMove(SInt32 xAbs, SInt32 yAbs);
void mouseMove(SInt32 x, SInt32 y);
//! Notify of mouse motion
/*!
Synthesize mouse events to generate mouse motion by the relative
amount \c xRel,yRel.
*/
void mouseRelativeMove(SInt32 xRel, SInt32 yRel);
void mouseRelativeMove(SInt32 dx, SInt32 dy);
//! Notify of mouse wheel motion
/*!
@ -297,7 +297,7 @@ public:
virtual void* getEventTarget() const;
virtual bool getClipboard(ClipboardID id, IClipboard*) const;
virtual void getShape(SInt32& x, SInt32& y,
SInt32& width, SInt32& height) const;
SInt32& w, SInt32& h) const;
virtual void getCursorPos(SInt32& x, SInt32& y) const;
IPlatformScreen* getPlatformScreen() { return m_screen; }
@ -331,7 +331,7 @@ private:
// note toggle keys that toggles on up/down (false) or on
// transition (true)
KeyModifierMask m_halfDuplex;
KeyModifierMask m_halfDuplex{};
// true if we're faking input on a primary screen
bool m_fakeInput;

View File

@ -18,27 +18,27 @@
#include "core/ServerApp.h"
#include "server/Server.h"
#include "server/ClientListener.h"
#include "server/ClientProxy.h"
#include "server/PrimaryClient.h"
#include "core/ArgParser.h"
#include "core/Screen.h"
#include "core/XScreen.h"
#include "core/ServerTaskBarReceiver.h"
#include "core/ServerArgs.h"
#include "net/SocketMultiplexer.h"
#include "net/TCPSocketFactory.h"
#include "net/XSocket.h"
#include "arch/Arch.h"
#include "base/EventQueue.h"
#include "base/log_outputters.h"
#include "base/FunctionEventJob.h"
#include "base/TMethodJob.h"
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "base/TMethodJob.h"
#include "base/log_outputters.h"
#include "common/Version.h"
#include "core/ArgParser.h"
#include "core/Screen.h"
#include "core/ServerArgs.h"
#include "core/ServerTaskBarReceiver.h"
#include "core/XScreen.h"
#include "net/SocketMultiplexer.h"
#include "net/TCPSocketFactory.h"
#include "net/XSocket.h"
#include "server/ClientListener.h"
#include "server/ClientProxy.h"
#include "server/PrimaryClient.h"
#include "server/Server.h"
#if SYSAPI_WIN32
#include "arch/win32/ArchMiscWindows.h"
@ -56,9 +56,9 @@
#include "platform/OSXDragSimulator.h"
#endif
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <fstream>
//
// ServerApp
@ -66,19 +66,18 @@
ServerApp::ServerApp(IEventQueue* events) :
App(events, new ServerArgs()),
m_server(NULL),
m_server(nullptr),
m_serverState(kUninitialized),
m_serverScreen(NULL),
m_primaryClient(NULL),
m_listener(NULL),
m_timer(NULL),
m_synergyAddress(NULL)
m_serverScreen(nullptr),
m_primaryClient(nullptr),
m_listener(nullptr),
m_timer(nullptr),
m_synergyAddress(nullptr)
{
}
ServerApp::~ServerApp()
{
}
= default;
void
ServerApp::parseArgs(int argc, const char* const* argv)
@ -159,7 +158,7 @@ ServerApp::help()
}
void
ServerApp::reloadSignalHandler(Arch::ESignal, void*)
ServerApp::reloadSignalHandler(Arch::ESignal /*unused*/, void* /*unused*/)
{
IEventQueue* events = App::instance().getEvents();
events->addEvent(Event(events->forServerApp().reloadConfig(),
@ -167,11 +166,11 @@ ServerApp::reloadSignalHandler(Arch::ESignal, void*)
}
void
ServerApp::reloadConfig(const Event&, void*)
ServerApp::reloadConfig(const Event& /*unused*/, void* /*unused*/)
{
LOG((CLOG_DEBUG "reload configuration"));
if (loadConfig(args().m_configFile)) {
if (m_server != NULL) {
if (m_server != nullptr) {
m_server->setConfig(*args().m_config);
}
LOG((CLOG_NOTE "reloaded configuration"));
@ -249,26 +248,26 @@ ServerApp::loadConfig(const String& pathname)
}
void
ServerApp::forceReconnect(const Event&, void*)
ServerApp::forceReconnect(const Event& /*unused*/, void* /*unused*/)
{
if (m_server != NULL) {
if (m_server != nullptr) {
m_server->disconnect();
}
}
void
ServerApp::handleClientConnected(const Event&, void* vlistener)
ServerApp::handleClientConnected(const Event& /*unused*/, void* vlistener)
{
ClientListener* listener = static_cast<ClientListener*>(vlistener);
auto* listener = static_cast<ClientListener*>(vlistener);
ClientProxy* client = listener->getNextClient();
if (client != NULL) {
if (client != nullptr) {
m_server->adoptClient(client);
updateStatus();
}
}
void
ServerApp::handleClientsDisconnected(const Event&, void*)
ServerApp::handleClientsDisconnected(const Event& /*unused*/, void* /*unused*/)
{
m_events->addEvent(Event(Event::kQuit));
}
@ -276,7 +275,7 @@ ServerApp::handleClientsDisconnected(const Event&, void*)
void
ServerApp::closeServer(Server* server)
{
if (server == NULL) {
if (server == nullptr) {
return;
}
@ -285,7 +284,7 @@ ServerApp::closeServer(Server* server)
// wait for clients to disconnect for up to timeout seconds
double timeout = 3.0;
EventQueueTimer* timer = m_events->newOneShotTimer(timeout, NULL);
EventQueueTimer* timer = m_events->newOneShotTimer(timeout, nullptr);
m_events->adoptHandler(Event::kTimer, timer,
new TMethodEventJob<ServerApp>(this, &ServerApp::handleClientsDisconnected));
m_events->adoptHandler(m_events->forServer().disconnected(), server,
@ -304,10 +303,10 @@ ServerApp::closeServer(Server* server)
void
ServerApp::stopRetryTimer()
{
if (m_timer != NULL) {
if (m_timer != nullptr) {
m_events->deleteTimer(m_timer);
m_events->removeHandler(Event::kTimer, NULL);
m_timer = NULL;
m_events->removeHandler(Event::kTimer, nullptr);
m_timer = nullptr;
}
}
@ -317,14 +316,14 @@ ServerApp::updateStatus()
updateStatus("");
}
void ServerApp::updateStatus(const String& msg)
void ServerApp::updateStatus(const String& /*msg*/)
{
}
void
ServerApp::closeClientListener(ClientListener* listen)
{
if (listen != NULL) {
if (listen != nullptr) {
m_events->removeHandler(m_events->forClientListener().connected(), listen);
delete listen;
}
@ -336,8 +335,8 @@ ServerApp::stopServer()
if (m_serverState == kStarted) {
closeServer(m_server);
closeClientListener(m_listener);
m_server = NULL;
m_listener = NULL;
m_server = nullptr;
m_listener = nullptr;
m_serverState = kInitialized;
}
else if (m_serverState == kStarting) {
@ -357,7 +356,7 @@ ServerApp::closePrimaryClient(PrimaryClient* primaryClient)
void
ServerApp::closeServerScreen(synergy::Screen* screen)
{
if (screen != NULL) {
if (screen != nullptr) {
m_events->removeHandler(m_events->forIScreen().error(),
screen->getEventTarget());
m_events->removeHandler(m_events->forIScreen().suspend(),
@ -374,8 +373,8 @@ void ServerApp::cleanupServer()
if (m_serverState == kInitialized) {
closePrimaryClient(m_primaryClient);
closeServerScreen(m_serverScreen);
m_primaryClient = NULL;
m_serverScreen = NULL;
m_primaryClient = nullptr;
m_serverScreen = nullptr;
m_serverState = kUninitialized;
}
else if (m_serverState == kInitializing ||
@ -389,7 +388,7 @@ void ServerApp::cleanupServer()
}
void
ServerApp::retryHandler(const Event&, void*)
ServerApp::retryHandler(const Event& /*unused*/, void* /*unused*/)
{
// discard old timer
assert(m_timer != NULL);
@ -443,8 +442,8 @@ bool ServerApp::initServer()
}
double retryTime;
synergy::Screen* serverScreen = NULL;
PrimaryClient* primaryClient = NULL;
synergy::Screen* serverScreen = nullptr;
PrimaryClient* primaryClient = nullptr;
try {
String name = args().m_config->getCanonicalName(args().m_name);
serverScreen = openServerScreen();
@ -479,16 +478,16 @@ bool ServerApp::initServer()
// install a timer and handler to retry later
assert(m_timer == NULL);
LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime));
m_timer = m_events->newOneShotTimer(retryTime, NULL);
m_timer = m_events->newOneShotTimer(retryTime, nullptr);
m_events->adoptHandler(Event::kTimer, m_timer,
new TMethodEventJob<ServerApp>(this, &ServerApp::retryHandler));
m_serverState = kInitializing;
return true;
}
else {
// don't try again
return false;
}
}
synergy::Screen*
@ -534,7 +533,7 @@ ServerApp::startServer()
}
double retryTime;
ClientListener* listener = NULL;
ClientListener* listener = nullptr;
try {
listener = openClientListener(args().m_config->getSynergyAddress());
m_server = openServer(*args().m_config, m_primaryClient);
@ -562,16 +561,16 @@ ServerApp::startServer()
// install a timer and handler to retry later
assert(m_timer == NULL);
LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime));
m_timer = m_events->newOneShotTimer(retryTime, NULL);
m_timer = m_events->newOneShotTimer(retryTime, nullptr);
m_events->adoptHandler(Event::kTimer, m_timer,
new TMethodEventJob<ServerApp>(this, &ServerApp::retryHandler));
m_serverState = kStarting;
return true;
}
else {
// don't try again
return false;
}
}
synergy::Screen*
@ -597,14 +596,14 @@ ServerApp::openPrimaryClient(const String& name, synergy::Screen* screen)
}
void
ServerApp::handleScreenError(const Event&, void*)
ServerApp::handleScreenError(const Event& /*unused*/, void* /*unused*/)
{
LOG((CLOG_CRIT "error on screen"));
m_events->addEvent(Event(Event::kQuit));
}
void
ServerApp::handleSuspend(const Event&, void*)
ServerApp::handleSuspend(const Event& /*unused*/, void* /*unused*/)
{
if (!m_suspended) {
LOG((CLOG_INFO "suspend"));
@ -614,7 +613,7 @@ ServerApp::handleSuspend(const Event&, void*)
}
void
ServerApp::handleResume(const Event&, void*)
ServerApp::handleResume(const Event& /*unused*/, void* /*unused*/)
{
if (m_suspended) {
LOG((CLOG_INFO "resume"));
@ -626,7 +625,7 @@ ServerApp::handleResume(const Event&, void*)
ClientListener*
ServerApp::openClientListener(const NetworkAddress& address)
{
ClientListener* listen = new ClientListener(
auto* listen = new ClientListener(
address,
new TCPSocketFactory(m_events, getSocketMultiplexer()),
m_events);
@ -642,7 +641,7 @@ ServerApp::openClientListener(const NetworkAddress& address)
Server*
ServerApp::openServer(Config& config, PrimaryClient* primaryClient)
{
Server* server = new Server(config, primaryClient, m_serverScreen, m_events, args());
auto* server = new Server(config, primaryClient, m_serverScreen, m_events, args());
try {
m_events->adoptHandler(
m_events->forServer().disconnected(), server,
@ -661,13 +660,13 @@ ServerApp::openServer(Config& config, PrimaryClient* primaryClient)
}
void
ServerApp::handleNoClients(const Event&, void*)
ServerApp::handleNoClients(const Event& /*unused*/, void* /*unused*/)
{
updateStatus();
}
void
ServerApp::handleScreenSwitched(const Event& e, void*)
ServerApp::handleScreenSwitched(const Event& /*e*/, void* /*unused*/)
{
}
@ -712,7 +711,7 @@ ServerApp::mainLoop()
}
// handle hangup signal by reloading the server's configuration
ARCH->setSignalHandler(Arch::kHANGUP, &reloadSignalHandler, NULL);
ARCH->setSignalHandler(Arch::kHANGUP, &reloadSignalHandler, nullptr);
m_events->adoptHandler(m_events->forServerApp().reloadConfig(),
m_events->getSystemTarget(),
new TMethodEventJob<ServerApp>(this, &ServerApp::reloadConfig));
@ -770,7 +769,7 @@ ServerApp::mainLoop()
return kExitSuccess;
}
void ServerApp::resetServer(const Event&, void*)
void ServerApp::resetServer(const Event& /*unused*/, void* /*unused*/)
{
LOG((CLOG_DEBUG1 "resetting server"));
stopServer();
@ -787,7 +786,7 @@ ServerApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc
args().m_pname = ARCH->getBasename(argv[0]);
// install caller's output filter
if (outputter != NULL) {
if (outputter != nullptr) {
CLOG->insert(outputter);
}
@ -812,9 +811,9 @@ ServerApp::standardStartup(int argc, char** argv)
if (args().m_daemon) {
return ARCH->daemonize(daemonName(), daemonMainLoopStatic);
}
else {
return mainLoop();
}
}
int

View File

@ -18,9 +18,7 @@
#include "core/ServerArgs.h"
ServerArgs::ServerArgs() :
m_configFile(),
m_serial(),
m_config(NULL)
m_config(nullptr)
{
}

View File

@ -17,12 +17,12 @@
*/
#include "core/ServerTaskBarReceiver.h"
#include "server/Server.h"
#include "mt/Lock.h"
#include "base/String.h"
#include "base/IEventQueue.h"
#include "arch/Arch.h"
#include "base/IEventQueue.h"
#include "base/String.h"
#include "common/Version.h"
#include "mt/Lock.h"
#include "server/Server.h"
//
// ServerTaskBarReceiver
@ -46,7 +46,7 @@ ServerTaskBarReceiver::updateStatus(Server* server, const String& errorMsg)
{
// update our status
m_errorMessage = errorMsg;
if (server == NULL) {
if (server == nullptr) {
if (m_errorMessage.empty()) {
m_state = kNotRunning;
}
@ -98,7 +98,7 @@ ServerTaskBarReceiver::quit()
}
void
ServerTaskBarReceiver::onStatusChanged(Server*)
ServerTaskBarReceiver::onStatusChanged(Server* /*unused*/)
{
// do nothing
}

View File

@ -17,19 +17,19 @@
#include "core/StreamChunker.h"
#include "mt/Lock.h"
#include "mt/Mutex.h"
#include "core/FileChunk.h"
#include "core/ClipboardChunk.h"
#include "core/protocol_types.h"
#include "base/EventTypes.h"
#include "base/Event.h"
#include "base/IEventQueue.h"
#include "base/EventTypes.h"
#include "base/EventTypes.h"
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "base/Stopwatch.h"
#include "base/String.h"
#include "common/stdexcept.h"
#include "core/ClipboardChunk.h"
#include "core/FileChunk.h"
#include "core/protocol_types.h"
#include "mt/Lock.h"
#include "mt/Mutex.h"
#include <fstream>
@ -39,7 +39,7 @@ static const size_t g_chunkSize = 32 * 1024; //32kb
bool StreamChunker::s_isChunkingFile = false;
bool StreamChunker::s_interruptFile = false;
Mutex* StreamChunker::s_interruptMutex = NULL;
Mutex* StreamChunker::s_interruptMutex = nullptr;
void
StreamChunker::sendFile(
@ -57,7 +57,7 @@ StreamChunker::sendFile(
// check file size
file.seekg (0, std::ios::end);
size_t size = (size_t)file.tellg();
auto size = (size_t)file.tellg();
// send first message (file size)
String fileSize = synergy::string::sizeTypeToString(size);
@ -84,9 +84,9 @@ StreamChunker::sendFile(
chunkSize = size - sentLength;
}
char* chunkData = new char[chunkSize];
auto* chunkData = new char[chunkSize];
file.read(chunkData, chunkSize);
UInt8* data = reinterpret_cast<UInt8*>(chunkData);
auto* data = reinterpret_cast<UInt8*>(chunkData);
FileChunk* fileChunk = FileChunk::data(data, chunkSize);
delete[] chunkData;

View File

@ -17,10 +17,10 @@
#include "core/ToolApp.h"
#include "core/ArgParser.h"
#include "arch/Arch.h"
#include "base/Log.h"
#include "base/String.h"
#include "core/ArgParser.h"
#include <iostream>
#include <sstream>

View File

@ -23,7 +23,7 @@
//
String
XScreenOpenFailure::getWhat() const throw()
XScreenOpenFailure::getWhat() const noexcept
{
return format("XScreenOpenFailure", "unable to open screen");
}
@ -34,7 +34,7 @@ XScreenOpenFailure::getWhat() const throw()
//
String
XScreenXInputFailure::getWhat() const throw()
XScreenXInputFailure::getWhat() const noexcept
{
return "";
}
@ -50,7 +50,7 @@ XScreenUnavailable::XScreenUnavailable(double timeUntilRetry) :
// do nothing
}
XScreenUnavailable::~XScreenUnavailable() _NOEXCEPT
XScreenUnavailable::~XScreenUnavailable() noexcept
{
// do nothing
}
@ -62,7 +62,7 @@ XScreenUnavailable::getRetryTime() const
}
String
XScreenUnavailable::getWhat() const throw()
XScreenUnavailable::getWhat() const noexcept
{
return format("XScreenUnavailable", "unable to open screen");
}

View File

@ -17,6 +17,8 @@
*/
#include "core/XSynergy.h"
#include <utility>
#include "base/String.h"
//
@ -24,7 +26,7 @@
//
String
XBadClient::getWhat() const throw()
XBadClient::getWhat() const noexcept
{
return "XBadClient";
}
@ -42,19 +44,19 @@ XIncompatibleClient::XIncompatibleClient(int major, int minor) :
}
int
XIncompatibleClient::getMajor() const throw()
XIncompatibleClient::getMajor() const noexcept
{
return m_major;
}
int
XIncompatibleClient::getMinor() const throw()
XIncompatibleClient::getMinor() const noexcept
{
return m_minor;
}
String
XIncompatibleClient::getWhat() const throw()
XIncompatibleClient::getWhat() const noexcept
{
return format("XIncompatibleClient", "incompatible client %{1}.%{2}",
synergy::string::sprintf("%d", m_major).c_str(),
@ -66,20 +68,20 @@ XIncompatibleClient::getWhat() const throw()
// XDuplicateClient
//
XDuplicateClient::XDuplicateClient(const String& name) :
m_name(name)
XDuplicateClient::XDuplicateClient(String name) :
m_name(std::move(name))
{
// do nothing
}
const String&
XDuplicateClient::getName() const throw()
XDuplicateClient::getName() const noexcept
{
return m_name;
}
String
XDuplicateClient::getWhat() const throw()
XDuplicateClient::getWhat() const noexcept
{
return format("XDuplicateClient", "duplicate client %{1}", m_name.c_str());
}
@ -89,20 +91,20 @@ XDuplicateClient::getWhat() const throw()
// XUnknownClient
//
XUnknownClient::XUnknownClient(const String& name) :
m_name(name)
XUnknownClient::XUnknownClient(String name) :
m_name(std::move(name))
{
// do nothing
}
const String&
XUnknownClient::getName() const throw()
XUnknownClient::getName() const noexcept
{
return m_name;
}
String
XUnknownClient::getWhat() const throw()
XUnknownClient::getWhat() const noexcept
{
return format("XUnknownClient", "unknown client %{1}", m_name.c_str());
}
@ -119,13 +121,13 @@ XExitApp::XExitApp(int code) :
}
int
XExitApp::getCode() const throw()
XExitApp::getCode() const noexcept
{
return m_code;
}
String
XExitApp::getWhat() const throw()
XExitApp::getWhat() const noexcept
{
return format(
"XExitApp", "exiting with code %{1}",

View File

@ -68,7 +68,7 @@ a client that is already connected.
*/
class XDuplicateClient : public XSynergy {
public:
XDuplicateClient(const String& name);
XDuplicateClient(String name);
virtual ~XDuplicateClient() _NOEXCEPT { }
//! @name accessors
@ -94,7 +94,7 @@ unknown to the server.
*/
class XUnknownClient : public XSynergy {
public:
XUnknownClient(const String& name);
XUnknownClient(String name);
virtual ~XUnknownClient() _NOEXCEPT { }
//! @name accessors

View File

@ -191,7 +191,7 @@ const KeyNameMapEntry kKeyNameMap[] = {
{ "Bar", 0x007c },
{ "BraceR", 0x007d },
{ "Tilde", 0x007e },
{ NULL, 0 },
{ nullptr, 0 },
};
const KeyModifierNameMapEntry kModifierNameMap[] = {
@ -204,5 +204,5 @@ const KeyModifierNameMapEntry kModifierNameMap[] = {
// { "ScrollLock", KeyModifierScrollLock },
{ "Shift", KeyModifierShift },
{ "Super", KeyModifierSuper },
{ NULL, 0 },
{ nullptr, 0 },
};

View File

@ -19,13 +19,12 @@
#include "core/unix/AppUtilUnix.h"
#include "core/ArgsBase.h"
AppUtilUnix::AppUtilUnix(IEventQueue* events)
AppUtilUnix::AppUtilUnix(IEventQueue* /*events*/)
{
}
AppUtilUnix::~AppUtilUnix()
{
}
= default;
int
standardStartupStatic(int argc, char** argv)
@ -36,7 +35,7 @@ standardStartupStatic(int argc, char** argv)
int
AppUtilUnix::run(int argc, char** argv)
{
return app().runInner(argc, argv, NULL, &standardStartupStatic);
return app().runInner(argc, argv, nullptr, &standardStartupStatic);
}
void

View File

@ -44,15 +44,15 @@ StreamBuffer::peek(UInt32 n)
// if requesting no data then return NULL so we don't try to access
// an empty list.
if (n == 0) {
return NULL;
return nullptr;
}
// reserve space in first chunk
ChunkList::iterator head = m_chunks.begin();
auto head = m_chunks.begin();
head->reserve(n + m_headUsed);
// consolidate chunks into the first chunk until it has n bytes
ChunkList::iterator scan = head;
auto scan = head;
++scan;
while (head->size() - m_headUsed < n && scan != m_chunks.end()) {
head->insert(head->end(), scan->begin(), scan->end());
@ -77,10 +77,10 @@ StreamBuffer::pop(UInt32 n)
m_size -= n;
// discard chunks until more than n bytes would've been discarded
ChunkList::iterator scan = m_chunks.begin();
auto scan = m_chunks.begin();
assert(scan != m_chunks.end());
while (scan->size() - m_headUsed <= n) {
n -= (UInt32)scan->size() - m_headUsed;
n -= static_cast<UInt32>(scan->size()) - m_headUsed;
m_headUsed = 0;
scan = m_chunks.erase(scan);
assert(scan != m_chunks.end());
@ -104,10 +104,10 @@ StreamBuffer::write(const void* vdata, UInt32 n)
m_size += n;
// cast data to bytes
const UInt8* data = static_cast<const UInt8*>(vdata);
const auto* data = static_cast<const UInt8*>(vdata);
// point to last chunk if it has space, otherwise append an empty chunk
ChunkList::iterator scan = m_chunks.end();
auto scan = m_chunks.end();
if (scan != m_chunks.begin()) {
--scan;
if (scan->size() >= kChunkSize) {
@ -122,9 +122,10 @@ StreamBuffer::write(const void* vdata, UInt32 n)
while (n > 0) {
// choose number of bytes for next chunk
assert(scan->size() <= kChunkSize);
UInt32 count = kChunkSize - (UInt32)scan->size();
if (count > n)
UInt32 count = kChunkSize - static_cast<UInt32>(scan->size());
if (count > n) {
count = n;
}
// transfer data
scan->insert(scan->end(), data, data + count);

View File

@ -53,7 +53,7 @@ public:
/*!
Appends \c n bytes from \c data to the buffer.
*/
void write(const void* data, UInt32 n);
void write(const void* vdata, UInt32 n);
//@}
//! @name accessors

View File

@ -112,7 +112,7 @@ StreamFilter::filterEvent(const Event& event)
}
void
StreamFilter::handleUpstreamEvent(const Event& event, void*)
StreamFilter::handleUpstreamEvent(const Event& event, void* /*unused*/)
{
filterEvent(event);
}

View File

@ -23,7 +23,7 @@
//
String
XIOClosed::getWhat() const throw()
XIOClosed::getWhat() const noexcept
{
return format("XIOClosed", "already closed");
}
@ -34,7 +34,7 @@ XIOClosed::getWhat() const throw()
//
String
XIOEndOfStream::getWhat() const throw()
XIOEndOfStream::getWhat() const noexcept
{
return format("XIOEndOfStream", "reached end of stream");
}
@ -45,7 +45,7 @@ XIOEndOfStream::getWhat() const throw()
//
String
XIOWouldBlock::getWhat() const throw()
XIOWouldBlock::getWhat() const noexcept
{
return format("XIOWouldBlock", "stream operation would block");
}

View File

@ -17,10 +17,10 @@
*/
#include "ipc/IpcClient.h"
#include "ipc/Ipc.h"
#include "ipc/IpcServerProxy.h"
#include "ipc/IpcMessage.h"
#include "base/TMethodEventJob.h"
#include "ipc/Ipc.h"
#include "ipc/IpcMessage.h"
#include "ipc/IpcServerProxy.h"
//
// IpcClient
@ -51,8 +51,7 @@ IpcClient::init()
}
IpcClient::~IpcClient()
{
}
= default;
void
IpcClient::connect()
@ -90,7 +89,7 @@ IpcClient::send(const IpcMessage& message)
}
void
IpcClient::handleConnected(const Event&, void*)
IpcClient::handleConnected(const Event& /*unused*/, void* /*unused*/)
{
m_events->addEvent(Event(
m_events->forIpcClient().connected(), this, m_server, Event::kDontFreeData));
@ -100,7 +99,7 @@ IpcClient::handleConnected(const Event&, void*)
}
void
IpcClient::handleMessageReceived(const Event& e, void*)
IpcClient::handleMessageReceived(const Event& e, void* /*unused*/)
{
Event event(m_events->forIpcClient().messageReceived(), this);
event.setDataObject(e.getDataObject());

View File

@ -18,13 +18,13 @@
#include "ipc/IpcClientProxy.h"
#include "ipc/Ipc.h"
#include "ipc/IpcMessage.h"
#include "arch/Arch.h"
#include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "core/ProtocolUtil.h"
#include "io/IStream.h"
#include "arch/Arch.h"
#include "base/TMethodEventJob.h"
#include "base/Log.h"
#include "ipc/Ipc.h"
#include "ipc/IpcMessage.h"
//
// IpcClientProxy
@ -82,21 +82,21 @@ IpcClientProxy::~IpcClientProxy()
}
void
IpcClientProxy::handleDisconnect(const Event&, void*)
IpcClientProxy::handleDisconnect(const Event& /*unused*/, void* /*unused*/)
{
disconnect();
LOG((CLOG_DEBUG "ipc client disconnected"));
}
void
IpcClientProxy::handleWriteError(const Event&, void*)
IpcClientProxy::handleWriteError(const Event& /*unused*/, void* /*unused*/)
{
disconnect();
LOG((CLOG_DEBUG "ipc client write error"));
}
void
IpcClientProxy::handleData(const Event&, void*)
IpcClientProxy::handleData(const Event& /*unused*/, void* /*unused*/)
{
// don't allow the dtor to destroy the stream while we're using it.
ArchMutexLock lock(m_readMutex);
@ -123,7 +123,7 @@ IpcClientProxy::handleData(const Event&, void*)
}
// don't delete with this event; the data is passed to a new event.
Event e(m_events->forIpcClientProxy().messageReceived(), this, NULL, Event::kDontFreeData);
Event e(m_events->forIpcClientProxy().messageReceived(), this, nullptr, Event::kDontFreeData);
e.setDataObject(m);
m_events->addEvent(e);
@ -145,7 +145,7 @@ IpcClientProxy::send(const IpcMessage& message)
switch (message.type()) {
case kIpcLogLine: {
const IpcLogLineMessage& llm = static_cast<const IpcLogLineMessage&>(message);
const auto& llm = dynamic_cast<const IpcLogLineMessage&>(message);
const String logLine = llm.logLine();
ProtocolUtil::writef(&m_stream, kIpcMsgLogLine, &logLine);
break;

View File

@ -18,17 +18,17 @@
#include "ipc/IpcLogOutputter.h"
#include "ipc/IpcServer.h"
#include "ipc/IpcMessage.h"
#include "ipc/Ipc.h"
#include "ipc/IpcClientProxy.h"
#include "mt/Thread.h"
#include "arch/Arch.h"
#include "arch/XArch.h"
#include "base/Event.h"
#include "base/EventQueue.h"
#include "base/TMethodEventJob.h"
#include "base/TMethodJob.h"
#include "ipc/Ipc.h"
#include "ipc/IpcClientProxy.h"
#include "ipc/IpcMessage.h"
#include "ipc/IpcServer.h"
#include "mt/Thread.h"
enum EIpcLogOutputter {
kBufferMaxSize = 1000,
@ -78,7 +78,7 @@ IpcLogOutputter::~IpcLogOutputter()
}
void
IpcLogOutputter::open(const char* title)
IpcLogOutputter::open(const char* /*title*/)
{
}
@ -94,12 +94,12 @@ IpcLogOutputter::close()
}
void
IpcLogOutputter::show(bool showIfEmpty)
IpcLogOutputter::show(bool /*showIfEmpty*/)
{
}
bool
IpcLogOutputter::write(ELevel, const char* text)
IpcLogOutputter::write(ELevel /*level*/, const char* text)
{
// ignore events from the buffer thread (would cause recursion).
if (m_bufferThread != nullptr &&
@ -148,7 +148,7 @@ IpcLogOutputter::isRunning()
}
void
IpcLogOutputter::bufferThread(void*)
IpcLogOutputter::bufferThread(void* /*unused*/)
{
m_bufferThreadId = m_bufferThread->getID();
m_running = true;

View File

@ -47,7 +47,7 @@ public:
virtual void open(const char* title);
virtual void close();
virtual void show(bool showIfEmpty);
virtual bool write(ELevel level, const char* message);
virtual bool write(ELevel level, const char* text);
//! @name manipulators
//@{

View File

@ -17,6 +17,8 @@
*/
#include "ipc/IpcMessage.h"
#include <utility>
#include "ipc/Ipc.h"
IpcMessage::IpcMessage(UInt8 type) :
@ -25,8 +27,7 @@ IpcMessage::IpcMessage(UInt8 type) :
}
IpcMessage::~IpcMessage()
{
}
= default;
IpcHelloMessage::IpcHelloMessage(EIpcClientType clientType) :
IpcMessage(kIpcHello),
@ -35,8 +36,7 @@ IpcHelloMessage::IpcHelloMessage(EIpcClientType clientType) :
}
IpcHelloMessage::~IpcHelloMessage()
{
}
= default;
IpcShutdownMessage::IpcShutdownMessage() :
IpcMessage(kIpcShutdown)
@ -44,26 +44,23 @@ IpcMessage(kIpcShutdown)
}
IpcShutdownMessage::~IpcShutdownMessage()
{
}
= default;
IpcLogLineMessage::IpcLogLineMessage(const String& logLine) :
IpcLogLineMessage::IpcLogLineMessage(String logLine) :
IpcMessage(kIpcLogLine),
m_logLine(logLine)
m_logLine(std::move(logLine))
{
}
IpcLogLineMessage::~IpcLogLineMessage()
{
}
= default;
IpcCommandMessage::IpcCommandMessage(const String& command, bool elevate) :
IpcCommandMessage::IpcCommandMessage(String command, bool elevate) :
IpcMessage(kIpcCommand),
m_command(command),
m_command(std::move(command)),
m_elevate(elevate)
{
}
IpcCommandMessage::~IpcCommandMessage()
{
}
= default;

View File

@ -58,7 +58,7 @@ public:
class IpcLogLineMessage : public IpcMessage {
public:
IpcLogLineMessage(const String& logLine);
IpcLogLineMessage(String logLine);
virtual ~IpcLogLineMessage();
//! Gets the log line.
@ -70,7 +70,7 @@ private:
class IpcCommandMessage : public IpcMessage {
public:
IpcCommandMessage(const String& command, bool elevate);
IpcCommandMessage(String command, bool elevate);
virtual ~IpcCommandMessage();
//! Gets the command.

View File

@ -18,15 +18,15 @@
#include "ipc/IpcServer.h"
#include "base/Event.h"
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "io/IStream.h"
#include "ipc/Ipc.h"
#include "ipc/IpcClientProxy.h"
#include "ipc/IpcMessage.h"
#include "net/IDataSocket.h"
#include "io/IStream.h"
#include "base/IEventQueue.h"
#include "base/TMethodEventJob.h"
#include "base/Event.h"
#include "base/Log.h"
//
// IpcServer
@ -71,9 +71,9 @@ IpcServer::~IpcServer()
return;
}
if (m_socket != nullptr) {
delete m_socket;
}
ARCH->lockMutex(m_clientsMutex);
ClientList::iterator it;
@ -94,17 +94,17 @@ IpcServer::listen()
}
void
IpcServer::handleClientConnecting(const Event&, void*)
IpcServer::handleClientConnecting(const Event& /*unused*/, void* /*unused*/)
{
synergy::IStream* stream = m_socket->accept();
if (stream == NULL) {
if (stream == nullptr) {
return;
}
LOG((CLOG_DEBUG "accepted ipc client connection"));
ARCH->lockMutex(m_clientsMutex);
IpcClientProxy* proxy = new IpcClientProxy(*stream, m_events);
auto* proxy = new IpcClientProxy(*stream, m_events);
m_clients.push_back(proxy);
ARCH->unlockMutex(m_clientsMutex);
@ -123,9 +123,9 @@ IpcServer::handleClientConnecting(const Event&, void*)
}
void
IpcServer::handleClientDisconnected(const Event& e, void*)
IpcServer::handleClientDisconnected(const Event& e, void* /*unused*/)
{
IpcClientProxy* proxy = static_cast<IpcClientProxy*>(e.getTarget());
auto* proxy = static_cast<IpcClientProxy*>(e.getTarget());
ArchMutexLock lock(m_clientsMutex);
m_clients.remove(proxy);
@ -135,7 +135,7 @@ IpcServer::handleClientDisconnected(const Event& e, void*)
}
void
IpcServer::handleMessageReceived(const Event& e, void*)
IpcServer::handleMessageReceived(const Event& e, void* /*unused*/)
{
Event event(m_events->forIpcServer().messageReceived(), this);
event.setDataObject(e.getDataObject());

View File

@ -76,10 +76,10 @@ private:
bool m_mock;
IEventQueue* m_events;
SocketMultiplexer* m_socketMultiplexer;
TCPListenSocket* m_socket;
TCPListenSocket* m_socket{};
NetworkAddress m_address;
ClientList m_clients;
ArchMutex m_clientsMutex;
ArchMutex m_clientsMutex{};
#ifdef TEST_ENV
public:

View File

@ -18,12 +18,12 @@
#include "ipc/IpcServerProxy.h"
#include "ipc/IpcMessage.h"
#include "ipc/Ipc.h"
#include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "core/ProtocolUtil.h"
#include "io/IStream.h"
#include "base/TMethodEventJob.h"
#include "base/Log.h"
#include "ipc/Ipc.h"
#include "ipc/IpcMessage.h"
//
// IpcServerProxy
@ -46,7 +46,7 @@ IpcServerProxy::~IpcServerProxy()
}
void
IpcServerProxy::handleData(const Event&, void*)
IpcServerProxy::handleData(const Event& /*unused*/, void* /*unused*/)
{
LOG((CLOG_DEBUG "start ipc handle data"));
@ -70,7 +70,7 @@ IpcServerProxy::handleData(const Event&, void*)
}
// don't delete with this event; the data is passed to a new event.
Event e(m_events->forIpcServerProxy().messageReceived(), this, NULL, Event::kDontFreeData);
Event e(m_events->forIpcServerProxy().messageReceived(), this, nullptr, Event::kDontFreeData);
e.setDataObject(m);
m_events->addEvent(e);
@ -87,13 +87,13 @@ IpcServerProxy::send(const IpcMessage& message)
switch (message.type()) {
case kIpcHello: {
const IpcHelloMessage& hm = static_cast<const IpcHelloMessage&>(message);
const auto& hm = dynamic_cast<const IpcHelloMessage&>(message);
ProtocolUtil::writef(&m_stream, kIpcMsgHello, hm.clientType());
break;
}
case kIpcCommand: {
const IpcCommandMessage& cm = static_cast<const IpcCommandMessage&>(message);
const auto& cm = dynamic_cast<const IpcCommandMessage&>(message);
const String command = cm.command();
ProtocolUtil::writef(&m_stream, kIpcMsgCommand, &command);
break;

View File

@ -70,9 +70,11 @@ CondVarBase::wait(Stopwatch& timer, double timeout) const
// Always call wait at least once, even if remain is 0, to give
// other thread a chance to grab the mutex to avoid deadlocks on
// busy waiting.
if (remain<0.0) remain=0.0;
if (wait(remain))
if (remain<0.0) { remain=0.0;
}
if (wait(remain)) {
return true;
}
remain = timeout - timer.getTime();
} while (remain >= 0.0);
return false;

View File

@ -29,7 +29,7 @@ Mutex::Mutex()
m_mutex = ARCH->newMutex();
}
Mutex::Mutex(const Mutex&)
Mutex::Mutex(const Mutex& /*unused*/)
{
m_mutex = ARCH->newMutex();
}
@ -40,7 +40,7 @@ Mutex::~Mutex()
}
Mutex&
Mutex::operator=(const Mutex&)
Mutex::operator=(const Mutex& /*unused*/)
{
return *this;
}

View File

@ -18,11 +18,11 @@
#include "mt/Thread.h"
#include "arch/Arch.h"
#include "base/IJob.h"
#include "base/Log.h"
#include "mt/XMT.h"
#include "mt/XThread.h"
#include "arch/Arch.h"
#include "base/Log.h"
#include "base/IJob.h"
//
// Thread
@ -31,7 +31,7 @@
Thread::Thread(IJob* job)
{
m_thread = ARCH->newThread(&Thread::threadFunc, job);
if (m_thread == NULL) {
if (m_thread == nullptr) {
// couldn't create thread
delete job;
throw XMTThreadUnavailable();
@ -111,10 +111,11 @@ Thread::wait(double timeout) const
void*
Thread::getResult() const
{
if (wait())
if (wait()) {
return ARCH->getResultOfThread(m_thread);
else
return NULL;
} else {
return nullptr;
}
}
IArchMultithread::ThreadID
@ -147,10 +148,10 @@ Thread::threadFunc(void* vjob)
}
// get job
IJob* job = static_cast<IJob*>(vjob);
auto* job = static_cast<IJob*>(vjob);
// run job
void* result = NULL;
void* result = nullptr;
try {
// go
LOG((CLOG_DEBUG1 "thread 0x%08x entry", id));

View File

@ -47,7 +47,7 @@ public:
Create and start a new thread executing the \c adoptedJob. The
new thread takes ownership of \c adoptedJob and will delete it.
*/
Thread(IJob* adoptedJob);
Thread(IJob* job);
//! Duplicate a thread handle
/*!

View File

@ -23,7 +23,7 @@
//
String
XMTThreadUnavailable::getWhat() const throw()
XMTThreadUnavailable::getWhat() const noexcept
{
return format("XMTThreadUnavailable", "cannot create thread");
}

Some files were not shown because too many files have changed in this diff Show More