Now that we know how the SCR-landscape can be navigated we will take a look at how the data that is dug in there can be accessed. The accessing methods already implied above shall now be defined more precisely.
There are four accessing methods.
Reading
We speak of reading, when the agent reads some configuration file or scans the system hardware and produces a YCP data structure representing this information.
Writing
We speak of writing, when the agent gets some YCP data structure and creates or modifies some system config file according to these data.
Executing
We speak of executing, when the agent gets some YCP data that can be interpreted as instruction and executes it. Usually this is being done by means of another program, e.g. the bash.
Dir
Comparared to the other accessing methods listed above, the Dir-command is somewhat special. It takes as argument an SCR-path that points to a specific node in the SCR-tree. It returns a list of all the sub-paths that are immediately below this node. This way it works just like a dir-command in a file system. For example if you apply this to the root of the SCR-tree (.), the answer would be a list with all the top nodes known by the SCR , e.g. ["audio", ... , "yast2"]. [1]
As a rule all SCR-agents implement some of the four accessing methods listed above. However depending on the task the agent was made for, not all of them may be provided.
For convenient use from YCP the accessing methods are realized by means of an API, i.e. a defined set of YCP-functions that are understood. You can call these functions from YCP if you prepend the commands with the name space identifier SCR:: which causes redirection to the SCR.
Table 5.2. The SCR-commands
Function | What it does |
---|---|
Read(path p) -> any | Reads the data represented by the node at path p. The value returned can be any YCP data type but it is always one single value. |
Write(path p, any v) -> boolean | Writes the value v to the node at path p. The boolean return value is true on success. On error the return value is false and a log entry is generated in the log file. Reasons for errors can be a mistyped value v or some problem with the periphery that lies behind the data-node. |
Execute(path p) -> boolean | This command is mostly used with the system-agent (see Section 5.6, “Useful SCR Agents”). Usually the return value indicates success or failure of the executed command. |
Dir(path p) -> list(string) | Returns a list of all subtree nodes immediately below the node p. For each such node the list contains a string denoting its name. If p does not point to a map node, i.e. the last path component is a leaf, the command will return an empty list or nil. |
[1] Unfortunately not all SCR-agents do support this command properly. There may be agents that wrongly return an empty list or even nil when queried this way.