Added switch delay and double-tap options to win32 and added a

tray icon to the client and server that gives status feedback to
the user and allows the user to kill the app.
This commit is contained in:
crs
2003-03-12 22:34:07 +00:00
parent f411df65fb
commit 1d17f865ea
82 changed files with 4420 additions and 396 deletions

113
lib/base/CJobList.cpp Normal file
View File

@@ -0,0 +1,113 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "CJobList.h"
#include "IJob.h"
#include "CArch.h"
//
// CJobList
//
CJobList::CJobList()
{
m_mutex = ARCH->newMutex();
}
CJobList::~CJobList()
{
ARCH->closeMutex(m_mutex);
}
void
CJobList::addJob(IJob* job)
{
// ignore bogus job
if (job == NULL) {
return;
}
// make a temporary list with the job. later we'll splice this
// list into our jobs list. since splice() never throws we
// don't have to try/catch to unlock the mutex.
CJobs tmpList;
tmpList.push_front(job);
// add job to list
ARCH->lockMutex(m_mutex);
m_jobs.splice(m_jobs.begin(), tmpList);
ARCH->unlockMutex(m_mutex);
}
void
CJobList::removeJob(IJob* job)
{
if (job != NULL) {
ARCH->lockMutex(m_mutex);
m_jobs.remove(job);
ARCH->unlockMutex(m_mutex);
}
}
void
CJobList::runJobs() const
{
// this is a little tricky. to allow any number of threads to
// traverse the list while jobs are added and removed while
// not holding the mutex when running a job (so other threads
// or the running job can add and remove jobs), we insert a
// new element into the list. this element has a NULL job and
// is a "safe place" while we traverse the list. the safe place
// is inserted at the start of the list (with the mutex locked)
// then, for each job, we lock the mutex and move the safe place
// past the next job, unlock the mutex, run the job and repeat
// until there are no more jobs. the safe place will not be
// removed by any other thread and is after every job that has
// been run and before every job that still needs to run. when
// all the jobs have been run we remove the safe place.
// add the safe place
CJobs tmpList;
tmpList.push_front(NULL);
ARCH->lockMutex(m_mutex);
m_jobs.splice(m_jobs.begin(), tmpList);
CJobs::iterator safePlace = m_jobs.begin();
// find the next non-NULL job (NULL jobs are safe places)
CJobs::iterator next = safePlace;
while (next != m_jobs.end() && *next == NULL)
++next;
while (next != m_jobs.end()) {
// found a job. run it without holding a lock. note the
// race condition here: we release the lock, allowing
// removeJob() to remove this job before we run the job.
// therefore the caller cannot safely destroy the job
// until all runJobs() complete.
IJob* job = *next;
++next;
m_jobs.splice(next, m_jobs, safePlace);
ARCH->unlockMutex(m_mutex);
job->run();
// next real job
ARCH->lockMutex(m_mutex);
next = safePlace;
while (next != m_jobs.end() && *next == NULL)
++next;
}
// remove the safe place
m_jobs.erase(safePlace);
ARCH->unlockMutex(m_mutex);
}

72
lib/base/CJobList.h Normal file
View File

@@ -0,0 +1,72 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef CJOBLIST_H
#define CJOBLIST_H
#include "IArchMultithread.h"
#include "stdlist.h"
class IJob;
class CJobList {
public:
CJobList();
~CJobList();
//! @name manipulators
//@{
//! Add a job
/*!
Add a job to the list. The client keeps ownership of the job.
Jobs can be safely added while \c runJobs() is executing.
*/
void addJob(IJob*);
//! Remove a job
/*!
Remove a job from the list. The client keeps ownership of the job.
Jobs can be safely removed while \c runJobs() is executing.
*/
void removeJob(IJob*);
//@}
//! @name accessors
//@{
//! Run all jobs
/*!
Run all jobs in the list. Any number of threads can call
\c runJobs() at once. Jobs can be added and removed while
\c runJobs() is executing in the same or another thread.
Any job added after \c runJobs() starts will not be run
by that call to runJobs(). Destroying a removed job
while \c runJobs() is executing is not safe unless the
removed completed before \c runJobs() started.
*/
void runJobs() const;
//@}
private:
typedef std::list<IJob*> CJobs;
typedef CJobs::iterator iterator;
CArchMutex m_mutex;
mutable CJobs m_jobs;
};
#endif

View File

@@ -156,3 +156,26 @@ CSystemLogOutputter::getNewline() const
{
return "";
}
//
// CSystemLogger
//
CSystemLogger::CSystemLogger(const char* title)
{
// redirect log messages
m_syslog = new CSystemLogOutputter;
m_stop = new CStopLogOutputter;
m_syslog->open(title);
CLOG->insert(m_stop);
CLOG->insert(m_syslog);
}
CSystemLogger::~CSystemLogger()
{
CLOG->remove(m_syslog);
CLOG->remove(m_stop);
delete m_stop;
delete m_syslog;
}

View File

@@ -68,4 +68,22 @@ public:
virtual const char* getNewline() const;
};
//! Write log to system log only
/*!
Creating an object of this type inserts a CStopLogOutputter followed
by a CSystemLogOutputter into CLog. The destructor removes those
outputters. Add one of these to any scope that needs to write to
the system log (only) and restore the old outputters when exiting
the scope.
*/
class CSystemLogger {
public:
CSystemLogger(const char* title);
~CSystemLogger();
private:
ILogOutputter* m_syslog;
ILogOutputter* m_stop;
};
#endif

View File

@@ -26,6 +26,7 @@ MAINTAINERCLEANFILES = \
noinst_LIBRARIES = libbase.a
libbase_a_SOURCES = \
CFunctionJob.cpp \
CJobList.cpp \
CLog.cpp \
CStopwatch.cpp \
CStringUtil.cpp \
@@ -33,6 +34,7 @@ libbase_a_SOURCES = \
LogOutputters.cpp \
XBase.cpp \
CFunctionJob.h \
CJobList.h \
CLog.h \
CStopwatch.h \
CString.h \

View File

@@ -91,6 +91,10 @@ SOURCE=.\CFunctionJob.cpp
# End Source File
# Begin Source File
SOURCE=.\CJobList.cpp
# End Source File
# Begin Source File
SOURCE=.\CLog.cpp
# End Source File
# Begin Source File
@@ -123,6 +127,10 @@ SOURCE=.\CFunctionJob.h
# End Source File
# Begin Source File
SOURCE=.\CJobList.h
# End Source File
# Begin Source File
SOURCE=.\CLog.h
# End Source File
# Begin Source File