8 #ifndef Y2AgentComponent_h
9 #define Y2AgentComponent_h
73 template <
class Agent>
81 template <
class Agent>
94 y2debug (
"evaluate (%s)", v->toString ().c_str ());
99 y2debug (
"Going to evaluate %s", v->toString ().c_str ());
102 if (value->isCode ())
104 YCodePtr c = v->asCode ()->code ();
109 y2milestone (
"Evaluating an expression, not SCR builtin");
110 value = value->asCode ()->evaluate ();
114 value = value->asCode ()->evaluate ();
117 if (value.isNull () || value->isVoid ())
120 y2debug (
"After code evaluation: %s", value->toString ().c_str ());
122 if( value->isTerm () ) {
123 YCPTerm term = value ->asTerm ();
124 string command = term->
name ();
128 if( command ==
"Read" ) {
129 return getSCRAgent ()-> Read (args->
value (0)->asPath (), args->
size() > 1 ? args->
value (1) :
YCPNull ()) ;
131 else if( command ==
"Write" ) {
132 return getSCRAgent ()-> Write (args->
value (0)->asPath (), args->
value (1), args->
size () > 2 ? args->
value (2) :
YCPNull ()) ;
134 else if( command ==
"Dir" ) {
135 return getSCRAgent ()-> Dir (args->
value (0)->asPath ()) ;
137 else if( command ==
"Error" ) {
138 return getSCRAgent ()-> Error (args->
value (0)->asPath ()) ;
140 else if( command ==
"Execute" ) {
141 y2debug(
"Execute, arg size is %d", args->
size() );
142 switch( args->
size() ) {
144 return getSCRAgent ()-> Execute (args->
value (0)->asPath ()) ;
146 return getSCRAgent ()-> Execute (args->
value (0)->asPath (), args->
value (1)) ;
148 return getSCRAgent ()-> Execute (args->
value (0)->asPath (), args->
value (1), args->
value (2)) ;
152 y2debug(
"Passing term to otherCommand" );
153 return getSCRAgent ()-> otherCommand (term);
157 if( value->isCode () ) {
158 y2debug(
"Passing (evaluated) code to otherCommand" );
159 return getSCRAgent ()-> otherCommand (value->asCode ()->evaluate ()->asTerm ());
163 y2error(
"Unhandled value (%s): %s", value->valuetype_str (), value->toString ().c_str () );
174 agent =
new Agent ();
182 y2error(
"Y2AgentComp::Read" );
183 return getSCRAgent()->Read (path);
186 #endif // Y2AgentComponent_h
string name() const
Definition: Y2AgentComponent.h:44
const char * my_name
Definition: Y2AgentComponent.h:63
SCRAgent * getSCRAgent()
Definition: Y2AgentComponent.h:170
~Y2AgentComp()
Definition: Y2AgentComponent.h:82
#define y2milestone(format, args...)
Definition: liby2util-r/src/include/y2util/y2log.h:110
YCPValue value(int n) const
Definition: YCPList.h:266
Communication handle to a YaST2 component.
Definition: Y2Component.h:262
SuSE Configuration Repository Agent.
Definition: SCRAgent.h:38
string name() const
Definition: YCPTerm.h:185
ScriptingAgent agent
Definition: scr.cc:14
#define y2error(format, args...)
Definition: liby2util-r/src/include/y2util/y2log.h:112
Wrapper for YCPListRep This class realizes an automatic memory management via YCPElement. Access the functionality of YCPListRep with the arrow operator. See YCPListRep.
Definition: YCPList.h:236
Y2AgentComp(const char *)
Definition: Y2AgentComponent.h:74
YCPValue evaluate(const YCPValue &command)
Definition: Y2AgentComponent.h:92
Wrapper for YCPVoidRep This class realizes an automatic memory management via YCPElement. Access the functionality of YCPVoidRep with the arrow operator. See YCPVoidRep.
Definition: YCPVoid.h:75
Wrapper for YCPTermRep This class realizes an automatic memory management via YCPElement. Access the functionality of YCPTermRep with the arrow operator. See YCPTermRep.
Definition: YCPTerm.h:177
YCPList args() const
Definition: YCPTerm.h:186
Wrapper for YCPValueRep This class realizes an automatic memory management via YCPElement. Access the functionality of YCPValueRep with the arrow operator. See YCPValueRep.
Definition: YCPValue.h:275
Wrapper for YCPPathRep This class realizes an automatic memory management via YCPElement. Access the functionality of YCPPathRep with the arrow operator. See YCPPathRep.
Definition: YCPPath.h:175
YCPValue Read(const YCPPath &path)
Definition: Y2AgentComponent.h:180
Definition: Y2AgentComponent.h:26
#define y2debug(format, args...)
Definition: liby2util-r/src/include/y2util/y2log.h:107
Definition: YCPElement.h:125
Agent * agent
Definition: Y2AgentComponent.h:68
int size() const
Definition: YCPList.h:250