yast2-core
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ScriptingAgent Class Reference

#include <ScriptingAgent.h>

Inheritance diagram for ScriptingAgent:
SCRAgent

Classes

struct  RegistrationDir
 

Public Member Functions

 ScriptingAgent (const string &root="/")
 
 ScriptingAgent (const string &root, const string &file)
 
 ~ScriptingAgent ()
 
virtual const char * root () const
 
virtual YCPValue Read (const YCPPath &path, const YCPValue &arg=YCPNull(), const YCPValue &opt=YCPNull())
 
virtual YCPBoolean Write (const YCPPath &path, const YCPValue &value, const YCPValue &arg=YCPNull())
 
virtual YCPList Dir (const YCPPath &path)
 
virtual YCPValue Execute (const YCPPath &path, const YCPValue &value=YCPNull(), const YCPValue &arg=YCPNull())
 
virtual YCPMap Error (const YCPPath &path)
 
YCPValue otherCommand (const YCPTerm &term)
 
virtual YCPBoolean RegisterAgent (const YCPPath &path, const YCPValue &value)
 
virtual YCPBoolean UnregisterAgent (const YCPPath &path)
 
virtual YCPBoolean UnregisterAllAgents ()
 
virtual YCPBoolean UnmountAgent (const YCPPath &path)
 
virtual YCPBoolean RegisterNewAgents ()
 
- Public Member Functions inherited from SCRAgent
 SCRAgent ()
 
virtual ~SCRAgent ()
 
void setAsCurrentSCR ()
 
string targetPath (const string &path) const
 

Private Types

typedef vector< SCRSubAgent * > SubAgents
 

Private Member Functions

void InitRegDirs ()
 
YCPValue MountAgent (const YCPPath &path)
 
YCPValue MountAllAgents ()
 
YCPValue UnmountAllAgents ()
 
void Sweep ()
 
void tryRegister (const YCPPath &path)
 
SubAgents::const_iterator findSubagent (const YCPPath &path)
 
SubAgents::const_iterator findAndRegisterSubagent (const YCPPath &path)
 
YCPList dirSubagents (const YCPPath &path)
 
YCPValue executeSubagentCommand (const char *command, const YCPPath &path, const YCPValue &arg=YCPNull(), const YCPValue &optpar=YCPNull())
 
SubAgents::iterator findByPath (const YCPPath &path)
 
void parseConfigFiles (const string &directory)
 
void parseSingleConfigFile (const string &file)
 

Private Attributes

bool done_sweep
 
string root_path
 
list< RegistrationDirregistration_dirs
 
SubAgents agents
 

Additional Inherited Members

- Static Public Member Functions inherited from SCRAgent
static YCPValue readconf (const char *filename)
 
static SCRAgentinstance ()
 
- Public Attributes inherited from SCRAgent
SCRAgentmainscragent
 

Detailed Description

The main agant that dispatches calls to other agents.

Member Typedef Documentation

typedef vector<SCRSubAgent*> ScriptingAgent::SubAgents
private

Type and list of subagents The vector is sorted by path

Constructor & Destructor Documentation

ScriptingAgent::ScriptingAgent ( const string &  root = "/")

Constructor.

References InitRegDirs(), and Sweep().

ScriptingAgent::ScriptingAgent ( const string &  root,
const string &  file 
)

Constructor. Load only a single SCR.

Parameters
fileSCR configuration file to be registered.

References InitRegDirs(), parseSingleConfigFile(), and y2debug.

ScriptingAgent::~ScriptingAgent ( )

Destructor. Also deletes subagents.

References UnregisterAllAgents().

Member Function Documentation

YCPList ScriptingAgent::Dir ( const YCPPath path)
virtual

Get a list of all subtrees.

Implements SCRAgent.

References executeSubagentCommand(), YCPElement::isNull(), and ycp2error.

YCPList ScriptingAgent::dirSubagents ( const YCPPath path)
private

