OSDN Git Service

* win32.cc (WSAEventWrapper): Implemented default
[pf3gnuchains/gcc-fork.git] / libjava / include / win32.h
1 // win32.h -- Helper functions for Microsoft-flavored OSs.
2
3 /* Copyright (C) 2002, 2003  Free Software Foundation
4
5    This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10
11 #ifndef __JV_WIN32_H__
12 #define __JV_WIN32_H__
13
14 // Enable UNICODE Support.?
15
16 #ifdef MINGW_LIBGCJ_UNICODE
17 #define UNICODE
18 #define _UNICODE
19 #endif // MINGW_LIBGCJ_UNICODE
20
21 #include <tchar.h>
22
23 // Includes
24 #define WIN32_LEAN_AND_MEAN
25 #include <windows.h>
26 #undef WIN32_LEAN_AND_MEAN
27 #undef STRICT
28
29 #include <ws2tcpip.h>
30 #include <gcj/cni.h>
31 #include <jvm.h>
32 #include <java/util/Properties.h>
33
34 #include <io.h>
35
36 /* Begin UNICODE Support Classes and Functions */
37
38 /* Helper class which creates a temporary, null-terminated,
39    wide-character C string. */
40 class _Jv_Win32TempString
41 {
42 public:
43   _Jv_Win32TempString(jstring jstr);
44   ~_Jv_Win32TempString();
45
46 // Accessors
47   operator LPCTSTR() const
48   {
49     return buf_;
50   }
51   LPCTSTR buf() const
52   {
53     return buf_;
54   }
55   LPTSTR buf()
56   {
57     return buf_;
58   }
59
60 private:
61   TCHAR stackbuf_[500];
62   LPTSTR buf_;
63 };
64
65 // Mimics the JV_TEMP_STRING_UTF macro in jvm.h
66 #define JV_TEMP_STRING_WIN32(x,y) _Jv_Win32TempString x(y);
67
68 // Creates a jstring from a LPCTSTR
69 extern jstring _Jv_Win32NewString (LPCTSTR pcsz);
70
71 /* End UNICODE Helpers */
72
73 // Prefix and suffix for shared libraries.
74 #define _Jv_platform_solib_prefix ""
75 #define _Jv_platform_solib_suffix ".dll"
76
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) ';')
81
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 }
88
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
92
93 /* Useful helper classes and methods. */
94
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
101 {
102 public:
103   // Default constructor. Call init() after this.
104   WSAEventWrapper();
105   WSAEventWrapper(int fd, DWORD dwSelFlags);
106   ~WSAEventWrapper();
107
108   // Used for two-step initialization after calling
109   // default constructor.
110   void init(int fd, DWORD dwSelFlags);
111
112   int getFD()
113   {
114     return m_fd;
115   }
116
117   WSAEVENT getEventHandle()
118   {
119     return m_hEvent;
120   }
121
122 private:
123   WSAEVENT m_hEvent;
124   int m_fd;
125   DWORD m_dwSelFlags;
126 };
127
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);
135
136 extern jstring
137 _Jv_WinStrError (int nErrorCode);
138
139 extern void
140 _Jv_ThrowIOException (DWORD dwErrorCode);
141
142 extern void
143 _Jv_ThrowIOException ();
144
145 extern void
146 _Jv_ThrowSocketException (DWORD dwErrorCode);
147
148 extern void
149 _Jv_ThrowSocketException ();
150
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]);
156
157 extern void
158 _Jv_platform_close_on_exec (HANDLE h);
159
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)
166 {
167   if (usecs > 0UL)
168     {
169       unsigned long millis = ((usecs + 999UL) / 1000UL);
170       Sleep (millis);
171     }
172 }
173 #endif /* JV_HASH_SYNCHRONIZATION */
174
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);
178
179 #endif /* __JV_WIN32_H__ */