ATLAS Offline Software
Loading...
Searching...
No Matches
JiveXML::ExternalONCRPCServerSvc Class Reference

This athena service will provide a link to an external ONCRPC server, e.g running as standalone application or in another athena application. More...

#include <ExternalONCRPCServerSvc.h>

Inheritance diagram for JiveXML::ExternalONCRPCServerSvc:
Collaboration diagram for JiveXML::ExternalONCRPCServerSvc:

Public Member Functions

 ExternalONCRPCServerSvc (const std::string &name, ISvcLocator *sl)
 Default constructor.
virtual ~ExternalONCRPCServerSvc ()
 Destructor.
virtual StatusCode initialize () override
 Gaudi default methods.
virtual StatusCode finalize () override
 Finalize - called once at the end.

Server methods

std::string m_hostName
double m_timeOut
CLIENT * m_client
virtual StatusCode UpdateEventForStream (const EventStreamID &evtStreamID, const std::string &event) override
 Put this event as new current event for stream given by name.
StatusCode GetClient ()
 Obtain a client handle by.
StatusCode ReleaseClient ()
 Destroy the private client handle.
struct timeval GetTimeout ()
 Convert timeout double in seconds to struct timeval.

Detailed Description

This athena service will provide a link to an external ONCRPC server, e.g running as standalone application or in another athena application.

It only provides means for streaming events to that server.

Definition at line 23 of file ExternalONCRPCServerSvc.h.

Constructor & Destructor Documentation

◆ ExternalONCRPCServerSvc()

JiveXML::ExternalONCRPCServerSvc::ExternalONCRPCServerSvc ( const std::string & name,
ISvcLocator * sl )

Default constructor.

Constructor.

Definition at line 16 of file ExternalONCRPCServerSvc.cxx.

16 :
17 base_class ( name, sl ),
18 m_client(NULL)
19 {
20 //declare properties
21 declareProperty("Hostname",m_hostName="localhost","The name of the host the external server is running on [ default: \"localhost\" ]");
22 declareProperty("Timeout",m_timeOut=10,"Timeout when calling the server in seconds [ default: 10 ]");
23 }

◆ ~ExternalONCRPCServerSvc()

JiveXML::ExternalONCRPCServerSvc::~ExternalONCRPCServerSvc ( )
virtual

Destructor.

Definition at line 28 of file ExternalONCRPCServerSvc.cxx.

28 {
29 ATH_MSG_VERBOSE( "Destructor() " );
30 }
#define ATH_MSG_VERBOSE(x)

Member Function Documentation

◆ finalize()

StatusCode JiveXML::ExternalONCRPCServerSvc::finalize ( )
overridevirtual

Finalize - called once at the end.

  • shut down server

Release the client

Definition at line 143 of file ExternalONCRPCServerSvc.cxx.

143 {
144
145 ATH_MSG_VERBOSE( "Finalize()" );
146
150 ReleaseClient().ignore();
151
152 return StatusCode::SUCCESS;
153 }
StatusCode ReleaseClient()
Destroy the private client handle.

◆ GetClient()

StatusCode JiveXML::ExternalONCRPCServerSvc::GetClient ( )
private

Obtain a client handle by.

  • creating a CLIENT object
  • pinging the server using NULLPROC

Definition at line 59 of file ExternalONCRPCServerSvc.cxx.

59 {
60
61 ATH_MSG_VERBOSE( "GetClient()" );
62
63 //Try to create client if not there yet
64#ifndef __APPLE__
65 if (!m_client) m_client = clnt_create(m_hostName.c_str(), ONCRPCSERVERPROG,ONCRPCSERVERVERS, "tcp");
66#else
67 char proto[] = "tcp";
68 if (!m_client) m_client = clnt_create((char*)m_hostName.c_str(), ONCRPCSERVERPROG,ONCRPCSERVERVERS, proto);
69#endif
70 //Fail if we still don't have a client
71 if (!m_client){
72 ATH_MSG_WARNING( "Unable to create client for server on host " << m_hostName << " using TCP/IP " );
73 return StatusCode::FAILURE;
74 }
75
76// xdr_void is defined inconsistently in xdr.h and gets a warning from gcc8.
77#if __GNUC__ >= 8
78# pragma GCC diagnostic push
79# pragma GCC diagnostic ignored "-Wcast-function-type"
80#endif
81#if defined(__clang__) && __clang_major__ >= 19
82# pragma clang diagnostic push
83# pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
84#endif
85 //Now try pinging the server
86 clnt_stat ret = clnt_call(m_client, NULLPROC, (xdrproc_t)xdr_void, NULL,
87 (xdrproc_t)xdr_void, NULL, GetTimeout());
88#if defined(__clang__) && __clang_major__ >= 19
89# pragma clang diagnostic pop
90#endif
91#if __GNUC__ >= 8
92# pragma GCC diagnostic pop
93#endif
94
95 //And check for the result
96 if (ret != RPC_SUCCESS){
97 ATH_MSG_WARNING( "Failed calling the server on host " << m_hostName << " : " << clnt_sperrno(ret) );
98 //Also destroy the client in this case - otherwise we might be stranded
99 //with an invalid client object
100 ReleaseClient().ignore();
101 //and return failure
102 return StatusCode::FAILURE;
103 }
104
105 //Be verbose on success
106 ATH_MSG_VERBOSE( "Successfully connected to server on host " << m_hostName );
107
108 return StatusCode::SUCCESS;
109 }
#define ATH_MSG_WARNING(x)
#define ONCRPCSERVERVERS
#define ONCRPCSERVERPROG
struct timeval GetTimeout()
Convert timeout double in seconds to struct timeval.

◆ GetTimeout()

struct timeval JiveXML::ExternalONCRPCServerSvc::GetTimeout ( )
private

Convert timeout double in seconds to struct timeval.

Definition at line 114 of file ExternalONCRPCServerSvc.cxx.

114 {
115 //Declare return value
116 struct timeval timeout = { 0, 0 };
117 //Catch for negatives
118 if (m_timeOut < 0) return timeout;
119 //Get seconds as integer part
120 timeout.tv_sec = static_cast<long>(m_timeOut);
121 //Get microseconds as fractional part
122 timeout.tv_usec = static_cast<long>((m_timeOut - timeout.tv_sec)*1e6);
123 //Finally return it
124 return timeout;
125 }

◆ initialize()

StatusCode JiveXML::ExternalONCRPCServerSvc::initialize ( )
overridevirtual

Gaudi default methods.

Initialize - called once in beginning.

  • create server

Try preemtivly creating a client right here - but ignore the result

Definition at line 36 of file ExternalONCRPCServerSvc.cxx.

36 {
37 ATH_MSG_VERBOSE( "Initialize()" );
38
39 //Initialize Service base
40 if (Service::initialize().isFailure()) return StatusCode::FAILURE;
41
42 //Initialize message stream level
43 msg().setLevel(outputLevel());
44 ATH_MSG_VERBOSE( "Output level is set to " << (int)msg().level() );
45
49 GetClient().ignore();
50
51 return StatusCode::SUCCESS;
52 }
StatusCode GetClient()
Obtain a client handle by.
MsgStream & msg
Definition testRead.cxx:32

◆ ReleaseClient()

StatusCode JiveXML::ExternalONCRPCServerSvc::ReleaseClient ( )
private

Destroy the private client handle.

Definition at line 130 of file ExternalONCRPCServerSvc.cxx.

130 {
131 //Destroy the client
132 if (m_client) clnt_destroy(m_client);
133 //And set pointer to NULL
134 m_client=NULL;
135 //For now always return success
136 return StatusCode::SUCCESS;
137 }

◆ UpdateEventForStream()

StatusCode JiveXML::ExternalONCRPCServerSvc::UpdateEventForStream ( const EventStreamID & evtStreamID,
const std::string & eventStr )
overridevirtual

Put this event as new current event for stream given by name.

Implementation of IServerSvc method.

Get one event and put it as the new event for the this stream, which is identified by EventStreamID

Definition at line 159 of file ExternalONCRPCServerSvc.cxx.

