XRootD
XrdCl::FSExecutor Class Reference

Execute queries given as a commandline. More...

#include <XrdClFSExecutor.hh>

+ Collaboration diagram for XrdCl::FSExecutor:

Public Types

typedef XRootDStatus(* Command) (FileSystem *fs, Env *env, const CommandParams &args)
 Definition of a command. More...
 
typedef std::vector< std::string > CommandParams
 Definition of command argument list. More...
 

Public Member Functions

 FSExecutor (const URL &url, Env *env=0)
 
 ~FSExecutor ()
 Destructor. More...
 
bool AddCommand (const std::string &name, Command command)
 
XRootDStatus Execute (const CommandParams &args)
 
EnvGetEnv ()
 Get the environment. More...
 

Detailed Description

Execute queries given as a commandline.

Definition at line 34 of file XrdClFSExecutor.hh.

Member Typedef Documentation

◆ Command

typedef XRootDStatus(* XrdCl::FSExecutor::Command) (FileSystem *fs, Env *env, const CommandParams &args)

Definition of a command.

Definition at line 45 of file XrdClFSExecutor.hh.

◆ CommandParams

typedef std::vector<std::string> XrdCl::FSExecutor::CommandParams

Definition of command argument list.

Definition at line 40 of file XrdClFSExecutor.hh.

Constructor & Destructor Documentation

◆ FSExecutor()

XrdCl::FSExecutor::FSExecutor ( const URL url,
Env env = 0 
)

Constructor

Parameters
urlthe server that the executor should contact
envexecution environment, the executor takes ownership over it

Definition at line 31 of file XrdClFSExecutor.cc.

31  :
32  pFS( 0 )
33  {
34  pFS = new FileSystem( url );
35  if( env )
36  pEnv = env;
37  else
38  pEnv = new Env();
39 
40  pEnv->PutString( "ServerURL", url.GetURL() );
41  }
bool PutString(const std::string &key, const std::string &value)
Definition: XrdClEnv.cc:52

References XrdCl::URL::GetURL(), and XrdCl::Env::PutString().

+ Here is the call graph for this function:

◆ ~FSExecutor()

XrdCl::FSExecutor::~FSExecutor ( )

Destructor.

Definition at line 46 of file XrdClFSExecutor.cc.

47  {
48  delete pFS;
49  delete pEnv;
50  }

Member Function Documentation

◆ AddCommand()

bool XrdCl::FSExecutor::AddCommand ( const std::string &  name,
Command  command 
)

Add a command to the set of known commands

Parameters
namename of the command
commandfunction pointer
Returns
status

Definition at line 55 of file XrdClFSExecutor.cc.

56  {
57  Log *log = DefaultEnv::GetLog();
58  CommandMap::iterator it = pCommands.find( name );
59  if( it != pCommands.end() )
60  {
61  log->Error( AppMsg, "Unable to register command %s. Already exists.",
62  name.c_str() );
63  return false;
64  }
65  pCommands.insert( std::make_pair( name, command ) );
66  return true;
67  }
static Log * GetLog()
Get default log.
const uint64_t AppMsg
XrdSysError Log
Definition: XrdConfig.cc:112

References XrdCl::AppMsg, XrdCl::Log::Error(), and XrdCl::DefaultEnv::GetLog().

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Execute()

XRootDStatus XrdCl::FSExecutor::Execute ( const CommandParams args)

Execute the given commandline

Parameters
args: arguments for the commandline to be executed, first of which is the command name
Returns
status of the execution

Definition at line 69 of file XrdClFSExecutor.cc.

70  {
71  std::stringstream cmdline;
72  std::ostream_iterator<std::string> oit(cmdline, " ");
73  std::copy(args.begin(), args.end(), oit);
74 
75  Log *log = DefaultEnv::GetLog();
76  log->Debug( AppMsg, "Executing: %s", cmdline.str().c_str() );
77 
78  if( args.empty() )
79  {
80  log->Dump( AppMsg, "Empty commandline." );
81  return 1;
82  }
83 
84  CommandParams::const_iterator parIt;
85  int i = 0;
86  for( parIt = args.begin(); parIt != args.end(); ++parIt, ++i )
87  log->Dump( AppMsg, " Param #%02d: '%s'", i, parIt->c_str() );
88 
89  //--------------------------------------------------------------------------
90  // Extract the command name
91  //--------------------------------------------------------------------------
92  std::string commandName = args.front();
93  CommandMap::iterator it = pCommands.find( commandName );
94  if( it == pCommands.end() )
95  {
96  log->Error( AppMsg, "Unknown command: %s", commandName.c_str() );
97  return XRootDStatus( stError, errUnknownCommand );
98  }
99 
100  return it->second( pFS, pEnv, args );
101  }
const uint16_t errUnknownCommand
Definition: XrdClStatus.hh:57
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32

References XrdCl::AppMsg, XrdCl::Log::Debug(), XrdCl::Log::Dump(), XrdCl::Log::Error(), XrdCl::errUnknownCommand, XrdCl::DefaultEnv::GetLog(), and XrdCl::stError.

Referenced by ExecuteCommand(), and ExecuteInteractive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetEnv()

Env* XrdCl::FSExecutor::GetEnv ( )
inline

Get the environment.

Definition at line 83 of file XrdClFSExecutor.hh.

84  {
85  return pEnv;
86  }

Referenced by ExecuteCommand(), and ExecuteInteractive().

+ Here is the caller graph for this function:

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