If a SCR::Dir falls inside our tree, we have to provide a listing

References YCPList::add(), agents, YCPList::size(), str, and YCPList::value().

Referenced by executeSubagentCommand().

YCPMap ScriptingAgent::Error ( const YCPPath path)
virtual

Get a detailed error description if a previous command failed

Reimplemented from SCRAgent.

References executeSubagentCommand(), YCPElement::isNull(), and ycp2error.

YCPValue ScriptingAgent::Execute ( const YCPPath path,
const YCPValue value = YCPNull (),
const YCPValue arg = YCPNull () 
)
virtual

Executes a command.

Reimplemented from SCRAgent.

References executeSubagentCommand(), YCPElement::isNull(), y2debug, and ycp2error.

YCPValue ScriptingAgent::executeSubagentCommand ( const char *  command,
const YCPPath path,
const YCPValue arg = YCPNull (),
const YCPValue optpar = YCPNull () 
)
private

Calls a subagent to execute a Read, Write, Dir or other command

Parameters
commandthe command like "Read", "Dir", ..
pathAll commands take a path as first parameter. Here you give an absolute path, for example .etc.liloconf.global. When calling the agent, this path will be made relative to the agents root. E.g. If the agent's root path would be .etc.liloconf and the command "Read", the resulting command would be Read (.global).
optionalvalue to be given as second parameter to the call

References YCPTerm::add(), agents, dirSubagents(), findAndRegisterSubagent(), YCPElement::isNull(), y2debug, ycp2error, and YCPError().

Referenced by Dir(), Error(), Execute(), Read(), and Write().

ScriptingAgent::SubAgents::const_iterator ScriptingAgent::findAndRegisterSubagent ( const YCPPath path)
private

Find it in agents, registering if necessary, sweeping if necessary

See Also
tryRegister
Sweep

References agents, done_sweep, findSubagent(), Sweep(), and tryRegister().

Referenced by executeSubagentCommand().

ScriptingAgent::SubAgents::iterator ScriptingAgent::findByPath ( const YCPPath path)
private

Find agent exactly matching path. Returns agents.end () if the path isn't covered by any agent. Does not try to register.

References agents.

Referenced by MountAgent(), parseSingleConfigFile(), RegisterAgent(), UnmountAgent(), and UnregisterAgent().

ScriptingAgent::SubAgents::const_iterator ScriptingAgent::findSubagent ( const YCPPath path)
private

Iterate thru agents

Returns
end if not found

Find the agent where the agent's path and the given path have the longest match. Example:

agent net at .etc.network agent isdn at .etc.network.isdn

The command Read (.etc.network.isdn.line0) will call agent isdn with Read (.line0). The command Read (.etc.network) will call agent net with Read (.).

References agents.

Referenced by findAndRegisterSubagent().

void ScriptingAgent::InitRegDirs ( )
private
YCPValue ScriptingAgent::MountAgent ( const YCPPath path)
private

Mount the agent handling path. This function is called automatically when the agent is used.

References agents, findByPath(), and YCPError().

Referenced by otherCommand().

YCPValue ScriptingAgent::MountAllAgents ( )
private

Mount all agents.

References agents, and YCPElement::isNull().

Referenced by otherCommand().

YCPValue ScriptingAgent::otherCommand ( const YCPTerm term)
virtual

Handle the commands MountAgent, MountAllAgents, UnmountAllAgents, YaST2Version, SuSEVersion. Formerly also 'UnregisterAgent', 'UnregisterAllAgents', 'UnmountAgent' which are now builtins.

Reimplemented from SCRAgent.

References MountAgent(), MountAllAgents(), YCPTerm::name(), RegisterAgent(), YCPTerm::size(), UnmountAllAgents(), UnregisterAgent(), and YCPTerm::value().

void ScriptingAgent::parseConfigFiles ( const string &  directory)
private

