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