indentation and other formatting changes. also cleaned up
#includes.
This commit is contained in:
parent
68940e58f3
commit
62519b19fe
|
@ -58,7 +58,6 @@ typedef unsigned char UInt8;
|
||||||
typedef unsigned short UInt16;
|
typedef unsigned short UInt16;
|
||||||
typedef unsigned int UInt32;
|
typedef unsigned int UInt32;
|
||||||
typedef unsigned long long UInt64;
|
typedef unsigned long long UInt64;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // CONFIG_PLATFORM_WIN32
|
#endif // CONFIG_PLATFORM_WIN32
|
||||||
|
|
|
@ -5,13 +5,14 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
CFunctionJob::CFunctionJob(void (*func)(void*), void* arg) :
|
CFunctionJob::CFunctionJob(void (*func)(void*), void* arg) :
|
||||||
m_func(func),
|
m_func(func),
|
||||||
m_arg(arg)
|
m_arg(arg)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFunctionJob::run()
|
void
|
||||||
|
CFunctionJob::run()
|
||||||
{
|
{
|
||||||
if (m_func != NULL) {
|
if (m_func != NULL) {
|
||||||
m_func(m_arg);
|
m_func(m_arg);
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
#include "CLog.h"
|
#include "CLog.h"
|
||||||
#include <stdio.h>
|
#include <cstdio>
|
||||||
#include <stdlib.h>
|
#include <cstdlib>
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#if defined(CONFIG_PLATFORM_WIN32)
|
#if defined(CONFIG_PLATFORM_WIN32)
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define CLOG_H
|
#define CLOG_H
|
||||||
|
|
||||||
#include "BasicTypes.h"
|
#include "BasicTypes.h"
|
||||||
#include <stdarg.h>
|
#include <cstdarg>
|
||||||
|
|
||||||
class CLog {
|
class CLog {
|
||||||
public:
|
public:
|
||||||
|
@ -24,7 +24,7 @@ public:
|
||||||
// type of lock/unlock function
|
// type of lock/unlock function
|
||||||
typedef void (*Lock)(bool lock);
|
typedef void (*Lock)(bool lock);
|
||||||
|
|
||||||
//
|
// print a log message
|
||||||
static void print(const char*, ...);
|
static void print(const char*, ...);
|
||||||
static void printt(const char* file, int line, const char*, ...);
|
static void printt(const char* file, int line, const char*, ...);
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,33 @@
|
||||||
#include "CString.h"
|
#include "CString.h"
|
||||||
#include <ctype.h>
|
#include <cctype>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
//
|
//
|
||||||
// CStringUtil::CaselessCmp
|
// CStringUtil::CaselessCmp
|
||||||
//
|
//
|
||||||
|
|
||||||
bool CStringUtil::CaselessCmp::cmpEqual(
|
bool
|
||||||
const CString::value_type& a,
|
CStringUtil::CaselessCmp::cmpEqual(
|
||||||
const CString::value_type& b)
|
const CString::value_type& a,
|
||||||
|
const CString::value_type& b)
|
||||||
{
|
{
|
||||||
// FIXME -- use std::tolower
|
// FIXME -- use std::tolower but not in all versions of libstdc++
|
||||||
return tolower(a) == tolower(b);
|
return tolower(a) == tolower(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CStringUtil::CaselessCmp::cmpLess(
|
bool
|
||||||
const CString::value_type& a,
|
CStringUtil::CaselessCmp::cmpLess(
|
||||||
const CString::value_type& b)
|
const CString::value_type& a,
|
||||||
|
const CString::value_type& b)
|
||||||
{
|
{
|
||||||
// FIXME -- use std::tolower
|
// FIXME -- use std::tolower but not in all versions of libstdc++
|
||||||
return tolower(a) < tolower(b);
|
return tolower(a) < tolower(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CStringUtil::CaselessCmp::less(
|
bool
|
||||||
const CString& a,
|
CStringUtil::CaselessCmp::less(
|
||||||
const CString& b)
|
const CString& a,
|
||||||
|
const CString& b)
|
||||||
{
|
{
|
||||||
return std::lexicographical_compare(
|
return std::lexicographical_compare(
|
||||||
a.begin(), a.end(),
|
a.begin(), a.end(),
|
||||||
|
@ -32,16 +35,18 @@ bool CStringUtil::CaselessCmp::less(
|
||||||
&CStringUtil::CaselessCmp::cmpLess);
|
&CStringUtil::CaselessCmp::cmpLess);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CStringUtil::CaselessCmp::equal(
|
bool
|
||||||
const CString& a,
|
CStringUtil::CaselessCmp::equal(
|
||||||
const CString& b)
|
const CString& a,
|
||||||
|
const CString& b)
|
||||||
{
|
{
|
||||||
return !(less(a, b) || less(b, a));
|
return !(less(a, b) || less(b, a));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CStringUtil::CaselessCmp::operator()(
|
bool
|
||||||
const CString& a,
|
CStringUtil::CaselessCmp::operator()(
|
||||||
const CString& b) const
|
const CString& a,
|
||||||
|
const CString& b) const
|
||||||
{
|
{
|
||||||
return less(a, b);
|
return less(a, b);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,48 +1,15 @@
|
||||||
#ifndef CSTRING_H
|
#ifndef CSTRING_H
|
||||||
#define CSTRING_H
|
#define CSTRING_H
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "stdpre.h"
|
#include "stdpre.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "stdpost.h"
|
#include "stdpost.h"
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
#pragma warning(push, 4)
|
|
||||||
#pragma warning(disable: 4097) // typedef-name used as synonym
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CSTRING_DEF_CTOR
|
|
||||||
#define CSTRING_ALLOC1
|
|
||||||
#define CSTRING_ALLOC2
|
|
||||||
#define CSTRING_DEF_CTOR CString() : _Myt() { }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// use to get appropriate type for string constants. it depends on
|
// use to get appropriate type for string constants. it depends on
|
||||||
// the internal representation type of CString.
|
// the internal representation type of CString.
|
||||||
#define _CS(_x) _x
|
#define _CS(_x) _x
|
||||||
|
|
||||||
class CString : public std::string {
|
typedef std::string CString;
|
||||||
public:
|
|
||||||
typedef char _e;
|
|
||||||
typedef _e CharT;
|
|
||||||
typedef std::allocator<_e> _a;
|
|
||||||
typedef std::string _Myt;
|
|
||||||
typedef const_iterator _It;
|
|
||||||
|
|
||||||
// same constructors as base class
|
|
||||||
CSTRING_DEF_CTOR
|
|
||||||
CString(const _Myt& _x) : _Myt(_x) { }
|
|
||||||
CString(const _Myt& _x, size_type _p, size_type _m CSTRING_ALLOC1) :
|
|
||||||
_Myt(_x, _p, _m CSTRING_ALLOC2) { }
|
|
||||||
CString(const _e *_s, size_type _n CSTRING_ALLOC1) :
|
|
||||||
_Myt(_s, _n CSTRING_ALLOC2) { }
|
|
||||||
CString(const _e *_s CSTRING_ALLOC1) :
|
|
||||||
_Myt(_s CSTRING_ALLOC2) { }
|
|
||||||
CString(size_type _n, _e _c CSTRING_ALLOC1) :
|
|
||||||
_Myt(_n, _c CSTRING_ALLOC2) { }
|
|
||||||
CString(_It _f, _It _l CSTRING_ALLOC1) :
|
|
||||||
_Myt(_f, _l CSTRING_ALLOC2) { }
|
|
||||||
};
|
|
||||||
|
|
||||||
class CStringUtil {
|
class CStringUtil {
|
||||||
public:
|
public:
|
||||||
|
@ -52,15 +19,11 @@ public:
|
||||||
static bool less(const CString&, const CString&);
|
static bool less(const CString&, const CString&);
|
||||||
static bool equal(const CString&, const CString&);
|
static bool equal(const CString&, const CString&);
|
||||||
static bool cmpLess(const CString::value_type&,
|
static bool cmpLess(const CString::value_type&,
|
||||||
const CString::value_type&);
|
const CString::value_type&);
|
||||||
static bool cmpEqual(const CString::value_type&,
|
static bool cmpEqual(const CString::value_type&,
|
||||||
const CString::value_type&);
|
const CString::value_type&);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
#pragma warning(pop)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -20,16 +20,17 @@ private:
|
||||||
template <class T>
|
template <class T>
|
||||||
inline
|
inline
|
||||||
TMethodJob<T>::TMethodJob(T* object, void (T::*method)(void*), void* arg) :
|
TMethodJob<T>::TMethodJob(T* object, void (T::*method)(void*), void* arg) :
|
||||||
m_object(object),
|
m_object(object),
|
||||||
m_method(method),
|
m_method(method),
|
||||||
m_arg(arg)
|
m_arg(arg)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline
|
inline
|
||||||
void TMethodJob<T>::run()
|
void
|
||||||
|
TMethodJob<T>::run()
|
||||||
{
|
{
|
||||||
if (m_object != NULL) {
|
if (m_object != NULL) {
|
||||||
(m_object->*m_method)(m_arg);
|
(m_object->*m_method)(m_arg);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "XBase.h"
|
#include "XBase.h"
|
||||||
#include <errno.h>
|
#include <cerrno>
|
||||||
|
|
||||||
// win32 wants a const char* argument to std::exception c'tor
|
// win32 wants a const char* argument to std::exception c'tor
|
||||||
#if defined(CONFIG_PLATFORM_WIN32)
|
#if defined(CONFIG_PLATFORM_WIN32)
|
||||||
|
@ -15,12 +15,16 @@
|
||||||
// XBase
|
// XBase
|
||||||
//
|
//
|
||||||
|
|
||||||
XBase::XBase() : exception(STDEXCEPTARG), m_what()
|
XBase::XBase() :
|
||||||
|
exception(STDEXCEPTARG),
|
||||||
|
m_what()
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
XBase::XBase(const CString& msg) : exception(STDEXCEPTARG), m_what(msg)
|
XBase::XBase(const CString& msg) :
|
||||||
|
exception(STDEXCEPTARG),
|
||||||
|
m_what(msg)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -30,7 +34,8 @@ XBase::~XBase()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* XBase::what() const
|
const char*
|
||||||
|
XBase::what() const
|
||||||
{
|
{
|
||||||
if (m_what.empty()) {
|
if (m_what.empty()) {
|
||||||
m_what = getWhat();
|
m_what = getWhat();
|
||||||
|
@ -38,8 +43,10 @@ const char* XBase::what() const
|
||||||
return m_what.c_str();
|
return m_what.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
CString XBase::format(const char* /*id*/,
|
CString
|
||||||
const char* fmt, ...) const throw()
|
XBase::format(
|
||||||
|
const char* /*id*/,
|
||||||
|
const char* fmt, ...) const throw()
|
||||||
{
|
{
|
||||||
// FIXME -- use id to lookup formating string
|
// FIXME -- use id to lookup formating string
|
||||||
// FIXME -- format string with arguments
|
// FIXME -- format string with arguments
|
||||||
|
@ -51,22 +58,26 @@ CString XBase::format(const char* /*id*/,
|
||||||
// MXErrno
|
// MXErrno
|
||||||
//
|
//
|
||||||
|
|
||||||
MXErrno::MXErrno() : m_errno(errno)
|
MXErrno::MXErrno() :
|
||||||
|
m_errno(errno)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
MXErrno::MXErrno(int err) : m_errno(err)
|
MXErrno::MXErrno(int err) :
|
||||||
|
m_errno(err)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
int MXErrno::getErrno() const
|
int
|
||||||
|
MXErrno::getErrno() const
|
||||||
{
|
{
|
||||||
return m_errno;
|
return m_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* MXErrno::getErrstr() const
|
const char*
|
||||||
|
MXErrno::getErrstr() const
|
||||||
{
|
{
|
||||||
return strerror(m_errno);
|
return strerror(m_errno);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ protected:
|
||||||
|
|
||||||
// look up a message and format it
|
// look up a message and format it
|
||||||
virtual CString format(const char* id,
|
virtual CString format(const char* id,
|
||||||
const char* defaultFormat, ...) const throw();
|
const char* defaultFormat, ...) const throw();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable CString m_what;
|
mutable CString m_what;
|
||||||
|
|
|
@ -42,4 +42,6 @@
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,11 +2,14 @@
|
||||||
#if !defined(CONFIG_PLATFORM_LINUX)
|
#if !defined(CONFIG_PLATFORM_LINUX)
|
||||||
#include <istream>
|
#include <istream>
|
||||||
#else
|
#else
|
||||||
|
// some versions of libstdc++ don't have <istream>
|
||||||
|
// FIXME -- only include iostream for versions that don't have istream
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#endif
|
#endif
|
||||||
#include "stdpost.h"
|
#include "stdpost.h"
|
||||||
|
|
||||||
#if defined(CONFIG_PLATFORM_WIN32) && defined(_MSC_VER)
|
#if defined(CONFIG_PLATFORM_WIN32) && defined(_MSC_VER)
|
||||||
|
// istream has no overloads for __int* types
|
||||||
inline
|
inline
|
||||||
std::istream& operator>>(std::istream& s, SInt8& i)
|
std::istream& operator>>(std::istream& s, SInt8& i)
|
||||||
{ return s >> (signed char&)i; }
|
{ return s >> (signed char&)i; }
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#if !defined(CONFIG_PLATFORM_LINUX)
|
#if !defined(CONFIG_PLATFORM_LINUX)
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#else
|
#else
|
||||||
|
// some versions of libstdc++ don't have <ostream>
|
||||||
|
// FIXME -- only include iostream for versions that don't have ostream
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#endif
|
#endif
|
||||||
#include "stdpost.h"
|
#include "stdpost.h"
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
#include "CClient.h"
|
#include "CClient.h"
|
||||||
|
#include "CClipboard.h"
|
||||||
#include "CInputPacketStream.h"
|
#include "CInputPacketStream.h"
|
||||||
#include "COutputPacketStream.h"
|
#include "COutputPacketStream.h"
|
||||||
#include "CProtocolUtil.h"
|
#include "CProtocolUtil.h"
|
||||||
#include "CClipboard.h"
|
|
||||||
#include "ISecondaryScreen.h"
|
#include "ISecondaryScreen.h"
|
||||||
#include "ProtocolTypes.h"
|
#include "ProtocolTypes.h"
|
||||||
#include "CLock.h"
|
|
||||||
#include "CLog.h"
|
|
||||||
#include "CThread.h"
|
|
||||||
#include "CTimerThread.h"
|
|
||||||
#include "TMethodJob.h"
|
|
||||||
#include "XScreen.h"
|
#include "XScreen.h"
|
||||||
#include "XSynergy.h"
|
#include "XSynergy.h"
|
||||||
|
#include "XSocket.h"
|
||||||
|
#include "CLock.h"
|
||||||
|
#include "CThread.h"
|
||||||
|
#include "CTimerThread.h"
|
||||||
#include "XThread.h"
|
#include "XThread.h"
|
||||||
#include <assert.h>
|
#include "CLog.h"
|
||||||
|
#include "TMethodJob.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
// hack to work around operator=() bug in STL in g++ prior to v3
|
// hack to work around operator=() bug in STL in g++ prior to v3
|
||||||
|
@ -28,15 +28,16 @@
|
||||||
// CClient
|
// CClient
|
||||||
//
|
//
|
||||||
|
|
||||||
CClient::CClient(const CString& clientName) :
|
CClient::CClient(
|
||||||
m_name(clientName),
|
const CString& clientName) :
|
||||||
m_input(NULL),
|
m_name(clientName),
|
||||||
m_output(NULL),
|
m_input(NULL),
|
||||||
m_screen(NULL),
|
m_output(NULL),
|
||||||
m_camp(false),
|
m_screen(NULL),
|
||||||
m_active(false),
|
m_camp(false),
|
||||||
m_seqNum(0),
|
m_active(false),
|
||||||
m_ignoreMove(false)
|
m_seqNum(0),
|
||||||
|
m_ignoreMove(false)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -46,12 +47,16 @@ CClient::~CClient()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::camp(bool on)
|
void
|
||||||
|
CClient::camp(
|
||||||
|
bool on)
|
||||||
{
|
{
|
||||||
m_camp = on;
|
m_camp = on;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClient::run(const CNetworkAddress& serverAddress)
|
bool
|
||||||
|
CClient::run(
|
||||||
|
const CNetworkAddress& serverAddress)
|
||||||
{
|
{
|
||||||
CThread* thread = NULL;
|
CThread* thread = NULL;
|
||||||
try {
|
try {
|
||||||
|
@ -128,12 +133,15 @@ bool CClient::run(const CNetworkAddress& serverAddress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::quit()
|
void
|
||||||
|
CClient::quit()
|
||||||
{
|
{
|
||||||
m_screen->stop();
|
m_screen->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onClipboardChanged(ClipboardID id)
|
void
|
||||||
|
CClient::onClipboardChanged(
|
||||||
|
ClipboardID id)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG "sending clipboard %d changed", id));
|
log((CLOG_DEBUG "sending clipboard %d changed", id));
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
@ -169,7 +177,8 @@ void CClient::onClipboardChanged(ClipboardID id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onResolutionChanged()
|
void
|
||||||
|
CClient::onResolutionChanged()
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG "resolution changed"));
|
log((CLOG_DEBUG "resolution changed"));
|
||||||
|
|
||||||
|
@ -183,7 +192,8 @@ void CClient::onResolutionChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "CTCPSocket.h" // FIXME
|
#include "CTCPSocket.h" // FIXME
|
||||||
void CClient::runSession(void*)
|
void
|
||||||
|
CClient::runSession(void*)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG "starting client \"%s\"", m_name.c_str()));
|
log((CLOG_DEBUG "starting client \"%s\"", m_name.c_str()));
|
||||||
|
|
||||||
|
@ -401,7 +411,8 @@ void CClient::runSession(void*)
|
||||||
#elif defined(CONFIG_PLATFORM_UNIX)
|
#elif defined(CONFIG_PLATFORM_UNIX)
|
||||||
#include "CXWindowsSecondaryScreen.h"
|
#include "CXWindowsSecondaryScreen.h"
|
||||||
#endif
|
#endif
|
||||||
void CClient::openSecondaryScreen()
|
void
|
||||||
|
CClient::openSecondaryScreen()
|
||||||
{
|
{
|
||||||
assert(m_screen == NULL);
|
assert(m_screen == NULL);
|
||||||
|
|
||||||
|
@ -428,7 +439,8 @@ void CClient::openSecondaryScreen()
|
||||||
m_screen->open(this);
|
m_screen->open(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::closeSecondaryScreen()
|
void
|
||||||
|
CClient::closeSecondaryScreen()
|
||||||
{
|
{
|
||||||
assert(m_screen != NULL);
|
assert(m_screen != NULL);
|
||||||
|
|
||||||
|
@ -447,7 +459,8 @@ void CClient::closeSecondaryScreen()
|
||||||
m_screen = NULL;
|
m_screen = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onEnter()
|
void
|
||||||
|
CClient::onEnter()
|
||||||
{
|
{
|
||||||
SInt16 x, y;
|
SInt16 x, y;
|
||||||
UInt16 mask;
|
UInt16 mask;
|
||||||
|
@ -460,7 +473,8 @@ void CClient::onEnter()
|
||||||
m_screen->enter(x, y, static_cast<KeyModifierMask>(mask));
|
m_screen->enter(x, y, static_cast<KeyModifierMask>(mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onLeave()
|
void
|
||||||
|
CClient::onLeave()
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "recv leave"));
|
log((CLOG_DEBUG1 "recv leave"));
|
||||||
|
|
||||||
|
@ -504,7 +518,8 @@ void CClient::onLeave()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onGrabClipboard()
|
void
|
||||||
|
CClient::onGrabClipboard()
|
||||||
{
|
{
|
||||||
ClipboardID id;
|
ClipboardID id;
|
||||||
UInt32 seqNum;
|
UInt32 seqNum;
|
||||||
|
@ -524,7 +539,8 @@ void CClient::onGrabClipboard()
|
||||||
m_screen->grabClipboard(id);
|
m_screen->grabClipboard(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onScreenSaver()
|
void
|
||||||
|
CClient::onScreenSaver()
|
||||||
{
|
{
|
||||||
SInt8 on;
|
SInt8 on;
|
||||||
{
|
{
|
||||||
|
@ -535,13 +551,15 @@ void CClient::onScreenSaver()
|
||||||
// FIXME
|
// FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onQueryInfo()
|
void
|
||||||
|
CClient::onQueryInfo()
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
onQueryInfoNoLock();
|
onQueryInfoNoLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onQueryInfoNoLock()
|
void
|
||||||
|
CClient::onQueryInfoNoLock()
|
||||||
{
|
{
|
||||||
SInt32 x, y, w, h;
|
SInt32 x, y, w, h;
|
||||||
m_screen->getMousePos(&x, &y);
|
m_screen->getMousePos(&x, &y);
|
||||||
|
@ -552,14 +570,16 @@ void CClient::onQueryInfoNoLock()
|
||||||
CProtocolUtil::writef(m_output, kMsgDInfo, w, h, zoneSize, x, y);
|
CProtocolUtil::writef(m_output, kMsgDInfo, w, h, zoneSize, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onInfoAcknowledgment()
|
void
|
||||||
|
CClient::onInfoAcknowledgment()
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "recv info acknowledgment"));
|
log((CLOG_DEBUG1 "recv info acknowledgment"));
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
m_ignoreMove = false;
|
m_ignoreMove = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onSetClipboard()
|
void
|
||||||
|
CClient::onSetClipboard()
|
||||||
{
|
{
|
||||||
ClipboardID id;
|
ClipboardID id;
|
||||||
CString data;
|
CString data;
|
||||||
|
@ -584,7 +604,8 @@ void CClient::onSetClipboard()
|
||||||
m_screen->setClipboard(id, &clipboard);
|
m_screen->setClipboard(id, &clipboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onKeyDown()
|
void
|
||||||
|
CClient::onKeyDown()
|
||||||
{
|
{
|
||||||
UInt16 id, mask;
|
UInt16 id, mask;
|
||||||
{
|
{
|
||||||
|
@ -596,7 +617,8 @@ void CClient::onKeyDown()
|
||||||
static_cast<KeyModifierMask>(mask));
|
static_cast<KeyModifierMask>(mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onKeyRepeat()
|
void
|
||||||
|
CClient::onKeyRepeat()
|
||||||
{
|
{
|
||||||
UInt16 id, mask, count;
|
UInt16 id, mask, count;
|
||||||
{
|
{
|
||||||
|
@ -609,7 +631,8 @@ void CClient::onKeyRepeat()
|
||||||
count);
|
count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onKeyUp()
|
void
|
||||||
|
CClient::onKeyUp()
|
||||||
{
|
{
|
||||||
UInt16 id, mask;
|
UInt16 id, mask;
|
||||||
{
|
{
|
||||||
|
@ -621,7 +644,8 @@ void CClient::onKeyUp()
|
||||||
static_cast<KeyModifierMask>(mask));
|
static_cast<KeyModifierMask>(mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onMouseDown()
|
void
|
||||||
|
CClient::onMouseDown()
|
||||||
{
|
{
|
||||||
SInt8 id;
|
SInt8 id;
|
||||||
{
|
{
|
||||||
|
@ -632,7 +656,8 @@ void CClient::onMouseDown()
|
||||||
m_screen->mouseDown(static_cast<ButtonID>(id));
|
m_screen->mouseDown(static_cast<ButtonID>(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onMouseUp()
|
void
|
||||||
|
CClient::onMouseUp()
|
||||||
{
|
{
|
||||||
SInt8 id;
|
SInt8 id;
|
||||||
{
|
{
|
||||||
|
@ -643,7 +668,8 @@ void CClient::onMouseUp()
|
||||||
m_screen->mouseUp(static_cast<ButtonID>(id));
|
m_screen->mouseUp(static_cast<ButtonID>(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onMouseMove()
|
void
|
||||||
|
CClient::onMouseMove()
|
||||||
{
|
{
|
||||||
bool ignore;
|
bool ignore;
|
||||||
SInt16 x, y;
|
SInt16 x, y;
|
||||||
|
@ -658,7 +684,8 @@ void CClient::onMouseMove()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onMouseWheel()
|
void
|
||||||
|
CClient::onMouseWheel()
|
||||||
{
|
{
|
||||||
SInt16 delta;
|
SInt16 delta;
|
||||||
{
|
{
|
||||||
|
@ -669,7 +696,8 @@ void CClient::onMouseWheel()
|
||||||
m_screen->mouseWheel(delta);
|
m_screen->mouseWheel(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onErrorIncompatible()
|
void
|
||||||
|
CClient::onErrorIncompatible()
|
||||||
{
|
{
|
||||||
SInt32 major, minor;
|
SInt32 major, minor;
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
@ -677,17 +705,20 @@ void CClient::onErrorIncompatible()
|
||||||
log((CLOG_ERR "server has incompatible version %d.%d", major, minor));
|
log((CLOG_ERR "server has incompatible version %d.%d", major, minor));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onErrorBusy()
|
void
|
||||||
|
CClient::onErrorBusy()
|
||||||
{
|
{
|
||||||
log((CLOG_ERR "server already has a connected client with name \"%s\"", m_name.c_str()));
|
log((CLOG_ERR "server already has a connected client with name \"%s\"", m_name.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onErrorUnknown()
|
void
|
||||||
|
CClient::onErrorUnknown()
|
||||||
{
|
{
|
||||||
log((CLOG_ERR "server refused client with name \"%s\"", m_name.c_str()));
|
log((CLOG_ERR "server refused client with name \"%s\"", m_name.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::onErrorBad()
|
void
|
||||||
|
CClient::onErrorBad()
|
||||||
{
|
{
|
||||||
log((CLOG_ERR "server disconnected due to a protocol error"));
|
log((CLOG_ERR "server disconnected due to a protocol error"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
#ifndef CCLIENT_H
|
#ifndef CCLIENT_H
|
||||||
#define CCLIENT_H
|
#define CCLIENT_H
|
||||||
|
|
||||||
#include "CMutex.h"
|
|
||||||
#include "CString.h"
|
|
||||||
#include "BasicTypes.h"
|
|
||||||
#include "ClipboardTypes.h"
|
#include "ClipboardTypes.h"
|
||||||
#include "IClipboard.h"
|
#include "IClipboard.h"
|
||||||
|
#include "CMutex.h"
|
||||||
|
#include "CString.h"
|
||||||
|
|
||||||
class CNetworkAddress;
|
class CNetworkAddress;
|
||||||
class IInputStream;
|
class IInputStream;
|
||||||
|
|
|
@ -1,27 +1,26 @@
|
||||||
#include "CMSWindowsSecondaryScreen.h"
|
#include "CMSWindowsSecondaryScreen.h"
|
||||||
#include "CMSWindowsClipboard.h"
|
|
||||||
#include "CClient.h"
|
#include "CClient.h"
|
||||||
#include "CPlatform.h"
|
|
||||||
#include "CClipboard.h"
|
#include "CClipboard.h"
|
||||||
#include "CLock.h"
|
#include "CMSWindowsClipboard.h"
|
||||||
#include "CLog.h"
|
#include "CPlatform.h"
|
||||||
#include "CThread.h"
|
|
||||||
#include "XScreen.h"
|
#include "XScreen.h"
|
||||||
#include <assert.h>
|
#include "CLock.h"
|
||||||
#include <ctype.h>
|
#include "CThread.h"
|
||||||
|
#include "CLog.h"
|
||||||
|
#include <cctype>
|
||||||
|
|
||||||
//
|
//
|
||||||
// CMSWindowsSecondaryScreen
|
// CMSWindowsSecondaryScreen
|
||||||
//
|
//
|
||||||
|
|
||||||
CMSWindowsSecondaryScreen::CMSWindowsSecondaryScreen() :
|
CMSWindowsSecondaryScreen::CMSWindowsSecondaryScreen() :
|
||||||
m_client(NULL),
|
m_client(NULL),
|
||||||
m_threadID(0),
|
m_threadID(0),
|
||||||
m_desk(NULL),
|
m_desk(NULL),
|
||||||
m_deskName(),
|
m_deskName(),
|
||||||
m_window(NULL),
|
m_window(NULL),
|
||||||
m_active(false),
|
m_active(false),
|
||||||
m_nextClipboardWindow(NULL)
|
m_nextClipboardWindow(NULL)
|
||||||
{
|
{
|
||||||
m_is95Family = CPlatform::isWindows95Family();
|
m_is95Family = CPlatform::isWindows95Family();
|
||||||
|
|
||||||
|
@ -35,7 +34,8 @@ CMSWindowsSecondaryScreen::~CMSWindowsSecondaryScreen()
|
||||||
assert(m_window == NULL);
|
assert(m_window == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::run()
|
void
|
||||||
|
CMSWindowsSecondaryScreen::run()
|
||||||
{
|
{
|
||||||
// must call run() from same thread as open()
|
// must call run() from same thread as open()
|
||||||
assert(m_threadID == GetCurrentThreadId());
|
assert(m_threadID == GetCurrentThreadId());
|
||||||
|
@ -61,12 +61,15 @@ void CMSWindowsSecondaryScreen::run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::stop()
|
void
|
||||||
|
CMSWindowsSecondaryScreen::stop()
|
||||||
{
|
{
|
||||||
doStop();
|
doStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::open(CClient* client)
|
void
|
||||||
|
CMSWindowsSecondaryScreen::open(
|
||||||
|
CClient* client)
|
||||||
{
|
{
|
||||||
assert(m_client == NULL);
|
assert(m_client == NULL);
|
||||||
assert(client != NULL);
|
assert(client != NULL);
|
||||||
|
@ -82,15 +85,17 @@ void CMSWindowsSecondaryScreen::open(CClient* client)
|
||||||
updateModifiers();
|
updateModifiers();
|
||||||
|
|
||||||
// assume primary has all clipboards
|
// assume primary has all clipboards
|
||||||
for (ClipboardID id = 0; id < kClipboardEnd; ++id)
|
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
||||||
grabClipboard(id);
|
grabClipboard(id);
|
||||||
|
}
|
||||||
|
|
||||||
// hide the cursor
|
// hide the cursor
|
||||||
m_active = true;
|
m_active = true;
|
||||||
leave();
|
leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::close()
|
void
|
||||||
|
CMSWindowsSecondaryScreen::close()
|
||||||
{
|
{
|
||||||
assert(m_client != NULL);
|
assert(m_client != NULL);
|
||||||
|
|
||||||
|
@ -101,8 +106,11 @@ void CMSWindowsSecondaryScreen::close()
|
||||||
m_client = NULL;
|
m_client = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::enter(
|
void
|
||||||
SInt32 x, SInt32 y, KeyModifierMask mask)
|
CMSWindowsSecondaryScreen::enter(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y,
|
||||||
|
KeyModifierMask mask)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
assert(m_window != NULL);
|
assert(m_window != NULL);
|
||||||
|
@ -134,7 +142,8 @@ void CMSWindowsSecondaryScreen::enter(
|
||||||
onEnter(x, y);
|
onEnter(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::leave()
|
void
|
||||||
|
CMSWindowsSecondaryScreen::leave()
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
assert(m_window != NULL);
|
assert(m_window != NULL);
|
||||||
|
@ -171,8 +180,10 @@ void CMSWindowsSecondaryScreen::leave()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::keyDown(
|
void
|
||||||
KeyID key, KeyModifierMask mask)
|
CMSWindowsSecondaryScreen::keyDown(
|
||||||
|
KeyID key,
|
||||||
|
KeyModifierMask mask)
|
||||||
{
|
{
|
||||||
Keystrokes keys;
|
Keystrokes keys;
|
||||||
UINT virtualKey;
|
UINT virtualKey;
|
||||||
|
@ -184,8 +195,9 @@ void CMSWindowsSecondaryScreen::keyDown(
|
||||||
// get the sequence of keys to simulate key press and the final
|
// get the sequence of keys to simulate key press and the final
|
||||||
// modifier state.
|
// modifier state.
|
||||||
m_mask = mapKey(keys, virtualKey, key, mask, kPress);
|
m_mask = mapKey(keys, virtualKey, key, mask, kPress);
|
||||||
if (keys.empty())
|
if (keys.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// generate key events
|
// generate key events
|
||||||
doKeystrokes(keys, 1);
|
doKeystrokes(keys, 1);
|
||||||
|
@ -210,8 +222,11 @@ void CMSWindowsSecondaryScreen::keyDown(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::keyRepeat(
|
void
|
||||||
KeyID key, KeyModifierMask mask, SInt32 count)
|
CMSWindowsSecondaryScreen::keyRepeat(
|
||||||
|
KeyID key,
|
||||||
|
KeyModifierMask mask,
|
||||||
|
SInt32 count)
|
||||||
{
|
{
|
||||||
Keystrokes keys;
|
Keystrokes keys;
|
||||||
UINT virtualKey;
|
UINT virtualKey;
|
||||||
|
@ -223,15 +238,18 @@ void CMSWindowsSecondaryScreen::keyRepeat(
|
||||||
// get the sequence of keys to simulate key repeat and the final
|
// get the sequence of keys to simulate key repeat and the final
|
||||||
// modifier state.
|
// modifier state.
|
||||||
m_mask = mapKey(keys, virtualKey, key, mask, kRepeat);
|
m_mask = mapKey(keys, virtualKey, key, mask, kRepeat);
|
||||||
if (keys.empty())
|
if (keys.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// generate key events
|
// generate key events
|
||||||
doKeystrokes(keys, count);
|
doKeystrokes(keys, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::keyUp(
|
void
|
||||||
KeyID key, KeyModifierMask mask)
|
CMSWindowsSecondaryScreen::keyUp(
|
||||||
|
KeyID key,
|
||||||
|
KeyModifierMask mask)
|
||||||
{
|
{
|
||||||
Keystrokes keys;
|
Keystrokes keys;
|
||||||
UINT virtualKey;
|
UINT virtualKey;
|
||||||
|
@ -243,8 +261,9 @@ void CMSWindowsSecondaryScreen::keyUp(
|
||||||
// get the sequence of keys to simulate key release and the final
|
// get the sequence of keys to simulate key release and the final
|
||||||
// modifier state.
|
// modifier state.
|
||||||
m_mask = mapKey(keys, virtualKey, key, mask, kRelease);
|
m_mask = mapKey(keys, virtualKey, key, mask, kRelease);
|
||||||
if (keys.empty())
|
if (keys.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// generate key events
|
// generate key events
|
||||||
doKeystrokes(keys, 1);
|
doKeystrokes(keys, 1);
|
||||||
|
@ -290,7 +309,9 @@ void CMSWindowsSecondaryScreen::keyUp(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::mouseDown(ButtonID button)
|
void
|
||||||
|
CMSWindowsSecondaryScreen::mouseDown(
|
||||||
|
ButtonID button)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
assert(m_window != NULL);
|
assert(m_window != NULL);
|
||||||
|
@ -300,11 +321,14 @@ void CMSWindowsSecondaryScreen::mouseDown(ButtonID button)
|
||||||
DWORD flags = mapButton(button, true);
|
DWORD flags = mapButton(button, true);
|
||||||
|
|
||||||
// send event
|
// send event
|
||||||
if (flags != 0)
|
if (flags != 0) {
|
||||||
mouse_event(flags, 0, 0, 0, 0);
|
mouse_event(flags, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::mouseUp(ButtonID button)
|
void
|
||||||
|
CMSWindowsSecondaryScreen::mouseUp(
|
||||||
|
ButtonID button)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
assert(m_window != NULL);
|
assert(m_window != NULL);
|
||||||
|
@ -314,12 +338,15 @@ void CMSWindowsSecondaryScreen::mouseUp(ButtonID button)
|
||||||
DWORD flags = mapButton(button, false);
|
DWORD flags = mapButton(button, false);
|
||||||
|
|
||||||
// send event
|
// send event
|
||||||
if (flags != 0)
|
if (flags != 0) {
|
||||||
mouse_event(flags, 0, 0, 0, 0);
|
mouse_event(flags, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::mouseMove(
|
void
|
||||||
SInt32 x, SInt32 y)
|
CMSWindowsSecondaryScreen::mouseMove(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
assert(m_window != NULL);
|
assert(m_window != NULL);
|
||||||
|
@ -333,7 +360,9 @@ void CMSWindowsSecondaryScreen::mouseMove(
|
||||||
0, 0);
|
0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::mouseWheel(SInt32 delta)
|
void
|
||||||
|
CMSWindowsSecondaryScreen::mouseWheel(
|
||||||
|
SInt32 delta)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
assert(m_window != NULL);
|
assert(m_window != NULL);
|
||||||
|
@ -342,8 +371,10 @@ void CMSWindowsSecondaryScreen::mouseWheel(SInt32 delta)
|
||||||
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, delta, 0);
|
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, delta, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::setClipboard(
|
void
|
||||||
ClipboardID /*id*/, const IClipboard* src)
|
CMSWindowsSecondaryScreen::setClipboard(
|
||||||
|
ClipboardID /*id*/,
|
||||||
|
const IClipboard* src)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
assert(m_window != NULL);
|
assert(m_window != NULL);
|
||||||
|
@ -352,8 +383,9 @@ void CMSWindowsSecondaryScreen::setClipboard(
|
||||||
CClipboard::copy(&dst, src);
|
CClipboard::copy(&dst, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::grabClipboard(
|
void
|
||||||
ClipboardID /*id*/)
|
CMSWindowsSecondaryScreen::grabClipboard(
|
||||||
|
ClipboardID /*id*/)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
assert(m_window != NULL);
|
assert(m_window != NULL);
|
||||||
|
@ -364,8 +396,10 @@ void CMSWindowsSecondaryScreen::grabClipboard(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::getMousePos(
|
void
|
||||||
SInt32* x, SInt32* y) const
|
CMSWindowsSecondaryScreen::getMousePos(
|
||||||
|
SInt32* x,
|
||||||
|
SInt32* y) const
|
||||||
{
|
{
|
||||||
assert(x != NULL);
|
assert(x != NULL);
|
||||||
assert(y != NULL);
|
assert(y != NULL);
|
||||||
|
@ -385,19 +419,24 @@ void CMSWindowsSecondaryScreen::getMousePos(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::getSize(
|
void
|
||||||
SInt32* width, SInt32* height) const
|
CMSWindowsSecondaryScreen::getSize(
|
||||||
|
SInt32* width,
|
||||||
|
SInt32* height) const
|
||||||
{
|
{
|
||||||
getScreenSize(width, height);
|
getScreenSize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
SInt32 CMSWindowsSecondaryScreen::getJumpZoneSize() const
|
SInt32
|
||||||
|
CMSWindowsSecondaryScreen::getJumpZoneSize() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::getClipboard(
|
void
|
||||||
ClipboardID /*id*/, IClipboard* dst) const
|
CMSWindowsSecondaryScreen::getClipboard(
|
||||||
|
ClipboardID /*id*/,
|
||||||
|
IClipboard* dst) const
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
assert(m_window != NULL);
|
assert(m_window != NULL);
|
||||||
|
@ -406,7 +445,8 @@ void CMSWindowsSecondaryScreen::getClipboard(
|
||||||
CClipboard::copy(dst, &src);
|
CClipboard::copy(dst, &src);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::onOpenDisplay()
|
void
|
||||||
|
CMSWindowsSecondaryScreen::onOpenDisplay()
|
||||||
{
|
{
|
||||||
assert(m_window == NULL);
|
assert(m_window == NULL);
|
||||||
|
|
||||||
|
@ -426,7 +466,8 @@ void CMSWindowsSecondaryScreen::onOpenDisplay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::onCloseDisplay()
|
void
|
||||||
|
CMSWindowsSecondaryScreen::onCloseDisplay()
|
||||||
{
|
{
|
||||||
// disconnect from desktop
|
// disconnect from desktop
|
||||||
if (m_is95Family) {
|
if (m_is95Family) {
|
||||||
|
@ -443,7 +484,9 @@ void CMSWindowsSecondaryScreen::onCloseDisplay()
|
||||||
assert(m_desk == NULL);
|
assert(m_desk == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMSWindowsSecondaryScreen::onPreTranslate(MSG* msg)
|
bool
|
||||||
|
CMSWindowsSecondaryScreen::onPreTranslate(
|
||||||
|
MSG* msg)
|
||||||
{
|
{
|
||||||
// handle event
|
// handle event
|
||||||
switch (msg->message) {
|
switch (msg->message) {
|
||||||
|
@ -466,9 +509,12 @@ bool CMSWindowsSecondaryScreen::onPreTranslate(MSG* msg)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT CMSWindowsSecondaryScreen::onEvent(
|
LRESULT
|
||||||
HWND hwnd, UINT msg,
|
CMSWindowsSecondaryScreen::onEvent(
|
||||||
WPARAM wParam, LPARAM lParam)
|
HWND hwnd,
|
||||||
|
UINT msg,
|
||||||
|
WPARAM wParam,
|
||||||
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case WM_QUERYENDSESSION:
|
case WM_QUERYENDSESSION:
|
||||||
|
@ -516,10 +562,12 @@ LRESULT CMSWindowsSecondaryScreen::onEvent(
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case WM_CHANGECBCHAIN:
|
case WM_CHANGECBCHAIN:
|
||||||
if (m_nextClipboardWindow == (HWND)wParam)
|
if (m_nextClipboardWindow == (HWND)wParam) {
|
||||||
m_nextClipboardWindow = (HWND)lParam;
|
m_nextClipboardWindow = (HWND)lParam;
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
SendMessage(m_nextClipboardWindow, msg, wParam, lParam);
|
SendMessage(m_nextClipboardWindow, msg, wParam, lParam);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case WM_DISPLAYCHANGE:
|
case WM_DISPLAYCHANGE:
|
||||||
|
@ -532,7 +580,10 @@ LRESULT CMSWindowsSecondaryScreen::onEvent(
|
||||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::onEnter(SInt32 x, SInt32 y)
|
void
|
||||||
|
CMSWindowsSecondaryScreen::onEnter(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
// warp to requested location
|
// warp to requested location
|
||||||
SInt32 w, h;
|
SInt32 w, h;
|
||||||
|
@ -546,7 +597,8 @@ void CMSWindowsSecondaryScreen::onEnter(SInt32 x, SInt32 y)
|
||||||
ShowWindow(m_window, SW_HIDE);
|
ShowWindow(m_window, SW_HIDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::onLeave()
|
void
|
||||||
|
CMSWindowsSecondaryScreen::onLeave()
|
||||||
{
|
{
|
||||||
// move hider window under the mouse (rather than moving the mouse
|
// move hider window under the mouse (rather than moving the mouse
|
||||||
// somewhere else on the screen)
|
// somewhere else on the screen)
|
||||||
|
@ -558,7 +610,8 @@ void CMSWindowsSecondaryScreen::onLeave()
|
||||||
ShowWindow(m_window, SW_SHOWNORMAL);
|
ShowWindow(m_window, SW_SHOWNORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMSWindowsSecondaryScreen::openDesktop()
|
bool
|
||||||
|
CMSWindowsSecondaryScreen::openDesktop()
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
|
||||||
|
@ -584,7 +637,8 @@ bool CMSWindowsSecondaryScreen::openDesktop()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::closeDesktop()
|
void
|
||||||
|
CMSWindowsSecondaryScreen::closeDesktop()
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
|
||||||
|
@ -599,7 +653,9 @@ void CMSWindowsSecondaryScreen::closeDesktop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMSWindowsSecondaryScreen::switchDesktop(HDESK desk)
|
bool
|
||||||
|
CMSWindowsSecondaryScreen::switchDesktop(
|
||||||
|
HDESK desk)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
|
||||||
|
@ -680,7 +736,8 @@ bool CMSWindowsSecondaryScreen::switchDesktop(HDESK desk)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::syncDesktop() const
|
void
|
||||||
|
CMSWindowsSecondaryScreen::syncDesktop() const
|
||||||
{
|
{
|
||||||
// note -- mutex must be locked on entry
|
// note -- mutex must be locked on entry
|
||||||
|
|
||||||
|
@ -697,7 +754,8 @@ void CMSWindowsSecondaryScreen::syncDesktop() const
|
||||||
AttachThreadInput(threadID, m_threadID, TRUE);
|
AttachThreadInput(threadID, m_threadID, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CMSWindowsSecondaryScreen::getCurrentDesktopName() const
|
CString
|
||||||
|
CMSWindowsSecondaryScreen::getCurrentDesktopName() const
|
||||||
{
|
{
|
||||||
return m_deskName;
|
return m_deskName;
|
||||||
}
|
}
|
||||||
|
@ -1189,8 +1247,10 @@ static const UINT* g_mapTable[] =
|
||||||
/* 0xfc */ NULL, g_terminal, g_function, g_miscellany
|
/* 0xfc */ NULL, g_terminal, g_function, g_miscellany
|
||||||
};
|
};
|
||||||
|
|
||||||
DWORD CMSWindowsSecondaryScreen::mapButton(
|
DWORD
|
||||||
ButtonID button, bool press) const
|
CMSWindowsSecondaryScreen::mapButton(
|
||||||
|
ButtonID button,
|
||||||
|
bool press) const
|
||||||
{
|
{
|
||||||
// map button id to button flag
|
// map button id to button flag
|
||||||
switch (button) {
|
switch (button) {
|
||||||
|
@ -1208,11 +1268,13 @@ DWORD CMSWindowsSecondaryScreen::mapButton(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyModifierMask CMSWindowsSecondaryScreen::mapKey(
|
KeyModifierMask
|
||||||
Keystrokes& keys,
|
CMSWindowsSecondaryScreen::mapKey(
|
||||||
UINT& virtualKey,
|
Keystrokes& keys,
|
||||||
KeyID id, KeyModifierMask mask,
|
UINT& virtualKey,
|
||||||
EKeyAction action) const
|
KeyID id,
|
||||||
|
KeyModifierMask mask,
|
||||||
|
EKeyAction action) const
|
||||||
{
|
{
|
||||||
// lookup the key table
|
// lookup the key table
|
||||||
const UInt32 mapID = ((id >> 8) & 0xff);
|
const UInt32 mapID = ((id >> 8) & 0xff);
|
||||||
|
@ -1264,12 +1326,15 @@ KeyModifierMask CMSWindowsSecondaryScreen::mapKey(
|
||||||
outMask &= ~KeyModifierShift;
|
outMask &= ~KeyModifierShift;
|
||||||
|
|
||||||
// convert system modifier mask to our mask
|
// convert system modifier mask to our mask
|
||||||
if (HIBYTE(vk) & 1)
|
if (HIBYTE(vk) & 1) {
|
||||||
outMask |= KeyModifierShift;
|
outMask |= KeyModifierShift;
|
||||||
if (HIBYTE(vk) & 2)
|
}
|
||||||
|
if (HIBYTE(vk) & 2) {
|
||||||
outMask |= KeyModifierControl;
|
outMask |= KeyModifierControl;
|
||||||
if (HIBYTE(vk) & 4)
|
}
|
||||||
|
if (HIBYTE(vk) & 4) {
|
||||||
outMask |= KeyModifierAlt;
|
outMask |= KeyModifierAlt;
|
||||||
|
}
|
||||||
log((CLOG_DEBUG2 "character %d to virtual key %d mask 0x%04x", code, LOBYTE(vk), outMask));
|
log((CLOG_DEBUG2 "character %d to virtual key %d mask 0x%04x", code, LOBYTE(vk), outMask));
|
||||||
|
|
||||||
// handle combination of caps-lock and shift. if caps-lock is
|
// handle combination of caps-lock and shift. if caps-lock is
|
||||||
|
@ -1457,8 +1522,9 @@ KeyModifierMask CMSWindowsSecondaryScreen::mapKey(
|
||||||
|
|
||||||
// add the key event
|
// add the key event
|
||||||
keystroke.m_virtualKey = virtualKey;
|
keystroke.m_virtualKey = virtualKey;
|
||||||
if (isExtended)
|
if (isExtended) {
|
||||||
keystroke.m_virtualKey |= 0x100;
|
keystroke.m_virtualKey |= 0x100;
|
||||||
|
}
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case kPress:
|
case kPress:
|
||||||
keystroke.m_press = true;
|
keystroke.m_press = true;
|
||||||
|
@ -1523,12 +1589,15 @@ KeyModifierMask CMSWindowsSecondaryScreen::mapKey(
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::doKeystrokes(
|
void
|
||||||
const Keystrokes& keys, SInt32 count)
|
CMSWindowsSecondaryScreen::doKeystrokes(
|
||||||
|
const Keystrokes& keys,
|
||||||
|
SInt32 count)
|
||||||
{
|
{
|
||||||
// do nothing if no keys or no repeats
|
// do nothing if no keys or no repeats
|
||||||
if (count < 1 || keys.empty())
|
if (count < 1 || keys.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// generate key events
|
// generate key events
|
||||||
for (Keystrokes::const_iterator k = keys.begin(); k != keys.end(); ) {
|
for (Keystrokes::const_iterator k = keys.begin(); k != keys.end(); ) {
|
||||||
|
@ -1556,7 +1625,8 @@ void CMSWindowsSecondaryScreen::doKeystrokes(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::updateKeys()
|
void
|
||||||
|
CMSWindowsSecondaryScreen::updateKeys()
|
||||||
{
|
{
|
||||||
// clear key state
|
// clear key state
|
||||||
memset(m_keys, 0, sizeof(m_keys));
|
memset(m_keys, 0, sizeof(m_keys));
|
||||||
|
@ -1579,29 +1649,40 @@ void CMSWindowsSecondaryScreen::updateKeys()
|
||||||
m_keys[VK_SCROLL] = static_cast<BYTE>(GetKeyState(VK_SCROLL));
|
m_keys[VK_SCROLL] = static_cast<BYTE>(GetKeyState(VK_SCROLL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::updateModifiers()
|
void
|
||||||
|
CMSWindowsSecondaryScreen::updateModifiers()
|
||||||
{
|
{
|
||||||
// update active modifier mask
|
// update active modifier mask
|
||||||
m_mask = 0;
|
m_mask = 0;
|
||||||
if ((m_keys[VK_LSHIFT] & 0x80) != 0 || (m_keys[VK_RSHIFT] & 0x80) != 0)
|
if ((m_keys[VK_LSHIFT] & 0x80) != 0 || (m_keys[VK_RSHIFT] & 0x80) != 0) {
|
||||||
m_mask |= KeyModifierShift;
|
m_mask |= KeyModifierShift;
|
||||||
if ((m_keys[VK_LCONTROL] & 0x80) != 0 || (m_keys[VK_RCONTROL] & 0x80) != 0)
|
}
|
||||||
|
if ((m_keys[VK_LCONTROL] & 0x80) != 0 ||
|
||||||
|
(m_keys[VK_RCONTROL] & 0x80) != 0) {
|
||||||
m_mask |= KeyModifierControl;
|
m_mask |= KeyModifierControl;
|
||||||
if ((m_keys[VK_LMENU] & 0x80) != 0 || (m_keys[VK_RMENU] & 0x80) != 0)
|
}
|
||||||
|
if ((m_keys[VK_LMENU] & 0x80) != 0 || (m_keys[VK_RMENU] & 0x80) != 0) {
|
||||||
m_mask |= KeyModifierAlt;
|
m_mask |= KeyModifierAlt;
|
||||||
if ((m_keys[VK_LWIN] & 0x80) != 0 || (m_keys[VK_RWIN] & 0x80) != 0)
|
}
|
||||||
|
if ((m_keys[VK_LWIN] & 0x80) != 0 || (m_keys[VK_RWIN] & 0x80) != 0) {
|
||||||
m_mask |= KeyModifierMeta;
|
m_mask |= KeyModifierMeta;
|
||||||
if ((m_keys[VK_CAPITAL] & 0x01) != 0)
|
}
|
||||||
|
if ((m_keys[VK_CAPITAL] & 0x01) != 0) {
|
||||||
m_mask |= KeyModifierCapsLock;
|
m_mask |= KeyModifierCapsLock;
|
||||||
if ((m_keys[VK_NUMLOCK] & 0x01) != 0)
|
}
|
||||||
|
if ((m_keys[VK_NUMLOCK] & 0x01) != 0) {
|
||||||
m_mask |= KeyModifierNumLock;
|
m_mask |= KeyModifierNumLock;
|
||||||
if ((m_keys[VK_SCROLL] & 0x01) != 0)
|
}
|
||||||
|
if ((m_keys[VK_SCROLL] & 0x01) != 0) {
|
||||||
m_mask |= KeyModifierScrollLock;
|
m_mask |= KeyModifierScrollLock;
|
||||||
|
}
|
||||||
log((CLOG_DEBUG2 "modifiers on update: 0x%04x", m_mask));
|
log((CLOG_DEBUG2 "modifiers on update: 0x%04x", m_mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::toggleKey(
|
void
|
||||||
UINT virtualKey, KeyModifierMask mask)
|
CMSWindowsSecondaryScreen::toggleKey(
|
||||||
|
UINT virtualKey,
|
||||||
|
KeyModifierMask mask)
|
||||||
{
|
{
|
||||||
// send key events to simulate a press and release
|
// send key events to simulate a press and release
|
||||||
sendKeyEvent(virtualKey, true);
|
sendKeyEvent(virtualKey, true);
|
||||||
|
@ -1612,13 +1693,15 @@ void CMSWindowsSecondaryScreen::toggleKey(
|
||||||
m_keys[virtualKey & 0xff] ^= 0x01;
|
m_keys[virtualKey & 0xff] ^= 0x01;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT CMSWindowsSecondaryScreen::virtualKeyToScanCode(
|
UINT
|
||||||
UINT& virtualKey)
|
CMSWindowsSecondaryScreen::virtualKeyToScanCode(
|
||||||
|
UINT& virtualKey)
|
||||||
{
|
{
|
||||||
// try mapping given virtual key
|
// try mapping given virtual key
|
||||||
UINT code = MapVirtualKey(virtualKey & 0xff, 0);
|
UINT code = MapVirtualKey(virtualKey & 0xff, 0);
|
||||||
if (code != 0)
|
if (code != 0) {
|
||||||
return code;
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
// no dice. if the virtual key distinguishes between left/right
|
// no dice. if the virtual key distinguishes between left/right
|
||||||
// then try the one that doesn't distinguish sides. windows (or
|
// then try the one that doesn't distinguish sides. windows (or
|
||||||
|
@ -1663,12 +1746,14 @@ UINT CMSWindowsSecondaryScreen::virtualKeyToScanCode(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMSWindowsSecondaryScreen::isExtendedKey(
|
bool
|
||||||
UINT virtualKey)
|
CMSWindowsSecondaryScreen::isExtendedKey(
|
||||||
|
UINT virtualKey)
|
||||||
{
|
{
|
||||||
// see if we've already encoded the extended flag
|
// see if we've already encoded the extended flag
|
||||||
if ((virtualKey & 0x100) != 0)
|
if ((virtualKey & 0x100) != 0) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// check known virtual keys
|
// check known virtual keys
|
||||||
switch (virtualKey & 0xff) {
|
switch (virtualKey & 0xff) {
|
||||||
|
@ -1685,14 +1770,18 @@ bool CMSWindowsSecondaryScreen::isExtendedKey(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsSecondaryScreen::sendKeyEvent(
|
void
|
||||||
UINT virtualKey, bool press)
|
CMSWindowsSecondaryScreen::sendKeyEvent(
|
||||||
|
UINT virtualKey,
|
||||||
|
bool press)
|
||||||
{
|
{
|
||||||
DWORD flags = 0;
|
DWORD flags = 0;
|
||||||
if (isExtendedKey(virtualKey))
|
if (isExtendedKey(virtualKey)) {
|
||||||
flags |= KEYEVENTF_EXTENDEDKEY;
|
flags |= KEYEVENTF_EXTENDEDKEY;
|
||||||
if (!press)
|
}
|
||||||
|
if (!press) {
|
||||||
flags |= KEYEVENTF_KEYUP;
|
flags |= KEYEVENTF_KEYUP;
|
||||||
|
}
|
||||||
const UINT code = virtualKeyToScanCode(virtualKey);
|
const UINT code = virtualKeyToScanCode(virtualKey);
|
||||||
keybd_event(static_cast<BYTE>(virtualKey & 0xff),
|
keybd_event(static_cast<BYTE>(virtualKey & 0xff),
|
||||||
static_cast<BYTE>(code), flags, 0);
|
static_cast<BYTE>(code), flags, 0);
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
#include "CString.h"
|
#include "CString.h"
|
||||||
#include "stdvector.h"
|
#include "stdvector.h"
|
||||||
|
|
||||||
class CMSWindowsSecondaryScreen : public CMSWindowsScreen, public ISecondaryScreen {
|
class CMSWindowsSecondaryScreen : public CMSWindowsScreen,
|
||||||
|
public ISecondaryScreen {
|
||||||
public:
|
public:
|
||||||
CMSWindowsSecondaryScreen();
|
CMSWindowsSecondaryScreen();
|
||||||
virtual ~CMSWindowsSecondaryScreen();
|
virtual ~CMSWindowsSecondaryScreen();
|
||||||
|
@ -18,7 +19,7 @@ public:
|
||||||
virtual void open(CClient*);
|
virtual void open(CClient*);
|
||||||
virtual void close();
|
virtual void close();
|
||||||
virtual void enter(SInt32 xAbsolute, SInt32 yAbsolute,
|
virtual void enter(SInt32 xAbsolute, SInt32 yAbsolute,
|
||||||
KeyModifierMask mask);
|
KeyModifierMask mask);
|
||||||
virtual void leave();
|
virtual void leave();
|
||||||
virtual void keyDown(KeyID, KeyModifierMask);
|
virtual void keyDown(KeyID, KeyModifierMask);
|
||||||
virtual void keyRepeat(KeyID, KeyModifierMask, SInt32 count);
|
virtual void keyRepeat(KeyID, KeyModifierMask, SInt32 count);
|
||||||
|
@ -68,7 +69,7 @@ private:
|
||||||
// key and button queries and operations
|
// key and button queries and operations
|
||||||
DWORD mapButton(ButtonID button, bool press) const;
|
DWORD mapButton(ButtonID button, bool press) const;
|
||||||
KeyModifierMask mapKey(Keystrokes&, UINT& virtualKey, KeyID,
|
KeyModifierMask mapKey(Keystrokes&, UINT& virtualKey, KeyID,
|
||||||
KeyModifierMask, EKeyAction) const;
|
KeyModifierMask, EKeyAction) const;
|
||||||
void doKeystrokes(const Keystrokes&, SInt32 count);
|
void doKeystrokes(const Keystrokes&, SInt32 count);
|
||||||
|
|
||||||
void updateKeys();
|
void updateKeys();
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
#include "CXWindowsSecondaryScreen.h"
|
#include "CXWindowsSecondaryScreen.h"
|
||||||
|
#include "CClient.h"
|
||||||
#include "CXWindowsClipboard.h"
|
#include "CXWindowsClipboard.h"
|
||||||
#include "CXWindowsUtil.h"
|
#include "CXWindowsUtil.h"
|
||||||
#include "CClient.h"
|
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
#include "CLog.h"
|
#include "CLog.h"
|
||||||
#include <assert.h>
|
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#define XK_MISCELLANY
|
#define XK_MISCELLANY
|
||||||
|
@ -17,8 +16,8 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
CXWindowsSecondaryScreen::CXWindowsSecondaryScreen() :
|
CXWindowsSecondaryScreen::CXWindowsSecondaryScreen() :
|
||||||
m_client(NULL),
|
m_client(NULL),
|
||||||
m_window(None)
|
m_window(None)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -28,7 +27,8 @@ CXWindowsSecondaryScreen::~CXWindowsSecondaryScreen()
|
||||||
assert(m_window == None);
|
assert(m_window == None);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::run()
|
void
|
||||||
|
CXWindowsSecondaryScreen::run()
|
||||||
{
|
{
|
||||||
assert(m_window != None);
|
assert(m_window != None);
|
||||||
|
|
||||||
|
@ -41,34 +41,39 @@ void CXWindowsSecondaryScreen::run()
|
||||||
|
|
||||||
// handle event
|
// handle event
|
||||||
switch (xevent.type) {
|
switch (xevent.type) {
|
||||||
case MappingNotify: {
|
case MappingNotify:
|
||||||
// keyboard mapping changed
|
{
|
||||||
CDisplayLock display(this);
|
// keyboard mapping changed
|
||||||
XRefreshKeyboardMapping(&xevent.xmapping);
|
CDisplayLock display(this);
|
||||||
updateKeys(display);
|
XRefreshKeyboardMapping(&xevent.xmapping);
|
||||||
updateKeycodeMap(display);
|
updateKeys(display);
|
||||||
updateModifierMap(display);
|
updateKeycodeMap(display);
|
||||||
updateModifiers(display);
|
updateModifierMap(display);
|
||||||
|
updateModifiers(display);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case LeaveNotify: {
|
case LeaveNotify:
|
||||||
// mouse moved out of hider window somehow. hide the window.
|
{
|
||||||
assert(m_window != None);
|
// mouse moved out of hider window somehow. hide the window.
|
||||||
CDisplayLock display(this);
|
assert(m_window != None);
|
||||||
XUnmapWindow(display, m_window);
|
CDisplayLock display(this);
|
||||||
|
XUnmapWindow(display, m_window);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::stop()
|
void
|
||||||
|
CXWindowsSecondaryScreen::stop()
|
||||||
{
|
{
|
||||||
doStop();
|
doStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::open(CClient* client)
|
void
|
||||||
|
CXWindowsSecondaryScreen::open(
|
||||||
|
CClient* client)
|
||||||
{
|
{
|
||||||
assert(m_client == NULL);
|
assert(m_client == NULL);
|
||||||
assert(client != NULL);
|
assert(client != NULL);
|
||||||
|
@ -84,8 +89,9 @@ void CXWindowsSecondaryScreen::open(CClient* client)
|
||||||
CDisplayLock display(this);
|
CDisplayLock display(this);
|
||||||
int majorOpcode, firstEvent, firstError;
|
int majorOpcode, firstEvent, firstError;
|
||||||
if (!XQueryExtension(display, XTestExtensionName,
|
if (!XQueryExtension(display, XTestExtensionName,
|
||||||
&majorOpcode, &firstEvent, &firstError))
|
&majorOpcode, &firstEvent, &firstError)) {
|
||||||
throw int(6); // FIXME -- make exception for this
|
throw int(6); // FIXME -- make exception for this
|
||||||
|
}
|
||||||
|
|
||||||
// update key state
|
// update key state
|
||||||
updateKeys(display);
|
updateKeys(display);
|
||||||
|
@ -102,11 +108,13 @@ void CXWindowsSecondaryScreen::open(CClient* client)
|
||||||
m_capsLockHalfDuplex = true;
|
m_capsLockHalfDuplex = true;
|
||||||
|
|
||||||
// assume primary has all clipboards
|
// assume primary has all clipboards
|
||||||
for (ClipboardID id = 0; id < kClipboardEnd; ++id)
|
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
||||||
grabClipboard(id);
|
grabClipboard(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::close()
|
void
|
||||||
|
CXWindowsSecondaryScreen::close()
|
||||||
{
|
{
|
||||||
assert(m_client != NULL);
|
assert(m_client != NULL);
|
||||||
|
|
||||||
|
@ -117,8 +125,11 @@ void CXWindowsSecondaryScreen::close()
|
||||||
m_client = NULL;
|
m_client = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::enter(
|
void
|
||||||
SInt32 x, SInt32 y, KeyModifierMask mask)
|
CXWindowsSecondaryScreen::enter(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y,
|
||||||
|
KeyModifierMask mask)
|
||||||
{
|
{
|
||||||
assert(m_window != None);
|
assert(m_window != None);
|
||||||
|
|
||||||
|
@ -149,14 +160,17 @@ void CXWindowsSecondaryScreen::enter(
|
||||||
XSync(display, False);
|
XSync(display, False);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::leave()
|
void
|
||||||
|
CXWindowsSecondaryScreen::leave()
|
||||||
{
|
{
|
||||||
CDisplayLock display(this);
|
CDisplayLock display(this);
|
||||||
leaveNoLock(display);
|
leaveNoLock(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::keyDown(
|
void
|
||||||
KeyID key, KeyModifierMask mask)
|
CXWindowsSecondaryScreen::keyDown(
|
||||||
|
KeyID key,
|
||||||
|
KeyModifierMask mask)
|
||||||
{
|
{
|
||||||
Keystrokes keys;
|
Keystrokes keys;
|
||||||
KeyCode keycode;
|
KeyCode keycode;
|
||||||
|
@ -164,8 +178,9 @@ void CXWindowsSecondaryScreen::keyDown(
|
||||||
// get the sequence of keys to simulate key press and the final
|
// get the sequence of keys to simulate key press and the final
|
||||||
// modifier state.
|
// modifier state.
|
||||||
m_mask = mapKey(keys, keycode, key, mask, kPress);
|
m_mask = mapKey(keys, keycode, key, mask, kPress);
|
||||||
if (keys.empty())
|
if (keys.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// generate key events
|
// generate key events
|
||||||
doKeystrokes(keys, 1);
|
doKeystrokes(keys, 1);
|
||||||
|
@ -174,8 +189,11 @@ void CXWindowsSecondaryScreen::keyDown(
|
||||||
m_keys[keycode] = true;
|
m_keys[keycode] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::keyRepeat(
|
void
|
||||||
KeyID key, KeyModifierMask mask, SInt32 count)
|
CXWindowsSecondaryScreen::keyRepeat(
|
||||||
|
KeyID key,
|
||||||
|
KeyModifierMask mask,
|
||||||
|
SInt32 count)
|
||||||
{
|
{
|
||||||
Keystrokes keys;
|
Keystrokes keys;
|
||||||
KeyCode keycode;
|
KeyCode keycode;
|
||||||
|
@ -183,15 +201,18 @@ void CXWindowsSecondaryScreen::keyRepeat(
|
||||||
// get the sequence of keys to simulate key repeat and the final
|
// get the sequence of keys to simulate key repeat and the final
|
||||||
// modifier state.
|
// modifier state.
|
||||||
m_mask = mapKey(keys, keycode, key, mask, kRepeat);
|
m_mask = mapKey(keys, keycode, key, mask, kRepeat);
|
||||||
if (keys.empty())
|
if (keys.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// generate key events
|
// generate key events
|
||||||
doKeystrokes(keys, count);
|
doKeystrokes(keys, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::keyUp(
|
void
|
||||||
KeyID key, KeyModifierMask mask)
|
CXWindowsSecondaryScreen::keyUp(
|
||||||
|
KeyID key,
|
||||||
|
KeyModifierMask mask)
|
||||||
{
|
{
|
||||||
Keystrokes keys;
|
Keystrokes keys;
|
||||||
KeyCode keycode;
|
KeyCode keycode;
|
||||||
|
@ -199,8 +220,9 @@ void CXWindowsSecondaryScreen::keyUp(
|
||||||
// get the sequence of keys to simulate key release and the final
|
// get the sequence of keys to simulate key release and the final
|
||||||
// modifier state.
|
// modifier state.
|
||||||
m_mask = mapKey(keys, keycode, key, mask, kRelease);
|
m_mask = mapKey(keys, keycode, key, mask, kRelease);
|
||||||
if (keys.empty())
|
if (keys.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// generate key events
|
// generate key events
|
||||||
doKeystrokes(keys, 1);
|
doKeystrokes(keys, 1);
|
||||||
|
@ -209,28 +231,37 @@ void CXWindowsSecondaryScreen::keyUp(
|
||||||
m_keys[keycode] = false;
|
m_keys[keycode] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::mouseDown(ButtonID button)
|
void
|
||||||
|
CXWindowsSecondaryScreen::mouseDown(
|
||||||
|
ButtonID button)
|
||||||
{
|
{
|
||||||
CDisplayLock display(this);
|
CDisplayLock display(this);
|
||||||
XTestFakeButtonEvent(display, mapButton(button), True, CurrentTime);
|
XTestFakeButtonEvent(display, mapButton(button), True, CurrentTime);
|
||||||
XSync(display, False);
|
XSync(display, False);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::mouseUp(ButtonID button)
|
void
|
||||||
|
CXWindowsSecondaryScreen::mouseUp(
|
||||||
|
ButtonID button)
|
||||||
{
|
{
|
||||||
CDisplayLock display(this);
|
CDisplayLock display(this);
|
||||||
XTestFakeButtonEvent(display, mapButton(button), False, CurrentTime);
|
XTestFakeButtonEvent(display, mapButton(button), False, CurrentTime);
|
||||||
XSync(display, False);
|
XSync(display, False);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::mouseMove(SInt32 x, SInt32 y)
|
void
|
||||||
|
CXWindowsSecondaryScreen::mouseMove(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
CDisplayLock display(this);
|
CDisplayLock display(this);
|
||||||
XTestFakeMotionEvent(display, getScreen(), x, y, CurrentTime);
|
XTestFakeMotionEvent(display, getScreen(), x, y, CurrentTime);
|
||||||
XSync(display, False);
|
XSync(display, False);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::mouseWheel(SInt32 delta)
|
void
|
||||||
|
CXWindowsSecondaryScreen::mouseWheel(
|
||||||
|
SInt32 delta)
|
||||||
{
|
{
|
||||||
// choose button depending on rotation direction
|
// choose button depending on rotation direction
|
||||||
const unsigned int button = (delta >= 0) ? 4 : 5;
|
const unsigned int button = (delta >= 0) ? 4 : 5;
|
||||||
|
@ -249,19 +280,25 @@ void CXWindowsSecondaryScreen::mouseWheel(SInt32 delta)
|
||||||
XSync(display, False);
|
XSync(display, False);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::setClipboard(
|
void
|
||||||
ClipboardID id, const IClipboard* clipboard)
|
CXWindowsSecondaryScreen::setClipboard(
|
||||||
|
ClipboardID id,
|
||||||
|
const IClipboard* clipboard)
|
||||||
{
|
{
|
||||||
setDisplayClipboard(id, clipboard);
|
setDisplayClipboard(id, clipboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::grabClipboard(ClipboardID id)
|
void
|
||||||
|
CXWindowsSecondaryScreen::grabClipboard(
|
||||||
|
ClipboardID id)
|
||||||
{
|
{
|
||||||
setDisplayClipboard(id, NULL);
|
setDisplayClipboard(id, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::getMousePos(
|
void
|
||||||
SInt32* x, SInt32* y) const
|
CXWindowsSecondaryScreen::getMousePos(
|
||||||
|
SInt32* x,
|
||||||
|
SInt32* y) const
|
||||||
{
|
{
|
||||||
CDisplayLock display(this);
|
CDisplayLock display(this);
|
||||||
int xTmp, yTmp, dummy;
|
int xTmp, yTmp, dummy;
|
||||||
|
@ -273,25 +310,31 @@ void CXWindowsSecondaryScreen::getMousePos(
|
||||||
*y = yTmp;
|
*y = yTmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::getSize(
|
void
|
||||||
SInt32* width, SInt32* height) const
|
CXWindowsSecondaryScreen::getSize(
|
||||||
|
SInt32* width,
|
||||||
|
SInt32* height) const
|
||||||
{
|
{
|
||||||
getScreenSize(width, height);
|
getScreenSize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
SInt32 CXWindowsSecondaryScreen::getJumpZoneSize() const
|
SInt32
|
||||||
|
CXWindowsSecondaryScreen::getJumpZoneSize() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::getClipboard(
|
void
|
||||||
ClipboardID id, IClipboard* clipboard) const
|
CXWindowsSecondaryScreen::getClipboard(
|
||||||
|
ClipboardID id,
|
||||||
|
IClipboard* clipboard) const
|
||||||
{
|
{
|
||||||
getDisplayClipboard(id, clipboard);
|
getDisplayClipboard(id, clipboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::onOpenDisplay(
|
void
|
||||||
Display* display)
|
CXWindowsSecondaryScreen::onOpenDisplay(
|
||||||
|
Display* display)
|
||||||
{
|
{
|
||||||
assert(m_window == None);
|
assert(m_window == None);
|
||||||
|
|
||||||
|
@ -318,15 +361,17 @@ void CXWindowsSecondaryScreen::onOpenDisplay(
|
||||||
leaveNoLock(display);
|
leaveNoLock(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
CXWindowsClipboard* CXWindowsSecondaryScreen::createClipboard(
|
CXWindowsClipboard*
|
||||||
ClipboardID id)
|
CXWindowsSecondaryScreen::createClipboard(
|
||||||
|
ClipboardID id)
|
||||||
{
|
{
|
||||||
CDisplayLock display(this);
|
CDisplayLock display(this);
|
||||||
return new CXWindowsClipboard(display, m_window, id);
|
return new CXWindowsClipboard(display, m_window, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::onCloseDisplay(
|
void
|
||||||
Display* display)
|
CXWindowsSecondaryScreen::onCloseDisplay(
|
||||||
|
Display* display)
|
||||||
{
|
{
|
||||||
assert(m_window != None);
|
assert(m_window != None);
|
||||||
|
|
||||||
|
@ -340,14 +385,17 @@ void CXWindowsSecondaryScreen::onCloseDisplay(
|
||||||
m_window = None;
|
m_window = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::onLostClipboard(
|
void
|
||||||
ClipboardID id)
|
CXWindowsSecondaryScreen::onLostClipboard(
|
||||||
|
ClipboardID id)
|
||||||
{
|
{
|
||||||
// tell client that the clipboard was grabbed locally
|
// tell client that the clipboard was grabbed locally
|
||||||
m_client->onClipboardChanged(id);
|
m_client->onClipboardChanged(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::leaveNoLock(Display* display)
|
void
|
||||||
|
CXWindowsSecondaryScreen::leaveNoLock(
|
||||||
|
Display* display)
|
||||||
{
|
{
|
||||||
assert(display != NULL);
|
assert(display != NULL);
|
||||||
assert(m_window != None);
|
assert(m_window != None);
|
||||||
|
@ -368,18 +416,21 @@ void CXWindowsSecondaryScreen::leaveNoLock(Display* display)
|
||||||
XWarpPointer(display, None, m_window, 0, 0, 0, 0, 0, 0);
|
XWarpPointer(display, None, m_window, 0, 0, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CXWindowsSecondaryScreen::mapButton(
|
unsigned int
|
||||||
ButtonID id) const
|
CXWindowsSecondaryScreen::mapButton(
|
||||||
|
ButtonID id) const
|
||||||
{
|
{
|
||||||
// FIXME -- should use button mapping?
|
// FIXME -- should use button mapping?
|
||||||
return static_cast<unsigned int>(id);
|
return static_cast<unsigned int>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyModifierMask CXWindowsSecondaryScreen::mapKey(
|
KeyModifierMask
|
||||||
Keystrokes& keys,
|
CXWindowsSecondaryScreen::mapKey(
|
||||||
KeyCode& keycode,
|
Keystrokes& keys,
|
||||||
KeyID id, KeyModifierMask mask,
|
KeyCode& keycode,
|
||||||
EKeyAction action) const
|
KeyID id,
|
||||||
|
KeyModifierMask mask,
|
||||||
|
EKeyAction action) const
|
||||||
{
|
{
|
||||||
// note -- must have display locked on entry
|
// note -- must have display locked on entry
|
||||||
|
|
||||||
|
@ -602,11 +653,12 @@ KeyModifierMask CXWindowsSecondaryScreen::mapKey(
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsSecondaryScreen::findKeyCode(
|
bool
|
||||||
KeyCode& keycode,
|
CXWindowsSecondaryScreen::findKeyCode(
|
||||||
unsigned int& maskOut,
|
KeyCode& keycode,
|
||||||
KeyID id,
|
unsigned int& maskOut,
|
||||||
unsigned int maskIn) const
|
KeyID id,
|
||||||
|
unsigned int maskIn) const
|
||||||
{
|
{
|
||||||
// if XK_Tab is requested with shift active then try XK_ISO_Left_Tab
|
// if XK_Tab is requested with shift active then try XK_ISO_Left_Tab
|
||||||
// instead. if that doesn't work, we'll fall back to XK_Tab with
|
// instead. if that doesn't work, we'll fall back to XK_Tab with
|
||||||
|
@ -734,12 +786,15 @@ bool CXWindowsSecondaryScreen::findKeyCode(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::doKeystrokes(
|
void
|
||||||
const Keystrokes& keys, SInt32 count)
|
CXWindowsSecondaryScreen::doKeystrokes(
|
||||||
|
const Keystrokes& keys,
|
||||||
|
SInt32 count)
|
||||||
{
|
{
|
||||||
// do nothing if no keys or no repeats
|
// do nothing if no keys or no repeats
|
||||||
if (count < 1 || keys.empty())
|
if (count < 1 || keys.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// lock display
|
// lock display
|
||||||
CDisplayLock display(this);
|
CDisplayLock display(this);
|
||||||
|
@ -774,29 +829,39 @@ void CXWindowsSecondaryScreen::doKeystrokes(
|
||||||
XSync(display, False);
|
XSync(display, False);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CXWindowsSecondaryScreen::maskToX(
|
unsigned int
|
||||||
KeyModifierMask inMask) const
|
CXWindowsSecondaryScreen::maskToX(
|
||||||
|
KeyModifierMask inMask) const
|
||||||
{
|
{
|
||||||
// FIXME -- should be configurable. also not using Mod3Mask.
|
// FIXME -- should be configurable. also not using Mod3Mask.
|
||||||
unsigned int outMask = 0;
|
unsigned int outMask = 0;
|
||||||
if (inMask & KeyModifierShift)
|
if (inMask & KeyModifierShift) {
|
||||||
outMask |= ShiftMask;
|
outMask |= ShiftMask;
|
||||||
if (inMask & KeyModifierControl)
|
}
|
||||||
|
if (inMask & KeyModifierControl) {
|
||||||
outMask |= ControlMask;
|
outMask |= ControlMask;
|
||||||
if (inMask & KeyModifierAlt)
|
}
|
||||||
|
if (inMask & KeyModifierAlt) {
|
||||||
outMask |= Mod1Mask;
|
outMask |= Mod1Mask;
|
||||||
if (inMask & KeyModifierMeta)
|
}
|
||||||
|
if (inMask & KeyModifierMeta) {
|
||||||
outMask |= Mod4Mask;
|
outMask |= Mod4Mask;
|
||||||
if (inMask & KeyModifierCapsLock)
|
}
|
||||||
|
if (inMask & KeyModifierCapsLock) {
|
||||||
outMask |= m_capsLockMask;
|
outMask |= m_capsLockMask;
|
||||||
if (inMask & KeyModifierNumLock)
|
}
|
||||||
|
if (inMask & KeyModifierNumLock) {
|
||||||
outMask |= m_numLockMask;
|
outMask |= m_numLockMask;
|
||||||
if (inMask & KeyModifierScrollLock)
|
}
|
||||||
|
if (inMask & KeyModifierScrollLock) {
|
||||||
outMask |= m_scrollLockMask;
|
outMask |= m_scrollLockMask;
|
||||||
|
}
|
||||||
return outMask;
|
return outMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::updateKeys(Display* display)
|
void
|
||||||
|
CXWindowsSecondaryScreen::updateKeys(
|
||||||
|
Display* display)
|
||||||
{
|
{
|
||||||
// ask server which keys are pressed
|
// ask server which keys are pressed
|
||||||
char keys[32];
|
char keys[32];
|
||||||
|
@ -815,8 +880,9 @@ void CXWindowsSecondaryScreen::updateKeys(Display* display)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::updateModifiers(
|
void
|
||||||
Display* display)
|
CXWindowsSecondaryScreen::updateModifiers(
|
||||||
|
Display* display)
|
||||||
{
|
{
|
||||||
// query the pointer to get the keyboard state
|
// query the pointer to get the keyboard state
|
||||||
Window root, window;
|
Window root, window;
|
||||||
|
@ -844,8 +910,9 @@ void CXWindowsSecondaryScreen::updateModifiers(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::updateKeycodeMap(
|
void
|
||||||
Display* display)
|
CXWindowsSecondaryScreen::updateKeycodeMap(
|
||||||
|
Display* display)
|
||||||
{
|
{
|
||||||
// get the number of keycodes
|
// get the number of keycodes
|
||||||
int minKeycode, maxKeycode;
|
int minKeycode, maxKeycode;
|
||||||
|
@ -898,8 +965,9 @@ void CXWindowsSecondaryScreen::updateKeycodeMap(
|
||||||
XFree(keysyms);
|
XFree(keysyms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::updateModifierMap(
|
void
|
||||||
Display* display)
|
CXWindowsSecondaryScreen::updateModifierMap(
|
||||||
|
Display* display)
|
||||||
{
|
{
|
||||||
// get modifier map from server
|
// get modifier map from server
|
||||||
XModifierKeymap* keymap = XGetModifierMapping(display);
|
XModifierKeymap* keymap = XGetModifierMapping(display);
|
||||||
|
@ -927,8 +995,9 @@ void CXWindowsSecondaryScreen::updateModifierMap(
|
||||||
m_keycodeToModifier.insert(std::make_pair(keycode, i));
|
m_keycodeToModifier.insert(std::make_pair(keycode, i));
|
||||||
|
|
||||||
// modifier is enabled if keycode isn't 0
|
// modifier is enabled if keycode isn't 0
|
||||||
if (keycode != 0)
|
if (keycode != 0) {
|
||||||
m_modifierMask |= bit;
|
m_modifierMask |= bit;
|
||||||
|
}
|
||||||
|
|
||||||
// modifier is a toggle if the keysym is a toggle modifier
|
// modifier is a toggle if the keysym is a toggle modifier
|
||||||
const KeySym keysym = XKeycodeToKeysym(display, keycode, 0);
|
const KeySym keysym = XKeycodeToKeysym(display, keycode, 0);
|
||||||
|
@ -952,14 +1021,17 @@ void CXWindowsSecondaryScreen::updateModifierMap(
|
||||||
XFreeModifiermap(keymap);
|
XFreeModifiermap(keymap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsSecondaryScreen::toggleKey(
|
void
|
||||||
Display* display,
|
CXWindowsSecondaryScreen::toggleKey(
|
||||||
KeySym keysym, unsigned int mask)
|
Display* display,
|
||||||
|
KeySym keysym,
|
||||||
|
unsigned int mask)
|
||||||
{
|
{
|
||||||
// lookup the keycode
|
// lookup the keycode
|
||||||
KeyCodeMap::const_iterator index = m_keycodeMap.find(keysym);
|
KeyCodeMap::const_iterator index = m_keycodeMap.find(keysym);
|
||||||
if (index == m_keycodeMap.end())
|
if (index == m_keycodeMap.end()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
KeyCode keycode = index->second.m_keycode;
|
KeyCode keycode = index->second.m_keycode;
|
||||||
|
|
||||||
// toggle the key
|
// toggle the key
|
||||||
|
@ -978,7 +1050,9 @@ void CXWindowsSecondaryScreen::toggleKey(
|
||||||
m_mask ^= mask;
|
m_mask ^= mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsSecondaryScreen::isToggleKeysym(KeySym key)
|
bool
|
||||||
|
CXWindowsSecondaryScreen::isToggleKeysym(
|
||||||
|
KeySym key)
|
||||||
{
|
{
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case XK_Caps_Lock:
|
case XK_Caps_Lock:
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
#include "stdmap.h"
|
#include "stdmap.h"
|
||||||
#include "stdvector.h"
|
#include "stdvector.h"
|
||||||
|
|
||||||
class CXWindowsSecondaryScreen : public CXWindowsScreen, public ISecondaryScreen {
|
class CXWindowsSecondaryScreen : public CXWindowsScreen,
|
||||||
|
public ISecondaryScreen {
|
||||||
public:
|
public:
|
||||||
CXWindowsSecondaryScreen();
|
CXWindowsSecondaryScreen();
|
||||||
virtual ~CXWindowsSecondaryScreen();
|
virtual ~CXWindowsSecondaryScreen();
|
||||||
|
@ -17,7 +18,7 @@ public:
|
||||||
virtual void open(CClient*);
|
virtual void open(CClient*);
|
||||||
virtual void close();
|
virtual void close();
|
||||||
virtual void enter(SInt32 xAbsolute, SInt32 yAbsolute,
|
virtual void enter(SInt32 xAbsolute, SInt32 yAbsolute,
|
||||||
KeyModifierMask mask);
|
KeyModifierMask mask);
|
||||||
virtual void leave();
|
virtual void leave();
|
||||||
virtual void keyDown(KeyID, KeyModifierMask);
|
virtual void keyDown(KeyID, KeyModifierMask);
|
||||||
virtual void keyRepeat(KeyID, KeyModifierMask, SInt32 count);
|
virtual void keyRepeat(KeyID, KeyModifierMask, SInt32 count);
|
||||||
|
@ -64,9 +65,9 @@ private:
|
||||||
unsigned int mapButton(ButtonID button) const;
|
unsigned int mapButton(ButtonID button) const;
|
||||||
|
|
||||||
unsigned int mapKey(Keystrokes&, KeyCode&, KeyID,
|
unsigned int mapKey(Keystrokes&, KeyCode&, KeyID,
|
||||||
KeyModifierMask, EKeyAction) const;
|
KeyModifierMask, EKeyAction) const;
|
||||||
bool findKeyCode(KeyCode&, unsigned int&,
|
bool findKeyCode(KeyCode&, unsigned int&,
|
||||||
KeyID id, unsigned int) const;
|
KeyID id, unsigned int) const;
|
||||||
void doKeystrokes(const Keystrokes&, SInt32 count);
|
void doKeystrokes(const Keystrokes&, SInt32 count);
|
||||||
unsigned int maskToX(KeyModifierMask) const;
|
unsigned int maskToX(KeyModifierMask) const;
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
#include "CClient.h"
|
#include "CClient.h"
|
||||||
#include "CString.h"
|
#include "CPlatform.h"
|
||||||
#include "CLog.h"
|
#include "ProtocolTypes.h"
|
||||||
|
#include "Version.h"
|
||||||
|
#include "CNetwork.h"
|
||||||
|
#include "CNetworkAddress.h"
|
||||||
|
#include "XSocket.h"
|
||||||
#include "CCondVar.h"
|
#include "CCondVar.h"
|
||||||
#include "CLock.h"
|
#include "CLock.h"
|
||||||
#include "CMutex.h"
|
#include "CMutex.h"
|
||||||
#include "CNetwork.h"
|
|
||||||
#include "CNetworkAddress.h"
|
|
||||||
#include "CPlatform.h"
|
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
#include "XThread.h"
|
#include "XThread.h"
|
||||||
#include "ProtocolTypes.h"
|
#include "CLog.h"
|
||||||
#include "Version.h"
|
#include "CString.h"
|
||||||
#include <assert.h>
|
#include <cstring>
|
||||||
|
|
||||||
// platform dependent name of a daemon
|
// platform dependent name of a daemon
|
||||||
#if defined(CONFIG_PLATFORM_WIN32)
|
#if defined(CONFIG_PLATFORM_WIN32)
|
||||||
|
@ -43,7 +44,10 @@ static CNetworkAddress s_serverAddress;
|
||||||
|
|
||||||
static CMutex* s_logMutex = NULL;
|
static CMutex* s_logMutex = NULL;
|
||||||
|
|
||||||
static void logLock(bool lock)
|
static
|
||||||
|
void
|
||||||
|
logLock(
|
||||||
|
bool lock)
|
||||||
{
|
{
|
||||||
assert(s_logMutex != NULL);
|
assert(s_logMutex != NULL);
|
||||||
|
|
||||||
|
@ -62,7 +66,10 @@ static void logLock(bool lock)
|
||||||
|
|
||||||
static CClient* s_client = NULL;
|
static CClient* s_client = NULL;
|
||||||
|
|
||||||
static int realMain(CMutex* mutex)
|
static
|
||||||
|
int
|
||||||
|
realMain(
|
||||||
|
CMutex* mutex)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// initialize threading library
|
// initialize threading library
|
||||||
|
@ -124,14 +131,18 @@ static int realMain(CMutex* mutex)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int restartMain()
|
static
|
||||||
|
int
|
||||||
|
restartMain()
|
||||||
{
|
{
|
||||||
return realMain(NULL);
|
return realMain(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// invoke realMain and wait for it. if s_restartable then keep
|
// invoke realMain and wait for it. if s_restartable then keep
|
||||||
// restarting realMain until it returns a terminate code.
|
// restarting realMain until it returns a terminate code.
|
||||||
static int restartableMain()
|
static
|
||||||
|
int
|
||||||
|
restartableMain()
|
||||||
{
|
{
|
||||||
if (s_restartable) {
|
if (s_restartable) {
|
||||||
CPlatform platform;
|
CPlatform platform;
|
||||||
|
@ -151,7 +162,9 @@ static int restartableMain()
|
||||||
|
|
||||||
static void (*bye)(int) = &exit;
|
static void (*bye)(int) = &exit;
|
||||||
|
|
||||||
static void version()
|
static
|
||||||
|
void
|
||||||
|
version()
|
||||||
{
|
{
|
||||||
log((CLOG_PRINT
|
log((CLOG_PRINT
|
||||||
"%s %d.%d.%d, protocol version %d.%d\n"
|
"%s %d.%d.%d, protocol version %d.%d\n"
|
||||||
|
@ -165,7 +178,9 @@ static void version()
|
||||||
kCopyright));
|
kCopyright));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void help()
|
static
|
||||||
|
void
|
||||||
|
help()
|
||||||
{
|
{
|
||||||
log((CLOG_PRINT
|
log((CLOG_PRINT
|
||||||
"Usage: %s"
|
"Usage: %s"
|
||||||
|
@ -213,11 +228,14 @@ static void help()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isArg(int argi,
|
static
|
||||||
int argc, const char** argv,
|
bool
|
||||||
const char* name1,
|
isArg(int argi,
|
||||||
const char* name2,
|
int argc,
|
||||||
int minRequiredParameters = 0)
|
const char** argv,
|
||||||
|
const char* name1,
|
||||||
|
const char* name2,
|
||||||
|
int minRequiredParameters = 0)
|
||||||
{
|
{
|
||||||
if ((name1 != NULL && strcmp(argv[argi], name1) == 0) ||
|
if ((name1 != NULL && strcmp(argv[argi], name1) == 0) ||
|
||||||
(name2 != NULL && strcmp(argv[argi], name2) == 0)) {
|
(name2 != NULL && strcmp(argv[argi], name2) == 0)) {
|
||||||
|
@ -234,7 +252,11 @@ static bool isArg(int argi,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse(int argc, const char** argv)
|
static
|
||||||
|
void
|
||||||
|
parse(
|
||||||
|
int argc,
|
||||||
|
const char** argv)
|
||||||
{
|
{
|
||||||
assert(pname != NULL);
|
assert(pname != NULL);
|
||||||
assert(argv != NULL);
|
assert(argv != NULL);
|
||||||
|
@ -413,7 +435,11 @@ static void parse(int argc, const char** argv)
|
||||||
|
|
||||||
#include "CMSWindowsScreen.h"
|
#include "CMSWindowsScreen.h"
|
||||||
|
|
||||||
static bool logMessageBox(int priority, const char* msg)
|
static
|
||||||
|
bool
|
||||||
|
logMessageBox(
|
||||||
|
int priority,
|
||||||
|
const char* msg)
|
||||||
{
|
{
|
||||||
if (priority <= CLog::kFATAL) {
|
if (priority <= CLog::kFATAL) {
|
||||||
MessageBox(NULL, msg, pname, MB_OK | MB_ICONWARNING);
|
MessageBox(NULL, msg, pname, MB_OK | MB_ICONWARNING);
|
||||||
|
@ -424,18 +450,26 @@ static bool logMessageBox(int priority, const char* msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void byeThrow(int x)
|
static
|
||||||
|
void
|
||||||
|
byeThrow(int x)
|
||||||
{
|
{
|
||||||
throw CWin32Platform::CDaemonFailed(x);
|
throw CWin32Platform::CDaemonFailed(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void daemonStop(void)
|
static
|
||||||
|
void
|
||||||
|
daemonStop(void)
|
||||||
{
|
{
|
||||||
s_client->quit();
|
s_client->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int daemonStartup(IPlatform* iplatform,
|
static
|
||||||
int argc, const char** argv)
|
int
|
||||||
|
daemonStartup(
|
||||||
|
IPlatform* iplatform,
|
||||||
|
int argc,
|
||||||
|
const char** argv)
|
||||||
{
|
{
|
||||||
// get platform pointer
|
// get platform pointer
|
||||||
CWin32Platform* platform = static_cast<CWin32Platform*>(iplatform);
|
CWin32Platform* platform = static_cast<CWin32Platform*>(iplatform);
|
||||||
|
@ -456,19 +490,30 @@ static int daemonStartup(IPlatform* iplatform,
|
||||||
return platform->runDaemon(realMain, daemonStop);
|
return platform->runDaemon(realMain, daemonStop);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int daemonStartup95(IPlatform*, int, const char**)
|
static
|
||||||
|
int
|
||||||
|
daemonStartup95(
|
||||||
|
IPlatform*,
|
||||||
|
int,
|
||||||
|
const char**)
|
||||||
{
|
{
|
||||||
return realMain(NULL);
|
return realMain(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool logDiscard(int, const char*)
|
static
|
||||||
|
bool
|
||||||
|
logDiscard(
|
||||||
|
int,
|
||||||
|
const char*)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool s_die = false;
|
static bool s_die = false;
|
||||||
|
|
||||||
static void checkParse(int e)
|
static
|
||||||
|
void
|
||||||
|
checkParse(int e)
|
||||||
{
|
{
|
||||||
// anything over 1 means invalid args. 1 means missing args.
|
// anything over 1 means invalid args. 1 means missing args.
|
||||||
// 0 means graceful exit. we plan to exit for anything but
|
// 0 means graceful exit. we plan to exit for anything but
|
||||||
|
@ -478,7 +523,12 @@ static void checkParse(int e)
|
||||||
throw s_die;
|
throw s_die;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
int WINAPI
|
||||||
|
WinMain(
|
||||||
|
HINSTANCE instance,
|
||||||
|
HINSTANCE,
|
||||||
|
LPSTR,
|
||||||
|
int)
|
||||||
{
|
{
|
||||||
CPlatform platform;
|
CPlatform platform;
|
||||||
|
|
||||||
|
@ -594,12 +644,20 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
||||||
|
|
||||||
#elif defined(CONFIG_PLATFORM_UNIX)
|
#elif defined(CONFIG_PLATFORM_UNIX)
|
||||||
|
|
||||||
static int daemonStartup(IPlatform*, int, const char**)
|
static
|
||||||
|
int
|
||||||
|
daemonStartup(
|
||||||
|
IPlatform*,
|
||||||
|
int,
|
||||||
|
const char**)
|
||||||
{
|
{
|
||||||
return restartableMain();
|
return restartableMain();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int
|
||||||
|
main(
|
||||||
|
int argc,
|
||||||
|
char** argv)
|
||||||
{
|
{
|
||||||
CPlatform platform;
|
CPlatform platform;
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
#include "CHTTPProtocol.h"
|
#include "CHTTPProtocol.h"
|
||||||
#include "CLog.h"
|
|
||||||
#include "XHTTP.h"
|
#include "XHTTP.h"
|
||||||
#include "IInputStream.h"
|
#include "IInputStream.h"
|
||||||
#include "IOutputStream.h"
|
#include "IOutputStream.h"
|
||||||
|
#include "CLog.h"
|
||||||
#include "stdsstream.h"
|
#include "stdsstream.h"
|
||||||
#include <assert.h>
|
#include <clocale>
|
||||||
#include <locale.h>
|
#include <ctime>
|
||||||
#include <time.h>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -23,8 +22,10 @@ CHTTPRequest::~CHTTPRequest()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPRequest::insertHeader(
|
void
|
||||||
const CString& name, const CString& value)
|
CHTTPRequest::insertHeader(
|
||||||
|
const CString& name,
|
||||||
|
const CString& value)
|
||||||
{
|
{
|
||||||
CHeaderMap::iterator index = m_headerByName.find(name);
|
CHeaderMap::iterator index = m_headerByName.find(name);
|
||||||
if (index != m_headerByName.end()) {
|
if (index != m_headerByName.end()) {
|
||||||
|
@ -37,8 +38,10 @@ void CHTTPRequest::insertHeader(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPRequest::appendHeader(
|
void
|
||||||
const CString& name, const CString& value)
|
CHTTPRequest::appendHeader(
|
||||||
|
const CString& name,
|
||||||
|
const CString& value)
|
||||||
{
|
{
|
||||||
CHeaderMap::iterator index = m_headerByName.find(name);
|
CHeaderMap::iterator index = m_headerByName.find(name);
|
||||||
if (index != m_headerByName.end()) {
|
if (index != m_headerByName.end()) {
|
||||||
|
@ -52,7 +55,9 @@ void CHTTPRequest::appendHeader(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPRequest::eraseHeader(const CString& name)
|
void
|
||||||
|
CHTTPRequest::eraseHeader(
|
||||||
|
const CString& name)
|
||||||
{
|
{
|
||||||
CHeaderMap::iterator index = m_headerByName.find(name);
|
CHeaderMap::iterator index = m_headerByName.find(name);
|
||||||
if (index != m_headerByName.end()) {
|
if (index != m_headerByName.end()) {
|
||||||
|
@ -60,12 +65,16 @@ void CHTTPRequest::eraseHeader(const CString& name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CHTTPRequest::isHeader(const CString& name) const
|
bool
|
||||||
|
CHTTPRequest::isHeader(
|
||||||
|
const CString& name) const
|
||||||
{
|
{
|
||||||
return (m_headerByName.find(name) != m_headerByName.end());
|
return (m_headerByName.find(name) != m_headerByName.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CHTTPRequest::getHeader(const CString& name) const
|
CString
|
||||||
|
CHTTPRequest::getHeader(
|
||||||
|
const CString& name) const
|
||||||
{
|
{
|
||||||
CHeaderMap::const_iterator index = m_headerByName.find(name);
|
CHeaderMap::const_iterator index = m_headerByName.find(name);
|
||||||
if (index != m_headerByName.end()) {
|
if (index != m_headerByName.end()) {
|
||||||
|
@ -81,8 +90,10 @@ CString CHTTPRequest::getHeader(const CString& name) const
|
||||||
// CHTTPProtocol
|
// CHTTPProtocol
|
||||||
//
|
//
|
||||||
|
|
||||||
CHTTPRequest* CHTTPProtocol::readRequest(
|
CHTTPRequest*
|
||||||
IInputStream* stream, UInt32 maxSize)
|
CHTTPProtocol::readRequest(
|
||||||
|
IInputStream* stream,
|
||||||
|
UInt32 maxSize)
|
||||||
{
|
{
|
||||||
CString scratch;
|
CString scratch;
|
||||||
|
|
||||||
|
@ -229,9 +240,10 @@ CHTTPRequest* CHTTPProtocol::readRequest(
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPProtocol::reply(
|
void
|
||||||
IOutputStream* stream,
|
CHTTPProtocol::reply(
|
||||||
CHTTPReply& reply)
|
IOutputStream* stream,
|
||||||
|
CHTTPReply& reply)
|
||||||
{
|
{
|
||||||
// suppress body for certain replies
|
// suppress body for certain replies
|
||||||
bool hasBody = true;
|
bool hasBody = true;
|
||||||
|
@ -308,9 +320,10 @@ void CHTTPProtocol::reply(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CHTTPProtocol::parseFormData(
|
bool
|
||||||
const CHTTPRequest& request,
|
CHTTPProtocol::parseFormData(
|
||||||
CFormParts& parts)
|
const CHTTPRequest& request,
|
||||||
|
CFormParts& parts)
|
||||||
{
|
{
|
||||||
static const char formData[] = "multipart/form-data";
|
static const char formData[] = "multipart/form-data";
|
||||||
static const char boundary[] = "boundary=";
|
static const char boundary[] = "boundary=";
|
||||||
|
@ -444,9 +457,10 @@ bool CHTTPProtocol::parseFormData(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CHTTPProtocol::readLine(
|
CString
|
||||||
IInputStream* stream,
|
CHTTPProtocol::readLine(
|
||||||
CString& tmpBuffer)
|
IInputStream* stream,
|
||||||
|
CString& tmpBuffer)
|
||||||
{
|
{
|
||||||
// read up to and including a CRLF from stream, using whatever
|
// read up to and including a CRLF from stream, using whatever
|
||||||
// is in tmpBuffer as if it were at the head of the stream.
|
// is in tmpBuffer as if it were at the head of the stream.
|
||||||
|
@ -478,10 +492,11 @@ CString CHTTPProtocol::readLine(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CHTTPProtocol::readBlock(
|
CString
|
||||||
IInputStream* stream,
|
CHTTPProtocol::readBlock(
|
||||||
UInt32 numBytes,
|
IInputStream* stream,
|
||||||
CString& tmpBuffer)
|
UInt32 numBytes,
|
||||||
|
CString& tmpBuffer)
|
||||||
{
|
{
|
||||||
CString data;
|
CString data;
|
||||||
|
|
||||||
|
@ -527,10 +542,11 @@ CString CHTTPProtocol::readBlock(
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CHTTPProtocol::readChunk(
|
CString
|
||||||
IInputStream* stream,
|
CHTTPProtocol::readChunk(
|
||||||
CString& tmpBuffer,
|
IInputStream* stream,
|
||||||
UInt32* maxSize)
|
CString& tmpBuffer,
|
||||||
|
UInt32* maxSize)
|
||||||
{
|
{
|
||||||
CString line;
|
CString line;
|
||||||
|
|
||||||
|
@ -577,12 +593,13 @@ CString CHTTPProtocol::readChunk(
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPProtocol::readHeaders(
|
void
|
||||||
IInputStream* stream,
|
CHTTPProtocol::readHeaders(
|
||||||
CHTTPRequest* request,
|
IInputStream* stream,
|
||||||
bool isFooter,
|
CHTTPRequest* request,
|
||||||
CString& tmpBuffer,
|
bool isFooter,
|
||||||
UInt32* maxSize)
|
CString& tmpBuffer,
|
||||||
|
UInt32* maxSize)
|
||||||
{
|
{
|
||||||
// parse headers. done with headers when we get a blank line.
|
// parse headers. done with headers when we get a blank line.
|
||||||
CString name;
|
CString name;
|
||||||
|
@ -634,7 +651,9 @@ void CHTTPProtocol::readHeaders(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CHTTPProtocol::isValidToken(const CString& token)
|
bool
|
||||||
|
CHTTPProtocol::isValidToken(
|
||||||
|
const CString& token)
|
||||||
{
|
{
|
||||||
return (token.find("()<>@,;:\\\"/[]?={} "
|
return (token.find("()<>@,;:\\\"/[]?={} "
|
||||||
"\0\1\2\3\4\5\6\7"
|
"\0\1\2\3\4\5\6\7"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef CHTTPPROTOCOL_H
|
#ifndef CHTTPPROTOCOL_H
|
||||||
#define CHTTPPROTOCOL_H
|
#define CHTTPPROTOCOL_H
|
||||||
|
|
||||||
#include "BasicTypes.h"
|
|
||||||
#include "CString.h"
|
#include "CString.h"
|
||||||
|
#include "BasicTypes.h"
|
||||||
#include "stdlist.h"
|
#include "stdlist.h"
|
||||||
#include "stdmap.h"
|
#include "stdmap.h"
|
||||||
#include "stdvector.h"
|
#include "stdvector.h"
|
||||||
|
@ -14,7 +14,7 @@ class CHTTPRequest {
|
||||||
public:
|
public:
|
||||||
typedef std::list<std::pair<CString, CString> > CHeaderList;
|
typedef std::list<std::pair<CString, CString> > CHeaderList;
|
||||||
typedef std::map<CString, CHeaderList::iterator,
|
typedef std::map<CString, CHeaderList::iterator,
|
||||||
CStringUtil::CaselessCmp> CHeaderMap;
|
CStringUtil::CaselessCmp> CHeaderMap;
|
||||||
typedef CHeaderList::const_iterator const_iterator;
|
typedef CHeaderList::const_iterator const_iterator;
|
||||||
|
|
||||||
CHTTPRequest();
|
CHTTPRequest();
|
||||||
|
@ -93,18 +93,18 @@ public:
|
||||||
// FIXME -- name/value pairs insufficient to save part headers
|
// FIXME -- name/value pairs insufficient to save part headers
|
||||||
typedef std::map<CString, CString> CFormParts;
|
typedef std::map<CString, CString> CFormParts;
|
||||||
static bool parseFormData(const CHTTPRequest&,
|
static bool parseFormData(const CHTTPRequest&,
|
||||||
CFormParts& parts);
|
CFormParts& parts);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static CString readLine(IInputStream*, CString& tmpBuffer);
|
static CString readLine(IInputStream*, CString& tmpBuffer);
|
||||||
static CString readBlock(IInputStream*,
|
static CString readBlock(IInputStream*,
|
||||||
UInt32 numBytes, CString& tmpBuffer);
|
UInt32 numBytes, CString& tmpBuffer);
|
||||||
static CString readChunk(IInputStream*, CString& tmpBuffer,
|
static CString readChunk(IInputStream*, CString& tmpBuffer,
|
||||||
UInt32* maxSize);
|
UInt32* maxSize);
|
||||||
static void readHeaders(IInputStream*,
|
static void readHeaders(IInputStream*,
|
||||||
CHTTPRequest*, bool isFooter,
|
CHTTPRequest*, bool isFooter,
|
||||||
CString& tmpBuffer,
|
CString& tmpBuffer,
|
||||||
UInt32* maxSize);
|
UInt32* maxSize);
|
||||||
|
|
||||||
static bool isValidToken(const CString&);
|
static bool isValidToken(const CString&);
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,18 +6,21 @@
|
||||||
// XHTTP
|
// XHTTP
|
||||||
//
|
//
|
||||||
|
|
||||||
XHTTP::XHTTP(SInt32 statusCode) :
|
XHTTP::XHTTP(
|
||||||
XBase(),
|
SInt32 statusCode) :
|
||||||
m_status(statusCode),
|
XBase(),
|
||||||
m_reason(getReason(statusCode))
|
m_status(statusCode),
|
||||||
|
m_reason(getReason(statusCode))
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
XHTTP::XHTTP(SInt32 statusCode, const CString& reasonPhrase) :
|
XHTTP::XHTTP(
|
||||||
XBase(),
|
SInt32 statusCode,
|
||||||
m_status(statusCode),
|
const CString& reasonPhrase) :
|
||||||
m_reason(reasonPhrase)
|
XBase(),
|
||||||
|
m_status(statusCode),
|
||||||
|
m_reason(reasonPhrase)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -27,22 +30,27 @@ XHTTP::~XHTTP()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
SInt32 XHTTP::getStatus() const
|
SInt32
|
||||||
|
XHTTP::getStatus() const
|
||||||
{
|
{
|
||||||
return m_status;
|
return m_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
CString XHTTP::getReason() const
|
CString
|
||||||
|
XHTTP::getReason() const
|
||||||
{
|
{
|
||||||
return m_reason;
|
return m_reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XHTTP::addHeaders(CHTTPReply&) const
|
void
|
||||||
|
XHTTP::addHeaders(
|
||||||
|
CHTTPReply&) const
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
CString XHTTP::getWhat() const throw()
|
CString
|
||||||
|
XHTTP::getWhat() const throw()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
|
@ -60,7 +68,9 @@ CString XHTTP::getWhat() const throw()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* XHTTP::getReason(SInt32 status)
|
const char*
|
||||||
|
XHTTP::getReason(
|
||||||
|
SInt32 status)
|
||||||
{
|
{
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 300: return "Multiple Choices";
|
case 300: return "Multiple Choices";
|
||||||
|
@ -100,9 +110,10 @@ const char* XHTTP::getReason(SInt32 status)
|
||||||
// XHTTPAllow
|
// XHTTPAllow
|
||||||
//
|
//
|
||||||
|
|
||||||
XHTTPAllow::XHTTPAllow(const CString& allowed) :
|
XHTTPAllow::XHTTPAllow(
|
||||||
XHTTP(405),
|
const CString& allowed) :
|
||||||
m_allowed(allowed)
|
XHTTP(405),
|
||||||
|
m_allowed(allowed)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -112,7 +123,9 @@ XHTTPAllow::~XHTTPAllow()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void XHTTPAllow::addHeaders(CHTTPReply& reply) const
|
void
|
||||||
|
XHTTPAllow::addHeaders(
|
||||||
|
CHTTPReply& reply) const
|
||||||
{
|
{
|
||||||
reply.m_headers.push_back(std::make_pair(CString("Allow"), m_allowed));
|
reply.m_headers.push_back(std::make_pair(CString("Allow"), m_allowed));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define XHTTP_H
|
#define XHTTP_H
|
||||||
|
|
||||||
#include "BasicTypes.h"
|
#include "BasicTypes.h"
|
||||||
#include "CString.h"
|
|
||||||
#include "XBase.h"
|
#include "XBase.h"
|
||||||
|
|
||||||
class CHTTPReply;
|
class CHTTPReply;
|
||||||
|
|
|
@ -4,19 +4,20 @@
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
#include "IJob.h"
|
#include "IJob.h"
|
||||||
#include "XIO.h"
|
#include "XIO.h"
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CBufferedInputStream
|
// CBufferedInputStream
|
||||||
//
|
//
|
||||||
|
|
||||||
CBufferedInputStream::CBufferedInputStream(CMutex* mutex, IJob* closeCB) :
|
CBufferedInputStream::CBufferedInputStream(
|
||||||
m_mutex(mutex),
|
CMutex* mutex,
|
||||||
m_empty(mutex, true),
|
IJob* closeCB) :
|
||||||
m_closeCB(closeCB),
|
m_mutex(mutex),
|
||||||
m_closed(false),
|
m_empty(mutex, true),
|
||||||
m_hungup(false)
|
m_closeCB(closeCB),
|
||||||
|
m_closed(false),
|
||||||
|
m_hungup(false)
|
||||||
{
|
{
|
||||||
assert(m_mutex != NULL);
|
assert(m_mutex != NULL);
|
||||||
}
|
}
|
||||||
|
@ -26,8 +27,10 @@ CBufferedInputStream::~CBufferedInputStream()
|
||||||
delete m_closeCB;
|
delete m_closeCB;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBufferedInputStream::write(
|
void
|
||||||
const void* data, UInt32 n)
|
CBufferedInputStream::write(
|
||||||
|
const void* data,
|
||||||
|
UInt32 n)
|
||||||
{
|
{
|
||||||
if (!m_hungup && n > 0) {
|
if (!m_hungup && n > 0) {
|
||||||
m_buffer.write(data, n);
|
m_buffer.write(data, n);
|
||||||
|
@ -36,14 +39,17 @@ void CBufferedInputStream::write(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBufferedInputStream::hangup()
|
void
|
||||||
|
CBufferedInputStream::hangup()
|
||||||
{
|
{
|
||||||
m_hungup = true;
|
m_hungup = true;
|
||||||
m_empty.broadcast();
|
m_empty.broadcast();
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CBufferedInputStream::readNoLock(
|
UInt32
|
||||||
void* dst, UInt32 n)
|
CBufferedInputStream::readNoLock(
|
||||||
|
void* dst,
|
||||||
|
UInt32 n)
|
||||||
{
|
{
|
||||||
if (m_closed) {
|
if (m_closed) {
|
||||||
throw XIOClosed();
|
throw XIOClosed();
|
||||||
|
@ -74,12 +80,14 @@ UInt32 CBufferedInputStream::readNoLock(
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CBufferedInputStream::getSizeNoLock() const
|
UInt32
|
||||||
|
CBufferedInputStream::getSizeNoLock() const
|
||||||
{
|
{
|
||||||
return m_buffer.getSize();
|
return m_buffer.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBufferedInputStream::close()
|
void
|
||||||
|
CBufferedInputStream::close()
|
||||||
{
|
{
|
||||||
CLock lock(m_mutex);
|
CLock lock(m_mutex);
|
||||||
if (m_closed) {
|
if (m_closed) {
|
||||||
|
@ -95,16 +103,18 @@ void CBufferedInputStream::close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CBufferedInputStream::read(
|
UInt32
|
||||||
void* dst, UInt32 n)
|
CBufferedInputStream::read(
|
||||||
|
void* dst,
|
||||||
|
UInt32 n)
|
||||||
{
|
{
|
||||||
CLock lock(m_mutex);
|
CLock lock(m_mutex);
|
||||||
return readNoLock(dst, n);
|
return readNoLock(dst, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CBufferedInputStream::getSize() const
|
UInt32
|
||||||
|
CBufferedInputStream::getSize() const
|
||||||
{
|
{
|
||||||
CLock lock(m_mutex);
|
CLock lock(m_mutex);
|
||||||
return getSizeNoLock();
|
return getSizeNoLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef CBUFFEREDINPUTSTREAM_H
|
#ifndef CBUFFEREDINPUTSTREAM_H
|
||||||
#define CBUFFEREDINPUTSTREAM_H
|
#define CBUFFEREDINPUTSTREAM_H
|
||||||
|
|
||||||
|
#include "IInputStream.h"
|
||||||
#include "CStreamBuffer.h"
|
#include "CStreamBuffer.h"
|
||||||
#include "CCondVar.h"
|
#include "CCondVar.h"
|
||||||
#include "IInputStream.h"
|
|
||||||
|
|
||||||
class CMutex;
|
class CMutex;
|
||||||
class IJob;
|
class IJob;
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
#include "CBufferedOutputStream.h"
|
#include "CBufferedOutputStream.h"
|
||||||
|
#include "XIO.h"
|
||||||
#include "CLock.h"
|
#include "CLock.h"
|
||||||
#include "CMutex.h"
|
#include "CMutex.h"
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
#include "IJob.h"
|
#include "IJob.h"
|
||||||
#include "XIO.h"
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CBufferedOutputStream
|
// CBufferedOutputStream
|
||||||
//
|
//
|
||||||
|
|
||||||
CBufferedOutputStream::CBufferedOutputStream(CMutex* mutex, IJob* closeCB) :
|
CBufferedOutputStream::CBufferedOutputStream(
|
||||||
m_mutex(mutex),
|
CMutex* mutex,
|
||||||
m_closeCB(closeCB),
|
IJob* closeCB) :
|
||||||
m_empty(mutex, true),
|
m_mutex(mutex),
|
||||||
m_closed(false)
|
m_closeCB(closeCB),
|
||||||
|
m_empty(mutex, true),
|
||||||
|
m_closed(false)
|
||||||
{
|
{
|
||||||
assert(m_mutex != NULL);
|
assert(m_mutex != NULL);
|
||||||
}
|
}
|
||||||
|
@ -24,12 +25,16 @@ CBufferedOutputStream::~CBufferedOutputStream()
|
||||||
delete m_closeCB;
|
delete m_closeCB;
|
||||||
}
|
}
|
||||||
|
|
||||||
const void* CBufferedOutputStream::peek(UInt32 n)
|
const void*
|
||||||
|
CBufferedOutputStream::peek(
|
||||||
|
UInt32 n)
|
||||||
{
|
{
|
||||||
return m_buffer.peek(n);
|
return m_buffer.peek(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBufferedOutputStream::pop(UInt32 n)
|
void
|
||||||
|
CBufferedOutputStream::pop(
|
||||||
|
UInt32 n)
|
||||||
{
|
{
|
||||||
m_buffer.pop(n);
|
m_buffer.pop(n);
|
||||||
if (m_buffer.getSize() == 0) {
|
if (m_buffer.getSize() == 0) {
|
||||||
|
@ -37,12 +42,14 @@ void CBufferedOutputStream::pop(UInt32 n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CBufferedOutputStream::getSize() const
|
UInt32
|
||||||
|
CBufferedOutputStream::getSize() const
|
||||||
{
|
{
|
||||||
return m_buffer.getSize();
|
return m_buffer.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBufferedOutputStream::close()
|
void
|
||||||
|
CBufferedOutputStream::close()
|
||||||
{
|
{
|
||||||
CLock lock(m_mutex);
|
CLock lock(m_mutex);
|
||||||
if (m_closed) {
|
if (m_closed) {
|
||||||
|
@ -56,8 +63,10 @@ void CBufferedOutputStream::close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CBufferedOutputStream::write(
|
UInt32
|
||||||
const void* data, UInt32 n)
|
CBufferedOutputStream::write(
|
||||||
|
const void* data,
|
||||||
|
UInt32 n)
|
||||||
{
|
{
|
||||||
CLock lock(m_mutex);
|
CLock lock(m_mutex);
|
||||||
if (m_closed) {
|
if (m_closed) {
|
||||||
|
@ -68,7 +77,8 @@ UInt32 CBufferedOutputStream::write(
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBufferedOutputStream::flush()
|
void
|
||||||
|
CBufferedOutputStream::flush()
|
||||||
{
|
{
|
||||||
// wait until all data is written
|
// wait until all data is written
|
||||||
CLock lock(m_mutex);
|
CLock lock(m_mutex);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef CBUFFEREDOUTPUTSTREAM_H
|
#ifndef CBUFFEREDOUTPUTSTREAM_H
|
||||||
#define CBUFFEREDOUTPUTSTREAM_H
|
#define CBUFFEREDOUTPUTSTREAM_H
|
||||||
|
|
||||||
#include "CStreamBuffer.h"
|
|
||||||
#include "IOutputStream.h"
|
#include "IOutputStream.h"
|
||||||
|
#include "CStreamBuffer.h"
|
||||||
#include "CCondVar.h"
|
#include "CCondVar.h"
|
||||||
|
|
||||||
class CMutex;
|
class CMutex;
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
#include "CInputStreamFilter.h"
|
#include "CInputStreamFilter.h"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CInputStreamFilter
|
// CInputStreamFilter
|
||||||
//
|
//
|
||||||
|
|
||||||
CInputStreamFilter::CInputStreamFilter(IInputStream* stream, bool adopted) :
|
CInputStreamFilter::CInputStreamFilter(
|
||||||
m_stream(stream),
|
IInputStream* stream,
|
||||||
m_adopted(adopted)
|
bool adopted) :
|
||||||
|
m_stream(stream),
|
||||||
|
m_adopted(adopted)
|
||||||
{
|
{
|
||||||
assert(m_stream != NULL);
|
assert(m_stream != NULL);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +20,8 @@ CInputStreamFilter::~CInputStreamFilter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IInputStream* CInputStreamFilter::getStream() const
|
IInputStream*
|
||||||
|
CInputStreamFilter::getStream() const
|
||||||
{
|
{
|
||||||
return m_stream;
|
return m_stream;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
#include "COutputStreamFilter.h"
|
#include "COutputStreamFilter.h"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// COutputStreamFilter
|
// COutputStreamFilter
|
||||||
//
|
//
|
||||||
|
|
||||||
COutputStreamFilter::COutputStreamFilter(IOutputStream* stream, bool adopted) :
|
COutputStreamFilter::COutputStreamFilter(
|
||||||
m_stream(stream),
|
IOutputStream* stream,
|
||||||
m_adopted(adopted)
|
bool adopted) :
|
||||||
|
m_stream(stream),
|
||||||
|
m_adopted(adopted)
|
||||||
{
|
{
|
||||||
assert(m_stream != NULL);
|
assert(m_stream != NULL);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +20,8 @@ COutputStreamFilter::~COutputStreamFilter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputStream* COutputStreamFilter::getStream() const
|
IOutputStream*
|
||||||
|
COutputStreamFilter::getStream() const
|
||||||
{
|
{
|
||||||
return m_stream;
|
return m_stream;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "CStreamBuffer.h"
|
#include "CStreamBuffer.h"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CStreamBuffer
|
// CStreamBuffer
|
||||||
|
@ -7,7 +6,8 @@
|
||||||
|
|
||||||
const UInt32 CStreamBuffer::kChunkSize = 4096;
|
const UInt32 CStreamBuffer::kChunkSize = 4096;
|
||||||
|
|
||||||
CStreamBuffer::CStreamBuffer() : m_size(0)
|
CStreamBuffer::CStreamBuffer() :
|
||||||
|
m_size(0)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,9 @@ CStreamBuffer::~CStreamBuffer()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
const void* CStreamBuffer::peek(UInt32 n)
|
const void*
|
||||||
|
CStreamBuffer::peek(
|
||||||
|
UInt32 n)
|
||||||
{
|
{
|
||||||
assert(n <= m_size);
|
assert(n <= m_size);
|
||||||
|
|
||||||
|
@ -36,7 +38,9 @@ const void* CStreamBuffer::peek(UInt32 n)
|
||||||
return reinterpret_cast<const void*>(head->begin());
|
return reinterpret_cast<const void*>(head->begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CStreamBuffer::pop(UInt32 n)
|
void
|
||||||
|
CStreamBuffer::pop(
|
||||||
|
UInt32 n)
|
||||||
{
|
{
|
||||||
// discard all chunks if n is greater than or equal to m_size
|
// discard all chunks if n is greater than or equal to m_size
|
||||||
if (n >= m_size) {
|
if (n >= m_size) {
|
||||||
|
@ -63,8 +67,10 @@ void CStreamBuffer::pop(UInt32 n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CStreamBuffer::write(
|
void
|
||||||
const void* vdata, UInt32 n)
|
CStreamBuffer::write(
|
||||||
|
const void* vdata,
|
||||||
|
UInt32 n)
|
||||||
{
|
{
|
||||||
assert(vdata != NULL);
|
assert(vdata != NULL);
|
||||||
|
|
||||||
|
@ -81,8 +87,9 @@ void CStreamBuffer::write(
|
||||||
ChunkList::iterator scan = m_chunks.end();
|
ChunkList::iterator scan = m_chunks.end();
|
||||||
if (scan != m_chunks.begin()) {
|
if (scan != m_chunks.begin()) {
|
||||||
--scan;
|
--scan;
|
||||||
if (scan->size() >= kChunkSize)
|
if (scan->size() >= kChunkSize) {
|
||||||
++scan;
|
++scan;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (scan == m_chunks.end()) {
|
if (scan == m_chunks.end()) {
|
||||||
scan = m_chunks.insert(scan, Chunk());
|
scan = m_chunks.insert(scan, Chunk());
|
||||||
|
@ -109,7 +116,8 @@ void CStreamBuffer::write(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CStreamBuffer::getSize() const
|
UInt32
|
||||||
|
CStreamBuffer::getSize() const
|
||||||
{
|
{
|
||||||
return m_size;
|
return m_size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "IInterface.h"
|
#include "IInterface.h"
|
||||||
#include "BasicTypes.h"
|
#include "BasicTypes.h"
|
||||||
#include "XIO.h"
|
|
||||||
|
|
||||||
class IInputStream : public IInterface {
|
class IInputStream : public IInterface {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "IInterface.h"
|
#include "IInterface.h"
|
||||||
#include "BasicTypes.h"
|
#include "BasicTypes.h"
|
||||||
#include "XIO.h"
|
|
||||||
|
|
||||||
class IOutputStream : public IInterface {
|
class IOutputStream : public IInterface {
|
||||||
public:
|
public:
|
||||||
|
|
16
io/XIO.cpp
16
io/XIO.cpp
|
@ -4,12 +4,14 @@
|
||||||
// XIOErrno
|
// XIOErrno
|
||||||
//
|
//
|
||||||
|
|
||||||
XIOErrno::XIOErrno() : MXErrno()
|
XIOErrno::XIOErrno() :
|
||||||
|
MXErrno()
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
XIOErrno::XIOErrno(int err) : MXErrno(err)
|
XIOErrno::XIOErrno(int err) :
|
||||||
|
MXErrno(err)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -19,7 +21,8 @@ XIOErrno::XIOErrno(int err) : MXErrno(err)
|
||||||
// XIOClose
|
// XIOClose
|
||||||
//
|
//
|
||||||
|
|
||||||
CString XIOClose::getWhat() const throw()
|
CString
|
||||||
|
XIOClose::getWhat() const throw()
|
||||||
{
|
{
|
||||||
return format("XIOClose", "close: %1", XIOErrno::getErrstr());
|
return format("XIOClose", "close: %1", XIOErrno::getErrstr());
|
||||||
}
|
}
|
||||||
|
@ -29,7 +32,8 @@ CString XIOClose::getWhat() const throw()
|
||||||
// XIOClosed
|
// XIOClosed
|
||||||
//
|
//
|
||||||
|
|
||||||
CString XIOClosed::getWhat() const throw()
|
CString
|
||||||
|
XIOClosed::getWhat() const throw()
|
||||||
{
|
{
|
||||||
return format("XIOClosed", "already closed");
|
return format("XIOClosed", "already closed");
|
||||||
}
|
}
|
||||||
|
@ -39,8 +43,8 @@ CString XIOClosed::getWhat() const throw()
|
||||||
// XIOEndOfStream
|
// XIOEndOfStream
|
||||||
//
|
//
|
||||||
|
|
||||||
CString XIOEndOfStream::getWhat() const throw()
|
CString
|
||||||
|
XIOEndOfStream::getWhat() const throw()
|
||||||
{
|
{
|
||||||
return format("XIOEndOfStream", "reached end of stream");
|
return format("XIOEndOfStream", "reached end of stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
io/XIO.h
1
io/XIO.h
|
@ -2,7 +2,6 @@
|
||||||
#define XIO_H
|
#define XIO_H
|
||||||
|
|
||||||
#include "XBase.h"
|
#include "XBase.h"
|
||||||
#include "BasicTypes.h"
|
|
||||||
|
|
||||||
class XIO : public XBase { };
|
class XIO : public XBase { };
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
#include "CCondVar.h"
|
#include "CCondVar.h"
|
||||||
#include "CStopwatch.h"
|
#include "CStopwatch.h"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CCondVarBase
|
// CCondVarBase
|
||||||
//
|
//
|
||||||
|
|
||||||
CCondVarBase::CCondVarBase(CMutex* mutex) :
|
CCondVarBase::CCondVarBase(CMutex* mutex) :
|
||||||
m_mutex(mutex)
|
m_mutex(mutex)
|
||||||
#if defined(CONFIG_PLATFORM_WIN32)
|
#if defined(CONFIG_PLATFORM_WIN32)
|
||||||
, m_waitCountMutex()
|
, m_waitCountMutex()
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
assert(m_mutex != NULL);
|
assert(m_mutex != NULL);
|
||||||
|
@ -21,23 +20,27 @@ CCondVarBase::~CCondVarBase()
|
||||||
fini();
|
fini();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCondVarBase::lock() const
|
void
|
||||||
|
CCondVarBase::lock() const
|
||||||
{
|
{
|
||||||
m_mutex->lock();
|
m_mutex->lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCondVarBase::unlock() const
|
void
|
||||||
|
CCondVarBase::unlock() const
|
||||||
{
|
{
|
||||||
m_mutex->unlock();
|
m_mutex->unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCondVarBase::wait(double timeout) const
|
bool
|
||||||
|
CCondVarBase::wait(double timeout) const
|
||||||
{
|
{
|
||||||
CStopwatch timer(true);
|
CStopwatch timer(true);
|
||||||
return wait(timer, timeout);
|
return wait(timer, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMutex* CCondVarBase::getMutex() const
|
CMutex*
|
||||||
|
CCondVarBase::getMutex() const
|
||||||
{
|
{
|
||||||
return m_mutex;
|
return m_mutex;
|
||||||
}
|
}
|
||||||
|
@ -47,9 +50,10 @@ CMutex* CCondVarBase::getMutex() const
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <errno.h>
|
#include <cerrno>
|
||||||
|
|
||||||
void CCondVarBase::init()
|
void
|
||||||
|
CCondVarBase::init()
|
||||||
{
|
{
|
||||||
pthread_cond_t* cond = new pthread_cond_t;
|
pthread_cond_t* cond = new pthread_cond_t;
|
||||||
int status = pthread_cond_init(cond, NULL);
|
int status = pthread_cond_init(cond, NULL);
|
||||||
|
@ -57,7 +61,8 @@ void CCondVarBase::init()
|
||||||
m_cond = reinterpret_cast<pthread_cond_t*>(cond);
|
m_cond = reinterpret_cast<pthread_cond_t*>(cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCondVarBase::fini()
|
void
|
||||||
|
CCondVarBase::fini()
|
||||||
{
|
{
|
||||||
pthread_cond_t* cond = reinterpret_cast<pthread_cond_t*>(m_cond);
|
pthread_cond_t* cond = reinterpret_cast<pthread_cond_t*>(m_cond);
|
||||||
int status = pthread_cond_destroy(cond);
|
int status = pthread_cond_destroy(cond);
|
||||||
|
@ -65,22 +70,26 @@ void CCondVarBase::fini()
|
||||||
delete cond;
|
delete cond;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCondVarBase::signal()
|
void
|
||||||
|
CCondVarBase::signal()
|
||||||
{
|
{
|
||||||
pthread_cond_t* cond = reinterpret_cast<pthread_cond_t*>(m_cond);
|
pthread_cond_t* cond = reinterpret_cast<pthread_cond_t*>(m_cond);
|
||||||
int status = pthread_cond_signal(cond);
|
int status = pthread_cond_signal(cond);
|
||||||
assert(status == 0);
|
assert(status == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCondVarBase::broadcast()
|
void
|
||||||
|
CCondVarBase::broadcast()
|
||||||
{
|
{
|
||||||
pthread_cond_t* cond = reinterpret_cast<pthread_cond_t*>(m_cond);
|
pthread_cond_t* cond = reinterpret_cast<pthread_cond_t*>(m_cond);
|
||||||
int status = pthread_cond_broadcast(cond);
|
int status = pthread_cond_broadcast(cond);
|
||||||
assert(status == 0);
|
assert(status == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCondVarBase::wait(
|
bool
|
||||||
CStopwatch& timer, double timeout) const
|
CCondVarBase::wait(
|
||||||
|
CStopwatch& timer,
|
||||||
|
double timeout) const
|
||||||
{
|
{
|
||||||
// check timeout against timer
|
// check timeout against timer
|
||||||
if (timeout >= 0.0) {
|
if (timeout >= 0.0) {
|
||||||
|
@ -143,8 +152,9 @@ bool CCondVarBase::wait(
|
||||||
CThread::testCancel();
|
CThread::testCancel();
|
||||||
|
|
||||||
// check wait status
|
// check wait status
|
||||||
if (status != ETIMEDOUT && status != EINTR)
|
if (status != ETIMEDOUT && status != EINTR) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
|
@ -180,7 +190,8 @@ bool CCondVarBase::wait(
|
||||||
// can cause busy waiting.
|
// can cause busy waiting.
|
||||||
//
|
//
|
||||||
|
|
||||||
void CCondVarBase::init()
|
void
|
||||||
|
CCondVarBase::init()
|
||||||
{
|
{
|
||||||
// prepare events
|
// prepare events
|
||||||
HANDLE* events = new HANDLE[2];
|
HANDLE* events = new HANDLE[2];
|
||||||
|
@ -192,7 +203,8 @@ void CCondVarBase::init()
|
||||||
m_waitCount = 0;
|
m_waitCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCondVarBase::fini()
|
void
|
||||||
|
CCondVarBase::fini()
|
||||||
{
|
{
|
||||||
HANDLE* events = reinterpret_cast<HANDLE*>(m_cond);
|
HANDLE* events = reinterpret_cast<HANDLE*>(m_cond);
|
||||||
CloseHandle(events[kSignal]);
|
CloseHandle(events[kSignal]);
|
||||||
|
@ -200,7 +212,8 @@ void CCondVarBase::fini()
|
||||||
delete[] events;
|
delete[] events;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCondVarBase::signal()
|
void
|
||||||
|
CCondVarBase::signal()
|
||||||
{
|
{
|
||||||
// is anybody waiting?
|
// is anybody waiting?
|
||||||
bool hasWaiter;
|
bool hasWaiter;
|
||||||
|
@ -210,11 +223,13 @@ void CCondVarBase::signal()
|
||||||
}
|
}
|
||||||
|
|
||||||
// wake one thread if anybody is waiting
|
// wake one thread if anybody is waiting
|
||||||
if (hasWaiter)
|
if (hasWaiter) {
|
||||||
SetEvent(reinterpret_cast<HANDLE*>(m_cond)[kSignal]);
|
SetEvent(reinterpret_cast<HANDLE*>(m_cond)[kSignal]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCondVarBase::broadcast()
|
void
|
||||||
|
CCondVarBase::broadcast()
|
||||||
{
|
{
|
||||||
// is anybody waiting?
|
// is anybody waiting?
|
||||||
bool hasWaiter;
|
bool hasWaiter;
|
||||||
|
@ -224,18 +239,22 @@ void CCondVarBase::broadcast()
|
||||||
}
|
}
|
||||||
|
|
||||||
// wake all threads if anybody is waiting
|
// wake all threads if anybody is waiting
|
||||||
if (hasWaiter)
|
if (hasWaiter) {
|
||||||
SetEvent(reinterpret_cast<HANDLE*>(m_cond)[kBroadcast]);
|
SetEvent(reinterpret_cast<HANDLE*>(m_cond)[kBroadcast]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCondVarBase::wait(
|
bool
|
||||||
CStopwatch& timer, double timeout) const
|
CCondVarBase::wait(
|
||||||
|
CStopwatch& timer,
|
||||||
|
double timeout) const
|
||||||
{
|
{
|
||||||
// check timeout against timer
|
// check timeout against timer
|
||||||
if (timeout >= 0.0) {
|
if (timeout >= 0.0) {
|
||||||
timeout -= timer.getTime();
|
timeout -= timer.getTime();
|
||||||
if (timeout < 0.0)
|
if (timeout < 0.0) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare to wait
|
// prepare to wait
|
||||||
|
@ -267,8 +286,9 @@ bool CCondVarBase::wait(
|
||||||
|
|
||||||
// cancel takes priority
|
// cancel takes priority
|
||||||
if (n == 3 && result != WAIT_OBJECT_0 + 2 &&
|
if (n == 3 && result != WAIT_OBJECT_0 + 2 &&
|
||||||
WaitForSingleObject(handles[2], 0) == WAIT_OBJECT_0)
|
WaitForSingleObject(handles[2], 0) == WAIT_OBJECT_0) {
|
||||||
result = WAIT_OBJECT_0 + 2;
|
result = WAIT_OBJECT_0 + 2;
|
||||||
|
}
|
||||||
|
|
||||||
// update the waiter count and check if we're the last waiter
|
// update the waiter count and check if we're the last waiter
|
||||||
bool last;
|
bool last;
|
||||||
|
@ -279,15 +299,17 @@ bool CCondVarBase::wait(
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset the broadcast event if we're the last waiter
|
// reset the broadcast event if we're the last waiter
|
||||||
if (last)
|
if (last) {
|
||||||
ResetEvent(events[kBroadcast]);
|
ResetEvent(events[kBroadcast]);
|
||||||
|
}
|
||||||
|
|
||||||
// reacquire the mutex
|
// reacquire the mutex
|
||||||
m_mutex->lock();
|
m_mutex->lock();
|
||||||
|
|
||||||
// cancel thread if necessary
|
// cancel thread if necessary
|
||||||
if (result == WAIT_OBJECT_0 + 2)
|
if (result == WAIT_OBJECT_0 + 2) {
|
||||||
currentRep->testCancel();
|
currentRep->testCancel();
|
||||||
|
}
|
||||||
|
|
||||||
// return success or failure
|
// return success or failure
|
||||||
return (result == WAIT_OBJECT_0 + 0 ||
|
return (result == WAIT_OBJECT_0 + 0 ||
|
||||||
|
|
|
@ -90,17 +90,21 @@ private:
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline
|
inline
|
||||||
CCondVar<T>::CCondVar(CMutex* mutex, const T& data) :
|
CCondVar<T>::CCondVar(
|
||||||
CCondVarBase(mutex), m_data(data)
|
CMutex* mutex,
|
||||||
|
const T& data) :
|
||||||
|
CCondVarBase(mutex),
|
||||||
|
m_data(data)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline
|
inline
|
||||||
CCondVar<T>::CCondVar(const CCondVar& cv) :
|
CCondVar<T>::CCondVar(
|
||||||
CCondVarBase(cv.getMutex()),
|
const CCondVar& cv) :
|
||||||
m_data(cv.m_data)
|
CCondVarBase(cv.getMutex()),
|
||||||
|
m_data(cv.m_data)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -114,7 +118,9 @@ CCondVar<T>::~CCondVar()
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline
|
inline
|
||||||
CCondVar<T>& CCondVar<T>::operator=(const CCondVar<T>& cv)
|
CCondVar<T>&
|
||||||
|
CCondVar<T>::operator=(
|
||||||
|
const CCondVar<T>& cv)
|
||||||
{
|
{
|
||||||
m_data = cv.m_data;
|
m_data = cv.m_data;
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -122,7 +128,9 @@ CCondVar<T>& CCondVar<T>::operator=(const CCondVar<T>& cv)
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline
|
inline
|
||||||
CCondVar<T>& CCondVar<T>::operator=(const T& data)
|
CCondVar<T>&
|
||||||
|
CCondVar<T>::operator=(
|
||||||
|
const T& data)
|
||||||
{
|
{
|
||||||
m_data = data;
|
m_data = data;
|
||||||
return *this;
|
return *this;
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
#include "CLock.h"
|
#include "CLock.h"
|
||||||
#include "CMutex.h"
|
|
||||||
#include "CCondVar.h"
|
#include "CCondVar.h"
|
||||||
|
#include "CMutex.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// CLock
|
// CLock
|
||||||
//
|
//
|
||||||
|
|
||||||
CLock::CLock(const CMutex* mutex) : m_mutex(mutex)
|
CLock::CLock(const CMutex* mutex) :
|
||||||
|
m_mutex(mutex)
|
||||||
{
|
{
|
||||||
m_mutex->lock();
|
m_mutex->lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
CLock::CLock(const CCondVarBase* cv) : m_mutex(cv->getMutex())
|
CLock::CLock(const CCondVarBase* cv) :
|
||||||
|
m_mutex(cv->getMutex())
|
||||||
{
|
{
|
||||||
m_mutex->lock();
|
m_mutex->lock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#ifndef CLOCK_H
|
#ifndef CLOCK_H
|
||||||
#define CLOCK_H
|
#define CLOCK_H
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
class CMutex;
|
class CMutex;
|
||||||
class CCondVarBase;
|
class CCondVarBase;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "CMutex.h"
|
#include "CMutex.h"
|
||||||
#include "CLog.h"
|
#include "CLog.h"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CMutex
|
// CMutex
|
||||||
|
@ -21,7 +20,9 @@ CMutex::~CMutex()
|
||||||
fini();
|
fini();
|
||||||
}
|
}
|
||||||
|
|
||||||
CMutex& CMutex::operator=(const CMutex&)
|
CMutex&
|
||||||
|
CMutex::operator=(
|
||||||
|
const CMutex&)
|
||||||
{
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -29,9 +30,10 @@ CMutex& CMutex::operator=(const CMutex&)
|
||||||
#if defined(CONFIG_PTHREADS)
|
#if defined(CONFIG_PTHREADS)
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <errno.h>
|
#include <cerrno>
|
||||||
|
|
||||||
void CMutex::init()
|
void
|
||||||
|
CMutex::init()
|
||||||
{
|
{
|
||||||
pthread_mutex_t* mutex = new pthread_mutex_t;
|
pthread_mutex_t* mutex = new pthread_mutex_t;
|
||||||
int status = pthread_mutex_init(mutex, NULL);
|
int status = pthread_mutex_init(mutex, NULL);
|
||||||
|
@ -41,11 +43,8 @@ void CMutex::init()
|
||||||
m_mutex = reinterpret_cast<void*>(mutex);
|
m_mutex = reinterpret_cast<void*>(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <stdlib.h>
|
void
|
||||||
#include <unistd.h>
|
CMutex::fini()
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
void CMutex::fini()
|
|
||||||
{
|
{
|
||||||
pthread_mutex_t* mutex = reinterpret_cast<pthread_mutex_t*>(m_mutex);
|
pthread_mutex_t* mutex = reinterpret_cast<pthread_mutex_t*>(m_mutex);
|
||||||
int status = pthread_mutex_destroy(mutex);
|
int status = pthread_mutex_destroy(mutex);
|
||||||
|
@ -54,7 +53,8 @@ void CMutex::fini()
|
||||||
delete mutex;
|
delete mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMutex::lock() const
|
void
|
||||||
|
CMutex::lock() const
|
||||||
{
|
{
|
||||||
pthread_mutex_t* mutex = reinterpret_cast<pthread_mutex_t*>(m_mutex);
|
pthread_mutex_t* mutex = reinterpret_cast<pthread_mutex_t*>(m_mutex);
|
||||||
int status = pthread_mutex_lock(mutex);
|
int status = pthread_mutex_lock(mutex);
|
||||||
|
@ -78,7 +78,8 @@ void CMutex::lock() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMutex::unlock() const
|
void
|
||||||
|
CMutex::unlock() const
|
||||||
{
|
{
|
||||||
pthread_mutex_t* mutex = reinterpret_cast<pthread_mutex_t*>(m_mutex);
|
pthread_mutex_t* mutex = reinterpret_cast<pthread_mutex_t*>(m_mutex);
|
||||||
int status = pthread_mutex_unlock(mutex);
|
int status = pthread_mutex_unlock(mutex);
|
||||||
|
@ -105,26 +106,30 @@ void CMutex::unlock() const
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
void CMutex::init()
|
void
|
||||||
|
CMutex::init()
|
||||||
{
|
{
|
||||||
CRITICAL_SECTION* mutex = new CRITICAL_SECTION;
|
CRITICAL_SECTION* mutex = new CRITICAL_SECTION;
|
||||||
InitializeCriticalSection(mutex);
|
InitializeCriticalSection(mutex);
|
||||||
m_mutex = reinterpret_cast<void*>(mutex);
|
m_mutex = reinterpret_cast<void*>(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMutex::fini()
|
void
|
||||||
|
CMutex::fini()
|
||||||
{
|
{
|
||||||
CRITICAL_SECTION* mutex = reinterpret_cast<CRITICAL_SECTION*>(m_mutex);
|
CRITICAL_SECTION* mutex = reinterpret_cast<CRITICAL_SECTION*>(m_mutex);
|
||||||
DeleteCriticalSection(mutex);
|
DeleteCriticalSection(mutex);
|
||||||
delete mutex;
|
delete mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMutex::lock() const
|
void
|
||||||
|
CMutex::lock() const
|
||||||
{
|
{
|
||||||
EnterCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(m_mutex));
|
EnterCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(m_mutex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMutex::unlock() const
|
void
|
||||||
|
CMutex::unlock() const
|
||||||
{
|
{
|
||||||
LeaveCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(m_mutex));
|
LeaveCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(m_mutex));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#ifndef CMUTEX_H
|
#ifndef CMUTEX_H
|
||||||
#define CMUTEX_H
|
#define CMUTEX_H
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
// recursive mutex class
|
// recursive mutex class
|
||||||
class CMutex {
|
class CMutex {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
|
#include "CLock.h"
|
||||||
#include "CThreadRep.h"
|
#include "CThreadRep.h"
|
||||||
#include "XThread.h"
|
#include "XThread.h"
|
||||||
#include "CLock.h"
|
|
||||||
#include "CStopwatch.h"
|
|
||||||
#include "CLog.h"
|
#include "CLog.h"
|
||||||
|
#include "CStopwatch.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// CThread
|
// CThread
|
||||||
|
@ -14,12 +14,14 @@ CThread::CThread(IJob* job, void* userData)
|
||||||
m_rep = new CThreadRep(job, userData);
|
m_rep = new CThreadRep(job, userData);
|
||||||
}
|
}
|
||||||
|
|
||||||
CThread::CThread(const CThread& thread) : m_rep(thread.m_rep)
|
CThread::CThread(const CThread& thread) :
|
||||||
|
m_rep(thread.m_rep)
|
||||||
{
|
{
|
||||||
m_rep->ref();
|
m_rep->ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
CThread::CThread(CThreadRep* rep) : m_rep(rep)
|
CThread::CThread(CThreadRep* rep) :
|
||||||
|
m_rep(rep)
|
||||||
{
|
{
|
||||||
// do nothing. rep should have already been Ref()'d.
|
// do nothing. rep should have already been Ref()'d.
|
||||||
}
|
}
|
||||||
|
@ -29,7 +31,9 @@ CThread::~CThread()
|
||||||
m_rep->unref();
|
m_rep->unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
CThread& CThread::operator=(const CThread& thread)
|
CThread&
|
||||||
|
CThread::operator=(
|
||||||
|
const CThread& thread)
|
||||||
{
|
{
|
||||||
if (thread.m_rep != m_rep) {
|
if (thread.m_rep != m_rep) {
|
||||||
m_rep->unref();
|
m_rep->unref();
|
||||||
|
@ -39,12 +43,15 @@ CThread& CThread::operator=(const CThread& thread)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThread::init()
|
void
|
||||||
|
CThread::init()
|
||||||
{
|
{
|
||||||
CThreadRep::initThreads();
|
CThreadRep::initThreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThread::sleep(double timeout)
|
void
|
||||||
|
CThread::sleep(
|
||||||
|
double timeout)
|
||||||
{
|
{
|
||||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||||
if (timeout >= 0.0) {
|
if (timeout >= 0.0) {
|
||||||
|
@ -54,47 +61,59 @@ void CThread::sleep(double timeout)
|
||||||
currentRep->testCancel();
|
currentRep->testCancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThread::exit(void* result)
|
void
|
||||||
|
CThread::exit(
|
||||||
|
void* result)
|
||||||
{
|
{
|
||||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||||
log((CLOG_DEBUG1 "throw exit on thread %p", currentRep.operator->()));
|
log((CLOG_DEBUG1 "throw exit on thread %p", currentRep.operator->()));
|
||||||
throw XThreadExit(result);
|
throw XThreadExit(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CThread::enableCancel(bool enable)
|
bool
|
||||||
|
CThread::enableCancel(
|
||||||
|
bool enable)
|
||||||
{
|
{
|
||||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||||
return currentRep->enableCancel(enable);
|
return currentRep->enableCancel(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThread::cancel()
|
void
|
||||||
|
CThread::cancel()
|
||||||
{
|
{
|
||||||
m_rep->cancel();
|
m_rep->cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThread::setPriority(int n)
|
void
|
||||||
|
CThread::setPriority(
|
||||||
|
int n)
|
||||||
{
|
{
|
||||||
m_rep->setPriority(n);
|
m_rep->setPriority(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
CThread CThread::getCurrentThread()
|
CThread
|
||||||
|
CThread::getCurrentThread()
|
||||||
{
|
{
|
||||||
return CThread(CThreadRep::getCurrentThreadRep());
|
return CThread(CThreadRep::getCurrentThreadRep());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CThread::wait(double timeout) const
|
bool
|
||||||
|
CThread::wait(
|
||||||
|
double timeout) const
|
||||||
{
|
{
|
||||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||||
return currentRep->wait(m_rep, timeout);
|
return currentRep->wait(m_rep, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThread::testCancel()
|
void
|
||||||
|
CThread::testCancel()
|
||||||
{
|
{
|
||||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||||
currentRep->testCancel();
|
currentRep->testCancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void* CThread::getResult() const
|
void*
|
||||||
|
CThread::getResult() const
|
||||||
{
|
{
|
||||||
if (wait())
|
if (wait())
|
||||||
return m_rep->getResult();
|
return m_rep->getResult();
|
||||||
|
@ -102,18 +121,23 @@ void* CThread::getResult() const
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* CThread::getUserData()
|
void*
|
||||||
|
CThread::getUserData()
|
||||||
{
|
{
|
||||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||||
return currentRep->getUserData();
|
return currentRep->getUserData();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CThread::operator==(const CThread& thread) const
|
bool
|
||||||
|
CThread::operator==(
|
||||||
|
const CThread& thread) const
|
||||||
{
|
{
|
||||||
return (m_rep == thread.m_rep);
|
return (m_rep == thread.m_rep);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CThread::operator!=(const CThread& thread) const
|
bool
|
||||||
|
CThread::operator!=(
|
||||||
|
const CThread& thread) const
|
||||||
{
|
{
|
||||||
return (m_rep != thread.m_rep);
|
return (m_rep != thread.m_rep);
|
||||||
}
|
}
|
||||||
|
@ -123,7 +147,8 @@ bool CThread::operator!=(const CThread& thread) const
|
||||||
// CThreadMaskCancel
|
// CThreadMaskCancel
|
||||||
//
|
//
|
||||||
|
|
||||||
CThreadMaskCancel::CThreadMaskCancel() : m_old(CThread::enableCancel(false))
|
CThreadMaskCancel::CThreadMaskCancel() :
|
||||||
|
m_old(CThread::enableCancel(false))
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#ifndef CTHREAD_H
|
#ifndef CTHREAD_H
|
||||||
#define CTHREAD_H
|
#define CTHREAD_H
|
||||||
|
|
||||||
#include "BasicTypes.h"
|
|
||||||
|
|
||||||
class IJob;
|
class IJob;
|
||||||
class CThreadRep;
|
class CThreadRep;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
#include "CThreadRep.h"
|
#include "CThreadRep.h"
|
||||||
#include "CThread.h"
|
|
||||||
#include "CMutex.h"
|
|
||||||
#include "CLock.h"
|
#include "CLock.h"
|
||||||
|
#include "CMutex.h"
|
||||||
|
#include "CThread.h"
|
||||||
#include "XThread.h"
|
#include "XThread.h"
|
||||||
#include "CLog.h"
|
#include "CLog.h"
|
||||||
#include "IJob.h"
|
#include "IJob.h"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#if defined(CONFIG_PTHREADS)
|
#if defined(CONFIG_PTHREADS)
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -23,7 +22,7 @@
|
||||||
class XThreadUnavailable { };
|
class XThreadUnavailable { };
|
||||||
|
|
||||||
#if defined(CONFIG_PLATFORM_UNIX) && !defined(NDEBUG)
|
#if defined(CONFIG_PLATFORM_UNIX) && !defined(NDEBUG)
|
||||||
#include <stdlib.h>
|
#include <cstdlib>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
@ -44,11 +43,12 @@ CThreadRep* CThreadRep::s_head = NULL;
|
||||||
pthread_t CThreadRep::s_signalThread;
|
pthread_t CThreadRep::s_signalThread;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CThreadRep::CThreadRep() : m_prev(NULL),
|
CThreadRep::CThreadRep() :
|
||||||
m_next(NULL),
|
m_prev(NULL),
|
||||||
m_refCount(1),
|
m_next(NULL),
|
||||||
m_job(NULL),
|
m_refCount(1),
|
||||||
m_userData(NULL)
|
m_job(NULL),
|
||||||
|
m_userData(NULL)
|
||||||
{
|
{
|
||||||
// note -- s_mutex must be locked on entry
|
// note -- s_mutex must be locked on entry
|
||||||
assert(s_mutex != NULL);
|
assert(s_mutex != NULL);
|
||||||
|
@ -73,11 +73,11 @@ CThreadRep::CThreadRep() : m_prev(NULL),
|
||||||
}
|
}
|
||||||
|
|
||||||
CThreadRep::CThreadRep(IJob* job, void* userData) :
|
CThreadRep::CThreadRep(IJob* job, void* userData) :
|
||||||
m_prev(NULL),
|
m_prev(NULL),
|
||||||
m_next(NULL),
|
m_next(NULL),
|
||||||
m_refCount(2), // 1 for us, 1 for thread
|
m_refCount(2), // 1 for us, 1 for thread
|
||||||
m_job(job),
|
m_job(job),
|
||||||
m_userData(userData)
|
m_userData(userData)
|
||||||
{
|
{
|
||||||
assert(m_job != NULL);
|
assert(m_job != NULL);
|
||||||
assert(s_mutex != NULL);
|
assert(s_mutex != NULL);
|
||||||
|
@ -103,15 +103,17 @@ CThreadRep::CThreadRep(IJob* job, void* userData) :
|
||||||
pthread_sigmask(SIG_BLOCK, &sigset, &oldsigset);
|
pthread_sigmask(SIG_BLOCK, &sigset, &oldsigset);
|
||||||
int status = pthread_create(&m_thread, NULL, threadFunc, (void*)this);
|
int status = pthread_create(&m_thread, NULL, threadFunc, (void*)this);
|
||||||
pthread_sigmask(SIG_SETMASK, &oldsigset, NULL);
|
pthread_sigmask(SIG_SETMASK, &oldsigset, NULL);
|
||||||
if (status != 0)
|
if (status != 0) {
|
||||||
throw XThreadUnavailable();
|
throw XThreadUnavailable();
|
||||||
|
}
|
||||||
#elif defined(CONFIG_PLATFORM_WIN32)
|
#elif defined(CONFIG_PLATFORM_WIN32)
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
m_thread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0,
|
m_thread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0,
|
||||||
threadFunc, (void*)this, 0, &id));
|
threadFunc, (void*)this, 0, &id));
|
||||||
m_id = static_cast<DWORD>(id);
|
m_id = static_cast<DWORD>(id);
|
||||||
if (m_thread == 0)
|
if (m_thread == 0) {
|
||||||
throw XThreadUnavailable();
|
throw XThreadUnavailable();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// insert ourself into linked list
|
// insert ourself into linked list
|
||||||
|
@ -143,7 +145,8 @@ CThreadRep::~CThreadRep()
|
||||||
fini();
|
fini();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::initThreads()
|
void
|
||||||
|
CThreadRep::initThreads()
|
||||||
{
|
{
|
||||||
if (s_mutex == NULL) {
|
if (s_mutex == NULL) {
|
||||||
s_mutex = new CMutex;
|
s_mutex = new CMutex;
|
||||||
|
@ -197,13 +200,15 @@ void CThreadRep::initThreads()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::ref()
|
void
|
||||||
|
CThreadRep::ref()
|
||||||
{
|
{
|
||||||
CLock lock(s_mutex);
|
CLock lock(s_mutex);
|
||||||
++m_refCount;
|
++m_refCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::unref()
|
void
|
||||||
|
CThreadRep::unref()
|
||||||
{
|
{
|
||||||
CLock lock(s_mutex);
|
CLock lock(s_mutex);
|
||||||
if (--m_refCount == 0) {
|
if (--m_refCount == 0) {
|
||||||
|
@ -211,7 +216,8 @@ void CThreadRep::unref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CThreadRep::enableCancel(bool enable)
|
bool
|
||||||
|
CThreadRep::enableCancel(bool enable)
|
||||||
{
|
{
|
||||||
CLock lock(s_mutex);
|
CLock lock(s_mutex);
|
||||||
const bool old = m_cancellable;
|
const bool old = m_cancellable;
|
||||||
|
@ -219,25 +225,29 @@ bool CThreadRep::enableCancel(bool enable)
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CThreadRep::isCancellable() const
|
bool
|
||||||
|
CThreadRep::isCancellable() const
|
||||||
{
|
{
|
||||||
CLock lock(s_mutex);
|
CLock lock(s_mutex);
|
||||||
return (m_cancellable && !m_cancelling);
|
return (m_cancellable && !m_cancelling);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* CThreadRep::getResult() const
|
void*
|
||||||
|
CThreadRep::getResult() const
|
||||||
{
|
{
|
||||||
// no lock necessary since thread isn't running
|
// no lock necessary since thread isn't running
|
||||||
return m_result;
|
return m_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* CThreadRep::getUserData() const
|
void*
|
||||||
|
CThreadRep::getUserData() const
|
||||||
{
|
{
|
||||||
// no lock necessary because the value never changes
|
// no lock necessary because the value never changes
|
||||||
return m_userData;
|
return m_userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
CThreadRep* CThreadRep::getCurrentThreadRep()
|
CThreadRep*
|
||||||
|
CThreadRep::getCurrentThreadRep()
|
||||||
{
|
{
|
||||||
assert(s_mutex != NULL);
|
assert(s_mutex != NULL);
|
||||||
|
|
||||||
|
@ -276,7 +286,8 @@ CThreadRep* CThreadRep::getCurrentThreadRep()
|
||||||
return scan;
|
return scan;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::doThreadFunc()
|
void
|
||||||
|
CThreadRep::doThreadFunc()
|
||||||
{
|
{
|
||||||
// default priority is slightly below normal
|
// default priority is slightly below normal
|
||||||
setPriority(1);
|
setPriority(1);
|
||||||
|
@ -318,9 +329,10 @@ void CThreadRep::doThreadFunc()
|
||||||
#if defined(CONFIG_PTHREADS)
|
#if defined(CONFIG_PTHREADS)
|
||||||
|
|
||||||
#include "CStopwatch.h"
|
#include "CStopwatch.h"
|
||||||
#include <time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
void CThreadRep::init()
|
void
|
||||||
|
CThreadRep::init()
|
||||||
{
|
{
|
||||||
m_result = NULL;
|
m_result = NULL;
|
||||||
m_cancellable = true;
|
m_cancellable = true;
|
||||||
|
@ -329,7 +341,8 @@ void CThreadRep::init()
|
||||||
m_exit = false;
|
m_exit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::fini()
|
void
|
||||||
|
CThreadRep::fini()
|
||||||
{
|
{
|
||||||
// main thread has NULL job
|
// main thread has NULL job
|
||||||
if (m_job != NULL) {
|
if (m_job != NULL) {
|
||||||
|
@ -337,10 +350,13 @@ void CThreadRep::fini()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::sleep(double timeout)
|
void
|
||||||
|
CThreadRep::sleep(
|
||||||
|
double timeout)
|
||||||
{
|
{
|
||||||
if (timeout < 0.0)
|
if (timeout < 0.0) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
struct timespec t;
|
struct timespec t;
|
||||||
t.tv_sec = (long)timeout;
|
t.tv_sec = (long)timeout;
|
||||||
t.tv_nsec = (long)(1000000000.0 * (timeout - (double)t.tv_sec));
|
t.tv_nsec = (long)(1000000000.0 * (timeout - (double)t.tv_sec));
|
||||||
|
@ -348,7 +364,8 @@ void CThreadRep::sleep(double timeout)
|
||||||
testCancel();
|
testCancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::cancel()
|
void
|
||||||
|
CThreadRep::cancel()
|
||||||
{
|
{
|
||||||
CLock lock(s_mutex);
|
CLock lock(s_mutex);
|
||||||
if (m_cancellable && !m_cancelling) {
|
if (m_cancellable && !m_cancelling) {
|
||||||
|
@ -363,14 +380,16 @@ void CThreadRep::cancel()
|
||||||
pthread_kill(m_thread, SIGWAKEUP);
|
pthread_kill(m_thread, SIGWAKEUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::testCancel()
|
void
|
||||||
|
CThreadRep::testCancel()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
CLock lock(s_mutex);
|
CLock lock(s_mutex);
|
||||||
|
|
||||||
// done if not cancelled, not cancellable, or already cancelling
|
// done if not cancelled, not cancellable, or already cancelling
|
||||||
if (!m_cancel || !m_cancellable || m_cancelling)
|
if (!m_cancel || !m_cancellable || m_cancelling) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// update state for cancel
|
// update state for cancel
|
||||||
m_cancel = false;
|
m_cancel = false;
|
||||||
|
@ -382,40 +401,50 @@ void CThreadRep::testCancel()
|
||||||
throw XThreadCancel();
|
throw XThreadCancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CThreadRep::wait(CThreadRep* target, double timeout)
|
bool
|
||||||
|
CThreadRep::wait(
|
||||||
|
CThreadRep* target,
|
||||||
|
double timeout)
|
||||||
{
|
{
|
||||||
if (target == this)
|
if (target == this) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
testCancel();
|
testCancel();
|
||||||
if (target->isExited())
|
if (target->isExited()) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (timeout != 0.0) {
|
if (timeout != 0.0) {
|
||||||
CStopwatch timer;
|
CStopwatch timer;
|
||||||
do {
|
do {
|
||||||
sleep(0.05);
|
sleep(0.05);
|
||||||
testCancel();
|
testCancel();
|
||||||
if (target->isExited())
|
if (target->isExited()) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
} while (timeout < 0.0 || timer.getTime() <= timeout);
|
} while (timeout < 0.0 || timer.getTime() <= timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::setPriority(int)
|
void
|
||||||
|
CThreadRep::setPriority(
|
||||||
|
int)
|
||||||
{
|
{
|
||||||
// FIXME
|
// FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CThreadRep::isExited() const
|
bool
|
||||||
|
CThreadRep::isExited() const
|
||||||
{
|
{
|
||||||
CLock lock(s_mutex);
|
CLock lock(s_mutex);
|
||||||
return m_exit;
|
return m_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* CThreadRep::threadFunc(void* arg)
|
void*
|
||||||
|
CThreadRep::threadFunc(void* arg)
|
||||||
{
|
{
|
||||||
CThreadRep* rep = (CThreadRep*)arg;
|
CThreadRep* rep = (CThreadRep*)arg;
|
||||||
|
|
||||||
|
@ -438,12 +467,16 @@ void* CThreadRep::threadFunc(void* arg)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::threadCancel(int)
|
void
|
||||||
|
CThreadRep::threadCancel(
|
||||||
|
int)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void* CThreadRep::threadSignalHandler(void* vrep)
|
void*
|
||||||
|
CThreadRep::threadSignalHandler(
|
||||||
|
void* vrep)
|
||||||
{
|
{
|
||||||
CThreadRep* mainThreadRep = reinterpret_cast<CThreadRep*>(vrep);
|
CThreadRep* mainThreadRep = reinterpret_cast<CThreadRep*>(vrep);
|
||||||
|
|
||||||
|
@ -466,7 +499,8 @@ void* CThreadRep::threadSignalHandler(void* vrep)
|
||||||
|
|
||||||
#elif defined(CONFIG_PLATFORM_WIN32)
|
#elif defined(CONFIG_PLATFORM_WIN32)
|
||||||
|
|
||||||
void CThreadRep::init()
|
void
|
||||||
|
CThreadRep::init()
|
||||||
{
|
{
|
||||||
m_result = NULL;
|
m_result = NULL;
|
||||||
m_cancellable = true;
|
m_cancellable = true;
|
||||||
|
@ -475,7 +509,8 @@ void CThreadRep::init()
|
||||||
m_cancel = CreateEvent(NULL, TRUE, FALSE, NULL);
|
m_cancel = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::fini()
|
void
|
||||||
|
CThreadRep::fini()
|
||||||
{
|
{
|
||||||
// destroy the events
|
// destroy the events
|
||||||
CloseHandle(m_cancel);
|
CloseHandle(m_cancel);
|
||||||
|
@ -487,26 +522,33 @@ void CThreadRep::fini()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::sleep(double timeout)
|
void
|
||||||
|
CThreadRep::sleep(
|
||||||
|
double timeout)
|
||||||
{
|
{
|
||||||
if (isCancellable())
|
if (isCancellable()) {
|
||||||
WaitForSingleObject(m_cancel, (DWORD)(1000.0 * timeout));
|
WaitForSingleObject(m_cancel, (DWORD)(1000.0 * timeout));
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
Sleep((DWORD)(1000.0 * timeout));
|
Sleep((DWORD)(1000.0 * timeout));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::cancel()
|
void
|
||||||
|
CThreadRep::cancel()
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "cancel thread %p", this));
|
log((CLOG_DEBUG1 "cancel thread %p", this));
|
||||||
SetEvent(m_cancel);
|
SetEvent(m_cancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::testCancel()
|
void
|
||||||
|
CThreadRep::testCancel()
|
||||||
{
|
{
|
||||||
// poll cancel event. return if not set.
|
// poll cancel event. return if not set.
|
||||||
const DWORD result = WaitForSingleObject(getCancelEvent(), 0);
|
const DWORD result = WaitForSingleObject(getCancelEvent(), 0);
|
||||||
if (result != WAIT_OBJECT_0)
|
if (result != WAIT_OBJECT_0) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// ignore if disabled or already cancelling
|
// ignore if disabled or already cancelling
|
||||||
|
@ -524,23 +566,29 @@ void CThreadRep::testCancel()
|
||||||
throw XThreadCancel();
|
throw XThreadCancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CThreadRep::wait(CThreadRep* target, double timeout)
|
bool
|
||||||
|
CThreadRep::wait(
|
||||||
|
CThreadRep* target,
|
||||||
|
double timeout)
|
||||||
{
|
{
|
||||||
// get the current thread. if it's the same as the target thread
|
// get the current thread. if it's the same as the target thread
|
||||||
// then the thread is waiting on itself.
|
// then the thread is waiting on itself.
|
||||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||||
if (target == this)
|
if (target == this) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// is cancellation enabled?
|
// is cancellation enabled?
|
||||||
const DWORD n = (isCancellable() ? 2 : 1);
|
const DWORD n = (isCancellable() ? 2 : 1);
|
||||||
|
|
||||||
// convert timeout
|
// convert timeout
|
||||||
DWORD t;
|
DWORD t;
|
||||||
if (timeout < 0.0)
|
if (timeout < 0.0) {
|
||||||
t = INFINITE;
|
t = INFINITE;
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
t = (DWORD)(1000.0 * timeout);
|
t = (DWORD)(1000.0 * timeout);
|
||||||
|
}
|
||||||
|
|
||||||
// wait for this thread to be cancelled or for the target thread to
|
// wait for this thread to be cancelled or for the target thread to
|
||||||
// terminate.
|
// terminate.
|
||||||
|
@ -551,8 +599,9 @@ bool CThreadRep::wait(CThreadRep* target, double timeout)
|
||||||
|
|
||||||
// cancel takes priority
|
// cancel takes priority
|
||||||
if (n == 2 && result != WAIT_OBJECT_0 + 1 &&
|
if (n == 2 && result != WAIT_OBJECT_0 + 1 &&
|
||||||
WaitForSingleObject(handles[1], 0) == WAIT_OBJECT_0)
|
WaitForSingleObject(handles[1], 0) == WAIT_OBJECT_0) {
|
||||||
result = WAIT_OBJECT_0 + 1;
|
result = WAIT_OBJECT_0 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
// handle result
|
// handle result
|
||||||
switch (result) {
|
switch (result) {
|
||||||
|
@ -570,7 +619,9 @@ bool CThreadRep::wait(CThreadRep* target, double timeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadRep::setPriority(int n)
|
void
|
||||||
|
CThreadRep::setPriority(
|
||||||
|
int n)
|
||||||
{
|
{
|
||||||
DWORD pClass = NORMAL_PRIORITY_CLASS;
|
DWORD pClass = NORMAL_PRIORITY_CLASS;
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
|
@ -601,19 +652,23 @@ void CThreadRep::setPriority(int n)
|
||||||
SetThreadPriority(m_thread, n);
|
SetThreadPriority(m_thread, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE CThreadRep::getExitEvent() const
|
HANDLE
|
||||||
|
CThreadRep::getExitEvent() const
|
||||||
{
|
{
|
||||||
// no lock necessary because the value never changes
|
// no lock necessary because the value never changes
|
||||||
return m_exit;
|
return m_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE CThreadRep::getCancelEvent() const
|
HANDLE
|
||||||
|
CThreadRep::getCancelEvent() const
|
||||||
{
|
{
|
||||||
// no lock necessary because the value never changes
|
// no lock necessary because the value never changes
|
||||||
return m_cancel;
|
return m_cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int __stdcall CThreadRep::threadFunc(void* arg)
|
unsigned int __stdcall
|
||||||
|
CThreadRep::threadFunc(
|
||||||
|
void* arg)
|
||||||
{
|
{
|
||||||
CThreadRep* rep = (CThreadRep*)arg;
|
CThreadRep* rep = (CThreadRep*)arg;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
#include "TMethodJob.h"
|
#include "TMethodJob.h"
|
||||||
#include "CLog.h"
|
#include "CLog.h"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CTimerThread
|
// CTimerThread
|
||||||
|
@ -33,7 +32,9 @@ CTimerThread::~CTimerThread()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTimerThread::timer(void*)
|
void
|
||||||
|
CTimerThread::timer(
|
||||||
|
void*)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "timeout in %f seconds", m_timeout));
|
log((CLOG_DEBUG1 "timeout in %f seconds", m_timeout));
|
||||||
CThread::sleep(m_timeout);
|
CThread::sleep(m_timeout);
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#ifndef CTIMERTHREAD_H
|
#ifndef CTIMERTHREAD_H
|
||||||
#define CTIMERTHREAD_H
|
#define CTIMERTHREAD_H
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
class CThread;
|
class CThread;
|
||||||
|
|
||||||
class CTimerThread {
|
class CTimerThread {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#ifndef XTHREAD_H
|
#ifndef XTHREAD_H
|
||||||
#define XTHREAD_H
|
#define XTHREAD_H
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
// generic thread exception
|
// generic thread exception
|
||||||
class XThread { };
|
class XThread { };
|
||||||
|
|
||||||
|
|
127
net/CNetwork.cpp
127
net/CNetwork.cpp
|
@ -1,7 +1,6 @@
|
||||||
#include "CNetwork.h"
|
#include "CNetwork.h"
|
||||||
#include "XNetwork.h"
|
#include "XNetwork.h"
|
||||||
#include "CLog.h"
|
#include "CLog.h"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CNetwork
|
// CNetwork
|
||||||
|
@ -51,15 +50,21 @@ const CNetwork::Socket CNetwork::Null = INVALID_SOCKET;
|
||||||
|
|
||||||
static HMODULE s_networkModule = NULL;
|
static HMODULE s_networkModule = NULL;
|
||||||
|
|
||||||
static FARPROC netGetProcAddress(HMODULE module, LPCSTR name)
|
static
|
||||||
|
FARPROC
|
||||||
|
netGetProcAddress(
|
||||||
|
HMODULE module,
|
||||||
|
LPCSTR name)
|
||||||
{
|
{
|
||||||
FARPROC func = ::GetProcAddress(module, name);
|
FARPROC func = ::GetProcAddress(module, name);
|
||||||
if (!func)
|
if (!func) {
|
||||||
throw XNetworkFunctionUnavailable(name);
|
throw XNetworkFunctionUnavailable(name);
|
||||||
|
}
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CNetwork::init()
|
void
|
||||||
|
CNetwork::init()
|
||||||
{
|
{
|
||||||
assert(WSACleanup == NULL);
|
assert(WSACleanup == NULL);
|
||||||
assert(s_networkModule == NULL);
|
assert(s_networkModule == NULL);
|
||||||
|
@ -98,7 +103,8 @@ void CNetwork::init()
|
||||||
throw XNetworkUnavailable();
|
throw XNetworkUnavailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CNetwork::cleanup()
|
void
|
||||||
|
CNetwork::cleanup()
|
||||||
{
|
{
|
||||||
if (s_networkModule != NULL) {
|
if (s_networkModule != NULL) {
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
@ -109,41 +115,55 @@ void CNetwork::cleanup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CNetwork::swaphtonl(UInt32 v)
|
UInt32
|
||||||
|
CNetwork::swaphtonl(
|
||||||
|
UInt32 v)
|
||||||
{
|
{
|
||||||
static const union { UInt16 s; UInt8 b[2]; } s_endian = { 0x1234 };
|
static const union { UInt16 s; UInt8 b[2]; } s_endian = { 0x1234 };
|
||||||
if (s_endian.b[0] == 0x34)
|
if (s_endian.b[0] == 0x34) {
|
||||||
return ((v & 0xff000000lu) >> 24) |
|
return ((v & 0xff000000lu) >> 24) |
|
||||||
((v & 0x00ff0000lu) >> 8) |
|
((v & 0x00ff0000lu) >> 8) |
|
||||||
((v & 0x0000ff00lu) << 8) |
|
((v & 0x0000ff00lu) << 8) |
|
||||||
((v & 0x000000fflu) << 24);
|
((v & 0x000000fflu) << 24);
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
return v;
|
return v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt16 CNetwork::swaphtons(UInt16 v)
|
UInt16
|
||||||
|
CNetwork::swaphtons(
|
||||||
|
UInt16 v)
|
||||||
{
|
{
|
||||||
static const union { UInt16 s; UInt8 b[2]; } s_endian = { 0x1234 };
|
static const union { UInt16 s; UInt8 b[2]; } s_endian = { 0x1234 };
|
||||||
if (s_endian.b[0] == 0x34)
|
if (s_endian.b[0] == 0x34) {
|
||||||
return static_cast<UInt16>( ((v & 0xff00u) >> 8) |
|
return static_cast<UInt16>( ((v & 0xff00u) >> 8) |
|
||||||
((v & 0x00ffu) << 8));
|
((v & 0x00ffu) << 8));
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
return v;
|
return v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CNetwork::swapntohl(UInt32 v)
|
UInt32
|
||||||
|
CNetwork::swapntohl(
|
||||||
|
UInt32 v)
|
||||||
{
|
{
|
||||||
return swaphtonl(v);
|
return swaphtonl(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt16 CNetwork::swapntohs(UInt16 v)
|
UInt16
|
||||||
|
CNetwork::swapntohs(
|
||||||
|
UInt16 v)
|
||||||
{
|
{
|
||||||
return swaphtons(v);
|
return swaphtons(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define setfunc(var, name, type) var = (type)netGetProcAddress(module, #name)
|
#define setfunc(var, name, type) var = (type)netGetProcAddress(module, #name)
|
||||||
|
|
||||||
void CNetwork::init2(HMODULE module)
|
void
|
||||||
|
CNetwork::init2(
|
||||||
|
HMODULE module)
|
||||||
{
|
{
|
||||||
assert(module != NULL);
|
assert(module != NULL);
|
||||||
|
|
||||||
|
@ -155,10 +175,12 @@ void CNetwork::init2(HMODULE module)
|
||||||
WORD version = MAKEWORD(1 /*major*/, 1 /*minor*/);
|
WORD version = MAKEWORD(1 /*major*/, 1 /*minor*/);
|
||||||
WSADATA data;
|
WSADATA data;
|
||||||
int err = startup(version, &data);
|
int err = startup(version, &data);
|
||||||
if (data.wVersion != version)
|
if (data.wVersion != version) {
|
||||||
throw XNetworkVersion(LOBYTE(data.wVersion), HIBYTE(data.wVersion));
|
throw XNetworkVersion(LOBYTE(data.wVersion), HIBYTE(data.wVersion));
|
||||||
if (err != 0)
|
}
|
||||||
|
if (err != 0) {
|
||||||
throw XNetworkFailed();
|
throw XNetworkFailed();
|
||||||
|
}
|
||||||
|
|
||||||
// get function addresses
|
// get function addresses
|
||||||
setfunc(accept, accept, Socket (PASCAL FAR *)(Socket s, Address FAR *addr, AddressLength FAR *addrlen));
|
setfunc(accept, accept, Socket (PASCAL FAR *)(Socket s, Address FAR *addr, AddressLength FAR *addrlen));
|
||||||
|
@ -198,7 +220,11 @@ void CNetwork::init2(HMODULE module)
|
||||||
s_networkModule = module;
|
s_networkModule = module;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PASCAL FAR CNetwork::poll2(PollEntry fd[], int nfds, int timeout)
|
int PASCAL FAR
|
||||||
|
CNetwork::poll2(
|
||||||
|
PollEntry fd[],
|
||||||
|
int nfds,
|
||||||
|
int timeout)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -241,32 +267,45 @@ int PASCAL FAR CNetwork::poll2(PollEntry fd[], int nfds, int timeout)
|
||||||
int n = select(0, readSetP, writeSetP, errSetP, timeout2P);
|
int n = select(0, readSetP, writeSetP, errSetP, timeout2P);
|
||||||
|
|
||||||
// handle results
|
// handle results
|
||||||
if (n == Error)
|
if (n == Error) {
|
||||||
return Error;
|
return Error;
|
||||||
if (n == 0)
|
}
|
||||||
|
if (n == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
n = 0;
|
n = 0;
|
||||||
for (i = 0; i < nfds; ++i) {
|
for (i = 0; i < nfds; ++i) {
|
||||||
fd[i].revents = 0;
|
fd[i].revents = 0;
|
||||||
if (FD_ISSET(fd[i].fd, &readSet))
|
if (FD_ISSET(fd[i].fd, &readSet)) {
|
||||||
fd[i].revents |= kPOLLIN;
|
fd[i].revents |= kPOLLIN;
|
||||||
if (FD_ISSET(fd[i].fd, &writeSet))
|
}
|
||||||
|
if (FD_ISSET(fd[i].fd, &writeSet)) {
|
||||||
fd[i].revents |= kPOLLOUT;
|
fd[i].revents |= kPOLLOUT;
|
||||||
if (FD_ISSET(fd[i].fd, &errSet))
|
}
|
||||||
|
if (FD_ISSET(fd[i].fd, &errSet)) {
|
||||||
fd[i].revents |= kPOLLERR;
|
fd[i].revents |= kPOLLERR;
|
||||||
if (fd[i].revents != 0)
|
}
|
||||||
|
if (fd[i].revents != 0) {
|
||||||
++n;
|
++n;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t PASCAL FAR CNetwork::read2(Socket s, void FAR * buf, size_t len)
|
ssize_t PASCAL FAR
|
||||||
|
CNetwork::read2(
|
||||||
|
Socket s,
|
||||||
|
void FAR* buf,
|
||||||
|
size_t len)
|
||||||
{
|
{
|
||||||
return recv(s, buf, len, 0);
|
return recv(s, buf, len, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t PASCAL FAR CNetwork::write2(Socket s,
|
ssize_t PASCAL FAR
|
||||||
const void FAR * buf, size_t len)
|
CNetwork::write2(
|
||||||
|
Socket s,
|
||||||
|
const void FAR* buf,
|
||||||
|
size_t len)
|
||||||
{
|
{
|
||||||
return send(s, buf, len, 0);
|
return send(s, buf, len, 0);
|
||||||
}
|
}
|
||||||
|
@ -283,37 +322,53 @@ ssize_t PASCAL FAR CNetwork::write2(Socket s,
|
||||||
|
|
||||||
#define setfunc(var, name, type) var = (type)::name
|
#define setfunc(var, name, type) var = (type)::name
|
||||||
|
|
||||||
UInt32 CNetwork::swaphtonl(UInt32 v)
|
UInt32
|
||||||
|
CNetwork::swaphtonl(
|
||||||
|
UInt32 v)
|
||||||
{
|
{
|
||||||
return htonl(v);
|
return htonl(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt16 CNetwork::swaphtons(UInt16 v)
|
UInt16
|
||||||
|
CNetwork::swaphtons(
|
||||||
|
UInt16 v)
|
||||||
{
|
{
|
||||||
return htons(v);
|
return htons(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CNetwork::swapntohl(UInt32 v)
|
UInt32
|
||||||
|
CNetwork::swapntohl(
|
||||||
|
UInt32 v)
|
||||||
{
|
{
|
||||||
return ntohl(v);
|
return ntohl(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt16 CNetwork::swapntohs(UInt16 v)
|
UInt16
|
||||||
|
CNetwork::swapntohs(
|
||||||
|
UInt16 v)
|
||||||
{
|
{
|
||||||
return ntohs(v);
|
return ntohs(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int myerrno()
|
static
|
||||||
|
int
|
||||||
|
myerrno()
|
||||||
{
|
{
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int myherrno()
|
static
|
||||||
|
int
|
||||||
|
myherrno()
|
||||||
{
|
{
|
||||||
return h_errno;
|
return h_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mygethostname(char* name, int namelen)
|
static
|
||||||
|
int
|
||||||
|
mygethostname(
|
||||||
|
char* name,
|
||||||
|
int namelen)
|
||||||
{
|
{
|
||||||
return gethostname(name, namelen);
|
return gethostname(name, namelen);
|
||||||
}
|
}
|
||||||
|
@ -321,7 +376,8 @@ static int mygethostname(char* name, int namelen)
|
||||||
const int CNetwork::Error = -1;
|
const int CNetwork::Error = -1;
|
||||||
const CNetwork::Socket CNetwork::Null = -1;
|
const CNetwork::Socket CNetwork::Null = -1;
|
||||||
|
|
||||||
void CNetwork::init()
|
void
|
||||||
|
CNetwork::init()
|
||||||
{
|
{
|
||||||
setfunc(accept, accept, Socket (PASCAL FAR *)(Socket s, Address FAR *addr, AddressLength FAR *addrlen));
|
setfunc(accept, accept, Socket (PASCAL FAR *)(Socket s, Address FAR *addr, AddressLength FAR *addrlen));
|
||||||
setfunc(bind, bind, int (PASCAL FAR *)(Socket s, const Address FAR *addr, AddressLength namelen));
|
setfunc(bind, bind, int (PASCAL FAR *)(Socket s, const Address FAR *addr, AddressLength namelen));
|
||||||
|
@ -355,7 +411,8 @@ void CNetwork::init()
|
||||||
setfunc(gethosterror, myherrno, int (PASCAL FAR *)(void));
|
setfunc(gethosterror, myherrno, int (PASCAL FAR *)(void));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CNetwork::cleanup()
|
void
|
||||||
|
CNetwork::cleanup()
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
#include "CNetworkAddress.h"
|
#include "CNetworkAddress.h"
|
||||||
#include "CString.h"
|
#include "XSocket.h"
|
||||||
#include <stdlib.h>
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
//
|
//
|
||||||
// CNetworkAddress
|
// CNetworkAddress
|
||||||
//
|
//
|
||||||
|
|
||||||
CNetworkAddress::CNetworkAddress() : m_port(0)
|
CNetworkAddress::CNetworkAddress() :
|
||||||
|
m_port(0)
|
||||||
{
|
{
|
||||||
// note -- make no calls to CNetwork socket interface here;
|
// note -- make no calls to CNetwork socket interface here;
|
||||||
// we're often called prior to CNetwork::init().
|
// we're often called prior to CNetwork::init().
|
||||||
|
@ -19,7 +21,9 @@ CNetworkAddress::CNetworkAddress() : m_port(0)
|
||||||
memset(inetAddress->sin_zero, 0, sizeof(inetAddress->sin_zero));
|
memset(inetAddress->sin_zero, 0, sizeof(inetAddress->sin_zero));
|
||||||
}
|
}
|
||||||
|
|
||||||
CNetworkAddress::CNetworkAddress(UInt16 port) : m_port(port)
|
CNetworkAddress::CNetworkAddress(
|
||||||
|
UInt16 port) :
|
||||||
|
m_port(port)
|
||||||
{
|
{
|
||||||
if (port == 0) {
|
if (port == 0) {
|
||||||
throw XSocketAddress(XSocketAddress::kBadPort, m_hostname, m_port);
|
throw XSocketAddress(XSocketAddress::kBadPort, m_hostname, m_port);
|
||||||
|
@ -33,9 +37,11 @@ CNetworkAddress::CNetworkAddress(UInt16 port) : m_port(port)
|
||||||
memset(inetAddress->sin_zero, 0, sizeof(inetAddress->sin_zero));
|
memset(inetAddress->sin_zero, 0, sizeof(inetAddress->sin_zero));
|
||||||
}
|
}
|
||||||
|
|
||||||
CNetworkAddress::CNetworkAddress(const CString& hostname_, UInt16 port) :
|
CNetworkAddress::CNetworkAddress(
|
||||||
m_hostname(hostname_),
|
const CString& hostname_,
|
||||||
m_port(port)
|
UInt16 port) :
|
||||||
|
m_hostname(hostname_),
|
||||||
|
m_port(port)
|
||||||
{
|
{
|
||||||
CString hostname(m_hostname);
|
CString hostname(m_hostname);
|
||||||
|
|
||||||
|
@ -126,27 +132,32 @@ CNetworkAddress::~CNetworkAddress()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CNetworkAddress::isValid() const
|
bool
|
||||||
|
CNetworkAddress::isValid() const
|
||||||
{
|
{
|
||||||
return (m_port != 0);
|
return (m_port != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CNetwork::Address* CNetworkAddress::getAddress() const
|
const CNetwork::Address*
|
||||||
|
CNetworkAddress::getAddress() const
|
||||||
{
|
{
|
||||||
return &m_address;
|
return &m_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
CNetwork::AddressLength CNetworkAddress::getAddressLength() const
|
CNetwork::AddressLength
|
||||||
|
CNetworkAddress::getAddressLength() const
|
||||||
{
|
{
|
||||||
return sizeof(m_address);
|
return sizeof(m_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CNetworkAddress::getHostname() const
|
CString
|
||||||
|
CNetworkAddress::getHostname() const
|
||||||
{
|
{
|
||||||
return m_hostname;
|
return m_hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt16 CNetworkAddress::getPort() const
|
UInt16
|
||||||
|
CNetworkAddress::getPort() const
|
||||||
{
|
{
|
||||||
return m_port;
|
return m_port;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define CNETWORKADDRESS_H
|
#define CNETWORKADDRESS_H
|
||||||
|
|
||||||
#include "CNetwork.h"
|
#include "CNetwork.h"
|
||||||
#include "XSocket.h"
|
|
||||||
#include "CString.h"
|
#include "CString.h"
|
||||||
#include "BasicTypes.h"
|
#include "BasicTypes.h"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "CTCPListenSocket.h"
|
#include "CTCPListenSocket.h"
|
||||||
#include "CTCPSocket.h"
|
#include "CTCPSocket.h"
|
||||||
#include "CNetworkAddress.h"
|
#include "CNetworkAddress.h"
|
||||||
|
#include "XIO.h"
|
||||||
|
#include "XSocket.h"
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -25,8 +27,9 @@ CTCPListenSocket::~CTCPListenSocket()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTCPListenSocket::bind(
|
void
|
||||||
const CNetworkAddress& addr)
|
CTCPListenSocket::bind(
|
||||||
|
const CNetworkAddress& addr)
|
||||||
{
|
{
|
||||||
if (CNetwork::bind(m_fd, addr.getAddress(),
|
if (CNetwork::bind(m_fd, addr.getAddress(),
|
||||||
addr.getAddressLength()) == CNetwork::Error) {
|
addr.getAddressLength()) == CNetwork::Error) {
|
||||||
|
@ -40,7 +43,8 @@ void CTCPListenSocket::bind(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ISocket* CTCPListenSocket::accept()
|
ISocket*
|
||||||
|
CTCPListenSocket::accept()
|
||||||
{
|
{
|
||||||
CNetwork::PollEntry pfds[1];
|
CNetwork::PollEntry pfds[1];
|
||||||
pfds[0].fd = m_fd;
|
pfds[0].fd = m_fd;
|
||||||
|
@ -59,7 +63,8 @@ ISocket* CTCPListenSocket::accept()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTCPListenSocket::close()
|
void
|
||||||
|
CTCPListenSocket::close()
|
||||||
{
|
{
|
||||||
if (m_fd == CNetwork::Null) {
|
if (m_fd == CNetwork::Null) {
|
||||||
throw XIOClosed();
|
throw XIOClosed();
|
||||||
|
|
|
@ -2,13 +2,14 @@
|
||||||
#include "CBufferedInputStream.h"
|
#include "CBufferedInputStream.h"
|
||||||
#include "CBufferedOutputStream.h"
|
#include "CBufferedOutputStream.h"
|
||||||
#include "CNetworkAddress.h"
|
#include "CNetworkAddress.h"
|
||||||
|
#include "XIO.h"
|
||||||
|
#include "XSocket.h"
|
||||||
|
#include "CCondVar.h"
|
||||||
#include "CLock.h"
|
#include "CLock.h"
|
||||||
#include "CMutex.h"
|
#include "CMutex.h"
|
||||||
#include "CCondVar.h"
|
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
#include "TMethodJob.h"
|
|
||||||
#include "CStopwatch.h"
|
#include "CStopwatch.h"
|
||||||
#include <assert.h>
|
#include "TMethodJob.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// CTCPSocket
|
// CTCPSocket
|
||||||
|
@ -23,7 +24,8 @@ CTCPSocket::CTCPSocket()
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
CTCPSocket::CTCPSocket(CNetwork::Socket fd) : m_fd(fd)
|
CTCPSocket::CTCPSocket(CNetwork::Socket fd) :
|
||||||
|
m_fd(fd)
|
||||||
{
|
{
|
||||||
assert(m_fd != CNetwork::Null);
|
assert(m_fd != CNetwork::Null);
|
||||||
|
|
||||||
|
@ -52,7 +54,9 @@ CTCPSocket::~CTCPSocket()
|
||||||
delete m_mutex;
|
delete m_mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTCPSocket::bind(const CNetworkAddress& addr)
|
void
|
||||||
|
CTCPSocket::bind(
|
||||||
|
const CNetworkAddress& addr)
|
||||||
{
|
{
|
||||||
if (CNetwork::bind(m_fd, addr.getAddress(),
|
if (CNetwork::bind(m_fd, addr.getAddress(),
|
||||||
addr.getAddressLength()) == CNetwork::Error) {
|
addr.getAddressLength()) == CNetwork::Error) {
|
||||||
|
@ -63,7 +67,9 @@ void CTCPSocket::bind(const CNetworkAddress& addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTCPSocket::connect(const CNetworkAddress& addr)
|
void
|
||||||
|
CTCPSocket::connect(
|
||||||
|
const CNetworkAddress& addr)
|
||||||
{
|
{
|
||||||
CThread::testCancel();
|
CThread::testCancel();
|
||||||
if (CNetwork::connect(m_fd, addr.getAddress(),
|
if (CNetwork::connect(m_fd, addr.getAddress(),
|
||||||
|
@ -78,7 +84,8 @@ void CTCPSocket::connect(const CNetworkAddress& addr)
|
||||||
this, &CTCPSocket::ioThread));
|
this, &CTCPSocket::ioThread));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTCPSocket::close()
|
void
|
||||||
|
CTCPSocket::close()
|
||||||
{
|
{
|
||||||
// see if buffers should be flushed
|
// see if buffers should be flushed
|
||||||
bool doFlush = false;
|
bool doFlush = false;
|
||||||
|
@ -117,17 +124,20 @@ void CTCPSocket::close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IInputStream* CTCPSocket::getInputStream()
|
IInputStream*
|
||||||
|
CTCPSocket::getInputStream()
|
||||||
{
|
{
|
||||||
return m_input;
|
return m_input;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputStream* CTCPSocket::getOutputStream()
|
IOutputStream*
|
||||||
|
CTCPSocket::getOutputStream()
|
||||||
{
|
{
|
||||||
return m_output;
|
return m_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTCPSocket::init()
|
void
|
||||||
|
CTCPSocket::init()
|
||||||
{
|
{
|
||||||
m_mutex = new CMutex;
|
m_mutex = new CMutex;
|
||||||
m_thread = NULL;
|
m_thread = NULL;
|
||||||
|
@ -146,7 +156,8 @@ void CTCPSocket::init()
|
||||||
CNetwork::setsockopt(m_fd, SOL_TCP, TCP_NODELAY, &flag, sizeof(flag));
|
CNetwork::setsockopt(m_fd, SOL_TCP, TCP_NODELAY, &flag, sizeof(flag));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTCPSocket::ioThread(void*)
|
void
|
||||||
|
CTCPSocket::ioThread(void*)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
ioService();
|
ioService();
|
||||||
|
@ -158,7 +169,8 @@ void CTCPSocket::ioThread(void*)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTCPSocket::ioCleanup()
|
void
|
||||||
|
CTCPSocket::ioCleanup()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
m_input->close();
|
m_input->close();
|
||||||
|
@ -174,7 +186,8 @@ void CTCPSocket::ioCleanup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTCPSocket::ioService()
|
void
|
||||||
|
CTCPSocket::ioService()
|
||||||
{
|
{
|
||||||
assert(m_fd != CNetwork::Null);
|
assert(m_fd != CNetwork::Null);
|
||||||
|
|
||||||
|
@ -249,14 +262,16 @@ void CTCPSocket::ioService()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTCPSocket::closeInput(void*)
|
void
|
||||||
|
CTCPSocket::closeInput(void*)
|
||||||
{
|
{
|
||||||
// note -- m_mutex should already be locked
|
// note -- m_mutex should already be locked
|
||||||
CNetwork::shutdown(m_fd, 0);
|
CNetwork::shutdown(m_fd, 0);
|
||||||
m_connected &= ~kRead;
|
m_connected &= ~kRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTCPSocket::closeOutput(void*)
|
void
|
||||||
|
CTCPSocket::closeOutput(void*)
|
||||||
{
|
{
|
||||||
// note -- m_mutex should already be locked
|
// note -- m_mutex should already be locked
|
||||||
CNetwork::shutdown(m_fd, 1);
|
CNetwork::shutdown(m_fd, 1);
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "ISocket.h"
|
#include "ISocket.h"
|
||||||
#include "CNetwork.h"
|
#include "CNetwork.h"
|
||||||
#include "XThread.h"
|
|
||||||
|
|
||||||
class CMutex;
|
class CMutex;
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
#define ILISTENSOCKET_H
|
#define ILISTENSOCKET_H
|
||||||
|
|
||||||
#include "IInterface.h"
|
#include "IInterface.h"
|
||||||
#include "XIO.h"
|
|
||||||
#include "XSocket.h"
|
|
||||||
|
|
||||||
class CNetworkAddress;
|
class CNetworkAddress;
|
||||||
class ISocket;
|
class ISocket;
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
#define ISOCKET_H
|
#define ISOCKET_H
|
||||||
|
|
||||||
#include "IInterface.h"
|
#include "IInterface.h"
|
||||||
#include "BasicTypes.h"
|
|
||||||
#include "XSocket.h"
|
|
||||||
#include "XIO.h"
|
|
||||||
|
|
||||||
class CNetworkAddress;
|
class CNetworkAddress;
|
||||||
class IInputStream;
|
class IInputStream;
|
||||||
|
|
|
@ -19,6 +19,7 @@ CXXFILES = \
|
||||||
CNetworkAddress.cpp \
|
CNetworkAddress.cpp \
|
||||||
CTCPSocket.cpp \
|
CTCPSocket.cpp \
|
||||||
CTCPListenSocket.cpp \
|
CTCPListenSocket.cpp \
|
||||||
|
XNetwork.cpp \
|
||||||
XSocket.cpp \
|
XSocket.cpp \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
// XNetworkUnavailable
|
// XNetworkUnavailable
|
||||||
//
|
//
|
||||||
|
|
||||||
CString XNetworkUnavailable::getWhat() const throw()
|
CString
|
||||||
|
XNetworkUnavailable::getWhat() const throw()
|
||||||
{
|
{
|
||||||
return format("XNetworkUnavailable", "network library is not available");
|
return format("XNetworkUnavailable", "network library is not available");
|
||||||
}
|
}
|
||||||
|
@ -14,7 +15,8 @@ CString XNetworkUnavailable::getWhat() const throw()
|
||||||
// XNetworkFailed
|
// XNetworkFailed
|
||||||
//
|
//
|
||||||
|
|
||||||
CString XNetworkFailed::getWhat() const throw()
|
CString
|
||||||
|
XNetworkFailed::getWhat() const throw()
|
||||||
{
|
{
|
||||||
return format("XNetworkFailed", "cannot initialize network library");
|
return format("XNetworkFailed", "cannot initialize network library");
|
||||||
}
|
}
|
||||||
|
@ -24,24 +26,29 @@ CString XNetworkFailed::getWhat() const throw()
|
||||||
// XNetworkVersion
|
// XNetworkVersion
|
||||||
//
|
//
|
||||||
|
|
||||||
XNetworkVersion::XNetworkVersion(int major, int minor) throw() :
|
XNetworkVersion::XNetworkVersion(
|
||||||
m_major(major),
|
int major,
|
||||||
m_minor(minor)
|
int minor) throw() :
|
||||||
|
m_major(major),
|
||||||
|
m_minor(minor)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
int XNetworkVersion::getMajor() const throw()
|
int
|
||||||
|
XNetworkVersion::getMajor() const throw()
|
||||||
{
|
{
|
||||||
return m_major;
|
return m_major;
|
||||||
}
|
}
|
||||||
|
|
||||||
int XNetworkVersion::getMinor() const throw()
|
int
|
||||||
|
XNetworkVersion::getMinor() const throw()
|
||||||
{
|
{
|
||||||
return m_minor;
|
return m_minor;
|
||||||
}
|
}
|
||||||
|
|
||||||
CString XNetworkVersion::getWhat() const throw()
|
CString
|
||||||
|
XNetworkVersion::getWhat() const throw()
|
||||||
{
|
{
|
||||||
return format("XNetworkVersion",
|
return format("XNetworkVersion",
|
||||||
"unsupported network version %d.%d",
|
"unsupported network version %d.%d",
|
||||||
|
@ -54,7 +61,7 @@ CString XNetworkVersion::getWhat() const throw()
|
||||||
//
|
//
|
||||||
|
|
||||||
XNetworkFunctionUnavailable::XNetworkFunctionUnavailable(
|
XNetworkFunctionUnavailable::XNetworkFunctionUnavailable(
|
||||||
const char* name) throw()
|
const char* name) throw()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
m_name = name;
|
m_name = name;
|
||||||
|
@ -64,7 +71,8 @@ XNetworkFunctionUnavailable::XNetworkFunctionUnavailable(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CString XNetworkFunctionUnavailable::getWhat() const throw()
|
CString
|
||||||
|
XNetworkFunctionUnavailable::getWhat() const throw()
|
||||||
{
|
{
|
||||||
return format("XNetworkFunctionUnavailable",
|
return format("XNetworkFunctionUnavailable",
|
||||||
"missing network function %s",
|
"missing network function %s",
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
#ifndef XNETWORK_H
|
#ifndef XNETWORK_H
|
||||||
#define XNETWORK_H
|
#define XNETWORK_H
|
||||||
|
|
||||||
#include "CString.h"
|
|
||||||
#include "XBase.h"
|
#include "XBase.h"
|
||||||
#include "BasicTypes.h"
|
#include "CString.h"
|
||||||
|
|
||||||
class XNetwork : public XBase { };
|
class XNetwork : public XBase { };
|
||||||
|
|
||||||
|
|
|
@ -4,31 +4,37 @@
|
||||||
// XSocketAddress
|
// XSocketAddress
|
||||||
//
|
//
|
||||||
|
|
||||||
XSocketAddress::XSocketAddress(Error error,
|
XSocketAddress::XSocketAddress(
|
||||||
const CString& hostname, UInt16 port) throw() :
|
Error error,
|
||||||
m_error(error),
|
const CString& hostname,
|
||||||
m_hostname(hostname),
|
UInt16 port) throw() :
|
||||||
m_port(port)
|
m_error(error),
|
||||||
|
m_hostname(hostname),
|
||||||
|
m_port(port)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
XSocketAddress::Error XSocketAddress::getError() const throw()
|
XSocketAddress::Error
|
||||||
|
XSocketAddress::getError() const throw()
|
||||||
{
|
{
|
||||||
return m_error;
|
return m_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
CString XSocketAddress::getHostname() const throw()
|
CString
|
||||||
|
XSocketAddress::getHostname() const throw()
|
||||||
{
|
{
|
||||||
return m_hostname;
|
return m_hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt16 XSocketAddress::getPort() const throw()
|
UInt16
|
||||||
|
XSocketAddress::getPort() const throw()
|
||||||
{
|
{
|
||||||
return m_port;
|
return m_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
CString XSocketAddress::getWhat() const throw()
|
CString
|
||||||
|
XSocketAddress::getWhat() const throw()
|
||||||
{
|
{
|
||||||
return "no address";
|
return "no address";
|
||||||
/*
|
/*
|
||||||
|
@ -43,12 +49,15 @@ CString XSocketAddress::getWhat() const throw()
|
||||||
// XSocketErrno
|
// XSocketErrno
|
||||||
//
|
//
|
||||||
|
|
||||||
XSocketErrno::XSocketErrno() : MXErrno()
|
XSocketErrno::XSocketErrno() :
|
||||||
|
MXErrno()
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
XSocketErrno::XSocketErrno(int err) : MXErrno(err)
|
XSocketErrno::XSocketErrno(
|
||||||
|
int err) :
|
||||||
|
MXErrno(err)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -58,7 +67,8 @@ XSocketErrno::XSocketErrno(int err) : MXErrno(err)
|
||||||
// XSocketBind
|
// XSocketBind
|
||||||
//
|
//
|
||||||
|
|
||||||
CString XSocketBind::getWhat() const throw()
|
CString
|
||||||
|
XSocketBind::getWhat() const throw()
|
||||||
{
|
{
|
||||||
return format("XSocketBind", "cannot bind address");
|
return format("XSocketBind", "cannot bind address");
|
||||||
}
|
}
|
||||||
|
@ -68,7 +78,8 @@ CString XSocketBind::getWhat() const throw()
|
||||||
// XSocketConnect
|
// XSocketConnect
|
||||||
//
|
//
|
||||||
|
|
||||||
CString XSocketConnect::getWhat() const throw()
|
CString
|
||||||
|
XSocketConnect::getWhat() const throw()
|
||||||
{
|
{
|
||||||
return format("XSocketConnect", "cannot connect socket");
|
return format("XSocketConnect", "cannot connect socket");
|
||||||
}
|
}
|
||||||
|
@ -78,7 +89,8 @@ CString XSocketConnect::getWhat() const throw()
|
||||||
// XSocketCreate
|
// XSocketCreate
|
||||||
//
|
//
|
||||||
|
|
||||||
CString XSocketCreate::getWhat() const throw()
|
CString
|
||||||
|
XSocketCreate::getWhat() const throw()
|
||||||
{
|
{
|
||||||
return format("XSocketCreate", "cannot create socket");
|
return format("XSocketCreate", "cannot create socket");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef XSOCKET_H
|
#ifndef XSOCKET_H
|
||||||
#define XSOCKET_H
|
#define XSOCKET_H
|
||||||
|
|
||||||
#include "CString.h"
|
|
||||||
#include "XBase.h"
|
#include "XBase.h"
|
||||||
|
#include "CString.h"
|
||||||
#include "BasicTypes.h"
|
#include "BasicTypes.h"
|
||||||
|
|
||||||
class XSocket : public XBase { };
|
class XSocket : public XBase { };
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#include "CMSWindowsClipboard.h"
|
#include "CMSWindowsClipboard.h"
|
||||||
#include "CString.h"
|
|
||||||
#include "CLog.h"
|
#include "CLog.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// CMSWindowsClipboard
|
// CMSWindowsClipboard
|
||||||
//
|
//
|
||||||
|
|
||||||
CMSWindowsClipboard::CMSWindowsClipboard(HWND window) :
|
CMSWindowsClipboard::CMSWindowsClipboard(
|
||||||
m_window(window),
|
HWND window) :
|
||||||
m_time(0)
|
m_window(window),
|
||||||
|
m_time(0)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,8 @@ CMSWindowsClipboard::~CMSWindowsClipboard()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMSWindowsClipboard::empty()
|
bool
|
||||||
|
CMSWindowsClipboard::empty()
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG "empty clipboard"));
|
log((CLOG_DEBUG "empty clipboard"));
|
||||||
|
|
||||||
|
@ -30,8 +31,10 @@ bool CMSWindowsClipboard::empty()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsClipboard::add(
|
void
|
||||||
EFormat format, const CString& data)
|
CMSWindowsClipboard::add(
|
||||||
|
EFormat format,
|
||||||
|
const CString& data)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG "add %d bytes to clipboard format: %d", data.size(), format));
|
log((CLOG_DEBUG "add %d bytes to clipboard format: %d", data.size(), format));
|
||||||
|
|
||||||
|
@ -54,7 +57,9 @@ void CMSWindowsClipboard::add(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMSWindowsClipboard::open(Time time) const
|
bool
|
||||||
|
CMSWindowsClipboard::open(
|
||||||
|
Time time) const
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG "open clipboard"));
|
log((CLOG_DEBUG "open clipboard"));
|
||||||
|
|
||||||
|
@ -68,29 +73,36 @@ bool CMSWindowsClipboard::open(Time time) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsClipboard::close() const
|
void
|
||||||
|
CMSWindowsClipboard::close() const
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG "close clipboard"));
|
log((CLOG_DEBUG "close clipboard"));
|
||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
IClipboard::Time CMSWindowsClipboard::getTime() const
|
IClipboard::Time
|
||||||
|
CMSWindowsClipboard::getTime() const
|
||||||
{
|
{
|
||||||
return m_time;
|
return m_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMSWindowsClipboard::has(EFormat format) const
|
bool
|
||||||
|
CMSWindowsClipboard::has(
|
||||||
|
EFormat format) const
|
||||||
{
|
{
|
||||||
const UINT win32Format = convertFormatToWin32(format);
|
const UINT win32Format = convertFormatToWin32(format);
|
||||||
return (win32Format != 0 && IsClipboardFormatAvailable(win32Format) != 0);
|
return (win32Format != 0 && IsClipboardFormatAvailable(win32Format) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CMSWindowsClipboard::get(EFormat format) const
|
CString
|
||||||
|
CMSWindowsClipboard::get(
|
||||||
|
EFormat format) const
|
||||||
{
|
{
|
||||||
// get the win32 format. return empty data if unknown format.
|
// get the win32 format. return empty data if unknown format.
|
||||||
const UINT win32Format = convertFormatToWin32(format);
|
const UINT win32Format = convertFormatToWin32(format);
|
||||||
if (win32Format == 0)
|
if (win32Format == 0) {
|
||||||
return CString();
|
return CString();
|
||||||
|
}
|
||||||
|
|
||||||
// get a handle to the clipboard data and convert it
|
// get a handle to the clipboard data and convert it
|
||||||
HANDLE win32Data = GetClipboardData(win32Format);
|
HANDLE win32Data = GetClipboardData(win32Format);
|
||||||
|
@ -106,8 +118,9 @@ CString CMSWindowsClipboard::get(EFormat format) const
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT CMSWindowsClipboard::convertFormatToWin32(
|
UINT
|
||||||
EFormat format) const
|
CMSWindowsClipboard::convertFormatToWin32(
|
||||||
|
EFormat format) const
|
||||||
{
|
{
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case kText:
|
case kText:
|
||||||
|
@ -118,8 +131,9 @@ UINT CMSWindowsClipboard::convertFormatToWin32(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE CMSWindowsClipboard::convertTextToWin32(
|
HANDLE
|
||||||
const CString& data) const
|
CMSWindowsClipboard::convertTextToWin32(
|
||||||
|
const CString& data) const
|
||||||
{
|
{
|
||||||
// compute size of converted text
|
// compute size of converted text
|
||||||
UInt32 dstSize = 1;
|
UInt32 dstSize = 1;
|
||||||
|
@ -157,14 +171,16 @@ HANDLE CMSWindowsClipboard::convertTextToWin32(
|
||||||
return gData;
|
return gData;
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CMSWindowsClipboard::convertTextFromWin32(
|
CString
|
||||||
HANDLE handle) const
|
CMSWindowsClipboard::convertTextFromWin32(
|
||||||
|
HANDLE handle) const
|
||||||
{
|
{
|
||||||
// get source data and it's size
|
// get source data and it's size
|
||||||
const char* src = (const char*)GlobalLock(handle);
|
const char* src = (const char*)GlobalLock(handle);
|
||||||
UInt32 srcSize = (SInt32)GlobalSize(handle);
|
UInt32 srcSize = (SInt32)GlobalSize(handle);
|
||||||
if (src == NULL || srcSize <= 1)
|
if (src == NULL || srcSize <= 1) {
|
||||||
return CString();
|
return CString();
|
||||||
|
}
|
||||||
|
|
||||||
// ignore trailing NUL
|
// ignore trailing NUL
|
||||||
--srcSize;
|
--srcSize;
|
||||||
|
@ -175,8 +191,9 @@ CString CMSWindowsClipboard::convertTextFromWin32(
|
||||||
for (index = 0; index < srcSize; ++index) {
|
for (index = 0; index < srcSize; ++index) {
|
||||||
if (src[index] == '\r') {
|
if (src[index] == '\r') {
|
||||||
// skip \r
|
// skip \r
|
||||||
if (index + 1 < srcSize && src[index + 1] == '\n')
|
if (index + 1 < srcSize && src[index + 1] == '\n') {
|
||||||
++index;
|
++index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
++dstSize;
|
++dstSize;
|
||||||
}
|
}
|
||||||
|
@ -189,8 +206,9 @@ CString CMSWindowsClipboard::convertTextFromWin32(
|
||||||
for (index = 0; index < srcSize; ++index) {
|
for (index = 0; index < srcSize; ++index) {
|
||||||
if (src[index] == '\r') {
|
if (src[index] == '\r') {
|
||||||
// skip \r
|
// skip \r
|
||||||
if (index + 1 < srcSize && src[index + 1] == '\n')
|
if (index + 1 < srcSize && src[index + 1] == '\n') {
|
||||||
++index;
|
++index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
data += src[index];
|
data += src[index];
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
#include "TMethodJob.h"
|
#include "TMethodJob.h"
|
||||||
#include "CLog.h"
|
#include "CLog.h"
|
||||||
#include "CString.h"
|
#include "CString.h"
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CMSWindowsScreen
|
// CMSWindowsScreen
|
||||||
|
@ -15,10 +14,10 @@ HINSTANCE CMSWindowsScreen::s_instance = NULL;
|
||||||
CMSWindowsScreen* CMSWindowsScreen::s_screen = NULL;
|
CMSWindowsScreen* CMSWindowsScreen::s_screen = NULL;
|
||||||
|
|
||||||
CMSWindowsScreen::CMSWindowsScreen() :
|
CMSWindowsScreen::CMSWindowsScreen() :
|
||||||
m_class(0),
|
m_class(0),
|
||||||
m_cursor(NULL),
|
m_cursor(NULL),
|
||||||
m_w(0), m_h(0),
|
m_w(0), m_h(0),
|
||||||
m_thread(0)
|
m_thread(0)
|
||||||
{
|
{
|
||||||
assert(s_screen == NULL);
|
assert(s_screen == NULL);
|
||||||
s_screen = this;
|
s_screen = this;
|
||||||
|
@ -30,12 +29,15 @@ CMSWindowsScreen::~CMSWindowsScreen()
|
||||||
s_screen = NULL;
|
s_screen = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsScreen::init(HINSTANCE instance)
|
void
|
||||||
|
CMSWindowsScreen::init(
|
||||||
|
HINSTANCE instance)
|
||||||
{
|
{
|
||||||
s_instance = instance;
|
s_instance = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsScreen::doRun()
|
void
|
||||||
|
CMSWindowsScreen::doRun()
|
||||||
{
|
{
|
||||||
// save thread id for posting quit message
|
// save thread id for posting quit message
|
||||||
m_thread = GetCurrentThreadId();
|
m_thread = GetCurrentThreadId();
|
||||||
|
@ -59,12 +61,14 @@ void CMSWindowsScreen::doRun()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsScreen::doStop()
|
void
|
||||||
|
CMSWindowsScreen::doStop()
|
||||||
{
|
{
|
||||||
PostThreadMessage(m_thread, WM_QUIT, 0, 0);
|
PostThreadMessage(m_thread, WM_QUIT, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsScreen::openDisplay()
|
void
|
||||||
|
CMSWindowsScreen::openDisplay()
|
||||||
{
|
{
|
||||||
assert(s_instance != NULL);
|
assert(s_instance != NULL);
|
||||||
assert(m_class == 0);
|
assert(m_class == 0);
|
||||||
|
@ -106,7 +110,8 @@ void CMSWindowsScreen::openDisplay()
|
||||||
onOpenDisplay();
|
onOpenDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsScreen::closeDisplay()
|
void
|
||||||
|
CMSWindowsScreen::closeDisplay()
|
||||||
{
|
{
|
||||||
assert(s_instance != NULL);
|
assert(s_instance != NULL);
|
||||||
assert(m_class != 0);
|
assert(m_class != 0);
|
||||||
|
@ -125,25 +130,30 @@ void CMSWindowsScreen::closeDisplay()
|
||||||
log((CLOG_DEBUG "closed display"));
|
log((CLOG_DEBUG "closed display"));
|
||||||
}
|
}
|
||||||
|
|
||||||
HINSTANCE CMSWindowsScreen::getInstance()
|
HINSTANCE
|
||||||
|
CMSWindowsScreen::getInstance()
|
||||||
{
|
{
|
||||||
return s_instance;
|
return s_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
ATOM CMSWindowsScreen::getClass() const
|
ATOM
|
||||||
|
CMSWindowsScreen::getClass() const
|
||||||
{
|
{
|
||||||
return m_class;
|
return m_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsScreen::updateScreenSize()
|
void
|
||||||
|
CMSWindowsScreen::updateScreenSize()
|
||||||
{
|
{
|
||||||
m_w = GetSystemMetrics(SM_CXSCREEN);
|
m_w = GetSystemMetrics(SM_CXSCREEN);
|
||||||
m_h = GetSystemMetrics(SM_CYSCREEN);
|
m_h = GetSystemMetrics(SM_CYSCREEN);
|
||||||
log((CLOG_INFO "display resize: %dx%d", m_w, m_h));
|
log((CLOG_INFO "display resize: %dx%d", m_w, m_h));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsScreen::getScreenSize(
|
void
|
||||||
SInt32* w, SInt32* h) const
|
CMSWindowsScreen::getScreenSize(
|
||||||
|
SInt32* w,
|
||||||
|
SInt32* h) const
|
||||||
{
|
{
|
||||||
assert(m_class != 0);
|
assert(m_class != 0);
|
||||||
assert(w != NULL && h != NULL);
|
assert(w != NULL && h != NULL);
|
||||||
|
@ -152,7 +162,8 @@ void CMSWindowsScreen::getScreenSize(
|
||||||
*h = m_h;
|
*h = m_h;
|
||||||
}
|
}
|
||||||
|
|
||||||
HDESK CMSWindowsScreen::openInputDesktop() const
|
HDESK
|
||||||
|
CMSWindowsScreen::openInputDesktop() const
|
||||||
{
|
{
|
||||||
return OpenInputDesktop(DF_ALLOWOTHERACCOUNTHOOK, TRUE,
|
return OpenInputDesktop(DF_ALLOWOTHERACCOUNTHOOK, TRUE,
|
||||||
DESKTOP_CREATEWINDOW |
|
DESKTOP_CREATEWINDOW |
|
||||||
|
@ -160,8 +171,9 @@ HDESK CMSWindowsScreen::openInputDesktop() const
|
||||||
GENERIC_WRITE);
|
GENERIC_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CMSWindowsScreen::getDesktopName(
|
CString
|
||||||
HDESK desk) const
|
CMSWindowsScreen::getDesktopName(
|
||||||
|
HDESK desk) const
|
||||||
{
|
{
|
||||||
if (desk == NULL) {
|
if (desk == NULL) {
|
||||||
return CString();
|
return CString();
|
||||||
|
@ -177,14 +189,17 @@ CString CMSWindowsScreen::getDesktopName(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMSWindowsScreen::isCurrentDesktop(
|
bool
|
||||||
HDESK desk) const
|
CMSWindowsScreen::isCurrentDesktop(
|
||||||
|
HDESK desk) const
|
||||||
{
|
{
|
||||||
return CStringUtil::CaselessCmp::equal(getDesktopName(desk),
|
return CStringUtil::CaselessCmp::equal(getDesktopName(desk),
|
||||||
getCurrentDesktopName());
|
getCurrentDesktopName());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsScreen::getEvent(MSG* msg) const
|
void
|
||||||
|
CMSWindowsScreen::getEvent(
|
||||||
|
MSG* msg) const
|
||||||
{
|
{
|
||||||
// wait for an event in a cancellable way
|
// wait for an event in a cancellable way
|
||||||
while (HIWORD(GetQueueStatus(QS_ALLINPUT)) == 0) {
|
while (HIWORD(GetQueueStatus(QS_ALLINPUT)) == 0) {
|
||||||
|
@ -193,9 +208,12 @@ void CMSWindowsScreen::getEvent(MSG* msg) const
|
||||||
GetMessage(msg, NULL, 0, 0);
|
GetMessage(msg, NULL, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK CMSWindowsScreen::wndProc(
|
LRESULT CALLBACK
|
||||||
HWND hwnd, UINT msg,
|
CMSWindowsScreen::wndProc(
|
||||||
WPARAM wParam, LPARAM lParam)
|
HWND hwnd,
|
||||||
|
UINT msg,
|
||||||
|
WPARAM wParam,
|
||||||
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
assert(s_screen != NULL);
|
assert(s_screen != NULL);
|
||||||
return s_screen->onEvent(hwnd, msg, wParam, lParam);
|
return s_screen->onEvent(hwnd, msg, wParam, lParam);
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
#ifndef CMSWINDOWSSCREEN_H
|
#ifndef CMSWINDOWSSCREEN_H
|
||||||
#define CMSWINDOWSSCREEN_H
|
#define CMSWINDOWSSCREEN_H
|
||||||
|
|
||||||
#include "CMutex.h"
|
|
||||||
#include "IClipboard.h"
|
#include "IClipboard.h"
|
||||||
#include "BasicTypes.h"
|
#include "CMutex.h"
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "CUnixPlatform.h"
|
#include "CUnixPlatform.h"
|
||||||
#include "CLog.h"
|
#include "CLog.h"
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -9,7 +9,6 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CUnixPlatform
|
// CUnixPlatform
|
||||||
//
|
//
|
||||||
|
@ -24,24 +23,29 @@ CUnixPlatform::~CUnixPlatform()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CUnixPlatform::installDaemon(
|
bool
|
||||||
const char*,
|
CUnixPlatform::installDaemon(
|
||||||
const char*,
|
const char*,
|
||||||
const char*,
|
const char*,
|
||||||
const char*)
|
const char*,
|
||||||
|
const char*)
|
||||||
{
|
{
|
||||||
// daemons don't require special installation
|
// daemons don't require special installation
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CUnixPlatform::uninstallDaemon(const char*)
|
bool
|
||||||
|
CUnixPlatform::uninstallDaemon(
|
||||||
|
const char*)
|
||||||
{
|
{
|
||||||
// daemons don't require special installation
|
// daemons don't require special installation
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CUnixPlatform::daemonize(
|
int
|
||||||
const char* name, DaemonFunc func)
|
CUnixPlatform::daemonize(
|
||||||
|
const char* name,
|
||||||
|
DaemonFunc func)
|
||||||
{
|
{
|
||||||
// fork so shell thinks we're done and so we're not a process
|
// fork so shell thinks we're done and so we're not a process
|
||||||
// group leader
|
// group leader
|
||||||
|
@ -86,43 +90,46 @@ int CUnixPlatform::daemonize(
|
||||||
return func(this, 1, &name);
|
return func(this, 1, &name);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CUnixPlatform::restart(
|
int
|
||||||
RestartFunc func, int minErrorCode)
|
CUnixPlatform::restart(
|
||||||
|
RestartFunc func,
|
||||||
|
int minErrorCode)
|
||||||
{
|
{
|
||||||
for (;;) {
|
for (;;) {
|
||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
default: {
|
default:
|
||||||
// parent process. wait for child to exit.
|
{
|
||||||
int status;
|
// parent process. wait for child to exit.
|
||||||
if (wait(&status) == -1) {
|
int status;
|
||||||
// wait failed. this is unexpected so bail.
|
if (wait(&status) == -1) {
|
||||||
log((CLOG_CRIT "wait() failed"));
|
// wait failed. this is unexpected so bail.
|
||||||
return minErrorCode;
|
log((CLOG_CRIT "wait() failed"));
|
||||||
}
|
return minErrorCode;
|
||||||
|
}
|
||||||
|
|
||||||
// what happened? if the child exited normally with a
|
// what happened? if the child exited normally with a
|
||||||
// status less than 16 then the child was deliberately
|
// status less than 16 then the child was deliberately
|
||||||
// terminated so we also terminate.
|
// terminated so we also terminate.
|
||||||
if (WIFEXITED(status) && WEXITSTATUS(status) < minErrorCode) {
|
if (WIFEXITED(status) && WEXITSTATUS(status) < minErrorCode) {
|
||||||
return WEXITSTATUS(status);
|
return WEXITSTATUS(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
// did child die horribly?
|
// did child die horribly?
|
||||||
if (WIFSIGNALED(status)) {
|
if (WIFSIGNALED(status)) {
|
||||||
switch (WTERMSIG(status)) {
|
switch (WTERMSIG(status)) {
|
||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
case SIGINT:
|
case SIGINT:
|
||||||
case SIGQUIT:
|
case SIGQUIT:
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// uh oh. bail out.
|
// uh oh. bail out.
|
||||||
return 16;
|
return 16;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case -1:
|
case -1:
|
||||||
// fork() failed. log the error and proceed as a child
|
// fork() failed. log the error and proceed as a child
|
||||||
|
@ -136,7 +143,9 @@ int CUnixPlatform::restart(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CUnixPlatform::getBasename(const char* pathname) const
|
const char*
|
||||||
|
CUnixPlatform::getBasename(
|
||||||
|
const char* pathname) const
|
||||||
{
|
{
|
||||||
if (pathname == NULL) {
|
if (pathname == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -151,7 +160,8 @@ const char* CUnixPlatform::getBasename(const char* pathname) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CUnixPlatform::getUserDirectory() const
|
CString
|
||||||
|
CUnixPlatform::getUserDirectory() const
|
||||||
{
|
{
|
||||||
// FIXME -- use geteuid? shouldn't run this setuid anyway.
|
// FIXME -- use geteuid? shouldn't run this setuid anyway.
|
||||||
struct passwd* pwent = getpwuid(getuid());
|
struct passwd* pwent = getpwuid(getuid());
|
||||||
|
@ -163,14 +173,16 @@ CString CUnixPlatform::getUserDirectory() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CUnixPlatform::getSystemDirectory() const
|
CString
|
||||||
|
CUnixPlatform::getSystemDirectory() const
|
||||||
{
|
{
|
||||||
return "/etc";
|
return "/etc";
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CUnixPlatform::addPathComponent(
|
CString
|
||||||
const CString& prefix,
|
CUnixPlatform::addPathComponent(
|
||||||
const CString& suffix) const
|
const CString& prefix,
|
||||||
|
const CString& suffix) const
|
||||||
{
|
{
|
||||||
CString path;
|
CString path;
|
||||||
path.reserve(prefix.size() + 1 + suffix.size());
|
path.reserve(prefix.size() + 1 + suffix.size());
|
||||||
|
@ -182,14 +194,18 @@ CString CUnixPlatform::addPathComponent(
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnixPlatform::setDaemonLogger(const char* name)
|
void
|
||||||
|
CUnixPlatform::setDaemonLogger(
|
||||||
|
const char* name)
|
||||||
{
|
{
|
||||||
openlog(name, 0, LOG_DAEMON);
|
openlog(name, 0, LOG_DAEMON);
|
||||||
CLog::setOutputter(&CUnixPlatform::deamonLogger);
|
CLog::setOutputter(&CUnixPlatform::deamonLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CUnixPlatform::deamonLogger(
|
bool
|
||||||
int priority, const char* msg)
|
CUnixPlatform::deamonLogger(
|
||||||
|
int priority,
|
||||||
|
const char* msg)
|
||||||
{
|
{
|
||||||
// convert priority
|
// convert priority
|
||||||
switch (priority) {
|
switch (priority) {
|
||||||
|
|
|
@ -10,9 +10,9 @@ public:
|
||||||
|
|
||||||
// IPlatform overrides
|
// IPlatform overrides
|
||||||
virtual bool installDaemon(const char* name,
|
virtual bool installDaemon(const char* name,
|
||||||
const char* description,
|
const char* description,
|
||||||
const char* pathname,
|
const char* pathname,
|
||||||
const char* commandLine);
|
const char* commandLine);
|
||||||
virtual bool uninstallDaemon(const char* name);
|
virtual bool uninstallDaemon(const char* name);
|
||||||
virtual int daemonize(const char* name, DaemonFunc);
|
virtual int daemonize(const char* name, DaemonFunc);
|
||||||
virtual int restart(RestartFunc, int minErrorCode);
|
virtual int restart(RestartFunc, int minErrorCode);
|
||||||
|
@ -20,8 +20,8 @@ public:
|
||||||
virtual CString getUserDirectory() const;
|
virtual CString getUserDirectory() const;
|
||||||
virtual CString getSystemDirectory() const;
|
virtual CString getSystemDirectory() const;
|
||||||
virtual CString addPathComponent(
|
virtual CString addPathComponent(
|
||||||
const CString& prefix,
|
const CString& prefix,
|
||||||
const CString& suffix) const;
|
const CString& suffix) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setDaemonLogger(const char* name);
|
virtual void setDaemonLogger(const char* name);
|
||||||
|
|
|
@ -3,10 +3,9 @@
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
#include "CLog.h"
|
#include "CLog.h"
|
||||||
#include "stdvector.h"
|
#include "stdvector.h"
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CWin32Platform
|
// CWin32Platform
|
||||||
|
@ -25,7 +24,8 @@ CWin32Platform::~CWin32Platform()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWin32Platform::isWindows95Family()
|
bool
|
||||||
|
CWin32Platform::isWindows95Family()
|
||||||
{
|
{
|
||||||
OSVERSIONINFO version;
|
OSVERSIONINFO version;
|
||||||
version.dwOSVersionInfoSize = sizeof(version);
|
version.dwOSVersionInfoSize = sizeof(version);
|
||||||
|
@ -36,16 +36,20 @@ bool CWin32Platform::isWindows95Family()
|
||||||
return (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
|
return (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWin32Platform::setStatus(
|
void
|
||||||
SERVICE_STATUS_HANDLE handle,
|
CWin32Platform::setStatus(
|
||||||
DWORD state)
|
SERVICE_STATUS_HANDLE handle,
|
||||||
|
DWORD state)
|
||||||
{
|
{
|
||||||
setStatus(handle, state, 0, 0);
|
setStatus(handle, state, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWin32Platform::setStatus(
|
void
|
||||||
SERVICE_STATUS_HANDLE handle,
|
CWin32Platform::setStatus(
|
||||||
DWORD state, DWORD step, DWORD waitHint)
|
SERVICE_STATUS_HANDLE handle,
|
||||||
|
DWORD state,
|
||||||
|
DWORD step,
|
||||||
|
DWORD waitHint)
|
||||||
{
|
{
|
||||||
SERVICE_STATUS status;
|
SERVICE_STATUS status;
|
||||||
status.dwServiceType = SERVICE_WIN32_OWN_PROCESS |
|
status.dwServiceType = SERVICE_WIN32_OWN_PROCESS |
|
||||||
|
@ -61,9 +65,10 @@ void CWin32Platform::setStatus(
|
||||||
SetServiceStatus(handle, &status);
|
SetServiceStatus(handle, &status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWin32Platform::setStatusError(
|
void
|
||||||
SERVICE_STATUS_HANDLE handle,
|
CWin32Platform::setStatusError(
|
||||||
DWORD error)
|
SERVICE_STATUS_HANDLE handle,
|
||||||
|
DWORD error)
|
||||||
{
|
{
|
||||||
SERVICE_STATUS status;
|
SERVICE_STATUS status;
|
||||||
status.dwServiceType = SERVICE_WIN32_OWN_PROCESS |
|
status.dwServiceType = SERVICE_WIN32_OWN_PROCESS |
|
||||||
|
@ -79,11 +84,12 @@ void CWin32Platform::setStatusError(
|
||||||
SetServiceStatus(handle, &status);
|
SetServiceStatus(handle, &status);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWin32Platform::installDaemon(
|
bool
|
||||||
const char* name,
|
CWin32Platform::installDaemon(
|
||||||
const char* description,
|
const char* name,
|
||||||
const char* pathname,
|
const char* description,
|
||||||
const char* commandLine)
|
const char* pathname,
|
||||||
|
const char* commandLine)
|
||||||
{
|
{
|
||||||
// windows 95 family services
|
// windows 95 family services
|
||||||
if (isWindows95Family()) {
|
if (isWindows95Family()) {
|
||||||
|
@ -174,7 +180,9 @@ bool CWin32Platform::installDaemon(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWin32Platform::uninstallDaemon(const char* name)
|
bool
|
||||||
|
CWin32Platform::uninstallDaemon(
|
||||||
|
const char* name)
|
||||||
{
|
{
|
||||||
// windows 95 family services
|
// windows 95 family services
|
||||||
if (isWindows95Family()) {
|
if (isWindows95Family()) {
|
||||||
|
@ -231,9 +239,10 @@ bool CWin32Platform::uninstallDaemon(const char* name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CWin32Platform::daemonize(
|
int
|
||||||
const char* name,
|
CWin32Platform::daemonize(
|
||||||
DaemonFunc func)
|
const char* name,
|
||||||
|
DaemonFunc func)
|
||||||
{
|
{
|
||||||
assert(name != NULL);
|
assert(name != NULL);
|
||||||
assert(func != NULL);
|
assert(func != NULL);
|
||||||
|
@ -294,8 +303,10 @@ int CWin32Platform::daemonize(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CWin32Platform::restart(
|
int
|
||||||
RestartFunc func, int /*minErrorCode*/)
|
CWin32Platform::restart(
|
||||||
|
RestartFunc func,
|
||||||
|
int /*minErrorCode*/)
|
||||||
{
|
{
|
||||||
// FIXME -- start in separate process or thread. note that this
|
// FIXME -- start in separate process or thread. note that this
|
||||||
// isn't too critical as win32 doesn't force us to terminate for
|
// isn't too critical as win32 doesn't force us to terminate for
|
||||||
|
@ -303,7 +314,9 @@ int CWin32Platform::restart(
|
||||||
return func();
|
return func();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CWin32Platform::getBasename(const char* pathname) const
|
const char*
|
||||||
|
CWin32Platform::getBasename(
|
||||||
|
const char* pathname) const
|
||||||
{
|
{
|
||||||
if (pathname == NULL) {
|
if (pathname == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -327,7 +340,8 @@ const char* CWin32Platform::getBasename(const char* pathname) const
|
||||||
return basename;
|
return basename;
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CWin32Platform::getUserDirectory() const
|
CString
|
||||||
|
CWin32Platform::getUserDirectory() const
|
||||||
{
|
{
|
||||||
// try %HOMEPATH%
|
// try %HOMEPATH%
|
||||||
TCHAR dir[MAX_PATH];
|
TCHAR dir[MAX_PATH];
|
||||||
|
@ -370,7 +384,8 @@ CString CWin32Platform::getUserDirectory() const
|
||||||
return "C:";
|
return "C:";
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CWin32Platform::getSystemDirectory() const
|
CString
|
||||||
|
CWin32Platform::getSystemDirectory() const
|
||||||
{
|
{
|
||||||
// get windows directory
|
// get windows directory
|
||||||
char dir[MAX_PATH];
|
char dir[MAX_PATH];
|
||||||
|
@ -383,9 +398,10 @@ CString CWin32Platform::getSystemDirectory() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CWin32Platform::addPathComponent(
|
CString
|
||||||
const CString& prefix,
|
CWin32Platform::addPathComponent(
|
||||||
const CString& suffix) const
|
const CString& prefix,
|
||||||
|
const CString& suffix) const
|
||||||
{
|
{
|
||||||
CString path;
|
CString path;
|
||||||
path.reserve(prefix.size() + 1 + suffix.size());
|
path.reserve(prefix.size() + 1 + suffix.size());
|
||||||
|
@ -399,8 +415,10 @@ CString CWin32Platform::addPathComponent(
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
HKEY CWin32Platform::openKey(
|
HKEY
|
||||||
HKEY key, const char* keyName)
|
CWin32Platform::openKey(
|
||||||
|
HKEY key,
|
||||||
|
const char* keyName)
|
||||||
{
|
{
|
||||||
// open next key
|
// open next key
|
||||||
HKEY newKey;
|
HKEY newKey;
|
||||||
|
@ -422,8 +440,10 @@ HKEY CWin32Platform::openKey(
|
||||||
return newKey;
|
return newKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
HKEY CWin32Platform::openKey(
|
HKEY
|
||||||
HKEY key, const char** keyNames)
|
CWin32Platform::openKey(
|
||||||
|
HKEY key,
|
||||||
|
const char** keyNames)
|
||||||
{
|
{
|
||||||
for (UInt32 i = 0; key != NULL && keyNames[i] != NULL; ++i) {
|
for (UInt32 i = 0; key != NULL && keyNames[i] != NULL; ++i) {
|
||||||
// open next key
|
// open next key
|
||||||
|
@ -432,28 +452,39 @@ HKEY CWin32Platform::openKey(
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWin32Platform::closeKey(HKEY key)
|
void
|
||||||
|
CWin32Platform::closeKey(
|
||||||
|
HKEY key)
|
||||||
{
|
{
|
||||||
assert(key != NULL);
|
assert(key != NULL);
|
||||||
RegCloseKey(key);
|
RegCloseKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWin32Platform::deleteKey(HKEY key, const char* name)
|
void
|
||||||
|
CWin32Platform::deleteKey(
|
||||||
|
HKEY key,
|
||||||
|
const char* name)
|
||||||
{
|
{
|
||||||
assert(key != NULL);
|
assert(key != NULL);
|
||||||
assert(name != NULL);
|
assert(name != NULL);
|
||||||
RegDeleteKey(key, name);
|
RegDeleteKey(key, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWin32Platform::deleteValue(HKEY key, const char* name)
|
void
|
||||||
|
CWin32Platform::deleteValue(
|
||||||
|
HKEY key,
|
||||||
|
const char* name)
|
||||||
{
|
{
|
||||||
assert(key != NULL);
|
assert(key != NULL);
|
||||||
assert(name != NULL);
|
assert(name != NULL);
|
||||||
RegDeleteValue(key, name);
|
RegDeleteValue(key, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWin32Platform::setValue(HKEY key,
|
void
|
||||||
const char* name, const CString& value)
|
CWin32Platform::setValue(
|
||||||
|
HKEY key,
|
||||||
|
const char* name,
|
||||||
|
const CString& value)
|
||||||
{
|
{
|
||||||
assert(key != NULL);
|
assert(key != NULL);
|
||||||
assert(name != NULL);
|
assert(name != NULL);
|
||||||
|
@ -462,8 +493,10 @@ void CWin32Platform::setValue(HKEY key,
|
||||||
value.size() + 1);
|
value.size() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CWin32Platform::readValueString(HKEY key,
|
CString
|
||||||
const char* name)
|
CWin32Platform::readValueString(
|
||||||
|
HKEY key,
|
||||||
|
const char* name)
|
||||||
{
|
{
|
||||||
// get the size of the string
|
// get the size of the string
|
||||||
DWORD type;
|
DWORD type;
|
||||||
|
@ -490,7 +523,8 @@ CString CWin32Platform::readValueString(HKEY key,
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
HKEY CWin32Platform::openNTServicesKey()
|
HKEY
|
||||||
|
CWin32Platform::openNTServicesKey()
|
||||||
{
|
{
|
||||||
static const char* s_keyNames[] = {
|
static const char* s_keyNames[] = {
|
||||||
_T("SYSTEM"),
|
_T("SYSTEM"),
|
||||||
|
@ -502,7 +536,8 @@ HKEY CWin32Platform::openNTServicesKey()
|
||||||
return openKey(HKEY_LOCAL_MACHINE, s_keyNames);
|
return openKey(HKEY_LOCAL_MACHINE, s_keyNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
HKEY CWin32Platform::open95ServicesKey()
|
HKEY
|
||||||
|
CWin32Platform::open95ServicesKey()
|
||||||
{
|
{
|
||||||
static const char* s_keyNames[] = {
|
static const char* s_keyNames[] = {
|
||||||
_T("Software"),
|
_T("Software"),
|
||||||
|
@ -516,7 +551,10 @@ HKEY CWin32Platform::open95ServicesKey()
|
||||||
return openKey(HKEY_LOCAL_MACHINE, s_keyNames);
|
return openKey(HKEY_LOCAL_MACHINE, s_keyNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CWin32Platform::runDaemon(RunFunc run, StopFunc stop)
|
int
|
||||||
|
CWin32Platform::runDaemon(
|
||||||
|
RunFunc run,
|
||||||
|
StopFunc stop)
|
||||||
{
|
{
|
||||||
// should only be called from DaemonFunc
|
// should only be called from DaemonFunc
|
||||||
assert(m_serviceMutex != NULL);
|
assert(m_serviceMutex != NULL);
|
||||||
|
@ -595,8 +633,10 @@ int CWin32Platform::runDaemon(RunFunc run, StopFunc stop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWin32Platform::serviceMain(
|
void
|
||||||
DWORD argc, LPTSTR* argvIn)
|
CWin32Platform::serviceMain(
|
||||||
|
DWORD argc,
|
||||||
|
LPTSTR* argvIn)
|
||||||
{
|
{
|
||||||
typedef std::vector<LPCTSTR> ArgList;
|
typedef std::vector<LPCTSTR> ArgList;
|
||||||
typedef std::vector<CString> Arguments;
|
typedef std::vector<CString> Arguments;
|
||||||
|
@ -718,13 +758,17 @@ void CWin32Platform::serviceMain(
|
||||||
// FIXME -- close event log?
|
// FIXME -- close event log?
|
||||||
}
|
}
|
||||||
|
|
||||||
void WINAPI CWin32Platform::serviceMainEntry(
|
void WINAPI
|
||||||
DWORD argc, LPTSTR* argv)
|
CWin32Platform::serviceMainEntry(
|
||||||
|
DWORD argc,
|
||||||
|
LPTSTR* argv)
|
||||||
{
|
{
|
||||||
s_daemonPlatform->serviceMain(argc, argv);
|
s_daemonPlatform->serviceMain(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWin32Platform::serviceHandler(DWORD ctrl)
|
void
|
||||||
|
CWin32Platform::serviceHandler(
|
||||||
|
DWORD ctrl)
|
||||||
{
|
{
|
||||||
assert(m_serviceMutex != NULL);
|
assert(m_serviceMutex != NULL);
|
||||||
assert(m_serviceState != NULL);
|
assert(m_serviceState != NULL);
|
||||||
|
@ -796,13 +840,17 @@ void CWin32Platform::serviceHandler(DWORD ctrl)
|
||||||
setStatus(m_statusHandle, *m_serviceState);
|
setStatus(m_statusHandle, *m_serviceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WINAPI CWin32Platform::serviceHandlerEntry(DWORD ctrl)
|
void WINAPI
|
||||||
|
CWin32Platform::serviceHandlerEntry(
|
||||||
|
DWORD ctrl)
|
||||||
{
|
{
|
||||||
s_daemonPlatform->serviceHandler(ctrl);
|
s_daemonPlatform->serviceHandler(ctrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWin32Platform::serviceLogger(
|
bool
|
||||||
int priority, const char* msg)
|
CWin32Platform::serviceLogger(
|
||||||
|
int priority,
|
||||||
|
const char* msg)
|
||||||
{
|
{
|
||||||
if (s_eventLog == NULL) {
|
if (s_eventLog == NULL) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -21,7 +21,7 @@ public:
|
||||||
// utility for calling SetServiceStatus()
|
// utility for calling SetServiceStatus()
|
||||||
static void setStatus(SERVICE_STATUS_HANDLE, DWORD state);
|
static void setStatus(SERVICE_STATUS_HANDLE, DWORD state);
|
||||||
static void setStatus(SERVICE_STATUS_HANDLE,
|
static void setStatus(SERVICE_STATUS_HANDLE,
|
||||||
DWORD state, DWORD step, DWORD waitHint);
|
DWORD state, DWORD step, DWORD waitHint);
|
||||||
static void setStatusError(SERVICE_STATUS_HANDLE, DWORD error);
|
static void setStatusError(SERVICE_STATUS_HANDLE, DWORD error);
|
||||||
|
|
||||||
// run a service. the RunFunc should unlock the passed in mutex
|
// run a service. the RunFunc should unlock the passed in mutex
|
||||||
|
@ -43,9 +43,9 @@ public:
|
||||||
|
|
||||||
// IPlatform overrides
|
// IPlatform overrides
|
||||||
virtual bool installDaemon(const char* name,
|
virtual bool installDaemon(const char* name,
|
||||||
const char* description,
|
const char* description,
|
||||||
const char* pathname,
|
const char* pathname,
|
||||||
const char* commandLine);
|
const char* commandLine);
|
||||||
virtual bool uninstallDaemon(const char* name);
|
virtual bool uninstallDaemon(const char* name);
|
||||||
virtual int daemonize(const char* name, DaemonFunc);
|
virtual int daemonize(const char* name, DaemonFunc);
|
||||||
virtual int restart(RestartFunc, int minErrorCode);
|
virtual int restart(RestartFunc, int minErrorCode);
|
||||||
|
@ -53,8 +53,8 @@ public:
|
||||||
virtual CString getUserDirectory() const;
|
virtual CString getUserDirectory() const;
|
||||||
virtual CString getSystemDirectory() const;
|
virtual CString getSystemDirectory() const;
|
||||||
virtual CString addPathComponent(
|
virtual CString addPathComponent(
|
||||||
const CString& prefix,
|
const CString& prefix,
|
||||||
const CString& suffix) const;
|
const CString& suffix) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static HKEY openKey(HKEY parent, const char*);
|
static HKEY openKey(HKEY parent, const char*);
|
||||||
|
@ -63,7 +63,7 @@ private:
|
||||||
static void deleteKey(HKEY, const char* name);
|
static void deleteKey(HKEY, const char* name);
|
||||||
static void deleteValue(HKEY, const char* name);
|
static void deleteValue(HKEY, const char* name);
|
||||||
static void setValue(HKEY, const char* name,
|
static void setValue(HKEY, const char* name,
|
||||||
const CString& value);
|
const CString& value);
|
||||||
static CString readValueString(HKEY, const char* name);
|
static CString readValueString(HKEY, const char* name);
|
||||||
static HKEY openNTServicesKey();
|
static HKEY openNTServicesKey();
|
||||||
static HKEY open95ServicesKey();
|
static HKEY open95ServicesKey();
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
#include "CXWindowsClipboard.h"
|
#include "CXWindowsClipboard.h"
|
||||||
#include "CXWindowsUtil.h"
|
#include "CXWindowsUtil.h"
|
||||||
#include "CLog.h"
|
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
|
#include "CLog.h"
|
||||||
#include "TMethodJob.h"
|
#include "TMethodJob.h"
|
||||||
#include <stdio.h>
|
#include <cstdio>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
|
||||||
//
|
//
|
||||||
// CXWindowsClipboard
|
// CXWindowsClipboard
|
||||||
//
|
//
|
||||||
|
|
||||||
CXWindowsClipboard::CXWindowsClipboard(Display* display,
|
CXWindowsClipboard::CXWindowsClipboard(
|
||||||
Window window, ClipboardID id) :
|
Display* display,
|
||||||
m_display(display),
|
Window window,
|
||||||
m_window(window),
|
ClipboardID id) :
|
||||||
m_id(id),
|
m_display(display),
|
||||||
m_open(false),
|
m_window(window),
|
||||||
m_time(0),
|
m_id(id),
|
||||||
m_owner(false),
|
m_open(false),
|
||||||
m_timeOwned(0),
|
m_time(0),
|
||||||
m_timeLost(0)
|
m_owner(false),
|
||||||
|
m_timeOwned(0),
|
||||||
|
m_timeLost(0)
|
||||||
{
|
{
|
||||||
// get some atoms
|
// get some atoms
|
||||||
m_atomTargets = XInternAtom(m_display, "TARGETS", False);
|
m_atomTargets = XInternAtom(m_display, "TARGETS", False);
|
||||||
|
@ -60,7 +62,9 @@ CXWindowsClipboard::~CXWindowsClipboard()
|
||||||
clearReplies();
|
clearReplies();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::lost(Time time)
|
void
|
||||||
|
CXWindowsClipboard::lost(
|
||||||
|
Time time)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG "lost clipboard %d ownership at %d", m_id, time));
|
log((CLOG_DEBUG "lost clipboard %d ownership at %d", m_id, time));
|
||||||
if (m_owner) {
|
if (m_owner) {
|
||||||
|
@ -70,10 +74,13 @@ void CXWindowsClipboard::lost(Time time)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::addRequest(
|
void
|
||||||
Window owner,
|
CXWindowsClipboard::addRequest(
|
||||||
Window requestor, Atom target,
|
Window owner,
|
||||||
::Time time, Atom property)
|
Window requestor,
|
||||||
|
Atom target,
|
||||||
|
::Time time,
|
||||||
|
Atom property)
|
||||||
{
|
{
|
||||||
// must be for our window and we must have owned the selection
|
// must be for our window and we must have owned the selection
|
||||||
// at the given time.
|
// at the given time.
|
||||||
|
@ -110,9 +117,12 @@ void CXWindowsClipboard::addRequest(
|
||||||
pushReplies();
|
pushReplies();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsClipboard::addSimpleRequest(
|
bool
|
||||||
Window requestor, Atom target,
|
CXWindowsClipboard::addSimpleRequest(
|
||||||
::Time time, Atom property)
|
Window requestor,
|
||||||
|
Atom target,
|
||||||
|
::Time time,
|
||||||
|
Atom property)
|
||||||
{
|
{
|
||||||
// obsolete requestors may supply a None property. in
|
// obsolete requestors may supply a None property. in
|
||||||
// that case we use the target as the property to store
|
// that case we use the target as the property to store
|
||||||
|
@ -151,9 +161,11 @@ bool CXWindowsClipboard::addSimpleRequest(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsClipboard::processRequest(
|
bool
|
||||||
Window requestor,
|
CXWindowsClipboard::processRequest(
|
||||||
::Time /*time*/, Atom property)
|
Window requestor,
|
||||||
|
::Time /*time*/,
|
||||||
|
Atom property)
|
||||||
{
|
{
|
||||||
CReplyMap::iterator index = m_replies.find(requestor);
|
CReplyMap::iterator index = m_replies.find(requestor);
|
||||||
if (index == m_replies.end()) {
|
if (index == m_replies.end()) {
|
||||||
|
@ -179,8 +191,9 @@ bool CXWindowsClipboard::processRequest(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsClipboard::destroyRequest(
|
bool
|
||||||
Window requestor)
|
CXWindowsClipboard::destroyRequest(
|
||||||
|
Window requestor)
|
||||||
{
|
{
|
||||||
CReplyMap::iterator index = m_replies.find(requestor);
|
CReplyMap::iterator index = m_replies.find(requestor);
|
||||||
if (index == m_replies.end()) {
|
if (index == m_replies.end()) {
|
||||||
|
@ -198,17 +211,20 @@ bool CXWindowsClipboard::destroyRequest(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window CXWindowsClipboard::getWindow() const
|
Window
|
||||||
|
CXWindowsClipboard::getWindow() const
|
||||||
{
|
{
|
||||||
return m_window;
|
return m_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
Atom CXWindowsClipboard::getSelection() const
|
Atom
|
||||||
|
CXWindowsClipboard::getSelection() const
|
||||||
{
|
{
|
||||||
return m_selection;
|
return m_selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsClipboard::empty()
|
bool
|
||||||
|
CXWindowsClipboard::empty()
|
||||||
{
|
{
|
||||||
assert(m_open);
|
assert(m_open);
|
||||||
|
|
||||||
|
@ -240,8 +256,10 @@ bool CXWindowsClipboard::empty()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::add(
|
void
|
||||||
EFormat format, const CString& data)
|
CXWindowsClipboard::add(
|
||||||
|
EFormat format,
|
||||||
|
const CString& data)
|
||||||
{
|
{
|
||||||
assert(m_open);
|
assert(m_open);
|
||||||
assert(m_owner);
|
assert(m_owner);
|
||||||
|
@ -254,7 +272,9 @@ void CXWindowsClipboard::add(
|
||||||
// FIXME -- set motif clipboard item?
|
// FIXME -- set motif clipboard item?
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsClipboard::open(Time time) const
|
bool
|
||||||
|
CXWindowsClipboard::open(
|
||||||
|
Time time) const
|
||||||
{
|
{
|
||||||
assert(!m_open);
|
assert(!m_open);
|
||||||
|
|
||||||
|
@ -304,7 +324,8 @@ bool CXWindowsClipboard::open(Time time) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::close() const
|
void
|
||||||
|
CXWindowsClipboard::close() const
|
||||||
{
|
{
|
||||||
assert(m_open);
|
assert(m_open);
|
||||||
|
|
||||||
|
@ -319,12 +340,15 @@ void CXWindowsClipboard::close() const
|
||||||
m_open = false;
|
m_open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
IClipboard::Time CXWindowsClipboard::getTime() const
|
IClipboard::Time
|
||||||
|
CXWindowsClipboard::getTime() const
|
||||||
{
|
{
|
||||||
return m_timeOwned;
|
return m_timeOwned;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsClipboard::has(EFormat format) const
|
bool
|
||||||
|
CXWindowsClipboard::has(
|
||||||
|
EFormat format) const
|
||||||
{
|
{
|
||||||
assert(m_open);
|
assert(m_open);
|
||||||
|
|
||||||
|
@ -332,7 +356,9 @@ bool CXWindowsClipboard::has(EFormat format) const
|
||||||
return m_added[format];
|
return m_added[format];
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CXWindowsClipboard::get(EFormat format) const
|
CString
|
||||||
|
CXWindowsClipboard::get(
|
||||||
|
EFormat format) const
|
||||||
{
|
{
|
||||||
assert(m_open);
|
assert(m_open);
|
||||||
|
|
||||||
|
@ -340,23 +366,28 @@ CString CXWindowsClipboard::get(EFormat format) const
|
||||||
return m_data[format];
|
return m_data[format];
|
||||||
}
|
}
|
||||||
|
|
||||||
IClipboard::EFormat CXWindowsClipboard::getFormat(Atom src) const
|
IClipboard::EFormat
|
||||||
|
CXWindowsClipboard::getFormat(
|
||||||
|
Atom src) const
|
||||||
{
|
{
|
||||||
// FIXME -- handle more formats (especially mime-type-like formats
|
// FIXME -- handle more formats (especially mime-type-like formats
|
||||||
// and various character encodings like unicode).
|
// and various character encodings like unicode).
|
||||||
if (src == m_atomString ||
|
if (src == m_atomString ||
|
||||||
src == m_atomText /*||
|
src == m_atomText /*||
|
||||||
src == m_atomCompoundText*/)
|
src == m_atomCompoundText*/) {
|
||||||
return IClipboard::kText;
|
return IClipboard::kText;
|
||||||
|
}
|
||||||
return IClipboard::kNumFormats;
|
return IClipboard::kNumFormats;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::clearCache() const
|
void
|
||||||
|
CXWindowsClipboard::clearCache() const
|
||||||
{
|
{
|
||||||
const_cast<CXWindowsClipboard*>(this)->doClearCache();
|
const_cast<CXWindowsClipboard*>(this)->doClearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::doClearCache()
|
void
|
||||||
|
CXWindowsClipboard::doClearCache()
|
||||||
{
|
{
|
||||||
m_cached = false;
|
m_cached = false;
|
||||||
for (SInt32 index = 0; index < kNumFormats; ++index) {
|
for (SInt32 index = 0; index < kNumFormats; ++index) {
|
||||||
|
@ -365,7 +396,8 @@ void CXWindowsClipboard::doClearCache()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::fillCache() const
|
void
|
||||||
|
CXWindowsClipboard::fillCache() const
|
||||||
{
|
{
|
||||||
// get the selection data if not already cached
|
// get the selection data if not already cached
|
||||||
if (!m_cached) {
|
if (!m_cached) {
|
||||||
|
@ -373,7 +405,8 @@ void CXWindowsClipboard::fillCache() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::doFillCache()
|
void
|
||||||
|
CXWindowsClipboard::doFillCache()
|
||||||
{
|
{
|
||||||
if (m_motif) {
|
if (m_motif) {
|
||||||
motifFillCache();
|
motifFillCache();
|
||||||
|
@ -385,7 +418,8 @@ void CXWindowsClipboard::doFillCache()
|
||||||
m_cacheTime = m_timeOwned;
|
m_cacheTime = m_timeOwned;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::icccmFillCache()
|
void
|
||||||
|
CXWindowsClipboard::icccmFillCache()
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG "ICCCM fill clipboard %d", m_id));
|
log((CLOG_DEBUG "ICCCM fill clipboard %d", m_id));
|
||||||
|
|
||||||
|
@ -447,10 +481,11 @@ void CXWindowsClipboard::icccmFillCache()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsClipboard::icccmGetSelection(
|
bool
|
||||||
Atom target,
|
CXWindowsClipboard::icccmGetSelection(
|
||||||
Atom* actualTarget,
|
Atom target,
|
||||||
CString* data) const
|
Atom* actualTarget,
|
||||||
|
CString* data) const
|
||||||
{
|
{
|
||||||
assert(actualTarget != NULL);
|
assert(actualTarget != NULL);
|
||||||
assert(data != NULL);
|
assert(data != NULL);
|
||||||
|
@ -470,7 +505,8 @@ bool CXWindowsClipboard::icccmGetSelection(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IClipboard::Time CXWindowsClipboard::icccmGetTime() const
|
IClipboard::Time
|
||||||
|
CXWindowsClipboard::icccmGetTime() const
|
||||||
{
|
{
|
||||||
Atom actualTarget;
|
Atom actualTarget;
|
||||||
CString data;
|
CString data;
|
||||||
|
@ -487,7 +523,8 @@ IClipboard::Time CXWindowsClipboard::icccmGetTime() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsClipboard::motifLockClipboard() const
|
bool
|
||||||
|
CXWindowsClipboard::motifLockClipboard() const
|
||||||
{
|
{
|
||||||
// fail if anybody owns the lock (even us, so this is non-recursive)
|
// fail if anybody owns the lock (even us, so this is non-recursive)
|
||||||
Window lockOwner = XGetSelectionOwner(m_display, m_atomMotifClipLock);
|
Window lockOwner = XGetSelectionOwner(m_display, m_atomMotifClipLock);
|
||||||
|
@ -510,7 +547,8 @@ bool CXWindowsClipboard::motifLockClipboard() const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::motifUnlockClipboard() const
|
void
|
||||||
|
CXWindowsClipboard::motifUnlockClipboard() const
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "unlocked motif clipboard"));
|
log((CLOG_DEBUG1 "unlocked motif clipboard"));
|
||||||
|
|
||||||
|
@ -525,7 +563,8 @@ void CXWindowsClipboard::motifUnlockClipboard() const
|
||||||
XSetSelectionOwner(m_display, m_atomMotifClipLock, None, time);
|
XSetSelectionOwner(m_display, m_atomMotifClipLock, None, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsClipboard::motifOwnsClipboard() const
|
bool
|
||||||
|
CXWindowsClipboard::motifOwnsClipboard() const
|
||||||
{
|
{
|
||||||
// get the current selection owner
|
// get the current selection owner
|
||||||
// FIXME -- this can't be right. even if the window is destroyed
|
// FIXME -- this can't be right. even if the window is destroyed
|
||||||
|
@ -563,7 +602,8 @@ bool CXWindowsClipboard::motifOwnsClipboard() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::motifFillCache()
|
void
|
||||||
|
CXWindowsClipboard::motifFillCache()
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG "Motif fill clipboard %d", m_id));
|
log((CLOG_DEBUG "Motif fill clipboard %d", m_id));
|
||||||
|
|
||||||
|
@ -677,14 +717,18 @@ void CXWindowsClipboard::motifFillCache()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IClipboard::Time CXWindowsClipboard::motifGetTime() const
|
IClipboard::Time
|
||||||
|
CXWindowsClipboard::motifGetTime() const
|
||||||
{
|
{
|
||||||
// FIXME -- does Motif report this?
|
// FIXME -- does Motif report this?
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsClipboard::insertMultipleReply(
|
bool
|
||||||
Window requestor, ::Time time, Atom property)
|
CXWindowsClipboard::insertMultipleReply(
|
||||||
|
Window requestor,
|
||||||
|
::Time time,
|
||||||
|
Atom property)
|
||||||
{
|
{
|
||||||
// get the requested targets
|
// get the requested targets
|
||||||
Atom target;
|
Atom target;
|
||||||
|
@ -735,7 +779,9 @@ bool CXWindowsClipboard::insertMultipleReply(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::insertReply(CReply* reply)
|
void
|
||||||
|
CXWindowsClipboard::insertReply(
|
||||||
|
CReply* reply)
|
||||||
{
|
{
|
||||||
assert(reply != NULL);
|
assert(reply != NULL);
|
||||||
|
|
||||||
|
@ -780,7 +826,8 @@ void CXWindowsClipboard::insertReply(CReply* reply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::pushReplies()
|
void
|
||||||
|
CXWindowsClipboard::pushReplies()
|
||||||
{
|
{
|
||||||
// send the first reply for each window if that reply hasn't
|
// send the first reply for each window if that reply hasn't
|
||||||
// been sent yet.
|
// been sent yet.
|
||||||
|
@ -793,10 +840,11 @@ void CXWindowsClipboard::pushReplies()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::pushReplies(
|
void
|
||||||
CReplyMap::iterator mapIndex,
|
CXWindowsClipboard::pushReplies(
|
||||||
CReplyList& replies,
|
CReplyMap::iterator mapIndex,
|
||||||
CReplyList::iterator index)
|
CReplyList& replies,
|
||||||
|
CReplyList::iterator index)
|
||||||
{
|
{
|
||||||
CReply* reply = *index;
|
CReply* reply = *index;
|
||||||
while (sendReply(reply)) {
|
while (sendReply(reply)) {
|
||||||
|
@ -821,7 +869,9 @@ void CXWindowsClipboard::pushReplies(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsClipboard::sendReply(CReply* reply)
|
bool
|
||||||
|
CXWindowsClipboard::sendReply(
|
||||||
|
CReply* reply)
|
||||||
{
|
{
|
||||||
assert(reply != NULL);
|
assert(reply != NULL);
|
||||||
|
|
||||||
|
@ -943,7 +993,8 @@ bool CXWindowsClipboard::sendReply(CReply* reply)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::clearReplies()
|
void
|
||||||
|
CXWindowsClipboard::clearReplies()
|
||||||
{
|
{
|
||||||
for (CReplyMap::iterator index = m_replies.begin();
|
for (CReplyMap::iterator index = m_replies.begin();
|
||||||
index != m_replies.end(); ++index) {
|
index != m_replies.end(); ++index) {
|
||||||
|
@ -953,7 +1004,9 @@ void CXWindowsClipboard::clearReplies()
|
||||||
m_eventMasks.clear();
|
m_eventMasks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::clearReplies(CReplyList& replies)
|
void
|
||||||
|
CXWindowsClipboard::clearReplies(
|
||||||
|
CReplyList& replies)
|
||||||
{
|
{
|
||||||
for (CReplyList::iterator index = replies.begin();
|
for (CReplyList::iterator index = replies.begin();
|
||||||
index != replies.end(); ++index) {
|
index != replies.end(); ++index) {
|
||||||
|
@ -962,9 +1015,13 @@ void CXWindowsClipboard::clearReplies(CReplyList& replies)
|
||||||
replies.clear();
|
replies.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::sendNotify(
|
void
|
||||||
Window requestor, Atom selection,
|
CXWindowsClipboard::sendNotify(
|
||||||
Atom target, Atom property, Time time)
|
Window requestor,
|
||||||
|
Atom selection,
|
||||||
|
Atom target,
|
||||||
|
Atom property,
|
||||||
|
Time time)
|
||||||
{
|
{
|
||||||
XEvent event;
|
XEvent event;
|
||||||
event.xselection.type = SelectionNotify;
|
event.xselection.type = SelectionNotify;
|
||||||
|
@ -978,26 +1035,33 @@ void CXWindowsClipboard::sendNotify(
|
||||||
XSendEvent(m_display, requestor, False, 0, &event);
|
XSendEvent(m_display, requestor, False, 0, &event);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsClipboard::wasOwnedAtTime(
|
bool
|
||||||
::Time time) const
|
CXWindowsClipboard::wasOwnedAtTime(
|
||||||
|
::Time time) const
|
||||||
{
|
{
|
||||||
// not owned if we've never owned the selection
|
// not owned if we've never owned the selection
|
||||||
if (m_timeOwned == 0)
|
if (m_timeOwned == 0) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// if time is CurrentTime then return true if we still own the
|
// if time is CurrentTime then return true if we still own the
|
||||||
// selection and false if we do not. else if we still own the
|
// selection and false if we do not. else if we still own the
|
||||||
// selection then get the current time, otherwise use
|
// selection then get the current time, otherwise use
|
||||||
// m_timeLost as the end time.
|
// m_timeLost as the end time.
|
||||||
Time lost = m_timeLost;
|
Time lost = m_timeLost;
|
||||||
if (m_timeLost == 0)
|
if (m_timeLost == 0) {
|
||||||
if (time == CurrentTime)
|
if (time == CurrentTime) {
|
||||||
return true;
|
return true;
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
lost = CXWindowsUtil::getCurrentTime(m_display, m_window);
|
lost = CXWindowsUtil::getCurrentTime(m_display, m_window);
|
||||||
else
|
}
|
||||||
if (time == CurrentTime)
|
}
|
||||||
|
else {
|
||||||
|
if (time == CurrentTime) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// compare time to range
|
// compare time to range
|
||||||
Time duration = lost - m_timeOwned;
|
Time duration = lost - m_timeOwned;
|
||||||
|
@ -1005,8 +1069,10 @@ bool CXWindowsClipboard::wasOwnedAtTime(
|
||||||
return (/*when >= 0 &&*/ when < duration);
|
return (/*when >= 0 &&*/ when < duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
Atom CXWindowsClipboard::getTargetsData(
|
Atom
|
||||||
CString& data, int* format) const
|
CXWindowsClipboard::getTargetsData(
|
||||||
|
CString& data,
|
||||||
|
int* format) const
|
||||||
{
|
{
|
||||||
assert(format != NULL);
|
assert(format != NULL);
|
||||||
|
|
||||||
|
@ -1029,8 +1095,10 @@ Atom CXWindowsClipboard::getTargetsData(
|
||||||
return m_atomTargets;
|
return m_atomTargets;
|
||||||
}
|
}
|
||||||
|
|
||||||
Atom CXWindowsClipboard::getTimestampData(
|
Atom
|
||||||
CString& data, int* format) const
|
CXWindowsClipboard::getTimestampData(
|
||||||
|
CString& data,
|
||||||
|
int* format) const
|
||||||
{
|
{
|
||||||
assert(format != NULL);
|
assert(format != NULL);
|
||||||
|
|
||||||
|
@ -1040,8 +1108,10 @@ Atom CXWindowsClipboard::getTimestampData(
|
||||||
return m_atomTimestamp;
|
return m_atomTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
Atom CXWindowsClipboard::getStringData(
|
Atom
|
||||||
CString& data, int* format) const
|
CXWindowsClipboard::getStringData(
|
||||||
|
CString& data,
|
||||||
|
int* format) const
|
||||||
{
|
{
|
||||||
assert(format != NULL);
|
assert(format != NULL);
|
||||||
|
|
||||||
|
@ -1061,17 +1131,19 @@ Atom CXWindowsClipboard::getStringData(
|
||||||
//
|
//
|
||||||
|
|
||||||
CXWindowsClipboard::CICCCMGetClipboard::CICCCMGetClipboard(
|
CXWindowsClipboard::CICCCMGetClipboard::CICCCMGetClipboard(
|
||||||
Window requestor, Time time, Atom property) :
|
Window requestor,
|
||||||
m_requestor(requestor),
|
Time time,
|
||||||
m_time(time),
|
Atom property) :
|
||||||
m_property(property),
|
m_requestor(requestor),
|
||||||
m_incr(false),
|
m_time(time),
|
||||||
m_failed(false),
|
m_property(property),
|
||||||
m_done(false),
|
m_incr(false),
|
||||||
m_reading(false),
|
m_failed(false),
|
||||||
m_data(NULL),
|
m_done(false),
|
||||||
m_actualTarget(NULL),
|
m_reading(false),
|
||||||
m_error(false)
|
m_data(NULL),
|
||||||
|
m_actualTarget(NULL),
|
||||||
|
m_error(false)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -1081,10 +1153,13 @@ CXWindowsClipboard::CICCCMGetClipboard::~CICCCMGetClipboard()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsClipboard::CICCCMGetClipboard::readClipboard(
|
bool
|
||||||
Display* display,
|
CXWindowsClipboard::CICCCMGetClipboard::readClipboard(
|
||||||
Atom selection, Atom target,
|
Display* display,
|
||||||
Atom* actualTarget, CString* data)
|
Atom selection,
|
||||||
|
Atom target,
|
||||||
|
Atom* actualTarget,
|
||||||
|
CString* data)
|
||||||
{
|
{
|
||||||
assert(actualTarget != NULL);
|
assert(actualTarget != NULL);
|
||||||
assert(data != NULL);
|
assert(data != NULL);
|
||||||
|
@ -1139,9 +1214,10 @@ bool CXWindowsClipboard::CICCCMGetClipboard::readClipboard(
|
||||||
return !m_failed;
|
return !m_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsClipboard::CICCCMGetClipboard::doEventPredicate(
|
bool
|
||||||
Display* display,
|
CXWindowsClipboard::CICCCMGetClipboard::doEventPredicate(
|
||||||
XEvent* xevent)
|
Display* display,
|
||||||
|
XEvent* xevent)
|
||||||
{
|
{
|
||||||
// process event
|
// process event
|
||||||
switch (xevent->type) {
|
switch (xevent->type) {
|
||||||
|
@ -1276,17 +1352,19 @@ log((CLOG_INFO " INCR secondary chunk")); // FIXME
|
||||||
return !m_incr;
|
return !m_incr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool CXWindowsClipboard::CICCCMGetClipboard::eventPredicate(
|
Bool
|
||||||
Display* display,
|
CXWindowsClipboard::CICCCMGetClipboard::eventPredicate(
|
||||||
XEvent* xevent,
|
Display* display,
|
||||||
XPointer arg)
|
XEvent* xevent,
|
||||||
|
XPointer arg)
|
||||||
{
|
{
|
||||||
CICCCMGetClipboard* self = reinterpret_cast<CICCCMGetClipboard*>(arg);
|
CICCCMGetClipboard* self = reinterpret_cast<CICCCMGetClipboard*>(arg);
|
||||||
return self->doEventPredicate(display, xevent) ? True : False;
|
return self->doEventPredicate(display, xevent) ? True : False;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClipboard::CICCCMGetClipboard::timeout(
|
void
|
||||||
void* vdisplay)
|
CXWindowsClipboard::CICCCMGetClipboard::timeout(
|
||||||
|
void* vdisplay)
|
||||||
{
|
{
|
||||||
// wait
|
// wait
|
||||||
CThread::sleep(0.2); // FIXME -- is this too short?
|
CThread::sleep(0.2); // FIXME -- is this too short?
|
||||||
|
@ -1308,35 +1386,42 @@ void CXWindowsClipboard::CICCCMGetClipboard::timeout(
|
||||||
// CXWindowsClipboard::CReply
|
// CXWindowsClipboard::CReply
|
||||||
//
|
//
|
||||||
|
|
||||||
CXWindowsClipboard::CReply::CReply(Window requestor,
|
CXWindowsClipboard::CReply::CReply(
|
||||||
Atom target, ::Time time) :
|
Window requestor,
|
||||||
m_requestor(requestor),
|
Atom target,
|
||||||
m_target(target),
|
::Time time) :
|
||||||
m_time(time),
|
m_requestor(requestor),
|
||||||
m_property(None),
|
m_target(target),
|
||||||
m_replied(false),
|
m_time(time),
|
||||||
m_done(false),
|
m_property(None),
|
||||||
m_data(),
|
m_replied(false),
|
||||||
m_type(None),
|
m_done(false),
|
||||||
m_format(32),
|
m_data(),
|
||||||
m_ptr(0)
|
m_type(None),
|
||||||
|
m_format(32),
|
||||||
|
m_ptr(0)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
CXWindowsClipboard::CReply::CReply(Window requestor,
|
CXWindowsClipboard::CReply::CReply(
|
||||||
Atom target, ::Time time, Atom property,
|
Window requestor,
|
||||||
const CString& data, Atom type, int format) :
|
Atom target,
|
||||||
m_requestor(requestor),
|
::Time time,
|
||||||
m_target(target),
|
Atom property,
|
||||||
m_time(time),
|
const CString& data,
|
||||||
m_property(property),
|
Atom type,
|
||||||
m_replied(false),
|
int format) :
|
||||||
m_done(false),
|
m_requestor(requestor),
|
||||||
m_data(data),
|
m_target(target),
|
||||||
m_type(type),
|
m_time(time),
|
||||||
m_format(format),
|
m_property(property),
|
||||||
m_ptr(0)
|
m_replied(false),
|
||||||
|
m_done(false),
|
||||||
|
m_data(data),
|
||||||
|
m_type(type),
|
||||||
|
m_format(format),
|
||||||
|
m_ptr(0)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "IClipboard.h"
|
#include "IClipboard.h"
|
||||||
#include "ClipboardTypes.h"
|
#include "ClipboardTypes.h"
|
||||||
#include "CString.h"
|
|
||||||
#include "stdmap.h"
|
#include "stdmap.h"
|
||||||
#include "stdlist.h"
|
#include "stdlist.h"
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
@ -20,13 +19,13 @@ public:
|
||||||
// owner window isn't this clipboard's window then this simply
|
// owner window isn't this clipboard's window then this simply
|
||||||
// sends a failure event to the requestor.
|
// sends a failure event to the requestor.
|
||||||
void addRequest(Window owner,
|
void addRequest(Window owner,
|
||||||
Window requestor, Atom target,
|
Window requestor, Atom target,
|
||||||
::Time time, Atom property);
|
::Time time, Atom property);
|
||||||
|
|
||||||
// continue processing a selection request. returns true if the
|
// continue processing a selection request. returns true if the
|
||||||
// request was handled, false if the request was unknown.
|
// request was handled, false if the request was unknown.
|
||||||
bool processRequest(Window requestor,
|
bool processRequest(Window requestor,
|
||||||
::Time time, Atom property);
|
::Time time, Atom property);
|
||||||
|
|
||||||
// terminate a selection request. returns true iff the request
|
// terminate a selection request. returns true iff the request
|
||||||
// was known and handled.
|
// was known and handled.
|
||||||
|
@ -56,8 +55,8 @@ private:
|
||||||
// could be performed, false otherwise. in either case, the
|
// could be performed, false otherwise. in either case, the
|
||||||
// reply is inserted.
|
// reply is inserted.
|
||||||
bool addSimpleRequest(
|
bool addSimpleRequest(
|
||||||
Window requestor, Atom target,
|
Window requestor, Atom target,
|
||||||
::Time time, Atom property);
|
::Time time, Atom property);
|
||||||
|
|
||||||
// clear the cache, resetting the cached flag and the added flag for
|
// clear the cache, resetting the cached flag and the added flag for
|
||||||
// each format.
|
// each format.
|
||||||
|
@ -71,8 +70,8 @@ private:
|
||||||
// ICCCM interoperability methods
|
// ICCCM interoperability methods
|
||||||
void icccmFillCache();
|
void icccmFillCache();
|
||||||
bool icccmGetSelection(Atom target,
|
bool icccmGetSelection(Atom target,
|
||||||
Atom* actualTarget,
|
Atom* actualTarget,
|
||||||
CString* data) const;
|
CString* data) const;
|
||||||
Time icccmGetTime() const;
|
Time icccmGetTime() const;
|
||||||
|
|
||||||
// motif interoperability methods
|
// motif interoperability methods
|
||||||
|
@ -97,15 +96,15 @@ private:
|
||||||
// true iff the conversion was successful or the conversion
|
// true iff the conversion was successful or the conversion
|
||||||
// cannot be performed (in which case *actualTarget == None).
|
// cannot be performed (in which case *actualTarget == None).
|
||||||
bool readClipboard(Display* display,
|
bool readClipboard(Display* display,
|
||||||
Atom selection, Atom target,
|
Atom selection, Atom target,
|
||||||
Atom* actualTarget, CString* data);
|
Atom* actualTarget, CString* data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool doEventPredicate(Display* display,
|
bool doEventPredicate(Display* display,
|
||||||
XEvent* event);
|
XEvent* event);
|
||||||
static Bool eventPredicate(Display* display,
|
static Bool eventPredicate(Display* display,
|
||||||
XEvent* event,
|
XEvent* event,
|
||||||
XPointer arg);
|
XPointer arg);
|
||||||
void timeout(void*);
|
void timeout(void*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -177,7 +176,7 @@ private:
|
||||||
public:
|
public:
|
||||||
CReply(Window, Atom target, ::Time);
|
CReply(Window, Atom target, ::Time);
|
||||||
CReply(Window, Atom target, ::Time, Atom property,
|
CReply(Window, Atom target, ::Time, Atom property,
|
||||||
const CString& data, Atom type, int format);
|
const CString& data, Atom type, int format);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// information about the request
|
// information about the request
|
||||||
|
@ -209,12 +208,12 @@ private:
|
||||||
void insertReply(CReply*);
|
void insertReply(CReply*);
|
||||||
void pushReplies();
|
void pushReplies();
|
||||||
void pushReplies(CReplyMap::iterator,
|
void pushReplies(CReplyMap::iterator,
|
||||||
CReplyList&, CReplyList::iterator);
|
CReplyList&, CReplyList::iterator);
|
||||||
bool sendReply(CReply*);
|
bool sendReply(CReply*);
|
||||||
void clearReplies();
|
void clearReplies();
|
||||||
void clearReplies(CReplyList&);
|
void clearReplies(CReplyList&);
|
||||||
void sendNotify(Window requestor, Atom selection,
|
void sendNotify(Window requestor, Atom selection,
|
||||||
Atom target, Atom property, Time time);
|
Atom target, Atom property, Time time);
|
||||||
bool wasOwnedAtTime(::Time) const;
|
bool wasOwnedAtTime(::Time) const;
|
||||||
|
|
||||||
// data conversion methods
|
// data conversion methods
|
||||||
|
|
|
@ -2,14 +2,13 @@
|
||||||
#include "CXWindowsClipboard.h"
|
#include "CXWindowsClipboard.h"
|
||||||
#include "CXWindowsUtil.h"
|
#include "CXWindowsUtil.h"
|
||||||
#include "CClipboard.h"
|
#include "CClipboard.h"
|
||||||
|
#include "XScreen.h"
|
||||||
#include "CLock.h"
|
#include "CLock.h"
|
||||||
|
#include "CThread.h"
|
||||||
#include "CLog.h"
|
#include "CLog.h"
|
||||||
#include "CString.h"
|
#include "CString.h"
|
||||||
#include "CThread.h"
|
#include <cstdlib>
|
||||||
#include "XScreen.h"
|
#include <cstring>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CXWindowsScreen
|
// CXWindowsScreen
|
||||||
|
@ -18,10 +17,10 @@
|
||||||
CXWindowsScreen* CXWindowsScreen::s_screen = NULL;
|
CXWindowsScreen* CXWindowsScreen::s_screen = NULL;
|
||||||
|
|
||||||
CXWindowsScreen::CXWindowsScreen() :
|
CXWindowsScreen::CXWindowsScreen() :
|
||||||
m_display(NULL),
|
m_display(NULL),
|
||||||
m_root(None),
|
m_root(None),
|
||||||
m_w(0), m_h(0),
|
m_w(0), m_h(0),
|
||||||
m_stop(false)
|
m_stop(false)
|
||||||
{
|
{
|
||||||
assert(s_screen == NULL);
|
assert(s_screen == NULL);
|
||||||
s_screen = this;
|
s_screen = this;
|
||||||
|
@ -35,7 +34,8 @@ CXWindowsScreen::~CXWindowsScreen()
|
||||||
s_screen = NULL;
|
s_screen = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsScreen::openDisplay()
|
void
|
||||||
|
CXWindowsScreen::openDisplay()
|
||||||
{
|
{
|
||||||
assert(m_display == NULL);
|
assert(m_display == NULL);
|
||||||
|
|
||||||
|
@ -51,11 +51,12 @@ void CXWindowsScreen::openDisplay()
|
||||||
// open the display
|
// open the display
|
||||||
log((CLOG_DEBUG "XOpenDisplay(\"%s\")", display));
|
log((CLOG_DEBUG "XOpenDisplay(\"%s\")", display));
|
||||||
m_display = XOpenDisplay(display);
|
m_display = XOpenDisplay(display);
|
||||||
if (m_display == NULL)
|
if (m_display == NULL) {
|
||||||
throw XScreenOpenFailure();
|
throw XScreenOpenFailure();
|
||||||
|
}
|
||||||
|
|
||||||
// get default screen
|
// get default screen
|
||||||
m_screen = DefaultScreen(m_display);
|
m_screen = DefaultScreen(m_display);
|
||||||
Screen* screen = ScreenOfDisplay(m_display, m_screen);
|
Screen* screen = ScreenOfDisplay(m_display, m_screen);
|
||||||
|
|
||||||
// get screen size
|
// get screen size
|
||||||
|
@ -75,7 +76,8 @@ void CXWindowsScreen::openDisplay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsScreen::closeDisplay()
|
void
|
||||||
|
CXWindowsScreen::closeDisplay()
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
|
||||||
|
@ -96,20 +98,24 @@ void CXWindowsScreen::closeDisplay()
|
||||||
XSetIOErrorHandler(NULL);
|
XSetIOErrorHandler(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CXWindowsScreen::getScreen() const
|
int
|
||||||
|
CXWindowsScreen::getScreen() const
|
||||||
{
|
{
|
||||||
assert(m_display != NULL);
|
assert(m_display != NULL);
|
||||||
return m_screen;
|
return m_screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window CXWindowsScreen::getRoot() const
|
Window
|
||||||
|
CXWindowsScreen::getRoot() const
|
||||||
{
|
{
|
||||||
assert(m_display != NULL);
|
assert(m_display != NULL);
|
||||||
return m_root;
|
return m_root;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsScreen::getScreenSize(
|
void
|
||||||
SInt32* w, SInt32* h) const
|
CXWindowsScreen::getScreenSize(
|
||||||
|
SInt32* w,
|
||||||
|
SInt32* h) const
|
||||||
{
|
{
|
||||||
assert(m_display != NULL);
|
assert(m_display != NULL);
|
||||||
assert(w != NULL && h != NULL);
|
assert(w != NULL && h != NULL);
|
||||||
|
@ -118,7 +124,8 @@ void CXWindowsScreen::getScreenSize(
|
||||||
*h = m_h;
|
*h = m_h;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor CXWindowsScreen::createBlankCursor() const
|
Cursor
|
||||||
|
CXWindowsScreen::createBlankCursor() const
|
||||||
{
|
{
|
||||||
// this seems just a bit more complicated than really necessary
|
// this seems just a bit more complicated than really necessary
|
||||||
|
|
||||||
|
@ -153,7 +160,9 @@ Cursor CXWindowsScreen::createBlankCursor() const
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsScreen::getEvent(XEvent* xevent) const
|
bool
|
||||||
|
CXWindowsScreen::getEvent(
|
||||||
|
XEvent* xevent) const
|
||||||
{
|
{
|
||||||
// wait for an event in a cancellable way and don't lock the
|
// wait for an event in a cancellable way and don't lock the
|
||||||
// display while we're waiting.
|
// display while we're waiting.
|
||||||
|
@ -182,13 +191,15 @@ bool CXWindowsScreen::getEvent(XEvent* xevent) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsScreen::doStop()
|
void
|
||||||
|
CXWindowsScreen::doStop()
|
||||||
{
|
{
|
||||||
// caller must have locked display
|
// caller must have locked display
|
||||||
m_stop = true;
|
m_stop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClipboardID CXWindowsScreen::getClipboardID(Atom selection) const
|
ClipboardID
|
||||||
|
CXWindowsScreen::getClipboardID(Atom selection) const
|
||||||
{
|
{
|
||||||
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
||||||
if (m_clipboard[id] != NULL &&
|
if (m_clipboard[id] != NULL &&
|
||||||
|
@ -199,27 +210,31 @@ ClipboardID CXWindowsScreen::getClipboardID(Atom selection) const
|
||||||
return kClipboardEnd;
|
return kClipboardEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsScreen::onUnexpectedClose()
|
void
|
||||||
|
CXWindowsScreen::onUnexpectedClose()
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsScreen::processEvent(XEvent* xevent)
|
bool
|
||||||
|
CXWindowsScreen::processEvent(
|
||||||
|
XEvent* xevent)
|
||||||
{
|
{
|
||||||
switch (xevent->type) {
|
switch (xevent->type) {
|
||||||
case SelectionClear: {
|
case SelectionClear:
|
||||||
// we just lost the selection. that means someone else
|
{
|
||||||
// grabbed the selection so this screen is now the
|
// we just lost the selection. that means someone else
|
||||||
// selection owner. report that to the subclass.
|
// grabbed the selection so this screen is now the
|
||||||
ClipboardID id = getClipboardID(xevent->xselectionclear.selection);
|
// selection owner. report that to the subclass.
|
||||||
if (id != kClipboardEnd) {
|
ClipboardID id = getClipboardID(xevent->xselectionclear.selection);
|
||||||
log((CLOG_DEBUG "lost clipboard %d ownership at time %d", id, xevent->xselectionclear.time));
|
if (id != kClipboardEnd) {
|
||||||
m_clipboard[id]->lost(xevent->xselectionclear.time);
|
log((CLOG_DEBUG "lost clipboard %d ownership at time %d", id, xevent->xselectionclear.time));
|
||||||
onLostClipboard(id);
|
m_clipboard[id]->lost(xevent->xselectionclear.time);
|
||||||
return true;
|
onLostClipboard(id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case SelectionNotify:
|
case SelectionNotify:
|
||||||
// notification of selection transferred. we shouldn't
|
// notification of selection transferred. we shouldn't
|
||||||
|
@ -234,28 +249,30 @@ bool CXWindowsScreen::processEvent(XEvent* xevent)
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case SelectionRequest: {
|
case SelectionRequest:
|
||||||
// somebody is asking for clipboard data
|
{
|
||||||
ClipboardID id = getClipboardID(xevent->xselectionrequest.selection);
|
// somebody is asking for clipboard data
|
||||||
if (id != kClipboardEnd) {
|
ClipboardID id = getClipboardID(
|
||||||
CLock lock(&m_mutex);
|
xevent->xselectionrequest.selection);
|
||||||
m_clipboard[id]->addRequest(
|
if (id != kClipboardEnd) {
|
||||||
|
CLock lock(&m_mutex);
|
||||||
|
m_clipboard[id]->addRequest(
|
||||||
xevent->xselectionrequest.owner,
|
xevent->xselectionrequest.owner,
|
||||||
xevent->xselectionrequest.requestor,
|
xevent->xselectionrequest.requestor,
|
||||||
xevent->xselectionrequest.target,
|
xevent->xselectionrequest.target,
|
||||||
xevent->xselectionrequest.time,
|
xevent->xselectionrequest.time,
|
||||||
xevent->xselectionrequest.property);
|
xevent->xselectionrequest.property);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case PropertyNotify:
|
case PropertyNotify:
|
||||||
// property delete may be part of a selection conversion
|
// property delete may be part of a selection conversion
|
||||||
if (xevent->xproperty.state == PropertyDelete) {
|
if (xevent->xproperty.state == PropertyDelete) {
|
||||||
processClipboardRequest(xevent->xproperty.window,
|
processClipboardRequest(xevent->xproperty.window,
|
||||||
xevent->xproperty.time,
|
xevent->xproperty.time,
|
||||||
xevent->xproperty.atom);
|
xevent->xproperty.atom);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -270,9 +287,10 @@ bool CXWindowsScreen::processEvent(XEvent* xevent)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsScreen::setDisplayClipboard(
|
bool
|
||||||
ClipboardID id,
|
CXWindowsScreen::setDisplayClipboard(
|
||||||
const IClipboard* clipboard)
|
ClipboardID id,
|
||||||
|
const IClipboard* clipboard)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
|
||||||
|
@ -300,9 +318,10 @@ bool CXWindowsScreen::setDisplayClipboard(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsScreen::getDisplayClipboard(
|
bool
|
||||||
ClipboardID id,
|
CXWindowsScreen::getDisplayClipboard(
|
||||||
IClipboard* clipboard) const
|
ClipboardID id,
|
||||||
|
IClipboard* clipboard) const
|
||||||
{
|
{
|
||||||
assert(clipboard != NULL);
|
assert(clipboard != NULL);
|
||||||
|
|
||||||
|
@ -322,9 +341,11 @@ bool CXWindowsScreen::getDisplayClipboard(
|
||||||
return CClipboard::copy(clipboard, m_clipboard[id], timestamp);
|
return CClipboard::copy(clipboard, m_clipboard[id], timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsScreen::processClipboardRequest(
|
void
|
||||||
Window requestor,
|
CXWindowsScreen::processClipboardRequest(
|
||||||
Time time, Atom property)
|
Window requestor,
|
||||||
|
Time time,
|
||||||
|
Atom property)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
|
||||||
|
@ -337,8 +358,9 @@ void CXWindowsScreen::processClipboardRequest(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsScreen::destroyClipboardRequest(
|
void
|
||||||
Window requestor)
|
CXWindowsScreen::destroyClipboardRequest(
|
||||||
|
Window requestor)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
|
||||||
|
@ -351,7 +373,9 @@ void CXWindowsScreen::destroyClipboardRequest(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CXWindowsScreen::ioErrorHandler(Display*)
|
int
|
||||||
|
CXWindowsScreen::ioErrorHandler(
|
||||||
|
Display*)
|
||||||
{
|
{
|
||||||
// the display has disconnected, probably because X is shutting
|
// the display has disconnected, probably because X is shutting
|
||||||
// down. X forces us to exit at this point. that's arguably
|
// down. X forces us to exit at this point. that's arguably
|
||||||
|
@ -371,9 +395,10 @@ int CXWindowsScreen::ioErrorHandler(Display*)
|
||||||
// CXWindowsScreen::CDisplayLock
|
// CXWindowsScreen::CDisplayLock
|
||||||
//
|
//
|
||||||
|
|
||||||
CXWindowsScreen::CDisplayLock::CDisplayLock(const CXWindowsScreen* screen) :
|
CXWindowsScreen::CDisplayLock::CDisplayLock(
|
||||||
m_mutex(&screen->m_mutex),
|
const CXWindowsScreen* screen) :
|
||||||
m_display(screen->m_display)
|
m_mutex(&screen->m_mutex),
|
||||||
|
m_display(screen->m_display)
|
||||||
{
|
{
|
||||||
assert(m_display != NULL);
|
assert(m_display != NULL);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef CXWINDOWSSCREEN_H
|
#ifndef CXWINDOWSSCREEN_H
|
||||||
#define CXWINDOWSSCREEN_H
|
#define CXWINDOWSSCREEN_H
|
||||||
|
|
||||||
#include "BasicTypes.h"
|
|
||||||
#include "ClipboardTypes.h"
|
#include "ClipboardTypes.h"
|
||||||
#include "CMutex.h"
|
#include "CMutex.h"
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
@ -58,11 +57,11 @@ protected:
|
||||||
|
|
||||||
// set the contents of the clipboard (i.e. primary selection)
|
// set the contents of the clipboard (i.e. primary selection)
|
||||||
bool setDisplayClipboard(ClipboardID,
|
bool setDisplayClipboard(ClipboardID,
|
||||||
const IClipboard* clipboard);
|
const IClipboard* clipboard);
|
||||||
|
|
||||||
// copy the clipboard contents to clipboard
|
// copy the clipboard contents to clipboard
|
||||||
bool getDisplayClipboard(ClipboardID,
|
bool getDisplayClipboard(ClipboardID,
|
||||||
IClipboard* clipboard) const;
|
IClipboard* clipboard) const;
|
||||||
|
|
||||||
// called by openDisplay() to allow subclasses to prepare the display.
|
// called by openDisplay() to allow subclasses to prepare the display.
|
||||||
// the display is locked and passed to the subclass.
|
// the display is locked and passed to the subclass.
|
||||||
|
@ -93,7 +92,7 @@ private:
|
||||||
|
|
||||||
// continue processing a selection request
|
// continue processing a selection request
|
||||||
void processClipboardRequest(Window window,
|
void processClipboardRequest(Window window,
|
||||||
Time time, Atom property);
|
Time time, Atom property);
|
||||||
|
|
||||||
// terminate a selection request
|
// terminate a selection request
|
||||||
void destroyClipboardRequest(Window window);
|
void destroyClipboardRequest(Window window);
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
#include "CXWindowsUtil.h"
|
#include "CXWindowsUtil.h"
|
||||||
#include "CLog.h"
|
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
#include <assert.h>
|
#include "CLog.h"
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
|
||||||
//
|
//
|
||||||
// CXWindowsUtil
|
// CXWindowsUtil
|
||||||
//
|
//
|
||||||
|
|
||||||
bool CXWindowsUtil::getWindowProperty(
|
bool
|
||||||
Display* display,
|
CXWindowsUtil::getWindowProperty(
|
||||||
Window window, Atom property,
|
Display* display,
|
||||||
CString* data, Atom* type,
|
Window window,
|
||||||
int* format, bool deleteProperty)
|
Atom property,
|
||||||
|
CString* data,
|
||||||
|
Atom* type,
|
||||||
|
int* format,
|
||||||
|
bool deleteProperty)
|
||||||
{
|
{
|
||||||
assert(display != NULL);
|
assert(display != NULL);
|
||||||
assert(data != NULL);
|
assert(data != NULL);
|
||||||
|
@ -84,11 +87,15 @@ bool CXWindowsUtil::getWindowProperty(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsUtil::setWindowProperty(
|
bool
|
||||||
Display* display,
|
CXWindowsUtil::setWindowProperty(
|
||||||
Window window, Atom property,
|
Display* display,
|
||||||
const void* vdata, UInt32 size,
|
Window window,
|
||||||
Atom type, SInt32 format)
|
Atom property,
|
||||||
|
const void* vdata,
|
||||||
|
UInt32 size,
|
||||||
|
Atom type,
|
||||||
|
SInt32 format)
|
||||||
{
|
{
|
||||||
const UInt32 length = 4 * XMaxRequestSize(display);
|
const UInt32 length = 4 * XMaxRequestSize(display);
|
||||||
const unsigned char* data = reinterpret_cast<const unsigned char*>(vdata);
|
const unsigned char* data = reinterpret_cast<const unsigned char*>(vdata);
|
||||||
|
@ -100,8 +107,9 @@ bool CXWindowsUtil::setWindowProperty(
|
||||||
|
|
||||||
// how much data to send in first chunk?
|
// how much data to send in first chunk?
|
||||||
UInt32 chunkSize = size;
|
UInt32 chunkSize = size;
|
||||||
if (chunkSize > length)
|
if (chunkSize > length) {
|
||||||
chunkSize = length;
|
chunkSize = length;
|
||||||
|
}
|
||||||
|
|
||||||
// send first chunk
|
// send first chunk
|
||||||
XChangeProperty(display, window, property,
|
XChangeProperty(display, window, property,
|
||||||
|
@ -113,8 +121,9 @@ bool CXWindowsUtil::setWindowProperty(
|
||||||
size -= chunkSize;
|
size -= chunkSize;
|
||||||
while (!error && size > 0) {
|
while (!error && size > 0) {
|
||||||
chunkSize = size;
|
chunkSize = size;
|
||||||
if (chunkSize > length)
|
if (chunkSize > length) {
|
||||||
chunkSize = length;
|
chunkSize = length;
|
||||||
|
}
|
||||||
XChangeProperty(display, window, property,
|
XChangeProperty(display, window, property,
|
||||||
type, format, PropModeAppend,
|
type, format, PropModeAppend,
|
||||||
data, chunkSize / datumSize);
|
data, chunkSize / datumSize);
|
||||||
|
@ -125,8 +134,10 @@ bool CXWindowsUtil::setWindowProperty(
|
||||||
return !error;
|
return !error;
|
||||||
}
|
}
|
||||||
|
|
||||||
Time CXWindowsUtil::getCurrentTime(
|
Time
|
||||||
Display* display, Window window)
|
CXWindowsUtil::getCurrentTime(
|
||||||
|
Display* display,
|
||||||
|
Window window)
|
||||||
{
|
{
|
||||||
// select property events on window
|
// select property events on window
|
||||||
XWindowAttributes attr;
|
XWindowAttributes attr;
|
||||||
|
@ -162,8 +173,11 @@ Time CXWindowsUtil::getCurrentTime(
|
||||||
return xevent.xproperty.time;
|
return xevent.xproperty.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool CXWindowsUtil::propertyNotifyPredicate(
|
Bool
|
||||||
Display*, XEvent* xevent, XPointer arg)
|
CXWindowsUtil::propertyNotifyPredicate(
|
||||||
|
Display*,
|
||||||
|
XEvent* xevent,
|
||||||
|
XPointer arg)
|
||||||
{
|
{
|
||||||
CPropertyNotifyPredicateInfo* filter =
|
CPropertyNotifyPredicateInfo* filter =
|
||||||
reinterpret_cast<CPropertyNotifyPredicateInfo*>(arg);
|
reinterpret_cast<CPropertyNotifyPredicateInfo*>(arg);
|
||||||
|
@ -185,12 +199,15 @@ CXWindowsUtil::CErrorLock::CErrorLock()
|
||||||
install(&CXWindowsUtil::CErrorLock::ignoreHandler, NULL);
|
install(&CXWindowsUtil::CErrorLock::ignoreHandler, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
CXWindowsUtil::CErrorLock::CErrorLock(bool* flag)
|
CXWindowsUtil::CErrorLock::CErrorLock(
|
||||||
|
bool* flag)
|
||||||
{
|
{
|
||||||
install(&CXWindowsUtil::CErrorLock::saveHandler, flag);
|
install(&CXWindowsUtil::CErrorLock::saveHandler, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
CXWindowsUtil::CErrorLock::CErrorLock(ErrorHandler handler, void* data)
|
CXWindowsUtil::CErrorLock::CErrorLock(
|
||||||
|
ErrorHandler handler,
|
||||||
|
void* data)
|
||||||
{
|
{
|
||||||
install(handler, data);
|
install(handler, data);
|
||||||
}
|
}
|
||||||
|
@ -201,8 +218,10 @@ CXWindowsUtil::CErrorLock::~CErrorLock()
|
||||||
s_top = m_next;
|
s_top = m_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsUtil::CErrorLock::install(
|
void
|
||||||
ErrorHandler handler, void* data)
|
CXWindowsUtil::CErrorLock::install(
|
||||||
|
ErrorHandler handler,
|
||||||
|
void* data)
|
||||||
{
|
{
|
||||||
m_handler = handler;
|
m_handler = handler;
|
||||||
m_userData = data;
|
m_userData = data;
|
||||||
|
@ -212,8 +231,10 @@ void CXWindowsUtil::CErrorLock::install(
|
||||||
s_top = this;
|
s_top = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CXWindowsUtil::CErrorLock::internalHandler(
|
int
|
||||||
Display* display, XErrorEvent* event)
|
CXWindowsUtil::CErrorLock::internalHandler(
|
||||||
|
Display* display,
|
||||||
|
XErrorEvent* event)
|
||||||
{
|
{
|
||||||
if (s_top != NULL && s_top->m_handler != NULL) {
|
if (s_top != NULL && s_top->m_handler != NULL) {
|
||||||
s_top->m_handler(display, event, s_top->m_userData);
|
s_top->m_handler(display, event, s_top->m_userData);
|
||||||
|
@ -221,14 +242,20 @@ int CXWindowsUtil::CErrorLock::internalHandler(
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsUtil::CErrorLock::ignoreHandler(
|
void
|
||||||
Display*, XErrorEvent*, void*)
|
CXWindowsUtil::CErrorLock::ignoreHandler(
|
||||||
|
Display*,
|
||||||
|
XErrorEvent*,
|
||||||
|
void*)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsUtil::CErrorLock::saveHandler(
|
void
|
||||||
Display*, XErrorEvent*, void* flag)
|
CXWindowsUtil::CErrorLock::saveHandler(
|
||||||
|
Display*,
|
||||||
|
XErrorEvent*,
|
||||||
|
void* flag)
|
||||||
{
|
{
|
||||||
*reinterpret_cast<bool*>(flag) = true;
|
*reinterpret_cast<bool*>(flag) = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
#ifndef CXWINDOWSUTIL_H
|
#ifndef CXWINDOWSUTIL_H
|
||||||
#define CXWINDOWSUTIL_H
|
#define CXWINDOWSUTIL_H
|
||||||
|
|
||||||
#include "BasicTypes.h"
|
|
||||||
#include "CString.h"
|
#include "CString.h"
|
||||||
|
#include "BasicTypes.h"
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
class CXWindowsUtil {
|
class CXWindowsUtil {
|
||||||
public:
|
public:
|
||||||
static bool getWindowProperty(Display*,
|
static bool getWindowProperty(Display*,
|
||||||
Window window, Atom property,
|
Window window, Atom property,
|
||||||
CString* data, Atom* type,
|
CString* data, Atom* type,
|
||||||
SInt32* format, bool deleteProperty);
|
SInt32* format, bool deleteProperty);
|
||||||
static bool setWindowProperty(Display*,
|
static bool setWindowProperty(Display*,
|
||||||
Window window, Atom property,
|
Window window, Atom property,
|
||||||
const void* data, UInt32 size,
|
const void* data, UInt32 size,
|
||||||
Atom type, SInt32 format);
|
Atom type, SInt32 format);
|
||||||
static Time getCurrentTime(Display*, Window);
|
static Time getCurrentTime(Display*, Window);
|
||||||
|
|
||||||
// class to set an X error handler in the c'tor and restore the
|
// class to set an X error handler in the c'tor and restore the
|
||||||
|
@ -55,7 +55,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
static Bool propertyNotifyPredicate(Display*,
|
static Bool propertyNotifyPredicate(Display*,
|
||||||
XEvent* xevent, XPointer arg);
|
XEvent* xevent, XPointer arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
#ifndef IPLATFORM_H
|
#ifndef IPLATFORM_H
|
||||||
#define IPLATFORM_H
|
#define IPLATFORM_H
|
||||||
|
|
||||||
#include "BasicTypes.h"
|
|
||||||
#include "CString.h"
|
|
||||||
#include "IInterface.h"
|
#include "IInterface.h"
|
||||||
|
#include "CString.h"
|
||||||
|
|
||||||
class IPlatform : public IInterface {
|
class IPlatform : public IInterface {
|
||||||
public:
|
public:
|
||||||
|
@ -16,9 +15,9 @@ public:
|
||||||
// include the name of program as the first argument.
|
// include the name of program as the first argument.
|
||||||
// FIXME -- throw on error? will get better error messages that way.
|
// FIXME -- throw on error? will get better error messages that way.
|
||||||
virtual bool installDaemon(const char* name,
|
virtual bool installDaemon(const char* name,
|
||||||
const char* description,
|
const char* description,
|
||||||
const char* pathname,
|
const char* pathname,
|
||||||
const char* commandLine) = 0;
|
const char* commandLine) = 0;
|
||||||
virtual bool uninstallDaemon(const char* name) = 0;
|
virtual bool uninstallDaemon(const char* name) = 0;
|
||||||
|
|
||||||
// daemonize. this should have the side effect of sending log
|
// daemonize. this should have the side effect of sending log
|
||||||
|
@ -67,8 +66,8 @@ public:
|
||||||
// is longer than allowed by the system. we'll rely on the
|
// is longer than allowed by the system. we'll rely on the
|
||||||
// system calls to tell us that.
|
// system calls to tell us that.
|
||||||
virtual CString addPathComponent(
|
virtual CString addPathComponent(
|
||||||
const CString& prefix,
|
const CString& prefix,
|
||||||
const CString& suffix) const = 0;
|
const CString& suffix) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "CConfig.h"
|
#include "CConfig.h"
|
||||||
#include "ProtocolTypes.h"
|
#include "ProtocolTypes.h"
|
||||||
|
#include "XSocket.h"
|
||||||
#include "stdistream.h"
|
#include "stdistream.h"
|
||||||
#include "stdostream.h"
|
#include "stdostream.h"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CConfig
|
// CConfig
|
||||||
|
@ -18,7 +18,9 @@ CConfig::~CConfig()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CConfig::addScreen(const CString& name)
|
bool
|
||||||
|
CConfig::addScreen(
|
||||||
|
const CString& name)
|
||||||
{
|
{
|
||||||
// alias name must not exist
|
// alias name must not exist
|
||||||
if (m_nameToCanonicalName.find(name) != m_nameToCanonicalName.end()) {
|
if (m_nameToCanonicalName.find(name) != m_nameToCanonicalName.end()) {
|
||||||
|
@ -34,7 +36,9 @@ bool CConfig::addScreen(const CString& name)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::removeScreen(const CString& name)
|
void
|
||||||
|
CConfig::removeScreen(
|
||||||
|
const CString& name)
|
||||||
{
|
{
|
||||||
// get canonical name and find cell
|
// get canonical name and find cell
|
||||||
CString canonical = getCanonicalName(name);
|
CString canonical = getCanonicalName(name);
|
||||||
|
@ -67,14 +71,17 @@ void CConfig::removeScreen(const CString& name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::removeAllScreens()
|
void
|
||||||
|
CConfig::removeAllScreens()
|
||||||
{
|
{
|
||||||
m_map.clear();
|
m_map.clear();
|
||||||
m_nameToCanonicalName.clear();
|
m_nameToCanonicalName.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CConfig::addAlias(const CString& canonical,
|
bool
|
||||||
const CString& alias)
|
CConfig::addAlias(
|
||||||
|
const CString& canonical,
|
||||||
|
const CString& alias)
|
||||||
{
|
{
|
||||||
// alias name must not exist
|
// alias name must not exist
|
||||||
if (m_nameToCanonicalName.find(alias) != m_nameToCanonicalName.end()) {
|
if (m_nameToCanonicalName.find(alias) != m_nameToCanonicalName.end()) {
|
||||||
|
@ -92,7 +99,9 @@ bool CConfig::addAlias(const CString& canonical,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CConfig::removeAlias(const CString& alias)
|
bool
|
||||||
|
CConfig::removeAlias(
|
||||||
|
const CString& alias)
|
||||||
{
|
{
|
||||||
// must not be a canonical name
|
// must not be a canonical name
|
||||||
if (m_map.find(alias) != m_map.end()) {
|
if (m_map.find(alias) != m_map.end()) {
|
||||||
|
@ -111,7 +120,8 @@ bool CConfig::removeAlias(const CString& alias)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::removeAllAliases()
|
void
|
||||||
|
CConfig::removeAllAliases()
|
||||||
{
|
{
|
||||||
// remove all names
|
// remove all names
|
||||||
m_nameToCanonicalName.clear();
|
m_nameToCanonicalName.clear();
|
||||||
|
@ -124,9 +134,11 @@ void CConfig::removeAllAliases()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CConfig::connect(const CString& srcName,
|
bool
|
||||||
EDirection srcSide,
|
CConfig::connect(
|
||||||
const CString& dstName)
|
const CString& srcName,
|
||||||
|
EDirection srcSide,
|
||||||
|
const CString& dstName)
|
||||||
{
|
{
|
||||||
// find source cell
|
// find source cell
|
||||||
CCellMap::iterator index = m_map.find(getCanonicalName(srcName));
|
CCellMap::iterator index = m_map.find(getCanonicalName(srcName));
|
||||||
|
@ -142,8 +154,10 @@ bool CConfig::connect(const CString& srcName,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CConfig::disconnect(const CString& srcName,
|
bool
|
||||||
EDirection srcSide)
|
CConfig::disconnect(
|
||||||
|
const CString& srcName,
|
||||||
|
EDirection srcSide)
|
||||||
{
|
{
|
||||||
// find source cell
|
// find source cell
|
||||||
CCellMap::iterator index = m_map.find(srcName);
|
CCellMap::iterator index = m_map.find(srcName);
|
||||||
|
@ -157,17 +171,23 @@ bool CConfig::disconnect(const CString& srcName,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::setSynergyAddress(const CNetworkAddress& addr)
|
void
|
||||||
|
CConfig::setSynergyAddress(
|
||||||
|
const CNetworkAddress& addr)
|
||||||
{
|
{
|
||||||
m_synergyAddress = addr;
|
m_synergyAddress = addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::setHTTPAddress(const CNetworkAddress& addr)
|
void
|
||||||
|
CConfig::setHTTPAddress(
|
||||||
|
const CNetworkAddress& addr)
|
||||||
{
|
{
|
||||||
m_httpAddress = addr;
|
m_httpAddress = addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CConfig::isValidScreenName(const CString& name) const
|
bool
|
||||||
|
CConfig::isValidScreenName(
|
||||||
|
const CString& name) const
|
||||||
{
|
{
|
||||||
// name is valid if matches validname
|
// name is valid if matches validname
|
||||||
// name ::= [A-Za-z0-9] | [A-Za-z0-9][-A-Za-z0-9]*[A-Za-z0-9]
|
// name ::= [A-Za-z0-9] | [A-Za-z0-9][-A-Za-z0-9]*[A-Za-z0-9]
|
||||||
|
@ -211,27 +231,35 @@ bool CConfig::isValidScreenName(const CString& name) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CConfig::const_iterator CConfig::begin() const
|
CConfig::const_iterator
|
||||||
|
CConfig::begin() const
|
||||||
{
|
{
|
||||||
return const_iterator(m_map.begin());
|
return const_iterator(m_map.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
CConfig::const_iterator CConfig::end() const
|
CConfig::const_iterator
|
||||||
|
CConfig::end() const
|
||||||
{
|
{
|
||||||
return const_iterator(m_map.end());
|
return const_iterator(m_map.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CConfig::isScreen(const CString& name) const
|
bool
|
||||||
|
CConfig::isScreen(
|
||||||
|
const CString& name) const
|
||||||
{
|
{
|
||||||
return (m_nameToCanonicalName.count(name) > 0);
|
return (m_nameToCanonicalName.count(name) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CConfig::isCanonicalName(const CString& name) const
|
bool
|
||||||
|
CConfig::isCanonicalName(
|
||||||
|
const CString& name) const
|
||||||
{
|
{
|
||||||
return CStringUtil::CaselessCmp::equal(getCanonicalName(name), name);
|
return CStringUtil::CaselessCmp::equal(getCanonicalName(name), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CConfig::getCanonicalName(const CString& name) const
|
CString
|
||||||
|
CConfig::getCanonicalName(
|
||||||
|
const CString& name) const
|
||||||
{
|
{
|
||||||
CNameMap::const_iterator index = m_nameToCanonicalName.find(name);
|
CNameMap::const_iterator index = m_nameToCanonicalName.find(name);
|
||||||
if (index == m_nameToCanonicalName.end()) {
|
if (index == m_nameToCanonicalName.end()) {
|
||||||
|
@ -242,8 +270,10 @@ CString CConfig::getCanonicalName(const CString& name) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CConfig::getNeighbor(const CString& srcName,
|
CString
|
||||||
EDirection srcSide) const
|
CConfig::getNeighbor(
|
||||||
|
const CString& srcName,
|
||||||
|
EDirection srcSide) const
|
||||||
{
|
{
|
||||||
// find source cell
|
// find source cell
|
||||||
CCellMap::const_iterator index = m_map.find(getCanonicalName(srcName));
|
CCellMap::const_iterator index = m_map.find(getCanonicalName(srcName));
|
||||||
|
@ -256,23 +286,30 @@ CString CConfig::getNeighbor(const CString& srcName,
|
||||||
srcSide - kFirstDirection]);
|
srcSide - kFirstDirection]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CNetworkAddress& CConfig::getSynergyAddress() const
|
const CNetworkAddress&
|
||||||
|
CConfig::getSynergyAddress() const
|
||||||
{
|
{
|
||||||
return m_synergyAddress;
|
return m_synergyAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CNetworkAddress& CConfig::getHTTPAddress() const
|
const CNetworkAddress&
|
||||||
|
CConfig::getHTTPAddress() const
|
||||||
{
|
{
|
||||||
return m_httpAddress;
|
return m_httpAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CConfig::dirName(EDirection dir)
|
const char*
|
||||||
|
CConfig::dirName(
|
||||||
|
EDirection dir)
|
||||||
{
|
{
|
||||||
static const char* s_name[] = { "left", "right", "top", "bottom" };
|
static const char* s_name[] = { "left", "right", "top", "bottom" };
|
||||||
return s_name[dir - kFirstDirection];
|
return s_name[dir - kFirstDirection];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CConfig::readLine(std::istream& s, CString& line)
|
bool
|
||||||
|
CConfig::readLine(
|
||||||
|
std::istream& s,
|
||||||
|
CString& line)
|
||||||
{
|
{
|
||||||
s >> std::ws;
|
s >> std::ws;
|
||||||
while (std::getline(s, line)) {
|
while (std::getline(s, line)) {
|
||||||
|
@ -295,7 +332,9 @@ bool CConfig::readLine(std::istream& s, CString& line)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::readSection(std::istream& s)
|
void
|
||||||
|
CConfig::readSection(
|
||||||
|
std::istream& s)
|
||||||
{
|
{
|
||||||
static const char s_section[] = "section:";
|
static const char s_section[] = "section:";
|
||||||
static const char s_network[] = "network";
|
static const char s_network[] = "network";
|
||||||
|
@ -343,7 +382,9 @@ void CConfig::readSection(std::istream& s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::readSectionNetwork(std::istream& s)
|
void
|
||||||
|
CConfig::readSectionNetwork(
|
||||||
|
std::istream& s)
|
||||||
{
|
{
|
||||||
CString line;
|
CString line;
|
||||||
CString name;
|
CString name;
|
||||||
|
@ -398,7 +439,9 @@ void CConfig::readSectionNetwork(std::istream& s)
|
||||||
throw XConfigRead("unexpected end of screens section");
|
throw XConfigRead("unexpected end of screens section");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::readSectionScreens(std::istream& s)
|
void
|
||||||
|
CConfig::readSectionScreens(
|
||||||
|
std::istream& s)
|
||||||
{
|
{
|
||||||
CString line;
|
CString line;
|
||||||
CString name;
|
CString name;
|
||||||
|
@ -433,7 +476,9 @@ void CConfig::readSectionScreens(std::istream& s)
|
||||||
throw XConfigRead("unexpected end of screens section");
|
throw XConfigRead("unexpected end of screens section");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::readSectionLinks(std::istream& s)
|
void
|
||||||
|
CConfig::readSectionLinks(
|
||||||
|
std::istream& s)
|
||||||
{
|
{
|
||||||
CString line;
|
CString line;
|
||||||
CString screen;
|
CString screen;
|
||||||
|
@ -513,7 +558,9 @@ void CConfig::readSectionLinks(std::istream& s)
|
||||||
throw XConfigRead("unexpected end of links section");
|
throw XConfigRead("unexpected end of links section");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::readSectionAliases(std::istream& s)
|
void
|
||||||
|
CConfig::readSectionAliases(
|
||||||
|
std::istream& s)
|
||||||
{
|
{
|
||||||
CString line;
|
CString line;
|
||||||
CString screen;
|
CString screen;
|
||||||
|
@ -559,7 +606,10 @@ void CConfig::readSectionAliases(std::istream& s)
|
||||||
// CConfig I/O
|
// CConfig I/O
|
||||||
//
|
//
|
||||||
|
|
||||||
std::istream& operator>>(std::istream& s, CConfig& config)
|
std::istream&
|
||||||
|
operator>>(
|
||||||
|
std::istream& s,
|
||||||
|
CConfig& config)
|
||||||
{
|
{
|
||||||
// FIXME -- should track line and column to improve error reporting
|
// FIXME -- should track line and column to improve error reporting
|
||||||
|
|
||||||
|
@ -571,7 +621,10 @@ std::istream& operator>>(std::istream& s, CConfig& config)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& s, const CConfig& config)
|
std::ostream&
|
||||||
|
operator<<(
|
||||||
|
std::ostream& s,
|
||||||
|
const CConfig& config)
|
||||||
{
|
{
|
||||||
// network section
|
// network section
|
||||||
s << "section: network" << std::endl;
|
s << "section: network" << std::endl;
|
||||||
|
@ -657,7 +710,9 @@ std::ostream& operator<<(std::ostream& s, const CConfig& config)
|
||||||
// CConfig I/O exceptions
|
// CConfig I/O exceptions
|
||||||
//
|
//
|
||||||
|
|
||||||
XConfigRead::XConfigRead(const CString& error) : m_error(error)
|
XConfigRead::XConfigRead(
|
||||||
|
const CString& error) :
|
||||||
|
m_error(error)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -667,7 +722,8 @@ XConfigRead::~XConfigRead()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
CString XConfigRead::getWhat() const throw()
|
CString
|
||||||
|
XConfigRead::getWhat() const throw()
|
||||||
{
|
{
|
||||||
return m_error;
|
return m_error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
#ifndef CCONFIG_H
|
#ifndef CCONFIG_H
|
||||||
#define CCONFIG_H
|
#define CCONFIG_H
|
||||||
|
|
||||||
#include "BasicTypes.h"
|
|
||||||
#include "CString.h"
|
|
||||||
#include "CNetworkAddress.h"
|
#include "CNetworkAddress.h"
|
||||||
#include "XBase.h"
|
#include "XBase.h"
|
||||||
#include <iosfwd>
|
|
||||||
#include "stdmap.h"
|
#include "stdmap.h"
|
||||||
#include "stdset.h"
|
#include "stdset.h"
|
||||||
|
#include <iosfwd>
|
||||||
|
|
||||||
class CConfig;
|
class CConfig;
|
||||||
|
|
||||||
|
@ -85,17 +83,17 @@ public:
|
||||||
// or the canonical name is unknown. removeAlias() fails if
|
// or the canonical name is unknown. removeAlias() fails if
|
||||||
// the alias is unknown or a canonical name.
|
// the alias is unknown or a canonical name.
|
||||||
bool addAlias(const CString& canonical,
|
bool addAlias(const CString& canonical,
|
||||||
const CString& alias);
|
const CString& alias);
|
||||||
bool removeAlias(const CString& alias);
|
bool removeAlias(const CString& alias);
|
||||||
void removeAllAliases();
|
void removeAllAliases();
|
||||||
|
|
||||||
// connect/disconnect edges. both return false if srcName is
|
// connect/disconnect edges. both return false if srcName is
|
||||||
// unknown.
|
// unknown.
|
||||||
bool connect(const CString& srcName,
|
bool connect(const CString& srcName,
|
||||||
EDirection srcSide,
|
EDirection srcSide,
|
||||||
const CString& dstName);
|
const CString& dstName);
|
||||||
bool disconnect(const CString& srcName,
|
bool disconnect(const CString& srcName,
|
||||||
EDirection srcSide);
|
EDirection srcSide);
|
||||||
|
|
||||||
// set the synergy and http listen addresses. there are no
|
// set the synergy and http listen addresses. there are no
|
||||||
// default addresses.
|
// default addresses.
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
#include "CHTTPServer.h"
|
#include "CHTTPServer.h"
|
||||||
#include "CHTTPProtocol.h"
|
|
||||||
#include "XHTTP.h"
|
|
||||||
#include "CServer.h"
|
|
||||||
#include "CConfig.h"
|
#include "CConfig.h"
|
||||||
#include "CLog.h"
|
#include "CHTTPProtocol.h"
|
||||||
#include "XThread.h"
|
#include "CServer.h"
|
||||||
|
#include "XHTTP.h"
|
||||||
#include "ISocket.h"
|
#include "ISocket.h"
|
||||||
|
#include "XThread.h"
|
||||||
|
#include "CLog.h"
|
||||||
#include "stdset.h"
|
#include "stdset.h"
|
||||||
#include "stdsstream.h"
|
#include "stdsstream.h"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CHTTPServer
|
// CHTTPServer
|
||||||
|
@ -19,7 +18,9 @@
|
||||||
// malicious client from causing us to use too much memory.
|
// malicious client from causing us to use too much memory.
|
||||||
const UInt32 CHTTPServer::s_maxRequestSize = 32768;
|
const UInt32 CHTTPServer::s_maxRequestSize = 32768;
|
||||||
|
|
||||||
CHTTPServer::CHTTPServer(CServer* server) : m_server(server)
|
CHTTPServer::CHTTPServer(
|
||||||
|
CServer* server) :
|
||||||
|
m_server(server)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -29,7 +30,9 @@ CHTTPServer::~CHTTPServer()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPServer::processRequest(ISocket* socket)
|
void
|
||||||
|
CHTTPServer::processRequest(
|
||||||
|
ISocket* socket)
|
||||||
{
|
{
|
||||||
assert(socket != NULL);
|
assert(socket != NULL);
|
||||||
|
|
||||||
|
@ -88,9 +91,10 @@ void CHTTPServer::processRequest(ISocket* socket)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPServer::doProcessRequest(
|
void
|
||||||
CHTTPRequest& request,
|
CHTTPServer::doProcessRequest(
|
||||||
CHTTPReply& reply)
|
CHTTPRequest& request,
|
||||||
|
CHTTPReply& reply)
|
||||||
{
|
{
|
||||||
reply.m_majorVersion = request.m_majorVersion;
|
reply.m_majorVersion = request.m_majorVersion;
|
||||||
reply.m_minorVersion = request.m_minorVersion;
|
reply.m_minorVersion = request.m_minorVersion;
|
||||||
|
@ -118,9 +122,10 @@ void CHTTPServer::doProcessRequest(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPServer::doProcessGetEditMap(
|
void
|
||||||
CHTTPRequest& /*request*/,
|
CHTTPServer::doProcessGetEditMap(
|
||||||
CHTTPReply& reply)
|
CHTTPRequest& /*request*/,
|
||||||
|
CHTTPReply& reply)
|
||||||
{
|
{
|
||||||
static const char* s_editMapProlog1 =
|
static const char* s_editMapProlog1 =
|
||||||
"<html>\r\n"
|
"<html>\r\n"
|
||||||
|
@ -228,9 +233,10 @@ void CHTTPServer::doProcessGetEditMap(
|
||||||
reply.m_body += s_editMapEpilog;
|
reply.m_body += s_editMapEpilog;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPServer::doProcessPostEditMap(
|
void
|
||||||
CHTTPRequest& request,
|
CHTTPServer::doProcessPostEditMap(
|
||||||
CHTTPReply& reply)
|
CHTTPRequest& request,
|
||||||
|
CHTTPReply& reply)
|
||||||
{
|
{
|
||||||
typedef std::vector<CString> ScreenArray;
|
typedef std::vector<CString> ScreenArray;
|
||||||
typedef std::set<CString> ScreenSet;
|
typedef std::set<CString> ScreenSet;
|
||||||
|
@ -323,8 +329,11 @@ void CHTTPServer::doProcessPostEditMap(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CHTTPServer::parseXY(
|
bool
|
||||||
const CString& xy, SInt32& x, SInt32& y)
|
CHTTPServer::parseXY(
|
||||||
|
const CString& xy,
|
||||||
|
SInt32& x,
|
||||||
|
SInt32& y)
|
||||||
{
|
{
|
||||||
std::istringstream s(xy);
|
std::istringstream s(xy);
|
||||||
char delimiter;
|
char delimiter;
|
||||||
|
@ -339,7 +348,9 @@ bool CHTTPServer::parseXY(
|
||||||
// CHTTPServer::CScreenArray
|
// CHTTPServer::CScreenArray
|
||||||
//
|
//
|
||||||
|
|
||||||
CHTTPServer::CScreenArray::CScreenArray() : m_w(0), m_h(0)
|
CHTTPServer::CScreenArray::CScreenArray() :
|
||||||
|
m_w(0),
|
||||||
|
m_h(0)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -349,7 +360,10 @@ CHTTPServer::CScreenArray::~CScreenArray()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPServer::CScreenArray::resize(SInt32 w, SInt32 h)
|
void
|
||||||
|
CHTTPServer::CScreenArray::resize(
|
||||||
|
SInt32 w,
|
||||||
|
SInt32 h)
|
||||||
{
|
{
|
||||||
m_screens.clear();
|
m_screens.clear();
|
||||||
m_screens.resize(w * h);
|
m_screens.resize(w * h);
|
||||||
|
@ -357,7 +371,9 @@ void CHTTPServer::CScreenArray::resize(SInt32 w, SInt32 h)
|
||||||
m_h = h;
|
m_h = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPServer::CScreenArray::insertRow(SInt32 i)
|
void
|
||||||
|
CHTTPServer::CScreenArray::insertRow(
|
||||||
|
SInt32 i)
|
||||||
{
|
{
|
||||||
assert(i >= 0 && i <= m_h);
|
assert(i >= 0 && i <= m_h);
|
||||||
|
|
||||||
|
@ -379,7 +395,9 @@ void CHTTPServer::CScreenArray::insertRow(SInt32 i)
|
||||||
++m_h;
|
++m_h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPServer::CScreenArray::insertColumn(SInt32 i)
|
void
|
||||||
|
CHTTPServer::CScreenArray::insertColumn(
|
||||||
|
SInt32 i)
|
||||||
{
|
{
|
||||||
assert(i >= 0 && i <= m_w);
|
assert(i >= 0 && i <= m_w);
|
||||||
|
|
||||||
|
@ -399,7 +417,9 @@ void CHTTPServer::CScreenArray::insertColumn(SInt32 i)
|
||||||
++m_w;
|
++m_w;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPServer::CScreenArray::eraseRow(SInt32 i)
|
void
|
||||||
|
CHTTPServer::CScreenArray::eraseRow(
|
||||||
|
SInt32 i)
|
||||||
{
|
{
|
||||||
assert(i >= 0 && i < m_h);
|
assert(i >= 0 && i < m_h);
|
||||||
|
|
||||||
|
@ -421,7 +441,9 @@ void CHTTPServer::CScreenArray::eraseRow(SInt32 i)
|
||||||
--m_h;
|
--m_h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPServer::CScreenArray::eraseColumn(SInt32 i)
|
void
|
||||||
|
CHTTPServer::CScreenArray::eraseColumn(
|
||||||
|
SInt32 i)
|
||||||
{
|
{
|
||||||
assert(i >= 0 && i < m_w);
|
assert(i >= 0 && i < m_w);
|
||||||
|
|
||||||
|
@ -441,7 +463,9 @@ void CHTTPServer::CScreenArray::eraseColumn(SInt32 i)
|
||||||
--m_w;
|
--m_w;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPServer::CScreenArray::rotateRows(SInt32 i)
|
void
|
||||||
|
CHTTPServer::CScreenArray::rotateRows(
|
||||||
|
SInt32 i)
|
||||||
{
|
{
|
||||||
// nothing to do if no rows
|
// nothing to do if no rows
|
||||||
if (m_h == 0) {
|
if (m_h == 0) {
|
||||||
|
@ -471,7 +495,9 @@ void CHTTPServer::CScreenArray::rotateRows(SInt32 i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPServer::CScreenArray::rotateColumns(SInt32 i)
|
void
|
||||||
|
CHTTPServer::CScreenArray::rotateColumns(
|
||||||
|
SInt32 i)
|
||||||
{
|
{
|
||||||
// nothing to do if no columns
|
// nothing to do if no columns
|
||||||
if (m_h == 0) {
|
if (m_h == 0) {
|
||||||
|
@ -501,13 +527,19 @@ void CHTTPServer::CScreenArray::rotateColumns(SInt32 i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPServer::CScreenArray::remove(SInt32 x, SInt32 y)
|
void
|
||||||
|
CHTTPServer::CScreenArray::remove(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
set(x, y, CString());
|
set(x, y, CString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPServer::CScreenArray::set(
|
void
|
||||||
SInt32 x, SInt32 y, const CString& name)
|
CHTTPServer::CScreenArray::set(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y,
|
||||||
|
const CString& name)
|
||||||
{
|
{
|
||||||
assert(x >= 0 && x < m_w);
|
assert(x >= 0 && x < m_w);
|
||||||
assert(y >= 0 && y < m_h);
|
assert(y >= 0 && y < m_h);
|
||||||
|
@ -515,8 +547,10 @@ void CHTTPServer::CScreenArray::set(
|
||||||
m_screens[x + y * m_w] = name;
|
m_screens[x + y * m_w] = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CHTTPServer::CScreenArray::isAllowed(
|
bool
|
||||||
SInt32 x, SInt32 y) const
|
CHTTPServer::CScreenArray::isAllowed(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y) const
|
||||||
{
|
{
|
||||||
assert(x >= 0 && x < m_w);
|
assert(x >= 0 && x < m_w);
|
||||||
assert(y >= 0 && y < m_h);
|
assert(y >= 0 && y < m_h);
|
||||||
|
@ -536,8 +570,10 @@ bool CHTTPServer::CScreenArray::isAllowed(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CHTTPServer::CScreenArray::isSet(
|
bool
|
||||||
SInt32 x, SInt32 y) const
|
CHTTPServer::CScreenArray::isSet(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y) const
|
||||||
{
|
{
|
||||||
assert(x >= 0 && x < m_w);
|
assert(x >= 0 && x < m_w);
|
||||||
assert(y >= 0 && y < m_h);
|
assert(y >= 0 && y < m_h);
|
||||||
|
@ -545,8 +581,10 @@ bool CHTTPServer::CScreenArray::isSet(
|
||||||
return !m_screens[x + y * m_w].empty();
|
return !m_screens[x + y * m_w].empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CHTTPServer::CScreenArray::get(
|
CString
|
||||||
SInt32 x, SInt32 y) const
|
CHTTPServer::CScreenArray::get(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y) const
|
||||||
{
|
{
|
||||||
assert(x >= 0 && x < m_w);
|
assert(x >= 0 && x < m_w);
|
||||||
assert(y >= 0 && y < m_h);
|
assert(y >= 0 && y < m_h);
|
||||||
|
@ -554,9 +592,11 @@ CString CHTTPServer::CScreenArray::get(
|
||||||
return m_screens[x + y * m_w];
|
return m_screens[x + y * m_w];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CHTTPServer::CScreenArray::find(
|
bool
|
||||||
const CString& name,
|
CHTTPServer::CScreenArray::find(
|
||||||
SInt32& xOut, SInt32& yOut) const
|
const CString& name,
|
||||||
|
SInt32& xOut,
|
||||||
|
SInt32& yOut) const
|
||||||
{
|
{
|
||||||
for (SInt32 y = 0; y < m_h; ++y) {
|
for (SInt32 y = 0; y < m_h; ++y) {
|
||||||
for (SInt32 x = 0; x < m_w; ++x) {
|
for (SInt32 x = 0; x < m_w; ++x) {
|
||||||
|
@ -570,7 +610,8 @@ bool CHTTPServer::CScreenArray::find(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CHTTPServer::CScreenArray::isValid() const
|
bool
|
||||||
|
CHTTPServer::CScreenArray::isValid() const
|
||||||
{
|
{
|
||||||
SInt32 count = 0, isolated = 0;
|
SInt32 count = 0, isolated = 0;
|
||||||
for (SInt32 y = 0; y < m_h; ++y) {
|
for (SInt32 y = 0; y < m_h; ++y) {
|
||||||
|
@ -586,8 +627,9 @@ bool CHTTPServer::CScreenArray::isValid() const
|
||||||
return (count <= 1 || isolated == 0);
|
return (count <= 1 || isolated == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CHTTPServer::CScreenArray::convertFrom(
|
bool
|
||||||
const CConfig& config)
|
CHTTPServer::CScreenArray::convertFrom(
|
||||||
|
const CConfig& config)
|
||||||
{
|
{
|
||||||
typedef std::set<CString> ScreenSet;
|
typedef std::set<CString> ScreenSet;
|
||||||
|
|
||||||
|
@ -717,8 +759,9 @@ bool CHTTPServer::CScreenArray::convertFrom(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHTTPServer::CScreenArray::convertTo(
|
void
|
||||||
CConfig& config) const
|
CHTTPServer::CScreenArray::convertTo(
|
||||||
|
CConfig& config) const
|
||||||
{
|
{
|
||||||
config.removeAllScreens();
|
config.removeAllScreens();
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef CHTTPSERVER_H
|
#ifndef CHTTPSERVER_H
|
||||||
#define CHTTPSERVER_H
|
#define CHTTPSERVER_H
|
||||||
|
|
||||||
#include "BasicTypes.h"
|
|
||||||
#include "CString.h"
|
#include "CString.h"
|
||||||
|
#include "BasicTypes.h"
|
||||||
#include "stdvector.h"
|
#include "stdvector.h"
|
||||||
|
|
||||||
class CServer;
|
class CServer;
|
||||||
|
|
|
@ -1,29 +1,28 @@
|
||||||
#include "CMSWindowsPrimaryScreen.h"
|
#include "CMSWindowsPrimaryScreen.h"
|
||||||
#include "CMSWindowsClipboard.h"
|
|
||||||
#include "CServer.h"
|
#include "CServer.h"
|
||||||
|
#include "CMSWindowsClipboard.h"
|
||||||
#include "CPlatform.h"
|
#include "CPlatform.h"
|
||||||
#include "XScreen.h"
|
#include "XScreen.h"
|
||||||
#include "XSynergy.h"
|
#include "XSynergy.h"
|
||||||
#include "CLog.h"
|
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
#include <assert.h>
|
#include "CLog.h"
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
|
|
||||||
//
|
//
|
||||||
// CMSWindowsPrimaryScreen
|
// CMSWindowsPrimaryScreen
|
||||||
//
|
//
|
||||||
|
|
||||||
CMSWindowsPrimaryScreen::CMSWindowsPrimaryScreen() :
|
CMSWindowsPrimaryScreen::CMSWindowsPrimaryScreen() :
|
||||||
m_server(NULL),
|
m_server(NULL),
|
||||||
m_threadID(0),
|
m_threadID(0),
|
||||||
m_desk(NULL),
|
m_desk(NULL),
|
||||||
m_deskName(),
|
m_deskName(),
|
||||||
m_window(NULL),
|
m_window(NULL),
|
||||||
m_active(false),
|
m_active(false),
|
||||||
m_mark(0),
|
m_mark(0),
|
||||||
m_markReceived(0),
|
m_markReceived(0),
|
||||||
m_nextClipboardWindow(NULL),
|
m_nextClipboardWindow(NULL),
|
||||||
m_clipboardOwner(NULL)
|
m_clipboardOwner(NULL)
|
||||||
{
|
{
|
||||||
// load the hook library
|
// load the hook library
|
||||||
m_hookLibrary = LoadLibrary("synrgyhk");
|
m_hookLibrary = LoadLibrary("synrgyhk");
|
||||||
|
@ -61,7 +60,8 @@ CMSWindowsPrimaryScreen::~CMSWindowsPrimaryScreen()
|
||||||
FreeLibrary(m_hookLibrary);
|
FreeLibrary(m_hookLibrary);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::run()
|
void
|
||||||
|
CMSWindowsPrimaryScreen::run()
|
||||||
{
|
{
|
||||||
// must call run() from same thread as open()
|
// must call run() from same thread as open()
|
||||||
assert(m_threadID == GetCurrentThreadId());
|
assert(m_threadID == GetCurrentThreadId());
|
||||||
|
@ -87,12 +87,15 @@ void CMSWindowsPrimaryScreen::run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::stop()
|
void
|
||||||
|
CMSWindowsPrimaryScreen::stop()
|
||||||
{
|
{
|
||||||
doStop();
|
doStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::open(CServer* server)
|
void
|
||||||
|
CMSWindowsPrimaryScreen::open(
|
||||||
|
CServer* server)
|
||||||
{
|
{
|
||||||
assert(m_server == NULL);
|
assert(m_server == NULL);
|
||||||
assert(server != NULL);
|
assert(server != NULL);
|
||||||
|
@ -126,7 +129,8 @@ void CMSWindowsPrimaryScreen::open(CServer* server)
|
||||||
enterNoWarp();
|
enterNoWarp();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::close()
|
void
|
||||||
|
CMSWindowsPrimaryScreen::close()
|
||||||
{
|
{
|
||||||
assert(m_server != NULL);
|
assert(m_server != NULL);
|
||||||
|
|
||||||
|
@ -137,7 +141,10 @@ void CMSWindowsPrimaryScreen::close()
|
||||||
m_server = NULL;
|
m_server = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::enter(SInt32 x, SInt32 y)
|
void
|
||||||
|
CMSWindowsPrimaryScreen::enter(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
log((CLOG_INFO "entering primary at %d,%d", x, y));
|
log((CLOG_INFO "entering primary at %d,%d", x, y));
|
||||||
assert(m_active == true);
|
assert(m_active == true);
|
||||||
|
@ -149,7 +156,8 @@ void CMSWindowsPrimaryScreen::enter(SInt32 x, SInt32 y)
|
||||||
warpCursor(x, y);
|
warpCursor(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMSWindowsPrimaryScreen::leave()
|
bool
|
||||||
|
CMSWindowsPrimaryScreen::leave()
|
||||||
{
|
{
|
||||||
log((CLOG_INFO "leaving primary"));
|
log((CLOG_INFO "leaving primary"));
|
||||||
assert(m_active == false);
|
assert(m_active == false);
|
||||||
|
@ -219,7 +227,8 @@ bool CMSWindowsPrimaryScreen::leave()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::onConfigure()
|
void
|
||||||
|
CMSWindowsPrimaryScreen::onConfigure()
|
||||||
{
|
{
|
||||||
if ((m_is95Family || m_desk != NULL) && !m_active) {
|
if ((m_is95Family || m_desk != NULL) && !m_active) {
|
||||||
SInt32 w, h;
|
SInt32 w, h;
|
||||||
|
@ -229,14 +238,19 @@ void CMSWindowsPrimaryScreen::onConfigure()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::warpCursor(SInt32 x, SInt32 y)
|
void
|
||||||
|
CMSWindowsPrimaryScreen::warpCursor(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
// set the cursor position without generating an event
|
// set the cursor position without generating an event
|
||||||
SetCursorPos(x, y);
|
SetCursorPos(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::setClipboard(
|
void
|
||||||
ClipboardID /*id*/, const IClipboard* src)
|
CMSWindowsPrimaryScreen::setClipboard(
|
||||||
|
ClipboardID /*id*/,
|
||||||
|
const IClipboard* src)
|
||||||
{
|
{
|
||||||
assert(m_window != NULL);
|
assert(m_window != NULL);
|
||||||
|
|
||||||
|
@ -244,8 +258,9 @@ void CMSWindowsPrimaryScreen::setClipboard(
|
||||||
CClipboard::copy(&dst, src);
|
CClipboard::copy(&dst, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::grabClipboard(
|
void
|
||||||
ClipboardID /*id*/)
|
CMSWindowsPrimaryScreen::grabClipboard(
|
||||||
|
ClipboardID /*id*/)
|
||||||
{
|
{
|
||||||
assert(m_window != NULL);
|
assert(m_window != NULL);
|
||||||
|
|
||||||
|
@ -255,19 +270,24 @@ void CMSWindowsPrimaryScreen::grabClipboard(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::getSize(
|
void
|
||||||
SInt32* width, SInt32* height) const
|
CMSWindowsPrimaryScreen::getSize(
|
||||||
|
SInt32* width,
|
||||||
|
SInt32* height) const
|
||||||
{
|
{
|
||||||
getScreenSize(width, height);
|
getScreenSize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
SInt32 CMSWindowsPrimaryScreen::getJumpZoneSize() const
|
SInt32
|
||||||
|
CMSWindowsPrimaryScreen::getJumpZoneSize() const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::getClipboard(
|
void
|
||||||
ClipboardID /*id*/, IClipboard* dst) const
|
CMSWindowsPrimaryScreen::getClipboard(
|
||||||
|
ClipboardID /*id*/,
|
||||||
|
IClipboard* dst) const
|
||||||
{
|
{
|
||||||
assert(m_window != NULL);
|
assert(m_window != NULL);
|
||||||
|
|
||||||
|
@ -275,7 +295,8 @@ void CMSWindowsPrimaryScreen::getClipboard(
|
||||||
CClipboard::copy(dst, &src);
|
CClipboard::copy(dst, &src);
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyModifierMask CMSWindowsPrimaryScreen::getToggleMask() const
|
KeyModifierMask
|
||||||
|
CMSWindowsPrimaryScreen::getToggleMask() const
|
||||||
{
|
{
|
||||||
KeyModifierMask mask = 0;
|
KeyModifierMask mask = 0;
|
||||||
if ((GetKeyState(VK_CAPITAL) & 0x01) != 0)
|
if ((GetKeyState(VK_CAPITAL) & 0x01) != 0)
|
||||||
|
@ -287,7 +308,8 @@ KeyModifierMask CMSWindowsPrimaryScreen::getToggleMask() const
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMSWindowsPrimaryScreen::isLockedToScreen() const
|
bool
|
||||||
|
CMSWindowsPrimaryScreen::isLockedToScreen() const
|
||||||
{
|
{
|
||||||
// check buttons
|
// check buttons
|
||||||
if (GetAsyncKeyState(VK_LBUTTON) < 0 ||
|
if (GetAsyncKeyState(VK_LBUTTON) < 0 ||
|
||||||
|
@ -310,7 +332,8 @@ bool CMSWindowsPrimaryScreen::isLockedToScreen() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::onOpenDisplay()
|
void
|
||||||
|
CMSWindowsPrimaryScreen::onOpenDisplay()
|
||||||
{
|
{
|
||||||
assert(m_window == NULL);
|
assert(m_window == NULL);
|
||||||
assert(m_server != NULL);
|
assert(m_server != NULL);
|
||||||
|
@ -331,7 +354,8 @@ void CMSWindowsPrimaryScreen::onOpenDisplay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::onCloseDisplay()
|
void
|
||||||
|
CMSWindowsPrimaryScreen::onCloseDisplay()
|
||||||
{
|
{
|
||||||
// disconnect from desktop
|
// disconnect from desktop
|
||||||
if (m_is95Family) {
|
if (m_is95Family) {
|
||||||
|
@ -348,7 +372,9 @@ void CMSWindowsPrimaryScreen::onCloseDisplay()
|
||||||
assert(m_desk == NULL);
|
assert(m_desk == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMSWindowsPrimaryScreen::onPreTranslate(MSG* msg)
|
bool
|
||||||
|
CMSWindowsPrimaryScreen::onPreTranslate(
|
||||||
|
MSG* msg)
|
||||||
{
|
{
|
||||||
// handle event
|
// handle event
|
||||||
switch (msg->message) {
|
switch (msg->message) {
|
||||||
|
@ -477,9 +503,12 @@ bool CMSWindowsPrimaryScreen::onPreTranslate(MSG* msg)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT CMSWindowsPrimaryScreen::onEvent(
|
LRESULT
|
||||||
HWND hwnd, UINT msg,
|
CMSWindowsPrimaryScreen::onEvent(
|
||||||
WPARAM wParam, LPARAM lParam)
|
HWND hwnd,
|
||||||
|
UINT msg,
|
||||||
|
WPARAM wParam,
|
||||||
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case WM_QUERYENDSESSION:
|
case WM_QUERYENDSESSION:
|
||||||
|
@ -571,7 +600,8 @@ LRESULT CMSWindowsPrimaryScreen::onEvent(
|
||||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::enterNoWarp()
|
void
|
||||||
|
CMSWindowsPrimaryScreen::enterNoWarp()
|
||||||
{
|
{
|
||||||
// not active anymore
|
// not active anymore
|
||||||
m_active = false;
|
m_active = false;
|
||||||
|
@ -595,7 +625,8 @@ void CMSWindowsPrimaryScreen::enterNoWarp()
|
||||||
nextMark();
|
nextMark();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::onEnter()
|
void
|
||||||
|
CMSWindowsPrimaryScreen::onEnter()
|
||||||
{
|
{
|
||||||
// restore the active window and hide our window. we can only set
|
// restore the active window and hide our window. we can only set
|
||||||
// the active window for another thread if we first attach our input
|
// the active window for another thread if we first attach our input
|
||||||
|
@ -613,7 +644,8 @@ void CMSWindowsPrimaryScreen::onEnter()
|
||||||
ShowWindow(m_window, SW_HIDE);
|
ShowWindow(m_window, SW_HIDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMSWindowsPrimaryScreen::onLeave()
|
bool
|
||||||
|
CMSWindowsPrimaryScreen::onLeave()
|
||||||
{
|
{
|
||||||
// remember the active window before we leave. GetActiveWindow()
|
// remember the active window before we leave. GetActiveWindow()
|
||||||
// will only return the active window for the thread's queue (i.e.
|
// will only return the active window for the thread's queue (i.e.
|
||||||
|
@ -643,7 +675,8 @@ bool CMSWindowsPrimaryScreen::onLeave()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::nextMark()
|
void
|
||||||
|
CMSWindowsPrimaryScreen::nextMark()
|
||||||
{
|
{
|
||||||
// next mark
|
// next mark
|
||||||
++m_mark;
|
++m_mark;
|
||||||
|
@ -652,7 +685,8 @@ void CMSWindowsPrimaryScreen::nextMark()
|
||||||
PostThreadMessage(m_threadID, SYNERGY_MSG_MARK, m_mark, 0);
|
PostThreadMessage(m_threadID, SYNERGY_MSG_MARK, m_mark, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMSWindowsPrimaryScreen::openDesktop()
|
bool
|
||||||
|
CMSWindowsPrimaryScreen::openDesktop()
|
||||||
{
|
{
|
||||||
// install hooks
|
// install hooks
|
||||||
m_install(m_threadID);
|
m_install(m_threadID);
|
||||||
|
@ -687,7 +721,8 @@ bool CMSWindowsPrimaryScreen::openDesktop()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::closeDesktop()
|
void
|
||||||
|
CMSWindowsPrimaryScreen::closeDesktop()
|
||||||
{
|
{
|
||||||
// destroy old window
|
// destroy old window
|
||||||
if (m_window != NULL) {
|
if (m_window != NULL) {
|
||||||
|
@ -714,7 +749,9 @@ void CMSWindowsPrimaryScreen::closeDesktop()
|
||||||
m_uninstall();
|
m_uninstall();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMSWindowsPrimaryScreen::switchDesktop(HDESK desk)
|
bool
|
||||||
|
CMSWindowsPrimaryScreen::switchDesktop(
|
||||||
|
HDESK desk)
|
||||||
{
|
{
|
||||||
// did we own the clipboard?
|
// did we own the clipboard?
|
||||||
bool ownClipboard = (m_clipboardOwner == m_window);
|
bool ownClipboard = (m_clipboardOwner == m_window);
|
||||||
|
@ -818,7 +855,8 @@ bool CMSWindowsPrimaryScreen::switchDesktop(HDESK desk)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CMSWindowsPrimaryScreen::getCurrentDesktopName() const
|
CString
|
||||||
|
CMSWindowsPrimaryScreen::getCurrentDesktopName() const
|
||||||
{
|
{
|
||||||
return m_deskName;
|
return m_deskName;
|
||||||
}
|
}
|
||||||
|
@ -1083,9 +1121,11 @@ static const KeyID g_virtualKey[] =
|
||||||
/* 0xff */ kKeyNone // reserved
|
/* 0xff */ kKeyNone // reserved
|
||||||
};
|
};
|
||||||
|
|
||||||
KeyID CMSWindowsPrimaryScreen::mapKey(
|
KeyID
|
||||||
WPARAM vkCode, LPARAM info,
|
CMSWindowsPrimaryScreen::mapKey(
|
||||||
KeyModifierMask* maskOut)
|
WPARAM vkCode,
|
||||||
|
LPARAM info,
|
||||||
|
KeyModifierMask* maskOut)
|
||||||
{
|
{
|
||||||
// note: known microsoft bugs
|
// note: known microsoft bugs
|
||||||
// Q72583 -- MapVirtualKey() maps keypad keys incorrectly
|
// Q72583 -- MapVirtualKey() maps keypad keys incorrectly
|
||||||
|
@ -1101,25 +1141,32 @@ KeyID CMSWindowsPrimaryScreen::mapKey(
|
||||||
KeyModifierMask mask = 0;
|
KeyModifierMask mask = 0;
|
||||||
if (((m_keys[VK_LSHIFT] |
|
if (((m_keys[VK_LSHIFT] |
|
||||||
m_keys[VK_RSHIFT] |
|
m_keys[VK_RSHIFT] |
|
||||||
m_keys[VK_SHIFT]) & 0x80) != 0)
|
m_keys[VK_SHIFT]) & 0x80) != 0) {
|
||||||
mask |= KeyModifierShift;
|
mask |= KeyModifierShift;
|
||||||
|
}
|
||||||
if (((m_keys[VK_LCONTROL] |
|
if (((m_keys[VK_LCONTROL] |
|
||||||
m_keys[VK_RCONTROL] |
|
m_keys[VK_RCONTROL] |
|
||||||
m_keys[VK_CONTROL]) & 0x80) != 0)
|
m_keys[VK_CONTROL]) & 0x80) != 0) {
|
||||||
mask |= KeyModifierControl;
|
mask |= KeyModifierControl;
|
||||||
|
}
|
||||||
if (((m_keys[VK_LMENU] |
|
if (((m_keys[VK_LMENU] |
|
||||||
m_keys[VK_RMENU] |
|
m_keys[VK_RMENU] |
|
||||||
m_keys[VK_MENU]) & 0x80) != 0)
|
m_keys[VK_MENU]) & 0x80) != 0) {
|
||||||
mask |= KeyModifierAlt;
|
mask |= KeyModifierAlt;
|
||||||
|
}
|
||||||
if (((m_keys[VK_LWIN] |
|
if (((m_keys[VK_LWIN] |
|
||||||
m_keys[VK_RWIN]) & 0x80) != 0)
|
m_keys[VK_RWIN]) & 0x80) != 0) {
|
||||||
mask |= KeyModifierMeta;
|
mask |= KeyModifierMeta;
|
||||||
if ((m_keys[VK_CAPITAL] & 0x01) != 0)
|
}
|
||||||
|
if ((m_keys[VK_CAPITAL] & 0x01) != 0) {
|
||||||
mask |= KeyModifierCapsLock;
|
mask |= KeyModifierCapsLock;
|
||||||
if ((m_keys[VK_NUMLOCK] & 0x01) != 0)
|
}
|
||||||
|
if ((m_keys[VK_NUMLOCK] & 0x01) != 0) {
|
||||||
mask |= KeyModifierNumLock;
|
mask |= KeyModifierNumLock;
|
||||||
if ((m_keys[VK_SCROLL] & 0x01) != 0)
|
}
|
||||||
|
if ((m_keys[VK_SCROLL] & 0x01) != 0) {
|
||||||
mask |= KeyModifierScrollLock;
|
mask |= KeyModifierScrollLock;
|
||||||
|
}
|
||||||
*maskOut = mask;
|
*maskOut = mask;
|
||||||
log((CLOG_DEBUG2 "key in vk=%d info=0x%08x mask=0x%04x", vkCode, info, mask));
|
log((CLOG_DEBUG2 "key in vk=%d info=0x%08x mask=0x%04x", vkCode, info, mask));
|
||||||
|
|
||||||
|
@ -1133,17 +1180,20 @@ KeyID CMSWindowsPrimaryScreen::mapKey(
|
||||||
UINT vkCode2 = MapVirtualKey(scanCode, 3);
|
UINT vkCode2 = MapVirtualKey(scanCode, 3);
|
||||||
|
|
||||||
// work around bug Q72583 (bad num pad conversion in MapVirtualKey())
|
// work around bug Q72583 (bad num pad conversion in MapVirtualKey())
|
||||||
if (vkCode >= VK_NUMPAD0 && vkCode <= VK_DIVIDE)
|
if (vkCode >= VK_NUMPAD0 && vkCode <= VK_DIVIDE) {
|
||||||
vkCode2 = vkCode;
|
vkCode2 = vkCode;
|
||||||
|
}
|
||||||
|
|
||||||
// MapVirtualKey() appears to map VK_LWIN, VK_RWIN, VK_APPS to
|
// MapVirtualKey() appears to map VK_LWIN, VK_RWIN, VK_APPS to
|
||||||
// some other meaningless virtual key. work around that bug.
|
// some other meaningless virtual key. work around that bug.
|
||||||
else if (vkCode >= VK_LWIN && vkCode <= VK_APPS)
|
else if (vkCode >= VK_LWIN && vkCode <= VK_APPS) {
|
||||||
vkCode2 = vkCode;
|
vkCode2 = vkCode;
|
||||||
|
}
|
||||||
|
|
||||||
// if MapVirtualKey failed then use original virtual key
|
// if MapVirtualKey failed then use original virtual key
|
||||||
else if (vkCode2 == 0)
|
else if (vkCode2 == 0) {
|
||||||
vkCode2 = vkCode;
|
vkCode2 = vkCode;
|
||||||
|
}
|
||||||
|
|
||||||
// sadly, win32 will not distinguish between the left and right
|
// sadly, win32 will not distinguish between the left and right
|
||||||
// control and alt keys using the above function. however, we
|
// control and alt keys using the above function. however, we
|
||||||
|
@ -1223,12 +1273,16 @@ KeyID CMSWindowsPrimaryScreen::mapKey(
|
||||||
// set shift state required to generate key
|
// set shift state required to generate key
|
||||||
BYTE keys[256];
|
BYTE keys[256];
|
||||||
memset(keys, 0, sizeof(keys));
|
memset(keys, 0, sizeof(keys));
|
||||||
if (vkCode & 0x0100)
|
// FIXME -- surely these masks should be different in each if expression
|
||||||
|
if (vkCode & 0x0100) {
|
||||||
keys[VK_SHIFT] = 0x80;
|
keys[VK_SHIFT] = 0x80;
|
||||||
if (vkCode & 0x0100)
|
}
|
||||||
|
if (vkCode & 0x0100) {
|
||||||
keys[VK_CONTROL] = 0x80;
|
keys[VK_CONTROL] = 0x80;
|
||||||
if (vkCode & 0x0100)
|
}
|
||||||
|
if (vkCode & 0x0100) {
|
||||||
keys[VK_MENU] = 0x80;
|
keys[VK_MENU] = 0x80;
|
||||||
|
}
|
||||||
|
|
||||||
// strip shift state off of virtual key code
|
// strip shift state off of virtual key code
|
||||||
vkCode &= 0x00ff;
|
vkCode &= 0x00ff;
|
||||||
|
@ -1245,8 +1299,9 @@ KeyID CMSWindowsPrimaryScreen::mapKey(
|
||||||
return kKeyNone;
|
return kKeyNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonID CMSWindowsPrimaryScreen::mapButton(
|
ButtonID
|
||||||
WPARAM button) const
|
CMSWindowsPrimaryScreen::mapButton(
|
||||||
|
WPARAM button) const
|
||||||
{
|
{
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
|
@ -1266,7 +1321,8 @@ ButtonID CMSWindowsPrimaryScreen::mapButton(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::updateKeys()
|
void
|
||||||
|
CMSWindowsPrimaryScreen::updateKeys()
|
||||||
{
|
{
|
||||||
// not using GetKeyboardState() because that doesn't seem to give
|
// not using GetKeyboardState() because that doesn't seem to give
|
||||||
// up-to-date results. i don't know why that is or why GetKeyState()
|
// up-to-date results. i don't know why that is or why GetKeyState()
|
||||||
|
@ -1293,8 +1349,10 @@ void CMSWindowsPrimaryScreen::updateKeys()
|
||||||
m_keys[VK_SCROLL] = static_cast<BYTE>(GetKeyState(VK_SCROLL));
|
m_keys[VK_SCROLL] = static_cast<BYTE>(GetKeyState(VK_SCROLL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMSWindowsPrimaryScreen::updateKey(
|
void
|
||||||
UINT vkCode, bool press)
|
CMSWindowsPrimaryScreen::updateKey(
|
||||||
|
UINT vkCode,
|
||||||
|
bool press)
|
||||||
{
|
{
|
||||||
if (press) {
|
if (press) {
|
||||||
switch (vkCode) {
|
switch (vkCode) {
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
#define CMSWINDOWSPRIMARYSCREEN_H
|
#define CMSWINDOWSPRIMARYSCREEN_H
|
||||||
|
|
||||||
#include "CMSWindowsScreen.h"
|
#include "CMSWindowsScreen.h"
|
||||||
#include "IPrimaryScreen.h"
|
|
||||||
#include "MouseTypes.h"
|
|
||||||
#include "CString.h"
|
|
||||||
#include "CSynergyHook.h"
|
#include "CSynergyHook.h"
|
||||||
|
#include "MouseTypes.h"
|
||||||
|
#include "IPrimaryScreen.h"
|
||||||
|
#include "CString.h"
|
||||||
|
|
||||||
class CMSWindowsPrimaryScreen : public CMSWindowsScreen, public IPrimaryScreen {
|
class CMSWindowsPrimaryScreen : public CMSWindowsScreen, public IPrimaryScreen {
|
||||||
public:
|
public:
|
||||||
|
@ -56,7 +56,7 @@ private:
|
||||||
|
|
||||||
// key and button queries
|
// key and button queries
|
||||||
KeyID mapKey(WPARAM keycode, LPARAM info,
|
KeyID mapKey(WPARAM keycode, LPARAM info,
|
||||||
KeyModifierMask* maskOut);
|
KeyModifierMask* maskOut);
|
||||||
ButtonID mapButton(WPARAM button) const;
|
ButtonID mapButton(WPARAM button) const;
|
||||||
void updateKeys();
|
void updateKeys();
|
||||||
void updateKey(UINT vkCode, bool press);
|
void updateKey(UINT vkCode, bool press);
|
||||||
|
|
|
@ -2,26 +2,25 @@
|
||||||
#include "CHTTPServer.h"
|
#include "CHTTPServer.h"
|
||||||
#include "CInputPacketStream.h"
|
#include "CInputPacketStream.h"
|
||||||
#include "COutputPacketStream.h"
|
#include "COutputPacketStream.h"
|
||||||
#include "CServerProtocol.h"
|
|
||||||
#include "CProtocolUtil.h"
|
#include "CProtocolUtil.h"
|
||||||
|
#include "CServerProtocol.h"
|
||||||
#include "IPrimaryScreen.h"
|
#include "IPrimaryScreen.h"
|
||||||
#include "ISocketFactory.h"
|
|
||||||
#include "ProtocolTypes.h"
|
#include "ProtocolTypes.h"
|
||||||
|
#include "XScreen.h"
|
||||||
|
#include "XSynergy.h"
|
||||||
#include "CNetworkAddress.h"
|
#include "CNetworkAddress.h"
|
||||||
#include "ISocket.h"
|
|
||||||
#include "IListenSocket.h"
|
#include "IListenSocket.h"
|
||||||
|
#include "ISocket.h"
|
||||||
|
#include "ISocketFactory.h"
|
||||||
|
#include "XSocket.h"
|
||||||
#include "CLock.h"
|
#include "CLock.h"
|
||||||
#include "CLog.h"
|
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
#include "CTimerThread.h"
|
#include "CTimerThread.h"
|
||||||
#include "CStopwatch.h"
|
|
||||||
#include "CFunctionJob.h"
|
|
||||||
#include "TMethodJob.h"
|
|
||||||
#include "XScreen.h"
|
|
||||||
#include "XSocket.h"
|
|
||||||
#include "XSynergy.h"
|
|
||||||
#include "XThread.h"
|
#include "XThread.h"
|
||||||
#include <assert.h>
|
#include "CFunctionJob.h"
|
||||||
|
#include "CLog.h"
|
||||||
|
#include "CStopwatch.h"
|
||||||
|
#include "TMethodJob.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
// hack to work around operator=() bug in STL in g++ prior to v3
|
// hack to work around operator=() bug in STL in g++ prior to v3
|
||||||
|
@ -31,32 +30,22 @@
|
||||||
#define assign(_dst, _src, _type) _dst = std::auto_ptr<_type >(_src)
|
#define assign(_dst, _src, _type) _dst = std::auto_ptr<_type >(_src)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* XXX
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
if (fork() == 0) abort();
|
|
||||||
else { wait(0); exit(1); }
|
|
||||||
*/
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CServer
|
// CServer
|
||||||
//
|
//
|
||||||
|
|
||||||
const SInt32 CServer::s_httpMaxSimultaneousRequests = 3;
|
const SInt32 CServer::s_httpMaxSimultaneousRequests = 3;
|
||||||
|
|
||||||
CServer::CServer(const CString& serverName) :
|
CServer::CServer(
|
||||||
m_name(serverName),
|
const CString& serverName) :
|
||||||
m_cleanupSize(&m_mutex, 0),
|
m_name(serverName),
|
||||||
m_primary(NULL),
|
m_cleanupSize(&m_mutex, 0),
|
||||||
m_active(NULL),
|
m_primary(NULL),
|
||||||
m_primaryInfo(NULL),
|
m_active(NULL),
|
||||||
m_seqNum(0),
|
m_primaryInfo(NULL),
|
||||||
m_httpServer(NULL),
|
m_seqNum(0),
|
||||||
m_httpAvailable(&m_mutex,
|
m_httpServer(NULL),
|
||||||
s_httpMaxSimultaneousRequests)
|
m_httpAvailable(&m_mutex, s_httpMaxSimultaneousRequests)
|
||||||
{
|
{
|
||||||
m_socketFactory = NULL;
|
m_socketFactory = NULL;
|
||||||
m_securityFactory = NULL;
|
m_securityFactory = NULL;
|
||||||
|
@ -68,7 +57,8 @@ CServer::~CServer()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::run()
|
void
|
||||||
|
CServer::run()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
log((CLOG_NOTE "starting server"));
|
log((CLOG_NOTE "starting server"));
|
||||||
|
@ -149,12 +139,14 @@ void CServer::run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::quit()
|
void
|
||||||
|
CServer::quit()
|
||||||
{
|
{
|
||||||
m_primary->stop();
|
m_primary->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::shutdown()
|
void
|
||||||
|
CServer::shutdown()
|
||||||
{
|
{
|
||||||
// stop all running threads but don't wait too long since some
|
// stop all running threads but don't wait too long since some
|
||||||
// threads may be unable to proceed until this thread returns.
|
// threads may be unable to proceed until this thread returns.
|
||||||
|
@ -167,7 +159,9 @@ void CServer::shutdown()
|
||||||
// note -- we do not attempt to close down the primary screen
|
// note -- we do not attempt to close down the primary screen
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CServer::setConfig(const CConfig& config)
|
bool
|
||||||
|
CServer::setConfig(
|
||||||
|
const CConfig& config)
|
||||||
{
|
{
|
||||||
typedef std::vector<CThread> CThreads;
|
typedef std::vector<CThread> CThreads;
|
||||||
CThreads threads;
|
CThreads threads;
|
||||||
|
@ -228,12 +222,15 @@ bool CServer::setConfig(const CConfig& config)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CServer::getPrimaryScreenName() const
|
CString
|
||||||
|
CServer::getPrimaryScreenName() const
|
||||||
{
|
{
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::getConfig(CConfig* config) const
|
void
|
||||||
|
CServer::getConfig(
|
||||||
|
CConfig* config) const
|
||||||
{
|
{
|
||||||
assert(config != NULL);
|
assert(config != NULL);
|
||||||
|
|
||||||
|
@ -241,7 +238,8 @@ void CServer::getConfig(CConfig* config) const
|
||||||
*config = m_config;
|
*config = m_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CServer::getActivePrimarySides() const
|
UInt32
|
||||||
|
CServer::getActivePrimarySides() const
|
||||||
{
|
{
|
||||||
UInt32 sides = 0;
|
UInt32 sides = 0;
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
@ -264,26 +262,40 @@ UInt32 CServer::getActivePrimarySides() const
|
||||||
return sides;
|
return sides;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::setInfo(
|
void
|
||||||
SInt32 w, SInt32 h, SInt32 zoneSize,
|
CServer::setInfo(
|
||||||
SInt32 x, SInt32 y)
|
SInt32 w,
|
||||||
|
SInt32 h,
|
||||||
|
SInt32 zoneSize,
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
assert(m_primaryInfo != NULL);
|
assert(m_primaryInfo != NULL);
|
||||||
setInfoNoLock(m_primaryInfo->m_name, w, h, zoneSize, x, y);
|
setInfoNoLock(m_primaryInfo->m_name, w, h, zoneSize, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::setInfo(const CString& client,
|
void
|
||||||
SInt32 w, SInt32 h, SInt32 zoneSize,
|
CServer::setInfo(
|
||||||
SInt32 x, SInt32 y)
|
const CString& client,
|
||||||
|
SInt32 w,
|
||||||
|
SInt32 h,
|
||||||
|
SInt32 zoneSize,
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
setInfoNoLock(client, w, h, zoneSize, x, y);
|
setInfoNoLock(client, w, h, zoneSize, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::setInfoNoLock(const CString& screen,
|
void
|
||||||
SInt32 w, SInt32 h, SInt32 zoneSize,
|
CServer::setInfoNoLock(
|
||||||
SInt32 x, SInt32 y)
|
const CString& screen,
|
||||||
|
SInt32 w,
|
||||||
|
SInt32 h,
|
||||||
|
SInt32 zoneSize,
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
assert(!screen.empty());
|
assert(!screen.empty());
|
||||||
assert(w > 0);
|
assert(w > 0);
|
||||||
|
@ -327,24 +339,30 @@ void CServer::setInfoNoLock(const CString& screen,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::grabClipboard(ClipboardID id)
|
void
|
||||||
|
CServer::grabClipboard(
|
||||||
|
ClipboardID id)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
assert(m_primaryInfo != NULL);
|
assert(m_primaryInfo != NULL);
|
||||||
grabClipboardNoLock(id, 0, m_primaryInfo->m_name);
|
grabClipboardNoLock(id, 0, m_primaryInfo->m_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::grabClipboard(
|
void
|
||||||
ClipboardID id, UInt32 seqNum,
|
CServer::grabClipboard(
|
||||||
const CString& client)
|
ClipboardID id,
|
||||||
|
UInt32 seqNum,
|
||||||
|
const CString& client)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
grabClipboardNoLock(id, seqNum, client);
|
grabClipboardNoLock(id, seqNum, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::grabClipboardNoLock(
|
void
|
||||||
ClipboardID id, UInt32 seqNum,
|
CServer::grabClipboardNoLock(
|
||||||
const CString& screen)
|
ClipboardID id,
|
||||||
|
UInt32 seqNum,
|
||||||
|
const CString& screen)
|
||||||
{
|
{
|
||||||
// note -- must be locked on entry
|
// note -- must be locked on entry
|
||||||
CClipboardInfo& clipboard = m_clipboards[id];
|
CClipboardInfo& clipboard = m_clipboards[id];
|
||||||
|
@ -402,8 +420,11 @@ void CServer::grabClipboardNoLock(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::setClipboard(ClipboardID id,
|
void
|
||||||
UInt32 seqNum, const CString& data)
|
CServer::setClipboard(
|
||||||
|
ClipboardID id,
|
||||||
|
UInt32 seqNum,
|
||||||
|
const CString& data)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
CClipboardInfo& clipboard = m_clipboards[id];
|
CClipboardInfo& clipboard = m_clipboards[id];
|
||||||
|
@ -433,13 +454,19 @@ void CServer::setClipboard(ClipboardID id,
|
||||||
sendClipboard(id);
|
sendClipboard(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CServer::onCommandKey(KeyID /*id*/,
|
bool
|
||||||
KeyModifierMask /*mask*/, bool /*down*/)
|
CServer::onCommandKey(
|
||||||
|
KeyID /*id*/,
|
||||||
|
KeyModifierMask /*mask*/,
|
||||||
|
bool /*down*/)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::onKeyDown(KeyID id, KeyModifierMask mask)
|
void
|
||||||
|
CServer::onKeyDown(
|
||||||
|
KeyID id,
|
||||||
|
KeyModifierMask mask)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "onKeyDown id=%d mask=0x%04x", id, mask));
|
log((CLOG_DEBUG1 "onKeyDown id=%d mask=0x%04x", id, mask));
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
@ -456,7 +483,10 @@ void CServer::onKeyDown(KeyID id, KeyModifierMask mask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::onKeyUp(KeyID id, KeyModifierMask mask)
|
void
|
||||||
|
CServer::onKeyUp(
|
||||||
|
KeyID id,
|
||||||
|
KeyModifierMask mask)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "onKeyUp id=%d mask=0x%04x", id, mask));
|
log((CLOG_DEBUG1 "onKeyUp id=%d mask=0x%04x", id, mask));
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
@ -473,8 +503,11 @@ void CServer::onKeyUp(KeyID id, KeyModifierMask mask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::onKeyRepeat(
|
void
|
||||||
KeyID id, KeyModifierMask mask, SInt32 count)
|
CServer::onKeyRepeat(
|
||||||
|
KeyID id,
|
||||||
|
KeyModifierMask mask,
|
||||||
|
SInt32 count)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "onKeyRepeat id=%d mask=0x%04x count=%d", id, mask, count));
|
log((CLOG_DEBUG1 "onKeyRepeat id=%d mask=0x%04x count=%d", id, mask, count));
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
@ -492,7 +525,9 @@ void CServer::onKeyRepeat(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::onMouseDown(ButtonID id)
|
void
|
||||||
|
CServer::onMouseDown(
|
||||||
|
ButtonID id)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "onMouseDown id=%d", id));
|
log((CLOG_DEBUG1 "onMouseDown id=%d", id));
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
@ -504,7 +539,9 @@ void CServer::onMouseDown(ButtonID id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::onMouseUp(ButtonID id)
|
void
|
||||||
|
CServer::onMouseUp(
|
||||||
|
ButtonID id)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "onMouseUp id=%d", id));
|
log((CLOG_DEBUG1 "onMouseUp id=%d", id));
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
@ -516,14 +553,20 @@ void CServer::onMouseUp(ButtonID id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CServer::onMouseMovePrimary(SInt32 x, SInt32 y)
|
bool
|
||||||
|
CServer::onMouseMovePrimary(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG2 "onMouseMovePrimary %d,%d", x, y));
|
log((CLOG_DEBUG2 "onMouseMovePrimary %d,%d", x, y));
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
return onMouseMovePrimaryNoLock(x, y);
|
return onMouseMovePrimaryNoLock(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CServer::onMouseMovePrimaryNoLock(SInt32 x, SInt32 y)
|
bool
|
||||||
|
CServer::onMouseMovePrimaryNoLock(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
// mouse move on primary (server's) screen
|
// mouse move on primary (server's) screen
|
||||||
assert(m_active != NULL);
|
assert(m_active != NULL);
|
||||||
|
@ -577,15 +620,20 @@ bool CServer::onMouseMovePrimaryNoLock(SInt32 x, SInt32 y)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::onMouseMoveSecondary(SInt32 dx, SInt32 dy)
|
void
|
||||||
|
CServer::onMouseMoveSecondary(
|
||||||
|
SInt32 dx,
|
||||||
|
SInt32 dy)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG2 "onMouseMoveSecondary %+d,%+d", dx, dy));
|
log((CLOG_DEBUG2 "onMouseMoveSecondary %+d,%+d", dx, dy));
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
onMouseMoveSecondaryNoLock(dx, dy);
|
onMouseMoveSecondaryNoLock(dx, dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::onMouseMoveSecondaryNoLock(
|
void
|
||||||
SInt32 dx, SInt32 dy)
|
CServer::onMouseMoveSecondaryNoLock(
|
||||||
|
SInt32 dx,
|
||||||
|
SInt32 dy)
|
||||||
{
|
{
|
||||||
// mouse move on secondary (client's) screen
|
// mouse move on secondary (client's) screen
|
||||||
assert(m_active != NULL);
|
assert(m_active != NULL);
|
||||||
|
@ -687,7 +735,9 @@ void CServer::onMouseMoveSecondaryNoLock(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::onMouseWheel(SInt32 delta)
|
void
|
||||||
|
CServer::onMouseWheel(
|
||||||
|
SInt32 delta)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "onMouseWheel %+d", delta));
|
log((CLOG_DEBUG1 "onMouseWheel %+d", delta));
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
@ -699,13 +749,15 @@ void CServer::onMouseWheel(SInt32 delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CServer::isLockedToScreen() const
|
bool
|
||||||
|
CServer::isLockedToScreen() const
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
return isLockedToScreenNoLock();
|
return isLockedToScreenNoLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CServer::isLockedToScreenNoLock() const
|
bool
|
||||||
|
CServer::isLockedToScreenNoLock() const
|
||||||
{
|
{
|
||||||
// locked if primary says we're locked
|
// locked if primary says we're locked
|
||||||
if (m_primary->isLockedToScreen()) {
|
if (m_primary->isLockedToScreen()) {
|
||||||
|
@ -721,8 +773,11 @@ bool CServer::isLockedToScreenNoLock() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::switchScreen(CScreenInfo* dst,
|
void
|
||||||
SInt32 x, SInt32 y)
|
CServer::switchScreen(
|
||||||
|
CScreenInfo* dst,
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
assert(dst != NULL);
|
assert(dst != NULL);
|
||||||
assert(x >= 0 && y >= 0 && x < dst->m_width && y < dst->m_height);
|
assert(x >= 0 && y >= 0 && x < dst->m_width && y < dst->m_height);
|
||||||
|
@ -789,8 +844,10 @@ void CServer::switchScreen(CScreenInfo* dst,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CServer::CScreenInfo* CServer::getNeighbor(CScreenInfo* src,
|
CServer::CScreenInfo*
|
||||||
CConfig::EDirection dir) const
|
CServer::getNeighbor(
|
||||||
|
CScreenInfo* src,
|
||||||
|
CConfig::EDirection dir) const
|
||||||
{
|
{
|
||||||
assert(src != NULL);
|
assert(src != NULL);
|
||||||
|
|
||||||
|
@ -821,9 +878,12 @@ CServer::CScreenInfo* CServer::getNeighbor(CScreenInfo* src,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CServer::CScreenInfo* CServer::getNeighbor(CScreenInfo* src,
|
CServer::CScreenInfo*
|
||||||
CConfig::EDirection srcSide,
|
CServer::getNeighbor(
|
||||||
SInt32& x, SInt32& y) const
|
CScreenInfo* src,
|
||||||
|
CConfig::EDirection srcSide,
|
||||||
|
SInt32& x,
|
||||||
|
SInt32& y) const
|
||||||
{
|
{
|
||||||
assert(src != NULL);
|
assert(src != NULL);
|
||||||
|
|
||||||
|
@ -936,10 +996,13 @@ CServer::CScreenInfo* CServer::getNeighbor(CScreenInfo* src,
|
||||||
return lastGoodScreen;
|
return lastGoodScreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::mapPosition(CScreenInfo* src,
|
void
|
||||||
CConfig::EDirection srcSide,
|
CServer::mapPosition(
|
||||||
CScreenInfo* dst,
|
CScreenInfo* src,
|
||||||
SInt32& x, SInt32& y) const
|
CConfig::EDirection srcSide,
|
||||||
|
CScreenInfo* dst,
|
||||||
|
SInt32& x,
|
||||||
|
SInt32& y) const
|
||||||
{
|
{
|
||||||
assert(src != NULL);
|
assert(src != NULL);
|
||||||
assert(dst != NULL);
|
assert(dst != NULL);
|
||||||
|
@ -949,32 +1012,39 @@ void CServer::mapPosition(CScreenInfo* src,
|
||||||
switch (srcSide) {
|
switch (srcSide) {
|
||||||
case CConfig::kLeft:
|
case CConfig::kLeft:
|
||||||
case CConfig::kRight:
|
case CConfig::kRight:
|
||||||
if (y < 0)
|
if (y < 0) {
|
||||||
y = 0;
|
y = 0;
|
||||||
else if (y >= src->m_height)
|
}
|
||||||
|
else if (y >= src->m_height) {
|
||||||
y = dst->m_height - 1;
|
y = dst->m_height - 1;
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
y = static_cast<SInt32>(0.5 + y *
|
y = static_cast<SInt32>(0.5 + y *
|
||||||
static_cast<double>(dst->m_height - 1) /
|
static_cast<double>(dst->m_height - 1) /
|
||||||
(src->m_height - 1));
|
(src->m_height - 1));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CConfig::kTop:
|
case CConfig::kTop:
|
||||||
case CConfig::kBottom:
|
case CConfig::kBottom:
|
||||||
if (x < 0)
|
if (x < 0) {
|
||||||
x = 0;
|
x = 0;
|
||||||
else if (x >= src->m_width)
|
}
|
||||||
|
else if (x >= src->m_width) {
|
||||||
x = dst->m_width - 1;
|
x = dst->m_width - 1;
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
x = static_cast<SInt32>(0.5 + x *
|
x = static_cast<SInt32>(0.5 + x *
|
||||||
static_cast<double>(dst->m_width - 1) /
|
static_cast<double>(dst->m_width - 1) /
|
||||||
(src->m_width - 1));
|
(src->m_width - 1));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "CTCPListenSocket.h"
|
#include "CTCPListenSocket.h"
|
||||||
void CServer::acceptClients(void*)
|
void
|
||||||
|
CServer::acceptClients(void*)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "starting to wait for clients"));
|
log((CLOG_DEBUG1 "starting to wait for clients"));
|
||||||
|
|
||||||
|
@ -1030,7 +1100,9 @@ void CServer::acceptClients(void*)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::handshakeClient(void* vsocket)
|
void
|
||||||
|
CServer::handshakeClient(
|
||||||
|
void* vsocket)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "negotiating with new client"));
|
log((CLOG_DEBUG1 "negotiating with new client"));
|
||||||
|
|
||||||
|
@ -1162,7 +1234,8 @@ void CServer::handshakeClient(void* vsocket)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::acceptHTTPClients(void*)
|
void
|
||||||
|
CServer::acceptHTTPClients(void*)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "starting to wait for HTTP clients"));
|
log((CLOG_DEBUG1 "starting to wait for HTTP clients"));
|
||||||
|
|
||||||
|
@ -1229,7 +1302,9 @@ void CServer::acceptHTTPClients(void*)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::processHTTPRequest(void* vsocket)
|
void
|
||||||
|
CServer::processHTTPRequest(
|
||||||
|
void* vsocket)
|
||||||
{
|
{
|
||||||
// add this thread to the list of threads to cancel. remove from
|
// add this thread to the list of threads to cancel. remove from
|
||||||
// list in d'tor.
|
// list in d'tor.
|
||||||
|
@ -1266,7 +1341,9 @@ void CServer::processHTTPRequest(void* vsocket)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::clearGotClipboard(ClipboardID id)
|
void
|
||||||
|
CServer::clearGotClipboard(
|
||||||
|
ClipboardID id)
|
||||||
{
|
{
|
||||||
for (CScreenList::const_iterator index = m_screens.begin();
|
for (CScreenList::const_iterator index = m_screens.begin();
|
||||||
index != m_screens.end(); ++index) {
|
index != m_screens.end(); ++index) {
|
||||||
|
@ -1274,7 +1351,9 @@ void CServer::clearGotClipboard(ClipboardID id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::sendClipboard(ClipboardID id)
|
void
|
||||||
|
CServer::sendClipboard(
|
||||||
|
ClipboardID id)
|
||||||
{
|
{
|
||||||
// do nothing if clipboard was already sent
|
// do nothing if clipboard was already sent
|
||||||
if (!m_active->m_gotClipboard[id]) {
|
if (!m_active->m_gotClipboard[id]) {
|
||||||
|
@ -1295,7 +1374,9 @@ void CServer::sendClipboard(ClipboardID id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::updatePrimaryClipboard(ClipboardID id)
|
void
|
||||||
|
CServer::updatePrimaryClipboard(
|
||||||
|
ClipboardID id)
|
||||||
{
|
{
|
||||||
CClipboardInfo& clipboard = m_clipboards[id];
|
CClipboardInfo& clipboard = m_clipboards[id];
|
||||||
|
|
||||||
|
@ -1339,7 +1420,8 @@ void CServer::updatePrimaryClipboard(ClipboardID id)
|
||||||
#elif defined(CONFIG_PLATFORM_UNIX)
|
#elif defined(CONFIG_PLATFORM_UNIX)
|
||||||
#include "CXWindowsPrimaryScreen.h"
|
#include "CXWindowsPrimaryScreen.h"
|
||||||
#endif
|
#endif
|
||||||
void CServer::openPrimaryScreen()
|
void
|
||||||
|
CServer::openPrimaryScreen()
|
||||||
{
|
{
|
||||||
assert(m_primary == NULL);
|
assert(m_primary == NULL);
|
||||||
|
|
||||||
|
@ -1387,7 +1469,8 @@ void CServer::openPrimaryScreen()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::closePrimaryScreen()
|
void
|
||||||
|
CServer::closePrimaryScreen()
|
||||||
{
|
{
|
||||||
assert(m_primary != NULL);
|
assert(m_primary != NULL);
|
||||||
|
|
||||||
|
@ -1410,14 +1493,18 @@ void CServer::closePrimaryScreen()
|
||||||
m_primary = NULL;
|
m_primary = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::addCleanupThread(const CThread& thread)
|
void
|
||||||
|
CServer::addCleanupThread(
|
||||||
|
const CThread& thread)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
m_cleanupList.insert(m_cleanupList.begin(), new CThread(thread));
|
m_cleanupList.insert(m_cleanupList.begin(), new CThread(thread));
|
||||||
m_cleanupSize = m_cleanupSize + 1;
|
m_cleanupSize = m_cleanupSize + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::removeCleanupThread(const CThread& thread)
|
void
|
||||||
|
CServer::removeCleanupThread(
|
||||||
|
const CThread& thread)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
for (CThreadList::iterator index = m_cleanupList.begin();
|
for (CThreadList::iterator index = m_cleanupList.begin();
|
||||||
|
@ -1435,7 +1522,9 @@ void CServer::removeCleanupThread(const CThread& thread)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::cleanupThreads(double timeout)
|
void
|
||||||
|
CServer::cleanupThreads(
|
||||||
|
double timeout)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "cleaning up threads"));
|
log((CLOG_DEBUG1 "cleaning up threads"));
|
||||||
|
|
||||||
|
@ -1474,8 +1563,10 @@ void CServer::cleanupThreads(double timeout)
|
||||||
log((CLOG_DEBUG1 "cleaned up threads"));
|
log((CLOG_DEBUG1 "cleaned up threads"));
|
||||||
}
|
}
|
||||||
|
|
||||||
CServer::CScreenInfo* CServer::addConnection(
|
CServer::CScreenInfo*
|
||||||
const CString& name, IServerProtocol* protocol)
|
CServer::addConnection(
|
||||||
|
const CString& name,
|
||||||
|
IServerProtocol* protocol)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG "adding connection \"%s\"", name.c_str()));
|
log((CLOG_DEBUG "adding connection \"%s\"", name.c_str()));
|
||||||
|
|
||||||
|
@ -1499,7 +1590,9 @@ CServer::CScreenInfo* CServer::addConnection(
|
||||||
return newScreen;
|
return newScreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::removeConnection(const CString& name)
|
void
|
||||||
|
CServer::removeConnection(
|
||||||
|
const CString& name)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG "removing connection \"%s\"", name.c_str()));
|
log((CLOG_DEBUG "removing connection \"%s\"", name.c_str()));
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
@ -1534,7 +1627,9 @@ void CServer::removeConnection(const CString& name)
|
||||||
// CServer::CCleanupNote
|
// CServer::CCleanupNote
|
||||||
//
|
//
|
||||||
|
|
||||||
CServer::CCleanupNote::CCleanupNote(CServer* server) : m_server(server)
|
CServer::CCleanupNote::CCleanupNote(
|
||||||
|
CServer* server) :
|
||||||
|
m_server(server)
|
||||||
{
|
{
|
||||||
assert(m_server != NULL);
|
assert(m_server != NULL);
|
||||||
m_server->addCleanupThread(CThread::getCurrentThread());
|
m_server->addCleanupThread(CThread::getCurrentThread());
|
||||||
|
@ -1550,11 +1645,12 @@ CServer::CCleanupNote::~CCleanupNote()
|
||||||
// CServer::CConnectionNote
|
// CServer::CConnectionNote
|
||||||
//
|
//
|
||||||
|
|
||||||
CServer::CConnectionNote::CConnectionNote(CServer* server,
|
CServer::CConnectionNote::CConnectionNote(
|
||||||
const CString& name,
|
CServer* server,
|
||||||
IServerProtocol* protocol) :
|
const CString& name,
|
||||||
m_server(server),
|
IServerProtocol* protocol) :
|
||||||
m_name(name)
|
m_server(server),
|
||||||
|
m_name(name)
|
||||||
{
|
{
|
||||||
assert(m_server != NULL);
|
assert(m_server != NULL);
|
||||||
m_server->addConnection(m_name, protocol);
|
m_server->addConnection(m_name, protocol);
|
||||||
|
@ -1570,14 +1666,16 @@ CServer::CConnectionNote::~CConnectionNote()
|
||||||
// CServer::CScreenInfo
|
// CServer::CScreenInfo
|
||||||
//
|
//
|
||||||
|
|
||||||
CServer::CScreenInfo::CScreenInfo(const CString& name,
|
CServer::CScreenInfo::CScreenInfo(
|
||||||
IServerProtocol* protocol) :
|
const CString& name,
|
||||||
m_thread(CThread::getCurrentThread()),
|
IServerProtocol* protocol) :
|
||||||
m_name(name),
|
m_thread(CThread::getCurrentThread()),
|
||||||
m_protocol(protocol),
|
m_name(name),
|
||||||
m_ready(false),
|
m_protocol(protocol),
|
||||||
m_width(0), m_height(0),
|
m_ready(false),
|
||||||
m_zoneSize(0)
|
m_width(0),
|
||||||
|
m_height(0),
|
||||||
|
m_zoneSize(0)
|
||||||
{
|
{
|
||||||
for (ClipboardID id = 0; id < kClipboardEnd; ++id)
|
for (ClipboardID id = 0; id < kClipboardEnd; ++id)
|
||||||
m_gotClipboard[id] = false;
|
m_gotClipboard[id] = false;
|
||||||
|
@ -1594,11 +1692,11 @@ CServer::CScreenInfo::~CScreenInfo()
|
||||||
//
|
//
|
||||||
|
|
||||||
CServer::CClipboardInfo::CClipboardInfo() :
|
CServer::CClipboardInfo::CClipboardInfo() :
|
||||||
m_clipboard(),
|
m_clipboard(),
|
||||||
m_clipboardData(),
|
m_clipboardData(),
|
||||||
m_clipboardOwner(),
|
m_clipboardOwner(),
|
||||||
m_clipboardSeqNum(0),
|
m_clipboardSeqNum(0),
|
||||||
m_clipboardReady(false)
|
m_clipboardReady(false)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
#ifndef CSERVER_H
|
#ifndef CSERVER_H
|
||||||
#define CSERVER_H
|
#define CSERVER_H
|
||||||
|
|
||||||
|
#include "CConfig.h"
|
||||||
|
#include "CClipboard.h"
|
||||||
#include "ClipboardTypes.h"
|
#include "ClipboardTypes.h"
|
||||||
#include "KeyTypes.h"
|
#include "KeyTypes.h"
|
||||||
#include "MouseTypes.h"
|
#include "MouseTypes.h"
|
||||||
#include "CConfig.h"
|
|
||||||
#include "CClipboard.h"
|
|
||||||
#include "CNetworkAddress.h"
|
#include "CNetworkAddress.h"
|
||||||
#include "CCondVar.h"
|
#include "CCondVar.h"
|
||||||
#include "CMutex.h"
|
#include "CMutex.h"
|
||||||
#include "CString.h"
|
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
#include "XBase.h"
|
|
||||||
#include "stdlist.h"
|
#include "stdlist.h"
|
||||||
#include "stdmap.h"
|
#include "stdmap.h"
|
||||||
|
|
||||||
|
@ -58,18 +56,18 @@ public:
|
||||||
|
|
||||||
// handle updates from primary
|
// handle updates from primary
|
||||||
void setInfo(SInt32 wScreen, SInt32 hScreen,
|
void setInfo(SInt32 wScreen, SInt32 hScreen,
|
||||||
SInt32 zoneSize,
|
SInt32 zoneSize,
|
||||||
SInt32 xMouse, SInt32 yMouse);
|
SInt32 xMouse, SInt32 yMouse);
|
||||||
|
|
||||||
// handle messages from clients
|
// handle messages from clients
|
||||||
void setInfo(const CString& clientName,
|
void setInfo(const CString& clientName,
|
||||||
SInt32 wScreen, SInt32 hScreen,
|
SInt32 wScreen, SInt32 hScreen,
|
||||||
SInt32 zoneSize,
|
SInt32 zoneSize,
|
||||||
SInt32 xMouse, SInt32 yMouse);
|
SInt32 xMouse, SInt32 yMouse);
|
||||||
void grabClipboard(ClipboardID,
|
void grabClipboard(ClipboardID,
|
||||||
UInt32 seqNum, const CString& clientName);
|
UInt32 seqNum, const CString& clientName);
|
||||||
void setClipboard(ClipboardID,
|
void setClipboard(ClipboardID,
|
||||||
UInt32 seqNum, const CString& data);
|
UInt32 seqNum, const CString& data);
|
||||||
|
|
||||||
// accessors
|
// accessors
|
||||||
|
|
||||||
|
@ -132,13 +130,13 @@ private:
|
||||||
|
|
||||||
// update screen info
|
// update screen info
|
||||||
void setInfoNoLock(const CString& screenName,
|
void setInfoNoLock(const CString& screenName,
|
||||||
SInt32 wScreen, SInt32 hScreen,
|
SInt32 wScreen, SInt32 hScreen,
|
||||||
SInt32 zoneSize,
|
SInt32 zoneSize,
|
||||||
SInt32 xMouse, SInt32 yMouse);
|
SInt32 xMouse, SInt32 yMouse);
|
||||||
|
|
||||||
// grab the clipboard
|
// grab the clipboard
|
||||||
void grabClipboardNoLock(ClipboardID,
|
void grabClipboardNoLock(ClipboardID,
|
||||||
UInt32 seqNum, const CString& clientName);
|
UInt32 seqNum, const CString& clientName);
|
||||||
|
|
||||||
// returns true iff mouse should be locked to the current screen
|
// returns true iff mouse should be locked to the current screen
|
||||||
bool isLockedToScreenNoLock() const;
|
bool isLockedToScreenNoLock() const;
|
||||||
|
@ -154,16 +152,16 @@ private:
|
||||||
// if the position is sufficiently far from the source then we
|
// if the position is sufficiently far from the source then we
|
||||||
// cross multiple screens.
|
// cross multiple screens.
|
||||||
CScreenInfo* getNeighbor(CScreenInfo*,
|
CScreenInfo* getNeighbor(CScreenInfo*,
|
||||||
CConfig::EDirection,
|
CConfig::EDirection,
|
||||||
SInt32& x, SInt32& y) const;
|
SInt32& x, SInt32& y) const;
|
||||||
|
|
||||||
// adjust coordinates to account for resolution differences. the
|
// adjust coordinates to account for resolution differences. the
|
||||||
// position is converted to a resolution independent form then
|
// position is converted to a resolution independent form then
|
||||||
// converted back to screen coordinates on the destination screen.
|
// converted back to screen coordinates on the destination screen.
|
||||||
void mapPosition(CScreenInfo* src,
|
void mapPosition(CScreenInfo* src,
|
||||||
CConfig::EDirection srcSide,
|
CConfig::EDirection srcSide,
|
||||||
CScreenInfo* dst,
|
CScreenInfo* dst,
|
||||||
SInt32& x, SInt32& y) const;
|
SInt32& x, SInt32& y) const;
|
||||||
|
|
||||||
// open/close the primary screen
|
// open/close the primary screen
|
||||||
void openPrimaryScreen();
|
void openPrimaryScreen();
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
#include "CServerProtocol.h"
|
#include "CServerProtocol.h"
|
||||||
#include "CServerProtocol1_0.h"
|
#include "CServerProtocol1_0.h"
|
||||||
#include "ProtocolTypes.h"
|
#include "ProtocolTypes.h"
|
||||||
|
#include "XSynergy.h"
|
||||||
#include "IOutputStream.h"
|
#include "IOutputStream.h"
|
||||||
#include <stdio.h>
|
#include <cstdio>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CServerProtocol
|
// CServerProtocol
|
||||||
//
|
//
|
||||||
|
|
||||||
CServerProtocol::CServerProtocol(CServer* server, const CString& client,
|
CServerProtocol::CServerProtocol(
|
||||||
IInputStream* input, IOutputStream* output) :
|
CServer* server,
|
||||||
m_server(server),
|
const CString& client,
|
||||||
m_client(client),
|
IInputStream* input,
|
||||||
m_input(input),
|
IOutputStream* output) :
|
||||||
m_output(output)
|
m_server(server),
|
||||||
|
m_client(client),
|
||||||
|
m_input(input),
|
||||||
|
m_output(output)
|
||||||
{
|
{
|
||||||
assert(m_server != NULL);
|
assert(m_server != NULL);
|
||||||
assert(m_input != NULL);
|
assert(m_input != NULL);
|
||||||
|
@ -26,29 +29,38 @@ CServerProtocol::~CServerProtocol()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
CServer* CServerProtocol::getServer() const
|
CServer*
|
||||||
|
CServerProtocol::getServer() const
|
||||||
{
|
{
|
||||||
return m_server;
|
return m_server;
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CServerProtocol::getClient() const
|
CString
|
||||||
|
CServerProtocol::getClient() const
|
||||||
{
|
{
|
||||||
return m_client;
|
return m_client;
|
||||||
}
|
}
|
||||||
|
|
||||||
IInputStream* CServerProtocol::getInputStream() const
|
IInputStream*
|
||||||
|
CServerProtocol::getInputStream() const
|
||||||
{
|
{
|
||||||
return m_input;
|
return m_input;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputStream* CServerProtocol::getOutputStream() const
|
IOutputStream*
|
||||||
|
CServerProtocol::getOutputStream() const
|
||||||
{
|
{
|
||||||
return m_output;
|
return m_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
IServerProtocol* CServerProtocol::create(SInt32 major, SInt32 minor,
|
IServerProtocol*
|
||||||
CServer* server, const CString& client,
|
CServerProtocol::create(
|
||||||
IInputStream* input, IOutputStream* output)
|
SInt32 major,
|
||||||
|
SInt32 minor,
|
||||||
|
CServer* server,
|
||||||
|
const CString& client,
|
||||||
|
IInputStream* input,
|
||||||
|
IOutputStream* output)
|
||||||
{
|
{
|
||||||
// disallow invalid version numbers
|
// disallow invalid version numbers
|
||||||
if (major < 0 || minor < 0) {
|
if (major < 0 || minor < 0) {
|
||||||
|
@ -70,4 +82,3 @@ IServerProtocol* CServerProtocol::create(SInt32 major, SInt32 minor,
|
||||||
// given version.
|
// given version.
|
||||||
return new CServerProtocol1_0(server, client, input, output);
|
return new CServerProtocol1_0(server, client, input, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef CSERVERPROTOCOL_H
|
#ifndef CSERVERPROTOCOL_H
|
||||||
#define CSERVERPROTOCOL_H
|
#define CSERVERPROTOCOL_H
|
||||||
|
|
||||||
#include "CString.h"
|
|
||||||
#include "IServerProtocol.h"
|
#include "IServerProtocol.h"
|
||||||
|
|
||||||
class CServer;
|
class CServer;
|
||||||
|
@ -11,7 +10,7 @@ class IOutputStream;
|
||||||
class CServerProtocol : public IServerProtocol {
|
class CServerProtocol : public IServerProtocol {
|
||||||
public:
|
public:
|
||||||
CServerProtocol(CServer*, const CString& clientName,
|
CServerProtocol(CServer*, const CString& clientName,
|
||||||
IInputStream*, IOutputStream*);
|
IInputStream*, IOutputStream*);
|
||||||
~CServerProtocol();
|
~CServerProtocol();
|
||||||
|
|
||||||
// manipulators
|
// manipulators
|
||||||
|
@ -24,15 +23,15 @@ public:
|
||||||
virtual IOutputStream* getOutputStream() const;
|
virtual IOutputStream* getOutputStream() const;
|
||||||
|
|
||||||
static IServerProtocol* create(SInt32 major, SInt32 minor,
|
static IServerProtocol* create(SInt32 major, SInt32 minor,
|
||||||
CServer*, const CString& clientName,
|
CServer*, const CString& clientName,
|
||||||
IInputStream*, IOutputStream*);
|
IInputStream*, IOutputStream*);
|
||||||
|
|
||||||
// IServerProtocol overrides
|
// IServerProtocol overrides
|
||||||
virtual void run() = 0;
|
virtual void run() = 0;
|
||||||
virtual void queryInfo() = 0;
|
virtual void queryInfo() = 0;
|
||||||
virtual void sendClose() = 0;
|
virtual void sendClose() = 0;
|
||||||
virtual void sendEnter(SInt32 xAbs, SInt32 yAbs,
|
virtual void sendEnter(SInt32 xAbs, SInt32 yAbs,
|
||||||
UInt32 seqNum, KeyModifierMask mask) = 0;
|
UInt32 seqNum, KeyModifierMask mask) = 0;
|
||||||
virtual void sendLeave() = 0;
|
virtual void sendLeave() = 0;
|
||||||
virtual void sendClipboard(ClipboardID, const CString&) = 0;
|
virtual void sendClipboard(ClipboardID, const CString&) = 0;
|
||||||
virtual void sendGrabClipboard(ClipboardID) = 0;
|
virtual void sendGrabClipboard(ClipboardID) = 0;
|
||||||
|
|
|
@ -3,19 +3,23 @@
|
||||||
#include "CClipboard.h"
|
#include "CClipboard.h"
|
||||||
#include "CProtocolUtil.h"
|
#include "CProtocolUtil.h"
|
||||||
#include "ProtocolTypes.h"
|
#include "ProtocolTypes.h"
|
||||||
|
#include "XSynergy.h"
|
||||||
#include "IInputStream.h"
|
#include "IInputStream.h"
|
||||||
#include "IOutputStream.h"
|
#include "IOutputStream.h"
|
||||||
#include "CLog.h"
|
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
#include <string.h>
|
#include "CLog.h"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
//
|
//
|
||||||
// CServerProtocol1_0
|
// CServerProtocol1_0
|
||||||
//
|
//
|
||||||
|
|
||||||
CServerProtocol1_0::CServerProtocol1_0(CServer* server, const CString& client,
|
CServerProtocol1_0::CServerProtocol1_0(
|
||||||
IInputStream* input, IOutputStream* output) :
|
CServer* server,
|
||||||
CServerProtocol(server, client, input, output)
|
const CString& client,
|
||||||
|
IInputStream* input,
|
||||||
|
IOutputStream* output) :
|
||||||
|
CServerProtocol(server, client, input, output)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -25,7 +29,8 @@ CServerProtocol1_0::~CServerProtocol1_0()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::run()
|
void
|
||||||
|
CServerProtocol1_0::run()
|
||||||
{
|
{
|
||||||
// handle messages until the client hangs up
|
// handle messages until the client hangs up
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -71,7 +76,8 @@ void CServerProtocol1_0::run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::queryInfo()
|
void
|
||||||
|
CServerProtocol1_0::queryInfo()
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "querying client \"%s\" info", getClient().c_str()));
|
log((CLOG_DEBUG1 "querying client \"%s\" info", getClient().c_str()));
|
||||||
|
|
||||||
|
@ -89,7 +95,8 @@ void CServerProtocol1_0::queryInfo()
|
||||||
recvInfo();
|
recvInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::sendClose()
|
void
|
||||||
|
CServerProtocol1_0::sendClose()
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "send close to \"%s\"", getClient().c_str()));
|
log((CLOG_DEBUG1 "send close to \"%s\"", getClient().c_str()));
|
||||||
CProtocolUtil::writef(getOutputStream(), kMsgCClose);
|
CProtocolUtil::writef(getOutputStream(), kMsgCClose);
|
||||||
|
@ -98,96 +105,120 @@ void CServerProtocol1_0::sendClose()
|
||||||
getOutputStream()->flush();
|
getOutputStream()->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::sendEnter(
|
void
|
||||||
SInt32 xAbs, SInt32 yAbs,
|
CServerProtocol1_0::sendEnter(
|
||||||
UInt32 seqNum, KeyModifierMask mask)
|
SInt32 xAbs,
|
||||||
|
SInt32 yAbs,
|
||||||
|
UInt32 seqNum,
|
||||||
|
KeyModifierMask mask)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "send enter to \"%s\", %d,%d %d %04x", getClient().c_str(), xAbs, yAbs, seqNum, mask));
|
log((CLOG_DEBUG1 "send enter to \"%s\", %d,%d %d %04x", getClient().c_str(), xAbs, yAbs, seqNum, mask));
|
||||||
CProtocolUtil::writef(getOutputStream(), kMsgCEnter,
|
CProtocolUtil::writef(getOutputStream(), kMsgCEnter,
|
||||||
xAbs, yAbs, seqNum, mask);
|
xAbs, yAbs, seqNum, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::sendLeave()
|
void
|
||||||
|
CServerProtocol1_0::sendLeave()
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "send leave to \"%s\"", getClient().c_str()));
|
log((CLOG_DEBUG1 "send leave to \"%s\"", getClient().c_str()));
|
||||||
CProtocolUtil::writef(getOutputStream(), kMsgCLeave);
|
CProtocolUtil::writef(getOutputStream(), kMsgCLeave);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::sendClipboard(
|
void
|
||||||
ClipboardID id, const CString& data)
|
CServerProtocol1_0::sendClipboard(
|
||||||
|
ClipboardID id,
|
||||||
|
const CString& data)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG "send clipboard %d to \"%s\" size=%d", id, getClient().c_str(), data.size()));
|
log((CLOG_DEBUG "send clipboard %d to \"%s\" size=%d", id, getClient().c_str(), data.size()));
|
||||||
CProtocolUtil::writef(getOutputStream(), kMsgDClipboard, id, 0, &data);
|
CProtocolUtil::writef(getOutputStream(), kMsgDClipboard, id, 0, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::sendGrabClipboard(ClipboardID id)
|
void
|
||||||
|
CServerProtocol1_0::sendGrabClipboard(
|
||||||
|
ClipboardID id)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG "send grab clipboard %d to \"%s\"", id, getClient().c_str()));
|
log((CLOG_DEBUG "send grab clipboard %d to \"%s\"", id, getClient().c_str()));
|
||||||
CProtocolUtil::writef(getOutputStream(), kMsgCClipboard, id, 0);
|
CProtocolUtil::writef(getOutputStream(), kMsgCClipboard, id, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::sendScreenSaver(bool on)
|
void
|
||||||
|
CServerProtocol1_0::sendScreenSaver(
|
||||||
|
bool on)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "send screen saver to \"%s\" on=%d", getClient().c_str(), on ? 1 : 0));
|
log((CLOG_DEBUG1 "send screen saver to \"%s\" on=%d", getClient().c_str(), on ? 1 : 0));
|
||||||
CProtocolUtil::writef(getOutputStream(), kMsgCScreenSaver, on ? 1 : 0);
|
CProtocolUtil::writef(getOutputStream(), kMsgCScreenSaver, on ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::sendInfoAcknowledgment()
|
void
|
||||||
|
CServerProtocol1_0::sendInfoAcknowledgment()
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "send info ack to \"%s\"", getClient().c_str()));
|
log((CLOG_DEBUG1 "send info ack to \"%s\"", getClient().c_str()));
|
||||||
CProtocolUtil::writef(getOutputStream(), kMsgCInfoAck);
|
CProtocolUtil::writef(getOutputStream(), kMsgCInfoAck);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::sendKeyDown(
|
void
|
||||||
KeyID key, KeyModifierMask mask)
|
CServerProtocol1_0::sendKeyDown(
|
||||||
|
KeyID key,
|
||||||
|
KeyModifierMask mask)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "send key down to \"%s\" id=%d, mask=0x%04x", getClient().c_str(), key, mask));
|
log((CLOG_DEBUG1 "send key down to \"%s\" id=%d, mask=0x%04x", getClient().c_str(), key, mask));
|
||||||
CProtocolUtil::writef(getOutputStream(), kMsgDKeyDown, key, mask);
|
CProtocolUtil::writef(getOutputStream(), kMsgDKeyDown, key, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::sendKeyRepeat(
|
void
|
||||||
KeyID key, KeyModifierMask mask, SInt32 count)
|
CServerProtocol1_0::sendKeyRepeat(
|
||||||
|
KeyID key,
|
||||||
|
KeyModifierMask mask,
|
||||||
|
SInt32 count)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "send key repeat to \"%s\" id=%d, mask=0x%04x, count=%d", getClient().c_str(), key, mask, count));
|
log((CLOG_DEBUG1 "send key repeat to \"%s\" id=%d, mask=0x%04x, count=%d", getClient().c_str(), key, mask, count));
|
||||||
CProtocolUtil::writef(getOutputStream(), kMsgDKeyRepeat, key, mask, count);
|
CProtocolUtil::writef(getOutputStream(), kMsgDKeyRepeat, key, mask, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::sendKeyUp(
|
void
|
||||||
KeyID key, KeyModifierMask mask)
|
CServerProtocol1_0::sendKeyUp(
|
||||||
|
KeyID key,
|
||||||
|
KeyModifierMask mask)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "send key up to \"%s\" id=%d, mask=0x%04x", getClient().c_str(), key, mask));
|
log((CLOG_DEBUG1 "send key up to \"%s\" id=%d, mask=0x%04x", getClient().c_str(), key, mask));
|
||||||
CProtocolUtil::writef(getOutputStream(), kMsgDKeyUp, key, mask);
|
CProtocolUtil::writef(getOutputStream(), kMsgDKeyUp, key, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::sendMouseDown(
|
void
|
||||||
ButtonID button)
|
CServerProtocol1_0::sendMouseDown(
|
||||||
|
ButtonID button)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "send mouse down to \"%s\" id=%d", getClient().c_str(), button));
|
log((CLOG_DEBUG1 "send mouse down to \"%s\" id=%d", getClient().c_str(), button));
|
||||||
CProtocolUtil::writef(getOutputStream(), kMsgDMouseDown, button);
|
CProtocolUtil::writef(getOutputStream(), kMsgDMouseDown, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::sendMouseUp(
|
void
|
||||||
ButtonID button)
|
CServerProtocol1_0::sendMouseUp(
|
||||||
|
ButtonID button)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "send mouse up to \"%s\" id=%d", getClient().c_str(), button));
|
log((CLOG_DEBUG1 "send mouse up to \"%s\" id=%d", getClient().c_str(), button));
|
||||||
CProtocolUtil::writef(getOutputStream(), kMsgDMouseUp, button);
|
CProtocolUtil::writef(getOutputStream(), kMsgDMouseUp, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::sendMouseMove(
|
void
|
||||||
SInt32 xAbs, SInt32 yAbs)
|
CServerProtocol1_0::sendMouseMove(
|
||||||
|
SInt32 xAbs,
|
||||||
|
SInt32 yAbs)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG2 "send mouse move to \"%s\" %d,%d", getClient().c_str(), xAbs, yAbs));
|
log((CLOG_DEBUG2 "send mouse move to \"%s\" %d,%d", getClient().c_str(), xAbs, yAbs));
|
||||||
CProtocolUtil::writef(getOutputStream(), kMsgDMouseMove, xAbs, yAbs);
|
CProtocolUtil::writef(getOutputStream(), kMsgDMouseMove, xAbs, yAbs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::sendMouseWheel(
|
void
|
||||||
SInt32 delta)
|
CServerProtocol1_0::sendMouseWheel(
|
||||||
|
SInt32 delta)
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG2 "send mouse wheel to \"%s\" %+d", getClient().c_str(), delta));
|
log((CLOG_DEBUG2 "send mouse wheel to \"%s\" %+d", getClient().c_str(), delta));
|
||||||
CProtocolUtil::writef(getOutputStream(), kMsgDMouseWheel, delta);
|
CProtocolUtil::writef(getOutputStream(), kMsgDMouseWheel, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::recvInfo()
|
void
|
||||||
|
CServerProtocol1_0::recvInfo()
|
||||||
{
|
{
|
||||||
// parse the message
|
// parse the message
|
||||||
SInt16 x, y, w, h, zoneInfo;
|
SInt16 x, y, w, h, zoneInfo;
|
||||||
|
@ -207,7 +238,8 @@ void CServerProtocol1_0::recvInfo()
|
||||||
getServer()->setInfo(getClient(), w, h, zoneInfo, x, y);
|
getServer()->setInfo(getClient(), w, h, zoneInfo, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::recvClipboard()
|
void
|
||||||
|
CServerProtocol1_0::recvClipboard()
|
||||||
{
|
{
|
||||||
// parse message
|
// parse message
|
||||||
ClipboardID id;
|
ClipboardID id;
|
||||||
|
@ -225,7 +257,8 @@ void CServerProtocol1_0::recvClipboard()
|
||||||
getServer()->setClipboard(id, seqNum, data);
|
getServer()->setClipboard(id, seqNum, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerProtocol1_0::recvGrabClipboard()
|
void
|
||||||
|
CServerProtocol1_0::recvGrabClipboard()
|
||||||
{
|
{
|
||||||
// parse message
|
// parse message
|
||||||
ClipboardID id;
|
ClipboardID id;
|
||||||
|
|
|
@ -17,7 +17,7 @@ public:
|
||||||
virtual void queryInfo();
|
virtual void queryInfo();
|
||||||
virtual void sendClose();
|
virtual void sendClose();
|
||||||
virtual void sendEnter(SInt32 xAbs, SInt32 yAbs,
|
virtual void sendEnter(SInt32 xAbs, SInt32 yAbs,
|
||||||
UInt32 seqNum, KeyModifierMask mask);
|
UInt32 seqNum, KeyModifierMask mask);
|
||||||
virtual void sendLeave();
|
virtual void sendLeave();
|
||||||
virtual void sendClipboard(ClipboardID, const CString&);
|
virtual void sendClipboard(ClipboardID, const CString&);
|
||||||
virtual void sendGrabClipboard(ClipboardID);
|
virtual void sendGrabClipboard(ClipboardID);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "CSynergyHook.h"
|
#include "CSynergyHook.h"
|
||||||
#include "CConfig.h"
|
#include "CConfig.h"
|
||||||
#include <assert.h>
|
|
||||||
#include <zmouse.h>
|
#include <zmouse.h>
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -60,7 +59,9 @@ static DWORD g_cursorThread = 0;
|
||||||
// internal functions
|
// internal functions
|
||||||
//
|
//
|
||||||
|
|
||||||
static void hideCursor(DWORD thread)
|
static
|
||||||
|
void
|
||||||
|
hideCursor(DWORD thread)
|
||||||
{
|
{
|
||||||
// we should be running the context of the window who's cursor
|
// we should be running the context of the window who's cursor
|
||||||
// we want to hide so we shouldn't have to attach thread input.
|
// we want to hide so we shouldn't have to attach thread input.
|
||||||
|
@ -69,7 +70,9 @@ static void hideCursor(DWORD thread)
|
||||||
SetCursor(NULL);
|
SetCursor(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void restoreCursor()
|
static
|
||||||
|
void
|
||||||
|
restoreCursor()
|
||||||
{
|
{
|
||||||
// restore the show cursor in the window we hid it last
|
// restore the show cursor in the window we hid it last
|
||||||
if (g_cursor != NULL && g_cursorThread != 0) {
|
if (g_cursor != NULL && g_cursorThread != 0) {
|
||||||
|
@ -84,7 +87,12 @@ static void restoreCursor()
|
||||||
g_cursorThread = 0;
|
g_cursorThread = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static LRESULT CALLBACK keyboardHook(int code, WPARAM wParam, LPARAM lParam)
|
static
|
||||||
|
LRESULT CALLBACK
|
||||||
|
keyboardHook(
|
||||||
|
int code,
|
||||||
|
WPARAM wParam,
|
||||||
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
if (code >= 0) {
|
if (code >= 0) {
|
||||||
if (g_relay) {
|
if (g_relay) {
|
||||||
|
@ -111,7 +119,12 @@ static LRESULT CALLBACK keyboardHook(int code, WPARAM wParam, LPARAM lParam)
|
||||||
return CallNextHookEx(g_keyboard, code, wParam, lParam);
|
return CallNextHookEx(g_keyboard, code, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
static LRESULT CALLBACK mouseHook(int code, WPARAM wParam, LPARAM lParam)
|
static
|
||||||
|
LRESULT CALLBACK
|
||||||
|
mouseHook(
|
||||||
|
int code,
|
||||||
|
WPARAM wParam,
|
||||||
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
if (code >= 0) {
|
if (code >= 0) {
|
||||||
if (g_relay) {
|
if (g_relay) {
|
||||||
|
@ -213,7 +226,12 @@ static LRESULT CALLBACK mouseHook(int code, WPARAM wParam, LPARAM lParam)
|
||||||
return CallNextHookEx(g_mouse, code, wParam, lParam);
|
return CallNextHookEx(g_mouse, code, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
static LRESULT CALLBACK cbtHook(int code, WPARAM wParam, LPARAM lParam)
|
static
|
||||||
|
LRESULT CALLBACK
|
||||||
|
cbtHook(
|
||||||
|
int code,
|
||||||
|
WPARAM wParam,
|
||||||
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
if (code >= 0) {
|
if (code >= 0) {
|
||||||
if (g_relay) {
|
if (g_relay) {
|
||||||
|
@ -224,7 +242,12 @@ static LRESULT CALLBACK cbtHook(int code, WPARAM wParam, LPARAM lParam)
|
||||||
return CallNextHookEx(g_cbt, code, wParam, lParam);
|
return CallNextHookEx(g_cbt, code, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
static LRESULT CALLBACK getMessageHook(int code, WPARAM wParam, LPARAM lParam)
|
static
|
||||||
|
LRESULT CALLBACK
|
||||||
|
getMessageHook(
|
||||||
|
int code,
|
||||||
|
WPARAM wParam,
|
||||||
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
if (code >= 0) {
|
if (code >= 0) {
|
||||||
if (g_relay) {
|
if (g_relay) {
|
||||||
|
@ -252,7 +275,12 @@ static LRESULT CALLBACK getMessageHook(int code, WPARAM wParam, LPARAM lParam)
|
||||||
// side, key repeats are not compressed for us.
|
// side, key repeats are not compressed for us.
|
||||||
//
|
//
|
||||||
|
|
||||||
static LRESULT CALLBACK keyboardLLHook(int code, WPARAM wParam, LPARAM lParam)
|
static
|
||||||
|
LRESULT CALLBACK
|
||||||
|
keyboardLLHook(
|
||||||
|
int code,
|
||||||
|
WPARAM wParam,
|
||||||
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
if (code >= 0) {
|
if (code >= 0) {
|
||||||
if (g_relay) {
|
if (g_relay) {
|
||||||
|
@ -296,7 +324,10 @@ static LRESULT CALLBACK keyboardLLHook(int code, WPARAM wParam, LPARAM lParam)
|
||||||
return CallNextHookEx(g_keyboardLL, code, wParam, lParam);
|
return CallNextHookEx(g_keyboardLL, code, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
static DWORD WINAPI getKeyboardLLProc(void*)
|
static
|
||||||
|
DWORD WINAPI
|
||||||
|
getKeyboardLLProc(
|
||||||
|
void*)
|
||||||
{
|
{
|
||||||
// thread proc for low-level keyboard hook. this does nothing but
|
// thread proc for low-level keyboard hook. this does nothing but
|
||||||
// install the hook, process events, and uninstall the hook.
|
// install the hook, process events, and uninstall the hook.
|
||||||
|
@ -349,7 +380,10 @@ static DWORD WINAPI getKeyboardLLProc(void*)
|
||||||
|
|
||||||
#error foo
|
#error foo
|
||||||
|
|
||||||
static DWORD WINAPI getKeyboardLLProc(void*)
|
static
|
||||||
|
DWORD WINAPI
|
||||||
|
getKeyboardLLProc(
|
||||||
|
void*)
|
||||||
{
|
{
|
||||||
g_keyHookThreadID = 0;
|
g_keyHookThreadID = 0;
|
||||||
SetEvent(g_keyHookEvent);
|
SetEvent(g_keyHookEvent);
|
||||||
|
@ -358,7 +392,9 @@ static DWORD WINAPI getKeyboardLLProc(void*)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static EWheelSupport GetWheelSupport()
|
static
|
||||||
|
EWheelSupport
|
||||||
|
getWheelSupport()
|
||||||
{
|
{
|
||||||
// get operating system
|
// get operating system
|
||||||
OSVERSIONINFO info;
|
OSVERSIONINFO info;
|
||||||
|
@ -404,7 +440,11 @@ static EWheelSupport GetWheelSupport()
|
||||||
// external functions
|
// external functions
|
||||||
//
|
//
|
||||||
|
|
||||||
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID)
|
BOOL WINAPI
|
||||||
|
DllMain(
|
||||||
|
HINSTANCE instance,
|
||||||
|
DWORD reason,
|
||||||
|
LPVOID)
|
||||||
{
|
{
|
||||||
if (reason == DLL_PROCESS_ATTACH) {
|
if (reason == DLL_PROCESS_ATTACH) {
|
||||||
if (g_hinstance == NULL) {
|
if (g_hinstance == NULL) {
|
||||||
|
@ -425,7 +465,9 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID)
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
int install(DWORD threadID)
|
int
|
||||||
|
install(
|
||||||
|
DWORD threadID)
|
||||||
{
|
{
|
||||||
assert(g_threadID == 0);
|
assert(g_threadID == 0);
|
||||||
assert(g_hinstance != NULL);
|
assert(g_hinstance != NULL);
|
||||||
|
@ -448,7 +490,7 @@ int install(DWORD threadID)
|
||||||
g_cursorThread = 0;
|
g_cursorThread = 0;
|
||||||
|
|
||||||
// check for mouse wheel support
|
// check for mouse wheel support
|
||||||
g_wheelSupport = GetWheelSupport();
|
g_wheelSupport = getWheelSupport();
|
||||||
|
|
||||||
// install keyboard hook
|
// install keyboard hook
|
||||||
g_keyboard = SetWindowsHookEx(WH_KEYBOARD,
|
g_keyboard = SetWindowsHookEx(WH_KEYBOARD,
|
||||||
|
@ -528,7 +570,9 @@ int install(DWORD threadID)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uninstall(void)
|
int
|
||||||
|
uninstall(
|
||||||
|
void)
|
||||||
{
|
{
|
||||||
assert(g_keyboard != NULL);
|
assert(g_keyboard != NULL);
|
||||||
assert(g_mouse != NULL);
|
assert(g_mouse != NULL);
|
||||||
|
@ -562,8 +606,12 @@ int uninstall(void)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setZone(UInt32 sides,
|
void
|
||||||
SInt32 w, SInt32 h, SInt32 jumpZoneSize)
|
setZone(
|
||||||
|
UInt32 sides,
|
||||||
|
SInt32 w,
|
||||||
|
SInt32 h,
|
||||||
|
SInt32 jumpZoneSize)
|
||||||
{
|
{
|
||||||
g_zoneSize = jumpZoneSize;
|
g_zoneSize = jumpZoneSize;
|
||||||
g_zoneSides = sides;
|
g_zoneSides = sides;
|
||||||
|
@ -573,7 +621,9 @@ void setZone(UInt32 sides,
|
||||||
restoreCursor();
|
restoreCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRelay(void)
|
void
|
||||||
|
setRelay(
|
||||||
|
void)
|
||||||
{
|
{
|
||||||
g_relay = true;
|
g_relay = true;
|
||||||
g_zoneSize = 0;
|
g_zoneSize = 0;
|
||||||
|
|
|
@ -31,7 +31,7 @@ typedef void (*SetRelayFunc)(void);
|
||||||
CSYNERGYHOOK_API int install(DWORD);
|
CSYNERGYHOOK_API int install(DWORD);
|
||||||
CSYNERGYHOOK_API int uninstall(void);
|
CSYNERGYHOOK_API int uninstall(void);
|
||||||
CSYNERGYHOOK_API void setZone(UInt32 sides,
|
CSYNERGYHOOK_API void setZone(UInt32 sides,
|
||||||
SInt32 w, SInt32 h, SInt32 jumpZoneSize);
|
SInt32 w, SInt32 h, SInt32 jumpZoneSize);
|
||||||
CSYNERGYHOOK_API void setRelay(void);
|
CSYNERGYHOOK_API void setRelay(void);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
#include "CXWindowsPrimaryScreen.h"
|
#include "CXWindowsPrimaryScreen.h"
|
||||||
|
#include "CServer.h"
|
||||||
#include "CXWindowsClipboard.h"
|
#include "CXWindowsClipboard.h"
|
||||||
#include "CXWindowsUtil.h"
|
#include "CXWindowsUtil.h"
|
||||||
#include "CServer.h"
|
|
||||||
#include "CStopwatch.h"
|
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
#include "CLog.h"
|
#include "CLog.h"
|
||||||
#include <assert.h>
|
#include "CStopwatch.h"
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#define XK_MISCELLANY
|
#define XK_MISCELLANY
|
||||||
|
@ -16,9 +15,9 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
CXWindowsPrimaryScreen::CXWindowsPrimaryScreen() :
|
CXWindowsPrimaryScreen::CXWindowsPrimaryScreen() :
|
||||||
m_server(NULL),
|
m_server(NULL),
|
||||||
m_active(false),
|
m_active(false),
|
||||||
m_window(None)
|
m_window(None)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -28,7 +27,8 @@ CXWindowsPrimaryScreen::~CXWindowsPrimaryScreen()
|
||||||
assert(m_window == None);
|
assert(m_window == None);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::run()
|
void
|
||||||
|
CXWindowsPrimaryScreen::run()
|
||||||
{
|
{
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// wait for and get the next event
|
// wait for and get the next event
|
||||||
|
@ -39,152 +39,163 @@ void CXWindowsPrimaryScreen::run()
|
||||||
|
|
||||||
// handle event
|
// handle event
|
||||||
switch (xevent.type) {
|
switch (xevent.type) {
|
||||||
case CreateNotify: {
|
case CreateNotify:
|
||||||
// select events on new window
|
{
|
||||||
CDisplayLock display(this);
|
// select events on new window
|
||||||
selectEvents(display, xevent.xcreatewindow.window);
|
CDisplayLock display(this);
|
||||||
break;
|
selectEvents(display, xevent.xcreatewindow.window);
|
||||||
}
|
|
||||||
|
|
||||||
case MappingNotify: {
|
|
||||||
// keyboard mapping changed
|
|
||||||
CDisplayLock display(this);
|
|
||||||
XRefreshKeyboardMapping(&xevent.xmapping);
|
|
||||||
updateModifierMap(display);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case KeyPress: {
|
|
||||||
log((CLOG_DEBUG1 "event: KeyPress code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
|
|
||||||
const KeyModifierMask mask = mapModifier(xevent.xkey.state);
|
|
||||||
const KeyID key = mapKey(&xevent.xkey);
|
|
||||||
if (key != kKeyNone) {
|
|
||||||
m_server->onKeyDown(key, mask);
|
|
||||||
if (key == XK_Caps_Lock && m_capsLockHalfDuplex) {
|
|
||||||
m_server->onKeyUp(key, mask | KeyModifierCapsLock);
|
|
||||||
}
|
|
||||||
else if (key == XK_Num_Lock && m_numLockHalfDuplex) {
|
|
||||||
m_server->onKeyUp(key, mask | KeyModifierNumLock);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case KeyRelease: {
|
case MappingNotify:
|
||||||
const KeyModifierMask mask = mapModifier(xevent.xkey.state);
|
{
|
||||||
const KeyID key = mapKey(&xevent.xkey);
|
// keyboard mapping changed
|
||||||
if (key != kKeyNone) {
|
|
||||||
// check if this is a key repeat by getting the next
|
|
||||||
// KeyPress event that has the same key and time as
|
|
||||||
// this release event, if any. first prepare the
|
|
||||||
// filter info.
|
|
||||||
CKeyEventInfo filter;
|
|
||||||
filter.m_event = KeyPress;
|
|
||||||
filter.m_window = xevent.xkey.window;
|
|
||||||
filter.m_time = xevent.xkey.time;
|
|
||||||
filter.m_keycode = xevent.xkey.keycode;
|
|
||||||
|
|
||||||
// now check for event
|
|
||||||
XEvent xevent2;
|
|
||||||
CDisplayLock display(this);
|
CDisplayLock display(this);
|
||||||
if (XCheckIfEvent(display, &xevent2,
|
XRefreshKeyboardMapping(&xevent.xmapping);
|
||||||
&CXWindowsPrimaryScreen::findKeyEvent,
|
updateModifierMap(display);
|
||||||
(XPointer)&filter) != True) {
|
}
|
||||||
// no press event follows so it's a plain release
|
break;
|
||||||
log((CLOG_DEBUG1 "event: KeyRelease code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
|
|
||||||
|
case KeyPress:
|
||||||
|
{
|
||||||
|
log((CLOG_DEBUG1 "event: KeyPress code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
|
||||||
|
const KeyModifierMask mask = mapModifier(xevent.xkey.state);
|
||||||
|
const KeyID key = mapKey(&xevent.xkey);
|
||||||
|
if (key != kKeyNone) {
|
||||||
|
m_server->onKeyDown(key, mask);
|
||||||
if (key == XK_Caps_Lock && m_capsLockHalfDuplex) {
|
if (key == XK_Caps_Lock && m_capsLockHalfDuplex) {
|
||||||
m_server->onKeyDown(key, mask);
|
m_server->onKeyUp(key, mask | KeyModifierCapsLock);
|
||||||
}
|
}
|
||||||
else if (key == XK_Num_Lock && m_numLockHalfDuplex) {
|
else if (key == XK_Num_Lock && m_numLockHalfDuplex) {
|
||||||
m_server->onKeyDown(key, mask);
|
m_server->onKeyUp(key, mask | KeyModifierNumLock);
|
||||||
}
|
}
|
||||||
m_server->onKeyUp(key, mask);
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KeyRelease:
|
||||||
|
{
|
||||||
|
const KeyModifierMask mask = mapModifier(xevent.xkey.state);
|
||||||
|
const KeyID key = mapKey(&xevent.xkey);
|
||||||
|
if (key != kKeyNone) {
|
||||||
|
// check if this is a key repeat by getting the next
|
||||||
|
// KeyPress event that has the same key and time as
|
||||||
|
// this release event, if any. first prepare the
|
||||||
|
// filter info.
|
||||||
|
CKeyEventInfo filter;
|
||||||
|
filter.m_event = KeyPress;
|
||||||
|
filter.m_window = xevent.xkey.window;
|
||||||
|
filter.m_time = xevent.xkey.time;
|
||||||
|
filter.m_keycode = xevent.xkey.keycode;
|
||||||
|
|
||||||
|
// now check for event
|
||||||
|
XEvent xevent2;
|
||||||
|
CDisplayLock display(this);
|
||||||
|
if (XCheckIfEvent(display, &xevent2,
|
||||||
|
&CXWindowsPrimaryScreen::findKeyEvent,
|
||||||
|
(XPointer)&filter) != True) {
|
||||||
|
// no press event follows so it's a plain release
|
||||||
|
log((CLOG_DEBUG1 "event: KeyRelease code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
|
||||||
|
if (key == XK_Caps_Lock && m_capsLockHalfDuplex) {
|
||||||
|
m_server->onKeyDown(key, mask);
|
||||||
|
}
|
||||||
|
else if (key == XK_Num_Lock && m_numLockHalfDuplex) {
|
||||||
|
m_server->onKeyDown(key, mask);
|
||||||
|
}
|
||||||
|
m_server->onKeyUp(key, mask);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// found a press event following so it's a repeat.
|
||||||
|
// we could attempt to count the already queued
|
||||||
|
// repeats but we'll just send a repeat of 1.
|
||||||
|
// note that we discard the press event.
|
||||||
|
log((CLOG_DEBUG1 "event: repeat code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
|
||||||
|
m_server->onKeyRepeat(key, mask, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ButtonPress:
|
||||||
|
{
|
||||||
|
log((CLOG_DEBUG1 "event: ButtonPress button=%d", xevent.xbutton.button));
|
||||||
|
const ButtonID button = mapButton(xevent.xbutton.button);
|
||||||
|
if (button != kButtonNone) {
|
||||||
|
m_server->onMouseDown(button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ButtonRelease:
|
||||||
|
{
|
||||||
|
log((CLOG_DEBUG1 "event: ButtonRelease button=%d", xevent.xbutton.button));
|
||||||
|
const ButtonID button = mapButton(xevent.xbutton.button);
|
||||||
|
if (button != kButtonNone) {
|
||||||
|
m_server->onMouseUp(button);
|
||||||
|
}
|
||||||
|
else if (xevent.xbutton.button == 4) {
|
||||||
|
// wheel forward (away from user)
|
||||||
|
m_server->onMouseWheel(120);
|
||||||
|
}
|
||||||
|
else if (xevent.xbutton.button == 5) {
|
||||||
|
// wheel backward (toward user)
|
||||||
|
m_server->onMouseWheel(-120);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MotionNotify:
|
||||||
|
{
|
||||||
|
log((CLOG_DEBUG2 "event: MotionNotify %d,%d", xevent.xmotion.x_root, xevent.xmotion.y_root));
|
||||||
|
SInt32 x, y;
|
||||||
|
if (!m_active) {
|
||||||
|
x = xevent.xmotion.x_root;
|
||||||
|
y = xevent.xmotion.y_root;
|
||||||
|
m_server->onMouseMovePrimary(x, y);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// found a press event following so it's a repeat.
|
// FIXME -- slurp up all remaining motion events?
|
||||||
// we could attempt to count the already queued
|
// probably not since keystrokes may go to wrong place.
|
||||||
// repeats but we'll just send a repeat of 1.
|
|
||||||
// note that we discard the press event.
|
// get mouse deltas
|
||||||
log((CLOG_DEBUG1 "event: repeat code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
|
{
|
||||||
m_server->onKeyRepeat(key, mask, 1);
|
CDisplayLock display(this);
|
||||||
|
Window root, window;
|
||||||
|
int xRoot, yRoot, xWindow, yWindow;
|
||||||
|
unsigned int mask;
|
||||||
|
if (!XQueryPointer(display, m_window, &root, &window,
|
||||||
|
&xRoot, &yRoot, &xWindow, &yWindow, &mask)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// compute position of center of window
|
||||||
|
SInt32 w, h;
|
||||||
|
getScreenSize(&w, &h);
|
||||||
|
x = xRoot - (w >> 1);
|
||||||
|
y = yRoot - (h >> 1);
|
||||||
|
|
||||||
|
// warp mouse back to center
|
||||||
|
warpCursorNoLock(display, w >> 1, h >> 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_server->onMouseMoveSecondary(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ButtonPress: {
|
|
||||||
log((CLOG_DEBUG1 "event: ButtonPress button=%d", xevent.xbutton.button));
|
|
||||||
const ButtonID button = mapButton(xevent.xbutton.button);
|
|
||||||
if (button != kButtonNone) {
|
|
||||||
m_server->onMouseDown(button);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case ButtonRelease: {
|
|
||||||
log((CLOG_DEBUG1 "event: ButtonRelease button=%d", xevent.xbutton.button));
|
|
||||||
const ButtonID button = mapButton(xevent.xbutton.button);
|
|
||||||
if (button != kButtonNone) {
|
|
||||||
m_server->onMouseUp(button);
|
|
||||||
}
|
|
||||||
else if (xevent.xbutton.button == 4) {
|
|
||||||
// wheel forward (away from user)
|
|
||||||
m_server->onMouseWheel(120);
|
|
||||||
}
|
|
||||||
else if (xevent.xbutton.button == 5) {
|
|
||||||
// wheel backward (toward user)
|
|
||||||
m_server->onMouseWheel(-120);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case MotionNotify: {
|
|
||||||
log((CLOG_DEBUG2 "event: MotionNotify %d,%d", xevent.xmotion.x_root, xevent.xmotion.y_root));
|
|
||||||
SInt32 x, y;
|
|
||||||
if (!m_active) {
|
|
||||||
x = xevent.xmotion.x_root;
|
|
||||||
y = xevent.xmotion.y_root;
|
|
||||||
m_server->onMouseMovePrimary(x, y);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// FIXME -- slurp up all remaining motion events?
|
|
||||||
// probably not since key strokes may go to wrong place.
|
|
||||||
|
|
||||||
// get mouse deltas
|
|
||||||
{
|
|
||||||
CDisplayLock display(this);
|
|
||||||
Window root, window;
|
|
||||||
int xRoot, yRoot, xWindow, yWindow;
|
|
||||||
unsigned int mask;
|
|
||||||
if (!XQueryPointer(display, m_window, &root, &window,
|
|
||||||
&xRoot, &yRoot, &xWindow, &yWindow, &mask))
|
|
||||||
break;
|
|
||||||
|
|
||||||
// compute position of center of window
|
|
||||||
SInt32 w, h;
|
|
||||||
getScreenSize(&w, &h);
|
|
||||||
x = xRoot - (w >> 1);
|
|
||||||
y = yRoot - (h >> 1);
|
|
||||||
|
|
||||||
// warp mouse back to center
|
|
||||||
warpCursorNoLock(display, w >> 1, h >> 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_server->onMouseMoveSecondary(x, y);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::stop()
|
void
|
||||||
|
CXWindowsPrimaryScreen::stop()
|
||||||
{
|
{
|
||||||
CDisplayLock display(this);
|
CDisplayLock display(this);
|
||||||
doStop();
|
doStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::open(CServer* server)
|
void
|
||||||
|
CXWindowsPrimaryScreen::open(
|
||||||
|
CServer* server)
|
||||||
{
|
{
|
||||||
assert(m_server == NULL);
|
assert(m_server == NULL);
|
||||||
assert(server != NULL);
|
assert(server != NULL);
|
||||||
|
@ -228,7 +239,8 @@ void CXWindowsPrimaryScreen::open(CServer* server)
|
||||||
m_server->setInfo(w, h, getJumpZoneSize(), x, y);
|
m_server->setInfo(w, h, getJumpZoneSize(), x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::close()
|
void
|
||||||
|
CXWindowsPrimaryScreen::close()
|
||||||
{
|
{
|
||||||
assert(m_server != NULL);
|
assert(m_server != NULL);
|
||||||
|
|
||||||
|
@ -239,7 +251,10 @@ void CXWindowsPrimaryScreen::close()
|
||||||
m_server = NULL;
|
m_server = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::enter(SInt32 x, SInt32 y)
|
void
|
||||||
|
CXWindowsPrimaryScreen::enter(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
log((CLOG_INFO "entering primary at %d,%d", x, y));
|
log((CLOG_INFO "entering primary at %d,%d", x, y));
|
||||||
assert(m_active == true);
|
assert(m_active == true);
|
||||||
|
@ -268,7 +283,8 @@ void CXWindowsPrimaryScreen::enter(SInt32 x, SInt32 y)
|
||||||
m_active = false;
|
m_active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsPrimaryScreen::leave()
|
bool
|
||||||
|
CXWindowsPrimaryScreen::leave()
|
||||||
{
|
{
|
||||||
log((CLOG_INFO "leaving primary"));
|
log((CLOG_INFO "leaving primary"));
|
||||||
assert(m_active == false);
|
assert(m_active == false);
|
||||||
|
@ -333,19 +349,26 @@ bool CXWindowsPrimaryScreen::leave()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::onConfigure()
|
void
|
||||||
|
CXWindowsPrimaryScreen::onConfigure()
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::warpCursor(SInt32 x, SInt32 y)
|
void
|
||||||
|
CXWindowsPrimaryScreen::warpCursor(
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
CDisplayLock display(this);
|
CDisplayLock display(this);
|
||||||
warpCursorNoLock(display, x, y);
|
warpCursorNoLock(display, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::warpCursorNoLock(
|
void
|
||||||
Display* display, SInt32 x, SInt32 y)
|
CXWindowsPrimaryScreen::warpCursorNoLock(
|
||||||
|
Display* display,
|
||||||
|
SInt32 x,
|
||||||
|
SInt32 y)
|
||||||
{
|
{
|
||||||
assert(display != NULL);
|
assert(display != NULL);
|
||||||
assert(m_window != None);
|
assert(m_window != None);
|
||||||
|
@ -363,35 +386,45 @@ void CXWindowsPrimaryScreen::warpCursorNoLock(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::setClipboard(
|
void
|
||||||
ClipboardID id, const IClipboard* clipboard)
|
CXWindowsPrimaryScreen::setClipboard(
|
||||||
|
ClipboardID id,
|
||||||
|
const IClipboard* clipboard)
|
||||||
{
|
{
|
||||||
setDisplayClipboard(id, clipboard);
|
setDisplayClipboard(id, clipboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::grabClipboard(ClipboardID id)
|
void
|
||||||
|
CXWindowsPrimaryScreen::grabClipboard(
|
||||||
|
ClipboardID id)
|
||||||
{
|
{
|
||||||
setDisplayClipboard(id, NULL);
|
setDisplayClipboard(id, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::getSize(
|
void
|
||||||
SInt32* width, SInt32* height) const
|
CXWindowsPrimaryScreen::getSize(
|
||||||
|
SInt32* width,
|
||||||
|
SInt32* height) const
|
||||||
{
|
{
|
||||||
getScreenSize(width, height);
|
getScreenSize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
SInt32 CXWindowsPrimaryScreen::getJumpZoneSize() const
|
SInt32
|
||||||
|
CXWindowsPrimaryScreen::getJumpZoneSize() const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::getClipboard(
|
void
|
||||||
ClipboardID id, IClipboard* clipboard) const
|
CXWindowsPrimaryScreen::getClipboard(
|
||||||
|
ClipboardID id,
|
||||||
|
IClipboard* clipboard) const
|
||||||
{
|
{
|
||||||
getDisplayClipboard(id, clipboard);
|
getDisplayClipboard(id, clipboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyModifierMask CXWindowsPrimaryScreen::getToggleMask() const
|
KeyModifierMask
|
||||||
|
CXWindowsPrimaryScreen::getToggleMask() const
|
||||||
{
|
{
|
||||||
CDisplayLock display(this);
|
CDisplayLock display(this);
|
||||||
|
|
||||||
|
@ -417,7 +450,8 @@ KeyModifierMask CXWindowsPrimaryScreen::getToggleMask() const
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXWindowsPrimaryScreen::isLockedToScreen() const
|
bool
|
||||||
|
CXWindowsPrimaryScreen::isLockedToScreen() const
|
||||||
{
|
{
|
||||||
CDisplayLock display(this);
|
CDisplayLock display(this);
|
||||||
|
|
||||||
|
@ -449,7 +483,9 @@ bool CXWindowsPrimaryScreen::isLockedToScreen() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::onOpenDisplay(Display* display)
|
void
|
||||||
|
CXWindowsPrimaryScreen::onOpenDisplay(
|
||||||
|
Display* display)
|
||||||
{
|
{
|
||||||
assert(m_window == None);
|
assert(m_window == None);
|
||||||
|
|
||||||
|
@ -479,14 +515,17 @@ void CXWindowsPrimaryScreen::onOpenDisplay(Display* display)
|
||||||
selectEvents(display, getRoot());
|
selectEvents(display, getRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
CXWindowsClipboard* CXWindowsPrimaryScreen::createClipboard(
|
CXWindowsClipboard*
|
||||||
ClipboardID id)
|
CXWindowsPrimaryScreen::createClipboard(
|
||||||
|
ClipboardID id)
|
||||||
{
|
{
|
||||||
CDisplayLock display(this);
|
CDisplayLock display(this);
|
||||||
return new CXWindowsClipboard(display, m_window, id);
|
return new CXWindowsClipboard(display, m_window, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::onCloseDisplay(Display* display)
|
void
|
||||||
|
CXWindowsPrimaryScreen::onCloseDisplay(
|
||||||
|
Display* display)
|
||||||
{
|
{
|
||||||
assert(m_window != None);
|
assert(m_window != None);
|
||||||
|
|
||||||
|
@ -497,7 +536,8 @@ void CXWindowsPrimaryScreen::onCloseDisplay(Display* display)
|
||||||
m_window = None;
|
m_window = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::onUnexpectedClose()
|
void
|
||||||
|
CXWindowsPrimaryScreen::onUnexpectedClose()
|
||||||
{
|
{
|
||||||
// tell server to shutdown
|
// tell server to shutdown
|
||||||
if (m_server != NULL) {
|
if (m_server != NULL) {
|
||||||
|
@ -505,15 +545,18 @@ void CXWindowsPrimaryScreen::onUnexpectedClose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::onLostClipboard(
|
void
|
||||||
ClipboardID id)
|
CXWindowsPrimaryScreen::onLostClipboard(
|
||||||
|
ClipboardID id)
|
||||||
{
|
{
|
||||||
// tell server that the clipboard was grabbed locally
|
// tell server that the clipboard was grabbed locally
|
||||||
m_server->grabClipboard(id);
|
m_server->grabClipboard(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::selectEvents(
|
void
|
||||||
Display* display, Window w) const
|
CXWindowsPrimaryScreen::selectEvents(
|
||||||
|
Display* display,
|
||||||
|
Window w) const
|
||||||
{
|
{
|
||||||
// ignore errors while we adjust event masks
|
// ignore errors while we adjust event masks
|
||||||
CXWindowsUtil::CErrorLock lock;
|
CXWindowsUtil::CErrorLock lock;
|
||||||
|
@ -522,8 +565,10 @@ void CXWindowsPrimaryScreen::selectEvents(
|
||||||
doSelectEvents(display, w);
|
doSelectEvents(display, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::doSelectEvents(
|
void
|
||||||
Display* display, Window w) const
|
CXWindowsPrimaryScreen::doSelectEvents(
|
||||||
|
Display* display,
|
||||||
|
Window w) const
|
||||||
{
|
{
|
||||||
// we want to track the mouse everywhere on the display. to achieve
|
// we want to track the mouse everywhere on the display. to achieve
|
||||||
// that we select PointerMotionMask on every window. we also select
|
// that we select PointerMotionMask on every window. we also select
|
||||||
|
@ -531,8 +576,9 @@ void CXWindowsPrimaryScreen::doSelectEvents(
|
||||||
// select events on new windows too.
|
// select events on new windows too.
|
||||||
|
|
||||||
// we don't want to adjust our grab window
|
// we don't want to adjust our grab window
|
||||||
if (w == m_window)
|
if (w == m_window) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// select events of interest
|
// select events of interest
|
||||||
XSelectInput(display, w, PointerMotionMask | SubstructureNotifyMask);
|
XSelectInput(display, w, PointerMotionMask | SubstructureNotifyMask);
|
||||||
|
@ -541,14 +587,16 @@ void CXWindowsPrimaryScreen::doSelectEvents(
|
||||||
Window rw, pw, *cw;
|
Window rw, pw, *cw;
|
||||||
unsigned int nc;
|
unsigned int nc;
|
||||||
if (XQueryTree(display, w, &rw, &pw, &cw, &nc)) {
|
if (XQueryTree(display, w, &rw, &pw, &cw, &nc)) {
|
||||||
for (unsigned int i = 0; i < nc; ++i)
|
for (unsigned int i = 0; i < nc; ++i) {
|
||||||
doSelectEvents(display, cw[i]);
|
doSelectEvents(display, cw[i]);
|
||||||
|
}
|
||||||
XFree(cw);
|
XFree(cw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyModifierMask CXWindowsPrimaryScreen::mapModifier(
|
KeyModifierMask
|
||||||
unsigned int state) const
|
CXWindowsPrimaryScreen::mapModifier(
|
||||||
|
unsigned int state) const
|
||||||
{
|
{
|
||||||
// FIXME -- should be configurable
|
// FIXME -- should be configurable
|
||||||
KeyModifierMask mask = 0;
|
KeyModifierMask mask = 0;
|
||||||
|
@ -569,7 +617,9 @@ KeyModifierMask CXWindowsPrimaryScreen::mapModifier(
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyID CXWindowsPrimaryScreen::mapKey(XKeyEvent* event) const
|
KeyID
|
||||||
|
CXWindowsPrimaryScreen::mapKey(
|
||||||
|
XKeyEvent* event) const
|
||||||
{
|
{
|
||||||
KeySym keysym;
|
KeySym keysym;
|
||||||
char dummy[1];
|
char dummy[1];
|
||||||
|
@ -579,18 +629,22 @@ KeyID CXWindowsPrimaryScreen::mapKey(XKeyEvent* event) const
|
||||||
return static_cast<KeyID>(keysym);
|
return static_cast<KeyID>(keysym);
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonID CXWindowsPrimaryScreen::mapButton(
|
ButtonID
|
||||||
unsigned int button) const
|
CXWindowsPrimaryScreen::mapButton(
|
||||||
|
unsigned int button) const
|
||||||
{
|
{
|
||||||
// FIXME -- should use button mapping?
|
// FIXME -- should use button mapping?
|
||||||
if (button >= 1 && button <= 3)
|
if (button >= 1 && button <= 3) {
|
||||||
return static_cast<ButtonID>(button);
|
return static_cast<ButtonID>(button);
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
return kButtonNone;
|
return kButtonNone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsPrimaryScreen::updateModifierMap(
|
void
|
||||||
Display* display)
|
CXWindowsPrimaryScreen::updateModifierMap(
|
||||||
|
Display* display)
|
||||||
{
|
{
|
||||||
// get modifier map from server
|
// get modifier map from server
|
||||||
XModifierKeymap* keymap = XGetModifierMapping(display);
|
XModifierKeymap* keymap = XGetModifierMapping(display);
|
||||||
|
@ -624,8 +678,11 @@ void CXWindowsPrimaryScreen::updateModifierMap(
|
||||||
XFreeModifiermap(keymap);
|
XFreeModifiermap(keymap);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool CXWindowsPrimaryScreen::findKeyEvent(
|
Bool
|
||||||
Display*, XEvent* xevent, XPointer arg)
|
CXWindowsPrimaryScreen::findKeyEvent(
|
||||||
|
Display*,
|
||||||
|
XEvent* xevent,
|
||||||
|
XPointer arg)
|
||||||
{
|
{
|
||||||
CKeyEventInfo* filter = reinterpret_cast<CKeyEventInfo*>(arg);
|
CKeyEventInfo* filter = reinterpret_cast<CKeyEventInfo*>(arg);
|
||||||
return (xevent->type == filter->m_event &&
|
return (xevent->type == filter->m_event &&
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
#ifndef CXWINDOWSPRIMARYSCREEN_H
|
#ifndef CXWINDOWSPRIMARYSCREEN_H
|
||||||
#define CXWINDOWSPRIMARYSCREEN_H
|
#define CXWINDOWSPRIMARYSCREEN_H
|
||||||
|
|
||||||
#include "KeyTypes.h"
|
|
||||||
#include "MouseTypes.h"
|
|
||||||
#include "CXWindowsScreen.h"
|
#include "CXWindowsScreen.h"
|
||||||
#include "IPrimaryScreen.h"
|
#include "IPrimaryScreen.h"
|
||||||
|
#include "MouseTypes.h"
|
||||||
|
|
||||||
class CXWindowsPrimaryScreen : public CXWindowsScreen, public IPrimaryScreen {
|
class CXWindowsPrimaryScreen : public CXWindowsScreen, public IPrimaryScreen {
|
||||||
public:
|
public:
|
||||||
|
@ -41,7 +40,7 @@ private:
|
||||||
void selectEvents(Display*, Window) const;
|
void selectEvents(Display*, Window) const;
|
||||||
void doSelectEvents(Display*, Window) const;
|
void doSelectEvents(Display*, Window) const;
|
||||||
void warpCursorNoLock(Display*,
|
void warpCursorNoLock(Display*,
|
||||||
SInt32 xAbsolute, SInt32 yAbsolute);
|
SInt32 xAbsolute, SInt32 yAbsolute);
|
||||||
|
|
||||||
KeyModifierMask mapModifier(unsigned int state) const;
|
KeyModifierMask mapModifier(unsigned int state) const;
|
||||||
KeyID mapKey(XKeyEvent*) const;
|
KeyID mapKey(XKeyEvent*) const;
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
#include "CServer.h"
|
#include "CServer.h"
|
||||||
#include "CConfig.h"
|
#include "CConfig.h"
|
||||||
#include "CLog.h"
|
|
||||||
#include "CLock.h"
|
|
||||||
#include "CMutex.h"
|
|
||||||
#include "CNetwork.h"
|
|
||||||
#include "CPlatform.h"
|
#include "CPlatform.h"
|
||||||
#include "CThread.h"
|
|
||||||
#include "XThread.h"
|
|
||||||
#include "ProtocolTypes.h"
|
#include "ProtocolTypes.h"
|
||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
|
#include "CNetwork.h"
|
||||||
|
#include "XSocket.h"
|
||||||
|
#include "CLock.h"
|
||||||
|
#include "CMutex.h"
|
||||||
|
#include "CThread.h"
|
||||||
|
#include "XThread.h"
|
||||||
|
#include "CLog.h"
|
||||||
#include "stdfstream.h"
|
#include "stdfstream.h"
|
||||||
#include <assert.h>
|
#include <cstring>
|
||||||
|
|
||||||
// platform dependent name of a daemon
|
// platform dependent name of a daemon
|
||||||
#if defined(CONFIG_PLATFORM_WIN32)
|
#if defined(CONFIG_PLATFORM_WIN32)
|
||||||
|
@ -51,7 +52,10 @@ static CConfig s_config;
|
||||||
|
|
||||||
static CMutex* s_logMutex = NULL;
|
static CMutex* s_logMutex = NULL;
|
||||||
|
|
||||||
static void logLock(bool lock)
|
static
|
||||||
|
void
|
||||||
|
logLock(
|
||||||
|
bool lock)
|
||||||
{
|
{
|
||||||
assert(s_logMutex != NULL);
|
assert(s_logMutex != NULL);
|
||||||
|
|
||||||
|
@ -70,7 +74,10 @@ static void logLock(bool lock)
|
||||||
|
|
||||||
static CServer* s_server = NULL;
|
static CServer* s_server = NULL;
|
||||||
|
|
||||||
static int realMain(CMutex* mutex)
|
static
|
||||||
|
int
|
||||||
|
realMain(
|
||||||
|
CMutex* mutex)
|
||||||
{
|
{
|
||||||
// s_serverLock should have mutex locked on entry
|
// s_serverLock should have mutex locked on entry
|
||||||
|
|
||||||
|
@ -153,14 +160,18 @@ static int realMain(CMutex* mutex)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int restartMain()
|
static
|
||||||
|
int
|
||||||
|
restartMain()
|
||||||
{
|
{
|
||||||
return realMain(NULL);
|
return realMain(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// invoke realMain and wait for it. if s_restartable then keep
|
// invoke realMain and wait for it. if s_restartable then keep
|
||||||
// restarting realMain until it returns a terminate code.
|
// restarting realMain until it returns a terminate code.
|
||||||
static int restartableMain()
|
static
|
||||||
|
int
|
||||||
|
restartableMain()
|
||||||
{
|
{
|
||||||
if (s_restartable) {
|
if (s_restartable) {
|
||||||
CPlatform platform;
|
CPlatform platform;
|
||||||
|
@ -180,7 +191,9 @@ static int restartableMain()
|
||||||
|
|
||||||
static void (*bye)(int) = &exit;
|
static void (*bye)(int) = &exit;
|
||||||
|
|
||||||
static void version()
|
static
|
||||||
|
void
|
||||||
|
version()
|
||||||
{
|
{
|
||||||
log((CLOG_PRINT
|
log((CLOG_PRINT
|
||||||
"%s %d.%d.%d, protocol version %d.%d\n"
|
"%s %d.%d.%d, protocol version %d.%d\n"
|
||||||
|
@ -194,7 +207,9 @@ static void version()
|
||||||
kCopyright));
|
kCopyright));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void help()
|
static
|
||||||
|
void
|
||||||
|
help()
|
||||||
{
|
{
|
||||||
CPlatform platform;
|
CPlatform platform;
|
||||||
|
|
||||||
|
@ -256,11 +271,14 @@ static void help()
|
||||||
CONFIG_NAME).c_str()));
|
CONFIG_NAME).c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isArg(int argi,
|
static
|
||||||
int argc, const char** argv,
|
bool
|
||||||
const char* name1,
|
isArg(int argi,
|
||||||
const char* name2,
|
int argc,
|
||||||
int minRequiredParameters = 0)
|
const char** argv,
|
||||||
|
const char* name1,
|
||||||
|
const char* name2,
|
||||||
|
int minRequiredParameters = 0)
|
||||||
{
|
{
|
||||||
if ((name1 != NULL && strcmp(argv[argi], name1) == 0) ||
|
if ((name1 != NULL && strcmp(argv[argi], name1) == 0) ||
|
||||||
(name2 != NULL && strcmp(argv[argi], name2) == 0)) {
|
(name2 != NULL && strcmp(argv[argi], name2) == 0)) {
|
||||||
|
@ -277,7 +295,11 @@ static bool isArg(int argi,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse(int argc, const char** argv)
|
static
|
||||||
|
void
|
||||||
|
parse(
|
||||||
|
int argc,
|
||||||
|
const char** argv)
|
||||||
{
|
{
|
||||||
assert(pname != NULL);
|
assert(pname != NULL);
|
||||||
assert(argv != NULL);
|
assert(argv != NULL);
|
||||||
|
@ -442,7 +464,11 @@ static void parse(int argc, const char** argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool loadConfig(const char* pathname, bool require)
|
static
|
||||||
|
bool
|
||||||
|
loadConfig(
|
||||||
|
const char* pathname,
|
||||||
|
bool require)
|
||||||
{
|
{
|
||||||
assert(pathname != NULL);
|
assert(pathname != NULL);
|
||||||
|
|
||||||
|
@ -471,7 +497,9 @@ static bool loadConfig(const char* pathname, bool require)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadConfig()
|
static
|
||||||
|
void
|
||||||
|
loadConfig()
|
||||||
{
|
{
|
||||||
// load the config file, if specified
|
// load the config file, if specified
|
||||||
if (s_configFile != NULL) {
|
if (s_configFile != NULL) {
|
||||||
|
@ -512,7 +540,11 @@ static void loadConfig()
|
||||||
|
|
||||||
#include "CMSWindowsScreen.h"
|
#include "CMSWindowsScreen.h"
|
||||||
|
|
||||||
static bool logMessageBox(int priority, const char* msg)
|
static
|
||||||
|
bool
|
||||||
|
logMessageBox(
|
||||||
|
int priority,
|
||||||
|
const char* msg)
|
||||||
{
|
{
|
||||||
if (priority <= CLog::kFATAL) {
|
if (priority <= CLog::kFATAL) {
|
||||||
MessageBox(NULL, msg, pname, MB_OK | MB_ICONWARNING);
|
MessageBox(NULL, msg, pname, MB_OK | MB_ICONWARNING);
|
||||||
|
@ -523,18 +555,26 @@ static bool logMessageBox(int priority, const char* msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void byeThrow(int x)
|
static
|
||||||
|
void
|
||||||
|
byeThrow(int x)
|
||||||
{
|
{
|
||||||
throw CWin32Platform::CDaemonFailed(x);
|
throw CWin32Platform::CDaemonFailed(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void daemonStop(void)
|
static
|
||||||
|
void
|
||||||
|
daemonStop(void)
|
||||||
{
|
{
|
||||||
s_server->quit();
|
s_server->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int daemonStartup(IPlatform* iplatform,
|
static
|
||||||
int argc, const char** argv)
|
int
|
||||||
|
daemonStartup(
|
||||||
|
IPlatform* iplatform,
|
||||||
|
int argc,
|
||||||
|
const char** argv)
|
||||||
{
|
{
|
||||||
// get platform pointer
|
// get platform pointer
|
||||||
CWin32Platform* platform = static_cast<CWin32Platform*>(iplatform);
|
CWin32Platform* platform = static_cast<CWin32Platform*>(iplatform);
|
||||||
|
@ -558,19 +598,30 @@ static int daemonStartup(IPlatform* iplatform,
|
||||||
return platform->runDaemon(realMain, daemonStop);
|
return platform->runDaemon(realMain, daemonStop);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int daemonStartup95(IPlatform*, int, const char**)
|
static
|
||||||
|
int
|
||||||
|
daemonStartup95(
|
||||||
|
IPlatform*,
|
||||||
|
int,
|
||||||
|
const char**)
|
||||||
{
|
{
|
||||||
return realMain(NULL);
|
return realMain(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool logDiscard(int, const char*)
|
static
|
||||||
|
bool
|
||||||
|
logDiscard(
|
||||||
|
int,
|
||||||
|
const char*)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool s_die = false;
|
static bool s_die = false;
|
||||||
|
|
||||||
static void checkParse(int e)
|
static
|
||||||
|
void
|
||||||
|
checkParse(int e)
|
||||||
{
|
{
|
||||||
// anything over 1 means invalid args. 1 means missing args.
|
// anything over 1 means invalid args. 1 means missing args.
|
||||||
// 0 means graceful exit. we plan to exit for anything but
|
// 0 means graceful exit. we plan to exit for anything but
|
||||||
|
@ -580,7 +631,12 @@ static void checkParse(int e)
|
||||||
throw s_die;
|
throw s_die;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
int WINAPI
|
||||||
|
WinMain(
|
||||||
|
HINSTANCE instance,
|
||||||
|
HINSTANCE,
|
||||||
|
LPSTR,
|
||||||
|
int)
|
||||||
{
|
{
|
||||||
CPlatform platform;
|
CPlatform platform;
|
||||||
|
|
||||||
|
@ -703,12 +759,20 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
||||||
|
|
||||||
#elif defined(CONFIG_PLATFORM_UNIX)
|
#elif defined(CONFIG_PLATFORM_UNIX)
|
||||||
|
|
||||||
static int daemonStartup(IPlatform*, int, const char**)
|
static
|
||||||
|
int
|
||||||
|
daemonStartup(
|
||||||
|
IPlatform*,
|
||||||
|
int,
|
||||||
|
const char**)
|
||||||
{
|
{
|
||||||
return restartableMain();
|
return restartableMain();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int
|
||||||
|
main(
|
||||||
|
int argc,
|
||||||
|
char** argv)
|
||||||
{
|
{
|
||||||
CPlatform platform;
|
CPlatform platform;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#include "CClipboard.h"
|
#include "CClipboard.h"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CClipboard
|
// CClipboard
|
||||||
//
|
//
|
||||||
|
|
||||||
CClipboard::CClipboard() : m_open(false), m_owner(false)
|
CClipboard::CClipboard() :
|
||||||
|
m_open(false),
|
||||||
|
m_owner(false)
|
||||||
{
|
{
|
||||||
open(0);
|
open(0);
|
||||||
empty();
|
empty();
|
||||||
|
@ -17,7 +18,8 @@ CClipboard::~CClipboard()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClipboard::empty()
|
bool
|
||||||
|
CClipboard::empty()
|
||||||
{
|
{
|
||||||
assert(m_open);
|
assert(m_open);
|
||||||
|
|
||||||
|
@ -36,7 +38,10 @@ bool CClipboard::empty()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClipboard::add(EFormat format, const CString& data)
|
void
|
||||||
|
CClipboard::add(
|
||||||
|
EFormat format,
|
||||||
|
const CString& data)
|
||||||
{
|
{
|
||||||
assert(m_open);
|
assert(m_open);
|
||||||
assert(m_owner);
|
assert(m_owner);
|
||||||
|
@ -45,7 +50,9 @@ void CClipboard::add(EFormat format, const CString& data)
|
||||||
m_added[format] = true;
|
m_added[format] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClipboard::open(Time time) const
|
bool
|
||||||
|
CClipboard::open(
|
||||||
|
Time time) const
|
||||||
{
|
{
|
||||||
assert(!m_open);
|
assert(!m_open);
|
||||||
|
|
||||||
|
@ -55,31 +62,40 @@ bool CClipboard::open(Time time) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClipboard::close() const
|
void
|
||||||
|
CClipboard::close() const
|
||||||
{
|
{
|
||||||
assert(m_open);
|
assert(m_open);
|
||||||
|
|
||||||
m_open = false;
|
m_open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CClipboard::Time CClipboard::getTime() const
|
CClipboard::Time
|
||||||
|
CClipboard::getTime() const
|
||||||
{
|
{
|
||||||
return m_timeOwned;
|
return m_timeOwned;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClipboard::has(EFormat format) const
|
bool
|
||||||
|
CClipboard::has(
|
||||||
|
EFormat format) const
|
||||||
{
|
{
|
||||||
assert(m_open);
|
assert(m_open);
|
||||||
return m_added[format];
|
return m_added[format];
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CClipboard::get(EFormat format) const
|
CString
|
||||||
|
CClipboard::get(
|
||||||
|
EFormat format) const
|
||||||
{
|
{
|
||||||
assert(m_open);
|
assert(m_open);
|
||||||
return m_data[format];
|
return m_data[format];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClipboard::copy(IClipboard* dst, const IClipboard* src)
|
bool
|
||||||
|
CClipboard::copy(
|
||||||
|
IClipboard* dst,
|
||||||
|
const IClipboard* src)
|
||||||
{
|
{
|
||||||
assert(dst != NULL);
|
assert(dst != NULL);
|
||||||
assert(src != NULL);
|
assert(src != NULL);
|
||||||
|
@ -87,8 +103,11 @@ bool CClipboard::copy(IClipboard* dst, const IClipboard* src)
|
||||||
return copy(dst, src, src->getTime());
|
return copy(dst, src, src->getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClipboard::copy(IClipboard* dst,
|
bool
|
||||||
const IClipboard* src, Time time)
|
CClipboard::copy(
|
||||||
|
IClipboard* dst,
|
||||||
|
const IClipboard* src,
|
||||||
|
Time time)
|
||||||
{
|
{
|
||||||
assert(dst != NULL);
|
assert(dst != NULL);
|
||||||
assert(src != NULL);
|
assert(src != NULL);
|
||||||
|
@ -114,7 +133,10 @@ bool CClipboard::copy(IClipboard* dst,
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClipboard::unmarshall(const CString& data, Time time)
|
void
|
||||||
|
CClipboard::unmarshall(
|
||||||
|
const CString& data,
|
||||||
|
Time time)
|
||||||
{
|
{
|
||||||
const char* index = data.data();
|
const char* index = data.data();
|
||||||
|
|
||||||
|
@ -146,7 +168,8 @@ void CClipboard::unmarshall(const CString& data, Time time)
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
CString CClipboard::marshall() const
|
CString
|
||||||
|
CClipboard::marshall() const
|
||||||
{
|
{
|
||||||
CString data;
|
CString data;
|
||||||
|
|
||||||
|
@ -177,7 +200,9 @@ CString CClipboard::marshall() const
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CClipboard::readUInt32(const char* buf) const
|
UInt32
|
||||||
|
CClipboard::readUInt32(
|
||||||
|
const char* buf) const
|
||||||
{
|
{
|
||||||
const unsigned char* ubuf = reinterpret_cast<const unsigned char*>(buf);
|
const unsigned char* ubuf = reinterpret_cast<const unsigned char*>(buf);
|
||||||
return (static_cast<UInt32>(ubuf[0]) << 24) |
|
return (static_cast<UInt32>(ubuf[0]) << 24) |
|
||||||
|
@ -186,7 +211,10 @@ UInt32 CClipboard::readUInt32(const char* buf) const
|
||||||
static_cast<UInt32>(ubuf[3]);
|
static_cast<UInt32>(ubuf[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClipboard::writeUInt32(CString* buf, UInt32 v) const
|
void
|
||||||
|
CClipboard::writeUInt32(
|
||||||
|
CString* buf,
|
||||||
|
UInt32 v) const
|
||||||
{
|
{
|
||||||
*buf += static_cast<UInt8>((v >> 24) & 0xff);
|
*buf += static_cast<UInt8>((v >> 24) & 0xff);
|
||||||
*buf += static_cast<UInt8>((v >> 16) & 0xff);
|
*buf += static_cast<UInt8>((v >> 16) & 0xff);
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "IClipboard.h"
|
#include "IClipboard.h"
|
||||||
#include "CString.h"
|
|
||||||
|
|
||||||
class CClipboard : public IClipboard {
|
class CClipboard : public IClipboard {
|
||||||
public:
|
public:
|
||||||
|
@ -23,6 +22,14 @@ public:
|
||||||
// marshall clipboard data
|
// marshall clipboard data
|
||||||
CString marshall() const;
|
CString marshall() const;
|
||||||
|
|
||||||
|
// transfer all the data in one clipboard to another. the
|
||||||
|
// clipboards can be of any concrete clipboard type (and
|
||||||
|
// they don't have to be the same type). this also sets
|
||||||
|
// the timestamp to time, if provided, or the time in src.
|
||||||
|
// returns true iff the copy succeeded.
|
||||||
|
static bool copy(IClipboard* dst, const IClipboard* src);
|
||||||
|
static bool copy(IClipboard* dst, const IClipboard* src, Time);
|
||||||
|
|
||||||
// IClipboard overrides
|
// IClipboard overrides
|
||||||
virtual bool empty();
|
virtual bool empty();
|
||||||
virtual void add(EFormat, const CString& data);
|
virtual void add(EFormat, const CString& data);
|
||||||
|
@ -32,16 +39,6 @@ public:
|
||||||
virtual bool has(EFormat) const;
|
virtual bool has(EFormat) const;
|
||||||
virtual CString get(EFormat) const;
|
virtual CString get(EFormat) const;
|
||||||
|
|
||||||
// accessors
|
|
||||||
|
|
||||||
// transfer all the data in one clipboard to another. the
|
|
||||||
// clipboards can be of any concrete clipboard type (and
|
|
||||||
// they don't have to be the same type). this also sets
|
|
||||||
// the timestamp to time, if provided, or the time in src.
|
|
||||||
// returns true iff the copy succeeded.
|
|
||||||
static bool copy(IClipboard* dst, const IClipboard* src);
|
|
||||||
static bool copy(IClipboard* dst, const IClipboard* src, Time);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UInt32 readUInt32(const char*) const;
|
UInt32 readUInt32(const char*) const;
|
||||||
void writeUInt32(CString*, UInt32) const;
|
void writeUInt32(CString*, UInt32) const;
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
#include "CInputPacketStream.h"
|
#include "CInputPacketStream.h"
|
||||||
#include "CLock.h"
|
#include "CLock.h"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CInputPacketStream
|
// CInputPacketStream
|
||||||
//
|
//
|
||||||
|
|
||||||
CInputPacketStream::CInputPacketStream(IInputStream* stream, bool adopt) :
|
CInputPacketStream::CInputPacketStream(
|
||||||
CInputStreamFilter(stream, adopt),
|
IInputStream* stream,
|
||||||
m_mutex(),
|
bool adopt) :
|
||||||
m_size(0),
|
CInputStreamFilter(stream, adopt),
|
||||||
m_buffer(&m_mutex, NULL)
|
m_mutex(),
|
||||||
|
m_size(0),
|
||||||
|
m_buffer(&m_mutex, NULL)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -20,13 +21,16 @@ CInputPacketStream::~CInputPacketStream()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInputPacketStream::close()
|
void
|
||||||
|
CInputPacketStream::close()
|
||||||
{
|
{
|
||||||
getStream()->close();
|
getStream()->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CInputPacketStream::read(
|
UInt32
|
||||||
void* buffer, UInt32 n)
|
CInputPacketStream::read(
|
||||||
|
void* buffer,
|
||||||
|
UInt32 n)
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
|
|
||||||
|
@ -50,13 +54,15 @@ UInt32 CInputPacketStream::read(
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CInputPacketStream::getSize() const
|
UInt32
|
||||||
|
CInputPacketStream::getSize() const
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
CLock lock(&m_mutex);
|
||||||
return getSizeNoLock();
|
return getSizeNoLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CInputPacketStream::getSizeNoLock() const
|
UInt32
|
||||||
|
CInputPacketStream::getSizeNoLock() const
|
||||||
{
|
{
|
||||||
while (!hasFullMessage()) {
|
while (!hasFullMessage()) {
|
||||||
// read more data
|
// read more data
|
||||||
|
@ -76,7 +82,8 @@ UInt32 CInputPacketStream::getSizeNoLock() const
|
||||||
return m_size;
|
return m_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CInputPacketStream::hasFullMessage() const
|
bool
|
||||||
|
CInputPacketStream::hasFullMessage() const
|
||||||
{
|
{
|
||||||
// get payload length if we don't have it yet
|
// get payload length if we don't have it yet
|
||||||
if (m_size == 0) {
|
if (m_size == 0) {
|
||||||
|
@ -106,4 +113,3 @@ bool CInputPacketStream::hasFullMessage() const
|
||||||
// the buffer
|
// the buffer
|
||||||
return (m_buffer.getSizeNoLock() >= m_size);
|
return (m_buffer.getSizeNoLock() >= m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,10 @@
|
||||||
// COuputPacketStream
|
// COuputPacketStream
|
||||||
//
|
//
|
||||||
|
|
||||||
COutputPacketStream::COutputPacketStream(IOutputStream* stream, bool adopt) :
|
COutputPacketStream::COutputPacketStream(
|
||||||
COutputStreamFilter(stream, adopt)
|
IOutputStream* stream,
|
||||||
|
bool adopt) :
|
||||||
|
COutputStreamFilter(stream, adopt)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -15,13 +17,16 @@ COutputPacketStream::~COutputPacketStream()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void COutputPacketStream::close()
|
void
|
||||||
|
COutputPacketStream::close()
|
||||||
{
|
{
|
||||||
getStream()->close();
|
getStream()->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 COutputPacketStream::write(
|
UInt32
|
||||||
const void* buffer, UInt32 count)
|
COutputPacketStream::write(
|
||||||
|
const void* buffer,
|
||||||
|
UInt32 count)
|
||||||
{
|
{
|
||||||
// write the length of the payload
|
// write the length of the payload
|
||||||
UInt8 length[4];
|
UInt8 length[4];
|
||||||
|
@ -49,7 +54,8 @@ UInt32 COutputPacketStream::write(
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void COutputPacketStream::flush()
|
void
|
||||||
|
COutputPacketStream::flush()
|
||||||
{
|
{
|
||||||
getStream()->flush();
|
getStream()->flush();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,18 @@
|
||||||
#include "IInputStream.h"
|
#include "IInputStream.h"
|
||||||
#include "IOutputStream.h"
|
#include "IOutputStream.h"
|
||||||
#include "CLog.h"
|
#include "CLog.h"
|
||||||
#include <assert.h>
|
#include <cctype>
|
||||||
#include <ctype.h>
|
#include <cstring>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CProtocolUtil
|
// CProtocolUtil
|
||||||
//
|
//
|
||||||
|
|
||||||
void CProtocolUtil::writef(IOutputStream* stream,
|
void
|
||||||
const char* fmt, ...)
|
CProtocolUtil::writef(
|
||||||
|
IOutputStream* stream,
|
||||||
|
const char* fmt,
|
||||||
|
...)
|
||||||
{
|
{
|
||||||
assert(stream != NULL);
|
assert(stream != NULL);
|
||||||
assert(fmt != NULL);
|
assert(fmt != NULL);
|
||||||
|
@ -47,8 +49,11 @@ void CProtocolUtil::writef(IOutputStream* stream,
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CProtocolUtil::readf(IInputStream* stream,
|
void
|
||||||
const char* fmt, ...)
|
CProtocolUtil::readf(
|
||||||
|
IInputStream* stream,
|
||||||
|
const char* fmt,
|
||||||
|
...)
|
||||||
{
|
{
|
||||||
assert(stream != NULL);
|
assert(stream != NULL);
|
||||||
assert(fmt != NULL);
|
assert(fmt != NULL);
|
||||||
|
@ -179,8 +184,10 @@ void CProtocolUtil::readf(IInputStream* stream,
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CProtocolUtil::getLength(
|
UInt32
|
||||||
const char* fmt, va_list args)
|
CProtocolUtil::getLength(
|
||||||
|
const char* fmt,
|
||||||
|
va_list args)
|
||||||
{
|
{
|
||||||
UInt32 n = 0;
|
UInt32 n = 0;
|
||||||
while (*fmt) {
|
while (*fmt) {
|
||||||
|
@ -228,8 +235,11 @@ UInt32 CProtocolUtil::getLength(
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CProtocolUtil::writef(void* buffer,
|
void
|
||||||
const char* fmt, va_list args)
|
CProtocolUtil::writef(
|
||||||
|
void* buffer,
|
||||||
|
const char* fmt,
|
||||||
|
va_list args)
|
||||||
{
|
{
|
||||||
UInt8* dst = reinterpret_cast<UInt8*>(buffer);
|
UInt8* dst = reinterpret_cast<UInt8*>(buffer);
|
||||||
|
|
||||||
|
@ -315,7 +325,9 @@ void CProtocolUtil::writef(void* buffer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 CProtocolUtil::eatLength(const char** pfmt)
|
UInt32
|
||||||
|
CProtocolUtil::eatLength(
|
||||||
|
const char** pfmt)
|
||||||
{
|
{
|
||||||
const char* fmt = *pfmt;
|
const char* fmt = *pfmt;
|
||||||
UInt32 n = 0;
|
UInt32 n = 0;
|
||||||
|
@ -339,8 +351,11 @@ UInt32 CProtocolUtil::eatLength(const char** pfmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CProtocolUtil::read(IInputStream* stream,
|
void
|
||||||
void* vbuffer, UInt32 count)
|
CProtocolUtil::read(
|
||||||
|
IInputStream* stream,
|
||||||
|
void* vbuffer,
|
||||||
|
UInt32 count)
|
||||||
{
|
{
|
||||||
assert(stream != NULL);
|
assert(stream != NULL);
|
||||||
assert(vbuffer != NULL);
|
assert(vbuffer != NULL);
|
||||||
|
@ -367,7 +382,8 @@ void CProtocolUtil::read(IInputStream* stream,
|
||||||
// XIOReadMismatch
|
// XIOReadMismatch
|
||||||
//
|
//
|
||||||
|
|
||||||
CString XIOReadMismatch::getWhat() const throw()
|
CString
|
||||||
|
XIOReadMismatch::getWhat() const throw()
|
||||||
{
|
{
|
||||||
return "CProtocolUtil::readf() mismatch";
|
return "CProtocolUtil::readf() mismatch";
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "BasicTypes.h"
|
#include "BasicTypes.h"
|
||||||
#include "XIO.h"
|
#include "XIO.h"
|
||||||
#include <stdarg.h>
|
#include <cstdarg>
|
||||||
|
|
||||||
class IInputStream;
|
class IInputStream;
|
||||||
class IOutputStream;
|
class IOutputStream;
|
||||||
|
@ -23,7 +23,7 @@ public:
|
||||||
// %s -- converts CString* to stream of bytes
|
// %s -- converts CString* to stream of bytes
|
||||||
// %S -- converts integer N and const UInt8* to stream of N bytes
|
// %S -- converts integer N and const UInt8* to stream of N bytes
|
||||||
static void writef(IOutputStream*,
|
static void writef(IOutputStream*,
|
||||||
const char* fmt, ...);
|
const char* fmt, ...);
|
||||||
|
|
||||||
// read formatted binary data from a buffer. this performs the
|
// read formatted binary data from a buffer. this performs the
|
||||||
// reverse operation of writef().
|
// reverse operation of writef().
|
||||||
|
@ -35,7 +35,7 @@ public:
|
||||||
// %4i -- reads an NBO 4 byte integer; arg is SInt32* or UInt32*
|
// %4i -- reads an NBO 4 byte integer; arg is SInt32* or UInt32*
|
||||||
// %s -- reads bytes; argument must be a CString*, *not* a char*
|
// %s -- reads bytes; argument must be a CString*, *not* a char*
|
||||||
static void readf(IInputStream*,
|
static void readf(IInputStream*,
|
||||||
const char* fmt, ...);
|
const char* fmt, ...);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static UInt32 getLength(const char* fmt, va_list);
|
static UInt32 getLength(const char* fmt, va_list);
|
||||||
|
|
|
@ -16,12 +16,14 @@ CTCPSocketFactory::~CTCPSocketFactory()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
ISocket* CTCPSocketFactory::create() const
|
ISocket*
|
||||||
|
CTCPSocketFactory::create() const
|
||||||
{
|
{
|
||||||
return new CTCPSocket;
|
return new CTCPSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
IListenSocket* CTCPSocketFactory::createListen() const
|
IListenSocket*
|
||||||
|
CTCPSocketFactory::createListen() const
|
||||||
{
|
{
|
||||||
return new CTCPListenSocket;
|
return new CTCPListenSocket;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,9 @@
|
||||||
#define ICLIPBOARD_H
|
#define ICLIPBOARD_H
|
||||||
|
|
||||||
#include "IInterface.h"
|
#include "IInterface.h"
|
||||||
|
#include "CString.h"
|
||||||
#include "BasicTypes.h"
|
#include "BasicTypes.h"
|
||||||
|
|
||||||
class CString;
|
|
||||||
|
|
||||||
class IClipboard : public IInterface {
|
class IClipboard : public IInterface {
|
||||||
public:
|
public:
|
||||||
// timestamp type. timestamps are in milliseconds from some
|
// timestamp type. timestamps are in milliseconds from some
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define IPRIMARYSCREEN_H
|
#define IPRIMARYSCREEN_H
|
||||||
|
|
||||||
#include "IInterface.h"
|
#include "IInterface.h"
|
||||||
#include "BasicTypes.h"
|
|
||||||
#include "KeyTypes.h"
|
#include "KeyTypes.h"
|
||||||
#include "ClipboardTypes.h"
|
#include "ClipboardTypes.h"
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define ISECONDARYSCREEN_H
|
#define ISECONDARYSCREEN_H
|
||||||
|
|
||||||
#include "IInterface.h"
|
#include "IInterface.h"
|
||||||
#include "BasicTypes.h"
|
|
||||||
#include "ClipboardTypes.h"
|
#include "ClipboardTypes.h"
|
||||||
#include "KeyTypes.h"
|
#include "KeyTypes.h"
|
||||||
#include "MouseTypes.h"
|
#include "MouseTypes.h"
|
||||||
|
@ -35,7 +34,7 @@ public:
|
||||||
// the cursor to the given coordinates and unhide it. prepare to
|
// the cursor to the given coordinates and unhide it. prepare to
|
||||||
// simulate input events.
|
// simulate input events.
|
||||||
virtual void enter(SInt32 xAbsolute, SInt32 yAbsolute,
|
virtual void enter(SInt32 xAbsolute, SInt32 yAbsolute,
|
||||||
KeyModifierMask mask) = 0;
|
KeyModifierMask mask) = 0;
|
||||||
|
|
||||||
// called when the user navigates off the secondary screen. clean
|
// called when the user navigates off the secondary screen. clean
|
||||||
// up input event simulation and hide the cursor.
|
// up input event simulation and hide the cursor.
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue