예제 #1
0
파일: CClient.cpp 프로젝트: JueSungMun/SPWC
CClient::CClient(const CString& name, const CNetworkAddress& address,
				ISocketFactory* socketFactory,
				IStreamFilterFactory* streamFilterFactory,
				CScreen* screen) :
	m_name(name),
	m_serverAddress(address),
	m_socketFactory(socketFactory),
	m_streamFilterFactory(streamFilterFactory),
	m_screen(screen),
	m_stream(NULL),
	m_timer(NULL),
	m_server(NULL),
	m_ready(false),
	m_active(false),
	m_suspended(false),
	m_connectOnResume(false)
{
	assert(m_socketFactory != NULL);
	assert(m_screen        != NULL);

	// register suspend/resume event handlers
	EVENTQUEUE->adoptHandler(IScreen::getSuspendEvent(),
							getEventTarget(),
							new TMethodEventJob<CClient>(this,
								&CClient::handleSuspend));
	EVENTQUEUE->adoptHandler(IScreen::getResumeEvent(),
							getEventTarget(),
							new TMethodEventJob<CClient>(this,
								&CClient::handleResume));
}
예제 #2
0
void
COSXScreen::handlePowerChangeRequest(natural_t messageType, void* messageArg)
{
	// we've received a power change notification
	switch (messageType) {
	case kIOMessageSystemWillSleep:
		// COSXScreen has to handle this in the main thread so we have to
		// queue a confirm sleep event here.  we actually don't allow the
		// system to sleep until the event is handled.
		m_events->addEvent(CEvent(m_events->forCOSXScreen().confirmSleep(),
								getEventTarget(), messageArg,
								CEvent::kDontFreeData));
		return;
			
	case kIOMessageSystemHasPoweredOn:
		LOG((CLOG_DEBUG "system wakeup"));
		m_events->addEvent(CEvent(m_events->forIScreen().resume(),
								getEventTarget()));
		break;

	default:
		break;
	}

	CLock lock(m_pmMutex);
	if (m_pmRootPort != 0) {
		IOAllowPowerChange(m_pmRootPort, (long)messageArg);
	}
}
예제 #3
0
파일: Client.cpp 프로젝트: Ameb/synergy
Client::Client(
		IEventQueue* events,
		const String& name, const NetworkAddress& address,
		ISocketFactory* socketFactory,
		synergy::Screen* screen,
		ClientArgs& args) :
	m_mock(false),
	m_name(name),
	m_serverAddress(address),
	m_socketFactory(socketFactory),
	m_screen(screen),
	m_stream(NULL),
	m_timer(NULL),
	m_server(NULL),
	m_ready(false),
	m_active(false),
	m_suspended(false),
	m_connectOnResume(false),
	m_events(events),
	m_sendFileThread(NULL),
	m_writeToDropDirThread(NULL),
	m_socket(NULL),
	m_useSecureNetwork(false),
	m_args(args)
{
	assert(m_socketFactory != NULL);
	assert(m_screen        != NULL);

	// register suspend/resume event handlers
	m_events->adoptHandler(m_events->forIScreen().suspend(),
							getEventTarget(),
							new TMethodEventJob<Client>(this,
								&Client::handleSuspend));
	m_events->adoptHandler(m_events->forIScreen().resume(),
							getEventTarget(),
							new TMethodEventJob<Client>(this,
								&Client::handleResume));

	if (m_args.m_enableDragDrop) {
		m_events->adoptHandler(m_events->forIScreen().fileChunkSending(),
								this,
								new TMethodEventJob<Client>(this,
									&Client::handleFileChunkSending));
		m_events->adoptHandler(m_events->forIScreen().fileRecieveCompleted(),
								this,
								new TMethodEventJob<Client>(this,
									&Client::handleFileRecieveCompleted));
	}

	if (m_args.m_enableCrypto) {
		m_useSecureNetwork = ARCH->plugin().exists(s_networkSecurity);
		if (m_useSecureNetwork == false) {
			LOG((CLOG_NOTE "crypto disabled because of ns plugin not available"));
		}
	}
}
예제 #4
0
CClient::CClient(
		IEventQueue* events,
		const CString& name, const CNetworkAddress& address,
		ISocketFactory* socketFactory,
		IStreamFilterFactory* streamFilterFactory,
		CScreen* screen,
		const CCryptoOptions& crypto,
		bool enableDragDrop) :
	m_mock(false),
	m_name(name),
	m_serverAddress(address),
	m_socketFactory(socketFactory),
	m_streamFilterFactory(streamFilterFactory),
	m_screen(screen),
	m_stream(NULL),
	m_timer(NULL),
	m_server(NULL),
	m_ready(false),
	m_active(false),
	m_suspended(false),
	m_connectOnResume(false),
	m_events(events),
	m_cryptoStream(NULL),
	m_crypto(crypto),
	m_sendFileThread(NULL),
	m_writeToDropDirThread(NULL),
	m_enableDragDrop(enableDragDrop)
{
	assert(m_socketFactory != NULL);
	assert(m_screen        != NULL);

	// register suspend/resume event handlers
	m_events->adoptHandler(m_events->forIScreen().suspend(),
							getEventTarget(),
							new TMethodEventJob<CClient>(this,
								&CClient::handleSuspend));
	m_events->adoptHandler(m_events->forIScreen().resume(),
							getEventTarget(),
							new TMethodEventJob<CClient>(this,
								&CClient::handleResume));

	if (m_enableDragDrop) {
		m_events->adoptHandler(m_events->forIScreen().fileChunkSending(),
								this,
								new TMethodEventJob<CClient>(this,
									&CClient::handleFileChunkSending));
		m_events->adoptHandler(m_events->forIScreen().fileRecieveCompleted(),
								this,
								new TMethodEventJob<CClient>(this,
									&CClient::handleFileRecieveCompleted));
	}
}
예제 #5
0
파일: CClient.cpp 프로젝트: JueSungMun/SPWC
CClient::~CClient()
{
	EVENTQUEUE->removeHandler(IScreen::getSuspendEvent(),
							  getEventTarget());
	EVENTQUEUE->removeHandler(IScreen::getResumeEvent(),
							  getEventTarget());

	cleanupTimer();
	cleanupScreen();
	cleanupConnecting();
	cleanupConnection();
	delete m_socketFactory;
	delete m_streamFilterFactory;
}
예제 #6
0
CClient::CClient(IEventQueue* events,
				const CString& name, const CNetworkAddress& address,
				ISocketFactory* socketFactory,
				IStreamFilterFactory* streamFilterFactory,
				CScreen* screen,
				const CCryptoOptions& crypto) :
	m_mock(false),
	m_name(name),
	m_serverAddress(address),
	m_socketFactory(socketFactory),
	m_streamFilterFactory(streamFilterFactory),
	m_screen(screen),
	m_stream(NULL),
	m_timer(NULL),
	m_server(NULL),
	m_ready(false),
	m_active(false),
	m_suspended(false),
	m_connectOnResume(false),
	m_events(events),
	m_cryptoStream(NULL),
	m_crypto(crypto)
{
	assert(m_socketFactory != NULL);
	assert(m_screen        != NULL);

	// register suspend/resume event handlers
	m_events->adoptHandler(m_events->forIScreen().suspend(),
							getEventTarget(),
							new TMethodEventJob<CClient>(this,
								&CClient::handleSuspend));
	m_events->adoptHandler(m_events->forIScreen().resume(),
							getEventTarget(),
							new TMethodEventJob<CClient>(this,
								&CClient::handleResume));
	m_events->adoptHandler(m_events->forISecondaryScreen().gameDeviceTimingResp(),
							getEventTarget(),
							new TMethodEventJob<CClient>(this,
								&CClient::handleGameDeviceTimingResp));
	m_events->adoptHandler(m_events->forISecondaryScreen().gameDeviceFeedback(),
							getEventTarget(),
							new TMethodEventJob<CClient>(this,
								&CClient::handleGameDeviceFeedback));
	m_events->adoptHandler(m_events->forIScreen().fileChunkSending(),
							this,
							new TMethodEventJob<CClient>(this,
								&CClient::handleFileChunkSending));
}
예제 #7
0
void
CTCPSocket::sendConnectionFailedEvent(const char* msg)
{
	CConnectionFailedInfo* info = new CConnectionFailedInfo(msg);
	m_events->addEvent(CEvent(m_events->forIDataSocket().connectionFailed(),
							getEventTarget(), info, CEvent::kDontFreeData));
}
bool
ClientProxy1_6::recvClipboard()
{
	// parse message
	static String dataCached;
	ClipboardID id;
	UInt32 seq;

	int r = ClipboardChunk::assemble(getStream(), dataCached, id, seq);

	if (r == kFinish) {
		LOG((CLOG_DEBUG "received client \"%s\" clipboard %d seqnum=%d, size=%d", getName().c_str(), id, seq, dataCached.size()));
		// save clipboard
		m_clipboard[id].m_clipboard.unmarshall(dataCached, 0);
		m_clipboard[id].m_sequenceNumber = seq;
		
		// notify
		ClipboardInfo* info = new ClipboardInfo;
		info->m_id = id;
		info->m_sequenceNumber = seq;
		m_events->addEvent(Event(m_events->forClipboard().clipboardChanged(),
								 getEventTarget(), info));
	}

	return true;
}
예제 #9
0
bool
ClientProxy1_0::parseMessage(const UInt8* code)
{
	if (memcmp(code, kMsgDInfo, 4) == 0) {
		if (recvInfo()) {
			m_events->addEvent(
							Event(m_events->forIScreen().shapeChanged(), getEventTarget()));
			return true;
		}
		return false;
	}
	else if (memcmp(code, kMsgCNoop, 4) == 0) {
		// discard no-ops
		LOG((CLOG_DEBUG2 "no-op from", getName().c_str()));
		return true;
	}
	else if (memcmp(code, kMsgCClipboard, 4) == 0) {
		return recvGrabClipboard();
	}
	else if (memcmp(code, kMsgDClipboard, 4) == 0) {
		return recvClipboard();
	}



	return false;
}
예제 #10
0
bool
CClientProxy1_0::recvClipboard()
{
	// parse message
	ClipboardID id;
	UInt32 seqNum;
	CString data;
	if (!CProtocolUtil::readf(getStream(),
							kMsgDClipboard + 4, &id, &seqNum, &data)) {
		return false;
	}
	LOG((CLOG_DEBUG "received client \"%s\" clipboard %d seqnum=%d, size=%d", getName().c_str(), id, seqNum, data.size()));

	// validate
	if (id >= kClipboardEnd) {
		return false;
	}

	// save clipboard
	m_clipboard[id].m_clipboard.unmarshall(data, 0);
	m_clipboard[id].m_sequenceNumber = seqNum;

	// notify
	CClipboardInfo* info   = new CClipboardInfo;
	info->m_id             = id;
	info->m_sequenceNumber = seqNum;
	EVENTQUEUE->addEvent(CEvent(getClipboardChangedEvent(),
							getEventTarget(), info));

	return true;
}
예제 #11
0
bool
CClientProxy1_0::recvGrabClipboard()
{
	// parse message
	ClipboardID id;
	UInt32 seqNum;
	if (!CProtocolUtil::readf(getStream(), kMsgCClipboard + 4, &id, &seqNum)) {
		return false;
	}
	LOG((CLOG_DEBUG "received client \"%s\" grabbed clipboard %d seqnum=%d", getName().c_str(), id, seqNum));

	// validate
	if (id >= kClipboardEnd) {
		return false;
	}

	// notify
	CClipboardInfo* info   = new CClipboardInfo;
	info->m_id             = id;
	info->m_sequenceNumber = seqNum;
	EVENTQUEUE->addEvent(CEvent(getClipboardGrabbedEvent(),
							getEventTarget(), info));

	return true;
}
예제 #12
0
void
CClientProxy1_0::disconnect()
{
	removeHandlers();
	getStream()->close();
	EVENTQUEUE->addEvent(CEvent(getDisconnectedEvent(), getEventTarget()));
}
예제 #13
0
bool
ClientProxy1_6::recvClipboard()
{
	// parse message
	static String dataCached;
	ClipboardID id;
	UInt32 seq;

	int r = ClipboardChunk::assemble(getStream(), dataCached, id, seq);

	if (r == kFinish) {
		LOG((CLOG_DEBUG "received client \"%s\" clipboard %d seqnum=%d, size=%d", getName().c_str(), id, seq, dataCached.size()));
		// save clipboard
		m_clipboard[id].m_clipboard.unmarshall(dataCached, 0);
		m_clipboard[id].m_sequenceNumber = seq;
		
		// notify
		ClipboardInfo* info = new ClipboardInfo;
		info->m_id = id;
		info->m_sequenceNumber = seq;
		m_events->addEvent(Event(m_events->forClipboard().clipboardChanged(),
								 getEventTarget(), info));
		LOG((CLOG_NOTIFY "clipboard transmission complete"));
	}
	else if (r == kStart) {
		size_t size = ClipboardChunk::getExpectedSize();
		LOG((CLOG_NOTIFY "clipboard transmission started: start receiving %u bytes of clipboard data", size));
	}

	return true;
}
예제 #14
0
void
CClient::setupScreen()
{
	assert(m_server == NULL);

	m_ready  = false;
	m_server = new CServerProxy(this, m_stream, *EVENTQUEUE);
	m_eventQueue.adoptHandler(IScreen::getShapeChangedEvent(),
							getEventTarget(),
							new TMethodEventJob<CClient>(this,
								&CClient::handleShapeChanged));
	m_eventQueue.adoptHandler(IScreen::getClipboardGrabbedEvent(),
							getEventTarget(),
							new TMethodEventJob<CClient>(this,
								&CClient::handleClipboardGrabbed));
}
예제 #15
0
void
CClient::cleanupScreen()
{
	if (m_server != NULL) {
		if (m_ready) {
			m_screen->disable();
			m_ready = false;
		}
		m_eventQueue.removeHandler(IScreen::getShapeChangedEvent(),
							getEventTarget());
		m_eventQueue.removeHandler(IScreen::getClipboardGrabbedEvent(),
							getEventTarget());
		delete m_server;
		m_server = NULL;
	}
}
예제 #16
0
파일: Client.cpp 프로젝트: 335/synergy
void
Client::setupScreen()
{
	assert(m_server == NULL);

	m_ready  = false;
	m_server = new ServerProxy(this, m_stream, m_events);
	m_events->adoptHandler(m_events->forIScreen().shapeChanged(),
							getEventTarget(),
							new TMethodEventJob<Client>(this,
								&Client::handleShapeChanged));
	m_events->adoptHandler(m_events->forClipboard().clipboardGrabbed(),
							getEventTarget(),
							new TMethodEventJob<Client>(this,
								&Client::handleClipboardGrabbed));
}
예제 #17
0
파일: Client.cpp 프로젝트: 335/synergy
void
Client::cleanupScreen()
{
	if (m_server != NULL) {
		if (m_ready) {
			m_screen->disable();
			m_ready = false;
		}
		m_events->removeHandler(m_events->forIScreen().shapeChanged(),
							getEventTarget());
		m_events->removeHandler(m_events->forClipboard().clipboardGrabbed(),
							getEventTarget());
		delete m_server;
		m_server = NULL;
	}
}
예제 #18
0
void
CClientProxy1_0::disconnect()
{
	removeHandlers();
	getStream()->close();
	m_events->addEvent(CEvent(m_events->forCClientProxy().disconnected(), getEventTarget()));
}
예제 #19
0
bool
COSXScreen::onHotKey(EventRef event) const
{
	// get the hotkey id
	EventHotKeyID hkid;
	GetEventParameter(event, kEventParamDirectObject, typeEventHotKeyID,
							NULL, sizeof(EventHotKeyID), NULL, &hkid);
	UInt32 id = hkid.id;

	// determine event type
	CEvent::Type type;
	UInt32 eventKind = GetEventKind(event);
	if (eventKind == kEventHotKeyPressed) {
		type = m_events->forIPrimaryScreen().hotKeyDown();
	}
	else if (eventKind == kEventHotKeyReleased) {
		type = m_events->forIPrimaryScreen().hotKeyUp();
	}
	else {
		return false;
	}

	m_events->addEvent(CEvent(type, getEventTarget(),
								CHotKeyInfo::alloc(id)));

	return true;
}
예제 #20
0
파일: Client.cpp 프로젝트: Ameb/synergy
Client::~Client()
{
	if (m_mock) {
		return;
	}

	m_events->removeHandler(m_events->forIScreen().suspend(),
							  getEventTarget());
	m_events->removeHandler(m_events->forIScreen().resume(),
							  getEventTarget());

	cleanupTimer();
	cleanupScreen();
	cleanupConnecting();
	cleanupConnection();
	delete m_socketFactory;
}
예제 #21
0
void
CClient::sendConnectionFailedEvent(const char* msg)
{
	CFailInfo* info = new CFailInfo(msg);
	info->m_retry = true;
	CEvent event(getConnectionFailedEvent(), getEventTarget(), info, CEvent::kDontFreeData);
	EVENTQUEUE->addEvent(event);
}
예제 #22
0
파일: Client.cpp 프로젝트: 335/synergy
void
Client::sendConnectionFailedEvent(const char* msg)
{
	FailInfo* info = new FailInfo(msg);
	info->m_retry = true;
	Event event(m_events->forClient().connectionFailed(), getEventTarget(), info, Event::kDontFreeData);
	m_events->addEvent(event);
}
예제 #23
0
void
CScreen::enablePrimary()
{
	// get notified of screen saver activation/deactivation
	m_screen->openScreensaver(true);

	// claim screen changed size
	EVENTQUEUE->addEvent(CEvent(getShapeChangedEvent(), getEventTarget()));
}
예제 #24
0
void
Screen::enablePrimary()
{
	// get notified of screen saver activation/deactivation
	m_screen->openScreensaver(true);

	// claim screen changed size
	m_events->addEvent(Event(m_events->forIScreen().shapeChanged(), getEventTarget()));
}
예제 #25
0
CClient::~CClient()
{
	// HACK: can't disable dtor with mocks
	if (m_mock)
		return;

	m_eventQueue.removeHandler(IScreen::getSuspendEvent(),
							  getEventTarget());
	m_eventQueue.removeHandler(IScreen::getResumeEvent(),
							  getEventTarget());

	cleanupTimer();
	cleanupScreen();
	cleanupConnecting();
	cleanupConnection();
	delete m_socketFactory;
	delete m_streamFilterFactory;
}
예제 #26
0
void
CTCPSocket::sendConnectionFailedEvent(const char* msg)
{
	CConnectionFailedInfo* info = (CConnectionFailedInfo*)malloc(
							sizeof(CConnectionFailedInfo) + strlen(msg));
	strcpy(info->m_what, msg);
	EVENTQUEUE->addEvent(CEvent(getConnectionFailedEvent(),
							getEventTarget(), info));
}
예제 #27
0
void
SecureSocket::connect(const NetworkAddress& addr)
{
	m_events->adoptHandler(m_events->forIDataSocket().connected(),
				getEventTarget(),
				new TMethodEventJob<SecureSocket>(this,
						&SecureSocket::handleTCPConnected));

	TCPSocket::connect(addr);
}
예제 #28
0
COSXScreen::~COSXScreen()
{
	disable();
	m_events->adoptBuffer(NULL);
	m_events->removeHandler(CEvent::kSystem, m_events->getSystemTarget());

	if (m_pmWatchThread) {
		// make sure the thread has setup the runloop.
		{
			CLock lock(m_pmMutex);
			while (!(bool)*m_pmThreadReady) {
				m_pmThreadReady->wait();
			}
		}

		// now exit the thread's runloop and wait for it to exit
		LOG((CLOG_DEBUG "stopping watchSystemPowerThread"));
		CFRunLoopStop(m_pmRunloop);
		m_pmWatchThread->wait();
		delete m_pmWatchThread;
		m_pmWatchThread = NULL;
	}
	delete m_pmThreadReady;
	delete m_pmMutex;

	m_events->removeHandler(m_events->forCOSXScreen().confirmSleep(),
								getEventTarget());

	RemoveEventHandler(m_switchEventHandlerRef);

#if defined(MAC_OS_X_VERSION_10_5)
	CGDisplayRemoveReconfigurationCallback(displayReconfigurationCallback, this);
#else
	DMRemoveExtendedNotifyProc(m_displayManagerNotificationUPP,
							NULL, &m_PSN, 0);

	if (m_hiddenWindow) {
		ReleaseWindow(m_hiddenWindow);
		m_hiddenWindow = NULL;
	}

	if (m_userInputWindow) {
		ReleaseWindow(m_userInputWindow);
		m_userInputWindow = NULL;
	}
#endif

	delete m_keyState;
	delete m_screensaver;
}
예제 #29
0
void
COSXScreen::handleConfirmSleep(const CEvent& event, void*)
{
	long messageArg = (long)event.getData();
	if (messageArg != 0) {
		CLock lock(m_pmMutex);
		if (m_pmRootPort != 0) {
			// deliver suspend event immediately.
			m_events->addEvent(CEvent(m_events->forIScreen().suspend(),
									getEventTarget(), NULL, 
									CEvent::kDeliverImmediately));
	
			LOG((CLOG_DEBUG "system will sleep"));
			IOAllowPowerChange(m_pmRootPort, messageArg);
		}
	}
}
예제 #30
0
COSXScreen::~COSXScreen()
{
	disable();
	EVENTQUEUE->adoptBuffer(NULL);
	EVENTQUEUE->removeHandler(CEvent::kSystem, IEventQueue::getSystemTarget());

	if (m_pmWatchThread) {
		// make sure the thread has setup the runloop.
		{
			CLock lock(m_pmMutex);
			while (!(bool)*m_pmThreadReady) {
				m_pmThreadReady->wait();
			}
		}

		// now exit the thread's runloop and wait for it to exit
		LOG((CLOG_DEBUG "stopping watchSystemPowerThread"));
		CFRunLoopStop(m_pmRunloop);
		m_pmWatchThread->wait();
		delete m_pmWatchThread;
		m_pmWatchThread = NULL;
	}
	delete m_pmThreadReady;
	delete m_pmMutex;

	EVENTQUEUE->removeHandler(COSXScreen::getConfirmSleepEvent(),
								getEventTarget());

	RemoveEventHandler(m_switchEventHandlerRef);

	CGDisplayRemoveReconfigurationCallback(displayReconfigurationCallback, this);
	if (m_hiddenWindow) {
		CFRelease(m_hiddenWindow);
		m_hiddenWindow = NULL;
	}

	if (m_userInputWindow) {
		CFRelease(m_userInputWindow);
		m_userInputWindow = NULL;
	}

	delete m_keyState;
	delete m_screensaver;
}