00001 00002 // // 00003 // DDSPSStatus // 00004 // // 00005 // Package: DDS (Data Dispatcher System). // 00006 // // 00007 // S. Kasahara 10/2006 // 00008 // // 00009 // Purpose: DDS Parent Server status. // 00010 // // 00011 // Parent Server Status. This class maintains a map of child process id's // 00012 // and their associated DDSClientId's. // 00013 // DDSParentServer has a DDSPSStatus data member. // 00014 // One use is that a "ddscomm -r" request for DDS // 00015 // parent server status report will have the parent // 00016 // server ship its DDSPSStatus object to the ddscomm // 00017 // client. // 00019 #include <iostream> 00020 using namespace std; 00021 00022 #include "Dispatcher/DDSPSStatus.h" 00023 #include "Dispatcher/DDSClientId.h" 00024 #include "MessageService/MsgService.h" 00025 00026 ClassImp(DDSPSStatus) 00027 00028 CVSID("$Id: DDSPSStatus.cxx,v 1.2 2006/11/01 02:44:56 schubert Exp $"); 00029 00030 ostream& operator << (ostream& os, const DDSPSStatus& pss) { 00031 return pss.Print(os); } 00032 00033 //_____________________________________________________________________________ 00034 DDSPSStatus::DDSPSStatus() : fClientMap() { 00035 // Default constructor 00036 00037 } 00038 00039 //_____________________________________________________________________________ 00040 DDSPSStatus::~DDSPSStatus() { 00041 // Destructor. 00042 00043 // Owns all DDSClientId's in map 00044 for ( ClientMapItr itr=fClientMap.begin(); itr != fClientMap.end(); itr++ ) { 00045 DDSClientId* clientid = itr->second; 00046 if ( clientid ) delete clientid; clientid = 0; 00047 } 00048 fClientMap.clear(); 00049 00050 } 00051 00052 //_____________________________________________________________________________ 00053 const DDSClientId* DDSPSStatus::GetClientId(int childpid) const { 00054 // Purpose: Retrieve ClientId corresponding child process id childpid from 00055 // map. If not in map, return null. 00056 00057 ClientMapConstItr citr = fClientMap.find(childpid); 00058 if ( citr == fClientMap.end() ) return 0; 00059 00060 return citr -> second; 00061 00062 } 00063 00064 //_____________________________________________________________________________ 00065 void DDSPSStatus::SetClientId(int childpid, DDSClientId* cid) { 00066 // Purpose: Set client id in fClientMap associated with child process id 00067 // childpid. ClientId is owned by this. 00068 00069 fClientMap.insert(make_pair(childpid,cid)); 00070 00071 } 00072 00073 //_____________________________________________________________________________ 00074 void DDSPSStatus::RemoveClientId(int childpid) { 00075 // Purpose: Remove map entry corresponding to child process id childpid. 00076 00077 ClientMapItr itr = fClientMap.find(childpid); 00078 if ( itr == fClientMap.end() ) { 00079 MSG("DDS",Msg::kWarning) << "DDSPSStatus::RemoveClientId w/Child pid " 00080 << childpid << "\nbut no matching pid in map." << endl; 00081 return; 00082 } 00083 00084 if ( itr -> second ) delete (itr->second); 00085 fClientMap.erase(itr); 00086 00087 return; 00088 00089 } 00090 00091 //_____________________________________________________________________________ 00092 std::ostream& DDSPSStatus::Print(std::ostream& os) const { 00093 // Purpose: Print DDSPSStatus status on std::ostream. 00094 00095 os << "DDSParentServer Status: "; 00096 00097 if ( fClientMap.size() == 0 ) { 00098 os << "No active clients." << endl; 00099 return os; 00100 } 00101 00102 // Loop over map containing active clients 00103 if ( fClientMap.size() == 1 ) 00104 os << fClientMap.size() << " active client." << endl; 00105 else 00106 os << fClientMap.size() << " active clients." << endl; 00107 00108 int ic = 0; 00109 for ( ClientMapConstItr citr = fClientMap.begin(); citr != fClientMap.end(); 00110 citr++ ) { 00111 DDSClientId* clientid = citr -> second; 00112 os << ic++ << ") " << *clientid; 00113 } 00114 os << endl; 00115 00116 return os; 00117 00118 } 00119 00120 //_____________________________________________________________________________ 00121 void DDSPSStatus::Print(Option_t* /* option */) const { 00122 // Purpose: Print method in TObject::Print format 00123 00124 Print(std::cout); 00125 00126 } 00127 00128 00129 00130 00131 00132 00133
1.3.9.1