1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP
#define BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP
#include <boost/config.hpp>
#include <string> //std::string
#include <sstream> //std::stringstream
#include <boost/interprocess/detail/os_thread_functions.hpp>
#include <boost/interprocess/detail/os_file_functions.hpp>
namespace boost{
namespace interprocess{
namespace test{
inline void get_process_id_name(std::string &str)
{
std::stringstream sstr;
sstr << "process_" << boost::interprocess::ipcdetail::get_current_process_id() << std::ends;
str = sstr.str().c_str();
}
inline void get_process_id_ptr_name(std::string &str, const void *ptr)
{
std::stringstream sstr;
sstr << "process_" << boost::interprocess::ipcdetail::get_current_process_id() << "_" << ptr << std::ends;
str = sstr.str().c_str();
}
inline const char *get_process_id_name()
{
static bool done = false;
static std::string str;
if(!done)
get_process_id_name(str);
return str.c_str();
}
inline const char *get_process_id_ptr_name(void *ptr)
{
static bool done = false;
static std::string str;
if(!done)
get_process_id_ptr_name(str, ptr);
return str.c_str();
}
inline const char *add_to_process_id_name(const char *name)
{
static bool done = false;
static std::string str;
if(!done){
get_process_id_name(str);
str += name;
}
return str.c_str();
}
inline const char *add_to_process_id_ptr_name(const char *name, void *ptr)
{
static bool done = false;
static std::string str;
if(!done){
get_process_id_ptr_name(str, ptr);
str += name;
}
return str.c_str();
}
} //namespace test{
inline std::string get_filename()
{
std::string ret (ipcdetail::get_temporary_path());
ret += "/";
ret += test::get_process_id_name();
return ret;
}
#ifdef BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES
namespace test {
inline void get_process_id_wname(std::wstring &str)
{
std::wstringstream sstr;
sstr << L"process_" << boost::interprocess::ipcdetail::get_current_process_id() << std::ends;
str = sstr.str().c_str();
}
inline const wchar_t *get_process_id_wname()
{
static bool done = false;
static std::wstring str;
if(!done)
get_process_id_wname(str);
return str.c_str();
}
inline const wchar_t *add_to_process_id_name(const wchar_t *name)
{
static bool done = false;
static std::wstring str;
if(!done){
get_process_id_wname(str);
str += name;
}
return str.c_str();
}
} //namespace test {
inline std::wstring get_wfilename()
{
std::wstring ret (ipcdetail::get_temporary_wpath());
ret += L"/";
ret += test::get_process_id_wname();
return ret;
}
#endif
} //namespace interprocess{
} //namespace boost{
#endif //#ifndef BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP
|