xrootd
XrdClUtils.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // XRootD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // XRootD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17 //------------------------------------------------------------------------------
18 
19 #ifndef __XRD_CL_UTILS_HH__
20 #define __XRD_CL_UTILS_HH__
21 
22 #include <string>
23 #include <vector>
24 #include <netinet/in.h>
25 #include "XrdCl/XrdClStatus.hh"
26 #include "XrdCl/XrdClLog.hh"
27 #include "XrdCl/XrdClURL.hh"
29 
30 #include <sys/time.h>
31 
32 namespace XrdCl
33 {
34  //----------------------------------------------------------------------------
36  //----------------------------------------------------------------------------
37  class Utils
38  {
39  public:
40  //------------------------------------------------------------------------
42  //------------------------------------------------------------------------
43  template<class Container>
44  static void splitString( Container &result,
45  const std::string &input,
46  const std::string &delimiter )
47  {
48  size_t start = 0;
49  size_t end = 0;
50  size_t length = 0;
51 
52  do
53  {
54  end = input.find( delimiter, start );
55 
56  if( end != std::string::npos )
57  length = end - start;
58  else
59  length = input.length() - start;
60 
61  if( length )
62  result.push_back( input.substr( start, length ) );
63 
64  start = end + delimiter.size();
65  }
66  while( end != std::string::npos );
67  }
68 
69  //------------------------------------------------------------------------
71  //------------------------------------------------------------------------
72  static Status GetHostAddresses( std::vector<sockaddr_in> &addresses,
73  const URL &url);
74 
75  //------------------------------------------------------------------------
77  //------------------------------------------------------------------------
78  static void LogHostAddresses( Log *log,
79  uint64_t type,
80  const std::string &hostId,
81  std::vector<sockaddr_in> &addresses );
82 
83  //------------------------------------------------------------------------
85  //------------------------------------------------------------------------
86  static std::string TimeToString( time_t timestamp );
87 
88  //------------------------------------------------------------------------
90  //------------------------------------------------------------------------
91  static uint64_t GetElapsedMicroSecs( timeval start, timeval end );
92 
93  //------------------------------------------------------------------------
95  //------------------------------------------------------------------------
96  static XRootDStatus GetRemoteCheckSum( std::string &checkSum,
97  const std::string &checkSumType,
98  const std::string &server,
99  const std::string &path );
100 
101  //------------------------------------------------------------------------
103  //------------------------------------------------------------------------
104  static XRootDStatus GetLocalCheckSum( std::string &checkSum,
105  const std::string &checkSumType,
106  const std::string &path );
107 
108  //------------------------------------------------------------------------
110  //------------------------------------------------------------------------
111  static std::string BytesToString( uint64_t bytes );
112 
113  //------------------------------------------------------------------------
115  //------------------------------------------------------------------------
116  static XRootDStatus CheckTPC( const std::string &server );
117  };
118 
119  //----------------------------------------------------------------------------
121  //----------------------------------------------------------------------------
123  {
124  public:
125  //------------------------------------------------------------------------
127  //------------------------------------------------------------------------
128  ScopedDescriptor( int descriptor ): pDescriptor( descriptor ) {}
129 
130  //------------------------------------------------------------------------
132  //------------------------------------------------------------------------
134 
135  //------------------------------------------------------------------------
137  //------------------------------------------------------------------------
138  int Release()
139  {
140  int desc = pDescriptor;
141  pDescriptor = -1;
142  return desc;
143  }
144 
145  //------------------------------------------------------------------------
147  //------------------------------------------------------------------------
149  {
150  return pDescriptor;
151  }
152 
153  private:
155  };
156 }
157 
158 #endif // __XRD_CL_UTILS_HH__