more refactoring.

This commit is contained in:
crs
2002-07-10 21:22:28 +00:00
parent 710e1bdd47
commit 3468f3d503
16 changed files with 176 additions and 276 deletions

View File

@@ -28,7 +28,6 @@ CClient::CClient(const CString& clientName) :
m_server(NULL),
m_camp(false),
m_active(false),
m_seqNum(0),
m_rejected(true)
{
// do nothing
@@ -66,18 +65,29 @@ CClient::wasRejected() const
}
void
CClient::onClipboardChanged(ClipboardID id)
CClient::onInfoChanged(const CClientInfo& info)
{
log((CLOG_DEBUG "resolution changed"));
CLock lock(&m_mutex);
if (m_server != NULL) {
m_server->onInfoChanged(info);
}
}
bool
CClient::onGrabClipboard(ClipboardID id)
{
CLock lock(&m_mutex);
if (m_server == NULL) {
// m_server can be NULL if the screen calls this method
// before we've gotten around to connecting to the server.
// we simply ignore the clipboard change in that case.
return;
return false;
}
// grab ownership
m_server->onGrabClipboard(m_name, id, m_seqNum);
m_server->onGrabClipboard(id);
// we now own the clipboard and it has not been sent to the server
m_ownClipboard[id] = true;
@@ -88,21 +98,14 @@ CClient::onClipboardChanged(ClipboardID id)
if (!m_active) {
sendClipboard(id);
}
return true;
}
void
CClient::onResolutionChanged()
CClient::onClipboardChanged(ClipboardID, const CString&)
{
log((CLOG_DEBUG "resolution changed"));
CLock lock(&m_mutex);
if (m_server != NULL) {
CClientInfo info;
m_screen->getShape(info.m_x, info.m_y, info.m_w, info.m_h);
m_screen->getMousePos(info.m_mx, info.m_my);
info.m_zoneSize = m_screen->getJumpZoneSize();
m_server->onInfoChanged("", info);
}
// ignore -- we'll check the clipboard when we leave
}
bool
@@ -194,7 +197,6 @@ CClient::enter(SInt32 xAbs, SInt32 yAbs,
{
CLock lock(&m_mutex);
m_active = true;
m_seqNum = seqNum;
}
m_screen->enter(xAbs, yAbs, mask);
@@ -337,9 +339,6 @@ CClient::openSecondaryScreen()
// not active
m_active = false;
// reset last sequence number
m_seqNum = 0;
// reset clipboard state
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
m_ownClipboard[id] = false;
@@ -349,12 +348,12 @@ CClient::openSecondaryScreen()
// open screen
log((CLOG_DEBUG1 "creating secondary screen"));
#if WINDOWS_LIKE
m_screen = new CMSWindowsSecondaryScreen;
m_screen = new CMSWindowsSecondaryScreen(this);
#elif UNIX_LIKE
m_screen = new CXWindowsSecondaryScreen;
m_screen = new CXWindowsSecondaryScreen(this);
#endif
log((CLOG_DEBUG1 "opening secondary screen"));
m_screen->open(this);
m_screen->open();
}
void
@@ -406,7 +405,7 @@ CClient::sendClipboard(ClipboardID id)
// save and send data if different
if (data != m_dataClipboard[id]) {
m_dataClipboard[id] = data;
m_server->onClipboardChanged(id, m_seqNum, data);
m_server->onClipboardChanged(id, data);
}
}
}

View File

