Author: cwittich
Date: Mon Jan 22 22:34:53 2007
New Revision: 25599
URL:
http://svn.reactos.org/svn/reactos?rev=25599&view=rev
Log:
named pipes support for linux builds
Modified:
trunk/reactos/tools/sysreg/file_reader.cpp
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/sysreg.mak
Modified: trunk/reactos/tools/sysreg/file_reader.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/file_reader.c…
==============================================================================
--- trunk/reactos/tools/sysreg/file_reader.cpp (original)
+++ trunk/reactos/tools/sysreg/file_reader.cpp Mon Jan 22 22:34:53 2007
@@ -133,9 +133,9 @@
TCHAR * offset = szBuffer;
#endif
total_length = 0;
- while(ptr = _tcsstr(offset, _T("\x0D\x0A")))
+ while((ptr = _tcsstr(offset, _T("\x0D\x0A"))) != NULL)
{
- int length = ((unsigned)ptr - (unsigned)offset);
+ long long length = ((long long)ptr - (long long)offset);
length /= sizeof(TCHAR);
offset[length] = _T('\0');
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 Mon Jan 22 22:34:53 2007
@@ -5,7 +5,7 @@
* FILE: tools/sysreg/namedpipe_reader.cpp
* PURPOSE: pipe reader support
* PROGRAMMERS: Johannes Anderwald (johannes.anderwald at sbox tugraz at)
- * Christoph von Wittich (Christoph(a)ApiViewer.de)
+ * Christoph von Wittich (Christoph_vW(a)ReactOS.org)
*/
#include "namedpipe_reader.h"
@@ -20,7 +20,7 @@
using std::vector;
//---------------------------------------------------------------------------------------
- NamedPipeReader::NamedPipeReader() : h_Pipe(NULL)
+ NamedPipeReader::NamedPipeReader() : h_Pipe(NULLVAL)
{
}
@@ -35,15 +35,13 @@
bool NamedPipeReader::openPipe(string const & PipeCmd)
{
- if (h_Pipe != NULL)
+ if (h_Pipe != NULLVAL)
{
cerr << "NamedPipeReader::openPipe> pipe already open" <<
endl;
return false;
}
-#ifdef __LINUX__
-
-#else
+#ifdef WIN32
h_Pipe = CreateFile(PipeCmd.c_str(),
GENERIC_WRITE | GENERIC_READ,
0,
@@ -55,6 +53,7 @@
if(INVALID_HANDLE_VALUE == h_Pipe) {
cerr << "NamedPipeReader::openPipe> failed to open pipe " <<
PipeCmd << GetLastError() << endl;
+ h_Pipe = NULLVAL;
return false;
}
else
@@ -66,7 +65,19 @@
ConnectNamedPipe(
h_Pipe,
0);
-
+#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;
+ }
#endif
}
@@ -82,14 +93,14 @@
}
-#ifdef __LINUX__
-
+#ifndef WIN32
+ close(h_Pipe);
#else
DisconnectNamedPipe(h_Pipe);
CloseHandle(h_Pipe);
#endif
- h_Pipe = NULL;
+ h_Pipe = NULLVAL;
return true;
}
//---------------------------------------------------------------------------------------
@@ -193,7 +204,7 @@
localbuf = (char*) HeapAlloc(GetProcessHeap(), 0, localsize * sizeof(char));
#ifdef UNICODE
wchar_t * wbuf = (WCHAR*) HeapAlloc(GetProcessHeap(), 0, localsize * sizeof(wchar_t));
-#endif
+#endif /* UNICODE */
if (localbuf != NULL)
{
bool append_line = false;
@@ -205,7 +216,7 @@
ZeroMemory(localbuf, localsize * sizeof(char));
#ifdef UNICODE
ZeroMemory(wbuf, localsize * sizeof(wchar_t));
-#endif
+#endif /* UNICODE */
fSuccess = ReadFile(
h_Pipe,
@@ -222,9 +233,9 @@
{
extractLines(wbuf, vect, append_line, cbRead);
}
-#else
+#else /* UNICODE */
extractLines(localbuf, vect, append_line, cbRead);
-#endif
+#endif /* UNICODE */
} while (!fSuccess); // repeat loop if ERROR_MORE_DATA
} while (append_line);
@@ -235,13 +246,52 @@
HeapFree(GetProcessHeap(), 0, localbuf);
#ifdef UNICODE
HeapFree(GetProcessHeap(), 0, wbuf);
-#endif
+#endif /* UNICODE */
}
else
{
return 0;
}
-#endif
+
+#else /* WIN32 */
+
+ localbuf = (char*) malloc(localsize * sizeof(char));
+ if (localbuf != NULL)
+ {
+
+ DWORD cbRead;
+
+ bool append_line = false;
+ do
+ {
+ do
+ {
+ memset(localbuf, 0, localsize * sizeof(char));
+
+ cbRead = read(h_Pipe,
+ localbuf,
+ (localsize-1) * sizeof(char));
+
+ if (cbRead > 0)
+ {
+ extractLines(localbuf, vect, append_line, cbRead);
+ }
+
+ } while (!cbRead); // repeat loop as long as there is data to read
+ } while (append_line);
+
+ if (cbRead < 0)
+ return 0;
+
+
+ free(localbuf);
+ }
+ else
+ {
+ return 0;
+ }
+
+#endif /* WIN32 */
return (vect.size () - lines);
}
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 Mon Jan 22 22:34:53 2007
@@ -18,10 +18,20 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef __LINUX__
-
-#elif defined(WIN32)
- #include <windows.h>
+#if defined(WIN32)
+#include <windows.h>
+#define NULLVAL NULL
+#else
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#define NULLVAL 0
+#define DWORD unsigned long
+#define HANDLE long
+#ifndef INVALID_HANDLE_VALUE
+#define INVALID_HANDLE_VALUE -1
+#endif
#endif
namespace System_
@@ -110,8 +120,6 @@
void extractLines(TCHAR * buffer, std::vector<string> & vect, bool &
append_line, unsigned long cbRead);
-
-
HANDLE h_Pipe;
}; // 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 Mon Jan 22 22:34:53 2007
@@ -11,7 +11,7 @@
#include "rosboot_test.h"
#include "pipe_reader.h"
-//#include "namedpipe_reader.h"
+#include "namedpipe_reader.h"
//#include "sym_file.h"
#include "file_reader.h"
#include "os_support.h"
@@ -31,10 +31,8 @@
{
using std::vector;
using System_::PipeReader;
-#if 0
using System_::NamedPipeReader;
- using System_::SymbolFile;
-#endif
+/* using System_::SymbolFile; */
using System_::FileReader;
using System_::OsSupport;
@@ -349,8 +347,8 @@
/// FIXME
/// split up arguments
+
OsSupport::ProcessID pid = OsSupport::createProcess ((TCHAR*)boot_cmd.c_str (), 0,
NULL);
-#if 0
string::size_type pipe_pos = boot_cmd.find (_T("serial pipe:"));
NamedPipeReader namedpipe_reader;
@@ -440,7 +438,7 @@
}
_sleep(3* CLOCKS_PER_SEC);
OsSupport::terminateProcess (pid);
-#endif
+
return ret;
}
//---------------------------------------------------------------------------------------
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 Mon Jan 22 22:34:53 2007
@@ -13,6 +13,10 @@
#include "reg_test.h"
#include <vector>
+#ifndef WIN32
+#include <unistd.h>
+#define _sleep sleep
+#endif
namespace Sysreg_
{
Modified: trunk/reactos/tools/sysreg/sysreg.mak
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/sysreg.mak?re…
==============================================================================
--- trunk/reactos/tools/sysreg/sysreg.mak (original)
+++ trunk/reactos/tools/sysreg/sysreg.mak Mon Jan 22 22:34:53 2007
@@ -22,6 +22,7 @@
conf_parser.cpp \
env_var.cpp \
pipe_reader.cpp \
+ namedpipe_reader.cpp \
rosboot_test.cpp \
sysreg.cpp \
file_reader.cpp \
@@ -87,4 +88,4 @@
.PHONY: sysregbuild_clean
sysreg_clean:
-@$(rm) $(SYSREGBUILD_TARGET) $(SYSREGBUILD_OBJECTS) 2>$(NUL)
-clean: sysreg_clean
+clean: sysreg_clean