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  bool get_usb_descriptors(uint16_t device_vid, uint16_t device_pid, const std::string& device_uid,
33  std::string& location, usb_spec& spec);
34 
35  class event_base
36  {
37  public:
38  virtual ~event_base();
39  virtual bool set();
40  virtual bool wait(DWORD timeout) const;
41 
42  static event_base* wait(const std::vector<event_base*>& events, bool waitAll, int timeout);
43  static event_base* wait_any(const std::vector<event_base*>& events, int timeout);
44  static event_base* wait_all(const std::vector<event_base*>& events, int timeout);
45 
46  HANDLE get_handle() const { return _handle; }
47 
48  protected:
49  explicit event_base(HANDLE handle);
50 
51  HANDLE _handle;
52 
53  private:
54  event_base() = delete;
55 
56  // Disallow copy:
57  event_base(const event_base&) = delete;
58  event_base& operator=(const event_base&) = delete;
59  };
60 
62  {
63  public:
65  };
66 
68  {
69  public:
71 
72  bool reset() const;
73  };
74 
76  {
80  };
81 
82  class named_mutex
83  {
84  public:
85  named_mutex(const char* id, unsigned timeout);
86  ~named_mutex();
87  bool try_lock() const;
88  void lock() const { acquire(); }
89  void unlock() const { release(); }
90 
91  private:
92  create_and_open_status create_named_mutex(const char* camID);
93  create_and_open_status open_named_mutex(const char* camID);
94  void update_id(const char* id);
95  void acquire() const;
96  void release() const;
97  void close();
98 
99  unsigned _timeout;
100  HANDLE _winusb_mutex;
101  };
102 
103  }
104 }
void unlock() const
Definition: win-helpers.h:89
Definition: win-helpers.h:67
bool check(const char *call, HRESULT hr, bool to_throw=true)
HANDLE get_handle() const
Definition: win-helpers.h:46
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:88
HANDLE _handle
Definition: win-helpers.h:51
usb_spec
Definition: backend.h:180
Definition: algo.h:16
static event_base * wait_any(const std::vector< event_base *> &events, int timeout)
bool get_usb_descriptors(uint16_t device_vid, uint16_t device_pid, const std::string &device_uid, std::string &location, usb_spec &spec)
create_and_open_status
Definition: win-helpers.h:75
Definition: backend-v4l2.h:50
Definition: win-helpers.h:79
Definition: win-helpers.h:61
std::vector< std::string > tokenize(std::string string, char separator)
Definition: win-helpers.h:77
virtual bool wait(DWORD timeout) const
Definition: win-helpers.h:78
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:35