Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DDSClientId.cxx

Go to the documentation of this file.
00001 
00002 //                                                                           //
00003 // DDSClientId                                                               //
00004 //                                                                           //
00005 // Package: DDS (Data Dispatcher System).                                    //
00006 //                                                                           //
00007 // S. Kasahara 10/2006                                                       //
00008 //                                                                           //
00009 // Purpose: Identification of DDS client.                                    //
00010 //                                                                           //
00012 #include <iostream>
00013 using namespace std;
00014 
00015 #include <TUnixSystem.h>
00016 
00017 #include "Dispatcher/DDSClientId.h"
00018 #include "MessageService/MsgService.h"
00019 
00020 ClassImp(DDSClientId)
00021 
00022 CVSID("$Id: DDSClientId.cxx,v 1.4 2007/08/24 05:23:48 schubert Exp $");
00023 
00024 ostream& operator << (ostream& os, const DDSClientId& cid) { 
00025                                                       return cid.Print(os); } 
00026 
00027 //_____________________________________________________________________________
00028 DDSClientId::DDSClientId(DDS::EClientType clienttype, string clientname) :
00029                  fClientType(clienttype), fClientName(clientname), 
00030                  fUserName(""), fRealName(""), fHostName(""),fStartTime(0), 
00031                  fChildPid(0) {
00032   // Default constructor 
00033 
00034   if ( fClientName.size() > 30 ) {
00035     fClientName.resize(30);
00036     MSG("DDS",Msg::kWarning) << "Client name exceeds 30 character limit."
00037                              << "\nTruncated to " 
00038                              << fClientName.c_str() << endl;
00039   }
00040   
00041   // Fill identifying user information using system functions
00042   UserGroup_t* usergrp = gSystem->GetUserInfo(gSystem->GetUid());
00043   if ( usergrp ) {
00044     fUserName = usergrp -> fUser; // username
00045     fRealName = usergrp -> fRealName; // user's full name
00046   }
00047   else {
00048     MSG("DDS",Msg::kWarning) 
00049        << "Failed to identify user info for client w/uid "
00050        << gSystem->GetUid() << "." << endl;
00051   }
00052   if ( usergrp ) delete usergrp; usergrp = 0; // has ownership
00053 
00054   // This system's host name and ip address
00055   fHostName = gSystem->HostName();
00056   
00057 }
00058 
00059 //_____________________________________________________________________________
00060 DDSClientId::~DDSClientId() {
00061   // Destructor.
00062 
00063 }
00064 
00065 //_____________________________________________________________________________
00066 void DDSClientId::Connected(int childpid) {
00067   // Purpose:  Invoked by DDSParentServer when client connection with
00068   //           child established.  Also sets start time of connection
00069   //           to Now.
00070   //           Protected method accessible only by DDSParentServer friend.
00071 
00072   fChildPid = childpid;
00073   fStartTime = VldTimeStamp(); // set to current time
00074 
00075 }
00076 
00077 //_____________________________________________________________________________
00078 std::ostream& DDSClientId::Print(std::ostream& os) const {
00079   // Purpose: Print DDSClientId status on std::ostream.
00080 
00081   VldTimeStamp currentTime;
00082   if ( fStartTime.GetSec() == 0 ) currentTime = VldTimeStamp(0);
00083 
00084   os << fUserName.c_str() 
00085      << " \"" << fRealName.c_str() << "\" "  
00086      << fHostName.c_str() << " Type: "
00087      << DDS::AsString(fClientType);
00088 
00089   if ( !fClientName.empty() ) os <<  "/" << fClientName.c_str();
00090 
00091   if ( fChildPid ) {
00092     os << "\n   CS pid " << fChildPid << " Start: " 
00093        << fStartTime.AsString("s") << " UpTime(sec): "
00094        << (currentTime-fStartTime).GetSec() << "." << endl;
00095   }
00096   else 
00097     os << endl;
00098 
00099 
00100   return os;
00101 
00102 }
00103 
00104 //_____________________________________________________________________________
00105 void DDSClientId::Print(Option_t* /* option */) const { 
00106   // Purpose: Print method in TObject::Print format
00107 
00108   Print(std::cout); 
00109 
00110 }
00111 
00112 
00113 
00114 
00115 
00116 
00117 

Generated on Mon Feb 15 11:06:36 2010 for loon by  doxygen 1.3.9.1