diff options
Diffstat (limited to 'src/3rdParty/efsw/platform')
17 files changed, 1017 insertions, 0 deletions
diff --git a/src/3rdParty/efsw/platform/platformimpl.hpp b/src/3rdParty/efsw/platform/platformimpl.hpp new file mode 100755 index 0000000..5442580 --- /dev/null +++ b/src/3rdParty/efsw/platform/platformimpl.hpp | |||
@@ -0,0 +1,20 @@ | |||
1 | #ifndef EFSW_PLATFORMIMPL_HPP | ||
2 | #define EFSW_PLATFORMIMPL_HPP | ||
3 | |||
4 | #include <efsw/base.hpp> | ||
5 | |||
6 | #if defined( EFSW_PLATFORM_POSIX ) | ||
7 | #include <efsw/platform/posix/ThreadImpl.hpp> | ||
8 | #include <efsw/platform/posix/MutexImpl.hpp> | ||
9 | #include <efsw/platform/posix/SystemImpl.hpp> | ||
10 | #include <efsw/platform/posix/FileSystemImpl.hpp> | ||
11 | #elif EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
12 | #include <efsw/platform/win/ThreadImpl.hpp> | ||
13 | #include <efsw/platform/win/MutexImpl.hpp> | ||
14 | #include <efsw/platform/win/SystemImpl.hpp> | ||
15 | #include <efsw/platform/win/FileSystemImpl.hpp> | ||
16 | #else | ||
17 | #error Thread, Mutex, and System not implemented for this platform. | ||
18 | #endif | ||
19 | |||
20 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/posix/FileSystemImpl.cpp b/src/3rdParty/efsw/platform/posix/FileSystemImpl.cpp new file mode 100755 index 0000000..92eeb47 --- /dev/null +++ b/src/3rdParty/efsw/platform/posix/FileSystemImpl.cpp | |||
@@ -0,0 +1,251 @@ | |||
1 | #include <efsw/platform/posix/FileSystemImpl.hpp> | ||
2 | |||
3 | #if defined( EFSW_PLATFORM_POSIX ) | ||
4 | |||
5 | #include <cstring> | ||
6 | #include <dirent.h> | ||
7 | #include <efsw/FileInfo.hpp> | ||
8 | #include <efsw/FileSystem.hpp> | ||
9 | #include <unistd.h> | ||
10 | |||
11 | #ifndef _DARWIN_FEATURE_64_BIT_INODE | ||
12 | #define _DARWIN_FEATURE_64_BIT_INODE | ||
13 | #endif | ||
14 | |||
15 | #ifndef _FILE_OFFSET_BITS | ||
16 | #define _FILE_OFFSET_BITS 64 | ||
17 | #endif | ||
18 | |||
19 | #include <climits> | ||
20 | #include <cstdlib> | ||
21 | #include <sys/stat.h> | ||
22 | |||
23 | #if EFSW_OS == EFSW_OS_LINUX || EFSW_OS == EFSW_OS_SOLARIS || EFSW_OS == EFSW_OS_ANDROID | ||
24 | #include <sys/vfs.h> | ||
25 | #elif EFSW_OS == EFSW_OS_MACOSX || EFSW_OS == EFSW_OS_BSD || EFSW_OS == EFSW_OS_IOS | ||
26 | #include <sys/mount.h> | ||
27 | #include <sys/param.h> | ||
28 | #endif | ||
29 | |||
30 | /** Remote file systems codes */ | ||
31 | #define S_MAGIC_AFS 0x5346414F | ||
32 | #define S_MAGIC_AUFS 0x61756673 | ||
33 | #define S_MAGIC_CEPH 0x00C36400 | ||
34 | #define S_MAGIC_CIFS 0xFF534D42 | ||
35 | #define S_MAGIC_CODA 0x73757245 | ||
36 | #define S_MAGIC_FHGFS 0x19830326 | ||
37 | #define S_MAGIC_FUSEBLK 0x65735546 | ||
38 | #define S_MAGIC_FUSECTL 0x65735543 | ||
39 | #define S_MAGIC_GFS 0x01161970 | ||
40 | #define S_MAGIC_GPFS 0x47504653 | ||
41 | #define S_MAGIC_KAFS 0x6B414653 | ||
42 | #define S_MAGIC_LUSTRE 0x0BD00BD0 | ||
43 | #define S_MAGIC_NCP 0x564C | ||
44 | #define S_MAGIC_NFS 0x6969 | ||
45 | #define S_MAGIC_NFSD 0x6E667364 | ||
46 | #define S_MAGIC_OCFS2 0x7461636F | ||
47 | #define S_MAGIC_PANFS 0xAAD7AAEA | ||
48 | #define S_MAGIC_PIPEFS 0x50495045 | ||
49 | #define S_MAGIC_SMB 0x517B | ||
50 | #define S_MAGIC_SNFS 0xBEEFDEAD | ||
51 | #define S_MAGIC_VMHGFS 0xBACBACBC | ||
52 | #define S_MAGIC_VXFS 0xA501FCF5 | ||
53 | |||
54 | #if EFSW_OS == EFSW_OS_LINUX | ||
55 | #include <cstdio> | ||
56 | #include <mntent.h> | ||
57 | #endif | ||
58 | |||
59 | namespace efsw { namespace Platform { | ||
60 | |||
61 | #if EFSW_OS == EFSW_OS_LINUX | ||
62 | |||
63 | std::string findMountPoint( std::string file ) { | ||
64 | std::string cwd = FileSystem::getCurrentWorkingDirectory(); | ||
65 | struct stat last_stat; | ||
66 | struct stat file_stat; | ||
67 | |||
68 | stat( file.c_str(), &file_stat ); | ||
69 | |||
70 | std::string mp; | ||
71 | |||
72 | if ( efsw::FileSystem::isDirectory( file ) ) { | ||
73 | last_stat = file_stat; | ||
74 | |||
75 | if ( !FileSystem::changeWorkingDirectory( file ) ) | ||
76 | return ""; | ||
77 | } else { | ||
78 | std::string dir = efsw::FileSystem::pathRemoveFileName( file ); | ||
79 | |||
80 | if ( !FileSystem::changeWorkingDirectory( dir ) ) | ||
81 | return ""; | ||
82 | |||
83 | if ( stat( ".", &last_stat ) < 0 ) | ||
84 | return ""; | ||
85 | } | ||
86 | |||
87 | while ( true ) { | ||
88 | struct stat st; | ||
89 | |||
90 | if ( stat( "..", &st ) < 0 ) | ||
91 | goto done; | ||
92 | |||
93 | if ( st.st_dev != last_stat.st_dev || st.st_ino == last_stat.st_ino ) | ||
94 | break; | ||
95 | |||
96 | if ( !FileSystem::changeWorkingDirectory( ".." ) ) { | ||
97 | goto done; | ||
98 | } | ||
99 | |||
100 | last_stat = st; | ||
101 | } | ||
102 | |||
103 | /* Finally reached a mount point, see what it's called. */ | ||
104 | mp = FileSystem::getCurrentWorkingDirectory(); | ||
105 | |||
106 | done: | ||
107 | FileSystem::changeWorkingDirectory( cwd ); | ||
108 | |||
109 | return mp; | ||
110 | } | ||
111 | |||
112 | std::string findDevicePath( const std::string& directory ) { | ||
113 | struct mntent* ent; | ||
114 | FILE* aFile; | ||
115 | |||
116 | aFile = setmntent( "/proc/mounts", "r" ); | ||
117 | |||
118 | if ( aFile == NULL ) | ||
119 | return ""; | ||
120 | |||
121 | while ( NULL != ( ent = getmntent( aFile ) ) ) { | ||
122 | std::string dirName( ent->mnt_dir ); | ||
123 | |||
124 | if ( dirName == directory ) { | ||
125 | std::string fsName( ent->mnt_fsname ); | ||
126 | |||
127 | endmntent( aFile ); | ||
128 | |||
129 | return fsName; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | endmntent( aFile ); | ||
134 | |||
135 | return ""; | ||
136 | } | ||
137 | |||
138 | bool isLocalFUSEDirectory( std::string directory ) { | ||
139 | efsw::FileSystem::dirRemoveSlashAtEnd( directory ); | ||
140 | |||
141 | directory = findMountPoint( directory ); | ||
142 | |||
143 | if ( !directory.empty() ) { | ||
144 | std::string devicePath = findDevicePath( directory ); | ||
145 | |||
146 | return !devicePath.empty(); | ||
147 | } | ||
148 | |||
149 | return false; | ||
150 | } | ||
151 | |||
152 | #endif | ||
153 | |||
154 | bool FileSystem::changeWorkingDirectory( const std::string& path ) { | ||
155 | return -1 != chdir( path.c_str() ); | ||
156 | } | ||
157 | |||
158 | std::string FileSystem::getCurrentWorkingDirectory() { | ||
159 | char dir[PATH_MAX + 1]; | ||
160 | char* result = getcwd( dir, PATH_MAX + 1 ); | ||
161 | return result != NULL ? std::string( result ) : std::string(); | ||
162 | } | ||
163 | |||
164 | FileInfoMap FileSystem::filesInfoFromPath( const std::string& path ) { | ||
165 | FileInfoMap files; | ||
166 | |||
167 | DIR* dp; | ||
168 | struct dirent* dirp; | ||
169 | |||
170 | if ( ( dp = opendir( path.c_str() ) ) == NULL ) | ||
171 | return files; | ||
172 | |||
173 | while ( ( dirp = readdir( dp ) ) != NULL ) { | ||
174 | if ( strcmp( dirp->d_name, ".." ) != 0 && strcmp( dirp->d_name, "." ) != 0 ) { | ||
175 | std::string name( dirp->d_name ); | ||
176 | std::string fpath( path + name ); | ||
177 | |||
178 | files[name] = FileInfo( fpath ); | ||
179 | } | ||
180 | } | ||
181 | |||
182 | closedir( dp ); | ||
183 | |||
184 | return files; | ||
185 | } | ||
186 | |||
187 | char FileSystem::getOSSlash() { | ||
188 | return '/'; | ||
189 | } | ||
190 | |||
191 | bool FileSystem::isDirectory( const std::string& path ) { | ||
192 | struct stat st; | ||
193 | int res = stat( path.c_str(), &st ); | ||
194 | |||
195 | if ( 0 == res ) { | ||
196 | return static_cast<bool>( S_ISDIR( st.st_mode ) ); | ||
197 | } | ||
198 | |||
199 | return false; | ||
200 | } | ||
201 | |||
202 | bool FileSystem::isRemoteFS( const std::string& directory ) { | ||
203 | #if EFSW_OS == EFSW_OS_LINUX || EFSW_OS == EFSW_OS_MACOSX || EFSW_OS == EFSW_OS_BSD || \ | ||
204 | EFSW_OS == EFSW_OS_SOLARIS || EFSW_OS == EFSW_OS_ANDROID || EFSW_OS == EFSW_OS_IOS | ||
205 | struct statfs statfsbuf; | ||
206 | |||
207 | statfs( directory.c_str(), &statfsbuf ); | ||
208 | |||
209 | switch ( statfsbuf.f_type | 0UL ) { | ||
210 | case S_MAGIC_FUSEBLK: /* 0x65735546 remote */ | ||
211 | { | ||
212 | #if EFSW_OS == EFSW_OS_LINUX | ||
213 | return !isLocalFUSEDirectory( directory ); | ||
214 | #endif | ||
215 | } | ||
216 | case S_MAGIC_AFS: /* 0x5346414F remote */ | ||
217 | case S_MAGIC_AUFS: /* 0x61756673 remote */ | ||
218 | case S_MAGIC_CEPH: /* 0x00C36400 remote */ | ||
219 | case S_MAGIC_CIFS: /* 0xFF534D42 remote */ | ||
220 | case S_MAGIC_CODA: /* 0x73757245 remote */ | ||
221 | case S_MAGIC_FHGFS: /* 0x19830326 remote */ | ||
222 | case S_MAGIC_FUSECTL: /* 0x65735543 remote */ | ||
223 | case S_MAGIC_GFS: /* 0x01161970 remote */ | ||
224 | case S_MAGIC_GPFS: /* 0x47504653 remote */ | ||
225 | case S_MAGIC_KAFS: /* 0x6B414653 remote */ | ||
226 | case S_MAGIC_LUSTRE: /* 0x0BD00BD0 remote */ | ||
227 | case S_MAGIC_NCP: /* 0x564C remote */ | ||
228 | case S_MAGIC_NFS: /* 0x6969 remote */ | ||
229 | case S_MAGIC_NFSD: /* 0x6E667364 remote */ | ||
230 | case S_MAGIC_OCFS2: /* 0x7461636F remote */ | ||
231 | case S_MAGIC_PANFS: /* 0xAAD7AAEA remote */ | ||
232 | case S_MAGIC_PIPEFS: /* 0x50495045 remote */ | ||
233 | case S_MAGIC_SMB: /* 0x517B remote */ | ||
234 | case S_MAGIC_SNFS: /* 0xBEEFDEAD remote */ | ||
235 | case S_MAGIC_VMHGFS: /* 0xBACBACBC remote */ | ||
236 | case S_MAGIC_VXFS: /* 0xA501FCF5 remote */ | ||
237 | { | ||
238 | return true; | ||
239 | } | ||
240 | default: { | ||
241 | return false; | ||
242 | } | ||
243 | } | ||
244 | #endif | ||
245 | |||
246 | return false; | ||
247 | } | ||
248 | |||
249 | }} // namespace efsw::Platform | ||
250 | |||
251 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/posix/FileSystemImpl.hpp b/src/3rdParty/efsw/platform/posix/FileSystemImpl.hpp new file mode 100755 index 0000000..0bfba76 --- /dev/null +++ b/src/3rdParty/efsw/platform/posix/FileSystemImpl.hpp | |||
@@ -0,0 +1,30 @@ | |||
1 | #ifndef EFSW_FILESYSTEMIMPLPOSIX_HPP | ||
2 | #define EFSW_FILESYSTEMIMPLPOSIX_HPP | ||
3 | |||
4 | #include <efsw/FileInfo.hpp> | ||
5 | #include <efsw/base.hpp> | ||
6 | |||
7 | #if defined( EFSW_PLATFORM_POSIX ) | ||
8 | |||
9 | namespace efsw { namespace Platform { | ||
10 | |||
11 | class FileSystem { | ||
12 | public: | ||
13 | static FileInfoMap filesInfoFromPath( const std::string& path ); | ||
14 | |||
15 | static char getOSSlash(); | ||
16 | |||
17 | static bool isDirectory( const std::string& path ); | ||
18 | |||
19 | static bool isRemoteFS( const std::string& directory ); | ||
20 | |||
21 | static bool changeWorkingDirectory( const std::string& path ); | ||
22 | |||
23 | static std::string getCurrentWorkingDirectory(); | ||
24 | }; | ||
25 | |||
26 | }} // namespace efsw::Platform | ||
27 | |||
28 | #endif | ||
29 | |||
30 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/posix/MutexImpl.cpp b/src/3rdParty/efsw/platform/posix/MutexImpl.cpp new file mode 100755 index 0000000..2233798 --- /dev/null +++ b/src/3rdParty/efsw/platform/posix/MutexImpl.cpp | |||
@@ -0,0 +1,28 @@ | |||
1 | #include <efsw/platform/posix/MutexImpl.hpp> | ||
2 | |||
3 | #if defined( EFSW_PLATFORM_POSIX ) | ||
4 | |||
5 | namespace efsw { namespace Platform { | ||
6 | |||
7 | MutexImpl::MutexImpl() { | ||
8 | pthread_mutexattr_t attributes; | ||
9 | pthread_mutexattr_init( &attributes ); | ||
10 | pthread_mutexattr_settype( &attributes, PTHREAD_MUTEX_RECURSIVE ); | ||
11 | pthread_mutex_init( &mMutex, &attributes ); | ||
12 | } | ||
13 | |||
14 | MutexImpl::~MutexImpl() { | ||
15 | pthread_mutex_destroy( &mMutex ); | ||
16 | } | ||
17 | |||
18 | void MutexImpl::lock() { | ||
19 | pthread_mutex_lock( &mMutex ); | ||
20 | } | ||
21 | |||
22 | void MutexImpl::unlock() { | ||
23 | pthread_mutex_unlock( &mMutex ); | ||
24 | } | ||
25 | |||
26 | }} // namespace efsw::Platform | ||
27 | |||
28 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/posix/MutexImpl.hpp b/src/3rdParty/efsw/platform/posix/MutexImpl.hpp new file mode 100755 index 0000000..a33d827 --- /dev/null +++ b/src/3rdParty/efsw/platform/posix/MutexImpl.hpp | |||
@@ -0,0 +1,30 @@ | |||
1 | #ifndef EFSW_MUTEXIMPLPOSIX_HPP | ||
2 | #define EFSW_MUTEXIMPLPOSIX_HPP | ||
3 | |||
4 | #include <efsw/base.hpp> | ||
5 | |||
6 | #if defined( EFSW_PLATFORM_POSIX ) | ||
7 | |||
8 | #include <pthread.h> | ||
9 | |||
10 | namespace efsw { namespace Platform { | ||
11 | |||
12 | class MutexImpl { | ||
13 | public: | ||
14 | MutexImpl(); | ||
15 | |||
16 | ~MutexImpl(); | ||
17 | |||
18 | void lock(); | ||
19 | |||
20 | void unlock(); | ||
21 | |||
22 | private: | ||
23 | pthread_mutex_t mMutex; | ||
24 | }; | ||
25 | |||
26 | }} // namespace efsw::Platform | ||
27 | |||
28 | #endif | ||
29 | |||
30 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/posix/SystemImpl.cpp b/src/3rdParty/efsw/platform/posix/SystemImpl.cpp new file mode 100755 index 0000000..37d4120 --- /dev/null +++ b/src/3rdParty/efsw/platform/posix/SystemImpl.cpp | |||
@@ -0,0 +1,168 @@ | |||
1 | #include <efsw/platform/posix/SystemImpl.hpp> | ||
2 | |||
3 | #if defined( EFSW_PLATFORM_POSIX ) | ||
4 | |||
5 | #include <cstdio> | ||
6 | #include <limits.h> | ||
7 | #include <pthread.h> | ||
8 | #include <sys/resource.h> | ||
9 | #include <sys/time.h> | ||
10 | |||
11 | #include <efsw/Debug.hpp> | ||
12 | #include <efsw/FileSystem.hpp> | ||
13 | |||
14 | #if EFSW_OS == EFSW_OS_MACOSX | ||
15 | #include <CoreFoundation/CoreFoundation.h> | ||
16 | #elif EFSW_OS == EFSW_OS_LINUX || EFSW_OS == EFSW_OS_ANDROID | ||
17 | #include <libgen.h> | ||
18 | #include <unistd.h> | ||
19 | #elif EFSW_OS == EFSW_OS_HAIKU | ||
20 | #include <kernel/OS.h> | ||
21 | #include <kernel/image.h> | ||
22 | #elif EFSW_OS == EFSW_OS_SOLARIS | ||
23 | #include <stdlib.h> | ||
24 | #elif EFSW_OS == EFSW_OS_BSD | ||
25 | #include <sys/sysctl.h> | ||
26 | #endif | ||
27 | |||
28 | namespace efsw { namespace Platform { | ||
29 | |||
30 | void System::sleep( const unsigned long& ms ) { | ||
31 | // usleep( static_cast<unsigned long>( ms * 1000 ) ); | ||
32 | |||
33 | // usleep is not reliable enough (it might block the | ||
34 | // whole process instead of just the current thread) | ||
35 | // so we must use pthread_cond_timedwait instead | ||
36 | |||
37 | // this implementation is inspired from Qt | ||
38 | // and taken from SFML | ||
39 | |||
40 | unsigned long long usecs = ms * 1000; | ||
41 | |||
42 | // get the current time | ||
43 | timeval tv; | ||
44 | gettimeofday( &tv, NULL ); | ||
45 | |||
46 | // construct the time limit (current time + time to wait) | ||
47 | timespec ti; | ||
48 | ti.tv_nsec = ( tv.tv_usec + ( usecs % 1000000 ) ) * 1000; | ||
49 | ti.tv_sec = tv.tv_sec + ( usecs / 1000000 ) + ( ti.tv_nsec / 1000000000 ); | ||
50 | ti.tv_nsec %= 1000000000; | ||
51 | |||
52 | // create a mutex and thread condition | ||
53 | pthread_mutex_t mutex; | ||
54 | pthread_mutex_init( &mutex, 0 ); | ||
55 | pthread_cond_t condition; | ||
56 | pthread_cond_init( &condition, 0 ); | ||
57 | |||
58 | // wait... | ||
59 | pthread_mutex_lock( &mutex ); | ||
60 | pthread_cond_timedwait( &condition, &mutex, &ti ); | ||
61 | pthread_mutex_unlock( &mutex ); | ||
62 | |||
63 | // destroy the mutex and condition | ||
64 | pthread_cond_destroy( &condition ); | ||
65 | } | ||
66 | |||
67 | std::string System::getProcessPath() { | ||
68 | #if EFSW_OS == EFSW_OS_MACOSX | ||
69 | char exe_file[FILENAME_MAX + 1]; | ||
70 | |||
71 | CFBundleRef mainBundle = CFBundleGetMainBundle(); | ||
72 | |||
73 | if ( mainBundle ) { | ||
74 | CFURLRef mainURL = CFBundleCopyBundleURL( mainBundle ); | ||
75 | |||
76 | if ( mainURL ) { | ||
77 | int ok = CFURLGetFileSystemRepresentation( mainURL, ( Boolean ) true, (UInt8*)exe_file, | ||
78 | FILENAME_MAX ); | ||
79 | |||
80 | if ( ok ) { | ||
81 | return std::string( exe_file ) + "/"; | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | |||
86 | return "./"; | ||
87 | #elif EFSW_OS == EFSW_OS_LINUX | ||
88 | char exe_file[FILENAME_MAX + 1]; | ||
89 | |||
90 | int size; | ||
91 | |||
92 | size = readlink( "/proc/self/exe", exe_file, FILENAME_MAX ); | ||
93 | |||
94 | if ( size < 0 ) { | ||
95 | return std::string( "./" ); | ||
96 | } else { | ||
97 | exe_file[size] = '\0'; | ||
98 | return std::string( dirname( exe_file ) ) + "/"; | ||
99 | } | ||
100 | |||
101 | #elif EFSW_OS == EFSW_OS_BSD | ||
102 | int mib[4]; | ||
103 | mib[0] = CTL_KERN; | ||
104 | mib[1] = KERN_PROC; | ||
105 | mib[2] = KERN_PROC_PATHNAME; | ||
106 | mib[3] = -1; | ||
107 | char buf[1024]; | ||
108 | size_t cb = sizeof( buf ); | ||
109 | sysctl( mib, 4, buf, &cb, NULL, 0 ); | ||
110 | |||
111 | return FileSystem::pathRemoveFileName( std::string( buf ) ); | ||
112 | |||
113 | #elif EFSW_OS == EFSW_OS_SOLARIS | ||
114 | return FileSystem::pathRemoveFileName( std::string( getexecname() ) ); | ||
115 | |||
116 | #elif EFSW_OS == EFSW_OS_HAIKU | ||
117 | image_info info; | ||
118 | int32 cookie = 0; | ||
119 | |||
120 | while ( B_OK == get_next_image_info( 0, &cookie, &info ) ) { | ||
121 | if ( info.type == B_APP_IMAGE ) | ||
122 | break; | ||
123 | } | ||
124 | |||
125 | return FileSystem::pathRemoveFileName( std::string( info.name ) ); | ||
126 | |||
127 | #elif EFSW_OS == EFSW_OS_ANDROID | ||
128 | return "/sdcard/"; | ||
129 | |||
130 | #else | ||
131 | #warning getProcessPath() not implemented on this platform. ( will return "./" ) | ||
132 | return "./"; | ||
133 | |||
134 | #endif | ||
135 | } | ||
136 | |||
137 | void System::maxFD() { | ||
138 | static bool maxed = false; | ||
139 | |||
140 | if ( !maxed ) { | ||
141 | struct rlimit limit; | ||
142 | getrlimit( RLIMIT_NOFILE, &limit ); | ||
143 | limit.rlim_cur = limit.rlim_max; | ||
144 | setrlimit( RLIMIT_NOFILE, &limit ); | ||
145 | |||
146 | getrlimit( RLIMIT_NOFILE, &limit ); | ||
147 | |||
148 | efDEBUG( "File descriptor limit %ld\n", limit.rlim_cur ); | ||
149 | |||
150 | maxed = true; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | Uint64 System::getMaxFD() { | ||
155 | static rlim_t max_fd = 0; | ||
156 | |||
157 | if ( max_fd == 0 ) { | ||
158 | struct rlimit limit; | ||
159 | getrlimit( RLIMIT_NOFILE, &limit ); | ||
160 | max_fd = limit.rlim_cur; | ||
161 | } | ||
162 | |||
163 | return max_fd; | ||
164 | } | ||
165 | |||
166 | }} // namespace efsw::Platform | ||
167 | |||
168 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/posix/SystemImpl.hpp b/src/3rdParty/efsw/platform/posix/SystemImpl.hpp new file mode 100755 index 0000000..9322b06 --- /dev/null +++ b/src/3rdParty/efsw/platform/posix/SystemImpl.hpp | |||
@@ -0,0 +1,25 @@ | |||
1 | #ifndef EFSW_SYSTEMIMPLPOSIX_HPP | ||
2 | #define EFSW_SYSTEMIMPLPOSIX_HPP | ||
3 | |||
4 | #include <efsw/base.hpp> | ||
5 | |||
6 | #if defined( EFSW_PLATFORM_POSIX ) | ||
7 | |||
8 | namespace efsw { namespace Platform { | ||
9 | |||
10 | class System { | ||
11 | public: | ||
12 | static void sleep( const unsigned long& ms ); | ||
13 | |||
14 | static std::string getProcessPath(); | ||
15 | |||
16 | static void maxFD(); | ||
17 | |||
18 | static Uint64 getMaxFD(); | ||
19 | }; | ||
20 | |||
21 | }} // namespace efsw::Platform | ||
22 | |||
23 | #endif | ||
24 | |||
25 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/posix/ThreadImpl.cpp b/src/3rdParty/efsw/platform/posix/ThreadImpl.cpp new file mode 100755 index 0000000..e0ae84f --- /dev/null +++ b/src/3rdParty/efsw/platform/posix/ThreadImpl.cpp | |||
@@ -0,0 +1,60 @@ | |||
1 | #include <efsw/Thread.hpp> | ||
2 | #include <efsw/platform/posix/ThreadImpl.hpp> | ||
3 | |||
4 | #if defined( EFSW_PLATFORM_POSIX ) | ||
5 | |||
6 | #include <cassert> | ||
7 | #include <efsw/Debug.hpp> | ||
8 | #include <iostream> | ||
9 | |||
10 | namespace efsw { namespace Platform { | ||
11 | |||
12 | ThreadImpl::ThreadImpl( Thread* owner ) : mIsActive( false ) { | ||
13 | mIsActive = pthread_create( &mThread, NULL, &ThreadImpl::entryPoint, owner ) == 0; | ||
14 | |||
15 | if ( !mIsActive ) { | ||
16 | efDEBUG( "Failed to create thread\n" ); | ||
17 | } | ||
18 | } | ||
19 | |||
20 | void ThreadImpl::wait() { | ||
21 | // Wait for the thread to finish, no timeout | ||
22 | if ( mIsActive ) { | ||
23 | assert( pthread_equal( pthread_self(), mThread ) == 0 ); | ||
24 | |||
25 | pthread_join( mThread, NULL ); | ||
26 | |||
27 | mIsActive = false; // Reset the thread state | ||
28 | } | ||
29 | } | ||
30 | |||
31 | void ThreadImpl::terminate() { | ||
32 | if ( mIsActive ) { | ||
33 | #if !defined( __ANDROID__ ) && !defined( ANDROID ) | ||
34 | pthread_cancel( mThread ); | ||
35 | #else | ||
36 | pthread_kill( mThread, SIGUSR1 ); | ||
37 | #endif | ||
38 | |||
39 | mIsActive = false; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | void* ThreadImpl::entryPoint( void* userData ) { | ||
44 | // The Thread instance is stored in the user data | ||
45 | Thread* owner = static_cast<Thread*>( userData ); | ||
46 | |||
47 | // Tell the thread to handle cancel requests immediatly | ||
48 | #ifdef PTHREAD_CANCEL_ASYNCHRONOUS | ||
49 | pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL ); | ||
50 | #endif | ||
51 | |||
52 | // Forward to the owner | ||
53 | owner->run(); | ||
54 | |||
55 | return NULL; | ||
56 | } | ||
57 | |||
58 | }} // namespace efsw::Platform | ||
59 | |||
60 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/posix/ThreadImpl.hpp b/src/3rdParty/efsw/platform/posix/ThreadImpl.hpp new file mode 100755 index 0000000..ffc6da0 --- /dev/null +++ b/src/3rdParty/efsw/platform/posix/ThreadImpl.hpp | |||
@@ -0,0 +1,36 @@ | |||
1 | #ifndef EFSW_THREADIMPLPOSIX_HPP | ||
2 | #define EFSW_THREADIMPLPOSIX_HPP | ||
3 | |||
4 | #include <efsw/base.hpp> | ||
5 | |||
6 | #if defined( EFSW_PLATFORM_POSIX ) | ||
7 | |||
8 | #include <pthread.h> | ||
9 | |||
10 | namespace efsw { | ||
11 | |||
12 | class Thread; | ||
13 | |||
14 | namespace Platform { | ||
15 | |||
16 | class ThreadImpl { | ||
17 | public: | ||
18 | ThreadImpl( Thread* owner ); | ||
19 | |||
20 | void wait(); | ||
21 | |||
22 | void terminate(); | ||
23 | |||
24 | protected: | ||
25 | static void* entryPoint( void* userData ); | ||
26 | |||
27 | pthread_t mThread; | ||
28 | bool mIsActive; | ||
29 | }; | ||
30 | |||
31 | } // namespace Platform | ||
32 | } // namespace efsw | ||
33 | |||
34 | #endif | ||
35 | |||
36 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/win/FileSystemImpl.cpp b/src/3rdParty/efsw/platform/win/FileSystemImpl.cpp new file mode 100755 index 0000000..2b87513 --- /dev/null +++ b/src/3rdParty/efsw/platform/win/FileSystemImpl.cpp | |||
@@ -0,0 +1,111 @@ | |||
1 | #include <efsw/platform/win/FileSystemImpl.hpp> | ||
2 | |||
3 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
4 | |||
5 | #include <climits> | ||
6 | #ifndef WIN32_LEAN_AND_MEAN | ||
7 | #define WIN32_LEAN_AND_MEAN | ||
8 | #endif | ||
9 | #include <windows.h> | ||
10 | |||
11 | #ifndef EFSW_COMPILER_MSVC | ||
12 | #include <dirent.h> | ||
13 | #else | ||
14 | #include <direct.h> | ||
15 | #endif | ||
16 | |||
17 | namespace efsw { namespace Platform { | ||
18 | |||
19 | bool FileSystem::changeWorkingDirectory( const std::string& path ) { | ||
20 | int res; | ||
21 | #ifdef EFSW_COMPILER_MSVC | ||
22 | #ifdef UNICODE | ||
23 | res = _wchdir( String::fromUtf8( path.c_str() ).toWideString().c_str() ); | ||
24 | #else | ||
25 | res = _chdir( String::fromUtf8( path.c_str() ).toAnsiString().c_str() ); | ||
26 | #endif | ||
27 | #else | ||
28 | res = chdir( path.c_str() ); | ||
29 | #endif | ||
30 | return -1 != res; | ||
31 | } | ||
32 | |||
33 | std::string FileSystem::getCurrentWorkingDirectory() { | ||
34 | #ifdef EFSW_COMPILER_MSVC | ||
35 | #if defined( UNICODE ) && !defined( EFSW_NO_WIDECHAR ) | ||
36 | wchar_t dir[_MAX_PATH]; | ||
37 | return ( 0 != GetCurrentDirectoryW( _MAX_PATH, dir ) ) ? String( dir ).toUtf8() : std::string(); | ||
38 | #else | ||
39 | char dir[_MAX_PATH]; | ||
40 | return ( 0 != GetCurrentDirectory( _MAX_PATH, dir ) ) ? String( dir, std::locale() ).toUtf8() | ||
41 | : std::string(); | ||
42 | #endif | ||
43 | #else | ||
44 | char dir[PATH_MAX + 1]; | ||
45 | getcwd( dir, PATH_MAX + 1 ); | ||
46 | return std::string( dir ); | ||
47 | #endif | ||
48 | } | ||
49 | |||
50 | FileInfoMap FileSystem::filesInfoFromPath( const std::string& path ) { | ||
51 | FileInfoMap files; | ||
52 | |||
53 | String tpath( path ); | ||
54 | |||
55 | if ( tpath[tpath.size() - 1] == '/' || tpath[tpath.size() - 1] == '\\' ) { | ||
56 | tpath += "*"; | ||
57 | } else { | ||
58 | tpath += "\\*"; | ||
59 | } | ||
60 | |||
61 | WIN32_FIND_DATAW findFileData; | ||
62 | HANDLE hFind = FindFirstFileW( (LPCWSTR)tpath.toWideString().c_str(), &findFileData ); | ||
63 | |||
64 | if ( hFind != INVALID_HANDLE_VALUE ) { | ||
65 | std::string name( String( findFileData.cFileName ).toUtf8() ); | ||
66 | std::string fpath( path + name ); | ||
67 | |||
68 | if ( name != "." && name != ".." ) { | ||
69 | files[name] = FileInfo( fpath ); | ||
70 | } | ||
71 | |||
72 | while ( FindNextFileW( hFind, &findFileData ) ) { | ||
73 | name = String( findFileData.cFileName ).toUtf8(); | ||
74 | fpath = path + name; | ||
75 | |||
76 | if ( name != "." && name != ".." ) { | ||
77 | files[name] = FileInfo( fpath ); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | FindClose( hFind ); | ||
82 | } | ||
83 | |||
84 | return files; | ||
85 | } | ||
86 | |||
87 | char FileSystem::getOSSlash() { | ||
88 | return '\\'; | ||
89 | } | ||
90 | |||
91 | bool FileSystem::isDirectory( const std::string& path ) { | ||
92 | DWORD attrs = GetFileAttributesW( String( path ).toWideString().c_str() ); | ||
93 | return attrs != INVALID_FILE_ATTRIBUTES && ( attrs & FILE_ATTRIBUTE_DIRECTORY ) != 0; | ||
94 | } | ||
95 | |||
96 | bool FileSystem::isRemoteFS( const std::string& directory ) { | ||
97 | if ( ( directory[0] == '\\' || directory[0] == '/' ) && | ||
98 | ( directory[1] == '\\' || directory[1] == '/' ) ) { | ||
99 | return true; | ||
100 | } | ||
101 | |||
102 | if ( directory.size() >= 3 ) { | ||
103 | return 4 == GetDriveTypeA( directory.substr( 0, 3 ).c_str() ); | ||
104 | } | ||
105 | |||
106 | return false; | ||
107 | } | ||
108 | |||
109 | }} // namespace efsw::Platform | ||
110 | |||
111 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/win/FileSystemImpl.hpp b/src/3rdParty/efsw/platform/win/FileSystemImpl.hpp new file mode 100755 index 0000000..e952efc --- /dev/null +++ b/src/3rdParty/efsw/platform/win/FileSystemImpl.hpp | |||
@@ -0,0 +1,31 @@ | |||
1 | #ifndef EFSW_FILESYSTEMIMPLWIN_HPP | ||
2 | #define EFSW_FILESYSTEMIMPLWIN_HPP | ||
3 | |||
4 | #include <efsw/FileInfo.hpp> | ||
5 | #include <efsw/String.hpp> | ||
6 | #include <efsw/base.hpp> | ||
7 | |||
8 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
9 | |||
10 | namespace efsw { namespace Platform { | ||
11 | |||
12 | class FileSystem { | ||
13 | public: | ||
14 | static FileInfoMap filesInfoFromPath( const std::string& path ); | ||
15 | |||
16 | static char getOSSlash(); | ||
17 | |||
18 | static bool isDirectory( const std::string& path ); | ||
19 | |||
20 | static bool isRemoteFS( const std::string& directory ); | ||
21 | |||
22 | static bool changeWorkingDirectory( const std::string& path ); | ||
23 | |||
24 | static std::string getCurrentWorkingDirectory(); | ||
25 | }; | ||
26 | |||
27 | }} // namespace efsw::Platform | ||
28 | |||
29 | #endif | ||
30 | |||
31 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/win/MutexImpl.cpp b/src/3rdParty/efsw/platform/win/MutexImpl.cpp new file mode 100755 index 0000000..62b7f83 --- /dev/null +++ b/src/3rdParty/efsw/platform/win/MutexImpl.cpp | |||
@@ -0,0 +1,25 @@ | |||
1 | #include <efsw/platform/win/MutexImpl.hpp> | ||
2 | |||
3 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
4 | |||
5 | namespace efsw { namespace Platform { | ||
6 | |||
7 | MutexImpl::MutexImpl() { | ||
8 | InitializeCriticalSection( &mMutex ); | ||
9 | } | ||
10 | |||
11 | MutexImpl::~MutexImpl() { | ||
12 | DeleteCriticalSection( &mMutex ); | ||
13 | } | ||
14 | |||
15 | void MutexImpl::lock() { | ||
16 | EnterCriticalSection( &mMutex ); | ||
17 | } | ||
18 | |||
19 | void MutexImpl::unlock() { | ||
20 | LeaveCriticalSection( &mMutex ); | ||
21 | } | ||
22 | |||
23 | }} // namespace efsw::Platform | ||
24 | |||
25 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/win/MutexImpl.hpp b/src/3rdParty/efsw/platform/win/MutexImpl.hpp new file mode 100755 index 0000000..7b06492 --- /dev/null +++ b/src/3rdParty/efsw/platform/win/MutexImpl.hpp | |||
@@ -0,0 +1,33 @@ | |||
1 | #ifndef EFSW_MUTEXIMPLWIN_HPP | ||
2 | #define EFSW_MUTEXIMPLWIN_HPP | ||
3 | |||
4 | #include <efsw/base.hpp> | ||
5 | |||
6 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
7 | |||
8 | #ifndef WIN32_LEAN_AND_MEAN | ||
9 | #define WIN32_LEAN_AND_MEAN | ||
10 | #endif | ||
11 | #include <windows.h> | ||
12 | |||
13 | namespace efsw { namespace Platform { | ||
14 | |||
15 | class MutexImpl { | ||
16 | public: | ||
17 | MutexImpl(); | ||
18 | |||
19 | ~MutexImpl(); | ||
20 | |||
21 | void lock(); | ||
22 | |||
23 | void unlock(); | ||
24 | |||
25 | private: | ||
26 | CRITICAL_SECTION mMutex; | ||
27 | }; | ||
28 | |||
29 | }} // namespace efsw::Platform | ||
30 | |||
31 | #endif | ||
32 | |||
33 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/win/SystemImpl.cpp b/src/3rdParty/efsw/platform/win/SystemImpl.cpp new file mode 100755 index 0000000..d1f2b21 --- /dev/null +++ b/src/3rdParty/efsw/platform/win/SystemImpl.cpp | |||
@@ -0,0 +1,46 @@ | |||
1 | #include <efsw/String.hpp> | ||
2 | #include <efsw/platform/win/SystemImpl.hpp> | ||
3 | |||
4 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
5 | |||
6 | #ifndef WIN32_LEAN_AND_MEAN | ||
7 | #define WIN32_LEAN_AND_MEAN | ||
8 | #endif | ||
9 | #include <cstdlib> | ||
10 | #include <windows.h> | ||
11 | |||
12 | namespace efsw { namespace Platform { | ||
13 | |||
14 | void System::sleep( const unsigned long& ms ) { | ||
15 | ::Sleep( ms ); | ||
16 | } | ||
17 | |||
18 | std::string System::getProcessPath() { | ||
19 | // Get path to executable: | ||
20 | WCHAR szDrive[_MAX_DRIVE]; | ||
21 | WCHAR szDir[_MAX_DIR]; | ||
22 | WCHAR szFilename[_MAX_DIR]; | ||
23 | WCHAR szExt[_MAX_DIR]; | ||
24 | std::wstring dllName( _MAX_DIR, 0 ); | ||
25 | |||
26 | GetModuleFileNameW( 0, &dllName[0], _MAX_PATH ); | ||
27 | |||
28 | #ifdef EFSW_COMPILER_MSVC | ||
29 | _wsplitpath_s( dllName.c_str(), szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szFilename, _MAX_DIR, | ||
30 | szExt, _MAX_DIR ); | ||
31 | #else | ||
32 | _wsplitpath( dllName.c_str(), szDrive, szDir, szFilename, szExt ); | ||
33 | #endif | ||
34 | |||
35 | return String( szDrive ).toUtf8() + String( szDir ).toUtf8(); | ||
36 | } | ||
37 | |||
38 | void System::maxFD() {} | ||
39 | |||
40 | Uint64 System::getMaxFD() { // Number of ReadDirectory per thread | ||
41 | return 60; | ||
42 | } | ||
43 | |||
44 | }} // namespace efsw::Platform | ||
45 | |||
46 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/win/SystemImpl.hpp b/src/3rdParty/efsw/platform/win/SystemImpl.hpp new file mode 100755 index 0000000..99b4867 --- /dev/null +++ b/src/3rdParty/efsw/platform/win/SystemImpl.hpp | |||
@@ -0,0 +1,25 @@ | |||
1 | #ifndef EFSW_SYSTEMIMPLWIN_HPP | ||
2 | #define EFSW_SYSTEMIMPLWIN_HPP | ||
3 | |||
4 | #include <efsw/base.hpp> | ||
5 | |||
6 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
7 | |||
8 | namespace efsw { namespace Platform { | ||
9 | |||
10 | class System { | ||
11 | public: | ||
12 | static void sleep( const unsigned long& ms ); | ||
13 | |||
14 | static std::string getProcessPath(); | ||
15 | |||
16 | static void maxFD(); | ||
17 | |||
18 | static Uint64 getMaxFD(); | ||
19 | }; | ||
20 | |||
21 | }} // namespace efsw::Platform | ||
22 | |||
23 | #endif | ||
24 | |||
25 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/win/ThreadImpl.cpp b/src/3rdParty/efsw/platform/win/ThreadImpl.cpp new file mode 100755 index 0000000..d0fde8b --- /dev/null +++ b/src/3rdParty/efsw/platform/win/ThreadImpl.cpp | |||
@@ -0,0 +1,56 @@ | |||
1 | #include <assert.h> | ||
2 | #include <efsw/Thread.hpp> | ||
3 | #include <efsw/platform/win/ThreadImpl.hpp> | ||
4 | |||
5 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
6 | |||
7 | #include <efsw/Debug.hpp> | ||
8 | |||
9 | namespace efsw { namespace Platform { | ||
10 | |||
11 | ThreadImpl::ThreadImpl( Thread* owner ) { | ||
12 | mThread = reinterpret_cast<HANDLE>( | ||
13 | _beginthreadex( NULL, 0, &ThreadImpl::entryPoint, owner, 0, &mThreadId ) ); | ||
14 | |||
15 | if ( !mThread ) { | ||
16 | efDEBUG( "Failed to create thread\n" ); | ||
17 | } | ||
18 | } | ||
19 | |||
20 | ThreadImpl::~ThreadImpl() { | ||
21 | if ( mThread ) { | ||
22 | CloseHandle( mThread ); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | void ThreadImpl::wait() { | ||
27 | // Wait for the thread to finish, no timeout | ||
28 | if ( mThread ) { | ||
29 | assert( mThreadId != GetCurrentThreadId() ); // A thread cannot wait for itself! | ||
30 | |||
31 | WaitForSingleObject( mThread, INFINITE ); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | void ThreadImpl::terminate() { | ||
36 | if ( mThread ) { | ||
37 | TerminateThread( mThread, 0 ); | ||
38 | } | ||
39 | } | ||
40 | |||
41 | unsigned int __stdcall ThreadImpl::entryPoint( void* userData ) { | ||
42 | // The Thread instance is stored in the user data | ||
43 | Thread* owner = static_cast<Thread*>( userData ); | ||
44 | |||
45 | // Forward to the owner | ||
46 | owner->run(); | ||
47 | |||
48 | // Optional, but it is cleaner | ||
49 | _endthreadex( 0 ); | ||
50 | |||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | }} // namespace efsw::Platform | ||
55 | |||
56 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/win/ThreadImpl.hpp b/src/3rdParty/efsw/platform/win/ThreadImpl.hpp new file mode 100755 index 0000000..1afb593 --- /dev/null +++ b/src/3rdParty/efsw/platform/win/ThreadImpl.hpp | |||
@@ -0,0 +1,42 @@ | |||
1 | #ifndef EFSW_THREADIMPLWIN_HPP | ||
2 | #define EFSW_THREADIMPLWIN_HPP | ||
3 | |||
4 | #include <efsw/base.hpp> | ||
5 | |||
6 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
7 | |||
8 | #ifndef WIN32_LEAN_AND_MEAN | ||
9 | #define WIN32_LEAN_AND_MEAN | ||
10 | #endif | ||
11 | #include <process.h> | ||
12 | #include <windows.h> | ||
13 | |||
14 | namespace efsw { | ||
15 | |||
16 | class Thread; | ||
17 | |||
18 | namespace Platform { | ||
19 | |||
20 | class ThreadImpl { | ||
21 | public: | ||
22 | ThreadImpl( Thread* owner ); | ||
23 | |||
24 | ~ThreadImpl(); | ||
25 | |||
26 | void wait(); | ||
27 | |||
28 | void terminate(); | ||
29 | |||
30 | protected: | ||
31 | static unsigned int __stdcall entryPoint( void* userData ); | ||
32 | |||
33 | HANDLE mThread; | ||
34 | unsigned int mThreadId; | ||
35 | }; | ||
36 | |||
37 | } // namespace Platform | ||
38 | } // namespace efsw | ||
39 | |||
40 | #endif | ||
41 | |||
42 | #endif | ||