Parses all SCR configuration files in the given directory, registers the agents. (If a SCR path is already registered, keep the old one.)

References less_than_inodes(), parseSingleConfigFile(), and y2debug.

Referenced by Sweep().

void ScriptingAgent::parseSingleConfigFile ( const string &  file)
private

Parses a single SCR configuration file, registers the agent. (If the SCR path is already registered, keep the old one.)

References agents, findByPath(), RegisterAgent(), y2debug, and y2warning.

Referenced by parseConfigFiles(), ScriptingAgent(), and tryRegister().

YCPValue ScriptingAgent::Read ( const YCPPath path,
const YCPValue arg = YCPNull (),
const YCPValue opt = YCPNull () 
)
virtual

Reads data.

Parameters
pathSpecifies what part of the subtree should be read. The path is specified relatively to Root()!

Implements SCRAgent.

References executeSubagentCommand(), YCPElement::isNull(), y2debug, and ycp2error.

YCPBoolean ScriptingAgent::RegisterAgent ( const YCPPath path,
const YCPValue value 
)
virtual

Register a agent, that is specify the scr path and the filename for it's definition or the term with the definition. The preferred way is to specify the filename.

Reimplemented from SCRAgent.

References agents, findByPath(), y2debug, and ycp2warning.

Referenced by otherCommand(), and parseSingleConfigFile().

YCPBoolean ScriptingAgent::RegisterNewAgents ( )
virtual

Register new agents. (bnc#245508#c16) Rescan the scrconf registration directories and register any agents at new(!) paths. Agents, even new ones, on paths that are registered already, will not be replaced. This means that .oes.specific.agent will start to work but something like adding /usr/local/etc/sysconfig to .sysconfig.network would not.

Reimplemented from SCRAgent.

References Sweep().

const char * ScriptingAgent::root ( ) const
virtual

Overrides root getter to provide root from constructor

See Also
SCRAgent::root

Reimplemented from SCRAgent.

References root_path.

void ScriptingAgent::Sweep ( )
private
void ScriptingAgent::tryRegister ( const YCPPath path)
private

For .foo.bar.baz, register foo.bar.baz.scr, or foo.bar.scr, or foo.scr. BTW we can register an unrelated path because this is just a heuristic.

References ScriptingAgent::RegistrationDir::name, parseSingleConfigFile(), registration_dirs, tr(), and y2debug.

Referenced by findAndRegisterSubagent().

YCPBoolean ScriptingAgent::UnmountAgent ( const YCPPath path)
virtual

Unmount the agent handling path.

Reimplemented from SCRAgent.

References agents, and findByPath().

YCPValue ScriptingAgent::UnmountAllAgents ( )
private

Unmount all agents.

References agents.

Referenced by otherCommand().

YCPBoolean ScriptingAgent::UnregisterAgent ( const YCPPath path)
virtual

Unregister a agent.

Reimplemented from SCRAgent.

References agents, findByPath(), and y2debug.

Referenced by otherCommand().

YCPBoolean ScriptingAgent::UnregisterAllAgents ( )
virtual

Unregister all agents.

Reimplemented from SCRAgent.

References agents, and done_sweep.

Referenced by ~ScriptingAgent().

YCPBoolean ScriptingAgent::Write ( const YCPPath path,
const YCPValue value,
const YCPValue arg = YCPNull () 
)
virtual

Writes data.

Implements SCRAgent.

References executeSubagentCommand(), YCPElement::isNull(), and ycp2error.

Member Data Documentation

SubAgents ScriptingAgent::agents
private
bool ScriptingAgent::done_sweep
private
list<RegistrationDir> ScriptingAgent::registration_dirs
private

Where to look for *.scr files, in order of preference

Referenced by InitRegDirs(), and tryRegister().

string ScriptingAgent::root_path
private

Referenced by root().


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

Generated on a sunny day for yast2-core by doxygen 1.8.5