/src/Fast-DDS/thirdparty/boost/include/boostconfig.hpp
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).  | 
2  |  | //  | 
3  |  | // Licensed under the Apache License, Version 2.0 (the "License");  | 
4  |  | // you may not use this file except in compliance with the License.  | 
5  |  | // You may obtain a copy of the License at  | 
6  |  | //  | 
7  |  | //     http://www.apache.org/licenses/LICENSE-2.0  | 
8  |  | //  | 
9  |  | // Unless required by applicable law or agreed to in writing, software  | 
10  |  | // distributed under the License is distributed on an "AS IS" BASIS,  | 
11  |  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
12  |  | // See the License for the specific language governing permissions and  | 
13  |  | // limitations under the License.  | 
14  |  |  | 
15  |  | #ifndef _FASTDDS_THIRDPARTYBOOST_BOOSTCONFIG_H_  | 
16  |  | #define _FASTDDS_THIRDPARTYBOOST_BOOSTCONFIG_H_  | 
17  |  |  | 
18  |  | #include <utils/shared_memory/BoostAtExitRegistry.hpp>  | 
19  |  |  | 
20  |  | #define BOOST_DATE_TIME_NO_LIB  | 
21  |  | #define BOOST_INTERPROCESS_ENABLE_TIMEOUT_WHEN_LOCKING  | 
22  | 0  | #define BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS 1000  | 
23  |  |  | 
24  |  | // We have patched part of the boost code, protecting all changes with this define  | 
25  |  | #define BOOST_FASTDDS_PATCHES  | 
26  |  |  | 
27  |  | // Starting on boost 1.76.0, this will force native emulation, which is what we want as  | 
28  |  | // it is more performant  | 
29  |  | #define BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION  | 
30  |  |  | 
31  |  | #ifdef ANDROID  | 
32  |  | #define BOOST_INTERPROCESS_SHARED_DIR_PATH "/data/local/tmp"  | 
33  |  | #endif  | 
34  |  |  | 
35  |  | #define BOOST_INTERPROCESS_ATEXIT(f) eprosima::detail::BoostAtExitRegistry::get_instance()->at_exit_register((f))  | 
36  |  |  | 
37  |  | #ifdef _MSC_VER  | 
38  |  |  | 
39  |  | #include <stdlib.h>  | 
40  |  | #include <sys/types.h>  | 
41  |  | #include <sys/stat.h>  | 
42  |  | #include <stdexcept>  | 
43  |  |  | 
44  |  | // TODO(Adolfo): This will fail if windows system without program data in C: drive  | 
45  |  | #define BOOST_INTERPROCESS_SHARED_DIR_PATH "C:\\ProgramData\\eprosima\\fastdds_interprocess"  | 
46  |  |  | 
47  |  | // Check that generic emulation has not been accidentally enabled  | 
48  |  | #include <boost/interprocess/detail/workaround.hpp>  | 
49  |  | #if defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION)  | 
50  |  | #  error "BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION must be disabled in boost/interprocess/detail/workarround.hpp"  | 
51  |  | #endif  // BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION  | 
52  |  |  | 
53  |  | #endif // _MSC_VER_  | 
54  |  |  | 
55  |  | /**  | 
56  |  |  * This singleton class performs some necesary system dependent initializations  | 
57  |  |  * before start working with shared-memory  | 
58  |  |  */  | 
59  |  | class SharedMemEnvironment  | 
60  |  | { | 
61  |  | public:  | 
62  |  |  | 
63  |  |     SharedMemEnvironment()  | 
64  |  | #ifdef _MSC_VER  | 
65  |  |         : is_init_done_(false)  | 
66  |  | #endif // ifdef _MSC_VER  | 
67  | 0  |     { | 
68  | 0  |     }  | 
69  |  |  | 
70  |  |     /**  | 
71  |  |      * @return the singleton instance  | 
72  |  |      */  | 
73  |  |     static SharedMemEnvironment& get()  | 
74  | 0  |     { | 
75  | 0  |         static SharedMemEnvironment singleton_instance;  | 
76  | 0  |         return singleton_instance;  | 
77  | 0  |     }  | 
78  |  |  | 
79  |  |     /**  | 
80  |  |      * Perform the initializacion, only the first time is called.  | 
81  |  |      */  | 
82  |  |     void init()  | 
83  | 0  |     { | 
84  |  | #ifdef _MSC_VER  | 
85  |  |         if (!is_init_done_)  | 
86  |  |         { | 
87  |  |             get().create_shared_dir_if_doesnt_exist();  | 
88  |  |  | 
89  |  |         }  | 
90  |  |  | 
91  |  |         is_init_done_ = true;  | 
92  |  | #endif // ifdef _MSC_VER  | 
93  | 0  |     }  | 
94  |  |  | 
95  |  | private:  | 
96  |  |  | 
97  |  | #ifdef _MSC_VER  | 
98  |  |  | 
99  |  |     bool is_init_done_;  | 
100  |  |  | 
101  |  |  | 
102  |  |     static void create_shared_dir_if_doesnt_exist()  | 
103  |  |     { | 
104  |  |         struct stat info;  | 
105  |  |  | 
106  |  |         // Cannot access shared_dir_path, we assume it doesn't exist  | 
107  |  |         if (stat(BOOST_INTERPROCESS_SHARED_DIR_PATH, &info) != 0)  | 
108  |  |         { | 
109  |  |             // Try to create it  | 
110  |  |             if (system(("mkdir " BOOST_INTERPROCESS_SHARED_DIR_PATH)) != 0) | 
111  |  |             { | 
112  |  |                 throw std::runtime_error("couldn't access nor create " BOOST_INTERPROCESS_SHARED_DIR_PATH); | 
113  |  |             }  | 
114  |  |         }  | 
115  |  |     }  | 
116  |  |  | 
117  |  |     void clean()  | 
118  |  |     { | 
119  |  |         system("del " BOOST_INTERPROCESS_SHARED_DIR_PATH "\\*.* /Q"); | 
120  |  |     }  | 
121  |  |  | 
122  |  | #endif // ifdef _MSC_VER  | 
123  |  |  | 
124  |  | };  | 
125  |  |  | 
126  |  | #endif // _FASTDDS_THIRDPARTYBOOST_BOOSTCONFIG_H_  |