Merge branch 'macos' of https://github.com/BenjaminNavarro/nana into BenjaminNavarro-macos

This commit is contained in:
Jinhao
2015-11-10 23:21:07 +08:00
28 changed files with 2235 additions and 86 deletions

View File

@@ -9,13 +9,15 @@
* @file: nana/system/platform.cpp
* @description:
* this implements some API for platform-independent programming
* @contributors:
* Benjamin Navarro(pr#81)
*/
#include <nana/deploy.hpp>
#if defined(NANA_WINDOWS)
#include <windows.h>
#include <nana/detail/win32/platform_spec.hpp>
#elif defined(NANA_LINUX)
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
#include <time.h>
#include <errno.h>
#include <unistd.h>
@@ -34,7 +36,7 @@ namespace system
{
#if defined(NANA_WINDOWS)
::Sleep(milliseconds);
#elif defined(NANA_LINUX)
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct timespec timeOut, remains;
timeOut.tv_sec = milliseconds / 1000;
timeOut.tv_nsec = (milliseconds % 1000) * 1000000;
@@ -56,6 +58,8 @@ namespace system
return ::GetCurrentThreadId();
#elif defined(NANA_LINUX)
return ::syscall(__NR_gettid);
#elif defined(NANA_MACOS)
return ::syscall(SYS_thread_selfid);
#endif
}
@@ -63,7 +67,7 @@ namespace system
{
#if defined(NANA_WINDOWS)
return ::GetTickCount();
#elif defined(NANA_LINUX)
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct timeval tv;
::gettimeofday(&tv, 0);
return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
@@ -88,7 +92,7 @@ namespace system
}
return (::GetAsyncKeyState(button) != 0);
#elif defined(NANA_LINUX)
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
return false;
#endif
}
@@ -109,7 +113,7 @@ namespace system
nana::detail::platform_spec::co_initializer co_init;
::ShellExecute(0, STR("open"), url.c_str(), 0, 0, SW_SHOWNORMAL);
}
#elif defined(NANA_LINUX)
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
#endif
}
}//end namespace system

View File

@@ -12,7 +12,7 @@
#include <nana/system/shared_wrapper.hpp>
#include <algorithm>
#include <iterator>
#ifdef NANA_LINUX
#if defined(NANA_LINUX) or defined(NANA_MACOS)
#include <dlfcn.h>
#else
#include <windows.h>
@@ -30,7 +30,7 @@ namespace system
module_t open(const char* filename)
{
#ifdef NANA_LINUX
#if defined(NANA_LINUX) or defined(NANA_MACOS)
return ::dlopen(filename, RTLD_LAZY);
#else
return ::LoadLibraryA(filename);
@@ -39,7 +39,7 @@ namespace system
void* symbols(module_t handle, const char* symbol)
{
#ifdef NANA_LINUX
#if defined(NANA_LINUX) or defined(NANA_MACOS)
return ::dlsym(handle, const_cast<char*>(symbol));
#else
return (void*)(::GetProcAddress(reinterpret_cast<HMODULE>(handle), symbol));
@@ -48,7 +48,7 @@ namespace system
void close(module_t handle)
{
#ifdef NANA_LINUX
#if defined(NANA_LINUX) or defined(NANA_MACOS)
::dlclose(handle);
#else
::FreeLibrary(reinterpret_cast<HMODULE>(handle));
@@ -90,7 +90,7 @@ namespace system
std::transform(filename + length - 13, filename + length , std::back_inserter(file), tolower);
if(file == ".nana_shared")
{
#ifdef NANA_LINUX
#if defined(NANA_LINUX) or defined(NANA_MACOS)
ofn.replace(length - 13, 13, ".so");
#else
ofn.replace(length - 13, 13, ".DLL");

View File

@@ -2,7 +2,7 @@
#include <nana/config.hpp>
#ifdef NANA_WINDOWS
#include <windows.h>
#elif defined(NANA_LINUX)
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
#include <sys/time.h>
#endif
@@ -15,7 +15,7 @@ namespace system
{
#if defined(NANA_WINDOWS)
LARGE_INTEGER beg_timestamp;
#elif defined(NANA_LINUX)
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct timeval beg_timestamp;
#endif
};
@@ -45,7 +45,7 @@ namespace system
{
#if defined(NANA_WINDOWS)
::QueryPerformanceCounter(&impl_->beg_timestamp);
#elif defined(NANA_LINUX)
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct timezone tz;
::gettimeofday(&impl_->beg_timestamp, &tz);
#endif
@@ -63,7 +63,7 @@ namespace system
::QueryPerformanceFrequency(&freq);
return double(diff)/double(freq.QuadPart) * 1000;
#elif defined(NANA_LINUX)
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);