2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / include / win32.h
blob8dd2964e6372fbda9bed145eb22c0bb14b445e80
1 // win32.h -- Helper functions for Microsoft-flavored OSs.
3 /* Copyright (C) 2002, 2003 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
11 #ifndef __JV_WIN32_H__
12 #define __JV_WIN32_H__
14 // Enable UNICODE Support.?
16 #ifdef MINGW_LIBGCJ_UNICODE
17 #define UNICODE
18 #define _UNICODE
19 #endif // MINGW_LIBGCJ_UNICODE
21 #include <tchar.h>
23 // Includes
24 #define WIN32_LEAN_AND_MEAN
25 #include <windows.h>
26 #undef WIN32_LEAN_AND_MEAN
27 #undef STRICT
29 #include <ws2tcpip.h>
30 #include <gcj/cni.h>
31 #include <jvm.h>
32 #include <java/util/Properties.h>
34 #include <io.h>
36 /* Begin UNICODE Support Classes and Functions */
38 /* Helper class which creates a temporary, null-terminated,
39 wide-character C string. */
40 class _Jv_Win32TempString
42 public:
43 _Jv_Win32TempString(jstring jstr);
44 ~_Jv_Win32TempString();
46 // Accessors
47 operator LPCTSTR() const
49 return buf_;
51 LPCTSTR buf() const
53 return buf_;
55 LPTSTR buf()
57 return buf_;
60 private:
61 TCHAR stackbuf_[500];
62 LPTSTR buf_;
65 // Mimics the JV_TEMP_STRING_UTF macro in jvm.h
66 #define JV_TEMP_STRING_WIN32(x,y) _Jv_Win32TempString x(y);
68 // Creates a jstring from a LPCTSTR
69 extern jstring _Jv_Win32NewString (LPCTSTR pcsz);
71 /* End UNICODE Helpers */
73 // Prefix and suffix for shared libraries.
74 #define _Jv_platform_solib_prefix ""
75 #define _Jv_platform_solib_suffix ".dll"
77 // Separator for file name components.
78 #define _Jv_platform_file_separator ((jchar) '\\')
79 // Separator for path components.
80 #define _Jv_platform_path_separator ((jchar) ';')
82 // List of names for `JNI_OnLoad'. On Win32, JNI_OnLoad is an
83 // "stdcall" function taking two pointers (8 bytes) as arguments. It
84 // could also have been exported as "JNI_OnLoad@8" (MinGW) or
85 // "_JNI_OnLoad@8" (MSVC).
86 #define _Jv_platform_onload_names \
87 { "JNI_OnLoad", "JNI_OnLoad@8", "_JNI_OnLoad@8", NULL }
89 // Type of libffi ABI used by JNICALL methods. NOTE: This must agree
90 // with the JNICALL definition in jni.h
91 #define _Jv_platform_ffi_abi FFI_STDCALL
93 /* Useful helper classes and methods. */
95 /* A C++ wrapper around a WSAEVENT which closes the event
96 in its destructor. If dwSelFlags is non-zero, we also
97 issue an WSAEventSelect on the socket descriptor with
98 the given flags; this is undone by a corresponding call
99 to WSAEventSelect(fd, 0, 0) in our destructor. */
100 class WSAEventWrapper
102 public:
103 // Default constructor. Call init() after this.
104 WSAEventWrapper();
105 WSAEventWrapper(int fd, DWORD dwSelFlags);
106 ~WSAEventWrapper();
108 // Used for two-step initialization after calling
109 // default constructor.
110 void init(int fd, DWORD dwSelFlags);
112 int getFD()
114 return m_fd;
117 WSAEVENT getEventHandle()
119 return m_hEvent;
122 private:
123 WSAEVENT m_hEvent;
124 int m_fd;
125 DWORD m_dwSelFlags;
128 // Error string text. The int argument is compatible
129 // with both int WSAGetLastError() and DWORD GetLastError()
130 // I tried avoiding having to pass the error explicitly, but
131 // it didn't work this was invoked with say
132 // throw new SomeException(_Jv_WinStrError()).
133 extern jstring
134 _Jv_WinStrError (LPCTSTR lpszPrologue, int nErrorCode);
136 extern jstring
137 _Jv_WinStrError (int nErrorCode);
139 extern void
140 _Jv_ThrowIOException (DWORD dwErrorCode);
142 extern void
143 _Jv_ThrowIOException ();
145 extern void
146 _Jv_ThrowSocketException (DWORD dwErrorCode);
148 extern void
149 _Jv_ThrowSocketException ();
151 // Platform implementation
152 extern void _Jv_platform_initialize (void);
153 extern void _Jv_platform_initProperties (java::util::Properties*);
154 extern jlong _Jv_platform_gettimeofday ();
155 extern int _Jv_pipe (int filedes[2]);
157 extern void
158 _Jv_platform_close_on_exec (HANDLE h);
160 #ifdef JV_HASH_SYNCHRONIZATION
161 /* Suspends the execution of the current thread for the specified
162 number of microseconds. Tries to emulate the behaviour of usleep()
163 on UNIX and provides a granularity of 1 millisecond. */
164 inline void
165 _Jv_platform_usleep (unsigned long usecs)
167 if (usecs > 0UL)
169 unsigned long millis = ((usecs + 999UL) / 1000UL);
170 Sleep (millis);
173 #endif /* JV_HASH_SYNCHRONIZATION */
175 /* Store up to SIZE return address of the current program state in
176 ARRAY and return the exact number of values stored. */
177 extern int backtrace (void **__array, int __size);
179 #endif /* __JV_WIN32_H__ */