19#define ERS_WARNING( message ) \
21 ERS_REPORT_IMPL( ers::warning, ers::Message, message, ); \
24#define ERS_ERROR( message ) \
26 ERS_REPORT_IMPL( ers::error, ers::Message, message, ); \
30 std::string fmterror(
int code) {
32 return std::string(strerror_r(code, buf,
sizeof(buf)));
72 ERS_DEBUG(MSG::VERBOSE,
"StartServingThread()");
76 int retVal = pthread_mutex_init(&m_accessLock,NULL);
78 ERS_WARNING(
"Unable to initialize access lock while starting server: " << fmterror(retVal));
79 return StatusCode::FAILURE;
94 return StatusCode::FAILURE;
97 return StatusCode::SUCCESS;
109 ERS_DEBUG(MSG::VERBOSE,
"StopServingThread()");
120 ERS_ERROR(
"Unable to create shutdown client for local server");
121 return StatusCode::FAILURE;
130 struct timeval timeout; timeout.tv_sec = 1; timeout.tv_usec = 0;
133# pragma GCC diagnostic push
134# pragma GCC diagnostic ignored "-Wcast-function-type"
136#if defined(__clang__) && __clang_major__ >= 19
137# pragma clang diagnostic push
138# pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
140 clnt_call(client, NULLPROC, (xdrproc_t)xdr_void, NULL, (xdrproc_t)xdr_void, NULL, timeout);
141#if defined(__clang__) && __clang_major__ >= 19
142# pragma clang diagnostic pop
145# pragma GCC diagnostic pop
151 ERS_INFO(
"Waiting for server thread to terminate ...");
153 ERS_INFO(
" ... finished server thread");
158 unsigned long NRequests = *(
unsigned long*)ret;
159 ERS_DEBUG(MSG::DEBUG,
"Server thread stopped after handling " << NRequests <<
" requests");
164 int retVal = pthread_mutex_destroy(&m_accessLock);
166 ERS_WARNING(
"Unable to destroy access lock after stopping server: " << fmterror(retVal));
167 return StatusCode::FAILURE;
170 return StatusCode::SUCCESS;
192 ERS_INFO(
"Reached post-condition after received signal " <<
m_receivedSignal );
210 ERS_DEBUG(MSG::VERBOSE,
"UpdateEventForStream");
214 ERS_ERROR(
"Invalid event stream identifier - cannot add event");
215 return StatusCode::FAILURE;
220 ERS_ERROR(
"Reached max. allowed number of streams " <<
NSTREAMMAX <<
" - cannot add event");
221 return StatusCode::FAILURE;
226 ERS_ERROR(
"Event is larger than allowed max. of " <<
NBYTESMAX <<
" bytes - cannot add event");
227 return StatusCode::FAILURE;
235 struct timespec timeout = { 30, 0 };
237 int retVal = pthread_mutex_timedlock(&m_accessLock, &timeout);
239 ERS_ERROR(
"Unable to obtain access lock to update event: " << fmterror(retVal));
240 return StatusCode::FAILURE;
259 }
catch (
const std::exception& e ) {
260 ERS_ERROR(
"Exception caught while updating event for stream "
261 << evtStreamID.
StreamName() <<
": " << e.what());
263 pthread_mutex_unlock(&m_accessLock);
265 return StatusCode::FAILURE;
269 retVal = pthread_mutex_unlock(&m_accessLock);
271 ERS_ERROR(
"Unable to release access lock after updating event: " << fmterror(retVal));
272 return StatusCode::FAILURE;
275 ERS_DEBUG(MSG::DEBUG,
"Updated stream " << evtStreamID.
StreamName()
277 <<
" from run Nr. " << evtStreamID.
RunNumber());
279 return StatusCode::SUCCESS;
300 std::vector<std::string> StreamNames;
303 int retVal = pthread_mutex_lock(&m_accessLock);
305 ERS_ERROR(
"Unable to obtain access lock to get stream names: " << fmterror(retVal));
321 retVal = pthread_mutex_unlock(&m_accessLock);
323 ERS_ERROR(
"Unable to release access lock after getting stream names: " << fmterror(retVal));
335 int retVal = pthread_mutex_lock(&m_accessLock);
337 ERS_ERROR(
"Unable to obtain access lock to get stream ID: " << fmterror(retVal));
353 retVal = pthread_mutex_unlock(&m_accessLock);
355 ERS_ERROR(
"Unable to release access lock after getting stream ID: " << fmterror(retVal));
367 int retVal = pthread_mutex_lock(&m_accessLock);
369 ERS_ERROR(
"Unable to obtain access lock to get event: " << fmterror(retVal));
370 return std::string(
"");
382 event = std::string((*MapItr).second);
386 retVal = pthread_mutex_unlock(&m_accessLock);
388 ERS_ERROR(
"Unable to release access lock after getting stream event: " << fmterror(retVal));
398 if (level <= MSG::DEBUG) ERS_REPORT_IMPL( ers::debug, ers::Message,
msg, level);
399 if (level == MSG::INFO) ERS_REPORT_IMPL( ers::info, ers::Message,
msg, );
400 if (level == MSG::WARNING) ERS_REPORT_IMPL( ers::warning, ers::Message,
msg, );
401 if (level == MSG::ERROR) ERS_REPORT_IMPL( ers::error, ers::Message,
msg, );
402 if (level >= MSG::FATAL) ERS_REPORT_IMPL( ers::fatal, ers::Message,
msg, );
#define ERS_WARNING(message)
#define ERS_ERROR(message)
For the client-server communication, each event is uniquely identified by the run number,...
unsigned int RunNumber() const
unsigned long EventNumber() const
const std::string & StreamName() const
virtual StatusCode UpdateEventForStream(const EventStreamID &evtStreamID, const std::string &event) override
Put this event as new current event for stream given by name.
virtual ~JiveXMLServer()
Destructor.
virtual std::vector< std::string > GetStreamNames() const override
get the names of all the streams
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.
virtual MSG::Level LogLevel() const override
Get the logging level.
virtual void ServerThreadStopped() override
Callback whenever the server thread is stopped.
static std::atomic< int > m_receivedSignal
static void signalHandler(int signum)
When the signal handler is called, switch the lock to the post condition.
StatusCode StartServingThread()
Start the serving thread.
void Wait()
Wait for the server finish.
EventStreamMap m_eventStreamMap
StatusCode StopServingThread()
Stop the serving thread.
pthread_t m_ServerThreadHandle
JiveXMLServer(int port=0)
Constructor.
virtual int GetState() const override
get the Status of the application
virtual const std::string GetEvent(const EventStreamID &evtStreamID) const override
get the current event for a particular stream
virtual const EventStreamID GetEventStreamID(const std::string &streamName) const override
get the current EventStreamID for a particular stream
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
const unsigned int NBYTESMAX
std::pair< const EventStreamID, const std::string > EventStreamPair
A map that stores events according to their EventStreamID Due to the way EventStreamID is build,...
const unsigned int NSTREAMMAX
struct ServerThreadArguments_t ServerThreadArguments
Arguments handed over fromt the main (Athena) thread to the server thread.
void * ONCRPCServerThread(void *args)
This is the actual server thread, which takes above arguments.