Commit 8f328ae5 authored by Dominik Charousset's avatar Dominik Charousset

Add get_process_id utility function

parent 5da4203c
......@@ -50,6 +50,7 @@ set (LIBCAF_CORE_SRCS
src/exit_reason.cpp
src/forwarding_actor_proxy.cpp
src/get_mac_addresses.cpp
src/get_process_id.cpp
src/get_root_uuid.cpp
src/group.cpp
src/group_manager.cpp
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_DETAIL_GET_PROCESS_ID_HPP
#define CAF_DETAIL_GET_PROCESS_ID_HPP
#include <string>
#include <vector>
#include <utility>
namespace caf {
namespace detail {
unsigned get_process_id();
} // namespace detail
} // namespace caf
#endif // CAF_DETAIL_GET_PROCESS_ID_HPP
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/detail/get_process_id.hpp"
#include "caf/config.hpp"
#ifdef CAF_WINDOWS
# include <Windows.h>
#else
# include <sys/types.h>
# include <unistd.h>
#endif
namespace caf {
namespace detail {
unsigned get_process_id() {
# ifdef CAF_WINDOWS
return GetCurrentProcessId();
# else
return static_cast<unsigned>(getpid());
# endif
}
} // namespace detail
} // namespace caf
......@@ -21,9 +21,6 @@
#include <cstring>
#include <sstream>
#include <unistd.h>
#include <sys/types.h>
#include "caf/config.hpp"
#include "caf/node_id.hpp"
#include "caf/serializer.hpp"
......@@ -36,6 +33,7 @@
#include "caf/detail/ripemd_160.hpp"
#include "caf/detail/safe_equal.hpp"
#include "caf/detail/get_root_uuid.hpp"
#include "caf/detail/get_process_id.hpp"
#include "caf/detail/get_mac_addresses.hpp"
namespace caf {
......@@ -165,7 +163,7 @@ node_id::data::~data() {
}
void node_id::data::stop() {
// nop
CAF_LOG_TRACE("");
}
// initializes singleton
......@@ -180,9 +178,8 @@ node_id::data* node_id::data::create_singleton() {
auto hd_serial_and_mac_addr = join(macs, "") + detail::get_root_uuid();
node_id::host_id_type nid;
detail::ripemd_160(nid, hd_serial_and_mac_addr);
auto ptr = make_counted<node_id::data>(static_cast<uint32_t>(getpid()), nid);
// note: ptr has a ref count of 1 -> implicitly held by detail::singletons
return ptr.release();
// note: pointer has a ref count of 1 -> implicitly held by detail::singletons
return new node_id::data(detail::get_process_id(), nid);
}
uint32_t node_id::process_id() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment