-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor and modernize the native interface #35
Merged
implausible
merged 50 commits into
Axosoft:master
from
xqp:refactor/remove_opa_and_use_cpp11_STL
Sep 23, 2017
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
92e1fd5
refactor the queue implementation
5ec8b6e
FIX: remove dependency to uv_sem_t in osx service
reneme 4425157
extend CMakeLists.txt for platform dependent code
reneme 62939cd
FIX: use const& of std::string
reneme b36a028
Merge pull request #1 from reneme/refactor/remove_opa_and_use_cpp11_STL
3015c9d
FIX: usage of condition variable
reneme 5fc4dbd
use the javascript tests with windows
2137636
Merge pull request #2 from reneme/refactor/remove_opa_and_use_cpp11_STL
87b2e59
remove dependency to OpenPA
reneme 28701c9
FIX: signed/unsigned compiler warning
reneme e91446e
Merge pull request #3 from reneme/refactor/remove_opa_and_use_cpp11_STL
5d11a18
change xcode configuration for nodejs 4 and 6
5c7fe7d
try to find a reace cond
feb3b0e
try msvs 2015
e7a94c3
FIX: build on macOS with node.js v4
reneme bfe9eee
switch from c++0x to proper c++11
reneme 4978e9a
Refactor: add a single shot semaphore for threadsafe state announcement
reneme 747d16e
FIX: remove unnecessary implementation
reneme 9c58e58
Merge pull request #4 from reneme/refactor/remove_opa_and_use_cpp11_STL
438cf33
merge with origin/master
ed56d42
FIX: code cosmetics
reneme a65bca5
Merge remote-tracking branch 'xqp/refactor/remove_opa_and_use_cpp11_S…
reneme 1e667d0
refactor the windows native implementation
422d46b
implement error handling in watcher and controller
def8e5a
use c++11 threads instead of native implementation
5352ae8
quickfix for windows js tests
94156e7
FIX: linux and macOS with std::shared_ptr<EventQueue>
reneme f5f6caa
Merge pull request #5 from reneme/refactor/remove_opa_and_use_cpp11_STL
ce29e83
fix deadlock in nodejs cpp interface
72459d6
delete unused files
31e3c18
move files and cleanup files
cd10116
revert some changes
85b10b3
Refactor: remove the self-tailored lock guard
reneme 7d6779f
Doc: SingleshotSemaphore
reneme daa2e52
FIX: cosmetics
reneme 60ade73
Merge pull request #6 from reneme/refactor/remove_opa_and_use_cpp11_STL
27d1677
Refactor: use std::thread rather then pthread_t
reneme da6e002
Merge pull request #7 from reneme/refactor/remove_opa_and_use_cpp11_STL
0a8befa
use semaphore to wait until thread is running
f224dbf
Merge pull request #8 from hrantzsch/refactor/remove_opa_and_use_cpp1…
c159680
review issues
6daa85f
Merge branch 'refactor/remove_opa_and_use_cpp11_STL' of https://githu…
7cd1053
style guide issue
2674f64
upgrade to msvc 2015 because compile error in older version
b782c47
FIX: review comments
reneme b651b28
Merge pull request #9 from reneme/refactor/remove_opa_and_use_cpp11_STL
f3a859c
FIX: missing header adaption
reneme a9aa805
Merge pull request #10 from reneme/refactor/remove_opa_and_use_cpp11_STL
01f1a75
fix compile errors in windows ci build
990cafb
remove empty line in cmakelists
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cmake_minimum_required (VERSION 3.1.0 FATAL_ERROR) | ||
set (PROJECT_NAME "NSFW") | ||
project (${PROJECT_NAME}) | ||
|
||
message (STATUS "Running CMake version ${CMAKE_VERSION}") | ||
|
||
set (NSFW_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include") | ||
|
||
add_subdirectory (src) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,33 @@ | ||
#ifndef NSFW_NATIVE_INTERFACE_H | ||
#define NSFW_NATIVE_INTERFACE_H | ||
|
||
#if defined(_WIN32) | ||
#include "../includes/win32/Controller.h" | ||
using NativeImplementation = Controller; | ||
#elif defined(__APPLE_CC__) | ||
#include "../includes/osx/FSEventsService.h" | ||
using NativeImplementation = FSEventsService; | ||
#elif defined(__linux__) || defined(__FreeBSD__) | ||
#include "../includes/linux/InotifyService.h" | ||
using NativeImplementation = InotifyService; | ||
#endif | ||
|
||
#include "Queue.h" | ||
#include <vector> | ||
|
||
class NativeInterface { | ||
public: | ||
NativeInterface(std::string path); | ||
NativeInterface(const std::string &path); | ||
~NativeInterface(); | ||
|
||
std::string getError(); | ||
std::vector<Event *> *getEvents(); | ||
std::vector<Event*> *getEvents(); | ||
bool hasErrored(); | ||
bool isWatching(); | ||
|
||
~NativeInterface(); | ||
private: | ||
EventQueue mQueue; | ||
void *mNativeInterface; | ||
std::shared_ptr<EventQueue> mQueue; | ||
std::unique_ptr<NativeImplementation> mNativeInterface; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#ifndef NSFW_SEMAPHORE_H | ||
#define NSFW_SEMAPHORE_H | ||
|
||
#include <condition_variable> | ||
#include <mutex> | ||
|
||
/** | ||
* This is a convenience abstraction around std::condition_variable that allows | ||
* for a one-shot synchronization point. Therefore the Semaphore has no way to | ||
* reset its state. | ||
* | ||
* It doesn't matter if the waiting thread calls `wait()` before or after the | ||
* signaling thread calls `signal()`. Only in the latter case the `wait()` won't | ||
* block. | ||
*/ | ||
class SingleshotSemaphore { | ||
public: | ||
SingleshotSemaphore() : mState(false) {} | ||
|
||
/** | ||
* Blocks the calling thread until the semaphore is signaled asynchronously. | ||
* If `signal()` has been called on the semaphore already, this won't block. | ||
*/ | ||
void wait() { | ||
std::unique_lock<std::mutex> lk(mMutex); | ||
|
||
while (!mState) { | ||
mCond.wait(lk); | ||
} | ||
} | ||
|
||
/** | ||
* Blocks the calling thread for a given time period and continues either | ||
* when `signal()` was called asynchronously or when the time is up. The | ||
* return condition is indicated by the returned boolean. | ||
* | ||
* \return true if the semaphore was signal()ed; false on timeout reached | ||
*/ | ||
bool waitFor(std::chrono::milliseconds ms) { | ||
std::unique_lock<std::mutex> lk(mMutex); | ||
|
||
if (mState) { | ||
return true; | ||
} | ||
|
||
mCond.wait_for(lk, ms); | ||
return mState; | ||
} | ||
|
||
/** | ||
* Unblocks all waiting threads of the semaphore. Note that threads reaching | ||
* the `wait()` on this semaphore after `signal()` has been called won't | ||
* block but continue immediately. | ||
*/ | ||
void signal() { | ||
std::unique_lock<std::mutex> lk(mMutex); | ||
mState = true; | ||
mCond.notify_all(); | ||
} | ||
|
||
private: | ||
std::mutex mMutex; | ||
std::condition_variable mCond; | ||
bool mState; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this still build with msvs_version set to 2013?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let us use the 2013 compiler :)