Author: janderwald
Date: Tue Sep 4 23:53:49 2007
New Revision: 28854
URL:
http://svn.reactos.org/svn/reactos?rev=28854&view=rev
Log:
- readd named pipe support for linux by Christoph_vW
- simplify named pipe code
- only allocate buffer for reading once
- dont format default hdd if it exists
- delay read at right position
- fix ROS_DELAY_READ option in config file - value is expected to be in seconds not
milliseconds
Modified:
trunk/reactos/tools/sysreg/namedpipe_reader.cpp
trunk/reactos/tools/sysreg/namedpipe_reader.h
trunk/reactos/tools/sysreg/rosboot_test.cpp
trunk/reactos/tools/sysreg/rosboot_test.h
trunk/reactos/tools/sysreg/txtmode.cfg
Modified: trunk/reactos/tools/sysreg/namedpipe_reader.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/namedpipe_rea…
==============================================================================
--- trunk/reactos/tools/sysreg/namedpipe_reader.cpp (original)
+++ trunk/reactos/tools/sysreg/namedpipe_reader.cpp Tue Sep 4 23:53:49 2007
@@ -20,15 +20,22 @@
using std::vector;
//---------------------------------------------------------------------------------------
- NamedPipeReader::NamedPipeReader() : DataSource(), h_Pipe(NULLVAL)
- {
-
+ NamedPipeReader::NamedPipeReader() : DataSource(), h_Pipe(NULLVAL), m_Buffer(0)
+ {
+#ifdef UNICODE
+ m_WBuffer = 0;
+#endif
}
//---------------------------------------------------------------------------------------
NamedPipeReader::~NamedPipeReader()
{
-
+ if (m_Buffer)
+ free(m_Buffer);
+#ifdef UNICODE
+ if (m_WBuffer)
+ free(m_WBuffer);
+#endif
}
bool NamedPipeReader::isSourceOpen()
@@ -45,15 +52,15 @@
cerr << "NamedPipeReader::openPipe> pipe already open" <<
endl;
return false;
}
-
+#ifndef __LINUX__
h_Pipe = CreateFile("\\\\.\\pipe\\qemu", //PipeCmd.c_str(),
- GENERIC_WRITE | GENERIC_READ,
- 0,
- NULL,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL,
- (HANDLE)
- NULL);
+ GENERIC_WRITE | GENERIC_READ,
+ 0,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ (HANDLE)
+ NULL);
if(INVALID_HANDLE_VALUE == h_Pipe) {
cerr << "NamedPipeReader::openPipe> failed to open pipe "
<< PipeCmd << " Error:" << GetLastError() << endl;
@@ -63,26 +70,46 @@
else
{
cout << "NamedPipeReader::openPipe> successfully opened pipe"
<< endl;
+ m_BufferLength = 100;
+ m_Buffer = (char*)malloc(sizeof(char) * m_BufferLength);
+#ifdef UNICODE
+ m_WBuffer = (WCHAR*)malloc(sizeof(WCHAR) * m_BufferLength);
+#endif
+ ConnectNamedPipe(h_Pipe,
+ 0);
+ return true;
+ }
+#else
+ h_Pipe = open("PipeCmd.c_str()", O_RDONLY);
+
+ if(INVALID_HANDLE_VALUE == h_Pipe) {
+ cerr << "NamedPipeReader::openPipe> failed to open pipe " <<
PipeCmd << endl;
+ h_Pipe = NULLVAL;
+ return false;
+ }
+ else
+ {
+ cout << "NamedPipeReader::openPipe> successfully opened pipe"
<< endl;
return true;
}
-
- ConnectNamedPipe(
- h_Pipe,
- 0);
+#endif
}
//---------------------------------------------------------------------------------------
bool NamedPipeReader::closeSource()
{
- if (h_Pipe == INVALID_HANDLE_VALUE)
+ if (h_Pipe == NULLVAL)
{
cerr << "NamedPipeReader::closePipe> pipe is not open" <<
endl;
return false;
}
+#ifdef __LINUX__
+ close(h_Pipe);
+#else
DisconnectNamedPipe(h_Pipe);
CloseHandle(h_Pipe);
-
+#endif
h_Pipe = NULLVAL;
return true;
}
@@ -173,70 +200,75 @@
append_line = false;
}
}
-
+//---------------------------------------------------------------------------------------
+ bool NamedPipeReader::readPipe(char * buffer, int bufferlength, long & read)
+ {
+
+#ifdef __LINUX__
+ long cbRead = read(h_Pipe,
+ buffer,
+ (bufferlength-1) * sizeof(char));
+#else
+ DWORD cbRead = 0;
+ BOOL fSuccess = ReadFile(h_Pipe,
+ buffer,
+ (bufferlength-1) * sizeof(char),
+ &cbRead,
+ NULL);
+
+ if (!fSuccess && GetLastError() != ERROR_MORE_DATA)
+ return false;
+#endif
+
+ read = cbRead;
+ return true;
+ }
//---------------------------------------------------------------------------------------
bool NamedPipeReader::readSource(vector<string> & vect)
{
- char * localbuf;
- DWORD localsize = 100;
size_t lines = vect.size ();
- BOOL fSuccess;
- localbuf = (char*) HeapAlloc(GetProcessHeap(), 0, localsize * sizeof(char));
-#ifdef UNICODE
- wchar_t * wbuf = (WCHAR*) HeapAlloc(GetProcessHeap(), 0, localsize * sizeof(wchar_t));
-#endif /* UNICODE */
- if (localbuf != NULL)
- {
- bool append_line = false;
- do
- {
- DWORD cbRead;
- do
- {
- ZeroMemory(localbuf, localsize * sizeof(char));
-#ifdef UNICODE
- ZeroMemory(wbuf, localsize * sizeof(wchar_t));
-#endif /* UNICODE */
-
- fSuccess = ReadFile(
- h_Pipe,
- localbuf,
- (localsize-1) * sizeof(char),
- &cbRead,
- NULL);
-
- if (! fSuccess && GetLastError() != ERROR_MORE_DATA)
- break;
-
-#ifdef UNICODE
- if (UnicodeConverter::ansi2Unicode(localbuf, wbuf, cbRead))
- {
- extractLines(wbuf, vect, append_line, cbRead);
- }
-#else /* UNICODE */
- extractLines(localbuf, vect, append_line, cbRead);
-#endif /* UNICODE */
-
- } while (!fSuccess); // repeat loop if ERROR_MORE_DATA
- } while (append_line);
-
- if (!fSuccess)
- return 0;
-
- HeapFree(GetProcessHeap(), 0, localbuf);
-#ifdef UNICODE
- HeapFree(GetProcessHeap(), 0, wbuf);
-#endif /* UNICODE */
- }
- else
- {
- return 0;
- }
-
- return (vect.size () - lines);
- }
+ if (h_Pipe == NULLVAL)
+ {
+ cerr << "Error: pipe is not open" << endl;
+ return false;
+ }
+
+ if (!m_Buffer)
+ {
+ cerr << "Error: no memory" << endl;
+ }
+
+#ifdef UNICODE
+ if (!m_WBuffer)
+ {
+ cerr << "Error: no memory" << endl;
+ }
+#endif
+
+ bool append_line = false;
+ do
+ {
+ memset(m_Buffer, 0x0, m_BufferLength * sizeof(char));
+ long cbRead = 0;
+
+ if (!readPipe(m_Buffer, 100, cbRead))
+ break;
+
+#ifdef UNICODE
+ memset(m_WBuffer, 0x0, m_BufferLength * sizeof(WCHAR));
+ if (!UnicodeConverter::ansi2Unicode(m_Buffer, m_WBuffer, cbRead))
+ break;
+ extractLines(m_WBuffer, vect, append_line, cbRead);
+#endif
+ extractLines(m_Buffer, vect, append_line, cbRead);
+
+
+ }while (append_line);
+
+ return (vect.size () - lines);
+}
} // end of namespace System_
Modified: trunk/reactos/tools/sysreg/namedpipe_reader.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/namedpipe_rea…
==============================================================================
--- trunk/reactos/tools/sysreg/namedpipe_reader.h (original)
+++ trunk/reactos/tools/sysreg/namedpipe_reader.h Tue Sep 4 23:53:49 2007
@@ -120,8 +120,15 @@
void extractLines(TCHAR * buffer, std::vector<string> & vect, bool &
append_line, unsigned long cbRead);
+ bool readPipe(char * buffer, int bufferlength, long & read);
+
HANDLE h_Pipe;
+ char * m_Buffer;
+ int m_BufferLength;
+#ifdef UNICODE
+ WCHAR * m_WBuffer;
+#endif
}; // end of class NamedPipeReader
Modified: trunk/reactos/tools/sysreg/rosboot_test.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/rosboot_test.…
==============================================================================
--- trunk/reactos/tools/sysreg/rosboot_test.cpp (original)
+++ trunk/reactos/tools/sysreg/rosboot_test.cpp Tue Sep 4 23:53:49 2007
@@ -247,12 +247,14 @@
}
#ifdef __LINUX__
- pipe = _T("stdio");
- m_Src = _T("");
+ pipe = _T("pipe:/tmp/qemu");
+ m_Src = _T("/tmp/qemu");
qemudir = _T("/usr/share/qemu");
+ m_DebugPort = _T("pipe");
#else
pipe = _T("pipe:qemu");
m_Src = _T("\\\\.\\pipe\\qemu");
+ m_DebugPort = _T("pipe");
if (!getQemuDir(qemudir))
{
return false;
@@ -322,29 +324,26 @@
pos = pipe.find(_T("pipe:"));
if (pos == 0)
{
-#ifdef __LINUX__
- cerr << "Error: reading from pipes is not supported with linux
hosts - use stdio" << endl;
- return false;
- }
-#else
pipe = pipe.substr(pos + 5, pipe.size() - pos - 5);
pos = pipe.find(_T(" "));
if (pos != string::npos)
{
- m_Src = _T("\\\\.\\pipe\\") + pipe.substr(0, pos);
- }
- else
- {
- m_Src = _T("\\\\.\\pipe\\") + pipe;
- }
+ pipe = pipe.substr(0, pos);
+ }
+#ifdef __LINUX__
+ m_Src = pipe;
+#else
+ m_Src = _T("\\\\.\\pipe\\") + pipe.substr(0, pos);
+#endif
+ m_DebugPort = _T("pipe");
return true;
}
-#endif
pos = pipe.find(_T("stdio"));
if (pos == 0)
{
#ifdef __LINUX__
m_Src = m_BootCmd;
+ m_DebugPort = _T("stdio");
return true;
#else
cerr << "Error: reading from stdio is not supported for windows hosts - use
pipes" << endl;
@@ -387,6 +386,11 @@
}
getDefaultHDDImage(m_HDDImage);
+ if (isFileExisting(m_HDDImage))
+ {
+ cerr << "Falling back to default hdd image " <<
m_HDDImage << endl;
+ return true;
+ }
return createHDDImage(m_HDDImage);
}
/*
@@ -552,19 +556,20 @@
}
cerr << "Opening Data Source:" << m_BootCmd << endl;
-
+/*
#ifdef __LINUX__
_tremove(m_PidFile.c_str ());
m_DataSource = new PipeReader();
m_Src = m_BootCmd;
#else
+*/
m_DataSource = new NamedPipeReader();
if (!executeBootCmd())
{
cerr << "Error: failed to launch emulator with: " <<
m_BootCmd << endl;
return false;
}
-#endif
+//#endif
return true;
}
@@ -659,23 +664,19 @@
return false;
}
#endif
-#ifndef __LINUX__
- OsSupport::delayExecution(1);
-#endif
-
- assert(m_DataSource != 0);
+
+ if (m_DelayRead)
+ {
+ cerr << "Delaying read for " << m_DelayRead <<
" seconds" << endl;
+ OsSupport::delayExecution(m_DelayRead);
+ }
+
if (!m_DataSource->openSource(m_Src))
{
cerr << "Error: failed to open data source with " <<
m_Src << endl;
cleanup();
return false;
}
-
- if (m_DelayRead)
- {
- OsSupport::delayExecution(m_DelayRead);
- }
-
#ifdef __LINUX__
/*
* For linux systems we can only
Modified: trunk/reactos/tools/sysreg/rosboot_test.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/rosboot_test.…
==============================================================================
--- trunk/reactos/tools/sysreg/rosboot_test.h (original)
+++ trunk/reactos/tools/sysreg/rosboot_test.h Tue Sep 4 23:53:49 2007
@@ -157,6 +157,7 @@
string m_MaxMem;
string m_BootCmd;
string m_Src;
+ string m_DebugPort;
string m_PidFile;
DataSource * m_DataSource;
Modified: trunk/reactos/tools/sysreg/txtmode.cfg
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/txtmode.cfg?r…
==============================================================================
--- trunk/reactos/tools/sysreg/txtmode.cfg (original)
+++ trunk/reactos/tools/sysreg/txtmode.cfg Tue Sep 4 23:53:49 2007
@@ -60,7 +60,7 @@
;
; Note: set this value if you have problems with timeouts or cutoff debugging data
;
-ROS_DELAY_READ=4000
+ROS_DELAY_READ=4
; ROS_CHECK_POINT
;