ATLAS Offline Software
IdentifiedSharedQueue.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <boost/interprocess/ipc/message_queue.hpp>
8 
9 #include <sstream>
10 
11 using namespace boost::interprocess;
12 
13 
14 //const std::size_t MAX_MSG_SIZE = 4096;
15 
16 namespace AthenaInterprocess {
17 
18 //- construction/destruction -------------------------------------------------
19 IdentifiedSharedQueue::IdentifiedSharedQueue() : SharedQueue()
20 {
21 /* empty */
22 }
23 
24  IdentifiedSharedQueue::IdentifiedSharedQueue( const std::string& name, int max_msg, std::size_t max_size, bool do_unlink ) :
25  SharedQueue( name, max_msg, max_size, do_unlink )
26 {
27 /* empty */
28 }
29 
30 //- public member functions --------------------------------------------------
31 inline std::string add_pid( const std::string& buf )
32 {
33  std::ostringstream s;
34  s << (long)getpid() << '\0' << buf;
35  return s.str();
36 }
37 
38 bool IdentifiedSharedQueue::try_send( const std::string& buf )
39 {
40  return this->SharedQueue::try_send( add_pid( buf ) );
41 }
42 
43 bool IdentifiedSharedQueue::send( const std::string& buf )
44 {
45  return this->SharedQueue::send( add_pid( buf ) );
46 }
47 
48 inline std::string get_pid( const std::string& buf, pid_t &pid )
49 {
50  std::istringstream s( buf );
51  long id = -1;
52  s >> id;
53  pid = (pid_t)id;
54  std::string::size_type pos = s.tellg();
55  if ( (pos+1) <= buf.size() )
56  return buf.substr( pos+1 );
57  return "";
58 }
59 
60 
62 {
63  pid_t pid;
64  return try_receive( pid );
65 }
66 
68 {
69  const std::string& buf = this->SharedQueue::try_receive();
70  return get_pid( buf, id );
71 }
72 
74 {
75  pid_t pid;
76  return receive( pid );
77 }
78 
80 {
81  const std::string& buf = this->SharedQueue::receive();
82  return get_pid( buf, id );
83 }
84 
85 } // namespace AthenaInterprocess
pid_t
int32_t pid_t
Definition: FPGATrackSimTypes.h:19
AthenaInterprocess::IdentifiedSharedQueue::try_send
virtual bool try_send(const std::string &)
Definition: IdentifiedSharedQueue.cxx:38
AthenaInterprocess
Definition: FdsRegistry.h:11
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
AthenaInterprocess::add_pid
std::string add_pid(const std::string &buf)
Definition: IdentifiedSharedQueue.cxx:31
AthenaInterprocess::IdentifiedSharedQueue::IdentifiedSharedQueue
IdentifiedSharedQueue()
Definition: IdentifiedSharedQueue.cxx:19
IdentifiedSharedQueue.h
AthenaInterprocess::SharedQueue::try_receive
virtual std::string try_receive()
Definition: SharedQueue.cxx:140
AthenaInterprocess::IdentifiedSharedQueue::receive
virtual std::string receive()
Definition: IdentifiedSharedQueue.cxx:73
AthenaInterprocess::IdentifiedSharedQueue::try_receive
virtual std::string try_receive()
Definition: IdentifiedSharedQueue.cxx:61
AthenaInterprocess::SharedQueue::send
virtual bool send(const std::string &)
Definition: SharedQueue.cxx:107
AthenaInterprocess::SharedQueue
Definition: SharedQueue.h:21
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
AthenaInterprocess::get_pid
std::string get_pid(const std::string &buf, pid_t &pid)
Definition: IdentifiedSharedQueue.cxx:48
AthenaInterprocess::IdentifiedSharedQueue::send
virtual bool send(const std::string &)
Definition: IdentifiedSharedQueue.cxx:43
AthenaInterprocess::SharedQueue::try_send
virtual bool try_send(const std::string &)
Definition: SharedQueue.cxx:102
boost::interprocess
Definition: AthenaSharedMemoryTool.h:24
AthenaInterprocess::SharedQueue::receive
virtual std::string receive()
Definition: SharedQueue.cxx:145