erster versuch der min max ausgibt
[201903hackathon.git] / inc / sample_utils / PlatformResources.hpp
1 /****************************************************************************\
2  * Copyright (C) 2017 Infineon Technologies & pmdtechnologies ag
3  *
4  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
5  * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
6  * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
7  * PARTICULAR PURPOSE.
8  *
9  \****************************************************************************/
10
11 #pragma once
12
13 #include <iostream>
14
15 #ifdef _WIN32
16 #include <windows.h>
17 #endif
18
19 namespace sample_utils
20 {
21     /**
22      * Some platforms (and certain frameworks on those platforms) require the application to call an
23      * initialization method before the library can use certain features.
24      *
25      * The only one currently affecting us is Windows COM, which is needed for the UVC camera
26      * support on Windows.
27      *
28      * Qt will also create these resources, in a Qt app the application does not need to create them
29      * (and Qt will fail to start if the application creates them with conflicting settings).
30      */
31     class PlatformResources
32     {
33 #ifdef _WIN32
34     public:
35         PlatformResources () :
36             m_initializedSuccessfully {false}
37         {
38             auto hr = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
39             if (FAILED (hr))
40             {
41                 std::cout << "Can not initialize for the COM framework, UVC devices will not work" << std::endl;
42             }
43             else
44             {
45                 m_initializedSuccessfully = true;
46             }
47         }
48
49         ~PlatformResources ()
50         {
51             if (m_initializedSuccessfully)
52             {
53                 CoUninitialize ();
54             }
55         }
56
57     private:
58         bool m_initializedSuccessfully;
59 #else
60     public:
61         PlatformResources () = default;
62         ~PlatformResources ()
63         {
64             // non-trivial destructor to avoid an "unused variable platformResources" warning
65             (void) this;
66         }
67 #endif
68     };
69 }