Initial commit
This commit is contained in:
15
common/os/CMakeLists.txt
Normal file
15
common/os/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
include_directories(${CMAKE_SOURCE_DIR}/common)
|
||||
|
||||
add_library(os STATIC
|
||||
Mutex.cxx
|
||||
Thread.cxx
|
||||
w32tiger.c
|
||||
os.cxx)
|
||||
|
||||
if(UNIX)
|
||||
target_link_libraries(os pthread)
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
libtool_create_control_file(os)
|
||||
endif()
|
||||
154
common/os/Mutex.cxx
Normal file
154
common/os/Mutex.cxx
Normal file
@@ -0,0 +1,154 @@
|
||||
/* Copyright 2015 Pierre Ossman for Cendio AB
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
* USA.
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <rdr/Exception.h>
|
||||
|
||||
#include <os/Mutex.h>
|
||||
|
||||
using namespace os;
|
||||
|
||||
Mutex::Mutex()
|
||||
{
|
||||
#ifdef WIN32
|
||||
systemMutex = new CRITICAL_SECTION;
|
||||
InitializeCriticalSection((CRITICAL_SECTION*)systemMutex);
|
||||
#else
|
||||
int ret;
|
||||
|
||||
systemMutex = new pthread_mutex_t;
|
||||
ret = pthread_mutex_init((pthread_mutex_t*)systemMutex, NULL);
|
||||
if (ret != 0)
|
||||
throw rdr::SystemException("Failed to create mutex", ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
Mutex::~Mutex()
|
||||
{
|
||||
#ifdef WIN32
|
||||
DeleteCriticalSection((CRITICAL_SECTION*)systemMutex);
|
||||
delete (CRITICAL_SECTION*)systemMutex;
|
||||
#else
|
||||
pthread_mutex_destroy((pthread_mutex_t*)systemMutex);
|
||||
delete (pthread_mutex_t*)systemMutex;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Mutex::lock()
|
||||
{
|
||||
#ifdef WIN32
|
||||
EnterCriticalSection((CRITICAL_SECTION*)systemMutex);
|
||||
#else
|
||||
int ret;
|
||||
|
||||
ret = pthread_mutex_lock((pthread_mutex_t*)systemMutex);
|
||||
if (ret != 0)
|
||||
throw rdr::SystemException("Failed to lock mutex", ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Mutex::unlock()
|
||||
{
|
||||
#ifdef WIN32
|
||||
LeaveCriticalSection((CRITICAL_SECTION*)systemMutex);
|
||||
#else
|
||||
int ret;
|
||||
|
||||
ret = pthread_mutex_unlock((pthread_mutex_t*)systemMutex);
|
||||
if (ret != 0)
|
||||
throw rdr::SystemException("Failed to unlock mutex", ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
Condition::Condition(Mutex* mutex)
|
||||
{
|
||||
this->mutex = mutex;
|
||||
|
||||
#ifdef WIN32
|
||||
systemCondition = new CONDITION_VARIABLE;
|
||||
InitializeConditionVariable((CONDITION_VARIABLE*)systemCondition);
|
||||
#else
|
||||
int ret;
|
||||
|
||||
systemCondition = new pthread_cond_t;
|
||||
ret = pthread_cond_init((pthread_cond_t*)systemCondition, NULL);
|
||||
if (ret != 0)
|
||||
throw rdr::SystemException("Failed to create condition variable", ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
Condition::~Condition()
|
||||
{
|
||||
#ifdef WIN32
|
||||
delete (CONDITION_VARIABLE*)systemCondition;
|
||||
#else
|
||||
pthread_cond_destroy((pthread_cond_t*)systemCondition);
|
||||
delete (pthread_cond_t*)systemCondition;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Condition::wait()
|
||||
{
|
||||
#ifdef WIN32
|
||||
BOOL ret;
|
||||
|
||||
ret = SleepConditionVariableCS((CONDITION_VARIABLE*)systemCondition,
|
||||
(CRITICAL_SECTION*)mutex->systemMutex,
|
||||
INFINITE);
|
||||
if (!ret)
|
||||
throw rdr::SystemException("Failed to wait on condition variable", GetLastError());
|
||||
#else
|
||||
int ret;
|
||||
|
||||
ret = pthread_cond_wait((pthread_cond_t*)systemCondition,
|
||||
(pthread_mutex_t*)mutex->systemMutex);
|
||||
if (ret != 0)
|
||||
throw rdr::SystemException("Failed to wait on condition variable", ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Condition::signal()
|
||||
{
|
||||
#ifdef WIN32
|
||||
WakeConditionVariable((CONDITION_VARIABLE*)systemCondition);
|
||||
#else
|
||||
int ret;
|
||||
|
||||
ret = pthread_cond_signal((pthread_cond_t*)systemCondition);
|
||||
if (ret != 0)
|
||||
throw rdr::SystemException("Failed to signal condition variable", ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Condition::broadcast()
|
||||
{
|
||||
#ifdef WIN32
|
||||
WakeAllConditionVariable((CONDITION_VARIABLE*)systemCondition);
|
||||
#else
|
||||
int ret;
|
||||
|
||||
ret = pthread_cond_broadcast((pthread_cond_t*)systemCondition);
|
||||
if (ret != 0)
|
||||
throw rdr::SystemException("Failed to broadcast condition variable", ret);
|
||||
#endif
|
||||
}
|
||||
64
common/os/Mutex.h
Normal file
64
common/os/Mutex.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/* Copyright 2015 Pierre Ossman for Cendio AB
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
* USA.
|
||||
*/
|
||||
|
||||
#ifndef __OS_MUTEX_H__
|
||||
#define __OS_MUTEX_H__
|
||||
|
||||
namespace os {
|
||||
class Condition;
|
||||
|
||||
class Mutex {
|
||||
public:
|
||||
Mutex();
|
||||
~Mutex();
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
private:
|
||||
friend class Condition;
|
||||
|
||||
void* systemMutex;
|
||||
};
|
||||
|
||||
class AutoMutex {
|
||||
public:
|
||||
AutoMutex(Mutex* mutex) { m = mutex; m->lock(); }
|
||||
~AutoMutex() { m->unlock(); }
|
||||
private:
|
||||
Mutex* m;
|
||||
};
|
||||
|
||||
class Condition {
|
||||
public:
|
||||
Condition(Mutex* mutex);
|
||||
~Condition();
|
||||
|
||||
void wait();
|
||||
|
||||
void signal();
|
||||
void broadcast();
|
||||
|
||||
private:
|
||||
Mutex* mutex;
|
||||
void* systemCondition;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
165
common/os/Thread.cxx
Normal file
165
common/os/Thread.cxx
Normal file
@@ -0,0 +1,165 @@
|
||||
/* Copyright 2015 Pierre Ossman for Cendio AB
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
* USA.
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <rdr/Exception.h>
|
||||
|
||||
#include <os/Mutex.h>
|
||||
#include <os/Thread.h>
|
||||
|
||||
using namespace os;
|
||||
|
||||
Thread::Thread() : running(false), threadId(NULL)
|
||||
{
|
||||
mutex = new Mutex;
|
||||
|
||||
#ifdef WIN32
|
||||
threadId = new HANDLE;
|
||||
#else
|
||||
threadId = new pthread_t;
|
||||
#endif
|
||||
}
|
||||
|
||||
Thread::~Thread()
|
||||
{
|
||||
#ifdef WIN32
|
||||
delete (HANDLE*)threadId;
|
||||
#else
|
||||
if (isRunning())
|
||||
pthread_cancel(*(pthread_t*)threadId);
|
||||
delete (pthread_t*)threadId;
|
||||
#endif
|
||||
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
void Thread::start()
|
||||
{
|
||||
AutoMutex a(mutex);
|
||||
|
||||
#ifdef WIN32
|
||||
*(HANDLE*)threadId = CreateThread(NULL, 0, startRoutine, this, 0, NULL);
|
||||
if (*(HANDLE*)threadId == NULL)
|
||||
throw rdr::SystemException("Failed to create thread", GetLastError());
|
||||
#else
|
||||
int ret;
|
||||
sigset_t all, old;
|
||||
|
||||
// Creating threads from libraries is a bit evil, so mitigate the
|
||||
// issue by at least avoiding signals on these threads
|
||||
sigfillset(&all);
|
||||
ret = pthread_sigmask(SIG_SETMASK, &all, &old);
|
||||
if (ret != 0)
|
||||
throw rdr::SystemException("Failed to mask signals", ret);
|
||||
|
||||
ret = pthread_create((pthread_t*)threadId, NULL, startRoutine, this);
|
||||
|
||||
pthread_sigmask(SIG_SETMASK, &old, NULL);
|
||||
|
||||
if (ret != 0)
|
||||
throw rdr::SystemException("Failed to create thread", ret);
|
||||
#endif
|
||||
|
||||
running = true;
|
||||
}
|
||||
|
||||
void Thread::wait()
|
||||
{
|
||||
if (!isRunning())
|
||||
return;
|
||||
|
||||
#ifdef WIN32
|
||||
DWORD ret;
|
||||
|
||||
ret = WaitForSingleObject(*(HANDLE*)threadId, INFINITE);
|
||||
if (ret != WAIT_OBJECT_0)
|
||||
throw rdr::SystemException("Failed to join thread", GetLastError());
|
||||
#else
|
||||
int ret;
|
||||
|
||||
ret = pthread_join(*(pthread_t*)threadId, NULL);
|
||||
if (ret != 0)
|
||||
throw rdr::SystemException("Failed to join thread", ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Thread::isRunning()
|
||||
{
|
||||
AutoMutex a(mutex);
|
||||
|
||||
return running;
|
||||
}
|
||||
|
||||
size_t Thread::getSystemCPUCount()
|
||||
{
|
||||
#ifdef WIN32
|
||||
SYSTEM_INFO si;
|
||||
size_t count;
|
||||
DWORD mask;
|
||||
|
||||
GetSystemInfo(&si);
|
||||
|
||||
count = 0;
|
||||
for (mask = si.dwActiveProcessorMask;mask != 0;mask >>= 1) {
|
||||
if (mask & 0x1)
|
||||
count++;
|
||||
}
|
||||
|
||||
if (count > si.dwNumberOfProcessors)
|
||||
count = si.dwNumberOfProcessors;
|
||||
|
||||
return count;
|
||||
#else
|
||||
long ret;
|
||||
|
||||
ret = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
if (ret == -1)
|
||||
return 0;
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
long unsigned __stdcall Thread::startRoutine(void* data)
|
||||
#else
|
||||
void* Thread::startRoutine(void* data)
|
||||
#endif
|
||||
{
|
||||
Thread *self;
|
||||
|
||||
self = (Thread*)data;
|
||||
|
||||
try {
|
||||
self->worker();
|
||||
} catch(...) {
|
||||
}
|
||||
|
||||
self->mutex->lock();
|
||||
self->running = false;
|
||||
self->mutex->unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
58
common/os/Thread.h
Normal file
58
common/os/Thread.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/* Copyright 2015 Pierre Ossman for Cendio AB
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
* USA.
|
||||
*/
|
||||
|
||||
#ifndef __OS_THREAD_H__
|
||||
#define __OS_THREAD_H__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace os {
|
||||
class Mutex;
|
||||
|
||||
class Thread {
|
||||
public:
|
||||
Thread();
|
||||
virtual ~Thread();
|
||||
|
||||
void start();
|
||||
void wait();
|
||||
|
||||
bool isRunning();
|
||||
|
||||
public:
|
||||
static size_t getSystemCPUCount();
|
||||
|
||||
protected:
|
||||
virtual void worker() = 0;
|
||||
|
||||
private:
|
||||
#ifdef WIN32
|
||||
static long unsigned __stdcall startRoutine(void* data);
|
||||
#else
|
||||
static void* startRoutine(void* data);
|
||||
#endif
|
||||
|
||||
private:
|
||||
Mutex *mutex;
|
||||
bool running;
|
||||
|
||||
void *threadId;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
97
common/os/os.cxx
Normal file
97
common/os/os.cxx
Normal file
@@ -0,0 +1,97 @@
|
||||
/* Copyright (C) 2010 TightVNC Team. All Rights Reserved.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
* USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <os/os.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <pwd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <wininet.h> /* MinGW needs it */
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
int getvnchomedir(char **dirp)
|
||||
{
|
||||
#ifndef WIN32
|
||||
char *homedir, *dir;
|
||||
size_t len;
|
||||
uid_t uid;
|
||||
struct passwd *passwd;
|
||||
#else
|
||||
TCHAR *dir;
|
||||
BOOL ret;
|
||||
#endif
|
||||
|
||||
assert(dirp != NULL && *dirp == NULL);
|
||||
|
||||
#ifndef WIN32
|
||||
homedir = getenv("HOME");
|
||||
if (homedir == NULL) {
|
||||
uid = getuid();
|
||||
passwd = getpwuid(uid);
|
||||
if (passwd == NULL) {
|
||||
/* Do we want emit error msg here? */
|
||||
return -1;
|
||||
}
|
||||
homedir = passwd->pw_dir;
|
||||
}
|
||||
|
||||
len = strlen(homedir);
|
||||
dir = new char[len+7];
|
||||
if (dir == NULL)
|
||||
return -1;
|
||||
|
||||
memcpy(dir, homedir, len);
|
||||
memcpy(dir + len, "/.vnc/\0", 7);
|
||||
#else
|
||||
dir = new TCHAR[MAX_PATH];
|
||||
if (dir == NULL)
|
||||
return -1;
|
||||
|
||||
ret = SHGetSpecialFolderPath(NULL, dir, CSIDL_APPDATA, FALSE);
|
||||
if (ret == FALSE) {
|
||||
delete [] dir;
|
||||
return -1;
|
||||
}
|
||||
memcpy(dir+strlen(dir), (TCHAR *)"\\vnc\\\0", 6);
|
||||
#endif
|
||||
*dirp = dir;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fileexists(char *file)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return (GetFileAttributes(file) == INVALID_FILE_ATTRIBUTES) ? -1 : 0;
|
||||
#else
|
||||
return access(file, R_OK);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
51
common/os/os.h
Normal file
51
common/os/os.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* Copyright (C) 2010 TightVNC Team. All Rights Reserved.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
* USA.
|
||||
*/
|
||||
|
||||
#ifndef OS_OS_H
|
||||
#define OS_OS_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <os/w32tiger.h>
|
||||
|
||||
/*
|
||||
* Get VNC home directory ($HOME/.vnc or %APPDATA%/vnc/).
|
||||
* If HOME environment variable is set then it is used.
|
||||
* Otherwise home directory is obtained via getpwuid function.
|
||||
*
|
||||
* Note for Windows:
|
||||
* This functions returns array of TCHARs, not array of chars.
|
||||
*
|
||||
* Returns:
|
||||
* 0 - Success
|
||||
* -1 - Failure
|
||||
*/
|
||||
int getvnchomedir(char **dirp);
|
||||
|
||||
/*
|
||||
* Check if the file exists
|
||||
*
|
||||
* Returns:
|
||||
* 0 - Success
|
||||
* -1 - Failure
|
||||
*/
|
||||
int fileexists(char *file);
|
||||
|
||||
#endif /* OS_OS_H */
|
||||
33
common/os/w32tiger.c
Normal file
33
common/os/w32tiger.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/* Copyright (C) 2011 TigerVNC Team. All Rights Reserved.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
* USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#define INITGUID
|
||||
#include <basetyps.h>
|
||||
|
||||
#ifndef HAVE_ACTIVE_DESKTOP_L
|
||||
DEFINE_GUID(CLSID_ActiveDesktop,0x75048700L,0xEF1F,0x11D0,0x98,0x88,0x00,0x60,0x97,0xDE,0xAC,0xF9);
|
||||
DEFINE_GUID(IID_IActiveDesktop,0xF490EB00L,0x1240,0x11D1,0x98,0x88,0x00,0x60,0x97,0xDE,0xAC,0xF9);
|
||||
#endif
|
||||
|
||||
#endif /* WIN32 */
|
||||
187
common/os/w32tiger.h
Normal file
187
common/os/w32tiger.h
Normal file
@@ -0,0 +1,187 @@
|
||||
/* Copyright (C) 2011 TigerVNC Team. All Rights Reserved.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
* USA.
|
||||
*/
|
||||
|
||||
#ifndef OS_W32TIGER_H
|
||||
#define OS_W32TIGER_H
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <windows.h>
|
||||
#include <wininet.h>
|
||||
#include <shlobj.h>
|
||||
#include <shlguid.h>
|
||||
#include <wininet.h>
|
||||
|
||||
|
||||
/* Windows has different names for these */
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
|
||||
|
||||
/* MSLLHOOKSTRUCT structure*/
|
||||
#ifndef LLMHF_INJECTED
|
||||
#define LLMHF_INJECTED 0x00000001
|
||||
#endif
|
||||
|
||||
|
||||
/* IActiveDesktop. As of 2011-10-12, MinGW does not define
|
||||
IActiveDesktop in any way (see tracker 2877129), while MinGW64 is
|
||||
broken: has the headers but not the lib symbols. */
|
||||
#ifndef HAVE_ACTIVE_DESKTOP_H
|
||||
extern const GUID CLSID_ActiveDesktop;
|
||||
extern const GUID IID_IActiveDesktop;
|
||||
|
||||
/* IActiveDesktop::AddUrl */
|
||||
#define ADDURL_SILENT 0x0001
|
||||
|
||||
/* IActiveDesktop::AddDesktopItemWithUI */
|
||||
#define DTI_ADDUI_DEFAULT 0x00000000
|
||||
#define DTI_ADDUI_DISPSUBWIZARD 0x00000001
|
||||
#define DTI_ADDUI_POSITIONITEM 0x00000002
|
||||
|
||||
/* IActiveDesktop::ModifyDesktopItem */
|
||||
#define COMP_ELEM_TYPE 0x00000001
|
||||
#define COMP_ELEM_CHECKED 0x00000002
|
||||
#define COMP_ELEM_DIRTY 0x00000004
|
||||
#define COMP_ELEM_NOSCROLL 0x00000008
|
||||
#define COMP_ELEM_POS_LEFT 0x00000010
|
||||
#define COMP_ELEM_POS_TOP 0x00000020
|
||||
#define COMP_ELEM_SIZE_WIDTH 0x00000040
|
||||
#define COMP_ELEM_SIZE_HEIGHT 0x00000080
|
||||
#define COMP_ELEM_POS_ZINDEX 0x00000100
|
||||
#define COMP_ELEM_SOURCE 0x00000200
|
||||
#define COMP_ELEM_FRIENDLYNAME 0x00000400
|
||||
#define COMP_ELEM_SUBSCRIBEDURL 0x00000800
|
||||
#define COMP_ELEM_ORIGINAL_CSI 0x00001000
|
||||
#define COMP_ELEM_RESTORED_CSI 0x00002000
|
||||
#define COMP_ELEM_CURITEMSTATE 0x00004000
|
||||
#define COMP_ELEM_ALL 0x00007FFF /* OR-ed all COMP_ELEM_ */
|
||||
|
||||
/* IActiveDesktop::GetWallpaper */
|
||||
#define AD_GETWP_BMP 0x00000000
|
||||
#define AD_GETWP_IMAGE 0x00000001
|
||||
#define AD_GETWP_LAST_APPLIED 0x00000002
|
||||
|
||||
/* IActiveDesktop::ApplyChanges */
|
||||
#define AD_APPLY_SAVE 0x00000001
|
||||
#define AD_APPLY_HTMLGEN 0x00000002
|
||||
#define AD_APPLY_REFRESH 0x00000004
|
||||
#define AD_APPLY_ALL 0x00000007 /* OR-ed three AD_APPLY_ above */
|
||||
#define AD_APPLY_FORCE 0x00000008
|
||||
#define AD_APPLY_BUFFERED_REFRESH 0x00000010
|
||||
#define AD_APPLY_DYNAMICREFRESH 0x00000020
|
||||
|
||||
/* Structures for IActiveDesktop */
|
||||
typedef struct {
|
||||
DWORD dwSize;
|
||||
int iLeft;
|
||||
int iTop;
|
||||
DWORD dwWidth;
|
||||
DWORD dwHeight;
|
||||
DWORD dwItemState;
|
||||
} COMPSTATEINFO, *LPCOMPSTATEINFO;
|
||||
typedef const COMPSTATEINFO *LPCCOMPSTATEINFO;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwSize;
|
||||
int iLeft;
|
||||
int iTop;
|
||||
DWORD dwWidth;
|
||||
DWORD dwHeight;
|
||||
int izIndex;
|
||||
BOOL fCanResize;
|
||||
BOOL fCanResizeX;
|
||||
BOOL fCanResizeY;
|
||||
int iPreferredLeftPercent;
|
||||
int iPreferredTopPercent;
|
||||
} COMPPOS, *LPCOMPPOS;
|
||||
typedef const COMPPOS *LPCCOMPPOS;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwSize;
|
||||
DWORD dwID;
|
||||
int iComponentType;
|
||||
BOOL fChecked;
|
||||
BOOL fDirty;
|
||||
BOOL fNoScroll;
|
||||
COMPPOS cpPos;
|
||||
WCHAR wszFriendlyName[MAX_PATH];
|
||||
WCHAR wszSource[INTERNET_MAX_URL_LENGTH];
|
||||
WCHAR wszSubscribedURL[INTERNET_MAX_URL_LENGTH];
|
||||
DWORD dwCurItemState;
|
||||
COMPSTATEINFO csiOriginal;
|
||||
COMPSTATEINFO csiRestored;
|
||||
} COMPONENT, *LPCOMPONENT;
|
||||
typedef const COMPONENT *LPCCOMPONENT;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwSize;
|
||||
BOOL fEnableComponents;
|
||||
BOOL fActiveDesktop;
|
||||
} COMPONENTSOPT, *LPCOMPONENTSOPT;
|
||||
typedef const COMPONENTSOPT *LPCCOMPONENTSOPT;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwSize;
|
||||
DWORD dwStyle;
|
||||
} WALLPAPEROPT, *LPWALLPAPEROPT;
|
||||
typedef const WALLPAPEROPT *LPCWALLPAPEROPT;
|
||||
|
||||
/* WALLPAPEROPT styles */
|
||||
#define WPSTYLE_CENTER 0x0
|
||||
#define WPSTYLE_TILE 0x1
|
||||
#define WPSTYLE_STRETCH 0x2
|
||||
#define WPSTYLE_MAX 0x3
|
||||
|
||||
/* Those two are defined in Windows 7 and newer, we don't need them now */
|
||||
#if 0
|
||||
#define WPSTYLE_KEEPASPECT 0x3
|
||||
#define WPSTYLE_CROPTOFIT 0x4
|
||||
#endif
|
||||
|
||||
#define INTERFACE IActiveDesktop
|
||||
DECLARE_INTERFACE_(IActiveDesktop, IUnknown)
|
||||
{
|
||||
STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE;
|
||||
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
|
||||
STDMETHOD_(ULONG,Release)(THIS) PURE;
|
||||
STDMETHOD(AddDesktopItem)(THIS_ LPCOMPONENT,DWORD) PURE;
|
||||
STDMETHOD(AddDesktopItemWithUI)(THIS_ HWND,LPCOMPONENT,DWORD) PURE;
|
||||
STDMETHOD(AddUrl)(THIS_ HWND,LPCWSTR,LPCOMPONENT,DWORD) PURE;
|
||||
STDMETHOD(ApplyChanges)(THIS_ DWORD) PURE;
|
||||
STDMETHOD(GenerateDesktopItemHtml)(THIS_ LPCWSTR,LPCOMPONENT,DWORD) PURE;
|
||||
STDMETHOD(GetDesktopItem)(THIS_ int,LPCOMPONENT,DWORD) PURE;
|
||||
STDMETHOD(GetDesktopItemByID)(THIS_ DWORD,LPCOMPONENT,DWORD) PURE;
|
||||
STDMETHOD(GetDesktopItemBySource)(THIS_ LPCWSTR,LPCOMPONENT,DWORD) PURE;
|
||||
STDMETHOD(GetDesktopItemCount)(THIS_ LPINT,DWORD) PURE;
|
||||
STDMETHOD(GetDesktopItemOptions)(THIS_ LPCOMPONENTSOPT,DWORD) PURE;
|
||||
STDMETHOD(GetPattern)(THIS_ LPWSTR,UINT,DWORD) PURE;
|
||||
STDMETHOD(GetWallpaper)(THIS_ LPWSTR,UINT,DWORD) PURE;
|
||||
STDMETHOD(GetWallpaperOptions)(THIS_ LPWALLPAPEROPT,DWORD) PURE;
|
||||
STDMETHOD(ModifyDesktopItem)(THIS_ LPCCOMPONENT,DWORD) PURE;
|
||||
STDMETHOD(RemoveDesktopItem)(THIS_ LPCCOMPONENT,DWORD) PURE;
|
||||
STDMETHOD(SetDesktopItemOptions)(THIS_ LPCCOMPONENTSOPT,DWORD) PURE;
|
||||
STDMETHOD(SetPattern)(THIS_ LPCWSTR,DWORD) PURE;
|
||||
STDMETHOD(SetWallpaper)(THIS_ LPCWSTR,DWORD) PURE;
|
||||
STDMETHOD(SetWallpaperOptions)(THIS_ LPCWALLPAPEROPT,DWORD) PURE;
|
||||
};
|
||||
#undef INTERFACE
|
||||
#endif /* HAVE_ACTIVE_DESKTOP_H */
|
||||
|
||||
#endif /* WIN32 */
|
||||
#endif /* OS_W32TIGER_H */
|
||||
89
common/os/winerrno.h
Normal file
89
common/os/winerrno.h
Normal file
@@ -0,0 +1,89 @@
|
||||
|
||||
/* Generated with:
|
||||
cat /usr/i686-pc-mingw32/sys-root/mingw/include/winerror.h \
|
||||
| awk '/#define WSAE.*WSABASE/{gsub("WSA", ""); print "#undef " $2 "\n#define " $2 " WSA" $2}' \
|
||||
| egrep -v 'EINTR|EBADF|EACCES|EFAULT|EINVAL|EMFILE|_QOS|PROVIDER|PROCTABLE'
|
||||
*/
|
||||
|
||||
#undef EWOULDBLOCK
|
||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#undef EINPROGRESS
|
||||
#define EINPROGRESS WSAEINPROGRESS
|
||||
#undef EALREADY
|
||||
#define EALREADY WSAEALREADY
|
||||
#undef ENOTSOCK
|
||||
#define ENOTSOCK WSAENOTSOCK
|
||||
#undef EDESTADDRREQ
|
||||
#define EDESTADDRREQ WSAEDESTADDRREQ
|
||||
#undef EMSGSIZE
|
||||
#define EMSGSIZE WSAEMSGSIZE
|
||||
#undef EPROTOTYPE
|
||||
#define EPROTOTYPE WSAEPROTOTYPE
|
||||
#undef ENOPROTOOPT
|
||||
#define ENOPROTOOPT WSAENOPROTOOPT
|
||||
#undef EPROTONOSUPPORT
|
||||
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
|
||||
#undef ESOCKTNOSUPPORT
|
||||
#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
|
||||
#undef EOPNOTSUPP
|
||||
#define EOPNOTSUPP WSAEOPNOTSUPP
|
||||
#undef EPFNOSUPPORT
|
||||
#define EPFNOSUPPORT WSAEPFNOSUPPORT
|
||||
#undef EAFNOSUPPORT
|
||||
#define EAFNOSUPPORT WSAEAFNOSUPPORT
|
||||
#undef EADDRINUSE
|
||||
#define EADDRINUSE WSAEADDRINUSE
|
||||
#undef EADDRNOTAVAIL
|
||||
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
|
||||
#undef ENETDOWN
|
||||
#define ENETDOWN WSAENETDOWN
|
||||
#undef ENETUNREACH
|
||||
#define ENETUNREACH WSAENETUNREACH
|
||||
#undef ENETRESET
|
||||
#define ENETRESET WSAENETRESET
|
||||
#undef ECONNABORTED
|
||||
#define ECONNABORTED WSAECONNABORTED
|
||||
#undef ECONNRESET
|
||||
#define ECONNRESET WSAECONNRESET
|
||||
#undef ENOBUFS
|
||||
#define ENOBUFS WSAENOBUFS
|
||||
#undef EISCONN
|
||||
#define EISCONN WSAEISCONN
|
||||
#undef ENOTCONN
|
||||
#define ENOTCONN WSAENOTCONN
|
||||
#undef ESHUTDOWN
|
||||
#define ESHUTDOWN WSAESHUTDOWN
|
||||
#undef ETOOMANYREFS
|
||||
#define ETOOMANYREFS WSAETOOMANYREFS
|
||||
#undef ETIMEDOUT
|
||||
#define ETIMEDOUT WSAETIMEDOUT
|
||||
#undef ECONNREFUSED
|
||||
#define ECONNREFUSED WSAECONNREFUSED
|
||||
#undef ELOOP
|
||||
#define ELOOP WSAELOOP
|
||||
#undef ENAMETOOLONG
|
||||
#define ENAMETOOLONG WSAENAMETOOLONG
|
||||
#undef EHOSTDOWN
|
||||
#define EHOSTDOWN WSAEHOSTDOWN
|
||||
#undef EHOSTUNREACH
|
||||
#define EHOSTUNREACH WSAEHOSTUNREACH
|
||||
#undef ENOTEMPTY
|
||||
#define ENOTEMPTY WSAENOTEMPTY
|
||||
#undef EPROCLIM
|
||||
#define EPROCLIM WSAEPROCLIM
|
||||
#undef EUSERS
|
||||
#define EUSERS WSAEUSERS
|
||||
#undef EDQUOT
|
||||
#define EDQUOT WSAEDQUOT
|
||||
#undef ESTALE
|
||||
#define ESTALE WSAESTALE
|
||||
#undef EREMOTE
|
||||
#define EREMOTE WSAEREMOTE
|
||||
#undef EDISCON
|
||||
#define EDISCON WSAEDISCON
|
||||
#undef ENOMORE
|
||||
#define ENOMORE WSAENOMORE
|
||||
#undef ECANCELLED
|
||||
#define ECANCELLED WSAECANCELLED
|
||||
#undef EREFUSED
|
||||
#define EREFUSED WSAEREFUSED
|
||||
Reference in New Issue
Block a user