Пример #1
0
	dword ClientTask()
	{
		CScopedLock _lock;
		CTcpClient* pClient = NULL;
		CDataDoubleLinkedListT<CTcpClient>::Iterator it = _tcpclients.Begin();
				
		if ( it && (*it) )
		{
			pClient = *it;
			_tcpclients.Remove(it, EmptyDeleteFunc, NULL);
		}
		if ( !pClient )
			return 0;

		CStringBuffer sBuffer;

		wcout(_T("ClientTask"));
		try
		{
			CStringConstIterator itB;
			bool bExit = false;

			_lock.unlock();
			ReceiveData(pClient, sBuffer);
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			ReceiveData(pClient, sBuffer);
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			ReceiveData(pClient, sBuffer);
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			ReceiveData(pClient, sBuffer);
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			ReceiveData(pClient, sBuffer);
			itB = sBuffer;
			itB.Find(_T("STOP\r\n"));
			if ( itB.IsBegin() )
				bExit = true;
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			pClient->CloseConnection();
			_lock.lock();
			pClient->release();
			_bExit = bExit;
		}
		catch ( CTcpClientException* ex )
		{
			COUT << ex->GetExceptionMessage() << endl;
			pClient->CloseConnection();
		}
		return 0;
	}
Пример #2
0
CStringBuffer CConsoleClipboard::GetClipboardText()
{
	CStringBuffer tmp;

#ifdef OK_SYS_WINDOWS
	if (!IsClipboardFormatAvailable(_CLIPBOARDTEXTFORMAT))
		return tmp;

	HWND hwnd = GetConsoleWindow();

	if ( !hwnd )
		return tmp;
    if (!OpenClipboard(hwnd)) 
		return tmp;
 
    HGLOBAL hglb = GetClipboardData(_CLIPBOARDTEXTFORMAT); 
    if (hglb != NULL) 
    { 
        LPTSTR  lptstr = (LPTSTR)GlobalLock(hglb); 
        if (lptstr != NULL) 
        {
			dword tlen = s_strlen(lptstr, INT_MAX);
			tmp.SetSize(__FILE__LINE__ tlen + 1);
			s_strcpy(CastMutable(CPointer, tmp.GetString()), tlen + 1, lptstr);
            GlobalUnlock(hglb); 
        } 
    } 
    CloseClipboard();
#endif
#ifdef OK_SYS_UNIX
	tmp = _clipboardtext;
#endif
	return tmp;
 }
Пример #3
0
static void TestTCPClientKeepAlive_SendData(CTcpClient& tcpClient, const CStringBuffer& buffer)
{
	CStringBuffer sBuffer;
	CByteBuffer bBuffer;
	dword numBytesSend;

	sBuffer.FormatString(__FILE__LINE__ _T("##%05d## %s"), buffer.GetLength(), buffer.GetString());
	sBuffer.convertToByteBuffer(bBuffer);
	tcpClient.SendData(bBuffer.get_Buffer(), bBuffer.get_BufferSize(), &numBytesSend);
	assert(numBytesSend == bBuffer.get_BufferSize());
}
Пример #4
0
	void SendData(CTcpClient* tcpClient, const CStringBuffer& buffer)
	{
		CScopedLock _lock;
		CStringBuffer sBuffer;
		CByteBuffer bBuffer;
		dword numBytesSend;

		sBuffer.FormatString(__FILE__LINE__ _T("##%05d## %s"), buffer.GetLength(), buffer.GetString());
		sBuffer.convertToByteBuffer(bBuffer);
		_lock.unlock();
		tcpClient->SendData(bBuffer.get_Buffer(), bBuffer.get_BufferSize(), &numBytesSend);
		assert(numBytesSend == bBuffer.get_BufferSize());
	}
Пример #5
0
	void ReceiveData(CTcpClient* tcpClient, CStringBuffer& buffer)
	{
		CScopedLock _lock;
		CStringBuffer responseString;
		CByteBuffer responseBuffer;
		dword numDataReceived = 0;
		dword totalDataReceived = 0;
		CStringConstIterator itB;
		CStringBuffer sBuffer;
		dword numData;

		for ( ; totalDataReceived < 10; )
		{
			responseBuffer.set_BufferSize(__FILE__LINE__ totalDataReceived + MAX_BUFFER);
			_lock.unlock();
			tcpClient->ReceiveData(responseBuffer.get_Buffer() + totalDataReceived, MAX_BUFFER, &numDataReceived);
			totalDataReceived += numDataReceived;
			_lock.lock();
			responseBuffer.set_BufferSize(__FILE__LINE__ totalDataReceived);
		}
		responseString.convertFromByteBuffer(responseBuffer);
		itB = responseString.GetString();
		buffer = responseString;
		if ( (itB[0] == _T('#')) && (itB[1] == _T('#')) && (itB[7] == _T('#')) && (itB[8] == _T('#')) )
		{
			responseString.SubString(2, 5, sBuffer);
			if ( sBuffer.ScanString(_T("%u"), &numData) <= 0 )
				return;
		}
		else
			return;
		for ( ; totalDataReceived < (10 + numData); )
		{
			responseBuffer.set_BufferSize(__FILE__LINE__ totalDataReceived + MAX_BUFFER);
			_lock.unlock();
			tcpClient->ReceiveData(responseBuffer.get_Buffer() + totalDataReceived, MAX_BUFFER, &numDataReceived);
			totalDataReceived += numDataReceived;
			_lock.lock();
			responseBuffer.set_BufferSize(__FILE__LINE__ totalDataReceived);
		}
		responseString.convertFromByteBuffer(responseBuffer);
		responseString.SubString(10, numData, buffer);
	}
