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 int UInt32;
|
||||
typedef unsigned long long UInt64;
|
||||
|
||||
#endif
|
||||
|
||||
#endif // CONFIG_PLATFORM_WIN32
|
||||
|
|
|
@ -11,7 +11,8 @@ CFunctionJob::CFunctionJob(void (*func)(void*), void* arg) :
|
|||
// do nothing
|
||||
}
|
||||
|
||||
void CFunctionJob::run()
|
||||
void
|
||||
CFunctionJob::run()
|
||||
{
|
||||
if (m_func != NULL) {
|
||||
m_func(m_arg);
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#include "CLog.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#if defined(CONFIG_PLATFORM_WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define CLOG_H
|
||||
|
||||
#include "BasicTypes.h"
|
||||
#include <stdarg.h>
|
||||
#include <cstdarg>
|
||||
|
||||
class CLog {
|
||||
public:
|
||||
|
@ -24,7 +24,7 @@ public:
|
|||
// type of lock/unlock function
|
||||
typedef void (*Lock)(bool lock);
|
||||
|
||||
//
|
||||
// print a log message
|
||||
static void print(const char*, ...);
|
||||
static void printt(const char* file, int line, const char*, ...);
|
||||
|
||||
|
|
|
@ -1,28 +1,31 @@
|
|||
#include "CString.h"
|
||||
#include <ctype.h>
|
||||
#include <cctype>
|
||||
#include <algorithm>
|
||||
|
||||
//
|
||||
// CStringUtil::CaselessCmp
|
||||
//
|
||||
|
||||
bool CStringUtil::CaselessCmp::cmpEqual(
|
||||
bool
|
||||
CStringUtil::CaselessCmp::cmpEqual(
|
||||
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);
|
||||
}
|
||||
|
||||
bool CStringUtil::CaselessCmp::cmpLess(
|
||||
bool
|
||||
CStringUtil::CaselessCmp::cmpLess(
|
||||
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);
|
||||
}
|
||||
|
||||
bool CStringUtil::CaselessCmp::less(
|
||||
bool
|
||||
CStringUtil::CaselessCmp::less(
|
||||
const CString& a,
|
||||
const CString& b)
|
||||
{
|
||||
|
@ -32,14 +35,16 @@ bool CStringUtil::CaselessCmp::less(
|
|||
&CStringUtil::CaselessCmp::cmpLess);
|
||||
}
|
||||
|
||||
bool CStringUtil::CaselessCmp::equal(
|
||||
bool
|
||||
CStringUtil::CaselessCmp::equal(
|
||||
const CString& a,
|
||||
const CString& b)
|
||||
{
|
||||
return !(less(a, b) || less(b, a));
|
||||
}
|
||||
|
||||
bool CStringUtil::CaselessCmp::operator()(
|
||||
bool
|
||||
CStringUtil::CaselessCmp::operator()(
|
||||
const CString& a,
|
||||
const CString& b) const
|
||||
{
|
||||
|
|
|
@ -1,48 +1,15 @@
|
|||
#ifndef CSTRING_H
|
||||
#define CSTRING_H
|
||||
|
||||
#include "common.h"
|
||||
#include "stdpre.h"
|
||||
#include <string>
|
||||
#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
|
||||
// the internal representation type of CString.
|
||||
#define _CS(_x) _x
|
||||
|
||||
class CString : public std::string {
|
||||
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) { }
|
||||
};
|
||||
typedef std::string CString;
|
||||
|
||||
class CStringUtil {
|
||||
public:
|
||||
|
@ -58,9 +25,5 @@ public:
|
|||
};
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -29,7 +29,8 @@ TMethodJob<T>::TMethodJob(T* object, void (T::*method)(void*), void* arg) :
|
|||
|
||||
template <class T>
|
||||
inline
|
||||
void TMethodJob<T>::run()
|
||||
void
|
||||
TMethodJob<T>::run()
|
||||
{
|
||||
if (m_object != NULL) {
|
||||
(m_object->*m_method)(m_arg);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "XBase.h"
|
||||
#include <errno.h>
|
||||
#include <cerrno>
|
||||
|
||||
// win32 wants a const char* argument to std::exception c'tor
|
||||
#if defined(CONFIG_PLATFORM_WIN32)
|
||||
|
@ -15,12 +15,16 @@
|
|||
// XBase
|
||||
//
|
||||
|
||||
XBase::XBase() : exception(STDEXCEPTARG), m_what()
|
||||
XBase::XBase() :
|
||||
exception(STDEXCEPTARG),
|
||||
m_what()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
XBase::XBase(const CString& msg) : exception(STDEXCEPTARG), m_what(msg)
|
||||
XBase::XBase(const CString& msg) :
|
||||
exception(STDEXCEPTARG),
|
||||
m_what(msg)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
@ -30,7 +34,8 @@ XBase::~XBase()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
const char* XBase::what() const
|
||||
const char*
|
||||
XBase::what() const
|
||||
{
|
||||
if (m_what.empty()) {
|
||||
m_what = getWhat();
|
||||
|
@ -38,7 +43,9 @@ const char* XBase::what() const
|
|||
return m_what.c_str();
|
||||
}
|
||||
|
||||
CString XBase::format(const char* /*id*/,
|
||||
CString
|
||||
XBase::format(
|
||||
const char* /*id*/,
|
||||
const char* fmt, ...) const throw()
|
||||
{
|
||||
// FIXME -- use id to lookup formating string
|
||||
|
@ -51,22 +58,26 @@ CString XBase::format(const char* /*id*/,
|
|||
// MXErrno
|
||||
//
|
||||
|
||||
MXErrno::MXErrno() : m_errno(errno)
|
||||
MXErrno::MXErrno() :
|
||||
m_errno(errno)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
MXErrno::MXErrno(int err) : m_errno(err)
|
||||
MXErrno::MXErrno(int err) :
|
||||
m_errno(err)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
int MXErrno::getErrno() const
|
||||
int
|
||||
MXErrno::getErrno() const
|
||||
{
|
||||
return m_errno;
|
||||
}
|
||||
|
||||
const char* MXErrno::getErrstr() const
|
||||
const char*
|
||||
MXErrno::getErrstr() const
|
||||
{
|
||||
return strerror(m_errno);
|
||||
}
|
||||
|
|
|
@ -42,4 +42,6 @@
|
|||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
#if !defined(CONFIG_PLATFORM_LINUX)
|
||||
#include <istream>
|
||||
#else
|
||||
// some versions of libstdc++ don't have <istream>
|
||||
// FIXME -- only include iostream for versions that don't have istream
|
||||
#include <iostream>
|
||||
#endif
|
||||
#include "stdpost.h"
|
||||
|
||||
#if defined(CONFIG_PLATFORM_WIN32) && defined(_MSC_VER)
|
||||
// istream has no overloads for __int* types
|
||||
inline
|
||||
std::istream& operator>>(std::istream& s, SInt8& i)
|
||||
{ return s >> (signed char&)i; }
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#if !defined(CONFIG_PLATFORM_LINUX)
|
||||
#include <ostream>
|
||||
#else
|
||||
// some versions of libstdc++ don't have <ostream>
|
||||
// FIXME -- only include iostream for versions that don't have ostream
|
||||
#include <iostream>
|
||||
#endif
|
||||
#include "stdpost.h"
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
#include "CClient.h"
|
||||
#include "CClipboard.h"
|
||||
#include "CInputPacketStream.h"
|
||||
#include "COutputPacketStream.h"
|
||||
#include "CProtocolUtil.h"
|
||||
#include "CClipboard.h"
|
||||
#include "ISecondaryScreen.h"
|
||||
#include "ProtocolTypes.h"
|
||||
#include "CLock.h"
|
||||
#include "CLog.h"
|
||||
#include "CThread.h"
|
||||
#include "CTimerThread.h"
|
||||
#include "TMethodJob.h"
|
||||
#include "XScreen.h"
|
||||
#include "XSynergy.h"
|
||||
#include "XSocket.h"
|
||||
#include "CLock.h"
|
||||
#include "CThread.h"
|
||||
#include "CTimerThread.h"
|
||||
#include "XThread.h"
|
||||
#include <assert.h>
|
||||
#include "CLog.h"
|
||||
#include "TMethodJob.h"
|
||||
#include <memory>
|
||||
|
||||
// hack to work around operator=() bug in STL in g++ prior to v3
|
||||
|
@ -28,7 +28,8 @@
|
|||
// CClient
|
||||
//
|
||||
|
||||
CClient::CClient(const CString& clientName) :
|
||||
CClient::CClient(
|
||||
const CString& clientName) :
|
||||
m_name(clientName),
|
||||
m_input(NULL),
|
||||
m_output(NULL),
|
||||
|
@ -46,12 +47,16 @@ CClient::~CClient()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
void CClient::camp(bool on)
|
||||
void
|
||||
CClient::camp(
|
||||
bool on)
|
||||
{
|
||||
m_camp = on;
|
||||
}
|
||||
|
||||
bool CClient::run(const CNetworkAddress& serverAddress)
|
||||
bool
|
||||
CClient::run(
|
||||
const CNetworkAddress& serverAddress)
|
||||
{
|
||||
CThread* thread = NULL;
|
||||
try {
|
||||
|
@ -128,12 +133,15 @@ bool CClient::run(const CNetworkAddress& serverAddress)
|
|||
}
|
||||
}
|
||||
|
||||
void CClient::quit()
|
||||
void
|
||||
CClient::quit()
|
||||
{
|
||||
m_screen->stop();
|
||||
}
|
||||
|
||||
void CClient::onClipboardChanged(ClipboardID id)
|
||||
void
|
||||
CClient::onClipboardChanged(
|
||||
ClipboardID id)
|
||||
{
|
||||
log((CLOG_DEBUG "sending clipboard %d changed", id));
|
||||
CLock lock(&m_mutex);
|
||||
|
@ -169,7 +177,8 @@ void CClient::onClipboardChanged(ClipboardID id)
|
|||
}
|
||||
}
|
||||
|
||||
void CClient::onResolutionChanged()
|
||||
void
|
||||
CClient::onResolutionChanged()
|
||||
{
|
||||
log((CLOG_DEBUG "resolution changed"));
|
||||
|
||||
|
@ -183,7 +192,8 @@ void CClient::onResolutionChanged()
|
|||
}
|
||||
|
||||
#include "CTCPSocket.h" // FIXME
|
||||
void CClient::runSession(void*)
|
||||
void
|
||||
CClient::runSession(void*)
|
||||
{
|
||||
log((CLOG_DEBUG "starting client \"%s\"", m_name.c_str()));
|
||||
|
||||
|
@ -401,7 +411,8 @@ void CClient::runSession(void*)
|
|||
#elif defined(CONFIG_PLATFORM_UNIX)
|
||||
#include "CXWindowsSecondaryScreen.h"
|
||||
#endif
|
||||
void CClient::openSecondaryScreen()
|
||||
void
|
||||
CClient::openSecondaryScreen()
|
||||
{
|
||||
assert(m_screen == NULL);
|
||||
|
||||
|
@ -428,7 +439,8 @@ void CClient::openSecondaryScreen()
|
|||
m_screen->open(this);
|
||||
}
|
||||
|
||||
void CClient::closeSecondaryScreen()
|
||||
void
|
||||
CClient::closeSecondaryScreen()
|
||||
{
|
||||
assert(m_screen != NULL);
|
||||
|
||||
|
@ -447,7 +459,8 @@ void CClient::closeSecondaryScreen()
|
|||
m_screen = NULL;
|
||||
}
|
||||
|
||||
void CClient::onEnter()
|
||||
void
|
||||
CClient::onEnter()
|
||||
{
|
||||
SInt16 x, y;
|
||||
UInt16 mask;
|
||||
|
@ -460,7 +473,8 @@ void CClient::onEnter()
|
|||
m_screen->enter(x, y, static_cast<KeyModifierMask>(mask));
|
||||
}
|
||||
|
||||
void CClient::onLeave()
|
||||
void
|
||||
CClient::onLeave()
|
||||
{
|
||||
log((CLOG_DEBUG1 "recv leave"));
|
||||
|
||||
|
@ -504,7 +518,8 @@ void CClient::onLeave()
|
|||
}
|
||||
}
|
||||
|
||||
void CClient::onGrabClipboard()
|
||||
void
|
||||
CClient::onGrabClipboard()
|
||||
{
|
||||
ClipboardID id;
|
||||
UInt32 seqNum;
|
||||
|
@ -524,7 +539,8 @@ void CClient::onGrabClipboard()
|
|||
m_screen->grabClipboard(id);
|
||||
}
|
||||
|
||||
void CClient::onScreenSaver()
|
||||
void
|
||||
CClient::onScreenSaver()
|
||||
{
|
||||
SInt8 on;
|
||||
{
|
||||
|
@ -535,13 +551,15 @@ void CClient::onScreenSaver()
|
|||
// FIXME
|
||||
}
|
||||
|
||||
void CClient::onQueryInfo()
|
||||
void
|
||||
CClient::onQueryInfo()
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
onQueryInfoNoLock();
|
||||
}
|
||||
|
||||
void CClient::onQueryInfoNoLock()
|
||||
void
|
||||
CClient::onQueryInfoNoLock()
|
||||
{
|
||||
SInt32 x, y, w, h;
|
||||
m_screen->getMousePos(&x, &y);
|
||||
|
@ -552,14 +570,16 @@ void CClient::onQueryInfoNoLock()
|
|||
CProtocolUtil::writef(m_output, kMsgDInfo, w, h, zoneSize, x, y);
|
||||
}
|
||||
|
||||
void CClient::onInfoAcknowledgment()
|
||||
void
|
||||
CClient::onInfoAcknowledgment()
|
||||
{
|
||||
log((CLOG_DEBUG1 "recv info acknowledgment"));
|
||||
CLock lock(&m_mutex);
|
||||
m_ignoreMove = false;
|
||||
}
|
||||
|
||||
void CClient::onSetClipboard()
|
||||
void
|
||||
CClient::onSetClipboard()
|
||||
{
|
||||
ClipboardID id;
|
||||
CString data;
|
||||
|
@ -584,7 +604,8 @@ void CClient::onSetClipboard()
|
|||
m_screen->setClipboard(id, &clipboard);
|
||||
}
|
||||
|
||||
void CClient::onKeyDown()
|
||||
void
|
||||
CClient::onKeyDown()
|
||||
{
|
||||
UInt16 id, mask;
|
||||
{
|
||||
|
@ -596,7 +617,8 @@ void CClient::onKeyDown()
|
|||
static_cast<KeyModifierMask>(mask));
|
||||
}
|
||||
|
||||
void CClient::onKeyRepeat()
|
||||
void
|
||||
CClient::onKeyRepeat()
|
||||
{
|
||||
UInt16 id, mask, count;
|
||||
{
|
||||
|
@ -609,7 +631,8 @@ void CClient::onKeyRepeat()
|
|||
count);
|
||||
}
|
||||
|
||||
void CClient::onKeyUp()
|
||||
void
|
||||
CClient::onKeyUp()
|
||||
{
|
||||
UInt16 id, mask;
|
||||
{
|
||||
|
@ -621,7 +644,8 @@ void CClient::onKeyUp()
|
|||
static_cast<KeyModifierMask>(mask));
|
||||
}
|
||||
|
||||
void CClient::onMouseDown()
|
||||
void
|
||||
CClient::onMouseDown()
|
||||
{
|
||||
SInt8 id;
|
||||
{
|
||||
|
@ -632,7 +656,8 @@ void CClient::onMouseDown()
|
|||
m_screen->mouseDown(static_cast<ButtonID>(id));
|
||||
}
|
||||
|
||||
void CClient::onMouseUp()
|
||||
void
|
||||
CClient::onMouseUp()
|
||||
{
|
||||
SInt8 id;
|
||||
{
|
||||
|
@ -643,7 +668,8 @@ void CClient::onMouseUp()
|
|||
m_screen->mouseUp(static_cast<ButtonID>(id));
|
||||
}
|
||||
|
||||
void CClient::onMouseMove()
|
||||
void
|
||||
CClient::onMouseMove()
|
||||
{
|
||||
bool ignore;
|
||||
SInt16 x, y;
|
||||
|
@ -658,7 +684,8 @@ void CClient::onMouseMove()
|
|||
}
|
||||
}
|
||||
|
||||
void CClient::onMouseWheel()
|
||||
void
|
||||
CClient::onMouseWheel()
|
||||
{
|
||||
SInt16 delta;
|
||||
{
|
||||
|
@ -669,7 +696,8 @@ void CClient::onMouseWheel()
|
|||
m_screen->mouseWheel(delta);
|
||||
}
|
||||
|
||||
void CClient::onErrorIncompatible()
|
||||
void
|
||||
CClient::onErrorIncompatible()
|
||||
{
|
||||
SInt32 major, minor;
|
||||
CLock lock(&m_mutex);
|
||||
|
@ -677,17 +705,20 @@ void CClient::onErrorIncompatible()
|
|||
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()));
|
||||
}
|
||||
|
||||
void CClient::onErrorUnknown()
|
||||
void
|
||||
CClient::onErrorUnknown()
|
||||
{
|
||||
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"));
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#ifndef CCLIENT_H
|
||||
#define CCLIENT_H
|
||||
|
||||
#include "CMutex.h"
|
||||
#include "CString.h"
|
||||
#include "BasicTypes.h"
|
||||
#include "ClipboardTypes.h"
|
||||
#include "IClipboard.h"
|
||||
#include "CMutex.h"
|
||||
#include "CString.h"
|
||||
|
||||
class CNetworkAddress;
|
||||
class IInputStream;
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
#include "CMSWindowsSecondaryScreen.h"
|
||||
#include "CMSWindowsClipboard.h"
|
||||
#include "CClient.h"
|
||||
#include "CPlatform.h"
|
||||
#include "CClipboard.h"
|
||||
#include "CLock.h"
|
||||
#include "CLog.h"
|
||||
#include "CThread.h"
|
||||
#include "CMSWindowsClipboard.h"
|
||||
#include "CPlatform.h"
|
||||
#include "XScreen.h"
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include "CLock.h"
|
||||
#include "CThread.h"
|
||||
#include "CLog.h"
|
||||
#include <cctype>
|
||||
|
||||
//
|
||||
// CMSWindowsSecondaryScreen
|
||||
|
@ -35,7 +34,8 @@ CMSWindowsSecondaryScreen::~CMSWindowsSecondaryScreen()
|
|||
assert(m_window == NULL);
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::run()
|
||||
void
|
||||
CMSWindowsSecondaryScreen::run()
|
||||
{
|
||||
// must call run() from same thread as open()
|
||||
assert(m_threadID == GetCurrentThreadId());
|
||||
|
@ -61,12 +61,15 @@ void CMSWindowsSecondaryScreen::run()
|
|||
}
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::stop()
|
||||
void
|
||||
CMSWindowsSecondaryScreen::stop()
|
||||
{
|
||||
doStop();
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::open(CClient* client)
|
||||
void
|
||||
CMSWindowsSecondaryScreen::open(
|
||||
CClient* client)
|
||||
{
|
||||
assert(m_client == NULL);
|
||||
assert(client != NULL);
|
||||
|
@ -82,15 +85,17 @@ void CMSWindowsSecondaryScreen::open(CClient* client)
|
|||
updateModifiers();
|
||||
|
||||
// assume primary has all clipboards
|
||||
for (ClipboardID id = 0; id < kClipboardEnd; ++id)
|
||||
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
||||
grabClipboard(id);
|
||||
}
|
||||
|
||||
// hide the cursor
|
||||
m_active = true;
|
||||
leave();
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::close()
|
||||
void
|
||||
CMSWindowsSecondaryScreen::close()
|
||||
{
|
||||
assert(m_client != NULL);
|
||||
|
||||
|
@ -101,8 +106,11 @@ void CMSWindowsSecondaryScreen::close()
|
|||
m_client = NULL;
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::enter(
|
||||
SInt32 x, SInt32 y, KeyModifierMask mask)
|
||||
void
|
||||
CMSWindowsSecondaryScreen::enter(
|
||||
SInt32 x,
|
||||
SInt32 y,
|
||||
KeyModifierMask mask)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
assert(m_window != NULL);
|
||||
|
@ -134,7 +142,8 @@ void CMSWindowsSecondaryScreen::enter(
|
|||
onEnter(x, y);
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::leave()
|
||||
void
|
||||
CMSWindowsSecondaryScreen::leave()
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
assert(m_window != NULL);
|
||||
|
@ -171,8 +180,10 @@ void CMSWindowsSecondaryScreen::leave()
|
|||
}
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::keyDown(
|
||||
KeyID key, KeyModifierMask mask)
|
||||
void
|
||||
CMSWindowsSecondaryScreen::keyDown(
|
||||
KeyID key,
|
||||
KeyModifierMask mask)
|
||||
{
|
||||
Keystrokes keys;
|
||||
UINT virtualKey;
|
||||
|
@ -184,8 +195,9 @@ void CMSWindowsSecondaryScreen::keyDown(
|
|||
// get the sequence of keys to simulate key press and the final
|
||||
// modifier state.
|
||||
m_mask = mapKey(keys, virtualKey, key, mask, kPress);
|
||||
if (keys.empty())
|
||||
if (keys.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// generate key events
|
||||
doKeystrokes(keys, 1);
|
||||
|
@ -210,8 +222,11 @@ void CMSWindowsSecondaryScreen::keyDown(
|
|||
}
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::keyRepeat(
|
||||
KeyID key, KeyModifierMask mask, SInt32 count)
|
||||
void
|
||||
CMSWindowsSecondaryScreen::keyRepeat(
|
||||
KeyID key,
|
||||
KeyModifierMask mask,
|
||||
SInt32 count)
|
||||
{
|
||||
Keystrokes keys;
|
||||
UINT virtualKey;
|
||||
|
@ -223,15 +238,18 @@ void CMSWindowsSecondaryScreen::keyRepeat(
|
|||
// get the sequence of keys to simulate key repeat and the final
|
||||
// modifier state.
|
||||
m_mask = mapKey(keys, virtualKey, key, mask, kRepeat);
|
||||
if (keys.empty())
|
||||
if (keys.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// generate key events
|
||||
doKeystrokes(keys, count);
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::keyUp(
|
||||
KeyID key, KeyModifierMask mask)
|
||||
void
|
||||
CMSWindowsSecondaryScreen::keyUp(
|
||||
KeyID key,
|
||||
KeyModifierMask mask)
|
||||
{
|
||||
Keystrokes keys;
|
||||
UINT virtualKey;
|
||||
|
@ -243,8 +261,9 @@ void CMSWindowsSecondaryScreen::keyUp(
|
|||
// get the sequence of keys to simulate key release and the final
|
||||
// modifier state.
|
||||
m_mask = mapKey(keys, virtualKey, key, mask, kRelease);
|
||||
if (keys.empty())
|
||||
if (keys.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// generate key events
|
||||
doKeystrokes(keys, 1);
|
||||
|
@ -290,7 +309,9 @@ void CMSWindowsSecondaryScreen::keyUp(
|
|||
}
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::mouseDown(ButtonID button)
|
||||
void
|
||||
CMSWindowsSecondaryScreen::mouseDown(
|
||||
ButtonID button)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
assert(m_window != NULL);
|
||||
|
@ -300,11 +321,14 @@ void CMSWindowsSecondaryScreen::mouseDown(ButtonID button)
|
|||
DWORD flags = mapButton(button, true);
|
||||
|
||||
// send event
|
||||
if (flags != 0)
|
||||
if (flags != 0) {
|
||||
mouse_event(flags, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::mouseUp(ButtonID button)
|
||||
void
|
||||
CMSWindowsSecondaryScreen::mouseUp(
|
||||
ButtonID button)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
assert(m_window != NULL);
|
||||
|
@ -314,12 +338,15 @@ void CMSWindowsSecondaryScreen::mouseUp(ButtonID button)
|
|||
DWORD flags = mapButton(button, false);
|
||||
|
||||
// send event
|
||||
if (flags != 0)
|
||||
if (flags != 0) {
|
||||
mouse_event(flags, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::mouseMove(
|
||||
SInt32 x, SInt32 y)
|
||||
void
|
||||
CMSWindowsSecondaryScreen::mouseMove(
|
||||
SInt32 x,
|
||||
SInt32 y)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
assert(m_window != NULL);
|
||||
|
@ -333,7 +360,9 @@ void CMSWindowsSecondaryScreen::mouseMove(
|
|||
0, 0);
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::mouseWheel(SInt32 delta)
|
||||
void
|
||||
CMSWindowsSecondaryScreen::mouseWheel(
|
||||
SInt32 delta)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
assert(m_window != NULL);
|
||||
|
@ -342,8 +371,10 @@ void CMSWindowsSecondaryScreen::mouseWheel(SInt32 delta)
|
|||
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, delta, 0);
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::setClipboard(
|
||||
ClipboardID /*id*/, const IClipboard* src)
|
||||
void
|
||||
CMSWindowsSecondaryScreen::setClipboard(
|
||||
ClipboardID /*id*/,
|
||||
const IClipboard* src)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
assert(m_window != NULL);
|
||||
|
@ -352,7 +383,8 @@ void CMSWindowsSecondaryScreen::setClipboard(
|
|||
CClipboard::copy(&dst, src);
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::grabClipboard(
|
||||
void
|
||||
CMSWindowsSecondaryScreen::grabClipboard(
|
||||
ClipboardID /*id*/)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
|
@ -364,8 +396,10 @@ void CMSWindowsSecondaryScreen::grabClipboard(
|
|||
}
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::getMousePos(
|
||||
SInt32* x, SInt32* y) const
|
||||
void
|
||||
CMSWindowsSecondaryScreen::getMousePos(
|
||||
SInt32* x,
|
||||
SInt32* y) const
|
||||
{
|
||||
assert(x != NULL);
|
||||
assert(y != NULL);
|
||||
|
@ -385,19 +419,24 @@ void CMSWindowsSecondaryScreen::getMousePos(
|
|||
}
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::getSize(
|
||||
SInt32* width, SInt32* height) const
|
||||
void
|
||||
CMSWindowsSecondaryScreen::getSize(
|
||||
SInt32* width,
|
||||
SInt32* height) const
|
||||
{
|
||||
getScreenSize(width, height);
|
||||
}
|
||||
|
||||
SInt32 CMSWindowsSecondaryScreen::getJumpZoneSize() const
|
||||
SInt32
|
||||
CMSWindowsSecondaryScreen::getJumpZoneSize() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::getClipboard(
|
||||
ClipboardID /*id*/, IClipboard* dst) const
|
||||
void
|
||||
CMSWindowsSecondaryScreen::getClipboard(
|
||||
ClipboardID /*id*/,
|
||||
IClipboard* dst) const
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
assert(m_window != NULL);
|
||||
|
@ -406,7 +445,8 @@ void CMSWindowsSecondaryScreen::getClipboard(
|
|||
CClipboard::copy(dst, &src);
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::onOpenDisplay()
|
||||
void
|
||||
CMSWindowsSecondaryScreen::onOpenDisplay()
|
||||
{
|
||||
assert(m_window == NULL);
|
||||
|
||||
|
@ -426,7 +466,8 @@ void CMSWindowsSecondaryScreen::onOpenDisplay()
|
|||
}
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::onCloseDisplay()
|
||||
void
|
||||
CMSWindowsSecondaryScreen::onCloseDisplay()
|
||||
{
|
||||
// disconnect from desktop
|
||||
if (m_is95Family) {
|
||||
|
@ -443,7 +484,9 @@ void CMSWindowsSecondaryScreen::onCloseDisplay()
|
|||
assert(m_desk == NULL);
|
||||
}
|
||||
|
||||
bool CMSWindowsSecondaryScreen::onPreTranslate(MSG* msg)
|
||||
bool
|
||||
CMSWindowsSecondaryScreen::onPreTranslate(
|
||||
MSG* msg)
|
||||
{
|
||||
// handle event
|
||||
switch (msg->message) {
|
||||
|
@ -466,9 +509,12 @@ bool CMSWindowsSecondaryScreen::onPreTranslate(MSG* msg)
|
|||
return false;
|
||||
}
|
||||
|
||||
LRESULT CMSWindowsSecondaryScreen::onEvent(
|
||||
HWND hwnd, UINT msg,
|
||||
WPARAM wParam, LPARAM lParam)
|
||||
LRESULT
|
||||
CMSWindowsSecondaryScreen::onEvent(
|
||||
HWND hwnd,
|
||||
UINT msg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
switch (msg) {
|
||||
case WM_QUERYENDSESSION:
|
||||
|
@ -516,10 +562,12 @@ LRESULT CMSWindowsSecondaryScreen::onEvent(
|
|||
return 0;
|
||||
|
||||
case WM_CHANGECBCHAIN:
|
||||
if (m_nextClipboardWindow == (HWND)wParam)
|
||||
if (m_nextClipboardWindow == (HWND)wParam) {
|
||||
m_nextClipboardWindow = (HWND)lParam;
|
||||
else
|
||||
}
|
||||
else {
|
||||
SendMessage(m_nextClipboardWindow, msg, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_DISPLAYCHANGE:
|
||||
|
@ -532,7 +580,10 @@ LRESULT CMSWindowsSecondaryScreen::onEvent(
|
|||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::onEnter(SInt32 x, SInt32 y)
|
||||
void
|
||||
CMSWindowsSecondaryScreen::onEnter(
|
||||
SInt32 x,
|
||||
SInt32 y)
|
||||
{
|
||||
// warp to requested location
|
||||
SInt32 w, h;
|
||||
|
@ -546,7 +597,8 @@ void CMSWindowsSecondaryScreen::onEnter(SInt32 x, SInt32 y)
|
|||
ShowWindow(m_window, SW_HIDE);
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::onLeave()
|
||||
void
|
||||
CMSWindowsSecondaryScreen::onLeave()
|
||||
{
|
||||
// move hider window under the mouse (rather than moving the mouse
|
||||
// somewhere else on the screen)
|
||||
|
@ -558,7 +610,8 @@ void CMSWindowsSecondaryScreen::onLeave()
|
|||
ShowWindow(m_window, SW_SHOWNORMAL);
|
||||
}
|
||||
|
||||
bool CMSWindowsSecondaryScreen::openDesktop()
|
||||
bool
|
||||
CMSWindowsSecondaryScreen::openDesktop()
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
|
||||
|
@ -584,7 +637,8 @@ bool CMSWindowsSecondaryScreen::openDesktop()
|
|||
return true;
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::closeDesktop()
|
||||
void
|
||||
CMSWindowsSecondaryScreen::closeDesktop()
|
||||
{
|
||||
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);
|
||||
|
||||
|
@ -680,7 +736,8 @@ bool CMSWindowsSecondaryScreen::switchDesktop(HDESK desk)
|
|||
return true;
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::syncDesktop() const
|
||||
void
|
||||
CMSWindowsSecondaryScreen::syncDesktop() const
|
||||
{
|
||||
// note -- mutex must be locked on entry
|
||||
|
||||
|
@ -697,7 +754,8 @@ void CMSWindowsSecondaryScreen::syncDesktop() const
|
|||
AttachThreadInput(threadID, m_threadID, TRUE);
|
||||
}
|
||||
|
||||
CString CMSWindowsSecondaryScreen::getCurrentDesktopName() const
|
||||
CString
|
||||
CMSWindowsSecondaryScreen::getCurrentDesktopName() const
|
||||
{
|
||||
return m_deskName;
|
||||
}
|
||||
|
@ -1189,8 +1247,10 @@ static const UINT* g_mapTable[] =
|
|||
/* 0xfc */ NULL, g_terminal, g_function, g_miscellany
|
||||
};
|
||||
|
||||
DWORD CMSWindowsSecondaryScreen::mapButton(
|
||||
ButtonID button, bool press) const
|
||||
DWORD
|
||||
CMSWindowsSecondaryScreen::mapButton(
|
||||
ButtonID button,
|
||||
bool press) const
|
||||
{
|
||||
// map button id to button flag
|
||||
switch (button) {
|
||||
|
@ -1208,10 +1268,12 @@ DWORD CMSWindowsSecondaryScreen::mapButton(
|
|||
}
|
||||
}
|
||||
|
||||
KeyModifierMask CMSWindowsSecondaryScreen::mapKey(
|
||||
KeyModifierMask
|
||||
CMSWindowsSecondaryScreen::mapKey(
|
||||
Keystrokes& keys,
|
||||
UINT& virtualKey,
|
||||
KeyID id, KeyModifierMask mask,
|
||||
KeyID id,
|
||||
KeyModifierMask mask,
|
||||
EKeyAction action) const
|
||||
{
|
||||
// lookup the key table
|
||||
|
@ -1264,12 +1326,15 @@ KeyModifierMask CMSWindowsSecondaryScreen::mapKey(
|
|||
outMask &= ~KeyModifierShift;
|
||||
|
||||
// convert system modifier mask to our mask
|
||||
if (HIBYTE(vk) & 1)
|
||||
if (HIBYTE(vk) & 1) {
|
||||
outMask |= KeyModifierShift;
|
||||
if (HIBYTE(vk) & 2)
|
||||
}
|
||||
if (HIBYTE(vk) & 2) {
|
||||
outMask |= KeyModifierControl;
|
||||
if (HIBYTE(vk) & 4)
|
||||
}
|
||||
if (HIBYTE(vk) & 4) {
|
||||
outMask |= KeyModifierAlt;
|
||||
}
|
||||
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
|
||||
|
@ -1457,8 +1522,9 @@ KeyModifierMask CMSWindowsSecondaryScreen::mapKey(
|
|||
|
||||
// add the key event
|
||||
keystroke.m_virtualKey = virtualKey;
|
||||
if (isExtended)
|
||||
if (isExtended) {
|
||||
keystroke.m_virtualKey |= 0x100;
|
||||
}
|
||||
switch (action) {
|
||||
case kPress:
|
||||
keystroke.m_press = true;
|
||||
|
@ -1523,12 +1589,15 @@ KeyModifierMask CMSWindowsSecondaryScreen::mapKey(
|
|||
return mask;
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::doKeystrokes(
|
||||
const Keystrokes& keys, SInt32 count)
|
||||
void
|
||||
CMSWindowsSecondaryScreen::doKeystrokes(
|
||||
const Keystrokes& keys,
|
||||
SInt32 count)
|
||||
{
|
||||
// do nothing if no keys or no repeats
|
||||
if (count < 1 || keys.empty())
|
||||
if (count < 1 || keys.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// generate key events
|
||||
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
|
||||
memset(m_keys, 0, sizeof(m_keys));
|
||||
|
@ -1579,29 +1649,40 @@ void CMSWindowsSecondaryScreen::updateKeys()
|
|||
m_keys[VK_SCROLL] = static_cast<BYTE>(GetKeyState(VK_SCROLL));
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::updateModifiers()
|
||||
void
|
||||
CMSWindowsSecondaryScreen::updateModifiers()
|
||||
{
|
||||
// update active modifier mask
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
if ((m_keys[VK_CAPITAL] & 0x01) != 0)
|
||||
}
|
||||
if ((m_keys[VK_CAPITAL] & 0x01) != 0) {
|
||||
m_mask |= KeyModifierCapsLock;
|
||||
if ((m_keys[VK_NUMLOCK] & 0x01) != 0)
|
||||
}
|
||||
if ((m_keys[VK_NUMLOCK] & 0x01) != 0) {
|
||||
m_mask |= KeyModifierNumLock;
|
||||
if ((m_keys[VK_SCROLL] & 0x01) != 0)
|
||||
}
|
||||
if ((m_keys[VK_SCROLL] & 0x01) != 0) {
|
||||
m_mask |= KeyModifierScrollLock;
|
||||
}
|
||||
log((CLOG_DEBUG2 "modifiers on update: 0x%04x", m_mask));
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::toggleKey(
|
||||
UINT virtualKey, KeyModifierMask mask)
|
||||
void
|
||||
CMSWindowsSecondaryScreen::toggleKey(
|
||||
UINT virtualKey,
|
||||
KeyModifierMask mask)
|
||||
{
|
||||
// send key events to simulate a press and release
|
||||
sendKeyEvent(virtualKey, true);
|
||||
|
@ -1612,13 +1693,15 @@ void CMSWindowsSecondaryScreen::toggleKey(
|
|||
m_keys[virtualKey & 0xff] ^= 0x01;
|
||||
}
|
||||
|
||||
UINT CMSWindowsSecondaryScreen::virtualKeyToScanCode(
|
||||
UINT
|
||||
CMSWindowsSecondaryScreen::virtualKeyToScanCode(
|
||||
UINT& virtualKey)
|
||||
{
|
||||
// try mapping given virtual key
|
||||
UINT code = MapVirtualKey(virtualKey & 0xff, 0);
|
||||
if (code != 0)
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
// no dice. if the virtual key distinguishes between left/right
|
||||
// then try the one that doesn't distinguish sides. windows (or
|
||||
|
@ -1663,12 +1746,14 @@ UINT CMSWindowsSecondaryScreen::virtualKeyToScanCode(
|
|||
}
|
||||
}
|
||||
|
||||
bool CMSWindowsSecondaryScreen::isExtendedKey(
|
||||
bool
|
||||
CMSWindowsSecondaryScreen::isExtendedKey(
|
||||
UINT virtualKey)
|
||||
{
|
||||
// see if we've already encoded the extended flag
|
||||
if ((virtualKey & 0x100) != 0)
|
||||
if ((virtualKey & 0x100) != 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// check known virtual keys
|
||||
switch (virtualKey & 0xff) {
|
||||
|
@ -1685,14 +1770,18 @@ bool CMSWindowsSecondaryScreen::isExtendedKey(
|
|||
}
|
||||
}
|
||||
|
||||
void CMSWindowsSecondaryScreen::sendKeyEvent(
|
||||
UINT virtualKey, bool press)
|
||||
void
|
||||
CMSWindowsSecondaryScreen::sendKeyEvent(
|
||||
UINT virtualKey,
|
||||
bool press)
|
||||
{
|
||||
DWORD flags = 0;
|
||||
if (isExtendedKey(virtualKey))
|
||||
if (isExtendedKey(virtualKey)) {
|
||||
flags |= KEYEVENTF_EXTENDEDKEY;
|
||||
if (!press)
|
||||
}
|
||||
if (!press) {
|
||||
flags |= KEYEVENTF_KEYUP;
|
||||
}
|
||||
const UINT code = virtualKeyToScanCode(virtualKey);
|
||||
keybd_event(static_cast<BYTE>(virtualKey & 0xff),
|
||||
static_cast<BYTE>(code), flags, 0);
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
#include "CString.h"
|
||||
#include "stdvector.h"
|
||||
|
||||
class CMSWindowsSecondaryScreen : public CMSWindowsScreen, public ISecondaryScreen {
|
||||
class CMSWindowsSecondaryScreen : public CMSWindowsScreen,
|
||||
public ISecondaryScreen {
|
||||
public:
|
||||
CMSWindowsSecondaryScreen();
|
||||
virtual ~CMSWindowsSecondaryScreen();
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#include "CXWindowsSecondaryScreen.h"
|
||||
#include "CClient.h"
|
||||
#include "CXWindowsClipboard.h"
|
||||
#include "CXWindowsUtil.h"
|
||||
#include "CClient.h"
|
||||
#include "CThread.h"
|
||||
#include "CLog.h"
|
||||
#include <assert.h>
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xutil.h>
|
||||
#define XK_MISCELLANY
|
||||
|
@ -28,7 +27,8 @@ CXWindowsSecondaryScreen::~CXWindowsSecondaryScreen()
|
|||
assert(m_window == None);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::run()
|
||||
void
|
||||
CXWindowsSecondaryScreen::run()
|
||||
{
|
||||
assert(m_window != None);
|
||||
|
||||
|
@ -41,7 +41,8 @@ void CXWindowsSecondaryScreen::run()
|
|||
|
||||
// handle event
|
||||
switch (xevent.type) {
|
||||
case MappingNotify: {
|
||||
case MappingNotify:
|
||||
{
|
||||
// keyboard mapping changed
|
||||
CDisplayLock display(this);
|
||||
XRefreshKeyboardMapping(&xevent.xmapping);
|
||||
|
@ -49,26 +50,30 @@ void CXWindowsSecondaryScreen::run()
|
|||
updateKeycodeMap(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);
|
||||
CDisplayLock display(this);
|
||||
XUnmapWindow(display, m_window);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::stop()
|
||||
void
|
||||
CXWindowsSecondaryScreen::stop()
|
||||
{
|
||||
doStop();
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::open(CClient* client)
|
||||
void
|
||||
CXWindowsSecondaryScreen::open(
|
||||
CClient* client)
|
||||
{
|
||||
assert(m_client == NULL);
|
||||
assert(client != NULL);
|
||||
|
@ -84,8 +89,9 @@ void CXWindowsSecondaryScreen::open(CClient* client)
|
|||
CDisplayLock display(this);
|
||||
int majorOpcode, firstEvent, firstError;
|
||||
if (!XQueryExtension(display, XTestExtensionName,
|
||||
&majorOpcode, &firstEvent, &firstError))
|
||||
&majorOpcode, &firstEvent, &firstError)) {
|
||||
throw int(6); // FIXME -- make exception for this
|
||||
}
|
||||
|
||||
// update key state
|
||||
updateKeys(display);
|
||||
|
@ -102,11 +108,13 @@ void CXWindowsSecondaryScreen::open(CClient* client)
|
|||
m_capsLockHalfDuplex = true;
|
||||
|
||||
// assume primary has all clipboards
|
||||
for (ClipboardID id = 0; id < kClipboardEnd; ++id)
|
||||
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
||||
grabClipboard(id);
|
||||
}
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::close()
|
||||
void
|
||||
CXWindowsSecondaryScreen::close()
|
||||
{
|
||||
assert(m_client != NULL);
|
||||
|
||||
|
@ -117,8 +125,11 @@ void CXWindowsSecondaryScreen::close()
|
|||
m_client = NULL;
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::enter(
|
||||
SInt32 x, SInt32 y, KeyModifierMask mask)
|
||||
void
|
||||
CXWindowsSecondaryScreen::enter(
|
||||
SInt32 x,
|
||||
SInt32 y,
|
||||
KeyModifierMask mask)
|
||||
{
|
||||
assert(m_window != None);
|
||||
|
||||
|
@ -149,14 +160,17 @@ void CXWindowsSecondaryScreen::enter(
|
|||
XSync(display, False);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::leave()
|
||||
void
|
||||
CXWindowsSecondaryScreen::leave()
|
||||
{
|
||||
CDisplayLock display(this);
|
||||
leaveNoLock(display);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::keyDown(
|
||||
KeyID key, KeyModifierMask mask)
|
||||
void
|
||||
CXWindowsSecondaryScreen::keyDown(
|
||||
KeyID key,
|
||||
KeyModifierMask mask)
|
||||
{
|
||||
Keystrokes keys;
|
||||
KeyCode keycode;
|
||||
|
@ -164,8 +178,9 @@ void CXWindowsSecondaryScreen::keyDown(
|
|||
// get the sequence of keys to simulate key press and the final
|
||||
// modifier state.
|
||||
m_mask = mapKey(keys, keycode, key, mask, kPress);
|
||||
if (keys.empty())
|
||||
if (keys.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// generate key events
|
||||
doKeystrokes(keys, 1);
|
||||
|
@ -174,8 +189,11 @@ void CXWindowsSecondaryScreen::keyDown(
|
|||
m_keys[keycode] = true;
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::keyRepeat(
|
||||
KeyID key, KeyModifierMask mask, SInt32 count)
|
||||
void
|
||||
CXWindowsSecondaryScreen::keyRepeat(
|
||||
KeyID key,
|
||||
KeyModifierMask mask,
|
||||
SInt32 count)
|
||||
{
|
||||
Keystrokes keys;
|
||||
KeyCode keycode;
|
||||
|
@ -183,15 +201,18 @@ void CXWindowsSecondaryScreen::keyRepeat(
|
|||
// get the sequence of keys to simulate key repeat and the final
|
||||
// modifier state.
|
||||
m_mask = mapKey(keys, keycode, key, mask, kRepeat);
|
||||
if (keys.empty())
|
||||
if (keys.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// generate key events
|
||||
doKeystrokes(keys, count);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::keyUp(
|
||||
KeyID key, KeyModifierMask mask)
|
||||
void
|
||||
CXWindowsSecondaryScreen::keyUp(
|
||||
KeyID key,
|
||||
KeyModifierMask mask)
|
||||
{
|
||||
Keystrokes keys;
|
||||
KeyCode keycode;
|
||||
|
@ -199,8 +220,9 @@ void CXWindowsSecondaryScreen::keyUp(
|
|||
// get the sequence of keys to simulate key release and the final
|
||||
// modifier state.
|
||||
m_mask = mapKey(keys, keycode, key, mask, kRelease);
|
||||
if (keys.empty())
|
||||
if (keys.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// generate key events
|
||||
doKeystrokes(keys, 1);
|
||||
|
@ -209,28 +231,37 @@ void CXWindowsSecondaryScreen::keyUp(
|
|||
m_keys[keycode] = false;
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::mouseDown(ButtonID button)
|
||||
void
|
||||
CXWindowsSecondaryScreen::mouseDown(
|
||||
ButtonID button)
|
||||
{
|
||||
CDisplayLock display(this);
|
||||
XTestFakeButtonEvent(display, mapButton(button), True, CurrentTime);
|
||||
XSync(display, False);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::mouseUp(ButtonID button)
|
||||
void
|
||||
CXWindowsSecondaryScreen::mouseUp(
|
||||
ButtonID button)
|
||||
{
|
||||
CDisplayLock display(this);
|
||||
XTestFakeButtonEvent(display, mapButton(button), False, CurrentTime);
|
||||
XSync(display, False);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::mouseMove(SInt32 x, SInt32 y)
|
||||
void
|
||||
CXWindowsSecondaryScreen::mouseMove(
|
||||
SInt32 x,
|
||||
SInt32 y)
|
||||
{
|
||||
CDisplayLock display(this);
|
||||
XTestFakeMotionEvent(display, getScreen(), x, y, CurrentTime);
|
||||
XSync(display, False);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::mouseWheel(SInt32 delta)
|
||||
void
|
||||
CXWindowsSecondaryScreen::mouseWheel(
|
||||
SInt32 delta)
|
||||
{
|
||||
// choose button depending on rotation direction
|
||||
const unsigned int button = (delta >= 0) ? 4 : 5;
|
||||
|
@ -249,19 +280,25 @@ void CXWindowsSecondaryScreen::mouseWheel(SInt32 delta)
|
|||
XSync(display, False);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::setClipboard(
|
||||
ClipboardID id, const IClipboard* clipboard)
|
||||
void
|
||||
CXWindowsSecondaryScreen::setClipboard(
|
||||
ClipboardID id,
|
||||
const IClipboard* clipboard)
|
||||
{
|
||||
setDisplayClipboard(id, clipboard);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::grabClipboard(ClipboardID id)
|
||||
void
|
||||
CXWindowsSecondaryScreen::grabClipboard(
|
||||
ClipboardID id)
|
||||
{
|
||||
setDisplayClipboard(id, NULL);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::getMousePos(
|
||||
SInt32* x, SInt32* y) const
|
||||
void
|
||||
CXWindowsSecondaryScreen::getMousePos(
|
||||
SInt32* x,
|
||||
SInt32* y) const
|
||||
{
|
||||
CDisplayLock display(this);
|
||||
int xTmp, yTmp, dummy;
|
||||
|
@ -273,24 +310,30 @@ void CXWindowsSecondaryScreen::getMousePos(
|
|||
*y = yTmp;
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::getSize(
|
||||
SInt32* width, SInt32* height) const
|
||||
void
|
||||
CXWindowsSecondaryScreen::getSize(
|
||||
SInt32* width,
|
||||
SInt32* height) const
|
||||
{
|
||||
getScreenSize(width, height);
|
||||
}
|
||||
|
||||
SInt32 CXWindowsSecondaryScreen::getJumpZoneSize() const
|
||||
SInt32
|
||||
CXWindowsSecondaryScreen::getJumpZoneSize() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::getClipboard(
|
||||
ClipboardID id, IClipboard* clipboard) const
|
||||
void
|
||||
CXWindowsSecondaryScreen::getClipboard(
|
||||
ClipboardID id,
|
||||
IClipboard* clipboard) const
|
||||
{
|
||||
getDisplayClipboard(id, clipboard);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::onOpenDisplay(
|
||||
void
|
||||
CXWindowsSecondaryScreen::onOpenDisplay(
|
||||
Display* display)
|
||||
{
|
||||
assert(m_window == None);
|
||||
|
@ -318,14 +361,16 @@ void CXWindowsSecondaryScreen::onOpenDisplay(
|
|||
leaveNoLock(display);
|
||||
}
|
||||
|
||||
CXWindowsClipboard* CXWindowsSecondaryScreen::createClipboard(
|
||||
CXWindowsClipboard*
|
||||
CXWindowsSecondaryScreen::createClipboard(
|
||||
ClipboardID id)
|
||||
{
|
||||
CDisplayLock display(this);
|
||||
return new CXWindowsClipboard(display, m_window, id);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::onCloseDisplay(
|
||||
void
|
||||
CXWindowsSecondaryScreen::onCloseDisplay(
|
||||
Display* display)
|
||||
{
|
||||
assert(m_window != None);
|
||||
|
@ -340,14 +385,17 @@ void CXWindowsSecondaryScreen::onCloseDisplay(
|
|||
m_window = None;
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::onLostClipboard(
|
||||
void
|
||||
CXWindowsSecondaryScreen::onLostClipboard(
|
||||
ClipboardID id)
|
||||
{
|
||||
// tell client that the clipboard was grabbed locally
|
||||
m_client->onClipboardChanged(id);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::leaveNoLock(Display* display)
|
||||
void
|
||||
CXWindowsSecondaryScreen::leaveNoLock(
|
||||
Display* display)
|
||||
{
|
||||
assert(display != NULL);
|
||||
assert(m_window != None);
|
||||
|
@ -368,17 +416,20 @@ void CXWindowsSecondaryScreen::leaveNoLock(Display* display)
|
|||
XWarpPointer(display, None, m_window, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
unsigned int CXWindowsSecondaryScreen::mapButton(
|
||||
unsigned int
|
||||
CXWindowsSecondaryScreen::mapButton(
|
||||
ButtonID id) const
|
||||
{
|
||||
// FIXME -- should use button mapping?
|
||||
return static_cast<unsigned int>(id);
|
||||
}
|
||||
|
||||
KeyModifierMask CXWindowsSecondaryScreen::mapKey(
|
||||
KeyModifierMask
|
||||
CXWindowsSecondaryScreen::mapKey(
|
||||
Keystrokes& keys,
|
||||
KeyCode& keycode,
|
||||
KeyID id, KeyModifierMask mask,
|
||||
KeyID id,
|
||||
KeyModifierMask mask,
|
||||
EKeyAction action) const
|
||||
{
|
||||
// note -- must have display locked on entry
|
||||
|
@ -602,7 +653,8 @@ KeyModifierMask CXWindowsSecondaryScreen::mapKey(
|
|||
return mask;
|
||||
}
|
||||
|
||||
bool CXWindowsSecondaryScreen::findKeyCode(
|
||||
bool
|
||||
CXWindowsSecondaryScreen::findKeyCode(
|
||||
KeyCode& keycode,
|
||||
unsigned int& maskOut,
|
||||
KeyID id,
|
||||
|
@ -734,12 +786,15 @@ bool CXWindowsSecondaryScreen::findKeyCode(
|
|||
return true;
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::doKeystrokes(
|
||||
const Keystrokes& keys, SInt32 count)
|
||||
void
|
||||
CXWindowsSecondaryScreen::doKeystrokes(
|
||||
const Keystrokes& keys,
|
||||
SInt32 count)
|
||||
{
|
||||
// do nothing if no keys or no repeats
|
||||
if (count < 1 || keys.empty())
|
||||
if (count < 1 || keys.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// lock display
|
||||
CDisplayLock display(this);
|
||||
|
@ -774,29 +829,39 @@ void CXWindowsSecondaryScreen::doKeystrokes(
|
|||
XSync(display, False);
|
||||
}
|
||||
|
||||
unsigned int CXWindowsSecondaryScreen::maskToX(
|
||||
unsigned int
|
||||
CXWindowsSecondaryScreen::maskToX(
|
||||
KeyModifierMask inMask) const
|
||||
{
|
||||
// FIXME -- should be configurable. also not using Mod3Mask.
|
||||
unsigned int outMask = 0;
|
||||
if (inMask & KeyModifierShift)
|
||||
if (inMask & KeyModifierShift) {
|
||||
outMask |= ShiftMask;
|
||||
if (inMask & KeyModifierControl)
|
||||
}
|
||||
if (inMask & KeyModifierControl) {
|
||||
outMask |= ControlMask;
|
||||
if (inMask & KeyModifierAlt)
|
||||
}
|
||||
if (inMask & KeyModifierAlt) {
|
||||
outMask |= Mod1Mask;
|
||||
if (inMask & KeyModifierMeta)
|
||||
}
|
||||
if (inMask & KeyModifierMeta) {
|
||||
outMask |= Mod4Mask;
|
||||
if (inMask & KeyModifierCapsLock)
|
||||
}
|
||||
if (inMask & KeyModifierCapsLock) {
|
||||
outMask |= m_capsLockMask;
|
||||
if (inMask & KeyModifierNumLock)
|
||||
}
|
||||
if (inMask & KeyModifierNumLock) {
|
||||
outMask |= m_numLockMask;
|
||||
if (inMask & KeyModifierScrollLock)
|
||||
}
|
||||
if (inMask & KeyModifierScrollLock) {
|
||||
outMask |= m_scrollLockMask;
|
||||
}
|
||||
return outMask;
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::updateKeys(Display* display)
|
||||
void
|
||||
CXWindowsSecondaryScreen::updateKeys(
|
||||
Display* display)
|
||||
{
|
||||
// ask server which keys are pressed
|
||||
char keys[32];
|
||||
|
@ -815,7 +880,8 @@ void CXWindowsSecondaryScreen::updateKeys(Display* display)
|
|||
}
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::updateModifiers(
|
||||
void
|
||||
CXWindowsSecondaryScreen::updateModifiers(
|
||||
Display* display)
|
||||
{
|
||||
// query the pointer to get the keyboard state
|
||||
|
@ -844,7 +910,8 @@ void CXWindowsSecondaryScreen::updateModifiers(
|
|||
}
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::updateKeycodeMap(
|
||||
void
|
||||
CXWindowsSecondaryScreen::updateKeycodeMap(
|
||||
Display* display)
|
||||
{
|
||||
// get the number of keycodes
|
||||
|
@ -898,7 +965,8 @@ void CXWindowsSecondaryScreen::updateKeycodeMap(
|
|||
XFree(keysyms);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::updateModifierMap(
|
||||
void
|
||||
CXWindowsSecondaryScreen::updateModifierMap(
|
||||
Display* display)
|
||||
{
|
||||
// get modifier map from server
|
||||
|
@ -927,8 +995,9 @@ void CXWindowsSecondaryScreen::updateModifierMap(
|
|||
m_keycodeToModifier.insert(std::make_pair(keycode, i));
|
||||
|
||||
// modifier is enabled if keycode isn't 0
|
||||
if (keycode != 0)
|
||||
if (keycode != 0) {
|
||||
m_modifierMask |= bit;
|
||||
}
|
||||
|
||||
// modifier is a toggle if the keysym is a toggle modifier
|
||||
const KeySym keysym = XKeycodeToKeysym(display, keycode, 0);
|
||||
|
@ -952,14 +1021,17 @@ void CXWindowsSecondaryScreen::updateModifierMap(
|
|||
XFreeModifiermap(keymap);
|
||||
}
|
||||
|
||||
void CXWindowsSecondaryScreen::toggleKey(
|
||||
void
|
||||
CXWindowsSecondaryScreen::toggleKey(
|
||||
Display* display,
|
||||
KeySym keysym, unsigned int mask)
|
||||
KeySym keysym,
|
||||
unsigned int mask)
|
||||
{
|
||||
// lookup the keycode
|
||||
KeyCodeMap::const_iterator index = m_keycodeMap.find(keysym);
|
||||
if (index == m_keycodeMap.end())
|
||||
if (index == m_keycodeMap.end()) {
|
||||
return;
|
||||
}
|
||||
KeyCode keycode = index->second.m_keycode;
|
||||
|
||||
// toggle the key
|
||||
|
@ -978,7 +1050,9 @@ void CXWindowsSecondaryScreen::toggleKey(
|
|||
m_mask ^= mask;
|
||||
}
|
||||
|
||||
bool CXWindowsSecondaryScreen::isToggleKeysym(KeySym key)
|
||||
bool
|
||||
CXWindowsSecondaryScreen::isToggleKeysym(
|
||||
KeySym key)
|
||||
{
|
||||
switch (key) {
|
||||
case XK_Caps_Lock:
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
#include "stdmap.h"
|
||||
#include "stdvector.h"
|
||||
|
||||
class CXWindowsSecondaryScreen : public CXWindowsScreen, public ISecondaryScreen {
|
||||
class CXWindowsSecondaryScreen : public CXWindowsScreen,
|
||||
public ISecondaryScreen {
|
||||
public:
|
||||
CXWindowsSecondaryScreen();
|
||||
virtual ~CXWindowsSecondaryScreen();
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
#include "CClient.h"
|
||||
#include "CString.h"
|
||||
#include "CLog.h"
|
||||
#include "CPlatform.h"
|
||||
#include "ProtocolTypes.h"
|
||||
#include "Version.h"
|
||||
#include "CNetwork.h"
|
||||
#include "CNetworkAddress.h"
|
||||
#include "XSocket.h"
|
||||
#include "CCondVar.h"
|
||||
#include "CLock.h"
|
||||
#include "CMutex.h"
|
||||
#include "CNetwork.h"
|
||||
#include "CNetworkAddress.h"
|
||||
#include "CPlatform.h"
|
||||
#include "CThread.h"
|
||||
#include "XThread.h"
|
||||
#include "ProtocolTypes.h"
|
||||
#include "Version.h"
|
||||
#include <assert.h>
|
||||
#include "CLog.h"
|
||||
#include "CString.h"
|
||||
#include <cstring>
|
||||
|
||||
// platform dependent name of a daemon
|
||||
#if defined(CONFIG_PLATFORM_WIN32)
|
||||
|
@ -43,7 +44,10 @@ static CNetworkAddress s_serverAddress;
|
|||
|
||||
static CMutex* s_logMutex = NULL;
|
||||
|
||||
static void logLock(bool lock)
|
||||
static
|
||||
void
|
||||
logLock(
|
||||
bool lock)
|
||||
{
|
||||
assert(s_logMutex != NULL);
|
||||
|
||||
|
@ -62,7 +66,10 @@ static void logLock(bool lock)
|
|||
|
||||
static CClient* s_client = NULL;
|
||||
|
||||
static int realMain(CMutex* mutex)
|
||||
static
|
||||
int
|
||||
realMain(
|
||||
CMutex* mutex)
|
||||
{
|
||||
try {
|
||||
// initialize threading library
|
||||
|
@ -124,14 +131,18 @@ static int realMain(CMutex* mutex)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int restartMain()
|
||||
static
|
||||
int
|
||||
restartMain()
|
||||
{
|
||||
return realMain(NULL);
|
||||
}
|
||||
|
||||
// invoke realMain and wait for it. if s_restartable then keep
|
||||
// restarting realMain until it returns a terminate code.
|
||||
static int restartableMain()
|
||||
static
|
||||
int
|
||||
restartableMain()
|
||||
{
|
||||
if (s_restartable) {
|
||||
CPlatform platform;
|
||||
|
@ -151,7 +162,9 @@ static int restartableMain()
|
|||
|
||||
static void (*bye)(int) = &exit;
|
||||
|
||||
static void version()
|
||||
static
|
||||
void
|
||||
version()
|
||||
{
|
||||
log((CLOG_PRINT
|
||||
"%s %d.%d.%d, protocol version %d.%d\n"
|
||||
|
@ -165,7 +178,9 @@ static void version()
|
|||
kCopyright));
|
||||
}
|
||||
|
||||
static void help()
|
||||
static
|
||||
void
|
||||
help()
|
||||
{
|
||||
log((CLOG_PRINT
|
||||
"Usage: %s"
|
||||
|
@ -213,8 +228,11 @@ static void help()
|
|||
|
||||
}
|
||||
|
||||
static bool isArg(int argi,
|
||||
int argc, const char** argv,
|
||||
static
|
||||
bool
|
||||
isArg(int argi,
|
||||
int argc,
|
||||
const char** argv,
|
||||
const char* name1,
|
||||
const char* name2,
|
||||
int minRequiredParameters = 0)
|
||||
|
@ -234,7 +252,11 @@ static bool isArg(int argi,
|
|||
return false;
|
||||
}
|
||||
|
||||
static void parse(int argc, const char** argv)
|
||||
static
|
||||
void
|
||||
parse(
|
||||
int argc,
|
||||
const char** argv)
|
||||
{
|
||||
assert(pname != NULL);
|
||||
assert(argv != NULL);
|
||||
|
@ -413,7 +435,11 @@ static void parse(int argc, const char** argv)
|
|||
|
||||
#include "CMSWindowsScreen.h"
|
||||
|
||||
static bool logMessageBox(int priority, const char* msg)
|
||||
static
|
||||
bool
|
||||
logMessageBox(
|
||||
int priority,
|
||||
const char* msg)
|
||||
{
|
||||
if (priority <= CLog::kFATAL) {
|
||||
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);
|
||||
}
|
||||
|
||||
static void daemonStop(void)
|
||||
static
|
||||
void
|
||||
daemonStop(void)
|
||||
{
|
||||
s_client->quit();
|
||||
}
|
||||
|
||||
static int daemonStartup(IPlatform* iplatform,
|
||||
int argc, const char** argv)
|
||||
static
|
||||
int
|
||||
daemonStartup(
|
||||
IPlatform* iplatform,
|
||||
int argc,
|
||||
const char** argv)
|
||||
{
|
||||
// get platform pointer
|
||||
CWin32Platform* platform = static_cast<CWin32Platform*>(iplatform);
|
||||
|
@ -456,19 +490,30 @@ static int daemonStartup(IPlatform* iplatform,
|
|||
return platform->runDaemon(realMain, daemonStop);
|
||||
}
|
||||
|
||||
static int daemonStartup95(IPlatform*, int, const char**)
|
||||
static
|
||||
int
|
||||
daemonStartup95(
|
||||
IPlatform*,
|
||||
int,
|
||||
const char**)
|
||||
{
|
||||
return realMain(NULL);
|
||||
}
|
||||
|
||||
static bool logDiscard(int, const char*)
|
||||
static
|
||||
bool
|
||||
logDiscard(
|
||||
int,
|
||||
const char*)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
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.
|
||||
// 0 means graceful exit. we plan to exit for anything but
|
||||
|
@ -478,7 +523,12 @@ static void checkParse(int e)
|
|||
throw s_die;
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
||||
int WINAPI
|
||||
WinMain(
|
||||
HINSTANCE instance,
|
||||
HINSTANCE,
|
||||
LPSTR,
|
||||
int)
|
||||
{
|
||||
CPlatform platform;
|
||||
|
||||
|
@ -594,12 +644,20 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
|||
|
||||
#elif defined(CONFIG_PLATFORM_UNIX)
|
||||
|
||||
static int daemonStartup(IPlatform*, int, const char**)
|
||||
static
|
||||
int
|
||||
daemonStartup(
|
||||
IPlatform*,
|
||||
int,
|
||||
const char**)
|
||||
{
|
||||
return restartableMain();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int
|
||||
main(
|
||||
int argc,
|
||||
char** argv)
|
||||
{
|
||||
CPlatform platform;
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#include "CHTTPProtocol.h"
|
||||
#include "CLog.h"
|
||||
#include "XHTTP.h"
|
||||
#include "IInputStream.h"
|
||||
#include "IOutputStream.h"
|
||||
#include "CLog.h"
|
||||
#include "stdsstream.h"
|
||||
#include <assert.h>
|
||||
#include <locale.h>
|
||||
#include <time.h>
|
||||
#include <clocale>
|
||||
#include <ctime>
|
||||
#include <algorithm>
|
||||
|
||||
//
|
||||
|
@ -23,8 +22,10 @@ CHTTPRequest::~CHTTPRequest()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
void CHTTPRequest::insertHeader(
|
||||
const CString& name, const CString& value)
|
||||
void
|
||||
CHTTPRequest::insertHeader(
|
||||
const CString& name,
|
||||
const CString& value)
|
||||
{
|
||||
CHeaderMap::iterator index = m_headerByName.find(name);
|
||||
if (index != m_headerByName.end()) {
|
||||
|
@ -37,8 +38,10 @@ void CHTTPRequest::insertHeader(
|
|||
}
|
||||
}
|
||||
|
||||
void CHTTPRequest::appendHeader(
|
||||
const CString& name, const CString& value)
|
||||
void
|
||||
CHTTPRequest::appendHeader(
|
||||
const CString& name,
|
||||
const CString& value)
|
||||
{
|
||||
CHeaderMap::iterator index = m_headerByName.find(name);
|
||||
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);
|
||||
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());
|
||||
}
|
||||
|
||||
CString CHTTPRequest::getHeader(const CString& name) const
|
||||
CString
|
||||
CHTTPRequest::getHeader(
|
||||
const CString& name) const
|
||||
{
|
||||
CHeaderMap::const_iterator index = m_headerByName.find(name);
|
||||
if (index != m_headerByName.end()) {
|
||||
|
@ -81,8 +90,10 @@ CString CHTTPRequest::getHeader(const CString& name) const
|
|||
// CHTTPProtocol
|
||||
//
|
||||
|
||||
CHTTPRequest* CHTTPProtocol::readRequest(
|
||||
IInputStream* stream, UInt32 maxSize)
|
||||
CHTTPRequest*
|
||||
CHTTPProtocol::readRequest(
|
||||
IInputStream* stream,
|
||||
UInt32 maxSize)
|
||||
{
|
||||
CString scratch;
|
||||
|
||||
|
@ -229,7 +240,8 @@ CHTTPRequest* CHTTPProtocol::readRequest(
|
|||
return request;
|
||||
}
|
||||
|
||||
void CHTTPProtocol::reply(
|
||||
void
|
||||
CHTTPProtocol::reply(
|
||||
IOutputStream* stream,
|
||||
CHTTPReply& reply)
|
||||
{
|
||||
|
@ -308,7 +320,8 @@ void CHTTPProtocol::reply(
|
|||
}
|
||||
}
|
||||
|
||||
bool CHTTPProtocol::parseFormData(
|
||||
bool
|
||||
CHTTPProtocol::parseFormData(
|
||||
const CHTTPRequest& request,
|
||||
CFormParts& parts)
|
||||
{
|
||||
|
@ -444,7 +457,8 @@ bool CHTTPProtocol::parseFormData(
|
|||
return false;
|
||||
}
|
||||
|
||||
CString CHTTPProtocol::readLine(
|
||||
CString
|
||||
CHTTPProtocol::readLine(
|
||||
IInputStream* stream,
|
||||
CString& tmpBuffer)
|
||||
{
|
||||
|
@ -478,7 +492,8 @@ CString CHTTPProtocol::readLine(
|
|||
}
|
||||
}
|
||||
|
||||
CString CHTTPProtocol::readBlock(
|
||||
CString
|
||||
CHTTPProtocol::readBlock(
|
||||
IInputStream* stream,
|
||||
UInt32 numBytes,
|
||||
CString& tmpBuffer)
|
||||
|
@ -527,7 +542,8 @@ CString CHTTPProtocol::readBlock(
|
|||
return data;
|
||||
}
|
||||
|
||||
CString CHTTPProtocol::readChunk(
|
||||
CString
|
||||
CHTTPProtocol::readChunk(
|
||||
IInputStream* stream,
|
||||
CString& tmpBuffer,
|
||||
UInt32* maxSize)
|
||||
|
@ -577,7 +593,8 @@ CString CHTTPProtocol::readChunk(
|
|||
return data;
|
||||
}
|
||||
|
||||
void CHTTPProtocol::readHeaders(
|
||||
void
|
||||
CHTTPProtocol::readHeaders(
|
||||
IInputStream* stream,
|
||||
CHTTPRequest* request,
|
||||
bool isFooter,
|
||||
|
@ -634,7 +651,9 @@ void CHTTPProtocol::readHeaders(
|
|||
}
|
||||
}
|
||||
|
||||
bool CHTTPProtocol::isValidToken(const CString& token)
|
||||
bool
|
||||
CHTTPProtocol::isValidToken(
|
||||
const CString& token)
|
||||
{
|
||||
return (token.find("()<>@,;:\\\"/[]?={} "
|
||||
"\0\1\2\3\4\5\6\7"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef CHTTPPROTOCOL_H
|
||||
#define CHTTPPROTOCOL_H
|
||||
|
||||
#include "BasicTypes.h"
|
||||
#include "CString.h"
|
||||
#include "BasicTypes.h"
|
||||
#include "stdlist.h"
|
||||
#include "stdmap.h"
|
||||
#include "stdvector.h"
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
// XHTTP
|
||||
//
|
||||
|
||||
XHTTP::XHTTP(SInt32 statusCode) :
|
||||
XHTTP::XHTTP(
|
||||
SInt32 statusCode) :
|
||||
XBase(),
|
||||
m_status(statusCode),
|
||||
m_reason(getReason(statusCode))
|
||||
|
@ -14,7 +15,9 @@ XHTTP::XHTTP(SInt32 statusCode) :
|
|||
// do nothing
|
||||
}
|
||||
|
||||
XHTTP::XHTTP(SInt32 statusCode, const CString& reasonPhrase) :
|
||||
XHTTP::XHTTP(
|
||||
SInt32 statusCode,
|
||||
const CString& reasonPhrase) :
|
||||
XBase(),
|
||||
m_status(statusCode),
|
||||
m_reason(reasonPhrase)
|
||||
|
@ -27,22 +30,27 @@ XHTTP::~XHTTP()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
SInt32 XHTTP::getStatus() const
|
||||
SInt32
|
||||
XHTTP::getStatus() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
|
||||
CString XHTTP::getReason() const
|
||||
CString
|
||||
XHTTP::getReason() const
|
||||
{
|
||||
return m_reason;
|
||||
}
|
||||
|
||||
void XHTTP::addHeaders(CHTTPReply&) const
|
||||
void
|
||||
XHTTP::addHeaders(
|
||||
CHTTPReply&) const
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
CString XHTTP::getWhat() const throw()
|
||||
CString
|
||||
XHTTP::getWhat() const throw()
|
||||
{
|
||||
try {
|
||||
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) {
|
||||
case 300: return "Multiple Choices";
|
||||
|
@ -100,7 +110,8 @@ const char* XHTTP::getReason(SInt32 status)
|
|||
// XHTTPAllow
|
||||
//
|
||||
|
||||
XHTTPAllow::XHTTPAllow(const CString& allowed) :
|
||||
XHTTPAllow::XHTTPAllow(
|
||||
const CString& allowed) :
|
||||
XHTTP(405),
|
||||
m_allowed(allowed)
|
||||
{
|
||||
|
@ -112,7 +123,9 @@ XHTTPAllow::~XHTTPAllow()
|
|||
// 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));
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define XHTTP_H
|
||||
|
||||
#include "BasicTypes.h"
|
||||
#include "CString.h"
|
||||
#include "XBase.h"
|
||||
|
||||
class CHTTPReply;
|
||||
|
|
|
@ -4,14 +4,15 @@
|
|||
#include "CThread.h"
|
||||
#include "IJob.h"
|
||||
#include "XIO.h"
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <cstring>
|
||||
|
||||
//
|
||||
// CBufferedInputStream
|
||||
//
|
||||
|
||||
CBufferedInputStream::CBufferedInputStream(CMutex* mutex, IJob* closeCB) :
|
||||
CBufferedInputStream::CBufferedInputStream(
|
||||
CMutex* mutex,
|
||||
IJob* closeCB) :
|
||||
m_mutex(mutex),
|
||||
m_empty(mutex, true),
|
||||
m_closeCB(closeCB),
|
||||
|
@ -26,8 +27,10 @@ CBufferedInputStream::~CBufferedInputStream()
|
|||
delete m_closeCB;
|
||||
}
|
||||
|
||||
void CBufferedInputStream::write(
|
||||
const void* data, UInt32 n)
|
||||
void
|
||||
CBufferedInputStream::write(
|
||||
const void* data,
|
||||
UInt32 n)
|
||||
{
|
||||
if (!m_hungup && n > 0) {
|
||||
m_buffer.write(data, n);
|
||||
|
@ -36,14 +39,17 @@ void CBufferedInputStream::write(
|
|||
}
|
||||
}
|
||||
|
||||
void CBufferedInputStream::hangup()
|
||||
void
|
||||
CBufferedInputStream::hangup()
|
||||
{
|
||||
m_hungup = true;
|
||||
m_empty.broadcast();
|
||||
}
|
||||
|
||||
UInt32 CBufferedInputStream::readNoLock(
|
||||
void* dst, UInt32 n)
|
||||
UInt32
|
||||
CBufferedInputStream::readNoLock(
|
||||
void* dst,
|
||||
UInt32 n)
|
||||
{
|
||||
if (m_closed) {
|
||||
throw XIOClosed();
|
||||
|
@ -74,12 +80,14 @@ UInt32 CBufferedInputStream::readNoLock(
|
|||
return n;
|
||||
}
|
||||
|
||||
UInt32 CBufferedInputStream::getSizeNoLock() const
|
||||
UInt32
|
||||
CBufferedInputStream::getSizeNoLock() const
|
||||
{
|
||||
return m_buffer.getSize();
|
||||
}
|
||||
|
||||
void CBufferedInputStream::close()
|
||||
void
|
||||
CBufferedInputStream::close()
|
||||
{
|
||||
CLock lock(m_mutex);
|
||||
if (m_closed) {
|
||||
|
@ -95,16 +103,18 @@ void CBufferedInputStream::close()
|
|||
}
|
||||
}
|
||||
|
||||
UInt32 CBufferedInputStream::read(
|
||||
void* dst, UInt32 n)
|
||||
UInt32
|
||||
CBufferedInputStream::read(
|
||||
void* dst,
|
||||
UInt32 n)
|
||||
{
|
||||
CLock lock(m_mutex);
|
||||
return readNoLock(dst, n);
|
||||
}
|
||||
|
||||
UInt32 CBufferedInputStream::getSize() const
|
||||
UInt32
|
||||
CBufferedInputStream::getSize() const
|
||||
{
|
||||
CLock lock(m_mutex);
|
||||
return getSizeNoLock();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#ifndef CBUFFEREDINPUTSTREAM_H
|
||||
#define CBUFFEREDINPUTSTREAM_H
|
||||
|
||||
#include "IInputStream.h"
|
||||
#include "CStreamBuffer.h"
|
||||
#include "CCondVar.h"
|
||||
#include "IInputStream.h"
|
||||
|
||||
class CMutex;
|
||||
class IJob;
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
#include "CBufferedOutputStream.h"
|
||||
#include "XIO.h"
|
||||
#include "CLock.h"
|
||||
#include "CMutex.h"
|
||||
#include "CThread.h"
|
||||
#include "IJob.h"
|
||||
#include "XIO.h"
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CBufferedOutputStream
|
||||
//
|
||||
|
||||
CBufferedOutputStream::CBufferedOutputStream(CMutex* mutex, IJob* closeCB) :
|
||||
CBufferedOutputStream::CBufferedOutputStream(
|
||||
CMutex* mutex,
|
||||
IJob* closeCB) :
|
||||
m_mutex(mutex),
|
||||
m_closeCB(closeCB),
|
||||
m_empty(mutex, true),
|
||||
|
@ -24,12 +25,16 @@ CBufferedOutputStream::~CBufferedOutputStream()
|
|||
delete m_closeCB;
|
||||
}
|
||||
|
||||
const void* CBufferedOutputStream::peek(UInt32 n)
|
||||
const void*
|
||||
CBufferedOutputStream::peek(
|
||||
UInt32 n)
|
||||
{
|
||||
return m_buffer.peek(n);
|
||||
}
|
||||
|
||||
void CBufferedOutputStream::pop(UInt32 n)
|
||||
void
|
||||
CBufferedOutputStream::pop(
|
||||
UInt32 n)
|
||||
{
|
||||
m_buffer.pop(n);
|
||||
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();
|
||||
}
|
||||
|
||||
void CBufferedOutputStream::close()
|
||||
void
|
||||
CBufferedOutputStream::close()
|
||||
{
|
||||
CLock lock(m_mutex);
|
||||
if (m_closed) {
|
||||
|
@ -56,8 +63,10 @@ void CBufferedOutputStream::close()
|
|||
}
|
||||
}
|
||||
|
||||
UInt32 CBufferedOutputStream::write(
|
||||
const void* data, UInt32 n)
|
||||
UInt32
|
||||
CBufferedOutputStream::write(
|
||||
const void* data,
|
||||
UInt32 n)
|
||||
{
|
||||
CLock lock(m_mutex);
|
||||
if (m_closed) {
|
||||
|
@ -68,7 +77,8 @@ UInt32 CBufferedOutputStream::write(
|
|||
return n;
|
||||
}
|
||||
|
||||
void CBufferedOutputStream::flush()
|
||||
void
|
||||
CBufferedOutputStream::flush()
|
||||
{
|
||||
// wait until all data is written
|
||||
CLock lock(m_mutex);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef CBUFFEREDOUTPUTSTREAM_H
|
||||
#define CBUFFEREDOUTPUTSTREAM_H
|
||||
|
||||
#include "CStreamBuffer.h"
|
||||
#include "IOutputStream.h"
|
||||
#include "CStreamBuffer.h"
|
||||
#include "CCondVar.h"
|
||||
|
||||
class CMutex;
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#include "CInputStreamFilter.h"
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CInputStreamFilter
|
||||
//
|
||||
|
||||
CInputStreamFilter::CInputStreamFilter(IInputStream* stream, bool adopted) :
|
||||
CInputStreamFilter::CInputStreamFilter(
|
||||
IInputStream* stream,
|
||||
bool adopted) :
|
||||
m_stream(stream),
|
||||
m_adopted(adopted)
|
||||
{
|
||||
|
@ -19,7 +20,8 @@ CInputStreamFilter::~CInputStreamFilter()
|
|||
}
|
||||
}
|
||||
|
||||
IInputStream* CInputStreamFilter::getStream() const
|
||||
IInputStream*
|
||||
CInputStreamFilter::getStream() const
|
||||
{
|
||||
return m_stream;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#include "COutputStreamFilter.h"
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// COutputStreamFilter
|
||||
//
|
||||
|
||||
COutputStreamFilter::COutputStreamFilter(IOutputStream* stream, bool adopted) :
|
||||
COutputStreamFilter::COutputStreamFilter(
|
||||
IOutputStream* stream,
|
||||
bool adopted) :
|
||||
m_stream(stream),
|
||||
m_adopted(adopted)
|
||||
{
|
||||
|
@ -19,7 +20,8 @@ COutputStreamFilter::~COutputStreamFilter()
|
|||
}
|
||||
}
|
||||
|
||||
IOutputStream* COutputStreamFilter::getStream() const
|
||||
IOutputStream*
|
||||
COutputStreamFilter::getStream() const
|
||||
{
|
||||
return m_stream;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "CStreamBuffer.h"
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CStreamBuffer
|
||||
|
@ -7,7 +6,8 @@
|
|||
|
||||
const UInt32 CStreamBuffer::kChunkSize = 4096;
|
||||
|
||||
CStreamBuffer::CStreamBuffer() : m_size(0)
|
||||
CStreamBuffer::CStreamBuffer() :
|
||||
m_size(0)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
@ -17,7 +17,9 @@ CStreamBuffer::~CStreamBuffer()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
const void* CStreamBuffer::peek(UInt32 n)
|
||||
const void*
|
||||
CStreamBuffer::peek(
|
||||
UInt32 n)
|
||||
{
|
||||
assert(n <= m_size);
|
||||
|
||||
|
@ -36,7 +38,9 @@ const void* CStreamBuffer::peek(UInt32 n)
|
|||
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
|
||||
if (n >= m_size) {
|
||||
|
@ -63,8 +67,10 @@ void CStreamBuffer::pop(UInt32 n)
|
|||
}
|
||||
}
|
||||
|
||||
void CStreamBuffer::write(
|
||||
const void* vdata, UInt32 n)
|
||||
void
|
||||
CStreamBuffer::write(
|
||||
const void* vdata,
|
||||
UInt32 n)
|
||||
{
|
||||
assert(vdata != NULL);
|
||||
|
||||
|
@ -81,9 +87,10 @@ void CStreamBuffer::write(
|
|||
ChunkList::iterator scan = m_chunks.end();
|
||||
if (scan != m_chunks.begin()) {
|
||||
--scan;
|
||||
if (scan->size() >= kChunkSize)
|
||||
if (scan->size() >= kChunkSize) {
|
||||
++scan;
|
||||
}
|
||||
}
|
||||
if (scan == m_chunks.end()) {
|
||||
scan = m_chunks.insert(scan, Chunk());
|
||||
}
|
||||
|
@ -109,7 +116,8 @@ void CStreamBuffer::write(
|
|||
}
|
||||
}
|
||||
|
||||
UInt32 CStreamBuffer::getSize() const
|
||||
UInt32
|
||||
CStreamBuffer::getSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "IInterface.h"
|
||||
#include "BasicTypes.h"
|
||||
#include "XIO.h"
|
||||
|
||||
class IInputStream : public IInterface {
|
||||
public:
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "IInterface.h"
|
||||
#include "BasicTypes.h"
|
||||
#include "XIO.h"
|
||||
|
||||
class IOutputStream : public IInterface {
|
||||
public:
|
||||
|
|
16
io/XIO.cpp
16
io/XIO.cpp
|
@ -4,12 +4,14 @@
|
|||
// XIOErrno
|
||||
//
|
||||
|
||||
XIOErrno::XIOErrno() : MXErrno()
|
||||
XIOErrno::XIOErrno() :
|
||||
MXErrno()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
XIOErrno::XIOErrno(int err) : MXErrno(err)
|
||||
XIOErrno::XIOErrno(int err) :
|
||||
MXErrno(err)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
@ -19,7 +21,8 @@ XIOErrno::XIOErrno(int err) : MXErrno(err)
|
|||
// XIOClose
|
||||
//
|
||||
|
||||
CString XIOClose::getWhat() const throw()
|
||||
CString
|
||||
XIOClose::getWhat() const throw()
|
||||
{
|
||||
return format("XIOClose", "close: %1", XIOErrno::getErrstr());
|
||||
}
|
||||
|
@ -29,7 +32,8 @@ CString XIOClose::getWhat() const throw()
|
|||
// XIOClosed
|
||||
//
|
||||
|
||||
CString XIOClosed::getWhat() const throw()
|
||||
CString
|
||||
XIOClosed::getWhat() const throw()
|
||||
{
|
||||
return format("XIOClosed", "already closed");
|
||||
}
|
||||
|
@ -39,8 +43,8 @@ CString XIOClosed::getWhat() const throw()
|
|||
// XIOEndOfStream
|
||||
//
|
||||
|
||||
CString XIOEndOfStream::getWhat() const throw()
|
||||
CString
|
||||
XIOEndOfStream::getWhat() const throw()
|
||||
{
|
||||
return format("XIOEndOfStream", "reached end of stream");
|
||||
}
|
||||
|
||||
|
|
1
io/XIO.h
1
io/XIO.h
|
@ -2,7 +2,6 @@
|
|||
#define XIO_H
|
||||
|
||||
#include "XBase.h"
|
||||
#include "BasicTypes.h"
|
||||
|
||||
class XIO : public XBase { };
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "CCondVar.h"
|
||||
#include "CStopwatch.h"
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CCondVarBase
|
||||
|
@ -21,23 +20,27 @@ CCondVarBase::~CCondVarBase()
|
|||
fini();
|
||||
}
|
||||
|
||||
void CCondVarBase::lock() const
|
||||
void
|
||||
CCondVarBase::lock() const
|
||||
{
|
||||
m_mutex->lock();
|
||||
}
|
||||
|
||||
void CCondVarBase::unlock() const
|
||||
void
|
||||
CCondVarBase::unlock() const
|
||||
{
|
||||
m_mutex->unlock();
|
||||
}
|
||||
|
||||
bool CCondVarBase::wait(double timeout) const
|
||||
bool
|
||||
CCondVarBase::wait(double timeout) const
|
||||
{
|
||||
CStopwatch timer(true);
|
||||
return wait(timer, timeout);
|
||||
}
|
||||
|
||||
CMutex* CCondVarBase::getMutex() const
|
||||
CMutex*
|
||||
CCondVarBase::getMutex() const
|
||||
{
|
||||
return m_mutex;
|
||||
}
|
||||
|
@ -47,9 +50,10 @@ CMutex* CCondVarBase::getMutex() const
|
|||
#include "CThread.h"
|
||||
#include <pthread.h>
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
#include <cerrno>
|
||||
|
||||
void CCondVarBase::init()
|
||||
void
|
||||
CCondVarBase::init()
|
||||
{
|
||||
pthread_cond_t* cond = new pthread_cond_t;
|
||||
int status = pthread_cond_init(cond, NULL);
|
||||
|
@ -57,7 +61,8 @@ void CCondVarBase::init()
|
|||
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);
|
||||
int status = pthread_cond_destroy(cond);
|
||||
|
@ -65,22 +70,26 @@ void CCondVarBase::fini()
|
|||
delete cond;
|
||||
}
|
||||
|
||||
void CCondVarBase::signal()
|
||||
void
|
||||
CCondVarBase::signal()
|
||||
{
|
||||
pthread_cond_t* cond = reinterpret_cast<pthread_cond_t*>(m_cond);
|
||||
int status = pthread_cond_signal(cond);
|
||||
assert(status == 0);
|
||||
}
|
||||
|
||||
void CCondVarBase::broadcast()
|
||||
void
|
||||
CCondVarBase::broadcast()
|
||||
{
|
||||
pthread_cond_t* cond = reinterpret_cast<pthread_cond_t*>(m_cond);
|
||||
int status = pthread_cond_broadcast(cond);
|
||||
assert(status == 0);
|
||||
}
|
||||
|
||||
bool CCondVarBase::wait(
|
||||
CStopwatch& timer, double timeout) const
|
||||
bool
|
||||
CCondVarBase::wait(
|
||||
CStopwatch& timer,
|
||||
double timeout) const
|
||||
{
|
||||
// check timeout against timer
|
||||
if (timeout >= 0.0) {
|
||||
|
@ -143,9 +152,10 @@ bool CCondVarBase::wait(
|
|||
CThread::testCancel();
|
||||
|
||||
// check wait status
|
||||
if (status != ETIMEDOUT && status != EINTR)
|
||||
if (status != ETIMEDOUT && status != EINTR) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case 0:
|
||||
|
@ -180,7 +190,8 @@ bool CCondVarBase::wait(
|
|||
// can cause busy waiting.
|
||||
//
|
||||
|
||||
void CCondVarBase::init()
|
||||
void
|
||||
CCondVarBase::init()
|
||||
{
|
||||
// prepare events
|
||||
HANDLE* events = new HANDLE[2];
|
||||
|
@ -192,7 +203,8 @@ void CCondVarBase::init()
|
|||
m_waitCount = 0;
|
||||
}
|
||||
|
||||
void CCondVarBase::fini()
|
||||
void
|
||||
CCondVarBase::fini()
|
||||
{
|
||||
HANDLE* events = reinterpret_cast<HANDLE*>(m_cond);
|
||||
CloseHandle(events[kSignal]);
|
||||
|
@ -200,7 +212,8 @@ void CCondVarBase::fini()
|
|||
delete[] events;
|
||||
}
|
||||
|
||||
void CCondVarBase::signal()
|
||||
void
|
||||
CCondVarBase::signal()
|
||||
{
|
||||
// is anybody waiting?
|
||||
bool hasWaiter;
|
||||
|
@ -210,11 +223,13 @@ void CCondVarBase::signal()
|
|||
}
|
||||
|
||||
// wake one thread if anybody is waiting
|
||||
if (hasWaiter)
|
||||
if (hasWaiter) {
|
||||
SetEvent(reinterpret_cast<HANDLE*>(m_cond)[kSignal]);
|
||||
}
|
||||
}
|
||||
|
||||
void CCondVarBase::broadcast()
|
||||
void
|
||||
CCondVarBase::broadcast()
|
||||
{
|
||||
// is anybody waiting?
|
||||
bool hasWaiter;
|
||||
|
@ -224,19 +239,23 @@ void CCondVarBase::broadcast()
|
|||
}
|
||||
|
||||
// wake all threads if anybody is waiting
|
||||
if (hasWaiter)
|
||||
if (hasWaiter) {
|
||||
SetEvent(reinterpret_cast<HANDLE*>(m_cond)[kBroadcast]);
|
||||
}
|
||||
}
|
||||
|
||||
bool CCondVarBase::wait(
|
||||
CStopwatch& timer, double timeout) const
|
||||
bool
|
||||
CCondVarBase::wait(
|
||||
CStopwatch& timer,
|
||||
double timeout) const
|
||||
{
|
||||
// check timeout against timer
|
||||
if (timeout >= 0.0) {
|
||||
timeout -= timer.getTime();
|
||||
if (timeout < 0.0)
|
||||
if (timeout < 0.0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// prepare to wait
|
||||
CThreadPtr currentRep = CThreadRep::getCurrentThreadRep();
|
||||
|
@ -267,8 +286,9 @@ bool CCondVarBase::wait(
|
|||
|
||||
// cancel takes priority
|
||||
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;
|
||||
}
|
||||
|
||||
// update the waiter count and check if we're the last waiter
|
||||
bool last;
|
||||
|
@ -279,15 +299,17 @@ bool CCondVarBase::wait(
|
|||
}
|
||||
|
||||
// reset the broadcast event if we're the last waiter
|
||||
if (last)
|
||||
if (last) {
|
||||
ResetEvent(events[kBroadcast]);
|
||||
}
|
||||
|
||||
// reacquire the mutex
|
||||
m_mutex->lock();
|
||||
|
||||
// cancel thread if necessary
|
||||
if (result == WAIT_OBJECT_0 + 2)
|
||||
if (result == WAIT_OBJECT_0 + 2) {
|
||||
currentRep->testCancel();
|
||||
}
|
||||
|
||||
// return success or failure
|
||||
return (result == WAIT_OBJECT_0 + 0 ||
|
||||
|
|
|
@ -90,15 +90,19 @@ private:
|
|||
|
||||
template <class T>
|
||||
inline
|
||||
CCondVar<T>::CCondVar(CMutex* mutex, const T& data) :
|
||||
CCondVarBase(mutex), m_data(data)
|
||||
CCondVar<T>::CCondVar(
|
||||
CMutex* mutex,
|
||||
const T& data) :
|
||||
CCondVarBase(mutex),
|
||||
m_data(data)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
CCondVar<T>::CCondVar(const CCondVar& cv) :
|
||||
CCondVar<T>::CCondVar(
|
||||
const CCondVar& cv) :
|
||||
CCondVarBase(cv.getMutex()),
|
||||
m_data(cv.m_data)
|
||||
{
|
||||
|
@ -114,7 +118,9 @@ CCondVar<T>::~CCondVar()
|
|||
|
||||
template <class T>
|
||||
inline
|
||||
CCondVar<T>& CCondVar<T>::operator=(const CCondVar<T>& cv)
|
||||
CCondVar<T>&
|
||||
CCondVar<T>::operator=(
|
||||
const CCondVar<T>& cv)
|
||||
{
|
||||
m_data = cv.m_data;
|
||||
return *this;
|
||||
|
@ -122,7 +128,9 @@ CCondVar<T>& CCondVar<T>::operator=(const CCondVar<T>& cv)
|
|||
|
||||
template <class T>
|
||||
inline
|
||||
CCondVar<T>& CCondVar<T>::operator=(const T& data)
|
||||
CCondVar<T>&
|
||||
CCondVar<T>::operator=(
|
||||
const T& data)
|
||||
{
|
||||
m_data = data;
|
||||
return *this;
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
#include "CLock.h"
|
||||
#include "CMutex.h"
|
||||
#include "CCondVar.h"
|
||||
#include "CMutex.h"
|
||||
|
||||
//
|
||||
// CLock
|
||||
//
|
||||
|
||||
CLock::CLock(const CMutex* mutex) : m_mutex(mutex)
|
||||
CLock::CLock(const CMutex* mutex) :
|
||||
m_mutex(mutex)
|
||||
{
|
||||
m_mutex->lock();
|
||||
}
|
||||
|
||||
CLock::CLock(const CCondVarBase* cv) : m_mutex(cv->getMutex())
|
||||
CLock::CLock(const CCondVarBase* cv) :
|
||||
m_mutex(cv->getMutex())
|
||||
{
|
||||
m_mutex->lock();
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef CLOCK_H
|
||||
#define CLOCK_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
class CMutex;
|
||||
class CCondVarBase;
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "CMutex.h"
|
||||
#include "CLog.h"
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CMutex
|
||||
|
@ -21,7 +20,9 @@ CMutex::~CMutex()
|
|||
fini();
|
||||
}
|
||||
|
||||
CMutex& CMutex::operator=(const CMutex&)
|
||||
CMutex&
|
||||
CMutex::operator=(
|
||||
const CMutex&)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
@ -29,9 +30,10 @@ CMutex& CMutex::operator=(const CMutex&)
|
|||
#if defined(CONFIG_PTHREADS)
|
||||
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <cerrno>
|
||||
|
||||
void CMutex::init()
|
||||
void
|
||||
CMutex::init()
|
||||
{
|
||||
pthread_mutex_t* mutex = new pthread_mutex_t;
|
||||
int status = pthread_mutex_init(mutex, NULL);
|
||||
|
@ -41,11 +43,8 @@ void CMutex::init()
|
|||
m_mutex = reinterpret_cast<void*>(mutex);
|
||||
}
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
void CMutex::fini()
|
||||
void
|
||||
CMutex::fini()
|
||||
{
|
||||
pthread_mutex_t* mutex = reinterpret_cast<pthread_mutex_t*>(m_mutex);
|
||||
int status = pthread_mutex_destroy(mutex);
|
||||
|
@ -54,7 +53,8 @@ void CMutex::fini()
|
|||
delete mutex;
|
||||
}
|
||||
|
||||
void CMutex::lock() const
|
||||
void
|
||||
CMutex::lock() const
|
||||
{
|
||||
pthread_mutex_t* mutex = reinterpret_cast<pthread_mutex_t*>(m_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);
|
||||
int status = pthread_mutex_unlock(mutex);
|
||||
|
@ -105,26 +106,30 @@ void CMutex::unlock() const
|
|||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
void CMutex::init()
|
||||
void
|
||||
CMutex::init()
|
||||
{
|
||||
CRITICAL_SECTION* mutex = new CRITICAL_SECTION;
|
||||
InitializeCriticalSection(mutex);
|
||||
m_mutex = reinterpret_cast<void*>(mutex);
|
||||
}
|
||||
|
||||
void CMutex::fini()
|
||||
void
|
||||
CMutex::fini()
|
||||
{
|
||||
CRITICAL_SECTION* mutex = reinterpret_cast<CRITICAL_SECTION*>(m_mutex);
|
||||
DeleteCriticalSection(mutex);
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
void CMutex::lock() const
|
||||
void
|
||||
CMutex::lock() const
|
||||
{
|
||||
EnterCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(m_mutex));
|
||||
}
|
||||
|
||||
void CMutex::unlock() const
|
||||
void
|
||||
CMutex::unlock() const
|
||||
{
|
||||
LeaveCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(m_mutex));
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef CMUTEX_H
|
||||
#define CMUTEX_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
// recursive mutex class
|
||||
class CMutex {
|
||||
public:
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "CThread.h"
|
||||
#include "CLock.h"
|
||||
#include "CThreadRep.h"
|
||||
#include "XThread.h"
|
||||
#include "CLock.h"
|
||||
#include "CStopwatch.h"
|
||||
#include "CLog.h"
|
||||
#include "CStopwatch.h"
|
||||
|
||||
//
|
||||
// CThread
|
||||
|
@ -14,12 +14,14 @@ CThread::CThread(IJob* job, void* 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();
|
||||
}
|
||||
|
||||
CThread::CThread(CThreadRep* rep) : m_rep(rep)
|
||||
CThread::CThread(CThreadRep* rep) :
|
||||
m_rep(rep)
|
||||
{
|
||||
// do nothing. rep should have already been Ref()'d.
|
||||
}
|
||||
|
@ -29,7 +31,9 @@ CThread::~CThread()
|
|||
m_rep->unref();
|
||||
}
|
||||
|
||||
CThread& CThread::operator=(const CThread& thread)
|
||||
CThread&
|
||||
CThread::operator=(
|
||||
const CThread& thread)
|
||||
{
|
||||
if (thread.m_rep != m_rep) {
|
||||
m_rep->unref();
|
||||
|
@ -39,12 +43,15 @@ CThread& CThread::operator=(const CThread& thread)
|
|||
return *this;
|
||||
}
|
||||
|
||||
void CThread::init()
|
||||
void
|
||||
CThread::init()
|
||||
{
|
||||
CThreadRep::initThreads();
|
||||
}
|
||||
|
||||
void CThread::sleep(double timeout)
|
||||
void
|
||||
CThread::sleep(
|
||||
double timeout)
|
||||
{
|
||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||
if (timeout >= 0.0) {
|
||||
|
@ -54,47 +61,59 @@ void CThread::sleep(double timeout)
|
|||
currentRep->testCancel();
|
||||
}
|
||||
|
||||
void CThread::exit(void* result)
|
||||
void
|
||||
CThread::exit(
|
||||
void* result)
|
||||
{
|
||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||
log((CLOG_DEBUG1 "throw exit on thread %p", currentRep.operator->()));
|
||||
throw XThreadExit(result);
|
||||
}
|
||||
|
||||
bool CThread::enableCancel(bool enable)
|
||||
bool
|
||||
CThread::enableCancel(
|
||||
bool enable)
|
||||
{
|
||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||
return currentRep->enableCancel(enable);
|
||||
}
|
||||
|
||||
void CThread::cancel()
|
||||
void
|
||||
CThread::cancel()
|
||||
{
|
||||
m_rep->cancel();
|
||||
}
|
||||
|
||||
void CThread::setPriority(int n)
|
||||
void
|
||||
CThread::setPriority(
|
||||
int n)
|
||||
{
|
||||
m_rep->setPriority(n);
|
||||
}
|
||||
|
||||
CThread CThread::getCurrentThread()
|
||||
CThread
|
||||
CThread::getCurrentThread()
|
||||
{
|
||||
return CThread(CThreadRep::getCurrentThreadRep());
|
||||
}
|
||||
|
||||
bool CThread::wait(double timeout) const
|
||||
bool
|
||||
CThread::wait(
|
||||
double timeout) const
|
||||
{
|
||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||
return currentRep->wait(m_rep, timeout);
|
||||
}
|
||||
|
||||
void CThread::testCancel()
|
||||
void
|
||||
CThread::testCancel()
|
||||
{
|
||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||
currentRep->testCancel();
|
||||
}
|
||||
|
||||
void* CThread::getResult() const
|
||||
void*
|
||||
CThread::getResult() const
|
||||
{
|
||||
if (wait())
|
||||
return m_rep->getResult();
|
||||
|
@ -102,18 +121,23 @@ void* CThread::getResult() const
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void* CThread::getUserData()
|
||||
void*
|
||||
CThread::getUserData()
|
||||
{
|
||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||
return currentRep->getUserData();
|
||||
}
|
||||
|
||||
bool CThread::operator==(const CThread& thread) const
|
||||
bool
|
||||
CThread::operator==(
|
||||
const CThread& thread) const
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -123,7 +147,8 @@ bool CThread::operator!=(const CThread& thread) const
|
|||
// CThreadMaskCancel
|
||||
//
|
||||
|
||||
CThreadMaskCancel::CThreadMaskCancel() : m_old(CThread::enableCancel(false))
|
||||
CThreadMaskCancel::CThreadMaskCancel() :
|
||||
m_old(CThread::enableCancel(false))
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef CTHREAD_H
|
||||
#define CTHREAD_H
|
||||
|
||||
#include "BasicTypes.h"
|
||||
|
||||
class IJob;
|
||||
class CThreadRep;
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#include "CThreadRep.h"
|
||||
#include "CThread.h"
|
||||
#include "CMutex.h"
|
||||
#include "CLock.h"
|
||||
#include "CMutex.h"
|
||||
#include "CThread.h"
|
||||
#include "XThread.h"
|
||||
#include "CLog.h"
|
||||
#include "IJob.h"
|
||||
#include <assert.h>
|
||||
|
||||
#if defined(CONFIG_PTHREADS)
|
||||
#include <signal.h>
|
||||
|
@ -23,7 +22,7 @@
|
|||
class XThreadUnavailable { };
|
||||
|
||||
#if defined(CONFIG_PLATFORM_UNIX) && !defined(NDEBUG)
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
@ -44,7 +43,8 @@ CThreadRep* CThreadRep::s_head = NULL;
|
|||
pthread_t CThreadRep::s_signalThread;
|
||||
#endif
|
||||
|
||||
CThreadRep::CThreadRep() : m_prev(NULL),
|
||||
CThreadRep::CThreadRep() :
|
||||
m_prev(NULL),
|
||||
m_next(NULL),
|
||||
m_refCount(1),
|
||||
m_job(NULL),
|
||||
|
@ -103,15 +103,17 @@ CThreadRep::CThreadRep(IJob* job, void* userData) :
|
|||
pthread_sigmask(SIG_BLOCK, &sigset, &oldsigset);
|
||||
int status = pthread_create(&m_thread, NULL, threadFunc, (void*)this);
|
||||
pthread_sigmask(SIG_SETMASK, &oldsigset, NULL);
|
||||
if (status != 0)
|
||||
if (status != 0) {
|
||||
throw XThreadUnavailable();
|
||||
}
|
||||
#elif defined(CONFIG_PLATFORM_WIN32)
|
||||
unsigned int id;
|
||||
m_thread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0,
|
||||
threadFunc, (void*)this, 0, &id));
|
||||
m_id = static_cast<DWORD>(id);
|
||||
if (m_thread == 0)
|
||||
if (m_thread == 0) {
|
||||
throw XThreadUnavailable();
|
||||
}
|
||||
#endif
|
||||
|
||||
// insert ourself into linked list
|
||||
|
@ -143,7 +145,8 @@ CThreadRep::~CThreadRep()
|
|||
fini();
|
||||
}
|
||||
|
||||
void CThreadRep::initThreads()
|
||||
void
|
||||
CThreadRep::initThreads()
|
||||
{
|
||||
if (s_mutex == NULL) {
|
||||
s_mutex = new CMutex;
|
||||
|
@ -197,13 +200,15 @@ void CThreadRep::initThreads()
|
|||
}
|
||||
}
|
||||
|
||||
void CThreadRep::ref()
|
||||
void
|
||||
CThreadRep::ref()
|
||||
{
|
||||
CLock lock(s_mutex);
|
||||
++m_refCount;
|
||||
}
|
||||
|
||||
void CThreadRep::unref()
|
||||
void
|
||||
CThreadRep::unref()
|
||||
{
|
||||
CLock lock(s_mutex);
|
||||
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);
|
||||
const bool old = m_cancellable;
|
||||
|
@ -219,25 +225,29 @@ bool CThreadRep::enableCancel(bool enable)
|
|||
return old;
|
||||
}
|
||||
|
||||
bool CThreadRep::isCancellable() const
|
||||
bool
|
||||
CThreadRep::isCancellable() const
|
||||
{
|
||||
CLock lock(s_mutex);
|
||||
return (m_cancellable && !m_cancelling);
|
||||
}
|
||||
|
||||
void* CThreadRep::getResult() const
|
||||
void*
|
||||
CThreadRep::getResult() const
|
||||
{
|
||||
// no lock necessary since thread isn't running
|
||||
return m_result;
|
||||
}
|
||||
|
||||
void* CThreadRep::getUserData() const
|
||||
void*
|
||||
CThreadRep::getUserData() const
|
||||
{
|
||||
// no lock necessary because the value never changes
|
||||
return m_userData;
|
||||
}
|
||||
|
||||
CThreadRep* CThreadRep::getCurrentThreadRep()
|
||||
CThreadRep*
|
||||
CThreadRep::getCurrentThreadRep()
|
||||
{
|
||||
assert(s_mutex != NULL);
|
||||
|
||||
|
@ -276,7 +286,8 @@ CThreadRep* CThreadRep::getCurrentThreadRep()
|
|||
return scan;
|
||||
}
|
||||
|
||||
void CThreadRep::doThreadFunc()
|
||||
void
|
||||
CThreadRep::doThreadFunc()
|
||||
{
|
||||
// default priority is slightly below normal
|
||||
setPriority(1);
|
||||
|
@ -318,9 +329,10 @@ void CThreadRep::doThreadFunc()
|
|||
#if defined(CONFIG_PTHREADS)
|
||||
|
||||
#include "CStopwatch.h"
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
void CThreadRep::init()
|
||||
void
|
||||
CThreadRep::init()
|
||||
{
|
||||
m_result = NULL;
|
||||
m_cancellable = true;
|
||||
|
@ -329,7 +341,8 @@ void CThreadRep::init()
|
|||
m_exit = false;
|
||||
}
|
||||
|
||||
void CThreadRep::fini()
|
||||
void
|
||||
CThreadRep::fini()
|
||||
{
|
||||
// main thread has NULL job
|
||||
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;
|
||||
}
|
||||
struct timespec t;
|
||||
t.tv_sec = (long)timeout;
|
||||
t.tv_nsec = (long)(1000000000.0 * (timeout - (double)t.tv_sec));
|
||||
|
@ -348,7 +364,8 @@ void CThreadRep::sleep(double timeout)
|
|||
testCancel();
|
||||
}
|
||||
|
||||
void CThreadRep::cancel()
|
||||
void
|
||||
CThreadRep::cancel()
|
||||
{
|
||||
CLock lock(s_mutex);
|
||||
if (m_cancellable && !m_cancelling) {
|
||||
|
@ -363,14 +380,16 @@ void CThreadRep::cancel()
|
|||
pthread_kill(m_thread, SIGWAKEUP);
|
||||
}
|
||||
|
||||
void CThreadRep::testCancel()
|
||||
void
|
||||
CThreadRep::testCancel()
|
||||
{
|
||||
{
|
||||
CLock lock(s_mutex);
|
||||
|
||||
// done if not cancelled, not cancellable, or already cancelling
|
||||
if (!m_cancel || !m_cancellable || m_cancelling)
|
||||
if (!m_cancel || !m_cancellable || m_cancelling) {
|
||||
return;
|
||||
}
|
||||
|
||||
// update state for cancel
|
||||
m_cancel = false;
|
||||
|
@ -382,40 +401,50 @@ void CThreadRep::testCancel()
|
|||
throw XThreadCancel();
|
||||
}
|
||||
|
||||
bool CThreadRep::wait(CThreadRep* target, double timeout)
|
||||
bool
|
||||
CThreadRep::wait(
|
||||
CThreadRep* target,
|
||||
double timeout)
|
||||
{
|
||||
if (target == this)
|
||||
if (target == this) {
|
||||
return false;
|
||||
}
|
||||
|
||||
testCancel();
|
||||
if (target->isExited())
|
||||
if (target->isExited()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (timeout != 0.0) {
|
||||
CStopwatch timer;
|
||||
do {
|
||||
sleep(0.05);
|
||||
testCancel();
|
||||
if (target->isExited())
|
||||
if (target->isExited()) {
|
||||
return true;
|
||||
}
|
||||
} while (timeout < 0.0 || timer.getTime() <= timeout);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CThreadRep::setPriority(int)
|
||||
void
|
||||
CThreadRep::setPriority(
|
||||
int)
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
|
||||
bool CThreadRep::isExited() const
|
||||
bool
|
||||
CThreadRep::isExited() const
|
||||
{
|
||||
CLock lock(s_mutex);
|
||||
return m_exit;
|
||||
}
|
||||
|
||||
void* CThreadRep::threadFunc(void* arg)
|
||||
void*
|
||||
CThreadRep::threadFunc(void* arg)
|
||||
{
|
||||
CThreadRep* rep = (CThreadRep*)arg;
|
||||
|
||||
|
@ -438,12 +467,16 @@ void* CThreadRep::threadFunc(void* arg)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void CThreadRep::threadCancel(int)
|
||||
void
|
||||
CThreadRep::threadCancel(
|
||||
int)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void* CThreadRep::threadSignalHandler(void* vrep)
|
||||
void*
|
||||
CThreadRep::threadSignalHandler(
|
||||
void* vrep)
|
||||
{
|
||||
CThreadRep* mainThreadRep = reinterpret_cast<CThreadRep*>(vrep);
|
||||
|
||||
|
@ -466,7 +499,8 @@ void* CThreadRep::threadSignalHandler(void* vrep)
|
|||
|
||||
#elif defined(CONFIG_PLATFORM_WIN32)
|
||||
|
||||
void CThreadRep::init()
|
||||
void
|
||||
CThreadRep::init()
|
||||
{
|
||||
m_result = NULL;
|
||||
m_cancellable = true;
|
||||
|
@ -475,7 +509,8 @@ void CThreadRep::init()
|
|||
m_cancel = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
}
|
||||
|
||||
void CThreadRep::fini()
|
||||
void
|
||||
CThreadRep::fini()
|
||||
{
|
||||
// destroy the events
|
||||
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));
|
||||
else
|
||||
}
|
||||
else {
|
||||
Sleep((DWORD)(1000.0 * timeout));
|
||||
}
|
||||
}
|
||||
|
||||
void CThreadRep::cancel()
|
||||
void
|
||||
CThreadRep::cancel()
|
||||
{
|
||||
log((CLOG_DEBUG1 "cancel thread %p", this));
|
||||
SetEvent(m_cancel);
|
||||
}
|
||||
|
||||
void CThreadRep::testCancel()
|
||||
void
|
||||
CThreadRep::testCancel()
|
||||
{
|
||||
// poll cancel event. return if not set.
|
||||
const DWORD result = WaitForSingleObject(getCancelEvent(), 0);
|
||||
if (result != WAIT_OBJECT_0)
|
||||
if (result != WAIT_OBJECT_0) {
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
// ignore if disabled or already cancelling
|
||||
|
@ -524,23 +566,29 @@ void CThreadRep::testCancel()
|
|||
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
|
||||
// then the thread is waiting on itself.
|
||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||
if (target == this)
|
||||
if (target == this) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// is cancellation enabled?
|
||||
const DWORD n = (isCancellable() ? 2 : 1);
|
||||
|
||||
// convert timeout
|
||||
DWORD t;
|
||||
if (timeout < 0.0)
|
||||
if (timeout < 0.0) {
|
||||
t = INFINITE;
|
||||
else
|
||||
}
|
||||
else {
|
||||
t = (DWORD)(1000.0 * timeout);
|
||||
}
|
||||
|
||||
// wait for this thread to be cancelled or for the target thread to
|
||||
// terminate.
|
||||
|
@ -551,8 +599,9 @@ bool CThreadRep::wait(CThreadRep* target, double timeout)
|
|||
|
||||
// cancel takes priority
|
||||
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;
|
||||
}
|
||||
|
||||
// handle 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;
|
||||
if (n < 0) {
|
||||
|
@ -601,19 +652,23 @@ void CThreadRep::setPriority(int n)
|
|||
SetThreadPriority(m_thread, n);
|
||||
}
|
||||
|
||||
HANDLE CThreadRep::getExitEvent() const
|
||||
HANDLE
|
||||
CThreadRep::getExitEvent() const
|
||||
{
|
||||
// no lock necessary because the value never changes
|
||||
return m_exit;
|
||||
}
|
||||
|
||||
HANDLE CThreadRep::getCancelEvent() const
|
||||
HANDLE
|
||||
CThreadRep::getCancelEvent() const
|
||||
{
|
||||
// no lock necessary because the value never changes
|
||||
return m_cancel;
|
||||
}
|
||||
|
||||
unsigned int __stdcall CThreadRep::threadFunc(void* arg)
|
||||
unsigned int __stdcall
|
||||
CThreadRep::threadFunc(
|
||||
void* arg)
|
||||
{
|
||||
CThreadRep* rep = (CThreadRep*)arg;
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "CThread.h"
|
||||
#include "TMethodJob.h"
|
||||
#include "CLog.h"
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CTimerThread
|
||||
|
@ -33,7 +32,9 @@ CTimerThread::~CTimerThread()
|
|||
}
|
||||
}
|
||||
|
||||
void CTimerThread::timer(void*)
|
||||
void
|
||||
CTimerThread::timer(
|
||||
void*)
|
||||
{
|
||||
log((CLOG_DEBUG1 "timeout in %f seconds", m_timeout));
|
||||
CThread::sleep(m_timeout);
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef CTIMERTHREAD_H
|
||||
#define CTIMERTHREAD_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
class CThread;
|
||||
|
||||
class CTimerThread {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef XTHREAD_H
|
||||
#define XTHREAD_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
// generic thread exception
|
||||
class XThread { };
|
||||
|
||||
|
|
127
net/CNetwork.cpp
127
net/CNetwork.cpp
|
@ -1,7 +1,6 @@
|
|||
#include "CNetwork.h"
|
||||
#include "XNetwork.h"
|
||||
#include "CLog.h"
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CNetwork
|
||||
|
@ -51,15 +50,21 @@ const CNetwork::Socket CNetwork::Null = INVALID_SOCKET;
|
|||
|
||||
static HMODULE s_networkModule = NULL;
|
||||
|
||||
static FARPROC netGetProcAddress(HMODULE module, LPCSTR name)
|
||||
static
|
||||
FARPROC
|
||||
netGetProcAddress(
|
||||
HMODULE module,
|
||||
LPCSTR name)
|
||||
{
|
||||
FARPROC func = ::GetProcAddress(module, name);
|
||||
if (!func)
|
||||
if (!func) {
|
||||
throw XNetworkFunctionUnavailable(name);
|
||||
}
|
||||
return func;
|
||||
}
|
||||
|
||||
void CNetwork::init()
|
||||
void
|
||||
CNetwork::init()
|
||||
{
|
||||
assert(WSACleanup == NULL);
|
||||
assert(s_networkModule == NULL);
|
||||
|
@ -98,7 +103,8 @@ void CNetwork::init()
|
|||
throw XNetworkUnavailable();
|
||||
}
|
||||
|
||||
void CNetwork::cleanup()
|
||||
void
|
||||
CNetwork::cleanup()
|
||||
{
|
||||
if (s_networkModule != NULL) {
|
||||
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 };
|
||||
if (s_endian.b[0] == 0x34)
|
||||
if (s_endian.b[0] == 0x34) {
|
||||
return ((v & 0xff000000lu) >> 24) |
|
||||
((v & 0x00ff0000lu) >> 8) |
|
||||
((v & 0x0000ff00lu) << 8) |
|
||||
((v & 0x000000fflu) << 24);
|
||||
else
|
||||
}
|
||||
else {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
UInt16 CNetwork::swaphtons(UInt16 v)
|
||||
UInt16
|
||||
CNetwork::swaphtons(
|
||||
UInt16 v)
|
||||
{
|
||||
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) |
|
||||
((v & 0x00ffu) << 8));
|
||||
else
|
||||
}
|
||||
else {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 CNetwork::swapntohl(UInt32 v)
|
||||
UInt32
|
||||
CNetwork::swapntohl(
|
||||
UInt32 v)
|
||||
{
|
||||
return swaphtonl(v);
|
||||
}
|
||||
|
||||
UInt16 CNetwork::swapntohs(UInt16 v)
|
||||
UInt16
|
||||
CNetwork::swapntohs(
|
||||
UInt16 v)
|
||||
{
|
||||
return swaphtons(v);
|
||||
}
|
||||
|
||||
#define setfunc(var, name, type) var = (type)netGetProcAddress(module, #name)
|
||||
|
||||
void CNetwork::init2(HMODULE module)
|
||||
void
|
||||
CNetwork::init2(
|
||||
HMODULE module)
|
||||
{
|
||||
assert(module != NULL);
|
||||
|
||||
|
@ -155,10 +175,12 @@ void CNetwork::init2(HMODULE module)
|
|||
WORD version = MAKEWORD(1 /*major*/, 1 /*minor*/);
|
||||
WSADATA data;
|
||||
int err = startup(version, &data);
|
||||
if (data.wVersion != version)
|
||||
if (data.wVersion != version) {
|
||||
throw XNetworkVersion(LOBYTE(data.wVersion), HIBYTE(data.wVersion));
|
||||
if (err != 0)
|
||||
}
|
||||
if (err != 0) {
|
||||
throw XNetworkFailed();
|
||||
}
|
||||
|
||||
// get function addresses
|
||||
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;
|
||||
}
|
||||
|
||||
int PASCAL FAR CNetwork::poll2(PollEntry fd[], int nfds, int timeout)
|
||||
int PASCAL FAR
|
||||
CNetwork::poll2(
|
||||
PollEntry fd[],
|
||||
int nfds,
|
||||
int timeout)
|
||||
{
|
||||
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);
|
||||
|
||||
// handle results
|
||||
if (n == Error)
|
||||
if (n == Error) {
|
||||
return Error;
|
||||
if (n == 0)
|
||||
}
|
||||
if (n == 0) {
|
||||
return 0;
|
||||
}
|
||||
n = 0;
|
||||
for (i = 0; i < nfds; ++i) {
|
||||
fd[i].revents = 0;
|
||||
if (FD_ISSET(fd[i].fd, &readSet))
|
||||
if (FD_ISSET(fd[i].fd, &readSet)) {
|
||||
fd[i].revents |= kPOLLIN;
|
||||
if (FD_ISSET(fd[i].fd, &writeSet))
|
||||
}
|
||||
if (FD_ISSET(fd[i].fd, &writeSet)) {
|
||||
fd[i].revents |= kPOLLOUT;
|
||||
if (FD_ISSET(fd[i].fd, &errSet))
|
||||
}
|
||||
if (FD_ISSET(fd[i].fd, &errSet)) {
|
||||
fd[i].revents |= kPOLLERR;
|
||||
if (fd[i].revents != 0)
|
||||
}
|
||||
if (fd[i].revents != 0) {
|
||||
++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);
|
||||
}
|
||||
|
||||
ssize_t PASCAL FAR CNetwork::write2(Socket s,
|
||||
const void FAR * buf, size_t len)
|
||||
ssize_t PASCAL FAR
|
||||
CNetwork::write2(
|
||||
Socket s,
|
||||
const void FAR* buf,
|
||||
size_t len)
|
||||
{
|
||||
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
|
||||
|
||||
UInt32 CNetwork::swaphtonl(UInt32 v)
|
||||
UInt32
|
||||
CNetwork::swaphtonl(
|
||||
UInt32 v)
|
||||
{
|
||||
return htonl(v);
|
||||
}
|
||||
|
||||
UInt16 CNetwork::swaphtons(UInt16 v)
|
||||
UInt16
|
||||
CNetwork::swaphtons(
|
||||
UInt16 v)
|
||||
{
|
||||
return htons(v);
|
||||
}
|
||||
|
||||
UInt32 CNetwork::swapntohl(UInt32 v)
|
||||
UInt32
|
||||
CNetwork::swapntohl(
|
||||
UInt32 v)
|
||||
{
|
||||
return ntohl(v);
|
||||
}
|
||||
|
||||
UInt16 CNetwork::swapntohs(UInt16 v)
|
||||
UInt16
|
||||
CNetwork::swapntohs(
|
||||
UInt16 v)
|
||||
{
|
||||
return ntohs(v);
|
||||
}
|
||||
|
||||
static int myerrno()
|
||||
static
|
||||
int
|
||||
myerrno()
|
||||
{
|
||||
return errno;
|
||||
}
|
||||
|
||||
static int myherrno()
|
||||
static
|
||||
int
|
||||
myherrno()
|
||||
{
|
||||
return h_errno;
|
||||
}
|
||||
|
||||
static int mygethostname(char* name, int namelen)
|
||||
static
|
||||
int
|
||||
mygethostname(
|
||||
char* name,
|
||||
int namelen)
|
||||
{
|
||||
return gethostname(name, namelen);
|
||||
}
|
||||
|
@ -321,7 +376,8 @@ static int mygethostname(char* name, int namelen)
|
|||
const int CNetwork::Error = -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(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));
|
||||
}
|
||||
|
||||
void CNetwork::cleanup()
|
||||
void
|
||||
CNetwork::cleanup()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
#include "CNetworkAddress.h"
|
||||
#include "CString.h"
|
||||
#include <stdlib.h>
|
||||
#include "XSocket.h"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
//
|
||||
// CNetworkAddress
|
||||
//
|
||||
|
||||
CNetworkAddress::CNetworkAddress() : m_port(0)
|
||||
CNetworkAddress::CNetworkAddress() :
|
||||
m_port(0)
|
||||
{
|
||||
// note -- make no calls to CNetwork socket interface here;
|
||||
// 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));
|
||||
}
|
||||
|
||||
CNetworkAddress::CNetworkAddress(UInt16 port) : m_port(port)
|
||||
CNetworkAddress::CNetworkAddress(
|
||||
UInt16 port) :
|
||||
m_port(port)
|
||||
{
|
||||
if (port == 0) {
|
||||
throw XSocketAddress(XSocketAddress::kBadPort, m_hostname, m_port);
|
||||
|
@ -33,7 +37,9 @@ CNetworkAddress::CNetworkAddress(UInt16 port) : m_port(port)
|
|||
memset(inetAddress->sin_zero, 0, sizeof(inetAddress->sin_zero));
|
||||
}
|
||||
|
||||
CNetworkAddress::CNetworkAddress(const CString& hostname_, UInt16 port) :
|
||||
CNetworkAddress::CNetworkAddress(
|
||||
const CString& hostname_,
|
||||
UInt16 port) :
|
||||
m_hostname(hostname_),
|
||||
m_port(port)
|
||||
{
|
||||
|
@ -126,27 +132,32 @@ CNetworkAddress::~CNetworkAddress()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
bool CNetworkAddress::isValid() const
|
||||
bool
|
||||
CNetworkAddress::isValid() const
|
||||
{
|
||||
return (m_port != 0);
|
||||
}
|
||||
|
||||
const CNetwork::Address* CNetworkAddress::getAddress() const
|
||||
const CNetwork::Address*
|
||||
CNetworkAddress::getAddress() const
|
||||
{
|
||||
return &m_address;
|
||||
}
|
||||
|
||||
CNetwork::AddressLength CNetworkAddress::getAddressLength() const
|
||||
CNetwork::AddressLength
|
||||
CNetworkAddress::getAddressLength() const
|
||||
{
|
||||
return sizeof(m_address);
|
||||
}
|
||||
|
||||
CString CNetworkAddress::getHostname() const
|
||||
CString
|
||||
CNetworkAddress::getHostname() const
|
||||
{
|
||||
return m_hostname;
|
||||
}
|
||||
|
||||
UInt16 CNetworkAddress::getPort() const
|
||||
UInt16
|
||||
CNetworkAddress::getPort() const
|
||||
{
|
||||
return m_port;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define CNETWORKADDRESS_H
|
||||
|
||||
#include "CNetwork.h"
|
||||
#include "XSocket.h"
|
||||
#include "CString.h"
|
||||
#include "BasicTypes.h"
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "CTCPListenSocket.h"
|
||||
#include "CTCPSocket.h"
|
||||
#include "CNetworkAddress.h"
|
||||
#include "XIO.h"
|
||||
#include "XSocket.h"
|
||||
#include "CThread.h"
|
||||
|
||||
//
|
||||
|
@ -25,7 +27,8 @@ CTCPListenSocket::~CTCPListenSocket()
|
|||
}
|
||||
}
|
||||
|
||||
void CTCPListenSocket::bind(
|
||||
void
|
||||
CTCPListenSocket::bind(
|
||||
const CNetworkAddress& addr)
|
||||
{
|
||||
if (CNetwork::bind(m_fd, addr.getAddress(),
|
||||
|
@ -40,7 +43,8 @@ void CTCPListenSocket::bind(
|
|||
}
|
||||
}
|
||||
|
||||
ISocket* CTCPListenSocket::accept()
|
||||
ISocket*
|
||||
CTCPListenSocket::accept()
|
||||
{
|
||||
CNetwork::PollEntry pfds[1];
|
||||
pfds[0].fd = m_fd;
|
||||
|
@ -59,7 +63,8 @@ ISocket* CTCPListenSocket::accept()
|
|||
}
|
||||
}
|
||||
|
||||
void CTCPListenSocket::close()
|
||||
void
|
||||
CTCPListenSocket::close()
|
||||
{
|
||||
if (m_fd == CNetwork::Null) {
|
||||
throw XIOClosed();
|
||||
|
|
|
@ -2,13 +2,14 @@
|
|||
#include "CBufferedInputStream.h"
|
||||
#include "CBufferedOutputStream.h"
|
||||
#include "CNetworkAddress.h"
|
||||
#include "XIO.h"
|
||||
#include "XSocket.h"
|
||||
#include "CCondVar.h"
|
||||
#include "CLock.h"
|
||||
#include "CMutex.h"
|
||||
#include "CCondVar.h"
|
||||
#include "CThread.h"
|
||||
#include "TMethodJob.h"
|
||||
#include "CStopwatch.h"
|
||||
#include <assert.h>
|
||||
#include "TMethodJob.h"
|
||||
|
||||
//
|
||||
// CTCPSocket
|
||||
|
@ -23,7 +24,8 @@ CTCPSocket::CTCPSocket()
|
|||
init();
|
||||
}
|
||||
|
||||
CTCPSocket::CTCPSocket(CNetwork::Socket fd) : m_fd(fd)
|
||||
CTCPSocket::CTCPSocket(CNetwork::Socket fd) :
|
||||
m_fd(fd)
|
||||
{
|
||||
assert(m_fd != CNetwork::Null);
|
||||
|
||||
|
@ -52,7 +54,9 @@ CTCPSocket::~CTCPSocket()
|
|||
delete m_mutex;
|
||||
}
|
||||
|
||||
void CTCPSocket::bind(const CNetworkAddress& addr)
|
||||
void
|
||||
CTCPSocket::bind(
|
||||
const CNetworkAddress& addr)
|
||||
{
|
||||
if (CNetwork::bind(m_fd, addr.getAddress(),
|
||||
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();
|
||||
if (CNetwork::connect(m_fd, addr.getAddress(),
|
||||
|
@ -78,7 +84,8 @@ void CTCPSocket::connect(const CNetworkAddress& addr)
|
|||
this, &CTCPSocket::ioThread));
|
||||
}
|
||||
|
||||
void CTCPSocket::close()
|
||||
void
|
||||
CTCPSocket::close()
|
||||
{
|
||||
// see if buffers should be flushed
|
||||
bool doFlush = false;
|
||||
|
@ -117,17 +124,20 @@ void CTCPSocket::close()
|
|||
}
|
||||
}
|
||||
|
||||
IInputStream* CTCPSocket::getInputStream()
|
||||
IInputStream*
|
||||
CTCPSocket::getInputStream()
|
||||
{
|
||||
return m_input;
|
||||
}
|
||||
|
||||
IOutputStream* CTCPSocket::getOutputStream()
|
||||
IOutputStream*
|
||||
CTCPSocket::getOutputStream()
|
||||
{
|
||||
return m_output;
|
||||
}
|
||||
|
||||
void CTCPSocket::init()
|
||||
void
|
||||
CTCPSocket::init()
|
||||
{
|
||||
m_mutex = new CMutex;
|
||||
m_thread = NULL;
|
||||
|
@ -146,7 +156,8 @@ void CTCPSocket::init()
|
|||
CNetwork::setsockopt(m_fd, SOL_TCP, TCP_NODELAY, &flag, sizeof(flag));
|
||||
}
|
||||
|
||||
void CTCPSocket::ioThread(void*)
|
||||
void
|
||||
CTCPSocket::ioThread(void*)
|
||||
{
|
||||
try {
|
||||
ioService();
|
||||
|
@ -158,7 +169,8 @@ void CTCPSocket::ioThread(void*)
|
|||
}
|
||||
}
|
||||
|
||||
void CTCPSocket::ioCleanup()
|
||||
void
|
||||
CTCPSocket::ioCleanup()
|
||||
{
|
||||
try {
|
||||
m_input->close();
|
||||
|
@ -174,7 +186,8 @@ void CTCPSocket::ioCleanup()
|
|||
}
|
||||
}
|
||||
|
||||
void CTCPSocket::ioService()
|
||||
void
|
||||
CTCPSocket::ioService()
|
||||
{
|
||||
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
|
||||
CNetwork::shutdown(m_fd, 0);
|
||||
m_connected &= ~kRead;
|
||||
}
|
||||
|
||||
void CTCPSocket::closeOutput(void*)
|
||||
void
|
||||
CTCPSocket::closeOutput(void*)
|
||||
{
|
||||
// note -- m_mutex should already be locked
|
||||
CNetwork::shutdown(m_fd, 1);
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "ISocket.h"
|
||||
#include "CNetwork.h"
|
||||
#include "XThread.h"
|
||||
|
||||
class CMutex;
|
||||
template <class T>
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#define ILISTENSOCKET_H
|
||||
|
||||
#include "IInterface.h"
|
||||
#include "XIO.h"
|
||||
#include "XSocket.h"
|
||||
|
||||
class CNetworkAddress;
|
||||
class ISocket;
|
||||
|
|
|
@ -2,9 +2,6 @@
|
|||
#define ISOCKET_H
|
||||
|
||||
#include "IInterface.h"
|
||||
#include "BasicTypes.h"
|
||||
#include "XSocket.h"
|
||||
#include "XIO.h"
|
||||
|
||||
class CNetworkAddress;
|
||||
class IInputStream;
|
||||
|
|
|
@ -19,6 +19,7 @@ CXXFILES = \
|
|||
CNetworkAddress.cpp \
|
||||
CTCPSocket.cpp \
|
||||
CTCPListenSocket.cpp \
|
||||
XNetwork.cpp \
|
||||
XSocket.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
// XNetworkUnavailable
|
||||
//
|
||||
|
||||
CString XNetworkUnavailable::getWhat() const throw()
|
||||
CString
|
||||
XNetworkUnavailable::getWhat() const throw()
|
||||
{
|
||||
return format("XNetworkUnavailable", "network library is not available");
|
||||
}
|
||||
|
@ -14,7 +15,8 @@ CString XNetworkUnavailable::getWhat() const throw()
|
|||
// XNetworkFailed
|
||||
//
|
||||
|
||||
CString XNetworkFailed::getWhat() const throw()
|
||||
CString
|
||||
XNetworkFailed::getWhat() const throw()
|
||||
{
|
||||
return format("XNetworkFailed", "cannot initialize network library");
|
||||
}
|
||||
|
@ -24,24 +26,29 @@ CString XNetworkFailed::getWhat() const throw()
|
|||
// XNetworkVersion
|
||||
//
|
||||
|
||||
XNetworkVersion::XNetworkVersion(int major, int minor) throw() :
|
||||
XNetworkVersion::XNetworkVersion(
|
||||
int major,
|
||||
int minor) throw() :
|
||||
m_major(major),
|
||||
m_minor(minor)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
int XNetworkVersion::getMajor() const throw()
|
||||
int
|
||||
XNetworkVersion::getMajor() const throw()
|
||||
{
|
||||
return m_major;
|
||||
}
|
||||
|
||||
int XNetworkVersion::getMinor() const throw()
|
||||
int
|
||||
XNetworkVersion::getMinor() const throw()
|
||||
{
|
||||
return m_minor;
|
||||
}
|
||||
|
||||
CString XNetworkVersion::getWhat() const throw()
|
||||
CString
|
||||
XNetworkVersion::getWhat() const throw()
|
||||
{
|
||||
return format("XNetworkVersion",
|
||||
"unsupported network version %d.%d",
|
||||
|
@ -64,7 +71,8 @@ XNetworkFunctionUnavailable::XNetworkFunctionUnavailable(
|
|||
}
|
||||
}
|
||||
|
||||
CString XNetworkFunctionUnavailable::getWhat() const throw()
|
||||
CString
|
||||
XNetworkFunctionUnavailable::getWhat() const throw()
|
||||
{
|
||||
return format("XNetworkFunctionUnavailable",
|
||||
"missing network function %s",
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
#ifndef XNETWORK_H
|
||||
#define XNETWORK_H
|
||||
|
||||
#include "CString.h"
|
||||
#include "XBase.h"
|
||||
#include "BasicTypes.h"
|
||||
#include "CString.h"
|
||||
|
||||
class XNetwork : public XBase { };
|
||||
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
// XSocketAddress
|
||||
//
|
||||
|
||||
XSocketAddress::XSocketAddress(Error error,
|
||||
const CString& hostname, UInt16 port) throw() :
|
||||
XSocketAddress::XSocketAddress(
|
||||
Error error,
|
||||
const CString& hostname,
|
||||
UInt16 port) throw() :
|
||||
m_error(error),
|
||||
m_hostname(hostname),
|
||||
m_port(port)
|
||||
|
@ -13,22 +15,26 @@ XSocketAddress::XSocketAddress(Error error,
|
|||
// do nothing
|
||||
}
|
||||
|
||||
XSocketAddress::Error XSocketAddress::getError() const throw()
|
||||
XSocketAddress::Error
|
||||
XSocketAddress::getError() const throw()
|
||||
{
|
||||
return m_error;
|
||||
}
|
||||
|
||||
CString XSocketAddress::getHostname() const throw()
|
||||
CString
|
||||
XSocketAddress::getHostname() const throw()
|
||||
{
|
||||
return m_hostname;
|
||||
}
|
||||
|
||||
UInt16 XSocketAddress::getPort() const throw()
|
||||
UInt16
|
||||
XSocketAddress::getPort() const throw()
|
||||
{
|
||||
return m_port;
|
||||
}
|
||||
|
||||
CString XSocketAddress::getWhat() const throw()
|
||||
CString
|
||||
XSocketAddress::getWhat() const throw()
|
||||
{
|
||||
return "no address";
|
||||
/*
|
||||
|
@ -43,12 +49,15 @@ CString XSocketAddress::getWhat() const throw()
|
|||
// XSocketErrno
|
||||
//
|
||||
|
||||
XSocketErrno::XSocketErrno() : MXErrno()
|
||||
XSocketErrno::XSocketErrno() :
|
||||
MXErrno()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
XSocketErrno::XSocketErrno(int err) : MXErrno(err)
|
||||
XSocketErrno::XSocketErrno(
|
||||
int err) :
|
||||
MXErrno(err)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
@ -58,7 +67,8 @@ XSocketErrno::XSocketErrno(int err) : MXErrno(err)
|
|||
// XSocketBind
|
||||
//
|
||||
|
||||
CString XSocketBind::getWhat() const throw()
|
||||
CString
|
||||
XSocketBind::getWhat() const throw()
|
||||
{
|
||||
return format("XSocketBind", "cannot bind address");
|
||||
}
|
||||
|
@ -68,7 +78,8 @@ CString XSocketBind::getWhat() const throw()
|
|||
// XSocketConnect
|
||||
//
|
||||
|
||||
CString XSocketConnect::getWhat() const throw()
|
||||
CString
|
||||
XSocketConnect::getWhat() const throw()
|
||||
{
|
||||
return format("XSocketConnect", "cannot connect socket");
|
||||
}
|
||||
|
@ -78,7 +89,8 @@ CString XSocketConnect::getWhat() const throw()
|
|||
// XSocketCreate
|
||||
//
|
||||
|
||||
CString XSocketCreate::getWhat() const throw()
|
||||
CString
|
||||
XSocketCreate::getWhat() const throw()
|
||||
{
|
||||
return format("XSocketCreate", "cannot create socket");
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef XSOCKET_H
|
||||
#define XSOCKET_H
|
||||
|
||||
#include "CString.h"
|
||||
#include "XBase.h"
|
||||
#include "CString.h"
|
||||
#include "BasicTypes.h"
|
||||
|
||||
class XSocket : public XBase { };
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#include "CMSWindowsClipboard.h"
|
||||
#include "CString.h"
|
||||
#include "CLog.h"
|
||||
|
||||
//
|
||||
// CMSWindowsClipboard
|
||||
//
|
||||
|
||||
CMSWindowsClipboard::CMSWindowsClipboard(HWND window) :
|
||||
CMSWindowsClipboard::CMSWindowsClipboard(
|
||||
HWND window) :
|
||||
m_window(window),
|
||||
m_time(0)
|
||||
{
|
||||
|
@ -18,7 +18,8 @@ CMSWindowsClipboard::~CMSWindowsClipboard()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
bool CMSWindowsClipboard::empty()
|
||||
bool
|
||||
CMSWindowsClipboard::empty()
|
||||
{
|
||||
log((CLOG_DEBUG "empty clipboard"));
|
||||
|
||||
|
@ -30,8 +31,10 @@ bool CMSWindowsClipboard::empty()
|
|||
return true;
|
||||
}
|
||||
|
||||
void CMSWindowsClipboard::add(
|
||||
EFormat format, const CString& data)
|
||||
void
|
||||
CMSWindowsClipboard::add(
|
||||
EFormat format,
|
||||
const CString& data)
|
||||
{
|
||||
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"));
|
||||
|
||||
|
@ -68,29 +73,36 @@ bool CMSWindowsClipboard::open(Time time) const
|
|||
return true;
|
||||
}
|
||||
|
||||
void CMSWindowsClipboard::close() const
|
||||
void
|
||||
CMSWindowsClipboard::close() const
|
||||
{
|
||||
log((CLOG_DEBUG "close clipboard"));
|
||||
CloseClipboard();
|
||||
}
|
||||
|
||||
IClipboard::Time CMSWindowsClipboard::getTime() const
|
||||
IClipboard::Time
|
||||
CMSWindowsClipboard::getTime() const
|
||||
{
|
||||
return m_time;
|
||||
}
|
||||
|
||||
bool CMSWindowsClipboard::has(EFormat format) const
|
||||
bool
|
||||
CMSWindowsClipboard::has(
|
||||
EFormat format) const
|
||||
{
|
||||
const UINT win32Format = convertFormatToWin32(format);
|
||||
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.
|
||||
const UINT win32Format = convertFormatToWin32(format);
|
||||
if (win32Format == 0)
|
||||
if (win32Format == 0) {
|
||||
return CString();
|
||||
}
|
||||
|
||||
// get a handle to the clipboard data and convert it
|
||||
HANDLE win32Data = GetClipboardData(win32Format);
|
||||
|
@ -106,7 +118,8 @@ CString CMSWindowsClipboard::get(EFormat format) const
|
|||
return data;
|
||||
}
|
||||
|
||||
UINT CMSWindowsClipboard::convertFormatToWin32(
|
||||
UINT
|
||||
CMSWindowsClipboard::convertFormatToWin32(
|
||||
EFormat format) const
|
||||
{
|
||||
switch (format) {
|
||||
|
@ -118,7 +131,8 @@ UINT CMSWindowsClipboard::convertFormatToWin32(
|
|||
}
|
||||
}
|
||||
|
||||
HANDLE CMSWindowsClipboard::convertTextToWin32(
|
||||
HANDLE
|
||||
CMSWindowsClipboard::convertTextToWin32(
|
||||
const CString& data) const
|
||||
{
|
||||
// compute size of converted text
|
||||
|
@ -157,14 +171,16 @@ HANDLE CMSWindowsClipboard::convertTextToWin32(
|
|||
return gData;
|
||||
}
|
||||
|
||||
CString CMSWindowsClipboard::convertTextFromWin32(
|
||||
CString
|
||||
CMSWindowsClipboard::convertTextFromWin32(
|
||||
HANDLE handle) const
|
||||
{
|
||||
// get source data and it's size
|
||||
const char* src = (const char*)GlobalLock(handle);
|
||||
UInt32 srcSize = (SInt32)GlobalSize(handle);
|
||||
if (src == NULL || srcSize <= 1)
|
||||
if (src == NULL || srcSize <= 1) {
|
||||
return CString();
|
||||
}
|
||||
|
||||
// ignore trailing NUL
|
||||
--srcSize;
|
||||
|
@ -175,9 +191,10 @@ CString CMSWindowsClipboard::convertTextFromWin32(
|
|||
for (index = 0; index < srcSize; ++index) {
|
||||
if (src[index] == '\r') {
|
||||
// skip \r
|
||||
if (index + 1 < srcSize && src[index + 1] == '\n')
|
||||
if (index + 1 < srcSize && src[index + 1] == '\n') {
|
||||
++index;
|
||||
}
|
||||
}
|
||||
++dstSize;
|
||||
}
|
||||
|
||||
|
@ -189,9 +206,10 @@ CString CMSWindowsClipboard::convertTextFromWin32(
|
|||
for (index = 0; index < srcSize; ++index) {
|
||||
if (src[index] == '\r') {
|
||||
// skip \r
|
||||
if (index + 1 < srcSize && src[index + 1] == '\n')
|
||||
if (index + 1 < srcSize && src[index + 1] == '\n') {
|
||||
++index;
|
||||
}
|
||||
}
|
||||
data += src[index];
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
#include "TMethodJob.h"
|
||||
#include "CLog.h"
|
||||
#include "CString.h"
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <cstring>
|
||||
|
||||
//
|
||||
// CMSWindowsScreen
|
||||
|
@ -30,12 +29,15 @@ CMSWindowsScreen::~CMSWindowsScreen()
|
|||
s_screen = NULL;
|
||||
}
|
||||
|
||||
void CMSWindowsScreen::init(HINSTANCE instance)
|
||||
void
|
||||
CMSWindowsScreen::init(
|
||||
HINSTANCE instance)
|
||||
{
|
||||
s_instance = instance;
|
||||
}
|
||||
|
||||
void CMSWindowsScreen::doRun()
|
||||
void
|
||||
CMSWindowsScreen::doRun()
|
||||
{
|
||||
// save thread id for posting quit message
|
||||
m_thread = GetCurrentThreadId();
|
||||
|
@ -59,12 +61,14 @@ void CMSWindowsScreen::doRun()
|
|||
}
|
||||
}
|
||||
|
||||
void CMSWindowsScreen::doStop()
|
||||
void
|
||||
CMSWindowsScreen::doStop()
|
||||
{
|
||||
PostThreadMessage(m_thread, WM_QUIT, 0, 0);
|
||||
}
|
||||
|
||||
void CMSWindowsScreen::openDisplay()
|
||||
void
|
||||
CMSWindowsScreen::openDisplay()
|
||||
{
|
||||
assert(s_instance != NULL);
|
||||
assert(m_class == 0);
|
||||
|
@ -106,7 +110,8 @@ void CMSWindowsScreen::openDisplay()
|
|||
onOpenDisplay();
|
||||
}
|
||||
|
||||
void CMSWindowsScreen::closeDisplay()
|
||||
void
|
||||
CMSWindowsScreen::closeDisplay()
|
||||
{
|
||||
assert(s_instance != NULL);
|
||||
assert(m_class != 0);
|
||||
|
@ -125,25 +130,30 @@ void CMSWindowsScreen::closeDisplay()
|
|||
log((CLOG_DEBUG "closed display"));
|
||||
}
|
||||
|
||||
HINSTANCE CMSWindowsScreen::getInstance()
|
||||
HINSTANCE
|
||||
CMSWindowsScreen::getInstance()
|
||||
{
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
ATOM CMSWindowsScreen::getClass() const
|
||||
ATOM
|
||||
CMSWindowsScreen::getClass() const
|
||||
{
|
||||
return m_class;
|
||||
}
|
||||
|
||||
void CMSWindowsScreen::updateScreenSize()
|
||||
void
|
||||
CMSWindowsScreen::updateScreenSize()
|
||||
{
|
||||
m_w = GetSystemMetrics(SM_CXSCREEN);
|
||||
m_h = GetSystemMetrics(SM_CYSCREEN);
|
||||
log((CLOG_INFO "display resize: %dx%d", m_w, m_h));
|
||||
}
|
||||
|
||||
void CMSWindowsScreen::getScreenSize(
|
||||
SInt32* w, SInt32* h) const
|
||||
void
|
||||
CMSWindowsScreen::getScreenSize(
|
||||
SInt32* w,
|
||||
SInt32* h) const
|
||||
{
|
||||
assert(m_class != 0);
|
||||
assert(w != NULL && h != NULL);
|
||||
|
@ -152,7 +162,8 @@ void CMSWindowsScreen::getScreenSize(
|
|||
*h = m_h;
|
||||
}
|
||||
|
||||
HDESK CMSWindowsScreen::openInputDesktop() const
|
||||
HDESK
|
||||
CMSWindowsScreen::openInputDesktop() const
|
||||
{
|
||||
return OpenInputDesktop(DF_ALLOWOTHERACCOUNTHOOK, TRUE,
|
||||
DESKTOP_CREATEWINDOW |
|
||||
|
@ -160,7 +171,8 @@ HDESK CMSWindowsScreen::openInputDesktop() const
|
|||
GENERIC_WRITE);
|
||||
}
|
||||
|
||||
CString CMSWindowsScreen::getDesktopName(
|
||||
CString
|
||||
CMSWindowsScreen::getDesktopName(
|
||||
HDESK desk) const
|
||||
{
|
||||
if (desk == NULL) {
|
||||
|
@ -177,14 +189,17 @@ CString CMSWindowsScreen::getDesktopName(
|
|||
}
|
||||
}
|
||||
|
||||
bool CMSWindowsScreen::isCurrentDesktop(
|
||||
bool
|
||||
CMSWindowsScreen::isCurrentDesktop(
|
||||
HDESK desk) const
|
||||
{
|
||||
return CStringUtil::CaselessCmp::equal(getDesktopName(desk),
|
||||
getCurrentDesktopName());
|
||||
}
|
||||
|
||||
void CMSWindowsScreen::getEvent(MSG* msg) const
|
||||
void
|
||||
CMSWindowsScreen::getEvent(
|
||||
MSG* msg) const
|
||||
{
|
||||
// wait for an event in a cancellable way
|
||||
while (HIWORD(GetQueueStatus(QS_ALLINPUT)) == 0) {
|
||||
|
@ -193,9 +208,12 @@ void CMSWindowsScreen::getEvent(MSG* msg) const
|
|||
GetMessage(msg, NULL, 0, 0);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK CMSWindowsScreen::wndProc(
|
||||
HWND hwnd, UINT msg,
|
||||
WPARAM wParam, LPARAM lParam)
|
||||
LRESULT CALLBACK
|
||||
CMSWindowsScreen::wndProc(
|
||||
HWND hwnd,
|
||||
UINT msg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
assert(s_screen != NULL);
|
||||
return s_screen->onEvent(hwnd, msg, wParam, lParam);
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
#ifndef CMSWINDOWSSCREEN_H
|
||||
#define CMSWINDOWSSCREEN_H
|
||||
|
||||
#include "CMutex.h"
|
||||
#include "IClipboard.h"
|
||||
#include "BasicTypes.h"
|
||||
#include "CMutex.h"
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "CUnixPlatform.h"
|
||||
#include "CLog.h"
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -9,7 +9,6 @@
|
|||
#include <fcntl.h>
|
||||
#include <syslog.h>
|
||||
|
||||
|
||||
//
|
||||
// CUnixPlatform
|
||||
//
|
||||
|
@ -24,7 +23,8 @@ CUnixPlatform::~CUnixPlatform()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
bool CUnixPlatform::installDaemon(
|
||||
bool
|
||||
CUnixPlatform::installDaemon(
|
||||
const char*,
|
||||
const char*,
|
||||
const char*,
|
||||
|
@ -34,14 +34,18 @@ bool CUnixPlatform::installDaemon(
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CUnixPlatform::uninstallDaemon(const char*)
|
||||
bool
|
||||
CUnixPlatform::uninstallDaemon(
|
||||
const char*)
|
||||
{
|
||||
// daemons don't require special installation
|
||||
return true;
|
||||
}
|
||||
|
||||
int CUnixPlatform::daemonize(
|
||||
const char* name, DaemonFunc func)
|
||||
int
|
||||
CUnixPlatform::daemonize(
|
||||
const char* name,
|
||||
DaemonFunc func)
|
||||
{
|
||||
// fork so shell thinks we're done and so we're not a process
|
||||
// group leader
|
||||
|
@ -86,12 +90,15 @@ int CUnixPlatform::daemonize(
|
|||
return func(this, 1, &name);
|
||||
}
|
||||
|
||||
int CUnixPlatform::restart(
|
||||
RestartFunc func, int minErrorCode)
|
||||
int
|
||||
CUnixPlatform::restart(
|
||||
RestartFunc func,
|
||||
int minErrorCode)
|
||||
{
|
||||
for (;;) {
|
||||
switch (fork()) {
|
||||
default: {
|
||||
default:
|
||||
{
|
||||
// parent process. wait for child to exit.
|
||||
int status;
|
||||
if (wait(&status) == -1) {
|
||||
|
@ -121,8 +128,8 @@ int CUnixPlatform::restart(
|
|||
return 16;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case -1:
|
||||
// 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) {
|
||||
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.
|
||||
struct passwd* pwent = getpwuid(getuid());
|
||||
|
@ -163,12 +173,14 @@ CString CUnixPlatform::getUserDirectory() const
|
|||
}
|
||||
}
|
||||
|
||||
CString CUnixPlatform::getSystemDirectory() const
|
||||
CString
|
||||
CUnixPlatform::getSystemDirectory() const
|
||||
{
|
||||
return "/etc";
|
||||
}
|
||||
|
||||
CString CUnixPlatform::addPathComponent(
|
||||
CString
|
||||
CUnixPlatform::addPathComponent(
|
||||
const CString& prefix,
|
||||
const CString& suffix) const
|
||||
{
|
||||
|
@ -182,14 +194,18 @@ CString CUnixPlatform::addPathComponent(
|
|||
return path;
|
||||
}
|
||||
|
||||
void CUnixPlatform::setDaemonLogger(const char* name)
|
||||
void
|
||||
CUnixPlatform::setDaemonLogger(
|
||||
const char* name)
|
||||
{
|
||||
openlog(name, 0, LOG_DAEMON);
|
||||
CLog::setOutputter(&CUnixPlatform::deamonLogger);
|
||||
}
|
||||
|
||||
bool CUnixPlatform::deamonLogger(
|
||||
int priority, const char* msg)
|
||||
bool
|
||||
CUnixPlatform::deamonLogger(
|
||||
int priority,
|
||||
const char* msg)
|
||||
{
|
||||
// convert priority
|
||||
switch (priority) {
|
||||
|
|
|
@ -3,10 +3,9 @@
|
|||
#include "CThread.h"
|
||||
#include "CLog.h"
|
||||
#include "stdvector.h"
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
#include <shlobj.h>
|
||||
#include <tchar.h>
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CWin32Platform
|
||||
|
@ -25,7 +24,8 @@ CWin32Platform::~CWin32Platform()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
bool CWin32Platform::isWindows95Family()
|
||||
bool
|
||||
CWin32Platform::isWindows95Family()
|
||||
{
|
||||
OSVERSIONINFO version;
|
||||
version.dwOSVersionInfoSize = sizeof(version);
|
||||
|
@ -36,16 +36,20 @@ bool CWin32Platform::isWindows95Family()
|
|||
return (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
|
||||
}
|
||||
|
||||
void CWin32Platform::setStatus(
|
||||
void
|
||||
CWin32Platform::setStatus(
|
||||
SERVICE_STATUS_HANDLE handle,
|
||||
DWORD state)
|
||||
{
|
||||
setStatus(handle, state, 0, 0);
|
||||
}
|
||||
|
||||
void CWin32Platform::setStatus(
|
||||
void
|
||||
CWin32Platform::setStatus(
|
||||
SERVICE_STATUS_HANDLE handle,
|
||||
DWORD state, DWORD step, DWORD waitHint)
|
||||
DWORD state,
|
||||
DWORD step,
|
||||
DWORD waitHint)
|
||||
{
|
||||
SERVICE_STATUS status;
|
||||
status.dwServiceType = SERVICE_WIN32_OWN_PROCESS |
|
||||
|
@ -61,7 +65,8 @@ void CWin32Platform::setStatus(
|
|||
SetServiceStatus(handle, &status);
|
||||
}
|
||||
|
||||
void CWin32Platform::setStatusError(
|
||||
void
|
||||
CWin32Platform::setStatusError(
|
||||
SERVICE_STATUS_HANDLE handle,
|
||||
DWORD error)
|
||||
{
|
||||
|
@ -79,7 +84,8 @@ void CWin32Platform::setStatusError(
|
|||
SetServiceStatus(handle, &status);
|
||||
}
|
||||
|
||||
bool CWin32Platform::installDaemon(
|
||||
bool
|
||||
CWin32Platform::installDaemon(
|
||||
const char* name,
|
||||
const char* description,
|
||||
const char* pathname,
|
||||
|
@ -174,7 +180,9 @@ bool CWin32Platform::installDaemon(
|
|||
}
|
||||
}
|
||||
|
||||
bool CWin32Platform::uninstallDaemon(const char* name)
|
||||
bool
|
||||
CWin32Platform::uninstallDaemon(
|
||||
const char* name)
|
||||
{
|
||||
// windows 95 family services
|
||||
if (isWindows95Family()) {
|
||||
|
@ -231,7 +239,8 @@ bool CWin32Platform::uninstallDaemon(const char* name)
|
|||
}
|
||||
}
|
||||
|
||||
int CWin32Platform::daemonize(
|
||||
int
|
||||
CWin32Platform::daemonize(
|
||||
const char* name,
|
||||
DaemonFunc func)
|
||||
{
|
||||
|
@ -294,8 +303,10 @@ int CWin32Platform::daemonize(
|
|||
}
|
||||
}
|
||||
|
||||
int CWin32Platform::restart(
|
||||
RestartFunc func, int /*minErrorCode*/)
|
||||
int
|
||||
CWin32Platform::restart(
|
||||
RestartFunc func,
|
||||
int /*minErrorCode*/)
|
||||
{
|
||||
// FIXME -- start in separate process or thread. note that this
|
||||
// isn't too critical as win32 doesn't force us to terminate for
|
||||
|
@ -303,7 +314,9 @@ int CWin32Platform::restart(
|
|||
return func();
|
||||
}
|
||||
|
||||
const char* CWin32Platform::getBasename(const char* pathname) const
|
||||
const char*
|
||||
CWin32Platform::getBasename(
|
||||
const char* pathname) const
|
||||
{
|
||||
if (pathname == NULL) {
|
||||
return NULL;
|
||||
|
@ -327,7 +340,8 @@ const char* CWin32Platform::getBasename(const char* pathname) const
|
|||
return basename;
|
||||
}
|
||||
|
||||
CString CWin32Platform::getUserDirectory() const
|
||||
CString
|
||||
CWin32Platform::getUserDirectory() const
|
||||
{
|
||||
// try %HOMEPATH%
|
||||
TCHAR dir[MAX_PATH];
|
||||
|
@ -370,7 +384,8 @@ CString CWin32Platform::getUserDirectory() const
|
|||
return "C:";
|
||||
}
|
||||
|
||||
CString CWin32Platform::getSystemDirectory() const
|
||||
CString
|
||||
CWin32Platform::getSystemDirectory() const
|
||||
{
|
||||
// get windows directory
|
||||
char dir[MAX_PATH];
|
||||
|
@ -383,7 +398,8 @@ CString CWin32Platform::getSystemDirectory() const
|
|||
}
|
||||
}
|
||||
|
||||
CString CWin32Platform::addPathComponent(
|
||||
CString
|
||||
CWin32Platform::addPathComponent(
|
||||
const CString& prefix,
|
||||
const CString& suffix) const
|
||||
{
|
||||
|
@ -399,8 +415,10 @@ CString CWin32Platform::addPathComponent(
|
|||
return path;
|
||||
}
|
||||
|
||||
HKEY CWin32Platform::openKey(
|
||||
HKEY key, const char* keyName)
|
||||
HKEY
|
||||
CWin32Platform::openKey(
|
||||
HKEY key,
|
||||
const char* keyName)
|
||||
{
|
||||
// open next key
|
||||
HKEY newKey;
|
||||
|
@ -422,8 +440,10 @@ HKEY CWin32Platform::openKey(
|
|||
return newKey;
|
||||
}
|
||||
|
||||
HKEY CWin32Platform::openKey(
|
||||
HKEY key, const char** keyNames)
|
||||
HKEY
|
||||
CWin32Platform::openKey(
|
||||
HKEY key,
|
||||
const char** keyNames)
|
||||
{
|
||||
for (UInt32 i = 0; key != NULL && keyNames[i] != NULL; ++i) {
|
||||
// open next key
|
||||
|
@ -432,28 +452,39 @@ HKEY CWin32Platform::openKey(
|
|||
return key;
|
||||
}
|
||||
|
||||
void CWin32Platform::closeKey(HKEY key)
|
||||
void
|
||||
CWin32Platform::closeKey(
|
||||
HKEY key)
|
||||
{
|
||||
assert(key != NULL);
|
||||
RegCloseKey(key);
|
||||
}
|
||||
|
||||
void CWin32Platform::deleteKey(HKEY key, const char* name)
|
||||
void
|
||||
CWin32Platform::deleteKey(
|
||||
HKEY key,
|
||||
const char* name)
|
||||
{
|
||||
assert(key != NULL);
|
||||
assert(name != NULL);
|
||||
RegDeleteKey(key, name);
|
||||
}
|
||||
|
||||
void CWin32Platform::deleteValue(HKEY key, const char* name)
|
||||
void
|
||||
CWin32Platform::deleteValue(
|
||||
HKEY key,
|
||||
const char* name)
|
||||
{
|
||||
assert(key != NULL);
|
||||
assert(name != NULL);
|
||||
RegDeleteValue(key, name);
|
||||
}
|
||||
|
||||
void CWin32Platform::setValue(HKEY key,
|
||||
const char* name, const CString& value)
|
||||
void
|
||||
CWin32Platform::setValue(
|
||||
HKEY key,
|
||||
const char* name,
|
||||
const CString& value)
|
||||
{
|
||||
assert(key != NULL);
|
||||
assert(name != NULL);
|
||||
|
@ -462,7 +493,9 @@ void CWin32Platform::setValue(HKEY key,
|
|||
value.size() + 1);
|
||||
}
|
||||
|
||||
CString CWin32Platform::readValueString(HKEY key,
|
||||
CString
|
||||
CWin32Platform::readValueString(
|
||||
HKEY key,
|
||||
const char* name)
|
||||
{
|
||||
// get the size of the string
|
||||
|
@ -490,7 +523,8 @@ CString CWin32Platform::readValueString(HKEY key,
|
|||
return value;
|
||||
}
|
||||
|
||||
HKEY CWin32Platform::openNTServicesKey()
|
||||
HKEY
|
||||
CWin32Platform::openNTServicesKey()
|
||||
{
|
||||
static const char* s_keyNames[] = {
|
||||
_T("SYSTEM"),
|
||||
|
@ -502,7 +536,8 @@ HKEY CWin32Platform::openNTServicesKey()
|
|||
return openKey(HKEY_LOCAL_MACHINE, s_keyNames);
|
||||
}
|
||||
|
||||
HKEY CWin32Platform::open95ServicesKey()
|
||||
HKEY
|
||||
CWin32Platform::open95ServicesKey()
|
||||
{
|
||||
static const char* s_keyNames[] = {
|
||||
_T("Software"),
|
||||
|
@ -516,7 +551,10 @@ HKEY CWin32Platform::open95ServicesKey()
|
|||
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
|
||||
assert(m_serviceMutex != NULL);
|
||||
|
@ -595,8 +633,10 @@ int CWin32Platform::runDaemon(RunFunc run, StopFunc stop)
|
|||
}
|
||||
}
|
||||
|
||||
void CWin32Platform::serviceMain(
|
||||
DWORD argc, LPTSTR* argvIn)
|
||||
void
|
||||
CWin32Platform::serviceMain(
|
||||
DWORD argc,
|
||||
LPTSTR* argvIn)
|
||||
{
|
||||
typedef std::vector<LPCTSTR> ArgList;
|
||||
typedef std::vector<CString> Arguments;
|
||||
|
@ -718,13 +758,17 @@ void CWin32Platform::serviceMain(
|
|||
// FIXME -- close event log?
|
||||
}
|
||||
|
||||
void WINAPI CWin32Platform::serviceMainEntry(
|
||||
DWORD argc, LPTSTR* argv)
|
||||
void WINAPI
|
||||
CWin32Platform::serviceMainEntry(
|
||||
DWORD argc,
|
||||
LPTSTR* argv)
|
||||
{
|
||||
s_daemonPlatform->serviceMain(argc, argv);
|
||||
}
|
||||
|
||||
void CWin32Platform::serviceHandler(DWORD ctrl)
|
||||
void
|
||||
CWin32Platform::serviceHandler(
|
||||
DWORD ctrl)
|
||||
{
|
||||
assert(m_serviceMutex != NULL);
|
||||
assert(m_serviceState != NULL);
|
||||
|
@ -796,13 +840,17 @@ void CWin32Platform::serviceHandler(DWORD ctrl)
|
|||
setStatus(m_statusHandle, *m_serviceState);
|
||||
}
|
||||
|
||||
void WINAPI CWin32Platform::serviceHandlerEntry(DWORD ctrl)
|
||||
void WINAPI
|
||||
CWin32Platform::serviceHandlerEntry(
|
||||
DWORD ctrl)
|
||||
{
|
||||
s_daemonPlatform->serviceHandler(ctrl);
|
||||
}
|
||||
|
||||
bool CWin32Platform::serviceLogger(
|
||||
int priority, const char* msg)
|
||||
bool
|
||||
CWin32Platform::serviceLogger(
|
||||
int priority,
|
||||
const char* msg)
|
||||
{
|
||||
if (s_eventLog == NULL) {
|
||||
return false;
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
#include "CXWindowsClipboard.h"
|
||||
#include "CXWindowsUtil.h"
|
||||
#include "CLog.h"
|
||||
#include "CThread.h"
|
||||
#include "CLog.h"
|
||||
#include "TMethodJob.h"
|
||||
#include <stdio.h>
|
||||
#include <cstdio>
|
||||
#include <X11/Xatom.h>
|
||||
|
||||
//
|
||||
// CXWindowsClipboard
|
||||
//
|
||||
|
||||
CXWindowsClipboard::CXWindowsClipboard(Display* display,
|
||||
Window window, ClipboardID id) :
|
||||
CXWindowsClipboard::CXWindowsClipboard(
|
||||
Display* display,
|
||||
Window window,
|
||||
ClipboardID id) :
|
||||
m_display(display),
|
||||
m_window(window),
|
||||
m_id(id),
|
||||
|
@ -60,7 +62,9 @@ CXWindowsClipboard::~CXWindowsClipboard()
|
|||
clearReplies();
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::lost(Time time)
|
||||
void
|
||||
CXWindowsClipboard::lost(
|
||||
Time time)
|
||||
{
|
||||
log((CLOG_DEBUG "lost clipboard %d ownership at %d", m_id, time));
|
||||
if (m_owner) {
|
||||
|
@ -70,10 +74,13 @@ void CXWindowsClipboard::lost(Time time)
|
|||
}
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::addRequest(
|
||||
void
|
||||
CXWindowsClipboard::addRequest(
|
||||
Window owner,
|
||||
Window requestor, Atom target,
|
||||
::Time time, Atom property)
|
||||
Window requestor,
|
||||
Atom target,
|
||||
::Time time,
|
||||
Atom property)
|
||||
{
|
||||
// must be for our window and we must have owned the selection
|
||||
// at the given time.
|
||||
|
@ -110,9 +117,12 @@ void CXWindowsClipboard::addRequest(
|
|||
pushReplies();
|
||||
}
|
||||
|
||||
bool CXWindowsClipboard::addSimpleRequest(
|
||||
Window requestor, Atom target,
|
||||
::Time time, Atom property)
|
||||
bool
|
||||
CXWindowsClipboard::addSimpleRequest(
|
||||
Window requestor,
|
||||
Atom target,
|
||||
::Time time,
|
||||
Atom property)
|
||||
{
|
||||
// obsolete requestors may supply a None property. in
|
||||
// that case we use the target as the property to store
|
||||
|
@ -151,9 +161,11 @@ bool CXWindowsClipboard::addSimpleRequest(
|
|||
}
|
||||
}
|
||||
|
||||
bool CXWindowsClipboard::processRequest(
|
||||
bool
|
||||
CXWindowsClipboard::processRequest(
|
||||
Window requestor,
|
||||
::Time /*time*/, Atom property)
|
||||
::Time /*time*/,
|
||||
Atom property)
|
||||
{
|
||||
CReplyMap::iterator index = m_replies.find(requestor);
|
||||
if (index == m_replies.end()) {
|
||||
|
@ -179,7 +191,8 @@ bool CXWindowsClipboard::processRequest(
|
|||
return false;
|
||||
}
|
||||
|
||||
bool CXWindowsClipboard::destroyRequest(
|
||||
bool
|
||||
CXWindowsClipboard::destroyRequest(
|
||||
Window requestor)
|
||||
{
|
||||
CReplyMap::iterator index = m_replies.find(requestor);
|
||||
|
@ -198,17 +211,20 @@ bool CXWindowsClipboard::destroyRequest(
|
|||
return true;
|
||||
}
|
||||
|
||||
Window CXWindowsClipboard::getWindow() const
|
||||
Window
|
||||
CXWindowsClipboard::getWindow() const
|
||||
{
|
||||
return m_window;
|
||||
}
|
||||
|
||||
Atom CXWindowsClipboard::getSelection() const
|
||||
Atom
|
||||
CXWindowsClipboard::getSelection() const
|
||||
{
|
||||
return m_selection;
|
||||
}
|
||||
|
||||
bool CXWindowsClipboard::empty()
|
||||
bool
|
||||
CXWindowsClipboard::empty()
|
||||
{
|
||||
assert(m_open);
|
||||
|
||||
|
@ -240,8 +256,10 @@ bool CXWindowsClipboard::empty()
|
|||
return true;
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::add(
|
||||
EFormat format, const CString& data)
|
||||
void
|
||||
CXWindowsClipboard::add(
|
||||
EFormat format,
|
||||
const CString& data)
|
||||
{
|
||||
assert(m_open);
|
||||
assert(m_owner);
|
||||
|
@ -254,7 +272,9 @@ void CXWindowsClipboard::add(
|
|||
// FIXME -- set motif clipboard item?
|
||||
}
|
||||
|
||||
bool CXWindowsClipboard::open(Time time) const
|
||||
bool
|
||||
CXWindowsClipboard::open(
|
||||
Time time) const
|
||||
{
|
||||
assert(!m_open);
|
||||
|
||||
|
@ -304,7 +324,8 @@ bool CXWindowsClipboard::open(Time time) const
|
|||
return true;
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::close() const
|
||||
void
|
||||
CXWindowsClipboard::close() const
|
||||
{
|
||||
assert(m_open);
|
||||
|
||||
|
@ -319,12 +340,15 @@ void CXWindowsClipboard::close() const
|
|||
m_open = false;
|
||||
}
|
||||
|
||||
IClipboard::Time CXWindowsClipboard::getTime() const
|
||||
IClipboard::Time
|
||||
CXWindowsClipboard::getTime() const
|
||||
{
|
||||
return m_timeOwned;
|
||||
}
|
||||
|
||||
bool CXWindowsClipboard::has(EFormat format) const
|
||||
bool
|
||||
CXWindowsClipboard::has(
|
||||
EFormat format) const
|
||||
{
|
||||
assert(m_open);
|
||||
|
||||
|
@ -332,7 +356,9 @@ bool CXWindowsClipboard::has(EFormat format) const
|
|||
return m_added[format];
|
||||
}
|
||||
|
||||
CString CXWindowsClipboard::get(EFormat format) const
|
||||
CString
|
||||
CXWindowsClipboard::get(
|
||||
EFormat format) const
|
||||
{
|
||||
assert(m_open);
|
||||
|
||||
|
@ -340,23 +366,28 @@ CString CXWindowsClipboard::get(EFormat format) const
|
|||
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
|
||||
// and various character encodings like unicode).
|
||||
if (src == m_atomString ||
|
||||
src == m_atomText /*||
|
||||
src == m_atomCompoundText*/)
|
||||
src == m_atomCompoundText*/) {
|
||||
return IClipboard::kText;
|
||||
}
|
||||
return IClipboard::kNumFormats;
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::clearCache() const
|
||||
void
|
||||
CXWindowsClipboard::clearCache() const
|
||||
{
|
||||
const_cast<CXWindowsClipboard*>(this)->doClearCache();
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::doClearCache()
|
||||
void
|
||||
CXWindowsClipboard::doClearCache()
|
||||
{
|
||||
m_cached = false;
|
||||
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
|
||||
if (!m_cached) {
|
||||
|
@ -373,7 +405,8 @@ void CXWindowsClipboard::fillCache() const
|
|||
}
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::doFillCache()
|
||||
void
|
||||
CXWindowsClipboard::doFillCache()
|
||||
{
|
||||
if (m_motif) {
|
||||
motifFillCache();
|
||||
|
@ -385,7 +418,8 @@ void CXWindowsClipboard::doFillCache()
|
|||
m_cacheTime = m_timeOwned;
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::icccmFillCache()
|
||||
void
|
||||
CXWindowsClipboard::icccmFillCache()
|
||||
{
|
||||
log((CLOG_DEBUG "ICCCM fill clipboard %d", m_id));
|
||||
|
||||
|
@ -447,7 +481,8 @@ void CXWindowsClipboard::icccmFillCache()
|
|||
}
|
||||
}
|
||||
|
||||
bool CXWindowsClipboard::icccmGetSelection(
|
||||
bool
|
||||
CXWindowsClipboard::icccmGetSelection(
|
||||
Atom target,
|
||||
Atom* actualTarget,
|
||||
CString* data) const
|
||||
|
@ -470,7 +505,8 @@ bool CXWindowsClipboard::icccmGetSelection(
|
|||
return true;
|
||||
}
|
||||
|
||||
IClipboard::Time CXWindowsClipboard::icccmGetTime() const
|
||||
IClipboard::Time
|
||||
CXWindowsClipboard::icccmGetTime() const
|
||||
{
|
||||
Atom actualTarget;
|
||||
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)
|
||||
Window lockOwner = XGetSelectionOwner(m_display, m_atomMotifClipLock);
|
||||
|
@ -510,7 +547,8 @@ bool CXWindowsClipboard::motifLockClipboard() const
|
|||
return true;
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::motifUnlockClipboard() const
|
||||
void
|
||||
CXWindowsClipboard::motifUnlockClipboard() const
|
||||
{
|
||||
log((CLOG_DEBUG1 "unlocked motif clipboard"));
|
||||
|
||||
|
@ -525,7 +563,8 @@ void CXWindowsClipboard::motifUnlockClipboard() const
|
|||
XSetSelectionOwner(m_display, m_atomMotifClipLock, None, time);
|
||||
}
|
||||
|
||||
bool CXWindowsClipboard::motifOwnsClipboard() const
|
||||
bool
|
||||
CXWindowsClipboard::motifOwnsClipboard() const
|
||||
{
|
||||
// get the current selection owner
|
||||
// FIXME -- this can't be right. even if the window is destroyed
|
||||
|
@ -563,7 +602,8 @@ bool CXWindowsClipboard::motifOwnsClipboard() const
|
|||
return false;
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::motifFillCache()
|
||||
void
|
||||
CXWindowsClipboard::motifFillCache()
|
||||
{
|
||||
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?
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CXWindowsClipboard::insertMultipleReply(
|
||||
Window requestor, ::Time time, Atom property)
|
||||
bool
|
||||
CXWindowsClipboard::insertMultipleReply(
|
||||
Window requestor,
|
||||
::Time time,
|
||||
Atom property)
|
||||
{
|
||||
// get the requested targets
|
||||
Atom target;
|
||||
|
@ -735,7 +779,9 @@ bool CXWindowsClipboard::insertMultipleReply(
|
|||
return true;
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::insertReply(CReply* reply)
|
||||
void
|
||||
CXWindowsClipboard::insertReply(
|
||||
CReply* reply)
|
||||
{
|
||||
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
|
||||
// been sent yet.
|
||||
|
@ -793,7 +840,8 @@ void CXWindowsClipboard::pushReplies()
|
|||
}
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::pushReplies(
|
||||
void
|
||||
CXWindowsClipboard::pushReplies(
|
||||
CReplyMap::iterator mapIndex,
|
||||
CReplyList& replies,
|
||||
CReplyList::iterator index)
|
||||
|
@ -821,7 +869,9 @@ void CXWindowsClipboard::pushReplies(
|
|||
}
|
||||
}
|
||||
|
||||
bool CXWindowsClipboard::sendReply(CReply* reply)
|
||||
bool
|
||||
CXWindowsClipboard::sendReply(
|
||||
CReply* reply)
|
||||
{
|
||||
assert(reply != NULL);
|
||||
|
||||
|
@ -943,7 +993,8 @@ bool CXWindowsClipboard::sendReply(CReply* reply)
|
|||
return false;
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::clearReplies()
|
||||
void
|
||||
CXWindowsClipboard::clearReplies()
|
||||
{
|
||||
for (CReplyMap::iterator index = m_replies.begin();
|
||||
index != m_replies.end(); ++index) {
|
||||
|
@ -953,7 +1004,9 @@ void CXWindowsClipboard::clearReplies()
|
|||
m_eventMasks.clear();
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::clearReplies(CReplyList& replies)
|
||||
void
|
||||
CXWindowsClipboard::clearReplies(
|
||||
CReplyList& replies)
|
||||
{
|
||||
for (CReplyList::iterator index = replies.begin();
|
||||
index != replies.end(); ++index) {
|
||||
|
@ -962,9 +1015,13 @@ void CXWindowsClipboard::clearReplies(CReplyList& replies)
|
|||
replies.clear();
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::sendNotify(
|
||||
Window requestor, Atom selection,
|
||||
Atom target, Atom property, Time time)
|
||||
void
|
||||
CXWindowsClipboard::sendNotify(
|
||||
Window requestor,
|
||||
Atom selection,
|
||||
Atom target,
|
||||
Atom property,
|
||||
Time time)
|
||||
{
|
||||
XEvent event;
|
||||
event.xselection.type = SelectionNotify;
|
||||
|
@ -978,26 +1035,33 @@ void CXWindowsClipboard::sendNotify(
|
|||
XSendEvent(m_display, requestor, False, 0, &event);
|
||||
}
|
||||
|
||||
bool CXWindowsClipboard::wasOwnedAtTime(
|
||||
bool
|
||||
CXWindowsClipboard::wasOwnedAtTime(
|
||||
::Time time) const
|
||||
{
|
||||
// not owned if we've never owned the selection
|
||||
if (m_timeOwned == 0)
|
||||
if (m_timeOwned == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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 then get the current time, otherwise use
|
||||
// m_timeLost as the end time.
|
||||
Time lost = m_timeLost;
|
||||
if (m_timeLost == 0)
|
||||
if (time == CurrentTime)
|
||||
if (m_timeLost == 0) {
|
||||
if (time == CurrentTime) {
|
||||
return true;
|
||||
else
|
||||
}
|
||||
else {
|
||||
lost = CXWindowsUtil::getCurrentTime(m_display, m_window);
|
||||
else
|
||||
if (time == CurrentTime)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (time == CurrentTime) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// compare time to range
|
||||
Time duration = lost - m_timeOwned;
|
||||
|
@ -1005,8 +1069,10 @@ bool CXWindowsClipboard::wasOwnedAtTime(
|
|||
return (/*when >= 0 &&*/ when < duration);
|
||||
}
|
||||
|
||||
Atom CXWindowsClipboard::getTargetsData(
|
||||
CString& data, int* format) const
|
||||
Atom
|
||||
CXWindowsClipboard::getTargetsData(
|
||||
CString& data,
|
||||
int* format) const
|
||||
{
|
||||
assert(format != NULL);
|
||||
|
||||
|
@ -1029,8 +1095,10 @@ Atom CXWindowsClipboard::getTargetsData(
|
|||
return m_atomTargets;
|
||||
}
|
||||
|
||||
Atom CXWindowsClipboard::getTimestampData(
|
||||
CString& data, int* format) const
|
||||
Atom
|
||||
CXWindowsClipboard::getTimestampData(
|
||||
CString& data,
|
||||
int* format) const
|
||||
{
|
||||
assert(format != NULL);
|
||||
|
||||
|
@ -1040,8 +1108,10 @@ Atom CXWindowsClipboard::getTimestampData(
|
|||
return m_atomTimestamp;
|
||||
}
|
||||
|
||||
Atom CXWindowsClipboard::getStringData(
|
||||
CString& data, int* format) const
|
||||
Atom
|
||||
CXWindowsClipboard::getStringData(
|
||||
CString& data,
|
||||
int* format) const
|
||||
{
|
||||
assert(format != NULL);
|
||||
|
||||
|
@ -1061,7 +1131,9 @@ Atom CXWindowsClipboard::getStringData(
|
|||
//
|
||||
|
||||
CXWindowsClipboard::CICCCMGetClipboard::CICCCMGetClipboard(
|
||||
Window requestor, Time time, Atom property) :
|
||||
Window requestor,
|
||||
Time time,
|
||||
Atom property) :
|
||||
m_requestor(requestor),
|
||||
m_time(time),
|
||||
m_property(property),
|
||||
|
@ -1081,10 +1153,13 @@ CXWindowsClipboard::CICCCMGetClipboard::~CICCCMGetClipboard()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
bool CXWindowsClipboard::CICCCMGetClipboard::readClipboard(
|
||||
bool
|
||||
CXWindowsClipboard::CICCCMGetClipboard::readClipboard(
|
||||
Display* display,
|
||||
Atom selection, Atom target,
|
||||
Atom* actualTarget, CString* data)
|
||||
Atom selection,
|
||||
Atom target,
|
||||
Atom* actualTarget,
|
||||
CString* data)
|
||||
{
|
||||
assert(actualTarget != NULL);
|
||||
assert(data != NULL);
|
||||
|
@ -1139,7 +1214,8 @@ bool CXWindowsClipboard::CICCCMGetClipboard::readClipboard(
|
|||
return !m_failed;
|
||||
}
|
||||
|
||||
bool CXWindowsClipboard::CICCCMGetClipboard::doEventPredicate(
|
||||
bool
|
||||
CXWindowsClipboard::CICCCMGetClipboard::doEventPredicate(
|
||||
Display* display,
|
||||
XEvent* xevent)
|
||||
{
|
||||
|
@ -1276,7 +1352,8 @@ log((CLOG_INFO " INCR secondary chunk")); // FIXME
|
|||
return !m_incr;
|
||||
}
|
||||
|
||||
Bool CXWindowsClipboard::CICCCMGetClipboard::eventPredicate(
|
||||
Bool
|
||||
CXWindowsClipboard::CICCCMGetClipboard::eventPredicate(
|
||||
Display* display,
|
||||
XEvent* xevent,
|
||||
XPointer arg)
|
||||
|
@ -1285,7 +1362,8 @@ Bool CXWindowsClipboard::CICCCMGetClipboard::eventPredicate(
|
|||
return self->doEventPredicate(display, xevent) ? True : False;
|
||||
}
|
||||
|
||||
void CXWindowsClipboard::CICCCMGetClipboard::timeout(
|
||||
void
|
||||
CXWindowsClipboard::CICCCMGetClipboard::timeout(
|
||||
void* vdisplay)
|
||||
{
|
||||
// wait
|
||||
|
@ -1308,8 +1386,10 @@ void CXWindowsClipboard::CICCCMGetClipboard::timeout(
|
|||
// CXWindowsClipboard::CReply
|
||||
//
|
||||
|
||||
CXWindowsClipboard::CReply::CReply(Window requestor,
|
||||
Atom target, ::Time time) :
|
||||
CXWindowsClipboard::CReply::CReply(
|
||||
Window requestor,
|
||||
Atom target,
|
||||
::Time time) :
|
||||
m_requestor(requestor),
|
||||
m_target(target),
|
||||
m_time(time),
|
||||
|
@ -1324,9 +1404,14 @@ CXWindowsClipboard::CReply::CReply(Window requestor,
|
|||
// do nothing
|
||||
}
|
||||
|
||||
CXWindowsClipboard::CReply::CReply(Window requestor,
|
||||
Atom target, ::Time time, Atom property,
|
||||
const CString& data, Atom type, int format) :
|
||||
CXWindowsClipboard::CReply::CReply(
|
||||
Window requestor,
|
||||
Atom target,
|
||||
::Time time,
|
||||
Atom property,
|
||||
const CString& data,
|
||||
Atom type,
|
||||
int format) :
|
||||
m_requestor(requestor),
|
||||
m_target(target),
|
||||
m_time(time),
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "IClipboard.h"
|
||||
#include "ClipboardTypes.h"
|
||||
#include "CString.h"
|
||||
#include "stdmap.h"
|
||||
#include "stdlist.h"
|
||||
#include <X11/Xlib.h>
|
||||
|
|
|
@ -2,14 +2,13 @@
|
|||
#include "CXWindowsClipboard.h"
|
||||
#include "CXWindowsUtil.h"
|
||||
#include "CClipboard.h"
|
||||
#include "XScreen.h"
|
||||
#include "CLock.h"
|
||||
#include "CThread.h"
|
||||
#include "CLog.h"
|
||||
#include "CString.h"
|
||||
#include "CThread.h"
|
||||
#include "XScreen.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
//
|
||||
// CXWindowsScreen
|
||||
|
@ -35,7 +34,8 @@ CXWindowsScreen::~CXWindowsScreen()
|
|||
s_screen = NULL;
|
||||
}
|
||||
|
||||
void CXWindowsScreen::openDisplay()
|
||||
void
|
||||
CXWindowsScreen::openDisplay()
|
||||
{
|
||||
assert(m_display == NULL);
|
||||
|
||||
|
@ -51,8 +51,9 @@ void CXWindowsScreen::openDisplay()
|
|||
// open the display
|
||||
log((CLOG_DEBUG "XOpenDisplay(\"%s\")", display));
|
||||
m_display = XOpenDisplay(display);
|
||||
if (m_display == NULL)
|
||||
if (m_display == NULL) {
|
||||
throw XScreenOpenFailure();
|
||||
}
|
||||
|
||||
// get default screen
|
||||
m_screen = DefaultScreen(m_display);
|
||||
|
@ -75,7 +76,8 @@ void CXWindowsScreen::openDisplay()
|
|||
}
|
||||
}
|
||||
|
||||
void CXWindowsScreen::closeDisplay()
|
||||
void
|
||||
CXWindowsScreen::closeDisplay()
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
|
||||
|
@ -96,20 +98,24 @@ void CXWindowsScreen::closeDisplay()
|
|||
XSetIOErrorHandler(NULL);
|
||||
}
|
||||
|
||||
int CXWindowsScreen::getScreen() const
|
||||
int
|
||||
CXWindowsScreen::getScreen() const
|
||||
{
|
||||
assert(m_display != NULL);
|
||||
return m_screen;
|
||||
}
|
||||
|
||||
Window CXWindowsScreen::getRoot() const
|
||||
Window
|
||||
CXWindowsScreen::getRoot() const
|
||||
{
|
||||
assert(m_display != NULL);
|
||||
return m_root;
|
||||
}
|
||||
|
||||
void CXWindowsScreen::getScreenSize(
|
||||
SInt32* w, SInt32* h) const
|
||||
void
|
||||
CXWindowsScreen::getScreenSize(
|
||||
SInt32* w,
|
||||
SInt32* h) const
|
||||
{
|
||||
assert(m_display != NULL);
|
||||
assert(w != NULL && h != NULL);
|
||||
|
@ -118,7 +124,8 @@ void CXWindowsScreen::getScreenSize(
|
|||
*h = m_h;
|
||||
}
|
||||
|
||||
Cursor CXWindowsScreen::createBlankCursor() const
|
||||
Cursor
|
||||
CXWindowsScreen::createBlankCursor() const
|
||||
{
|
||||
// this seems just a bit more complicated than really necessary
|
||||
|
||||
|
@ -153,7 +160,9 @@ Cursor CXWindowsScreen::createBlankCursor() const
|
|||
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
|
||||
// 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
|
||||
m_stop = true;
|
||||
}
|
||||
|
||||
ClipboardID CXWindowsScreen::getClipboardID(Atom selection) const
|
||||
ClipboardID
|
||||
CXWindowsScreen::getClipboardID(Atom selection) const
|
||||
{
|
||||
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
||||
if (m_clipboard[id] != NULL &&
|
||||
|
@ -199,15 +210,19 @@ ClipboardID CXWindowsScreen::getClipboardID(Atom selection) const
|
|||
return kClipboardEnd;
|
||||
}
|
||||
|
||||
void CXWindowsScreen::onUnexpectedClose()
|
||||
void
|
||||
CXWindowsScreen::onUnexpectedClose()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
bool CXWindowsScreen::processEvent(XEvent* xevent)
|
||||
bool
|
||||
CXWindowsScreen::processEvent(
|
||||
XEvent* xevent)
|
||||
{
|
||||
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
|
||||
// selection owner. report that to the subclass.
|
||||
|
@ -218,8 +233,8 @@ bool CXWindowsScreen::processEvent(XEvent* xevent)
|
|||
onLostClipboard(id);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SelectionNotify:
|
||||
// notification of selection transferred. we shouldn't
|
||||
|
@ -234,9 +249,11 @@ bool CXWindowsScreen::processEvent(XEvent* xevent)
|
|||
}
|
||||
return true;
|
||||
|
||||
case SelectionRequest: {
|
||||
case SelectionRequest:
|
||||
{
|
||||
// somebody is asking for clipboard data
|
||||
ClipboardID id = getClipboardID(xevent->xselectionrequest.selection);
|
||||
ClipboardID id = getClipboardID(
|
||||
xevent->xselectionrequest.selection);
|
||||
if (id != kClipboardEnd) {
|
||||
CLock lock(&m_mutex);
|
||||
m_clipboard[id]->addRequest(
|
||||
|
@ -247,8 +264,8 @@ bool CXWindowsScreen::processEvent(XEvent* xevent)
|
|||
xevent->xselectionrequest.property);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case PropertyNotify:
|
||||
// property delete may be part of a selection conversion
|
||||
|
@ -270,7 +287,8 @@ bool CXWindowsScreen::processEvent(XEvent* xevent)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool CXWindowsScreen::setDisplayClipboard(
|
||||
bool
|
||||
CXWindowsScreen::setDisplayClipboard(
|
||||
ClipboardID id,
|
||||
const IClipboard* clipboard)
|
||||
{
|
||||
|
@ -300,7 +318,8 @@ bool CXWindowsScreen::setDisplayClipboard(
|
|||
}
|
||||
}
|
||||
|
||||
bool CXWindowsScreen::getDisplayClipboard(
|
||||
bool
|
||||
CXWindowsScreen::getDisplayClipboard(
|
||||
ClipboardID id,
|
||||
IClipboard* clipboard) const
|
||||
{
|
||||
|
@ -322,9 +341,11 @@ bool CXWindowsScreen::getDisplayClipboard(
|
|||
return CClipboard::copy(clipboard, m_clipboard[id], timestamp);
|
||||
}
|
||||
|
||||
void CXWindowsScreen::processClipboardRequest(
|
||||
void
|
||||
CXWindowsScreen::processClipboardRequest(
|
||||
Window requestor,
|
||||
Time time, Atom property)
|
||||
Time time,
|
||||
Atom property)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
|
||||
|
@ -337,7 +358,8 @@ void CXWindowsScreen::processClipboardRequest(
|
|||
}
|
||||
}
|
||||
|
||||
void CXWindowsScreen::destroyClipboardRequest(
|
||||
void
|
||||
CXWindowsScreen::destroyClipboardRequest(
|
||||
Window requestor)
|
||||
{
|
||||
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
|
||||
// down. X forces us to exit at this point. that's arguably
|
||||
|
@ -371,7 +395,8 @@ int CXWindowsScreen::ioErrorHandler(Display*)
|
|||
// CXWindowsScreen::CDisplayLock
|
||||
//
|
||||
|
||||
CXWindowsScreen::CDisplayLock::CDisplayLock(const CXWindowsScreen* screen) :
|
||||
CXWindowsScreen::CDisplayLock::CDisplayLock(
|
||||
const CXWindowsScreen* screen) :
|
||||
m_mutex(&screen->m_mutex),
|
||||
m_display(screen->m_display)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef CXWINDOWSSCREEN_H
|
||||
#define CXWINDOWSSCREEN_H
|
||||
|
||||
#include "BasicTypes.h"
|
||||
#include "ClipboardTypes.h"
|
||||
#include "CMutex.h"
|
||||
#include <X11/Xlib.h>
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
#include "CXWindowsUtil.h"
|
||||
#include "CLog.h"
|
||||
#include "CThread.h"
|
||||
#include <assert.h>
|
||||
#include "CLog.h"
|
||||
#include <X11/Xatom.h>
|
||||
|
||||
//
|
||||
// CXWindowsUtil
|
||||
//
|
||||
|
||||
bool CXWindowsUtil::getWindowProperty(
|
||||
bool
|
||||
CXWindowsUtil::getWindowProperty(
|
||||
Display* display,
|
||||
Window window, Atom property,
|
||||
CString* data, Atom* type,
|
||||
int* format, bool deleteProperty)
|
||||
Window window,
|
||||
Atom property,
|
||||
CString* data,
|
||||
Atom* type,
|
||||
int* format,
|
||||
bool deleteProperty)
|
||||
{
|
||||
assert(display != NULL);
|
||||
assert(data != NULL);
|
||||
|
@ -84,11 +87,15 @@ bool CXWindowsUtil::getWindowProperty(
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CXWindowsUtil::setWindowProperty(
|
||||
bool
|
||||
CXWindowsUtil::setWindowProperty(
|
||||
Display* display,
|
||||
Window window, Atom property,
|
||||
const void* vdata, UInt32 size,
|
||||
Atom type, SInt32 format)
|
||||
Window window,
|
||||
Atom property,
|
||||
const void* vdata,
|
||||
UInt32 size,
|
||||
Atom type,
|
||||
SInt32 format)
|
||||
{
|
||||
const UInt32 length = 4 * XMaxRequestSize(display);
|
||||
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?
|
||||
UInt32 chunkSize = size;
|
||||
if (chunkSize > length)
|
||||
if (chunkSize > length) {
|
||||
chunkSize = length;
|
||||
}
|
||||
|
||||
// send first chunk
|
||||
XChangeProperty(display, window, property,
|
||||
|
@ -113,8 +121,9 @@ bool CXWindowsUtil::setWindowProperty(
|
|||
size -= chunkSize;
|
||||
while (!error && size > 0) {
|
||||
chunkSize = size;
|
||||
if (chunkSize > length)
|
||||
if (chunkSize > length) {
|
||||
chunkSize = length;
|
||||
}
|
||||
XChangeProperty(display, window, property,
|
||||
type, format, PropModeAppend,
|
||||
data, chunkSize / datumSize);
|
||||
|
@ -125,8 +134,10 @@ bool CXWindowsUtil::setWindowProperty(
|
|||
return !error;
|
||||
}
|
||||
|
||||
Time CXWindowsUtil::getCurrentTime(
|
||||
Display* display, Window window)
|
||||
Time
|
||||
CXWindowsUtil::getCurrentTime(
|
||||
Display* display,
|
||||
Window window)
|
||||
{
|
||||
// select property events on window
|
||||
XWindowAttributes attr;
|
||||
|
@ -162,8 +173,11 @@ Time CXWindowsUtil::getCurrentTime(
|
|||
return xevent.xproperty.time;
|
||||
}
|
||||
|
||||
Bool CXWindowsUtil::propertyNotifyPredicate(
|
||||
Display*, XEvent* xevent, XPointer arg)
|
||||
Bool
|
||||
CXWindowsUtil::propertyNotifyPredicate(
|
||||
Display*,
|
||||
XEvent* xevent,
|
||||
XPointer arg)
|
||||
{
|
||||
CPropertyNotifyPredicateInfo* filter =
|
||||
reinterpret_cast<CPropertyNotifyPredicateInfo*>(arg);
|
||||
|
@ -185,12 +199,15 @@ CXWindowsUtil::CErrorLock::CErrorLock()
|
|||
install(&CXWindowsUtil::CErrorLock::ignoreHandler, NULL);
|
||||
}
|
||||
|
||||
CXWindowsUtil::CErrorLock::CErrorLock(bool* flag)
|
||||
CXWindowsUtil::CErrorLock::CErrorLock(
|
||||
bool* flag)
|
||||
{
|
||||
install(&CXWindowsUtil::CErrorLock::saveHandler, flag);
|
||||
}
|
||||
|
||||
CXWindowsUtil::CErrorLock::CErrorLock(ErrorHandler handler, void* data)
|
||||
CXWindowsUtil::CErrorLock::CErrorLock(
|
||||
ErrorHandler handler,
|
||||
void* data)
|
||||
{
|
||||
install(handler, data);
|
||||
}
|
||||
|
@ -201,8 +218,10 @@ CXWindowsUtil::CErrorLock::~CErrorLock()
|
|||
s_top = m_next;
|
||||
}
|
||||
|
||||
void CXWindowsUtil::CErrorLock::install(
|
||||
ErrorHandler handler, void* data)
|
||||
void
|
||||
CXWindowsUtil::CErrorLock::install(
|
||||
ErrorHandler handler,
|
||||
void* data)
|
||||
{
|
||||
m_handler = handler;
|
||||
m_userData = data;
|
||||
|
@ -212,8 +231,10 @@ void CXWindowsUtil::CErrorLock::install(
|
|||
s_top = this;
|
||||
}
|
||||
|
||||
int CXWindowsUtil::CErrorLock::internalHandler(
|
||||
Display* display, XErrorEvent* event)
|
||||
int
|
||||
CXWindowsUtil::CErrorLock::internalHandler(
|
||||
Display* display,
|
||||
XErrorEvent* event)
|
||||
{
|
||||
if (s_top != NULL && s_top->m_handler != NULL) {
|
||||
s_top->m_handler(display, event, s_top->m_userData);
|
||||
|
@ -221,14 +242,20 @@ int CXWindowsUtil::CErrorLock::internalHandler(
|
|||
return 0;
|
||||
}
|
||||
|
||||
void CXWindowsUtil::CErrorLock::ignoreHandler(
|
||||
Display*, XErrorEvent*, void*)
|
||||
void
|
||||
CXWindowsUtil::CErrorLock::ignoreHandler(
|
||||
Display*,
|
||||
XErrorEvent*,
|
||||
void*)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void CXWindowsUtil::CErrorLock::saveHandler(
|
||||
Display*, XErrorEvent*, void* flag)
|
||||
void
|
||||
CXWindowsUtil::CErrorLock::saveHandler(
|
||||
Display*,
|
||||
XErrorEvent*,
|
||||
void* flag)
|
||||
{
|
||||
*reinterpret_cast<bool*>(flag) = true;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef CXWINDOWSUTIL_H
|
||||
#define CXWINDOWSUTIL_H
|
||||
|
||||
#include "BasicTypes.h"
|
||||
#include "CString.h"
|
||||
#include "BasicTypes.h"
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
class CXWindowsUtil {
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
#ifndef IPLATFORM_H
|
||||
#define IPLATFORM_H
|
||||
|
||||
#include "BasicTypes.h"
|
||||
#include "CString.h"
|
||||
#include "IInterface.h"
|
||||
#include "CString.h"
|
||||
|
||||
class IPlatform : public IInterface {
|
||||
public:
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "CConfig.h"
|
||||
#include "ProtocolTypes.h"
|
||||
#include "XSocket.h"
|
||||
#include "stdistream.h"
|
||||
#include "stdostream.h"
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CConfig
|
||||
|
@ -18,7 +18,9 @@ CConfig::~CConfig()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
bool CConfig::addScreen(const CString& name)
|
||||
bool
|
||||
CConfig::addScreen(
|
||||
const CString& name)
|
||||
{
|
||||
// alias name must not exist
|
||||
if (m_nameToCanonicalName.find(name) != m_nameToCanonicalName.end()) {
|
||||
|
@ -34,7 +36,9 @@ bool CConfig::addScreen(const CString& name)
|
|||
return true;
|
||||
}
|
||||
|
||||
void CConfig::removeScreen(const CString& name)
|
||||
void
|
||||
CConfig::removeScreen(
|
||||
const CString& name)
|
||||
{
|
||||
// get canonical name and find cell
|
||||
CString canonical = getCanonicalName(name);
|
||||
|
@ -67,13 +71,16 @@ void CConfig::removeScreen(const CString& name)
|
|||
}
|
||||
}
|
||||
|
||||
void CConfig::removeAllScreens()
|
||||
void
|
||||
CConfig::removeAllScreens()
|
||||
{
|
||||
m_map.clear();
|
||||
m_nameToCanonicalName.clear();
|
||||
}
|
||||
|
||||
bool CConfig::addAlias(const CString& canonical,
|
||||
bool
|
||||
CConfig::addAlias(
|
||||
const CString& canonical,
|
||||
const CString& alias)
|
||||
{
|
||||
// alias name must not exist
|
||||
|
@ -92,7 +99,9 @@ bool CConfig::addAlias(const CString& canonical,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CConfig::removeAlias(const CString& alias)
|
||||
bool
|
||||
CConfig::removeAlias(
|
||||
const CString& alias)
|
||||
{
|
||||
// must not be a canonical name
|
||||
if (m_map.find(alias) != m_map.end()) {
|
||||
|
@ -111,7 +120,8 @@ bool CConfig::removeAlias(const CString& alias)
|
|||
return true;
|
||||
}
|
||||
|
||||
void CConfig::removeAllAliases()
|
||||
void
|
||||
CConfig::removeAllAliases()
|
||||
{
|
||||
// remove all names
|
||||
m_nameToCanonicalName.clear();
|
||||
|
@ -124,7 +134,9 @@ void CConfig::removeAllAliases()
|
|||
}
|
||||
}
|
||||
|
||||
bool CConfig::connect(const CString& srcName,
|
||||
bool
|
||||
CConfig::connect(
|
||||
const CString& srcName,
|
||||
EDirection srcSide,
|
||||
const CString& dstName)
|
||||
{
|
||||
|
@ -142,7 +154,9 @@ bool CConfig::connect(const CString& srcName,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CConfig::disconnect(const CString& srcName,
|
||||
bool
|
||||
CConfig::disconnect(
|
||||
const CString& srcName,
|
||||
EDirection srcSide)
|
||||
{
|
||||
// find source cell
|
||||
|
@ -157,17 +171,23 @@ bool CConfig::disconnect(const CString& srcName,
|
|||
return true;
|
||||
}
|
||||
|
||||
void CConfig::setSynergyAddress(const CNetworkAddress& addr)
|
||||
void
|
||||
CConfig::setSynergyAddress(
|
||||
const CNetworkAddress& addr)
|
||||
{
|
||||
m_synergyAddress = addr;
|
||||
}
|
||||
|
||||
void CConfig::setHTTPAddress(const CNetworkAddress& addr)
|
||||
void
|
||||
CConfig::setHTTPAddress(
|
||||
const CNetworkAddress& 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 ::= [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;
|
||||
}
|
||||
|
||||
CConfig::const_iterator CConfig::begin() const
|
||||
CConfig::const_iterator
|
||||
CConfig::begin() const
|
||||
{
|
||||
return const_iterator(m_map.begin());
|
||||
}
|
||||
|
||||
CConfig::const_iterator CConfig::end() const
|
||||
CConfig::const_iterator
|
||||
CConfig::end() const
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
bool CConfig::isCanonicalName(const CString& name) const
|
||||
bool
|
||||
CConfig::isCanonicalName(
|
||||
const CString& name) const
|
||||
{
|
||||
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);
|
||||
if (index == m_nameToCanonicalName.end()) {
|
||||
|
@ -242,7 +270,9 @@ CString CConfig::getCanonicalName(const CString& name) const
|
|||
}
|
||||
}
|
||||
|
||||
CString CConfig::getNeighbor(const CString& srcName,
|
||||
CString
|
||||
CConfig::getNeighbor(
|
||||
const CString& srcName,
|
||||
EDirection srcSide) const
|
||||
{
|
||||
// find source cell
|
||||
|
@ -256,23 +286,30 @@ CString CConfig::getNeighbor(const CString& srcName,
|
|||
srcSide - kFirstDirection]);
|
||||
}
|
||||
|
||||
const CNetworkAddress& CConfig::getSynergyAddress() const
|
||||
const CNetworkAddress&
|
||||
CConfig::getSynergyAddress() const
|
||||
{
|
||||
return m_synergyAddress;
|
||||
}
|
||||
|
||||
const CNetworkAddress& CConfig::getHTTPAddress() const
|
||||
const CNetworkAddress&
|
||||
CConfig::getHTTPAddress() const
|
||||
{
|
||||
return m_httpAddress;
|
||||
}
|
||||
|
||||
const char* CConfig::dirName(EDirection dir)
|
||||
const char*
|
||||
CConfig::dirName(
|
||||
EDirection dir)
|
||||
{
|
||||
static const char* s_name[] = { "left", "right", "top", "bottom" };
|
||||
return s_name[dir - kFirstDirection];
|
||||
}
|
||||
|
||||
bool CConfig::readLine(std::istream& s, CString& line)
|
||||
bool
|
||||
CConfig::readLine(
|
||||
std::istream& s,
|
||||
CString& line)
|
||||
{
|
||||
s >> std::ws;
|
||||
while (std::getline(s, line)) {
|
||||
|
@ -295,7 +332,9 @@ bool CConfig::readLine(std::istream& s, CString& line)
|
|||
return false;
|
||||
}
|
||||
|
||||
void CConfig::readSection(std::istream& s)
|
||||
void
|
||||
CConfig::readSection(
|
||||
std::istream& s)
|
||||
{
|
||||
static const char s_section[] = "section:";
|
||||
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 name;
|
||||
|
@ -398,7 +439,9 @@ void CConfig::readSectionNetwork(std::istream& s)
|
|||
throw XConfigRead("unexpected end of screens section");
|
||||
}
|
||||
|
||||
void CConfig::readSectionScreens(std::istream& s)
|
||||
void
|
||||
CConfig::readSectionScreens(
|
||||
std::istream& s)
|
||||
{
|
||||
CString line;
|
||||
CString name;
|
||||
|
@ -433,7 +476,9 @@ void CConfig::readSectionScreens(std::istream& s)
|
|||
throw XConfigRead("unexpected end of screens section");
|
||||
}
|
||||
|
||||
void CConfig::readSectionLinks(std::istream& s)
|
||||
void
|
||||
CConfig::readSectionLinks(
|
||||
std::istream& s)
|
||||
{
|
||||
CString line;
|
||||
CString screen;
|
||||
|
@ -513,7 +558,9 @@ void CConfig::readSectionLinks(std::istream& s)
|
|||
throw XConfigRead("unexpected end of links section");
|
||||
}
|
||||
|
||||
void CConfig::readSectionAliases(std::istream& s)
|
||||
void
|
||||
CConfig::readSectionAliases(
|
||||
std::istream& s)
|
||||
{
|
||||
CString line;
|
||||
CString screen;
|
||||
|
@ -559,7 +606,10 @@ void CConfig::readSectionAliases(std::istream& s)
|
|||
// 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
|
||||
|
||||
|
@ -571,7 +621,10 @@ std::istream& operator>>(std::istream& s, CConfig& config)
|
|||
return s;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& s, const CConfig& config)
|
||||
std::ostream&
|
||||
operator<<(
|
||||
std::ostream& s,
|
||||
const CConfig& config)
|
||||
{
|
||||
// network section
|
||||
s << "section: network" << std::endl;
|
||||
|
@ -657,7 +710,9 @@ std::ostream& operator<<(std::ostream& s, const CConfig& config)
|
|||
// CConfig I/O exceptions
|
||||
//
|
||||
|
||||
XConfigRead::XConfigRead(const CString& error) : m_error(error)
|
||||
XConfigRead::XConfigRead(
|
||||
const CString& error) :
|
||||
m_error(error)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
@ -667,7 +722,8 @@ XConfigRead::~XConfigRead()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
CString XConfigRead::getWhat() const throw()
|
||||
CString
|
||||
XConfigRead::getWhat() const throw()
|
||||
{
|
||||
return m_error;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
#ifndef CCONFIG_H
|
||||
#define CCONFIG_H
|
||||
|
||||
#include "BasicTypes.h"
|
||||
#include "CString.h"
|
||||
#include "CNetworkAddress.h"
|
||||
#include "XBase.h"
|
||||
#include <iosfwd>
|
||||
#include "stdmap.h"
|
||||
#include "stdset.h"
|
||||
#include <iosfwd>
|
||||
|
||||
class CConfig;
|
||||
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
#include "CHTTPServer.h"
|
||||
#include "CHTTPProtocol.h"
|
||||
#include "XHTTP.h"
|
||||
#include "CServer.h"
|
||||
#include "CConfig.h"
|
||||
#include "CLog.h"
|
||||
#include "XThread.h"
|
||||
#include "CHTTPProtocol.h"
|
||||
#include "CServer.h"
|
||||
#include "XHTTP.h"
|
||||
#include "ISocket.h"
|
||||
#include "XThread.h"
|
||||
#include "CLog.h"
|
||||
#include "stdset.h"
|
||||
#include "stdsstream.h"
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CHTTPServer
|
||||
|
@ -19,7 +18,9 @@
|
|||
// malicious client from causing us to use too much memory.
|
||||
const UInt32 CHTTPServer::s_maxRequestSize = 32768;
|
||||
|
||||
CHTTPServer::CHTTPServer(CServer* server) : m_server(server)
|
||||
CHTTPServer::CHTTPServer(
|
||||
CServer* server) :
|
||||
m_server(server)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
@ -29,7 +30,9 @@ CHTTPServer::~CHTTPServer()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
void CHTTPServer::processRequest(ISocket* socket)
|
||||
void
|
||||
CHTTPServer::processRequest(
|
||||
ISocket* socket)
|
||||
{
|
||||
assert(socket != NULL);
|
||||
|
||||
|
@ -88,7 +91,8 @@ void CHTTPServer::processRequest(ISocket* socket)
|
|||
}
|
||||
}
|
||||
|
||||
void CHTTPServer::doProcessRequest(
|
||||
void
|
||||
CHTTPServer::doProcessRequest(
|
||||
CHTTPRequest& request,
|
||||
CHTTPReply& reply)
|
||||
{
|
||||
|
@ -118,7 +122,8 @@ void CHTTPServer::doProcessRequest(
|
|||
}
|
||||
}
|
||||
|
||||
void CHTTPServer::doProcessGetEditMap(
|
||||
void
|
||||
CHTTPServer::doProcessGetEditMap(
|
||||
CHTTPRequest& /*request*/,
|
||||
CHTTPReply& reply)
|
||||
{
|
||||
|
@ -228,7 +233,8 @@ void CHTTPServer::doProcessGetEditMap(
|
|||
reply.m_body += s_editMapEpilog;
|
||||
}
|
||||
|
||||
void CHTTPServer::doProcessPostEditMap(
|
||||
void
|
||||
CHTTPServer::doProcessPostEditMap(
|
||||
CHTTPRequest& request,
|
||||
CHTTPReply& reply)
|
||||
{
|
||||
|
@ -323,8 +329,11 @@ void CHTTPServer::doProcessPostEditMap(
|
|||
}
|
||||
}
|
||||
|
||||
bool CHTTPServer::parseXY(
|
||||
const CString& xy, SInt32& x, SInt32& y)
|
||||
bool
|
||||
CHTTPServer::parseXY(
|
||||
const CString& xy,
|
||||
SInt32& x,
|
||||
SInt32& y)
|
||||
{
|
||||
std::istringstream s(xy);
|
||||
char delimiter;
|
||||
|
@ -339,7 +348,9 @@ bool CHTTPServer::parseXY(
|
|||
// CHTTPServer::CScreenArray
|
||||
//
|
||||
|
||||
CHTTPServer::CScreenArray::CScreenArray() : m_w(0), m_h(0)
|
||||
CHTTPServer::CScreenArray::CScreenArray() :
|
||||
m_w(0),
|
||||
m_h(0)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
@ -349,7 +360,10 @@ CHTTPServer::CScreenArray::~CScreenArray()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
void CHTTPServer::CScreenArray::resize(SInt32 w, SInt32 h)
|
||||
void
|
||||
CHTTPServer::CScreenArray::resize(
|
||||
SInt32 w,
|
||||
SInt32 h)
|
||||
{
|
||||
m_screens.clear();
|
||||
m_screens.resize(w * h);
|
||||
|
@ -357,7 +371,9 @@ void CHTTPServer::CScreenArray::resize(SInt32 w, SInt32 h)
|
|||
m_h = h;
|
||||
}
|
||||
|
||||
void CHTTPServer::CScreenArray::insertRow(SInt32 i)
|
||||
void
|
||||
CHTTPServer::CScreenArray::insertRow(
|
||||
SInt32 i)
|
||||
{
|
||||
assert(i >= 0 && i <= m_h);
|
||||
|
||||
|
@ -379,7 +395,9 @@ void CHTTPServer::CScreenArray::insertRow(SInt32 i)
|
|||
++m_h;
|
||||
}
|
||||
|
||||
void CHTTPServer::CScreenArray::insertColumn(SInt32 i)
|
||||
void
|
||||
CHTTPServer::CScreenArray::insertColumn(
|
||||
SInt32 i)
|
||||
{
|
||||
assert(i >= 0 && i <= m_w);
|
||||
|
||||
|
@ -399,7 +417,9 @@ void CHTTPServer::CScreenArray::insertColumn(SInt32 i)
|
|||
++m_w;
|
||||
}
|
||||
|
||||
void CHTTPServer::CScreenArray::eraseRow(SInt32 i)
|
||||
void
|
||||
CHTTPServer::CScreenArray::eraseRow(
|
||||
SInt32 i)
|
||||
{
|
||||
assert(i >= 0 && i < m_h);
|
||||
|
||||
|
@ -421,7 +441,9 @@ void CHTTPServer::CScreenArray::eraseRow(SInt32 i)
|
|||
--m_h;
|
||||
}
|
||||
|
||||
void CHTTPServer::CScreenArray::eraseColumn(SInt32 i)
|
||||
void
|
||||
CHTTPServer::CScreenArray::eraseColumn(
|
||||
SInt32 i)
|
||||
{
|
||||
assert(i >= 0 && i < m_w);
|
||||
|
||||
|
@ -441,7 +463,9 @@ void CHTTPServer::CScreenArray::eraseColumn(SInt32 i)
|
|||
--m_w;
|
||||
}
|
||||
|
||||
void CHTTPServer::CScreenArray::rotateRows(SInt32 i)
|
||||
void
|
||||
CHTTPServer::CScreenArray::rotateRows(
|
||||
SInt32 i)
|
||||
{
|
||||
// nothing to do if no rows
|
||||
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
|
||||
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());
|
||||
}
|
||||
|
||||
void CHTTPServer::CScreenArray::set(
|
||||
SInt32 x, SInt32 y, const CString& name)
|
||||
void
|
||||
CHTTPServer::CScreenArray::set(
|
||||
SInt32 x,
|
||||
SInt32 y,
|
||||
const CString& name)
|
||||
{
|
||||
assert(x >= 0 && x < m_w);
|
||||
assert(y >= 0 && y < m_h);
|
||||
|
@ -515,8 +547,10 @@ void CHTTPServer::CScreenArray::set(
|
|||
m_screens[x + y * m_w] = name;
|
||||
}
|
||||
|
||||
bool CHTTPServer::CScreenArray::isAllowed(
|
||||
SInt32 x, SInt32 y) const
|
||||
bool
|
||||
CHTTPServer::CScreenArray::isAllowed(
|
||||
SInt32 x,
|
||||
SInt32 y) const
|
||||
{
|
||||
assert(x >= 0 && x < m_w);
|
||||
assert(y >= 0 && y < m_h);
|
||||
|
@ -536,8 +570,10 @@ bool CHTTPServer::CScreenArray::isAllowed(
|
|||
return false;
|
||||
}
|
||||
|
||||
bool CHTTPServer::CScreenArray::isSet(
|
||||
SInt32 x, SInt32 y) const
|
||||
bool
|
||||
CHTTPServer::CScreenArray::isSet(
|
||||
SInt32 x,
|
||||
SInt32 y) const
|
||||
{
|
||||
assert(x >= 0 && x < m_w);
|
||||
assert(y >= 0 && y < m_h);
|
||||
|
@ -545,8 +581,10 @@ bool CHTTPServer::CScreenArray::isSet(
|
|||
return !m_screens[x + y * m_w].empty();
|
||||
}
|
||||
|
||||
CString CHTTPServer::CScreenArray::get(
|
||||
SInt32 x, SInt32 y) const
|
||||
CString
|
||||
CHTTPServer::CScreenArray::get(
|
||||
SInt32 x,
|
||||
SInt32 y) const
|
||||
{
|
||||
assert(x >= 0 && x < m_w);
|
||||
assert(y >= 0 && y < m_h);
|
||||
|
@ -554,9 +592,11 @@ CString CHTTPServer::CScreenArray::get(
|
|||
return m_screens[x + y * m_w];
|
||||
}
|
||||
|
||||
bool CHTTPServer::CScreenArray::find(
|
||||
bool
|
||||
CHTTPServer::CScreenArray::find(
|
||||
const CString& name,
|
||||
SInt32& xOut, SInt32& yOut) const
|
||||
SInt32& xOut,
|
||||
SInt32& yOut) const
|
||||
{
|
||||
for (SInt32 y = 0; y < m_h; ++y) {
|
||||
for (SInt32 x = 0; x < m_w; ++x) {
|
||||
|
@ -570,7 +610,8 @@ bool CHTTPServer::CScreenArray::find(
|
|||
return false;
|
||||
}
|
||||
|
||||
bool CHTTPServer::CScreenArray::isValid() const
|
||||
bool
|
||||
CHTTPServer::CScreenArray::isValid() const
|
||||
{
|
||||
SInt32 count = 0, isolated = 0;
|
||||
for (SInt32 y = 0; y < m_h; ++y) {
|
||||
|
@ -586,7 +627,8 @@ bool CHTTPServer::CScreenArray::isValid() const
|
|||
return (count <= 1 || isolated == 0);
|
||||
}
|
||||
|
||||
bool CHTTPServer::CScreenArray::convertFrom(
|
||||
bool
|
||||
CHTTPServer::CScreenArray::convertFrom(
|
||||
const CConfig& config)
|
||||
{
|
||||
typedef std::set<CString> ScreenSet;
|
||||
|
@ -717,7 +759,8 @@ bool CHTTPServer::CScreenArray::convertFrom(
|
|||
return true;
|
||||
}
|
||||
|
||||
void CHTTPServer::CScreenArray::convertTo(
|
||||
void
|
||||
CHTTPServer::CScreenArray::convertTo(
|
||||
CConfig& config) const
|
||||
{
|
||||
config.removeAllScreens();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef CHTTPSERVER_H
|
||||
#define CHTTPSERVER_H
|
||||
|
||||
#include "BasicTypes.h"
|
||||
#include "CString.h"
|
||||
#include "BasicTypes.h"
|
||||
#include "stdvector.h"
|
||||
|
||||
class CServer;
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#include "CMSWindowsPrimaryScreen.h"
|
||||
#include "CMSWindowsClipboard.h"
|
||||
#include "CServer.h"
|
||||
#include "CMSWindowsClipboard.h"
|
||||
#include "CPlatform.h"
|
||||
#include "XScreen.h"
|
||||
#include "XSynergy.h"
|
||||
#include "CLog.h"
|
||||
#include "CThread.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "CLog.h"
|
||||
#include <cstring>
|
||||
|
||||
//
|
||||
// CMSWindowsPrimaryScreen
|
||||
|
@ -61,7 +60,8 @@ CMSWindowsPrimaryScreen::~CMSWindowsPrimaryScreen()
|
|||
FreeLibrary(m_hookLibrary);
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::run()
|
||||
void
|
||||
CMSWindowsPrimaryScreen::run()
|
||||
{
|
||||
// must call run() from same thread as open()
|
||||
assert(m_threadID == GetCurrentThreadId());
|
||||
|
@ -87,12 +87,15 @@ void CMSWindowsPrimaryScreen::run()
|
|||
}
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::stop()
|
||||
void
|
||||
CMSWindowsPrimaryScreen::stop()
|
||||
{
|
||||
doStop();
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::open(CServer* server)
|
||||
void
|
||||
CMSWindowsPrimaryScreen::open(
|
||||
CServer* server)
|
||||
{
|
||||
assert(m_server == NULL);
|
||||
assert(server != NULL);
|
||||
|
@ -126,7 +129,8 @@ void CMSWindowsPrimaryScreen::open(CServer* server)
|
|||
enterNoWarp();
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::close()
|
||||
void
|
||||
CMSWindowsPrimaryScreen::close()
|
||||
{
|
||||
assert(m_server != NULL);
|
||||
|
||||
|
@ -137,7 +141,10 @@ void CMSWindowsPrimaryScreen::close()
|
|||
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));
|
||||
assert(m_active == true);
|
||||
|
@ -149,7 +156,8 @@ void CMSWindowsPrimaryScreen::enter(SInt32 x, SInt32 y)
|
|||
warpCursor(x, y);
|
||||
}
|
||||
|
||||
bool CMSWindowsPrimaryScreen::leave()
|
||||
bool
|
||||
CMSWindowsPrimaryScreen::leave()
|
||||
{
|
||||
log((CLOG_INFO "leaving primary"));
|
||||
assert(m_active == false);
|
||||
|
@ -219,7 +227,8 @@ bool CMSWindowsPrimaryScreen::leave()
|
|||
return true;
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::onConfigure()
|
||||
void
|
||||
CMSWindowsPrimaryScreen::onConfigure()
|
||||
{
|
||||
if ((m_is95Family || m_desk != NULL) && !m_active) {
|
||||
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
|
||||
SetCursorPos(x, y);
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::setClipboard(
|
||||
ClipboardID /*id*/, const IClipboard* src)
|
||||
void
|
||||
CMSWindowsPrimaryScreen::setClipboard(
|
||||
ClipboardID /*id*/,
|
||||
const IClipboard* src)
|
||||
{
|
||||
assert(m_window != NULL);
|
||||
|
||||
|
@ -244,7 +258,8 @@ void CMSWindowsPrimaryScreen::setClipboard(
|
|||
CClipboard::copy(&dst, src);
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::grabClipboard(
|
||||
void
|
||||
CMSWindowsPrimaryScreen::grabClipboard(
|
||||
ClipboardID /*id*/)
|
||||
{
|
||||
assert(m_window != NULL);
|
||||
|
@ -255,19 +270,24 @@ void CMSWindowsPrimaryScreen::grabClipboard(
|
|||
}
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::getSize(
|
||||
SInt32* width, SInt32* height) const
|
||||
void
|
||||
CMSWindowsPrimaryScreen::getSize(
|
||||
SInt32* width,
|
||||
SInt32* height) const
|
||||
{
|
||||
getScreenSize(width, height);
|
||||
}
|
||||
|
||||
SInt32 CMSWindowsPrimaryScreen::getJumpZoneSize() const
|
||||
SInt32
|
||||
CMSWindowsPrimaryScreen::getJumpZoneSize() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::getClipboard(
|
||||
ClipboardID /*id*/, IClipboard* dst) const
|
||||
void
|
||||
CMSWindowsPrimaryScreen::getClipboard(
|
||||
ClipboardID /*id*/,
|
||||
IClipboard* dst) const
|
||||
{
|
||||
assert(m_window != NULL);
|
||||
|
||||
|
@ -275,7 +295,8 @@ void CMSWindowsPrimaryScreen::getClipboard(
|
|||
CClipboard::copy(dst, &src);
|
||||
}
|
||||
|
||||
KeyModifierMask CMSWindowsPrimaryScreen::getToggleMask() const
|
||||
KeyModifierMask
|
||||
CMSWindowsPrimaryScreen::getToggleMask() const
|
||||
{
|
||||
KeyModifierMask mask = 0;
|
||||
if ((GetKeyState(VK_CAPITAL) & 0x01) != 0)
|
||||
|
@ -287,7 +308,8 @@ KeyModifierMask CMSWindowsPrimaryScreen::getToggleMask() const
|
|||
return mask;
|
||||
}
|
||||
|
||||
bool CMSWindowsPrimaryScreen::isLockedToScreen() const
|
||||
bool
|
||||
CMSWindowsPrimaryScreen::isLockedToScreen() const
|
||||
{
|
||||
// check buttons
|
||||
if (GetAsyncKeyState(VK_LBUTTON) < 0 ||
|
||||
|
@ -310,7 +332,8 @@ bool CMSWindowsPrimaryScreen::isLockedToScreen() const
|
|||
return false;
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::onOpenDisplay()
|
||||
void
|
||||
CMSWindowsPrimaryScreen::onOpenDisplay()
|
||||
{
|
||||
assert(m_window == NULL);
|
||||
assert(m_server != NULL);
|
||||
|
@ -331,7 +354,8 @@ void CMSWindowsPrimaryScreen::onOpenDisplay()
|
|||
}
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::onCloseDisplay()
|
||||
void
|
||||
CMSWindowsPrimaryScreen::onCloseDisplay()
|
||||
{
|
||||
// disconnect from desktop
|
||||
if (m_is95Family) {
|
||||
|
@ -348,7 +372,9 @@ void CMSWindowsPrimaryScreen::onCloseDisplay()
|
|||
assert(m_desk == NULL);
|
||||
}
|
||||
|
||||
bool CMSWindowsPrimaryScreen::onPreTranslate(MSG* msg)
|
||||
bool
|
||||
CMSWindowsPrimaryScreen::onPreTranslate(
|
||||
MSG* msg)
|
||||
{
|
||||
// handle event
|
||||
switch (msg->message) {
|
||||
|
@ -477,9 +503,12 @@ bool CMSWindowsPrimaryScreen::onPreTranslate(MSG* msg)
|
|||
return false;
|
||||
}
|
||||
|
||||
LRESULT CMSWindowsPrimaryScreen::onEvent(
|
||||
HWND hwnd, UINT msg,
|
||||
WPARAM wParam, LPARAM lParam)
|
||||
LRESULT
|
||||
CMSWindowsPrimaryScreen::onEvent(
|
||||
HWND hwnd,
|
||||
UINT msg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
switch (msg) {
|
||||
case WM_QUERYENDSESSION:
|
||||
|
@ -571,7 +600,8 @@ LRESULT CMSWindowsPrimaryScreen::onEvent(
|
|||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::enterNoWarp()
|
||||
void
|
||||
CMSWindowsPrimaryScreen::enterNoWarp()
|
||||
{
|
||||
// not active anymore
|
||||
m_active = false;
|
||||
|
@ -595,7 +625,8 @@ void CMSWindowsPrimaryScreen::enterNoWarp()
|
|||
nextMark();
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::onEnter()
|
||||
void
|
||||
CMSWindowsPrimaryScreen::onEnter()
|
||||
{
|
||||
// restore the active window and hide our window. we can only set
|
||||
// the active window for another thread if we first attach our input
|
||||
|
@ -613,7 +644,8 @@ void CMSWindowsPrimaryScreen::onEnter()
|
|||
ShowWindow(m_window, SW_HIDE);
|
||||
}
|
||||
|
||||
bool CMSWindowsPrimaryScreen::onLeave()
|
||||
bool
|
||||
CMSWindowsPrimaryScreen::onLeave()
|
||||
{
|
||||
// remember the active window before we leave. GetActiveWindow()
|
||||
// will only return the active window for the thread's queue (i.e.
|
||||
|
@ -643,7 +675,8 @@ bool CMSWindowsPrimaryScreen::onLeave()
|
|||
return true;
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::nextMark()
|
||||
void
|
||||
CMSWindowsPrimaryScreen::nextMark()
|
||||
{
|
||||
// next mark
|
||||
++m_mark;
|
||||
|
@ -652,7 +685,8 @@ void CMSWindowsPrimaryScreen::nextMark()
|
|||
PostThreadMessage(m_threadID, SYNERGY_MSG_MARK, m_mark, 0);
|
||||
}
|
||||
|
||||
bool CMSWindowsPrimaryScreen::openDesktop()
|
||||
bool
|
||||
CMSWindowsPrimaryScreen::openDesktop()
|
||||
{
|
||||
// install hooks
|
||||
m_install(m_threadID);
|
||||
|
@ -687,7 +721,8 @@ bool CMSWindowsPrimaryScreen::openDesktop()
|
|||
return true;
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::closeDesktop()
|
||||
void
|
||||
CMSWindowsPrimaryScreen::closeDesktop()
|
||||
{
|
||||
// destroy old window
|
||||
if (m_window != NULL) {
|
||||
|
@ -714,7 +749,9 @@ void CMSWindowsPrimaryScreen::closeDesktop()
|
|||
m_uninstall();
|
||||
}
|
||||
|
||||
bool CMSWindowsPrimaryScreen::switchDesktop(HDESK desk)
|
||||
bool
|
||||
CMSWindowsPrimaryScreen::switchDesktop(
|
||||
HDESK desk)
|
||||
{
|
||||
// did we own the clipboard?
|
||||
bool ownClipboard = (m_clipboardOwner == m_window);
|
||||
|
@ -818,7 +855,8 @@ bool CMSWindowsPrimaryScreen::switchDesktop(HDESK desk)
|
|||
return true;
|
||||
}
|
||||
|
||||
CString CMSWindowsPrimaryScreen::getCurrentDesktopName() const
|
||||
CString
|
||||
CMSWindowsPrimaryScreen::getCurrentDesktopName() const
|
||||
{
|
||||
return m_deskName;
|
||||
}
|
||||
|
@ -1083,8 +1121,10 @@ static const KeyID g_virtualKey[] =
|
|||
/* 0xff */ kKeyNone // reserved
|
||||
};
|
||||
|
||||
KeyID CMSWindowsPrimaryScreen::mapKey(
|
||||
WPARAM vkCode, LPARAM info,
|
||||
KeyID
|
||||
CMSWindowsPrimaryScreen::mapKey(
|
||||
WPARAM vkCode,
|
||||
LPARAM info,
|
||||
KeyModifierMask* maskOut)
|
||||
{
|
||||
// note: known microsoft bugs
|
||||
|
@ -1101,25 +1141,32 @@ KeyID CMSWindowsPrimaryScreen::mapKey(
|
|||
KeyModifierMask mask = 0;
|
||||
if (((m_keys[VK_LSHIFT] |
|
||||
m_keys[VK_RSHIFT] |
|
||||
m_keys[VK_SHIFT]) & 0x80) != 0)
|
||||
m_keys[VK_SHIFT]) & 0x80) != 0) {
|
||||
mask |= KeyModifierShift;
|
||||
}
|
||||
if (((m_keys[VK_LCONTROL] |
|
||||
m_keys[VK_RCONTROL] |
|
||||
m_keys[VK_CONTROL]) & 0x80) != 0)
|
||||
m_keys[VK_CONTROL]) & 0x80) != 0) {
|
||||
mask |= KeyModifierControl;
|
||||
}
|
||||
if (((m_keys[VK_LMENU] |
|
||||
m_keys[VK_RMENU] |
|
||||
m_keys[VK_MENU]) & 0x80) != 0)
|
||||
m_keys[VK_MENU]) & 0x80) != 0) {
|
||||
mask |= KeyModifierAlt;
|
||||
}
|
||||
if (((m_keys[VK_LWIN] |
|
||||
m_keys[VK_RWIN]) & 0x80) != 0)
|
||||
m_keys[VK_RWIN]) & 0x80) != 0) {
|
||||
mask |= KeyModifierMeta;
|
||||
if ((m_keys[VK_CAPITAL] & 0x01) != 0)
|
||||
}
|
||||
if ((m_keys[VK_CAPITAL] & 0x01) != 0) {
|
||||
mask |= KeyModifierCapsLock;
|
||||
if ((m_keys[VK_NUMLOCK] & 0x01) != 0)
|
||||
}
|
||||
if ((m_keys[VK_NUMLOCK] & 0x01) != 0) {
|
||||
mask |= KeyModifierNumLock;
|
||||
if ((m_keys[VK_SCROLL] & 0x01) != 0)
|
||||
}
|
||||
if ((m_keys[VK_SCROLL] & 0x01) != 0) {
|
||||
mask |= KeyModifierScrollLock;
|
||||
}
|
||||
*maskOut = 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);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// MapVirtualKey() appears to map VK_LWIN, VK_RWIN, VK_APPS to
|
||||
// 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;
|
||||
}
|
||||
|
||||
// if MapVirtualKey failed then use original virtual key
|
||||
else if (vkCode2 == 0)
|
||||
else if (vkCode2 == 0) {
|
||||
vkCode2 = vkCode;
|
||||
}
|
||||
|
||||
// sadly, win32 will not distinguish between the left and right
|
||||
// control and alt keys using the above function. however, we
|
||||
|
@ -1223,12 +1273,16 @@ KeyID CMSWindowsPrimaryScreen::mapKey(
|
|||
// set shift state required to generate key
|
||||
BYTE keys[256];
|
||||
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;
|
||||
if (vkCode & 0x0100)
|
||||
}
|
||||
if (vkCode & 0x0100) {
|
||||
keys[VK_CONTROL] = 0x80;
|
||||
if (vkCode & 0x0100)
|
||||
}
|
||||
if (vkCode & 0x0100) {
|
||||
keys[VK_MENU] = 0x80;
|
||||
}
|
||||
|
||||
// strip shift state off of virtual key code
|
||||
vkCode &= 0x00ff;
|
||||
|
@ -1245,7 +1299,8 @@ KeyID CMSWindowsPrimaryScreen::mapKey(
|
|||
return kKeyNone;
|
||||
}
|
||||
|
||||
ButtonID CMSWindowsPrimaryScreen::mapButton(
|
||||
ButtonID
|
||||
CMSWindowsPrimaryScreen::mapButton(
|
||||
WPARAM button) const
|
||||
{
|
||||
switch (button) {
|
||||
|
@ -1266,7 +1321,8 @@ ButtonID CMSWindowsPrimaryScreen::mapButton(
|
|||
}
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::updateKeys()
|
||||
void
|
||||
CMSWindowsPrimaryScreen::updateKeys()
|
||||
{
|
||||
// not using GetKeyboardState() because that doesn't seem to give
|
||||
// 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));
|
||||
}
|
||||
|
||||
void CMSWindowsPrimaryScreen::updateKey(
|
||||
UINT vkCode, bool press)
|
||||
void
|
||||
CMSWindowsPrimaryScreen::updateKey(
|
||||
UINT vkCode,
|
||||
bool press)
|
||||
{
|
||||
if (press) {
|
||||
switch (vkCode) {
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
#define CMSWINDOWSPRIMARYSCREEN_H
|
||||
|
||||
#include "CMSWindowsScreen.h"
|
||||
#include "IPrimaryScreen.h"
|
||||
#include "MouseTypes.h"
|
||||
#include "CString.h"
|
||||
#include "CSynergyHook.h"
|
||||
#include "MouseTypes.h"
|
||||
#include "IPrimaryScreen.h"
|
||||
#include "CString.h"
|
||||
|
||||
class CMSWindowsPrimaryScreen : public CMSWindowsScreen, public IPrimaryScreen {
|
||||
public:
|
||||
|
|
|
@ -2,26 +2,25 @@
|
|||
#include "CHTTPServer.h"
|
||||
#include "CInputPacketStream.h"
|
||||
#include "COutputPacketStream.h"
|
||||
#include "CServerProtocol.h"
|
||||
#include "CProtocolUtil.h"
|
||||
#include "CServerProtocol.h"
|
||||
#include "IPrimaryScreen.h"
|
||||
#include "ISocketFactory.h"
|
||||
#include "ProtocolTypes.h"
|
||||
#include "XScreen.h"
|
||||
#include "XSynergy.h"
|
||||
#include "CNetworkAddress.h"
|
||||
#include "ISocket.h"
|
||||
#include "IListenSocket.h"
|
||||
#include "ISocket.h"
|
||||
#include "ISocketFactory.h"
|
||||
#include "XSocket.h"
|
||||
#include "CLock.h"
|
||||
#include "CLog.h"
|
||||
#include "CThread.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 <assert.h>
|
||||
#include "CFunctionJob.h"
|
||||
#include "CLog.h"
|
||||
#include "CStopwatch.h"
|
||||
#include "TMethodJob.h"
|
||||
#include <memory>
|
||||
|
||||
// hack to work around operator=() bug in STL in g++ prior to v3
|
||||
|
@ -31,23 +30,14 @@
|
|||
#define assign(_dst, _src, _type) _dst = std::auto_ptr<_type >(_src)
|
||||
#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
|
||||
//
|
||||
|
||||
const SInt32 CServer::s_httpMaxSimultaneousRequests = 3;
|
||||
|
||||
CServer::CServer(const CString& serverName) :
|
||||
CServer::CServer(
|
||||
const CString& serverName) :
|
||||
m_name(serverName),
|
||||
m_cleanupSize(&m_mutex, 0),
|
||||
m_primary(NULL),
|
||||
|
@ -55,8 +45,7 @@ CServer::CServer(const CString& serverName) :
|
|||
m_primaryInfo(NULL),
|
||||
m_seqNum(0),
|
||||
m_httpServer(NULL),
|
||||
m_httpAvailable(&m_mutex,
|
||||
s_httpMaxSimultaneousRequests)
|
||||
m_httpAvailable(&m_mutex, s_httpMaxSimultaneousRequests)
|
||||
{
|
||||
m_socketFactory = NULL;
|
||||
m_securityFactory = NULL;
|
||||
|
@ -68,7 +57,8 @@ CServer::~CServer()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
void CServer::run()
|
||||
void
|
||||
CServer::run()
|
||||
{
|
||||
try {
|
||||
log((CLOG_NOTE "starting server"));
|
||||
|
@ -149,12 +139,14 @@ void CServer::run()
|
|||
}
|
||||
}
|
||||
|
||||
void CServer::quit()
|
||||
void
|
||||
CServer::quit()
|
||||
{
|
||||
m_primary->stop();
|
||||
}
|
||||
|
||||
void CServer::shutdown()
|
||||
void
|
||||
CServer::shutdown()
|
||||
{
|
||||
// stop all running threads but don't wait too long since some
|
||||
// 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
|
||||
}
|
||||
|
||||
bool CServer::setConfig(const CConfig& config)
|
||||
bool
|
||||
CServer::setConfig(
|
||||
const CConfig& config)
|
||||
{
|
||||
typedef std::vector<CThread> CThreads;
|
||||
CThreads threads;
|
||||
|
@ -228,12 +222,15 @@ bool CServer::setConfig(const CConfig& config)
|
|||
return true;
|
||||
}
|
||||
|
||||
CString CServer::getPrimaryScreenName() const
|
||||
CString
|
||||
CServer::getPrimaryScreenName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void CServer::getConfig(CConfig* config) const
|
||||
void
|
||||
CServer::getConfig(
|
||||
CConfig* config) const
|
||||
{
|
||||
assert(config != NULL);
|
||||
|
||||
|
@ -241,7 +238,8 @@ void CServer::getConfig(CConfig* config) const
|
|||
*config = m_config;
|
||||
}
|
||||
|
||||
UInt32 CServer::getActivePrimarySides() const
|
||||
UInt32
|
||||
CServer::getActivePrimarySides() const
|
||||
{
|
||||
UInt32 sides = 0;
|
||||
CLock lock(&m_mutex);
|
||||
|
@ -264,26 +262,40 @@ UInt32 CServer::getActivePrimarySides() const
|
|||
return sides;
|
||||
}
|
||||
|
||||
void CServer::setInfo(
|
||||
SInt32 w, SInt32 h, SInt32 zoneSize,
|
||||
SInt32 x, SInt32 y)
|
||||
void
|
||||
CServer::setInfo(
|
||||
SInt32 w,
|
||||
SInt32 h,
|
||||
SInt32 zoneSize,
|
||||
SInt32 x,
|
||||
SInt32 y)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
assert(m_primaryInfo != NULL);
|
||||
setInfoNoLock(m_primaryInfo->m_name, w, h, zoneSize, x, y);
|
||||
}
|
||||
|
||||
void CServer::setInfo(const CString& client,
|
||||
SInt32 w, SInt32 h, SInt32 zoneSize,
|
||||
SInt32 x, SInt32 y)
|
||||
void
|
||||
CServer::setInfo(
|
||||
const CString& client,
|
||||
SInt32 w,
|
||||
SInt32 h,
|
||||
SInt32 zoneSize,
|
||||
SInt32 x,
|
||||
SInt32 y)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
setInfoNoLock(client, w, h, zoneSize, x, y);
|
||||
}
|
||||
|
||||
void CServer::setInfoNoLock(const CString& screen,
|
||||
SInt32 w, SInt32 h, SInt32 zoneSize,
|
||||
SInt32 x, SInt32 y)
|
||||
void
|
||||
CServer::setInfoNoLock(
|
||||
const CString& screen,
|
||||
SInt32 w,
|
||||
SInt32 h,
|
||||
SInt32 zoneSize,
|
||||
SInt32 x,
|
||||
SInt32 y)
|
||||
{
|
||||
assert(!screen.empty());
|
||||
assert(w > 0);
|
||||
|
@ -327,23 +339,29 @@ void CServer::setInfoNoLock(const CString& screen,
|
|||
}
|
||||
}
|
||||
|
||||
void CServer::grabClipboard(ClipboardID id)
|
||||
void
|
||||
CServer::grabClipboard(
|
||||
ClipboardID id)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
assert(m_primaryInfo != NULL);
|
||||
grabClipboardNoLock(id, 0, m_primaryInfo->m_name);
|
||||
}
|
||||
|
||||
void CServer::grabClipboard(
|
||||
ClipboardID id, UInt32 seqNum,
|
||||
void
|
||||
CServer::grabClipboard(
|
||||
ClipboardID id,
|
||||
UInt32 seqNum,
|
||||
const CString& client)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
grabClipboardNoLock(id, seqNum, client);
|
||||
}
|
||||
|
||||
void CServer::grabClipboardNoLock(
|
||||
ClipboardID id, UInt32 seqNum,
|
||||
void
|
||||
CServer::grabClipboardNoLock(
|
||||
ClipboardID id,
|
||||
UInt32 seqNum,
|
||||
const CString& screen)
|
||||
{
|
||||
// note -- must be locked on entry
|
||||
|
@ -402,8 +420,11 @@ void CServer::grabClipboardNoLock(
|
|||
}
|
||||
}
|
||||
|
||||
void CServer::setClipboard(ClipboardID id,
|
||||
UInt32 seqNum, const CString& data)
|
||||
void
|
||||
CServer::setClipboard(
|
||||
ClipboardID id,
|
||||
UInt32 seqNum,
|
||||
const CString& data)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
CClipboardInfo& clipboard = m_clipboards[id];
|
||||
|
@ -433,13 +454,19 @@ void CServer::setClipboard(ClipboardID id,
|
|||
sendClipboard(id);
|
||||
}
|
||||
|
||||
bool CServer::onCommandKey(KeyID /*id*/,
|
||||
KeyModifierMask /*mask*/, bool /*down*/)
|
||||
bool
|
||||
CServer::onCommandKey(
|
||||
KeyID /*id*/,
|
||||
KeyModifierMask /*mask*/,
|
||||
bool /*down*/)
|
||||
{
|
||||
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));
|
||||
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));
|
||||
CLock lock(&m_mutex);
|
||||
|
@ -473,8 +503,11 @@ void CServer::onKeyUp(KeyID id, KeyModifierMask mask)
|
|||
}
|
||||
}
|
||||
|
||||
void CServer::onKeyRepeat(
|
||||
KeyID id, KeyModifierMask mask, SInt32 count)
|
||||
void
|
||||
CServer::onKeyRepeat(
|
||||
KeyID id,
|
||||
KeyModifierMask mask,
|
||||
SInt32 count)
|
||||
{
|
||||
log((CLOG_DEBUG1 "onKeyRepeat id=%d mask=0x%04x count=%d", id, mask, count));
|
||||
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));
|
||||
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));
|
||||
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));
|
||||
CLock lock(&m_mutex);
|
||||
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
|
||||
assert(m_active != NULL);
|
||||
|
@ -577,15 +620,20 @@ bool CServer::onMouseMovePrimaryNoLock(SInt32 x, SInt32 y)
|
|||
return true;
|
||||
}
|
||||
|
||||
void CServer::onMouseMoveSecondary(SInt32 dx, SInt32 dy)
|
||||
void
|
||||
CServer::onMouseMoveSecondary(
|
||||
SInt32 dx,
|
||||
SInt32 dy)
|
||||
{
|
||||
log((CLOG_DEBUG2 "onMouseMoveSecondary %+d,%+d", dx, dy));
|
||||
CLock lock(&m_mutex);
|
||||
onMouseMoveSecondaryNoLock(dx, dy);
|
||||
}
|
||||
|
||||
void CServer::onMouseMoveSecondaryNoLock(
|
||||
SInt32 dx, SInt32 dy)
|
||||
void
|
||||
CServer::onMouseMoveSecondaryNoLock(
|
||||
SInt32 dx,
|
||||
SInt32 dy)
|
||||
{
|
||||
// mouse move on secondary (client's) screen
|
||||
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));
|
||||
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);
|
||||
return isLockedToScreenNoLock();
|
||||
}
|
||||
|
||||
bool CServer::isLockedToScreenNoLock() const
|
||||
bool
|
||||
CServer::isLockedToScreenNoLock() const
|
||||
{
|
||||
// locked if primary says we're locked
|
||||
if (m_primary->isLockedToScreen()) {
|
||||
|
@ -721,8 +773,11 @@ bool CServer::isLockedToScreenNoLock() const
|
|||
return false;
|
||||
}
|
||||
|
||||
void CServer::switchScreen(CScreenInfo* dst,
|
||||
SInt32 x, SInt32 y)
|
||||
void
|
||||
CServer::switchScreen(
|
||||
CScreenInfo* dst,
|
||||
SInt32 x,
|
||||
SInt32 y)
|
||||
{
|
||||
assert(dst != NULL);
|
||||
assert(x >= 0 && y >= 0 && x < dst->m_width && y < dst->m_height);
|
||||
|
@ -789,7 +844,9 @@ void CServer::switchScreen(CScreenInfo* dst,
|
|||
}
|
||||
}
|
||||
|
||||
CServer::CScreenInfo* CServer::getNeighbor(CScreenInfo* src,
|
||||
CServer::CScreenInfo*
|
||||
CServer::getNeighbor(
|
||||
CScreenInfo* src,
|
||||
CConfig::EDirection dir) const
|
||||
{
|
||||
assert(src != NULL);
|
||||
|
@ -821,9 +878,12 @@ CServer::CScreenInfo* CServer::getNeighbor(CScreenInfo* src,
|
|||
}
|
||||
}
|
||||
|
||||
CServer::CScreenInfo* CServer::getNeighbor(CScreenInfo* src,
|
||||
CServer::CScreenInfo*
|
||||
CServer::getNeighbor(
|
||||
CScreenInfo* src,
|
||||
CConfig::EDirection srcSide,
|
||||
SInt32& x, SInt32& y) const
|
||||
SInt32& x,
|
||||
SInt32& y) const
|
||||
{
|
||||
assert(src != NULL);
|
||||
|
||||
|
@ -936,10 +996,13 @@ CServer::CScreenInfo* CServer::getNeighbor(CScreenInfo* src,
|
|||
return lastGoodScreen;
|
||||
}
|
||||
|
||||
void CServer::mapPosition(CScreenInfo* src,
|
||||
void
|
||||
CServer::mapPosition(
|
||||
CScreenInfo* src,
|
||||
CConfig::EDirection srcSide,
|
||||
CScreenInfo* dst,
|
||||
SInt32& x, SInt32& y) const
|
||||
SInt32& x,
|
||||
SInt32& y) const
|
||||
{
|
||||
assert(src != NULL);
|
||||
assert(dst != NULL);
|
||||
|
@ -949,32 +1012,39 @@ void CServer::mapPosition(CScreenInfo* src,
|
|||
switch (srcSide) {
|
||||
case CConfig::kLeft:
|
||||
case CConfig::kRight:
|
||||
if (y < 0)
|
||||
if (y < 0) {
|
||||
y = 0;
|
||||
else if (y >= src->m_height)
|
||||
}
|
||||
else if (y >= src->m_height) {
|
||||
y = dst->m_height - 1;
|
||||
else
|
||||
}
|
||||
else {
|
||||
y = static_cast<SInt32>(0.5 + y *
|
||||
static_cast<double>(dst->m_height - 1) /
|
||||
(src->m_height - 1));
|
||||
}
|
||||
break;
|
||||
|
||||
case CConfig::kTop:
|
||||
case CConfig::kBottom:
|
||||
if (x < 0)
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
else if (x >= src->m_width)
|
||||
}
|
||||
else if (x >= src->m_width) {
|
||||
x = dst->m_width - 1;
|
||||
else
|
||||
}
|
||||
else {
|
||||
x = static_cast<SInt32>(0.5 + x *
|
||||
static_cast<double>(dst->m_width - 1) /
|
||||
(src->m_width - 1));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#include "CTCPListenSocket.h"
|
||||
void CServer::acceptClients(void*)
|
||||
void
|
||||
CServer::acceptClients(void*)
|
||||
{
|
||||
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"));
|
||||
|
||||
|
@ -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"));
|
||||
|
||||
|
@ -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
|
||||
// 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();
|
||||
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
|
||||
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];
|
||||
|
||||
|
@ -1339,7 +1420,8 @@ void CServer::updatePrimaryClipboard(ClipboardID id)
|
|||
#elif defined(CONFIG_PLATFORM_UNIX)
|
||||
#include "CXWindowsPrimaryScreen.h"
|
||||
#endif
|
||||
void CServer::openPrimaryScreen()
|
||||
void
|
||||
CServer::openPrimaryScreen()
|
||||
{
|
||||
assert(m_primary == NULL);
|
||||
|
||||
|
@ -1387,7 +1469,8 @@ void CServer::openPrimaryScreen()
|
|||
}
|
||||
}
|
||||
|
||||
void CServer::closePrimaryScreen()
|
||||
void
|
||||
CServer::closePrimaryScreen()
|
||||
{
|
||||
assert(m_primary != NULL);
|
||||
|
||||
|
@ -1410,14 +1493,18 @@ void CServer::closePrimaryScreen()
|
|||
m_primary = NULL;
|
||||
}
|
||||
|
||||
void CServer::addCleanupThread(const CThread& thread)
|
||||
void
|
||||
CServer::addCleanupThread(
|
||||
const CThread& thread)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
m_cleanupList.insert(m_cleanupList.begin(), new CThread(thread));
|
||||
m_cleanupSize = m_cleanupSize + 1;
|
||||
}
|
||||
|
||||
void CServer::removeCleanupThread(const CThread& thread)
|
||||
void
|
||||
CServer::removeCleanupThread(
|
||||
const CThread& thread)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
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"));
|
||||
|
||||
|
@ -1474,8 +1563,10 @@ void CServer::cleanupThreads(double timeout)
|
|||
log((CLOG_DEBUG1 "cleaned up threads"));
|
||||
}
|
||||
|
||||
CServer::CScreenInfo* CServer::addConnection(
|
||||
const CString& name, IServerProtocol* protocol)
|
||||
CServer::CScreenInfo*
|
||||
CServer::addConnection(
|
||||
const CString& name,
|
||||
IServerProtocol* protocol)
|
||||
{
|
||||
log((CLOG_DEBUG "adding connection \"%s\"", name.c_str()));
|
||||
|
||||
|
@ -1499,7 +1590,9 @@ CServer::CScreenInfo* CServer::addConnection(
|
|||
return newScreen;
|
||||
}
|
||||
|
||||
void CServer::removeConnection(const CString& name)
|
||||
void
|
||||
CServer::removeConnection(
|
||||
const CString& name)
|
||||
{
|
||||
log((CLOG_DEBUG "removing connection \"%s\"", name.c_str()));
|
||||
CLock lock(&m_mutex);
|
||||
|
@ -1534,7 +1627,9 @@ void CServer::removeConnection(const CString& name)
|
|||
// CServer::CCleanupNote
|
||||
//
|
||||
|
||||
CServer::CCleanupNote::CCleanupNote(CServer* server) : m_server(server)
|
||||
CServer::CCleanupNote::CCleanupNote(
|
||||
CServer* server) :
|
||||
m_server(server)
|
||||
{
|
||||
assert(m_server != NULL);
|
||||
m_server->addCleanupThread(CThread::getCurrentThread());
|
||||
|
@ -1550,7 +1645,8 @@ CServer::CCleanupNote::~CCleanupNote()
|
|||
// CServer::CConnectionNote
|
||||
//
|
||||
|
||||
CServer::CConnectionNote::CConnectionNote(CServer* server,
|
||||
CServer::CConnectionNote::CConnectionNote(
|
||||
CServer* server,
|
||||
const CString& name,
|
||||
IServerProtocol* protocol) :
|
||||
m_server(server),
|
||||
|
@ -1570,13 +1666,15 @@ CServer::CConnectionNote::~CConnectionNote()
|
|||
// CServer::CScreenInfo
|
||||
//
|
||||
|
||||
CServer::CScreenInfo::CScreenInfo(const CString& name,
|
||||
CServer::CScreenInfo::CScreenInfo(
|
||||
const CString& name,
|
||||
IServerProtocol* protocol) :
|
||||
m_thread(CThread::getCurrentThread()),
|
||||
m_name(name),
|
||||
m_protocol(protocol),
|
||||
m_ready(false),
|
||||
m_width(0), m_height(0),
|
||||
m_width(0),
|
||||
m_height(0),
|
||||
m_zoneSize(0)
|
||||
{
|
||||
for (ClipboardID id = 0; id < kClipboardEnd; ++id)
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
#ifndef CSERVER_H
|
||||
#define CSERVER_H
|
||||
|
||||
#include "CConfig.h"
|
||||
#include "CClipboard.h"
|
||||
#include "ClipboardTypes.h"
|
||||
#include "KeyTypes.h"
|
||||
#include "MouseTypes.h"
|
||||
#include "CConfig.h"
|
||||
#include "CClipboard.h"
|
||||
#include "CNetworkAddress.h"
|
||||
#include "CCondVar.h"
|
||||
#include "CMutex.h"
|
||||
#include "CString.h"
|
||||
#include "CThread.h"
|
||||
#include "XBase.h"
|
||||
#include "stdlist.h"
|
||||
#include "stdmap.h"
|
||||
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
#include "CServerProtocol.h"
|
||||
#include "CServerProtocol1_0.h"
|
||||
#include "ProtocolTypes.h"
|
||||
#include "XSynergy.h"
|
||||
#include "IOutputStream.h"
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <cstdio>
|
||||
|
||||
//
|
||||
// CServerProtocol
|
||||
//
|
||||
|
||||
CServerProtocol::CServerProtocol(CServer* server, const CString& client,
|
||||
IInputStream* input, IOutputStream* output) :
|
||||
CServerProtocol::CServerProtocol(
|
||||
CServer* server,
|
||||
const CString& client,
|
||||
IInputStream* input,
|
||||
IOutputStream* output) :
|
||||
m_server(server),
|
||||
m_client(client),
|
||||
m_input(input),
|
||||
|
@ -26,29 +29,38 @@ CServerProtocol::~CServerProtocol()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
CServer* CServerProtocol::getServer() const
|
||||
CServer*
|
||||
CServerProtocol::getServer() const
|
||||
{
|
||||
return m_server;
|
||||
}
|
||||
|
||||
CString CServerProtocol::getClient() const
|
||||
CString
|
||||
CServerProtocol::getClient() const
|
||||
{
|
||||
return m_client;
|
||||
}
|
||||
|
||||
IInputStream* CServerProtocol::getInputStream() const
|
||||
IInputStream*
|
||||
CServerProtocol::getInputStream() const
|
||||
{
|
||||
return m_input;
|
||||
}
|
||||
|
||||
IOutputStream* CServerProtocol::getOutputStream() const
|
||||
IOutputStream*
|
||||
CServerProtocol::getOutputStream() const
|
||||
{
|
||||
return m_output;
|
||||
}
|
||||
|
||||
IServerProtocol* CServerProtocol::create(SInt32 major, SInt32 minor,
|
||||
CServer* server, const CString& client,
|
||||
IInputStream* input, IOutputStream* output)
|
||||
IServerProtocol*
|
||||
CServerProtocol::create(
|
||||
SInt32 major,
|
||||
SInt32 minor,
|
||||
CServer* server,
|
||||
const CString& client,
|
||||
IInputStream* input,
|
||||
IOutputStream* output)
|
||||
{
|
||||
// disallow invalid version numbers
|
||||
if (major < 0 || minor < 0) {
|
||||
|
@ -70,4 +82,3 @@ IServerProtocol* CServerProtocol::create(SInt32 major, SInt32 minor,
|
|||
// given version.
|
||||
return new CServerProtocol1_0(server, client, input, output);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef CSERVERPROTOCOL_H
|
||||
#define CSERVERPROTOCOL_H
|
||||
|
||||
#include "CString.h"
|
||||
#include "IServerProtocol.h"
|
||||
|
||||
class CServer;
|
||||
|
|
|
@ -3,18 +3,22 @@
|
|||
#include "CClipboard.h"
|
||||
#include "CProtocolUtil.h"
|
||||
#include "ProtocolTypes.h"
|
||||
#include "XSynergy.h"
|
||||
#include "IInputStream.h"
|
||||
#include "IOutputStream.h"
|
||||
#include "CLog.h"
|
||||
#include "CThread.h"
|
||||
#include <string.h>
|
||||
#include "CLog.h"
|
||||
#include <cstring>
|
||||
|
||||
//
|
||||
// CServerProtocol1_0
|
||||
//
|
||||
|
||||
CServerProtocol1_0::CServerProtocol1_0(CServer* server, const CString& client,
|
||||
IInputStream* input, IOutputStream* output) :
|
||||
CServerProtocol1_0::CServerProtocol1_0(
|
||||
CServer* server,
|
||||
const CString& client,
|
||||
IInputStream* input,
|
||||
IOutputStream* output) :
|
||||
CServerProtocol(server, client, input, output)
|
||||
{
|
||||
// do nothing
|
||||
|
@ -25,7 +29,8 @@ CServerProtocol1_0::~CServerProtocol1_0()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::run()
|
||||
void
|
||||
CServerProtocol1_0::run()
|
||||
{
|
||||
// handle messages until the client hangs up
|
||||
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()));
|
||||
|
||||
|
@ -89,7 +95,8 @@ void CServerProtocol1_0::queryInfo()
|
|||
recvInfo();
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::sendClose()
|
||||
void
|
||||
CServerProtocol1_0::sendClose()
|
||||
{
|
||||
log((CLOG_DEBUG1 "send close to \"%s\"", getClient().c_str()));
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgCClose);
|
||||
|
@ -98,96 +105,120 @@ void CServerProtocol1_0::sendClose()
|
|||
getOutputStream()->flush();
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::sendEnter(
|
||||
SInt32 xAbs, SInt32 yAbs,
|
||||
UInt32 seqNum, KeyModifierMask mask)
|
||||
void
|
||||
CServerProtocol1_0::sendEnter(
|
||||
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));
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgCEnter,
|
||||
xAbs, yAbs, seqNum, mask);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::sendLeave()
|
||||
void
|
||||
CServerProtocol1_0::sendLeave()
|
||||
{
|
||||
log((CLOG_DEBUG1 "send leave to \"%s\"", getClient().c_str()));
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgCLeave);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::sendClipboard(
|
||||
ClipboardID id, const CString& data)
|
||||
void
|
||||
CServerProtocol1_0::sendClipboard(
|
||||
ClipboardID id,
|
||||
const CString& data)
|
||||
{
|
||||
log((CLOG_DEBUG "send clipboard %d to \"%s\" size=%d", id, getClient().c_str(), data.size()));
|
||||
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()));
|
||||
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));
|
||||
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()));
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgCInfoAck);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::sendKeyDown(
|
||||
KeyID key, KeyModifierMask mask)
|
||||
void
|
||||
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));
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgDKeyDown, key, mask);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::sendKeyRepeat(
|
||||
KeyID key, KeyModifierMask mask, SInt32 count)
|
||||
void
|
||||
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));
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgDKeyRepeat, key, mask, count);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::sendKeyUp(
|
||||
KeyID key, KeyModifierMask mask)
|
||||
void
|
||||
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));
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgDKeyUp, key, mask);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::sendMouseDown(
|
||||
void
|
||||
CServerProtocol1_0::sendMouseDown(
|
||||
ButtonID button)
|
||||
{
|
||||
log((CLOG_DEBUG1 "send mouse down to \"%s\" id=%d", getClient().c_str(), button));
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgDMouseDown, button);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::sendMouseUp(
|
||||
void
|
||||
CServerProtocol1_0::sendMouseUp(
|
||||
ButtonID button)
|
||||
{
|
||||
log((CLOG_DEBUG1 "send mouse up to \"%s\" id=%d", getClient().c_str(), button));
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgDMouseUp, button);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::sendMouseMove(
|
||||
SInt32 xAbs, SInt32 yAbs)
|
||||
void
|
||||
CServerProtocol1_0::sendMouseMove(
|
||||
SInt32 xAbs,
|
||||
SInt32 yAbs)
|
||||
{
|
||||
log((CLOG_DEBUG2 "send mouse move to \"%s\" %d,%d", getClient().c_str(), xAbs, yAbs));
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgDMouseMove, xAbs, yAbs);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::sendMouseWheel(
|
||||
void
|
||||
CServerProtocol1_0::sendMouseWheel(
|
||||
SInt32 delta)
|
||||
{
|
||||
log((CLOG_DEBUG2 "send mouse wheel to \"%s\" %+d", getClient().c_str(), delta));
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgDMouseWheel, delta);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::recvInfo()
|
||||
void
|
||||
CServerProtocol1_0::recvInfo()
|
||||
{
|
||||
// parse the message
|
||||
SInt16 x, y, w, h, zoneInfo;
|
||||
|
@ -207,7 +238,8 @@ void CServerProtocol1_0::recvInfo()
|
|||
getServer()->setInfo(getClient(), w, h, zoneInfo, x, y);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::recvClipboard()
|
||||
void
|
||||
CServerProtocol1_0::recvClipboard()
|
||||
{
|
||||
// parse message
|
||||
ClipboardID id;
|
||||
|
@ -225,7 +257,8 @@ void CServerProtocol1_0::recvClipboard()
|
|||
getServer()->setClipboard(id, seqNum, data);
|
||||
}
|
||||
|
||||
void CServerProtocol1_0::recvGrabClipboard()
|
||||
void
|
||||
CServerProtocol1_0::recvGrabClipboard()
|
||||
{
|
||||
// parse message
|
||||
ClipboardID id;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "CSynergyHook.h"
|
||||
#include "CConfig.h"
|
||||
#include <assert.h>
|
||||
#include <zmouse.h>
|
||||
|
||||
//
|
||||
|
@ -60,7 +59,9 @@ static DWORD g_cursorThread = 0;
|
|||
// 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 want to hide so we shouldn't have to attach thread input.
|
||||
|
@ -69,7 +70,9 @@ static void hideCursor(DWORD thread)
|
|||
SetCursor(NULL);
|
||||
}
|
||||
|
||||
static void restoreCursor()
|
||||
static
|
||||
void
|
||||
restoreCursor()
|
||||
{
|
||||
// restore the show cursor in the window we hid it last
|
||||
if (g_cursor != NULL && g_cursorThread != 0) {
|
||||
|
@ -84,7 +87,12 @@ static void restoreCursor()
|
|||
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 (g_relay) {
|
||||
|
@ -111,7 +119,12 @@ static LRESULT CALLBACK keyboardHook(int code, WPARAM wParam, LPARAM 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 (g_relay) {
|
||||
|
@ -213,7 +226,12 @@ static LRESULT CALLBACK mouseHook(int code, WPARAM wParam, LPARAM 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 (g_relay) {
|
||||
|
@ -224,7 +242,12 @@ static LRESULT CALLBACK cbtHook(int code, WPARAM wParam, LPARAM 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 (g_relay) {
|
||||
|
@ -252,7 +275,12 @@ static LRESULT CALLBACK getMessageHook(int code, WPARAM wParam, LPARAM lParam)
|
|||
// 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 (g_relay) {
|
||||
|
@ -296,7 +324,10 @@ static LRESULT CALLBACK keyboardLLHook(int code, WPARAM wParam, LPARAM 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
|
||||
// install the hook, process events, and uninstall the hook.
|
||||
|
@ -349,7 +380,10 @@ static DWORD WINAPI getKeyboardLLProc(void*)
|
|||
|
||||
#error foo
|
||||
|
||||
static DWORD WINAPI getKeyboardLLProc(void*)
|
||||
static
|
||||
DWORD WINAPI
|
||||
getKeyboardLLProc(
|
||||
void*)
|
||||
{
|
||||
g_keyHookThreadID = 0;
|
||||
SetEvent(g_keyHookEvent);
|
||||
|
@ -358,7 +392,9 @@ static DWORD WINAPI getKeyboardLLProc(void*)
|
|||
|
||||
#endif
|
||||
|
||||
static EWheelSupport GetWheelSupport()
|
||||
static
|
||||
EWheelSupport
|
||||
getWheelSupport()
|
||||
{
|
||||
// get operating system
|
||||
OSVERSIONINFO info;
|
||||
|
@ -404,7 +440,11 @@ static EWheelSupport GetWheelSupport()
|
|||
// external functions
|
||||
//
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID)
|
||||
BOOL WINAPI
|
||||
DllMain(
|
||||
HINSTANCE instance,
|
||||
DWORD reason,
|
||||
LPVOID)
|
||||
{
|
||||
if (reason == DLL_PROCESS_ATTACH) {
|
||||
if (g_hinstance == NULL) {
|
||||
|
@ -425,7 +465,9 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID)
|
|||
|
||||
extern "C" {
|
||||
|
||||
int install(DWORD threadID)
|
||||
int
|
||||
install(
|
||||
DWORD threadID)
|
||||
{
|
||||
assert(g_threadID == 0);
|
||||
assert(g_hinstance != NULL);
|
||||
|
@ -448,7 +490,7 @@ int install(DWORD threadID)
|
|||
g_cursorThread = 0;
|
||||
|
||||
// check for mouse wheel support
|
||||
g_wheelSupport = GetWheelSupport();
|
||||
g_wheelSupport = getWheelSupport();
|
||||
|
||||
// install keyboard hook
|
||||
g_keyboard = SetWindowsHookEx(WH_KEYBOARD,
|
||||
|
@ -528,7 +570,9 @@ int install(DWORD threadID)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int uninstall(void)
|
||||
int
|
||||
uninstall(
|
||||
void)
|
||||
{
|
||||
assert(g_keyboard != NULL);
|
||||
assert(g_mouse != NULL);
|
||||
|
@ -562,8 +606,12 @@ int uninstall(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
void setZone(UInt32 sides,
|
||||
SInt32 w, SInt32 h, SInt32 jumpZoneSize)
|
||||
void
|
||||
setZone(
|
||||
UInt32 sides,
|
||||
SInt32 w,
|
||||
SInt32 h,
|
||||
SInt32 jumpZoneSize)
|
||||
{
|
||||
g_zoneSize = jumpZoneSize;
|
||||
g_zoneSides = sides;
|
||||
|
@ -573,7 +621,9 @@ void setZone(UInt32 sides,
|
|||
restoreCursor();
|
||||
}
|
||||
|
||||
void setRelay(void)
|
||||
void
|
||||
setRelay(
|
||||
void)
|
||||
{
|
||||
g_relay = true;
|
||||
g_zoneSize = 0;
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#include "CXWindowsPrimaryScreen.h"
|
||||
#include "CServer.h"
|
||||
#include "CXWindowsClipboard.h"
|
||||
#include "CXWindowsUtil.h"
|
||||
#include "CServer.h"
|
||||
#include "CStopwatch.h"
|
||||
#include "CThread.h"
|
||||
#include "CLog.h"
|
||||
#include <assert.h>
|
||||
#include "CStopwatch.h"
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xutil.h>
|
||||
#define XK_MISCELLANY
|
||||
|
@ -28,7 +27,8 @@ CXWindowsPrimaryScreen::~CXWindowsPrimaryScreen()
|
|||
assert(m_window == None);
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::run()
|
||||
void
|
||||
CXWindowsPrimaryScreen::run()
|
||||
{
|
||||
for (;;) {
|
||||
// wait for and get the next event
|
||||
|
@ -39,22 +39,25 @@ void CXWindowsPrimaryScreen::run()
|
|||
|
||||
// handle event
|
||||
switch (xevent.type) {
|
||||
case CreateNotify: {
|
||||
case CreateNotify:
|
||||
{
|
||||
// select events on new window
|
||||
CDisplayLock display(this);
|
||||
selectEvents(display, xevent.xcreatewindow.window);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case MappingNotify: {
|
||||
case MappingNotify:
|
||||
{
|
||||
// keyboard mapping changed
|
||||
CDisplayLock display(this);
|
||||
XRefreshKeyboardMapping(&xevent.xmapping);
|
||||
updateModifierMap(display);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case KeyPress: {
|
||||
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);
|
||||
|
@ -67,10 +70,11 @@ void CXWindowsPrimaryScreen::run()
|
|||
m_server->onKeyUp(key, mask | KeyModifierNumLock);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case KeyRelease: {
|
||||
case KeyRelease:
|
||||
{
|
||||
const KeyModifierMask mask = mapModifier(xevent.xkey.state);
|
||||
const KeyID key = mapKey(&xevent.xkey);
|
||||
if (key != kKeyNone) {
|
||||
|
@ -109,19 +113,21 @@ void CXWindowsPrimaryScreen::run()
|
|||
m_server->onKeyRepeat(key, mask, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ButtonPress: {
|
||||
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;
|
||||
}
|
||||
break;
|
||||
|
||||
case ButtonRelease: {
|
||||
case ButtonRelease:
|
||||
{
|
||||
log((CLOG_DEBUG1 "event: ButtonRelease button=%d", xevent.xbutton.button));
|
||||
const ButtonID button = mapButton(xevent.xbutton.button);
|
||||
if (button != kButtonNone) {
|
||||
|
@ -135,10 +141,11 @@ void CXWindowsPrimaryScreen::run()
|
|||
// wheel backward (toward user)
|
||||
m_server->onMouseWheel(-120);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case MotionNotify: {
|
||||
case MotionNotify:
|
||||
{
|
||||
log((CLOG_DEBUG2 "event: MotionNotify %d,%d", xevent.xmotion.x_root, xevent.xmotion.y_root));
|
||||
SInt32 x, y;
|
||||
if (!m_active) {
|
||||
|
@ -148,7 +155,7 @@ void CXWindowsPrimaryScreen::run()
|
|||
}
|
||||
else {
|
||||
// FIXME -- slurp up all remaining motion events?
|
||||
// probably not since key strokes may go to wrong place.
|
||||
// probably not since keystrokes may go to wrong place.
|
||||
|
||||
// get mouse deltas
|
||||
{
|
||||
|
@ -157,8 +164,9 @@ void CXWindowsPrimaryScreen::run()
|
|||
int xRoot, yRoot, xWindow, yWindow;
|
||||
unsigned int mask;
|
||||
if (!XQueryPointer(display, m_window, &root, &window,
|
||||
&xRoot, &yRoot, &xWindow, &yWindow, &mask))
|
||||
&xRoot, &yRoot, &xWindow, &yWindow, &mask)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// compute position of center of window
|
||||
SInt32 w, h;
|
||||
|
@ -172,19 +180,22 @@ void CXWindowsPrimaryScreen::run()
|
|||
|
||||
m_server->onMouseMoveSecondary(x, y);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::stop()
|
||||
void
|
||||
CXWindowsPrimaryScreen::stop()
|
||||
{
|
||||
CDisplayLock display(this);
|
||||
doStop();
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::open(CServer* server)
|
||||
void
|
||||
CXWindowsPrimaryScreen::open(
|
||||
CServer* server)
|
||||
{
|
||||
assert(m_server == NULL);
|
||||
assert(server != NULL);
|
||||
|
@ -228,7 +239,8 @@ void CXWindowsPrimaryScreen::open(CServer* server)
|
|||
m_server->setInfo(w, h, getJumpZoneSize(), x, y);
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::close()
|
||||
void
|
||||
CXWindowsPrimaryScreen::close()
|
||||
{
|
||||
assert(m_server != NULL);
|
||||
|
||||
|
@ -239,7 +251,10 @@ void CXWindowsPrimaryScreen::close()
|
|||
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));
|
||||
assert(m_active == true);
|
||||
|
@ -268,7 +283,8 @@ void CXWindowsPrimaryScreen::enter(SInt32 x, SInt32 y)
|
|||
m_active = false;
|
||||
}
|
||||
|
||||
bool CXWindowsPrimaryScreen::leave()
|
||||
bool
|
||||
CXWindowsPrimaryScreen::leave()
|
||||
{
|
||||
log((CLOG_INFO "leaving primary"));
|
||||
assert(m_active == false);
|
||||
|
@ -333,19 +349,26 @@ bool CXWindowsPrimaryScreen::leave()
|
|||
return true;
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::onConfigure()
|
||||
void
|
||||
CXWindowsPrimaryScreen::onConfigure()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::warpCursor(SInt32 x, SInt32 y)
|
||||
void
|
||||
CXWindowsPrimaryScreen::warpCursor(
|
||||
SInt32 x,
|
||||
SInt32 y)
|
||||
{
|
||||
CDisplayLock display(this);
|
||||
warpCursorNoLock(display, x, y);
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::warpCursorNoLock(
|
||||
Display* display, SInt32 x, SInt32 y)
|
||||
void
|
||||
CXWindowsPrimaryScreen::warpCursorNoLock(
|
||||
Display* display,
|
||||
SInt32 x,
|
||||
SInt32 y)
|
||||
{
|
||||
assert(display != NULL);
|
||||
assert(m_window != None);
|
||||
|
@ -363,35 +386,45 @@ void CXWindowsPrimaryScreen::warpCursorNoLock(
|
|||
}
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::setClipboard(
|
||||
ClipboardID id, const IClipboard* clipboard)
|
||||
void
|
||||
CXWindowsPrimaryScreen::setClipboard(
|
||||
ClipboardID id,
|
||||
const IClipboard* clipboard)
|
||||
{
|
||||
setDisplayClipboard(id, clipboard);
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::grabClipboard(ClipboardID id)
|
||||
void
|
||||
CXWindowsPrimaryScreen::grabClipboard(
|
||||
ClipboardID id)
|
||||
{
|
||||
setDisplayClipboard(id, NULL);
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::getSize(
|
||||
SInt32* width, SInt32* height) const
|
||||
void
|
||||
CXWindowsPrimaryScreen::getSize(
|
||||
SInt32* width,
|
||||
SInt32* height) const
|
||||
{
|
||||
getScreenSize(width, height);
|
||||
}
|
||||
|
||||
SInt32 CXWindowsPrimaryScreen::getJumpZoneSize() const
|
||||
SInt32
|
||||
CXWindowsPrimaryScreen::getJumpZoneSize() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::getClipboard(
|
||||
ClipboardID id, IClipboard* clipboard) const
|
||||
void
|
||||
CXWindowsPrimaryScreen::getClipboard(
|
||||
ClipboardID id,
|
||||
IClipboard* clipboard) const
|
||||
{
|
||||
getDisplayClipboard(id, clipboard);
|
||||
}
|
||||
|
||||
KeyModifierMask CXWindowsPrimaryScreen::getToggleMask() const
|
||||
KeyModifierMask
|
||||
CXWindowsPrimaryScreen::getToggleMask() const
|
||||
{
|
||||
CDisplayLock display(this);
|
||||
|
||||
|
@ -417,7 +450,8 @@ KeyModifierMask CXWindowsPrimaryScreen::getToggleMask() const
|
|||
return mask;
|
||||
}
|
||||
|
||||
bool CXWindowsPrimaryScreen::isLockedToScreen() const
|
||||
bool
|
||||
CXWindowsPrimaryScreen::isLockedToScreen() const
|
||||
{
|
||||
CDisplayLock display(this);
|
||||
|
||||
|
@ -449,7 +483,9 @@ bool CXWindowsPrimaryScreen::isLockedToScreen() const
|
|||
return false;
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::onOpenDisplay(Display* display)
|
||||
void
|
||||
CXWindowsPrimaryScreen::onOpenDisplay(
|
||||
Display* display)
|
||||
{
|
||||
assert(m_window == None);
|
||||
|
||||
|
@ -479,14 +515,17 @@ void CXWindowsPrimaryScreen::onOpenDisplay(Display* display)
|
|||
selectEvents(display, getRoot());
|
||||
}
|
||||
|
||||
CXWindowsClipboard* CXWindowsPrimaryScreen::createClipboard(
|
||||
CXWindowsClipboard*
|
||||
CXWindowsPrimaryScreen::createClipboard(
|
||||
ClipboardID id)
|
||||
{
|
||||
CDisplayLock display(this);
|
||||
return new CXWindowsClipboard(display, m_window, id);
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::onCloseDisplay(Display* display)
|
||||
void
|
||||
CXWindowsPrimaryScreen::onCloseDisplay(
|
||||
Display* display)
|
||||
{
|
||||
assert(m_window != None);
|
||||
|
||||
|
@ -497,7 +536,8 @@ void CXWindowsPrimaryScreen::onCloseDisplay(Display* display)
|
|||
m_window = None;
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::onUnexpectedClose()
|
||||
void
|
||||
CXWindowsPrimaryScreen::onUnexpectedClose()
|
||||
{
|
||||
// tell server to shutdown
|
||||
if (m_server != NULL) {
|
||||
|
@ -505,15 +545,18 @@ void CXWindowsPrimaryScreen::onUnexpectedClose()
|
|||
}
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::onLostClipboard(
|
||||
void
|
||||
CXWindowsPrimaryScreen::onLostClipboard(
|
||||
ClipboardID id)
|
||||
{
|
||||
// tell server that the clipboard was grabbed locally
|
||||
m_server->grabClipboard(id);
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::selectEvents(
|
||||
Display* display, Window w) const
|
||||
void
|
||||
CXWindowsPrimaryScreen::selectEvents(
|
||||
Display* display,
|
||||
Window w) const
|
||||
{
|
||||
// ignore errors while we adjust event masks
|
||||
CXWindowsUtil::CErrorLock lock;
|
||||
|
@ -522,8 +565,10 @@ void CXWindowsPrimaryScreen::selectEvents(
|
|||
doSelectEvents(display, w);
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::doSelectEvents(
|
||||
Display* display, Window w) const
|
||||
void
|
||||
CXWindowsPrimaryScreen::doSelectEvents(
|
||||
Display* display,
|
||||
Window w) const
|
||||
{
|
||||
// we want to track the mouse everywhere on the display. to achieve
|
||||
// that we select PointerMotionMask on every window. we also select
|
||||
|
@ -531,8 +576,9 @@ void CXWindowsPrimaryScreen::doSelectEvents(
|
|||
// select events on new windows too.
|
||||
|
||||
// we don't want to adjust our grab window
|
||||
if (w == m_window)
|
||||
if (w == m_window) {
|
||||
return;
|
||||
}
|
||||
|
||||
// select events of interest
|
||||
XSelectInput(display, w, PointerMotionMask | SubstructureNotifyMask);
|
||||
|
@ -541,13 +587,15 @@ void CXWindowsPrimaryScreen::doSelectEvents(
|
|||
Window rw, pw, *cw;
|
||||
unsigned int 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]);
|
||||
}
|
||||
XFree(cw);
|
||||
}
|
||||
}
|
||||
|
||||
KeyModifierMask CXWindowsPrimaryScreen::mapModifier(
|
||||
KeyModifierMask
|
||||
CXWindowsPrimaryScreen::mapModifier(
|
||||
unsigned int state) const
|
||||
{
|
||||
// FIXME -- should be configurable
|
||||
|
@ -569,7 +617,9 @@ KeyModifierMask CXWindowsPrimaryScreen::mapModifier(
|
|||
return mask;
|
||||
}
|
||||
|
||||
KeyID CXWindowsPrimaryScreen::mapKey(XKeyEvent* event) const
|
||||
KeyID
|
||||
CXWindowsPrimaryScreen::mapKey(
|
||||
XKeyEvent* event) const
|
||||
{
|
||||
KeySym keysym;
|
||||
char dummy[1];
|
||||
|
@ -579,17 +629,21 @@ KeyID CXWindowsPrimaryScreen::mapKey(XKeyEvent* event) const
|
|||
return static_cast<KeyID>(keysym);
|
||||
}
|
||||
|
||||
ButtonID CXWindowsPrimaryScreen::mapButton(
|
||||
ButtonID
|
||||
CXWindowsPrimaryScreen::mapButton(
|
||||
unsigned int button) const
|
||||
{
|
||||
// FIXME -- should use button mapping?
|
||||
if (button >= 1 && button <= 3)
|
||||
if (button >= 1 && button <= 3) {
|
||||
return static_cast<ButtonID>(button);
|
||||
else
|
||||
}
|
||||
else {
|
||||
return kButtonNone;
|
||||
}
|
||||
}
|
||||
|
||||
void CXWindowsPrimaryScreen::updateModifierMap(
|
||||
void
|
||||
CXWindowsPrimaryScreen::updateModifierMap(
|
||||
Display* display)
|
||||
{
|
||||
// get modifier map from server
|
||||
|
@ -624,8 +678,11 @@ void CXWindowsPrimaryScreen::updateModifierMap(
|
|||
XFreeModifiermap(keymap);
|
||||
}
|
||||
|
||||
Bool CXWindowsPrimaryScreen::findKeyEvent(
|
||||
Display*, XEvent* xevent, XPointer arg)
|
||||
Bool
|
||||
CXWindowsPrimaryScreen::findKeyEvent(
|
||||
Display*,
|
||||
XEvent* xevent,
|
||||
XPointer arg)
|
||||
{
|
||||
CKeyEventInfo* filter = reinterpret_cast<CKeyEventInfo*>(arg);
|
||||
return (xevent->type == filter->m_event &&
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#ifndef CXWINDOWSPRIMARYSCREEN_H
|
||||
#define CXWINDOWSPRIMARYSCREEN_H
|
||||
|
||||
#include "KeyTypes.h"
|
||||
#include "MouseTypes.h"
|
||||
#include "CXWindowsScreen.h"
|
||||
#include "IPrimaryScreen.h"
|
||||
#include "MouseTypes.h"
|
||||
|
||||
class CXWindowsPrimaryScreen : public CXWindowsScreen, public IPrimaryScreen {
|
||||
public:
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
#include "CServer.h"
|
||||
#include "CConfig.h"
|
||||
#include "CLog.h"
|
||||
#include "CLock.h"
|
||||
#include "CMutex.h"
|
||||
#include "CNetwork.h"
|
||||
#include "CPlatform.h"
|
||||
#include "CThread.h"
|
||||
#include "XThread.h"
|
||||
#include "ProtocolTypes.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 <assert.h>
|
||||
#include <cstring>
|
||||
|
||||
// platform dependent name of a daemon
|
||||
#if defined(CONFIG_PLATFORM_WIN32)
|
||||
|
@ -51,7 +52,10 @@ static CConfig s_config;
|
|||
|
||||
static CMutex* s_logMutex = NULL;
|
||||
|
||||
static void logLock(bool lock)
|
||||
static
|
||||
void
|
||||
logLock(
|
||||
bool lock)
|
||||
{
|
||||
assert(s_logMutex != NULL);
|
||||
|
||||
|
@ -70,7 +74,10 @@ static void logLock(bool lock)
|
|||
|
||||
static CServer* s_server = NULL;
|
||||
|
||||
static int realMain(CMutex* mutex)
|
||||
static
|
||||
int
|
||||
realMain(
|
||||
CMutex* mutex)
|
||||
{
|
||||
// s_serverLock should have mutex locked on entry
|
||||
|
||||
|
@ -153,14 +160,18 @@ static int realMain(CMutex* mutex)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int restartMain()
|
||||
static
|
||||
int
|
||||
restartMain()
|
||||
{
|
||||
return realMain(NULL);
|
||||
}
|
||||
|
||||
// invoke realMain and wait for it. if s_restartable then keep
|
||||
// restarting realMain until it returns a terminate code.
|
||||
static int restartableMain()
|
||||
static
|
||||
int
|
||||
restartableMain()
|
||||
{
|
||||
if (s_restartable) {
|
||||
CPlatform platform;
|
||||
|
@ -180,7 +191,9 @@ static int restartableMain()
|
|||
|
||||
static void (*bye)(int) = &exit;
|
||||
|
||||
static void version()
|
||||
static
|
||||
void
|
||||
version()
|
||||
{
|
||||
log((CLOG_PRINT
|
||||
"%s %d.%d.%d, protocol version %d.%d\n"
|
||||
|
@ -194,7 +207,9 @@ static void version()
|
|||
kCopyright));
|
||||
}
|
||||
|
||||
static void help()
|
||||
static
|
||||
void
|
||||
help()
|
||||
{
|
||||
CPlatform platform;
|
||||
|
||||
|
@ -256,8 +271,11 @@ static void help()
|
|||
CONFIG_NAME).c_str()));
|
||||
}
|
||||
|
||||
static bool isArg(int argi,
|
||||
int argc, const char** argv,
|
||||
static
|
||||
bool
|
||||
isArg(int argi,
|
||||
int argc,
|
||||
const char** argv,
|
||||
const char* name1,
|
||||
const char* name2,
|
||||
int minRequiredParameters = 0)
|
||||
|
@ -277,7 +295,11 @@ static bool isArg(int argi,
|
|||
return false;
|
||||
}
|
||||
|
||||
static void parse(int argc, const char** argv)
|
||||
static
|
||||
void
|
||||
parse(
|
||||
int argc,
|
||||
const char** argv)
|
||||
{
|
||||
assert(pname != 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);
|
||||
|
||||
|
@ -471,7 +497,9 @@ static bool loadConfig(const char* pathname, bool require)
|
|||
return false;
|
||||
}
|
||||
|
||||
static void loadConfig()
|
||||
static
|
||||
void
|
||||
loadConfig()
|
||||
{
|
||||
// load the config file, if specified
|
||||
if (s_configFile != NULL) {
|
||||
|
@ -512,7 +540,11 @@ static void loadConfig()
|
|||
|
||||
#include "CMSWindowsScreen.h"
|
||||
|
||||
static bool logMessageBox(int priority, const char* msg)
|
||||
static
|
||||
bool
|
||||
logMessageBox(
|
||||
int priority,
|
||||
const char* msg)
|
||||
{
|
||||
if (priority <= CLog::kFATAL) {
|
||||
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);
|
||||
}
|
||||
|
||||
static void daemonStop(void)
|
||||
static
|
||||
void
|
||||
daemonStop(void)
|
||||
{
|
||||
s_server->quit();
|
||||
}
|
||||
|
||||
static int daemonStartup(IPlatform* iplatform,
|
||||
int argc, const char** argv)
|
||||
static
|
||||
int
|
||||
daemonStartup(
|
||||
IPlatform* iplatform,
|
||||
int argc,
|
||||
const char** argv)
|
||||
{
|
||||
// get platform pointer
|
||||
CWin32Platform* platform = static_cast<CWin32Platform*>(iplatform);
|
||||
|
@ -558,19 +598,30 @@ static int daemonStartup(IPlatform* iplatform,
|
|||
return platform->runDaemon(realMain, daemonStop);
|
||||
}
|
||||
|
||||
static int daemonStartup95(IPlatform*, int, const char**)
|
||||
static
|
||||
int
|
||||
daemonStartup95(
|
||||
IPlatform*,
|
||||
int,
|
||||
const char**)
|
||||
{
|
||||
return realMain(NULL);
|
||||
}
|
||||
|
||||
static bool logDiscard(int, const char*)
|
||||
static
|
||||
bool
|
||||
logDiscard(
|
||||
int,
|
||||
const char*)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
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.
|
||||
// 0 means graceful exit. we plan to exit for anything but
|
||||
|
@ -580,7 +631,12 @@ static void checkParse(int e)
|
|||
throw s_die;
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
||||
int WINAPI
|
||||
WinMain(
|
||||
HINSTANCE instance,
|
||||
HINSTANCE,
|
||||
LPSTR,
|
||||
int)
|
||||
{
|
||||
CPlatform platform;
|
||||
|
||||
|
@ -703,12 +759,20 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
|||
|
||||
#elif defined(CONFIG_PLATFORM_UNIX)
|
||||
|
||||
static int daemonStartup(IPlatform*, int, const char**)
|
||||
static
|
||||
int
|
||||
daemonStartup(
|
||||
IPlatform*,
|
||||
int,
|
||||
const char**)
|
||||
{
|
||||
return restartableMain();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int
|
||||
main(
|
||||
int argc,
|
||||
char** argv)
|
||||
{
|
||||
CPlatform platform;
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#include "CClipboard.h"
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CClipboard
|
||||
//
|
||||
|
||||
CClipboard::CClipboard() : m_open(false), m_owner(false)
|
||||
CClipboard::CClipboard() :
|
||||
m_open(false),
|
||||
m_owner(false)
|
||||
{
|
||||
open(0);
|
||||
empty();
|
||||
|
@ -17,7 +18,8 @@ CClipboard::~CClipboard()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
bool CClipboard::empty()
|
||||
bool
|
||||
CClipboard::empty()
|
||||
{
|
||||
assert(m_open);
|
||||
|
||||
|
@ -36,7 +38,10 @@ bool CClipboard::empty()
|
|||
return true;
|
||||
}
|
||||
|
||||
void CClipboard::add(EFormat format, const CString& data)
|
||||
void
|
||||
CClipboard::add(
|
||||
EFormat format,
|
||||
const CString& data)
|
||||
{
|
||||
assert(m_open);
|
||||
assert(m_owner);
|
||||
|
@ -45,7 +50,9 @@ void CClipboard::add(EFormat format, const CString& data)
|
|||
m_added[format] = true;
|
||||
}
|
||||
|
||||
bool CClipboard::open(Time time) const
|
||||
bool
|
||||
CClipboard::open(
|
||||
Time time) const
|
||||
{
|
||||
assert(!m_open);
|
||||
|
||||
|
@ -55,31 +62,40 @@ bool CClipboard::open(Time time) const
|
|||
return true;
|
||||
}
|
||||
|
||||
void CClipboard::close() const
|
||||
void
|
||||
CClipboard::close() const
|
||||
{
|
||||
assert(m_open);
|
||||
|
||||
m_open = false;
|
||||
}
|
||||
|
||||
CClipboard::Time CClipboard::getTime() const
|
||||
CClipboard::Time
|
||||
CClipboard::getTime() const
|
||||
{
|
||||
return m_timeOwned;
|
||||
}
|
||||
|
||||
bool CClipboard::has(EFormat format) const
|
||||
bool
|
||||
CClipboard::has(
|
||||
EFormat format) const
|
||||
{
|
||||
assert(m_open);
|
||||
return m_added[format];
|
||||
}
|
||||
|
||||
CString CClipboard::get(EFormat format) const
|
||||
CString
|
||||
CClipboard::get(
|
||||
EFormat format) const
|
||||
{
|
||||
assert(m_open);
|
||||
return m_data[format];
|
||||
}
|
||||
|
||||
bool CClipboard::copy(IClipboard* dst, const IClipboard* src)
|
||||
bool
|
||||
CClipboard::copy(
|
||||
IClipboard* dst,
|
||||
const IClipboard* src)
|
||||
{
|
||||
assert(dst != NULL);
|
||||
assert(src != NULL);
|
||||
|
@ -87,8 +103,11 @@ bool CClipboard::copy(IClipboard* dst, const IClipboard* src)
|
|||
return copy(dst, src, src->getTime());
|
||||
}
|
||||
|
||||
bool CClipboard::copy(IClipboard* dst,
|
||||
const IClipboard* src, Time time)
|
||||
bool
|
||||
CClipboard::copy(
|
||||
IClipboard* dst,
|
||||
const IClipboard* src,
|
||||
Time time)
|
||||
{
|
||||
assert(dst != NULL);
|
||||
assert(src != NULL);
|
||||
|
@ -114,7 +133,10 @@ bool CClipboard::copy(IClipboard* dst,
|
|||
return success;
|
||||
}
|
||||
|
||||
void CClipboard::unmarshall(const CString& data, Time time)
|
||||
void
|
||||
CClipboard::unmarshall(
|
||||
const CString& data,
|
||||
Time time)
|
||||
{
|
||||
const char* index = data.data();
|
||||
|
||||
|
@ -146,7 +168,8 @@ void CClipboard::unmarshall(const CString& data, Time time)
|
|||
close();
|
||||
}
|
||||
|
||||
CString CClipboard::marshall() const
|
||||
CString
|
||||
CClipboard::marshall() const
|
||||
{
|
||||
CString data;
|
||||
|
||||
|
@ -177,7 +200,9 @@ CString CClipboard::marshall() const
|
|||
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);
|
||||
return (static_cast<UInt32>(ubuf[0]) << 24) |
|
||||
|
@ -186,7 +211,10 @@ UInt32 CClipboard::readUInt32(const char* buf) const
|
|||
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 >> 16) & 0xff);
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
//
|
||||
|
||||
#include "IClipboard.h"
|
||||
#include "CString.h"
|
||||
|
||||
class CClipboard : public IClipboard {
|
||||
public:
|
||||
|
@ -23,6 +22,14 @@ public:
|
|||
// marshall clipboard data
|
||||
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
|
||||
virtual bool empty();
|
||||
virtual void add(EFormat, const CString& data);
|
||||
|
@ -32,16 +39,6 @@ public:
|
|||
virtual bool has(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:
|
||||
UInt32 readUInt32(const char*) const;
|
||||
void writeUInt32(CString*, UInt32) const;
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#include "CInputPacketStream.h"
|
||||
#include "CLock.h"
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CInputPacketStream
|
||||
//
|
||||
|
||||
CInputPacketStream::CInputPacketStream(IInputStream* stream, bool adopt) :
|
||||
CInputPacketStream::CInputPacketStream(
|
||||
IInputStream* stream,
|
||||
bool adopt) :
|
||||
CInputStreamFilter(stream, adopt),
|
||||
m_mutex(),
|
||||
m_size(0),
|
||||
|
@ -20,13 +21,16 @@ CInputPacketStream::~CInputPacketStream()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
void CInputPacketStream::close()
|
||||
void
|
||||
CInputPacketStream::close()
|
||||
{
|
||||
getStream()->close();
|
||||
}
|
||||
|
||||
UInt32 CInputPacketStream::read(
|
||||
void* buffer, UInt32 n)
|
||||
UInt32
|
||||
CInputPacketStream::read(
|
||||
void* buffer,
|
||||
UInt32 n)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
|
||||
|
@ -50,13 +54,15 @@ UInt32 CInputPacketStream::read(
|
|||
return n;
|
||||
}
|
||||
|
||||
UInt32 CInputPacketStream::getSize() const
|
||||
UInt32
|
||||
CInputPacketStream::getSize() const
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
return getSizeNoLock();
|
||||
}
|
||||
|
||||
UInt32 CInputPacketStream::getSizeNoLock() const
|
||||
UInt32
|
||||
CInputPacketStream::getSizeNoLock() const
|
||||
{
|
||||
while (!hasFullMessage()) {
|
||||
// read more data
|
||||
|
@ -76,7 +82,8 @@ UInt32 CInputPacketStream::getSizeNoLock() const
|
|||
return m_size;
|
||||
}
|
||||
|
||||
bool CInputPacketStream::hasFullMessage() const
|
||||
bool
|
||||
CInputPacketStream::hasFullMessage() const
|
||||
{
|
||||
// get payload length if we don't have it yet
|
||||
if (m_size == 0) {
|
||||
|
@ -106,4 +113,3 @@ bool CInputPacketStream::hasFullMessage() const
|
|||
// the buffer
|
||||
return (m_buffer.getSizeNoLock() >= m_size);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
// COuputPacketStream
|
||||
//
|
||||
|
||||
COutputPacketStream::COutputPacketStream(IOutputStream* stream, bool adopt) :
|
||||
COutputPacketStream::COutputPacketStream(
|
||||
IOutputStream* stream,
|
||||
bool adopt) :
|
||||
COutputStreamFilter(stream, adopt)
|
||||
{
|
||||
// do nothing
|
||||
|
@ -15,13 +17,16 @@ COutputPacketStream::~COutputPacketStream()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
void COutputPacketStream::close()
|
||||
void
|
||||
COutputPacketStream::close()
|
||||
{
|
||||
getStream()->close();
|
||||
}
|
||||
|
||||
UInt32 COutputPacketStream::write(
|
||||
const void* buffer, UInt32 count)
|
||||
UInt32
|
||||
COutputPacketStream::write(
|
||||
const void* buffer,
|
||||
UInt32 count)
|
||||
{
|
||||
// write the length of the payload
|
||||
UInt8 length[4];
|
||||
|
@ -49,7 +54,8 @@ UInt32 COutputPacketStream::write(
|
|||
return count;
|
||||
}
|
||||
|
||||
void COutputPacketStream::flush()
|
||||
void
|
||||
COutputPacketStream::flush()
|
||||
{
|
||||
getStream()->flush();
|
||||
}
|
||||
|
|
|
@ -2,16 +2,18 @@
|
|||
#include "IInputStream.h"
|
||||
#include "IOutputStream.h"
|
||||
#include "CLog.h"
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
|
||||
//
|
||||
// CProtocolUtil
|
||||
//
|
||||
|
||||
void CProtocolUtil::writef(IOutputStream* stream,
|
||||
const char* fmt, ...)
|
||||
void
|
||||
CProtocolUtil::writef(
|
||||
IOutputStream* stream,
|
||||
const char* fmt,
|
||||
...)
|
||||
{
|
||||
assert(stream != NULL);
|
||||
assert(fmt != NULL);
|
||||
|
@ -47,8 +49,11 @@ void CProtocolUtil::writef(IOutputStream* stream,
|
|||
delete[] buffer;
|
||||
}
|
||||
|
||||
void CProtocolUtil::readf(IInputStream* stream,
|
||||
const char* fmt, ...)
|
||||
void
|
||||
CProtocolUtil::readf(
|
||||
IInputStream* stream,
|
||||
const char* fmt,
|
||||
...)
|
||||
{
|
||||
assert(stream != NULL);
|
||||
assert(fmt != NULL);
|
||||
|
@ -179,8 +184,10 @@ void CProtocolUtil::readf(IInputStream* stream,
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
UInt32 CProtocolUtil::getLength(
|
||||
const char* fmt, va_list args)
|
||||
UInt32
|
||||
CProtocolUtil::getLength(
|
||||
const char* fmt,
|
||||
va_list args)
|
||||
{
|
||||
UInt32 n = 0;
|
||||
while (*fmt) {
|
||||
|
@ -228,8 +235,11 @@ UInt32 CProtocolUtil::getLength(
|
|||
return n;
|
||||
}
|
||||
|
||||
void CProtocolUtil::writef(void* buffer,
|
||||
const char* fmt, va_list args)
|
||||
void
|
||||
CProtocolUtil::writef(
|
||||
void* buffer,
|
||||
const char* fmt,
|
||||
va_list args)
|
||||
{
|
||||
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;
|
||||
UInt32 n = 0;
|
||||
|
@ -339,8 +351,11 @@ UInt32 CProtocolUtil::eatLength(const char** pfmt)
|
|||
}
|
||||
}
|
||||
|
||||
void CProtocolUtil::read(IInputStream* stream,
|
||||
void* vbuffer, UInt32 count)
|
||||
void
|
||||
CProtocolUtil::read(
|
||||
IInputStream* stream,
|
||||
void* vbuffer,
|
||||
UInt32 count)
|
||||
{
|
||||
assert(stream != NULL);
|
||||
assert(vbuffer != NULL);
|
||||
|
@ -367,7 +382,8 @@ void CProtocolUtil::read(IInputStream* stream,
|
|||
// XIOReadMismatch
|
||||
//
|
||||
|
||||
CString XIOReadMismatch::getWhat() const throw()
|
||||
CString
|
||||
XIOReadMismatch::getWhat() const throw()
|
||||
{
|
||||
return "CProtocolUtil::readf() mismatch";
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "BasicTypes.h"
|
||||
#include "XIO.h"
|
||||
#include <stdarg.h>
|
||||
#include <cstdarg>
|
||||
|
||||
class IInputStream;
|
||||
class IOutputStream;
|
||||
|
|
|
@ -16,12 +16,14 @@ CTCPSocketFactory::~CTCPSocketFactory()
|
|||
// do nothing
|
||||
}
|
||||
|
||||
ISocket* CTCPSocketFactory::create() const
|
||||
ISocket*
|
||||
CTCPSocketFactory::create() const
|
||||
{
|
||||
return new CTCPSocket;
|
||||
}
|
||||
|
||||
IListenSocket* CTCPSocketFactory::createListen() const
|
||||
IListenSocket*
|
||||
CTCPSocketFactory::createListen() const
|
||||
{
|
||||
return new CTCPListenSocket;
|
||||
}
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
#define ICLIPBOARD_H
|
||||
|
||||
#include "IInterface.h"
|
||||
#include "CString.h"
|
||||
#include "BasicTypes.h"
|
||||
|
||||
class CString;
|
||||
|
||||
class IClipboard : public IInterface {
|
||||
public:
|
||||
// timestamp type. timestamps are in milliseconds from some
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define IPRIMARYSCREEN_H
|
||||
|
||||
#include "IInterface.h"
|
||||
#include "BasicTypes.h"
|
||||
#include "KeyTypes.h"
|
||||
#include "ClipboardTypes.h"
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define ISECONDARYSCREEN_H
|
||||
|
||||
#include "IInterface.h"
|
||||
#include "BasicTypes.h"
|
||||
#include "ClipboardTypes.h"
|
||||
#include "KeyTypes.h"
|
||||
#include "MouseTypes.h"
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#ifndef ISERVERPROTOCOL_H
|
||||
#define ISERVERPROTOCOL_H
|
||||
|
||||
#include "IInterface.h"
|
||||
#include "ClipboardTypes.h"
|
||||
#include "KeyTypes.h"
|
||||
#include "MouseTypes.h"
|
||||
#include "IInterface.h"
|
||||
#include "XSynergy.h"
|
||||
#include "XIO.h"
|
||||
#include "CString.h"
|
||||
|
||||
class IClipboard;
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define ISOCKETFACTORY_H
|
||||
|
||||
#include "IInterface.h"
|
||||
#include "XSocket.h"
|
||||
|
||||
class ISocket;
|
||||
class IListenSocket;
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
// XScreenOpenFailure
|
||||
//
|
||||
|
||||
CString XScreenOpenFailure::getWhat() const throw()
|
||||
CString
|
||||
XScreenOpenFailure::getWhat() const throw()
|
||||
{
|
||||
return "XScreenOpenFailure";
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
// XBadClient
|
||||
//
|
||||
|
||||
CString XBadClient::getWhat() const throw()
|
||||
CString
|
||||
XBadClient::getWhat() const throw()
|
||||
{
|
||||
return "XBadClient";
|
||||
}
|
||||
|
@ -14,24 +15,29 @@ CString XBadClient::getWhat() const throw()
|
|||
// XIncompatibleClient
|
||||
//
|
||||
|
||||
XIncompatibleClient::XIncompatibleClient(int major, int minor) :
|
||||
XIncompatibleClient::XIncompatibleClient(
|
||||
int major,
|
||||
int minor) :
|
||||
m_major(major),
|
||||
m_minor(minor)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
int XIncompatibleClient::getMajor() const throw()
|
||||
int
|
||||
XIncompatibleClient::getMajor() const throw()
|
||||
{
|
||||
return m_major;
|
||||
}
|
||||
|
||||
int XIncompatibleClient::getMinor() const throw()
|
||||
int
|
||||
XIncompatibleClient::getMinor() const throw()
|
||||
{
|
||||
return m_minor;
|
||||
}
|
||||
|
||||
CString XIncompatibleClient::getWhat() const throw()
|
||||
CString
|
||||
XIncompatibleClient::getWhat() const throw()
|
||||
{
|
||||
return "XIncompatibleClient";
|
||||
}
|
||||
|
@ -41,17 +47,21 @@ CString XIncompatibleClient::getWhat() const throw()
|
|||
// XDuplicateClient
|
||||
//
|
||||
|
||||
XDuplicateClient::XDuplicateClient(const CString& name) : m_name(name)
|
||||
XDuplicateClient::XDuplicateClient(
|
||||
const CString& name) :
|
||||
m_name(name)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
const CString& XDuplicateClient::getName() const throw()
|
||||
const CString&
|
||||
XDuplicateClient::getName() const throw()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
CString XDuplicateClient::getWhat() const throw()
|
||||
CString
|
||||
XDuplicateClient::getWhat() const throw()
|
||||
{
|
||||
return "XDuplicateClient";
|
||||
}
|
||||
|
@ -61,17 +71,21 @@ CString XDuplicateClient::getWhat() const throw()
|
|||
// XUnknownClient
|
||||
//
|
||||
|
||||
XUnknownClient::XUnknownClient(const CString& name) : m_name(name)
|
||||
XUnknownClient::XUnknownClient(
|
||||
const CString& name) :
|
||||
m_name(name)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
const CString& XUnknownClient::getName() const throw()
|
||||
const CString&
|
||||
XUnknownClient::getName() const throw()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
CString XUnknownClient::getWhat() const throw()
|
||||
CString
|
||||
XUnknownClient::getWhat() const throw()
|
||||
{
|
||||
return "XUnknownClient";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue