DDSClient Class Reference

#include <DDSClient.h>

List of all members.

Public Member Functions

 DDSClient (const char *serverhost, UInt_t serverport=0, DDS::EMessageType initmsg=DDS::kData, DDS::EClientType type=DDS::kUnknownClientType, std::string clientname="")
virtual ~DDSClient ()
DDS::EMessageType GetStatus () const
const DDSPSStatusGetPSStatus () const
const DDSClientIdGetClientId () const
DDSSubscriptionGetSubscription () const
bool IsValid () const
std::ostream & Print (std::ostream &ms) const
DDS::EMessageType GoToFile (std::string filename, std::string &returnedfilename)
DDS::EMessageType GoToNextFile (std::string &returnedfilename)
DDS::EMessageType Next (MomNavigator *&mom, UInt_t waittime=120, UInt_t advanceby=1)
DDS::EMessageType Shutdown ()
DDS::EMessageType Subscribe ()

Private Member Functions

DDS::EMessageType SendMessage ()

Private Attributes

DDS::EMessageType fStatus
TSocket * fTSocket
DDSSubscriptionfSubscription
TMessage * fMessageIn
TMessage fMessageOut
TInetAddress fClientAddress
TInetAddress fServerAddress
DDSClientIdfClientId
DDSPSStatusfPSStatus

Detailed Description

Definition at line 29 of file DDSClient.h.


Constructor & Destructor Documentation

DDSClient::DDSClient ( const char *  serverhost,
UInt_t  serverport = 0,
DDS::EMessageType  initmsg = DDS::kData,
DDS::EClientType  type = DDS::kUnknownClientType,
std::string  clientname = "" 
)
DDSClient::~DDSClient (  )  [virtual]

Definition at line 155 of file DDSClient.cxx.

References IsValid(), and Shutdown().

00155                       {
00156   // Purpose: Destructor.
00157   //
00158   // Argument: n/a.
00159   //
00160   // Return: n/a.
00161   //
00162   // Contact: S. Kasahara
00163   //
00164 
00165   if ( IsValid() ) Shutdown();
00166   if ( fSubscription ) delete fSubscription; fSubscription = 0;
00167   if ( fMessageIn ) delete fMessageIn; fMessageIn = 0;
00168   if ( fClientId ) delete fClientId; fClientId = 0;
00169   if ( fPSStatus ) delete fPSStatus; fPSStatus = 0;
00170   
00171 }


Member Function Documentation

const DDSClientId* DDSClient::GetClientId (  )  const [inline]

Definition at line 44 of file DDSClient.h.

References fClientId.

00044 { return fClientId; }

const DDSPSStatus* DDSClient::GetPSStatus (  )  const [inline]

Definition at line 43 of file DDSClient.h.

References fPSStatus.

Referenced by main().

00043 { return fPSStatus; }

DDS::EMessageType DDSClient::GetStatus (  )  const [inline]

Definition at line 42 of file DDSClient.h.

References fStatus.

Referenced by main().

00042 { return fStatus; }

DDSSubscription* DDSClient::GetSubscription (  )  const [inline]

Definition at line 45 of file DDSClient.h.

References fSubscription.

Referenced by ReadDispatcherModule::ConnectToServer(), and main().

00045 { return fSubscription; }

DDS::EMessageType DDSClient::GoToFile ( std::string  filename,
std::string &  returnedfilename 
)

Definition at line 173 of file DDSClient.cxx.

References fMessageOut, IsValid(), DDS::kGoToFile, DDS::kOk, DDS::kSocketError, Msg::kWarning, MSG, and SendMessage().

Referenced by IoDDSStreamItr::GoToFile(), and GoToNextFile().

00174                                                                    {
00175   // 
00176   // Purpose: Advance to serving data from file filename.
00177   //
00178   // Arguments:filename  filename of interest, e.g. F00001782_0000.mdaq.root.
00179   //                     Specifying a relative path means that the path
00180   //                     will be assumed relative to the data source
00181   //                     directory defined on the server.
00182   //                     filename may be a symbolic link file, e.g.
00183   //                     'currentfile' will advance to the file pointed
00184   //                     to by 'currentfile' in the data source directory.
00185   //
00186   //           returnedfilename  filename actually advanced to on the server 
00187   //                             side.
00188   //
00189   // Return: DDS::kOk if returnedfilename is not empty, else errorcode.
00190   //
00191   // Contact: S. Kasahara
00192   //
00193   // Notes:  If file is not found, the server will be set to serve
00194   //         data from the first file alphanumerically beyond the requested
00195   //         filename.
00196   //         Special arguments: "next" (advance to next file)
00197   //
00198 
00199   DDS::EMessageType msgrc;  // return status of service request
00200   char newfilename[512];
00201 
00202   if ( this -> IsValid() ) {
00203     // reset message buffer and tell it type of msg
00204     fMessageOut.Reset(DDS::kGoToFile | kMESS_ACK);
00205     fMessageOut << filename.c_str();  // load filename into message buffer
00206 
00207     // Send fMessageOut to childserver
00208     msgrc = SendMessage();
00209     if ( msgrc == DDS::kOk ) {
00210       // fMessageIn should contain newfilename string
00211       (*fMessageIn) >> newfilename;
00212     }
00213   }
00214   else {
00215     MSG("DDS",Msg::kWarning) 
00216     << "GoToFile requested with invalid socket connection." << endl;
00217     msgrc = DDS::kSocketError; 
00218   }
00219   returnedfilename = newfilename;
00220   return msgrc;
00221 
00222 }

DDS::EMessageType DDSClient::GoToNextFile ( std::string &  returnedfilename  ) 

Definition at line 224 of file DDSClient.cxx.

References GoToFile().

Referenced by IoDDSStreamItr::NextFile().

00224                                                                    {
00225   // 
00226   // Purpose: Advance to serving data from next file in directory.
00227   //          This request only makes sense when user has subscribed in
00228   //          DDS::kAll mode.
00229   //
00230   // Arguments: returnedfilename.  Name of file actually advanced to.
00231   //
00232   // Return: DDS::kOk if returnedfilename is not empty, else errorcode.
00233   //
00234   // Contact: S. Kasahara
00235   //
00236 
00237   return this -> GoToFile("next",returnedfilename);
00238 
00239 }

bool DDSClient::IsValid (  )  const [inline]

Definition at line 46 of file DDSClient.h.

References fTSocket.

Referenced by GoToFile(), IoDDSStreamItr::InitDDSClient(), Next(), Print(), Shutdown(), Subscribe(), and ~DDSClient().

00046 { return (fTSocket != (TSocket*)0) ? true : false; }

DDS::EMessageType DDSClient::Next ( MomNavigator *&  mom,
UInt_t  waittime = 120,
UInt_t  advanceby = 1 
)

Definition at line 241 of file DDSClient.cxx.

References fMessageOut, Registry::GetCharString(), Registry::GetInt(), RecMinos::GetTempTags(), IsValid(), DDS::kNext, DDS::kOk, DDS::kSocketError, Msg::kWarning, MSG, SendMessage(), and Registry::Set().

Referenced by IoDDSStreamItr::Increment(), ReadDispatcherModule::IsNewEventReady(), and IoDDSStreamItr::LoadRecords().

00242                                                     {
00243   // 
00244   // Purpose: Request and receive next available entry satisfying client's
00245   //          subscription from child server.
00246   //
00247   // Arguments:mom       pointer to MomNavigator object to be filled with
00248   //                     retrieved MomNavigator from dispatcher server.
00249   //                     See Notes. 
00250   //           waittime  time(sec) that client wishes to wait for next 
00251   //                     available entry satisfying subscription before 
00252   //                     timing out (default = 120).
00253   //           advanceby number of record sets to advance by through 
00254   //                     stream(s) (default = 1).
00255   //
00256   // Return: DDS::EMessageType  return status of service request.
00257   //
00258   // Contact: S. Kasahara
00259   //
00260   // Notes:  For historic reasons, the user can specify the input 
00261   //         MomNavigator* mom pointer in one of two ways:
00262   //         1)mom == 0.  In this case, a new MomNavigator is created and mom
00263   //                      is set to point to it.  
00264   //         2)mom == a pointer to an existing MomNavigator object.  In this
00265   //                  case, objects retrieved by the dispatcher are added to
00266   //                  the existing mom object.
00267   //         In both cases, the user owns and must delete the MomNavigator
00268   //         object pointed to by mom.
00269   //
00270 
00271   DDS::EMessageType msgrc;  // return status of service request
00272   // Local copy of Mom used to receive collection of objects from childserver
00273   MomNavigator* localMom = 0;  
00274 
00275   if ( IsValid() ) {
00276     // reset message buffer and tell it type of msg
00277     fMessageOut.Reset(DDS::kNext | kMESS_ACK); 
00278     fMessageOut << waittime;  // load requested waittime into message buffer
00279     fMessageOut << advanceby; // load requested advanceby interval
00280     // Send fMessageOut to childserver
00281     msgrc = SendMessage();
00282     if ( msgrc == DDS::kOk ) {
00283       // fMessageIn should contain object of type MomNavigator
00284       localMom = dynamic_cast<MomNavigator*>
00285                  (fMessageIn -> ReadObject(fMessageIn->GetClass()));
00286       if (!localMom) {
00287         MSG("DDS",Msg::kWarning) 
00288         << "Next failed to receive expected MomNavigator object." << endl;
00289       }
00290       else {
00291         // if user hasn't supplied a mom pointer, initialize one here
00292         if (!mom) mom = new MomNavigator(); // this is dumb, but historic
00293         // Loop over Mom fragments to repack fTempTags object in record
00294         // that otherwise wouldn't survive i/o.  This is ugly.
00295         // Add received records to users Mom
00296         TObjArray* objArray =const_cast<TObjArray*>
00297                                (localMom -> GetFragmentArray());
00298         Int_t nrecord = objArray -> GetEntriesFast();
00299         for ( Int_t irec=0; irec < nrecord/2; irec++ ) {
00300           //record is removed from localMom to pass to usr's mom for ownership 
00301           RecMinos* record = dynamic_cast<RecMinos*>(objArray->RemoveAt(irec));
00302           Registry* temptags=dynamic_cast<Registry*>
00303                                (objArray->At(irec+nrecord/2));
00304           record->GetTempTags().Set("stream",temptags->GetCharString("stream"));
00305           record->GetTempTags().Set("tree",temptags->GetCharString("tree"));
00306           record->GetTempTags().Set("file",temptags->GetCharString("file"));
00307           record->GetTempTags().Set("index",temptags->GetInt("index"));
00308           record->GetTempTags().SetName(temptags->GetName());
00309           mom -> AdoptFragment(record); // new owner of record
00310         }
00311         delete localMom; localMom=0; // clears array and deletes temptags
00312       }
00313     } 
00314   }
00315   else {
00316     MSG("DDS",Msg::kWarning) 
00317     << "Next requested with invalid socket connection." << endl;
00318     msgrc = DDS::kSocketError; 
00319   }
00320 
00321   return msgrc;
00322 
00323 }

std::ostream & DDSClient::Print ( std::ostream &  ms  )  const

Definition at line 325 of file DDSClient.cxx.

References fClientAddress, fServerAddress, and IsValid().

Referenced by operator<<().

00325                                                  {
00326   // Purpose: Print DDSClient status on std::ostream.
00327   //
00328   // Argument: ms  std::ostream to print on.
00329   //
00330   // Return: std::ostream reference.
00331   //
00332   // Contact: S. Kasahara
00333   //
00334 
00335   if ( IsValid() ) {
00336     ms << "Client socket connected from local address:" << endl;
00337     // Print the local host name, address, and port number
00338     ms << fClientAddress.GetHostName() << "/"<< fClientAddress.GetHostAddress()
00339        << "(port " << fClientAddress.GetPort() << ")." << endl;
00340     ms << "to a child server at remote address:" << endl;
00341     // Print the child server's host name, address, and port number
00342     ms << fServerAddress.GetHostName() << "/"<< fServerAddress.GetHostAddress()
00343        << "(port " << fServerAddress.GetPort() << ")." << endl;
00344   }
00345   else {
00346     ms << "Client to child server socket is not connected." << endl;
00347   }
00348 
00349   return ms;
00350 
00351 }

DDS::EMessageType DDSClient::SendMessage (  )  [private]

Definition at line 353 of file DDSClient.cxx.

References fMessageOut, DDS::kSocketError, Msg::kWarning, and MSG.

Referenced by GoToFile(), Next(), Shutdown(), and Subscribe().

00353                                        {
00354   //
00355   // Purpose: Send message previously loaded in fMessageOut to child server.
00356   //
00357   // Argument: none.
00358   //
00359   // Return: msgrc of type DDS::EMessageType received from server. Complete
00360   //         message received from server is stored in fMessageIn.
00361   //
00362   // Contact: S. Kasahara
00363   //
00364 
00365   DDS::EMessageType msgrc = DDS::kSocketError;  // default return code
00366   // Delete previously retrieved message if any
00367   if (fMessageIn) delete fMessageIn; fMessageIn = 0;
00368 
00369   // Send requested message to server
00370   Int_t rc = fTSocket -> Send(fMessageOut);
00371   if (rc < 0) {
00372     MSG("DDS",Msg::kWarning) << "\nReceived socket error code "
00373                  << rc << " in send of message to server." << endl; 
00374     //  if ( errno == EPIPE ) {
00375       // Broken pipe between child server and client is fatal
00376       MSG("DDS",Msg::kWarning) 
00377       << "\nSocket will be shutdown." << endl;
00378       if ( fTSocket ) delete fTSocket; fTSocket = 0;
00379     // }
00380   }
00381   else {
00382     // Wait for return message from user
00383     Int_t rc = fTSocket -> Recv(fMessageIn);
00384     if (rc < 0) {
00385       MSG("DDS",Msg::kWarning) << "\nReceived socket error code "
00386                  << rc << " in send of message to server." << endl; 
00387       //if ( errno == EPIPE ) {
00388         // Broken pipe between child server and client is fatal
00389         MSG("DDS",Msg::kWarning) 
00390         << "\nSocket will be shutdown." << endl;
00391         if ( fTSocket ) delete fTSocket; fTSocket = 0;
00392       // }
00393     }
00394     else {
00395       if ( ! fMessageIn ) {
00396         MSG("DDS",Msg::kWarning) 
00397           << "Received empty fMessageIn from fTSocket->Recv()"
00398           << endl;
00399       }
00400       else 
00401         msgrc = static_cast< DDS::EMessageType > (fMessageIn -> What());
00402     }
00403   }
00404 
00405   return msgrc;
00406 
00407 }

DDS::EMessageType DDSClient::Shutdown (  ) 

Definition at line 410 of file DDSClient.cxx.

References fMessageOut, IsValid(), DDS::kShutdown, DDS::kSocketError, Msg::kWarning, MSG, and SendMessage().

Referenced by ReadDispatcherModule::IsNewEventReady(), and ~DDSClient().

00410                                     {
00411   //
00412   // Purpose: Send child server the shutdown message.
00413   //
00414   // Argument: none.
00415   //
00416   // Return: DDS::EMessageType  return status of service request
00417   //
00418   // Contact: S. Kasahara
00419   //
00420 
00421   DDS::EMessageType msgrc;  // return status of service request
00422 
00423   if ( IsValid() ) {
00424     // reset message buffer & tell it msg type
00425     fMessageOut.Reset(DDS::kShutdown | kMESS_ACK); 
00426     // Send fMessageOut to childserver
00427     msgrc = SendMessage();
00428   }
00429   else {
00430     MSG("DDS",Msg::kWarning) 
00431     << "Shutdown requested with invalid socket connection." << endl;
00432     msgrc = DDS::kSocketError; 
00433   }
00434 
00435   if (fTSocket) delete fTSocket; fTSocket = 0;
00436 
00437   return msgrc;
00438 
00439 }

DDS::EMessageType DDSClient::Subscribe (  ) 

Definition at line 441 of file DDSClient.cxx.

References fMessageOut, IsValid(), DDS::kSocketError, DDS::kSubscribe, Msg::kWarning, MSG, and SendMessage().

Referenced by ReadDispatcherModule::ConnectToServer(), main(), and IoDDSStreamItr::Subscribe().

00441                                      {
00442   //
00443   // Purpose: Submit subscription object to the dispatcher child server.
00444   //
00445   // Argument: none.
00446   //
00447   // Return: DDS::EMessageType  return status of service request
00448   //
00449   // Contact: S. Kasahara
00450   //
00451   // Notes: The subscription object of type DDSSubscription can be retrieved 
00452   //        and modified by the client via the DDSClient::GetSubscription() 
00453   //        method.  There is no limit to the number of times that the
00454   //        subscription object can be modified and resubmitted to the server.
00455   //
00456 
00457   DDS::EMessageType msgrc;  // return status of service request
00458 
00459   if ( IsValid() ) {
00460     // reset buffer & tell it msg type
00461     fMessageOut.Reset(DDS::kSubscribe | kMESS_ACK); 
00462     fMessageOut.WriteObject(fSubscription); 
00463     msgrc = SendMessage(); // Submit subscription to server
00464   }
00465   else {
00466     MSG("DDS",Msg::kWarning) 
00467     << "Subscribe requested with invalid socket connection." << endl;
00468     msgrc = DDS::kSocketError; 
00469   }
00470 
00471   return msgrc;
00472 
00473 }


Member Data Documentation

TInetAddress DDSClient::fClientAddress [private]

Definition at line 68 of file DDSClient.h.

Referenced by Print().

Definition at line 70 of file DDSClient.h.

Referenced by GetClientId().

TMessage* DDSClient::fMessageIn [private]

Definition at line 66 of file DDSClient.h.

TMessage DDSClient::fMessageOut [private]

Definition at line 67 of file DDSClient.h.

Referenced by GoToFile(), Next(), SendMessage(), Shutdown(), and Subscribe().

Definition at line 71 of file DDSClient.h.

Referenced by GetPSStatus().

TInetAddress DDSClient::fServerAddress [private]

Definition at line 69 of file DDSClient.h.

Referenced by Print().

Definition at line 63 of file DDSClient.h.

Referenced by GetStatus().

Definition at line 65 of file DDSClient.h.

Referenced by GetSubscription().

TSocket* DDSClient::fTSocket [private]

Definition at line 64 of file DDSClient.h.

Referenced by IsValid().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1