Merge branch 'feature-freebsd-posix' into develop

This commit is contained in:
Jinhao
2018-05-08 04:52:13 +08:00
32 changed files with 509 additions and 255 deletions

View File

@@ -17,12 +17,49 @@
#if defined(NANA_WINDOWS)
#include <windows.h>
#include "../detail/mswin/platform_spec.hpp"
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
#elif defined(NANA_POSIX)
#include <time.h>
#include <errno.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/syscall.h>
#include <pthread.h>
#include <sys/stat.h>
#include <spawn.h>
#include <string.h>
static void posix_open_url(const char *url_utf8)
{
extern char **environ;
const char *home = getenv("HOME");
std::string cheat(home);
cheat += "/.mozilla";
struct stat exists{};
// TODO: generalize this for chromium, opera, waterfox, etc.
// Most desktop environments (KDE, Gnome, Lumina etc.) provide a way to set
// your preferred browser - but there are more desktops than browsers.
// Look for $HOME/.mozilla directory as strong evidence they use firefox.
if ( stat(cheat.c_str(), &exists) == 0 && S_ISDIR(exists.st_mode))
{
const char *path = "";
static const char *likely[2] = { "/usr/local/bin/firefox", "/usr/bin/firefox"};
if ( stat(likely[0], &exists) == 0 && S_ISREG(exists.st_mode))
path = likely[0];
else if ( stat(likely[1], &exists) == 0 && S_ISREG(exists.st_mode) )
path = likely[1];
else return;
pid_t pid = 0;
static const char firefox[] = "firefox";
char name[sizeof firefox]{};
// argv does not like const-literals so make a copy.
strcpy(name, firefox);
char *argv[3] = {name, const_cast<char *>(url_utf8), nullptr};
posix_spawn(&pid, path, NULL, NULL, argv, environ);
}
}
#endif
namespace nana
@@ -36,7 +73,7 @@ namespace system
{
#if defined(NANA_WINDOWS)
::Sleep(milliseconds);
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
#elif defined(NANA_POSIX)
struct timespec timeOut, remains;
timeOut.tv_sec = milliseconds / 1000;
timeOut.tv_nsec = (milliseconds % 1000) * 1000000;
@@ -52,14 +89,16 @@ namespace system
//this_thread_id
//@brief: get the identifier of calling thread.
unsigned long this_thread_id()
thread_t this_thread_id()
{
#if defined(NANA_WINDOWS)
return ::GetCurrentThreadId();
return (thread_t)::GetCurrentThreadId();
#elif defined(NANA_LINUX)
return ::syscall(__NR_gettid);
return (thread_t)::syscall(__NR_gettid);
#elif defined(NANA_MACOS)
return ::syscall(SYS_thread_selfid);
return (thread_t)::syscall(SYS_thread_selfid);
#elif defined(NANA_POSIX)
return (thread_t)pthread_self();
#endif
}
@@ -67,7 +106,7 @@ namespace system
{
#if defined(NANA_WINDOWS)
return ::GetTickCount();
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
#elif defined(NANA_POSIX)
struct timeval tv;
::gettimeofday(&tv, 0);
return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
@@ -92,7 +131,7 @@ namespace system
}
return (::GetAsyncKeyState(button) != 0);
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
#elif defined(NANA_POSIX)
static_cast<void>(button); //eliminate unused parameter compiler warning.
return false;
#endif
@@ -105,7 +144,6 @@ namespace system
return;
#if defined(NANA_WINDOWS)
std::wstring url = to_wstring(url_utf8);
if(::ShellExecute(0, L"open", url.c_str(), 0, 0, SW_SHOWNORMAL) < reinterpret_cast<HINSTANCE>(32))
{
//Because ShellExecute can delegate execution to Shell extensions (data sources, context menu handlers,
@@ -115,8 +153,9 @@ namespace system
nana::detail::platform_spec::co_initializer co_init;
::ShellExecute(0, L"open", url.c_str(), 0, 0, SW_SHOWNORMAL);
}
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
#elif defined(NANA_POSIX)
posix_open_url(url_utf8.c_str());
#endif
}
}
}//end namespace system
}//end namespace nana

View File

@@ -2,8 +2,8 @@
* Operation System Shared Linkage Library Wrapper Implementation
* Copyright(C) 2003 Jinhao
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* @file: nana/system/shared_wrapper.cpp
@@ -12,7 +12,7 @@
#include <nana/system/shared_wrapper.hpp>
#include <algorithm>
#include <iterator>
#if defined(NANA_LINUX) || defined(NANA_MACOS)
#if defined(NANA_POSIX)
#include <dlfcn.h>
#else
#include <windows.h>
@@ -30,7 +30,7 @@ namespace system
module_t open(const char* filename)
{
#if defined(NANA_LINUX) || defined(NANA_MACOS)
#if defined(NANA_POSIX)
return ::dlopen(filename, RTLD_LAZY);
#else
return ::LoadLibraryA(filename);
@@ -39,7 +39,7 @@ namespace system
void* symbols(module_t handle, const char* symbol)
{
#if defined(NANA_LINUX) || defined(NANA_MACOS)
#if defined(NANA_POSIX)
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)
{
#if defined(NANA_LINUX) || defined(NANA_MACOS)
#if defined(NANA_POSIX)
::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")
{
#if defined(NANA_LINUX) || defined(NANA_MACOS)
#if defined(NANA_POSIX)
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) || defined(NANA_MACOS)
#elif defined(NANA_POSIX)
#include <sys/time.h>
#endif
@@ -15,7 +15,7 @@ namespace system
{
#if defined(NANA_WINDOWS)
LARGE_INTEGER beg_timestamp;
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
#elif defined(NANA_POSIX)
struct timeval beg_timestamp;
#endif
};
@@ -45,7 +45,7 @@ namespace system
{
#if defined(NANA_WINDOWS)
::QueryPerformanceCounter(&impl_->beg_timestamp);
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
#elif defined(NANA_POSIX)
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) || defined(NANA_MACOS)
#elif defined(NANA_POSIX)
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);