@@ -1,6 +1,7 @@
#ifndef CCLIENT_H
#define CCLIENT_H
#include "IScreenReceiver.h"
#include "IClient.h"
#include "IClipboard.h"
#include "CNetworkAddress.h"
@@ -10,9 +11,9 @@ class CServerProxy;
class CThread;
class IDataSocket;
class ISecondaryScreen;
class IServer;
class IScreenReceiver;
class CClient : public IClient {
class CClient : public IScreenReceiver, public IClient {
public:
CClient(const CString& clientName);
~CClient();
@@ -32,31 +33,21 @@ public:
// after a successful open().
void quit();
// handle events on client's screen
// FIXME -- this should mimic methods on IServer
// FIXME -- maybe create a IScreenReceiver with these methods and
// have CPrimaryClient and CClient inherit from them. IServer
// still needs similar methods with extra parameters, though. so
// CServerProxy
// CPrimaryClient
// CClient
// need IScreenReceiver. these classes effective receive notifications
// from screens. note that there's another class of notifications that
// only the server needs (key, mouyse, screensaver). so maybe we have
// IPrimaryScreenReceiver and ISecondaryScreenReceiver (the latter is
// derived with no extra methods from IScreenReceiver).
void onClipboardChanged(ClipboardID);
void onResolutionChanged();
// accessors
// returns true if the server rejected us
bool wasRejected() const;
// IScreenReceiver overrides
virtual void onInfoChanged(const CClientInfo&);
virtual bool onGrabClipboard(ClipboardID);
virtual void onClipboardChanged(ClipboardID, const CString&);
// IClient overrides
virtual bool open();
virtual void run();
virtual void close();
// FIXME -- can we avoid passing everything here?
virtual void enter(SInt32 xAbs, SInt32 yAbs,
UInt32 seqNum, KeyModifierMask mask,
bool screenSaver);
@@ -97,11 +88,10 @@ private:
CMutex m_mutex;
CString m_name;
ISecondaryScreen* m_screen;
IServer* m_server;
IScreenReceiver* m_server;
CNetworkAddress m_serverAddress;
bool m_camp;
bool m_active;
UInt32 m_seqNum;
bool m_rejected;
bool m_ownClipboard[kClipboardEnd];
IClipboard::Time m_timeClipboard[kClipboardEnd];

View File

@@ -18,7 +18,8 @@ CServerProxy::CServerProxy(IClient* client,
IInputStream* input, IOutputStream* output) :
m_client(client),
m_input(input),
m_output(output)
m_output(output),
m_seqNum(0)
{
assert(m_client != NULL);
assert(m_input != NULL);
@@ -40,7 +41,10 @@ CServerProxy::run()
m_compressMouse = false;
// not ignoring mouse motions
m_ignoreMouse = false;
m_ignoreMouse = false;
// reset sequence number
m_seqNum = 0;
// handle messages from server
CStopwatch heartbeat;
@@ -218,13 +222,7 @@ CServerProxy::getOutputStream() const
}
void
CServerProxy::onError()
{
// ignore
}
void
CServerProxy::onInfoChanged(const CString&, const CClientInfo& info)
CServerProxy::onInfoChanged(const CClientInfo& info)
{
// ignore mouse motion until we receive acknowledgment of our info
// change message.
@@ -236,74 +234,19 @@ CServerProxy::onInfoChanged(const CString&, const CClientInfo& info)
}
bool
CServerProxy::onGrabClipboard(const CString&, ClipboardID id, UInt32 seqNum)
CServerProxy::onGrabClipboard(ClipboardID id)
{
log((CLOG_DEBUG1 "sending clipboard %d changed", id));
CLock lock(&m_mutex);
CProtocolUtil::writef(getOutputStream(), kMsgCClipboard, id, seqNum);
CProtocolUtil::writef(getOutputStream(), kMsgCClipboard, id, m_seqNum);
}
void
CServerProxy::onClipboardChanged(ClipboardID id,
UInt32 seqNum, const CString& data)
CServerProxy::onClipboardChanged(ClipboardID id, const CString& data)
{
log((CLOG_DEBUG1 "sending clipboard %d seqnum=%d, size=%d", id, seqNum, data.size()));
CLock lock(&m_mutex);
CProtocolUtil::writef(getOutputStream(), kMsgDClipboard, id, seqNum, &data);
}
void
CServerProxy::onKeyDown(KeyID, KeyModifierMask)
{
// ignore
}
void
CServerProxy::onKeyUp(KeyID, KeyModifierMask)
{
// ignore
}
void
CServerProxy::onKeyRepeat(KeyID, KeyModifierMask, SInt32)
{
// ignore
}
void
CServerProxy::onMouseDown(ButtonID)
{
// ignore
}
void
CServerProxy::onMouseUp(ButtonID)
{
// ignore
}
bool
CServerProxy::onMouseMovePrimary(SInt32, SInt32)
{
return false;
}
void
CServerProxy::onMouseMoveSecondary(SInt32, SInt32)
{
// ignore
}
void
CServerProxy::onMouseWheel(SInt32)
{
// ignore
}
void
CServerProxy::onScreenSaver(bool)
{
// ignore
log((CLOG_DEBUG1 "sending clipboard %d seqnum=%d, size=%d", id, m_seqNum, data.size()));
CProtocolUtil::writef(getOutputStream(), kMsgDClipboard, id, m_seqNum, &data);
}
void
@@ -353,6 +296,7 @@ CServerProxy::enter()
{
CLock lock(&m_mutex);
m_compressMouse = false;
m_seqNum = seqNum;
}
// forward

View File

@@ -1,14 +1,14 @@
#ifndef CSERVERPROXY_H
#define CSERVERPROXY_H
#include "IServer.h"
#include "IScreenReceiver.h"
#include "CMutex.h"
class IClient;
class IInputStream;
class IOutputStream;
class CServerProxy : public IServer {
class CServerProxy : public IScreenReceiver {
public:
CServerProxy(IClient* client,
IInputStream* adoptedInput,
@@ -33,23 +33,10 @@ public:
IInputStream* getInputStream() const;
IOutputStream* getOutputStream() const;
// IServer overrides
virtual void onError();
virtual void onInfoChanged(const CString& clientName,
const CClientInfo&);
virtual bool onGrabClipboard(const CString& clientName,
ClipboardID, UInt32 seqNum);
virtual void onClipboardChanged(ClipboardID,
UInt32 seqNum, const CString& data);
virtual void onKeyDown(KeyID, KeyModifierMask);
virtual void onKeyUp(KeyID, KeyModifierMask);
virtual void onKeyRepeat(KeyID, KeyModifierMask, SInt32 count);
virtual void onMouseDown(ButtonID);
virtual void onMouseUp(ButtonID);
virtual bool onMouseMovePrimary(SInt32 x, SInt32 y);
virtual void onMouseMoveSecondary(SInt32 dx, SInt32 dy);
virtual void onMouseWheel(SInt32 delta);
virtual void onScreenSaver(bool activated);
// IScreenReceiver overrides
virtual void onInfoChanged(const CClientInfo&);
virtual bool onGrabClipboard(ClipboardID);
virtual void onClipboardChanged(ClipboardID, const CString& data);
private:
// if compressing mouse motion then send the last motion now
@@ -80,6 +67,8 @@ private:
IInputStream* m_input;
IOutputStream* m_output;
UInt32 m_seqNum;
bool m_compressMouse;
SInt32 m_xMouse, m_yMouse;

View File

@@ -24,8 +24,8 @@
// CXWindowsSecondaryScreen
//
CXWindowsSecondaryScreen::CXWindowsSecondaryScreen() :
m_client(NULL),
CXWindowsSecondaryScreen::CXWindowsSecondaryScreen(IScreenReceiver* receiver) :
m_receiver(receiver),
m_window(None)
{
// do nothing
@@ -82,13 +82,9 @@ CXWindowsSecondaryScreen::stop()
}
void
CXWindowsSecondaryScreen::open(CClient* client)
CXWindowsSecondaryScreen::open()
{
assert(m_client == NULL);
assert(client != NULL);
// set the client
m_client = client;
assert(m_receiver != NULL);
// open the display
openDisplay();
@@ -128,8 +124,6 @@ CXWindowsSecondaryScreen::open(CClient* client)
void
CXWindowsSecondaryScreen::close()
{
assert(m_client != NULL);
// release keys that are logically pressed
releaseKeys();
@@ -138,9 +132,6 @@ CXWindowsSecondaryScreen::close()
// close the display
closeDisplay();
// done with client
m_client = NULL;
}
void
@@ -396,7 +387,7 @@ void
CXWindowsSecondaryScreen::onLostClipboard(ClipboardID id)
{
// tell client that the clipboard was grabbed locally
m_client->onClipboardChanged(id);
m_receiver->onGrabClipboard(id);
}
void

View File

@@ -6,16 +6,18 @@
#include "stdmap.h"
#include "stdvector.h"
class IScreenReceiver;
class CXWindowsSecondaryScreen : public CXWindowsScreen,
public ISecondaryScreen {
public:
CXWindowsSecondaryScreen();
CXWindowsSecondaryScreen(IScreenReceiver*);
virtual ~CXWindowsSecondaryScreen();
// ISecondaryScreen overrides
virtual void run();
virtual void stop();
virtual void open(CClient*);
virtual void open();
virtual void close();
virtual void enter(SInt32 xAbsolute, SInt32 yAbsolute,
KeyModifierMask mask);
@@ -81,7 +83,7 @@ private:
static bool isToggleKeysym(KeySym);
private:
CClient* m_client;
IScreenReceiver* m_receiver;
Window m_window;
// note toggle keys that toggles on up/down (false) or on

View File

@@ -6,7 +6,6 @@
#include "KeyTypes.h"
#include "MouseTypes.h"
class CClient;
class IClipboard;
class ISecondaryScreen : public IInterface {
@@ -23,9 +22,9 @@ public:
virtual void stop() = 0;
// initialize the screen, hide the cursor, and disable the screen
// saver. start reporting certain events to the client (clipboard
// stolen and screen size changed).
virtual void open(CClient*) = 0;
// saver. start reporting events to the IScreenReceiver (which is
// set through some other interface).
virtual void open() = 0;
// close the screen. should restore the screen saver. it should
// also simulate key up events for any keys that have simulate key