Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
win-helpers.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 #pragma once
4 
5 #ifndef NOMINMAX
6 #define NOMINMAX
7 #endif
8 
9 #include <string>
10 #include <vector>
11 
12 #include <windows.h>
13 
14 #define WAIT_FOR_MUTEX_TIME_OUT (5000)
15 
16 namespace librealsense
17 {
18  namespace platform
19  {
20  bool check(const char * call, HRESULT hr, bool to_throw = true);
21 #define CHECK_HR(x) check(#x, x);
22 #define LOG_HR(x) check(#x, x, false);
23 
24  std::string win_to_utf(const WCHAR * s);
25 
26  bool is_win10_redstone2();
27 
28  std::vector<std::string> tokenize(std::string string, char separator);
29 
30  bool parse_usb_path(uint16_t & vid, uint16_t & pid, uint16_t & mi, std::string & unique_id, const std::string & path);
31 
32  std::string get_usb_port_id(uint16_t device_vid, uint16_t device_pid, const std::string& device_uid);
33 
34  class event_base
35  {
36  public:
37  virtual ~event_base();
38  virtual bool set();
39  virtual bool wait(DWORD timeout) const;
40 
41  static event_base* wait(const std::vector<event_base*>& events, bool waitAll, int timeout);
42  static event_base* wait_any(const std::vector<event_base*>& events, int timeout);
43  static event_base* wait_all(const std::vector<event_base*>& events, int timeout);
44 
45  HANDLE get_handle() const { return _handle; }
46 
47  protected:
48  explicit event_base(HANDLE handle);
49 
50  HANDLE _handle;
51 
52  private:
53  event_base() = delete;
54 
55  // Disallow copy:
56  event_base(const event_base&) = delete;
57  event_base& operator=(const event_base&) = delete;
58  };
59 
61  {
62  public:
64  };
65 
67  {
68  public:
70 
71  bool reset() const;
72  };
73 
75  {
79  };
80 
81  class named_mutex
82  {
83  public:
84  named_mutex(const char* id, unsigned timeout);
85  ~named_mutex();
86  bool try_lock() const;
87  void lock() const { acquire(); }
88  void unlock() const { release(); }
89 
90  private:
91  create_and_open_status create_named_mutex(const char* camID);
92  create_and_open_status open_named_mutex(const char* camID);
93  void update_id(const char* id);
94  void acquire() const;
95  void release() const;
96  void close();
97 
98  unsigned _timeout;
99  HANDLE _winusb_mutex;
100  };
101 
102  }
103 }
void unlock() const
Definition: win-helpers.h:88
Definition: win-helpers.h:66
bool check(const char *call, HRESULT hr, bool to_throw=true)
HANDLE get_handle() const
Definition: win-helpers.h:45
static event_base * wait_all(const std::vector< event_base *> &events, int timeout)
std::string win_to_utf(const WCHAR *s)
void lock() const
Definition: win-helpers.h:87
HANDLE _handle
Definition: win-helpers.h:50
Definition: algo.h:16
std::string get_usb_port_id(uint16_t device_vid, uint16_t device_pid, const std::string &device_uid)
static event_base * wait_any(const std::vector< event_base *> &events, int timeout)
create_and_open_status
Definition: win-helpers.h:74
Definition: win-helpers.h:78
Definition: win-helpers.h:60
named_mutex(const std::string &device_path, unsigned timeout)
std::vector< std::string > tokenize(std::string string, char separator)
Definition: win-helpers.h:76
virtual bool wait(DWORD timeout) const
Definition: win-helpers.h:77
bool parse_usb_path(uint16_t &vid, uint16_t &pid, uint16_t &mi, std::string &unique_id, const std::string &path)
Definition: win-helpers.h:34