Пример #6
0
	virtual int main()
	{
		int result = 0;

		if (m_bHelp)
		{
			CStringBuffer tmp;

			usage(tmp);
			MessageBox(NULL, tmp.GetString(), _T("Usage"), MB_OK | MB_ICONINFORMATION);
			return result;
		}

		if (!m_bAnyOption)
		{
			get_ResourceManager()->add_resource(_T("CFRAMEWND"), CResourceManager::WindowAccelarator, IDC_XGUILOG);
			get_ResourceManager()->add_resource(_T("CFRAMEWND"), CResourceManager::WindowTitle, IDS_APP_TITLE);
			get_ResourceManager()->add_resource(_T("CFRAMEWND"), CResourceManager::WindowIcon, IDI_XGUILOG);
			get_ResourceManager()->add_resource(_T("CFRAMEWND"), CResourceManager::WindowSmallIcon, IDI_SMALL);
			get_ResourceManager()->add_resource(_T("CFRAMEWND"), CResourceManager::WindowMenu, IDC_XGUILOG);

			XGuiLog* win = OK_NEW_OPERATOR XGuiLog();

			win->set_ClientBorder(TRUE);
			win->set_ClientHScrollEnabled(TRUE);
			win->set_ClientVScrollEnabled(TRUE);
			win->set_StatusBarEnabled(TRUE);
			win->set_ToolBarEnabled(TRUE);
			win->set_DockingEnabled(TRUE);
			result = do_messageloop(win);
		}
		if (m_bMDITest)
		{
			get_ResourceManager()->add_resource(_T("CMDIFRAME"), CResourceManager::WindowAccelarator, IDC_XMDITEST);
			get_ResourceManager()->add_resource(_T("CMDIFRAME"), CResourceManager::WindowTitle, IDS_APP_TITLE);
			get_ResourceManager()->add_resource(_T("CMDIFRAME"), CResourceManager::WindowIcon, IDI_XGUILOG);
			get_ResourceManager()->add_resource(_T("CMDIFRAME"), CResourceManager::WindowSmallIcon, IDI_SMALL);
			get_ResourceManager()->add_resource(_T("CMDIFRAME"), CResourceManager::WindowMenu, IDC_XMDITEST);

			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest1"), CResourceManager::WindowTitle, IDS_DOCKING);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest1"), CResourceManager::WindowIcon, IDI_DOCKING);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest1"), CResourceManager::WindowSmallIcon, IDI_DOCKING);

			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest2"), CResourceManager::WindowTitle, IDS_CLASSVIEW);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest2"), CResourceManager::WindowIcon, IDI_CLASSVIEW);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest2"), CResourceManager::WindowSmallIcon, IDI_CLASSVIEW);

			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest3"), CResourceManager::WindowTitle, IDS_FILEVIEW);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest3"), CResourceManager::WindowIcon, IDI_FILEVIEW);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest3"), CResourceManager::WindowSmallIcon, IDI_FILEVIEW);

			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest4"), CResourceManager::WindowTitle, IDS_RECT);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest4"), CResourceManager::WindowIcon, IDI_RECT);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest4"), CResourceManager::WindowSmallIcon, IDI_RECT);

			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest5"), CResourceManager::WindowTitle, IDS_TEXT);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest5"), CResourceManager::WindowIcon, IDI_TEXT);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest5"), CResourceManager::WindowSmallIcon, IDI_TEXT);

			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest6"), CResourceManager::WindowTitle, IDS_TEXT);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest6"), CResourceManager::WindowIcon, IDI_TEXT);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest6"), CResourceManager::WindowSmallIcon, IDI_TEXT);

			XGuiMDITest* win = OK_NEW_OPERATOR XGuiMDITest();

			win->set_StatusBarEnabled(TRUE);
			win->set_ToolBarEnabled(TRUE);
			win->set_DockingEnabled(TRUE);
			result = do_messageloop(win);
		}
		return result;
	}