ATLAS Offline Software
JiveXMLServer.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef JIVEXML_JIVEXMLSERVER_H
6 #define JIVEXML_JIVEXMLSERVER_H
7 
18 #include <vector>
19 #include <string>
20 
21 //athena includes
22 #include <GaudiKernel/IMessageSvc.h>
23 #include <GaudiKernel/StatusCode.h>
25 
26 //JiveXML includes
27 #include <JiveXML/IServer.h>
28 #include <JiveXML/EventStream.h>
29 
30 //tdaq includes
31 #include <owl/semaphore.h>
32 
33 namespace JiveXML {
34 
35  //Forward declarations
36  class ThreadCollection;
37 
38  class JiveXMLServer: virtual public IServer {
39 
40  public:
41  //Constructor with port number
42  JiveXMLServer( int port = 0 );
43 
44  //Destructor
45  virtual ~JiveXMLServer();
46 
50  virtual StatusCode UpdateEventForStream( const EventStreamID& evtStreamID, const std::string & event) override;
52 
56  virtual std::vector<std::string> GetStreamNames() const override;
58  virtual const EventStreamID GetEventStreamID(const std::string& streamName) const override;
60  virtual const std::string GetEvent( const EventStreamID& evtStreamID ) const override;
62  virtual int GetState() const override;
64 
66 
68  virtual void Message( const MSG::Level level, const std::string& msg ) const override;
70  virtual MSG::Level LogLevel() const override;
72 
80  virtual bool GetRunServerFlag () const override { return m_runServerThread; };
82  virtual void ServerThreadStopped() override;
84  void Wait();
86 
87 
88  private:
89 
90  //Signal handler must be static function
91  static void signalHandler (int signum);
92 
93  //Static semaphore used to suspend main thread while server thread is
94  //running. The semaphore will reach its post-condition either by
95  // a) receiving a signal through the signal handler
96  // b) the ServerThreadStopped callback being called
97  inline static OWLSemaphore lock ATLAS_THREAD_SAFE;
98 
99  //Store the received signal in a static member
100  inline static std::atomic<int> m_receivedSignal{0};
101 
102  //Port number property - defaults to zero in which case
103  //it is dynamically assigned
105 
106  //A map of the streams and their current events
108 
109  //A mutex (mutual exclusive) lock for the data map
110  mutable pthread_mutex_t m_accessLock ATLAS_THREAD_SAFE;
111 
112  //A handle to the server thread
114 
115  //Once this flag is set to false, the thread will stop after handling its
116  //last request
118  };
119 }
120 
121 #endif
JiveXML::JiveXMLServer::signalHandler
static void signalHandler(int signum)
When the signal handler is called, switch the lock to the post condition.
Definition: JiveXMLServer.cxx:169
JiveXML::JiveXMLServer::m_eventStreamMap
EventStreamMap m_eventStreamMap
Definition: JiveXMLServer.h:107
JiveXML::JiveXMLServer::GetEvent
virtual const std::string GetEvent(const EventStreamID &evtStreamID) const override
get the current event for a particular stream
Definition: JiveXMLServer.cxx:357
JiveXML::JiveXMLServer::portNumber
int portNumber
Definition: JiveXMLServer.h:104
JiveXML::JiveXMLServer::GetState
virtual int GetState() const override
get the Status of the application
Definition: JiveXMLServer.cxx:279
JiveXML::EventStreamMap
std::map< const EventStreamID, const std::string > EventStreamMap
Definition: EventStream.h:87
JiveXML::JiveXMLServer::StopServingThread
StatusCode StopServingThread()
Stop the serving thread.
Definition: JiveXMLServer.cxx:107
JiveXML::JiveXMLServer::GetStreamNames
virtual std::vector< std::string > GetStreamNames() const override
get the names of all the streams
Definition: JiveXMLServer.cxx:290
JiveXML::JiveXMLServer::Message
virtual void Message(const MSG::Level level, const std::string &msg) const override
This function is exposed to allow using ERS messaging service from other threads.
Definition: JiveXMLServer.cxx:389
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
JiveXML::JiveXMLServer::m_runServerThread
bool m_runServerThread
Definition: JiveXMLServer.h:117
JiveXML::JiveXMLServer::JiveXMLServer
JiveXMLServer(int port=0)
Constructor.
Definition: JiveXMLServer.cxx:41
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
JiveXML::JiveXMLServer::GetRunServerFlag
virtual bool GetRunServerFlag() const override
The server thread will stop once this flag is set to false.
Definition: JiveXMLServer.h:80
JiveXML::JiveXMLServer::LogLevel
virtual MSG::Level LogLevel() const override
Get the logging level.
Definition: JiveXMLServer.cxx:401
JiveXML::JiveXMLServer::ATLAS_THREAD_SAFE
pthread_mutex_t m_accessLock ATLAS_THREAD_SAFE
Definition: JiveXMLServer.h:110
JiveXML::JiveXMLServer
Definition: JiveXMLServer.h:38
JiveXML::EventStreamID
For the client-server communication, each event is uniquely identified by the run number,...
Definition: EventStream.h:19
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:22
JiveXML::JiveXMLServer::GetEventStreamID
virtual const EventStreamID GetEventStreamID(const std::string &streamName) const override
get the current EventStreamID for a particular stream
Definition: JiveXMLServer.cxx:325
IServer.h
JiveXML::IServer
Pure abstract interface for all full server implementations.
Definition: IServer.h:22
AthenaPoolExample_Copy.streamName
string streamName
Definition: AthenaPoolExample_Copy.py:39
JiveXML::JiveXMLServer::m_receivedSignal
static std::atomic< int > m_receivedSignal
Definition: JiveXMLServer.h:100
JiveXML::JiveXMLServer::StartServingThread
StatusCode StartServingThread()
Start the serving thread.
Definition: JiveXMLServer.cxx:70
JiveXML::JiveXMLServer::m_ServerThreadHandle
pthread_t m_ServerThreadHandle
Definition: JiveXMLServer.h:113
JiveXML::JiveXMLServer::ATLAS_THREAD_SAFE
static OWLSemaphore lock ATLAS_THREAD_SAFE
Definition: JiveXMLServer.h:97
JiveXML::JiveXMLServer::ServerThreadStopped
virtual void ServerThreadStopped() override
Callback whenever the server thread is stopped.
Definition: JiveXMLServer.cxx:192
JiveXML::JiveXMLServer::Wait
void Wait()
Wait for the server finish.
Definition: JiveXMLServer.cxx:181
JiveXML::JiveXMLServer::~JiveXMLServer
virtual ~JiveXMLServer()
Destructor.
Definition: JiveXMLServer.cxx:58
checker_macros.h
Define macros for attributes used to control the static checker.
EventStream.h
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
JiveXML::JiveXMLServer::UpdateEventForStream
virtual StatusCode UpdateEventForStream(const EventStreamID &evtStreamID, const std::string &event) override
Put this event as new current event for stream given by name.
Definition: JiveXMLServer.cxx:201