159 {
160
161 ATH_MSG_VERBOSE( "UpdateEventForStream()" );
162
163 //Check that the event stream id is valid
164 if (!evtStreamID.isValid()){
165 ATH_MSG_ERROR( "Invalid event stream identifier - cannot add event" );
166 return StatusCode::FAILURE;
167 }
168
169 //Now create an event C-struct that we can send to the server
170 //NOTE: the struct has to be properly initialized
171 Event event;
172 event.isAvailable = false ; event.isIdentical = false ; event.isCompressed = false ;
173 event.RunNumber = evtStreamID.RunNumber();
174 event.EventNumber=evtStreamID.EventNumber();
175 event.StreamName=strdup(evtStreamID.StreamName().c_str());
176 event.NBytes = strlen(eventStr.c_str())+1;
177 event.EventData = strdup(eventStr.c_str());
178
179 ATH_MSG_VERBOSE( "Created event structure for event " << event.EventNumber
180 << " from run " << event.RunNumber
181 << " to be put in stream " << event.StreamName
182 << " with " << event.NBytes << " bytes" );
183
184 //Try to get a client
185 if (GetClient().isFailure()) {
186 ATH_MSG_WARNING( "Failed obtaining a client for sever on host " << m_hostName );
187 ATH_MSG_WARNING( " while updating stream " << evtStreamID.StreamName()
188 << " with event " << evtStreamID.EventNumber()
189 << " from run " << evtStreamID.RunNumber() );
190 //delete char * strings malloc'ed by strdup
191 //are checkers enabled here?
192 auto *p1 = const_cast<char*>(event.StreamName);
193 auto *p2 = const_cast<char*>(event.EventData);
194 free(p1);
195 free(p2);
196 return StatusCode::FAILURE;
197 }
198
199 //Call the client to update the event
200 bool isSuccess = false;
201 clnt_stat ret = clnt_call(m_client, ONCRPC_SETEVENT_PROC, (xdrproc_t)xdr_event, (caddr_t)&event,
202 (xdrproc_t)xdr_bool,(caddr_t)&isSuccess, GetTimeout());
203
204 //And check for the result
205 if (ret != RPC_SUCCESS){
206 ATH_MSG_WARNING( "Failed calling the server on host " << m_hostName << " : " << clnt_sperrno(ret) );
207 ATH_MSG_WARNING( " while updating stream " << evtStreamID.StreamName()
208 << " with event " << evtStreamID.EventNumber()
209 << " from run " << evtStreamID.RunNumber() );
210 return StatusCode::FAILURE;
211 }
212
213 //Check if the server managed to update the event from return value
214 if (!isSuccess){
215 ATH_MSG_WARNING( "Server on host " << m_hostName << " returned failure " );
216 ATH_MSG_WARNING( " while updating stream " << evtStreamID.StreamName()
217 << " with event " << evtStreamID.EventNumber()
218 << " from run " << evtStreamID.RunNumber() );
219 return StatusCode::FAILURE;
220 }
221
222 //Be verbose on success
223 ATH_MSG_DEBUG( "Server on host " << m_hostName << " returned success " );
224 ATH_MSG_DEBUG( " while updating stream " << evtStreamID.StreamName()
225 << " with event " << evtStreamID.EventNumber()
226 << " from run " << evtStreamID.RunNumber() );
227
228 //Finally free the memory allocated for the event structure
229 xdr_free((xdrproc_t)xdr_event,(caddr_t)&event);
230
231 return StatusCode::SUCCESS;
232 }
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
#define ONCRPC_SETEVENT_PROC
struct Event_t Event
bool_t xdr_event(XDR *xdrsp, Event *event)
De-/Encoding of Event_t.

Member Data Documentation

◆ m_client

CLIENT* JiveXML::ExternalONCRPCServerSvc::m_client
private

Definition at line 59 of file ExternalONCRPCServerSvc.h.

◆ m_hostName

std::string JiveXML::ExternalONCRPCServerSvc::m_hostName
private

Definition at line 53 of file ExternalONCRPCServerSvc.h.

◆ m_timeOut

double JiveXML::ExternalONCRPCServerSvc::m_timeOut
private

Definition at line 56 of file ExternalONCRPCServerSvc.h.


The documentation for this class was generated from the following files: