Communication handle to a YaST2 component. More...
#include <Y2Component.h>
Public Member Functions | |
Y2Component () | |
virtual | ~Y2Component () |
virtual string | name () const =0 |
virtual YCPValue | evaluate (const YCPValue &command) |
virtual void | result (const YCPValue &result) |
virtual void | setServerOptions (int argc, char **argv) |
virtual Y2Namespace * | import (const char *name_space) |
virtual YCPValue | doActualWork (const YCPList &arglist, Y2Component *user_interface) |
virtual SCRAgent * | getSCRAgent () |
virtual bool | remote () const |
Communication handle to a YaST2 component.
YaST2 is a network oriented client/server architecture. Currently there exist five differnt types of components: userinterfaces, modules, the workflowmanagers, the repository (scr) and scr agents. All components are communicating using the same protocol.
The communication between two components is asymmetric. On component is said to be the server, the other to be the client. The protocol begins with the client sending an YCPValueRep, the command to the server. The server evaluates it and returns an YCPValueRep, the answer. Now the client sends the next command and so on. When the client has finished the work with the server, it sends a result value to the server and both sides close the connection. The result is a special YCPValueRep that is a term with the symbol "result" and exactly one argument.
Each component may be realized by a binary program (under Linux: ELF), by a process listening to an internet-domain socket, by a shared library plugin in ELF format (ending in .so), by a YCP script that is executed by the Workflowmanager (WFM), or by a C++ class that is linked to the Generic YaST2 Frontend (GF).
When you want to implement a component you need to subclass Y2Component and define the virtual functions (some of them only for a client component, some of them only for a server component). Furthermore you need to subclass Y2ComponentCreator and create a global variable from this class.
When you implement a component that needs the services of another component then you ask the Y2ComponentBroker to get a handle to it. That handle is of type Y2Component. Once you have got the handle, you can use it communicate with the component, regardless whether it is realized by a program, a plugin or what so ever.
See Y2ComponentBroker for examples.
Y2Component::Y2Component | ( | ) |
Y2Component::~Y2Component | ( | ) | [virtual] |
Base class must have virtual destructor.
YCPValue Y2Component::doActualWork | ( | const YCPList & | arglist, | |
Y2Component * | user_interface | |||
) | [virtual] |
This function must be overridden by an actual client. Here the client does its actual work.
arglist | YCPList of client arguments. | |
user_interface | Option display server (user interface) Most clients need interaction with the user. The different YaST2 user interfaces are servers. If the user interace is already active and running, give a handle to it with this parameter. Give 0 here if no user interface is running yet and either the module launches the user interace itself or it it does not need one. |
This method is only defined, if the component is a client.
Reimplemented in Y2PluginComponent, Y2ProgramComponent, Y2SerialComponent, Y2StdioComponent, and Y2WFMComponent.
References name(), and y2internal.
Referenced by Y2WFMComponent::CallFunction(), Y2PluginComponent::doActualWork(), and main().
Starts the server, if it is not already started and does what a server is good for: Gets a command, evaluates (or executes) it and returns the result.
command | The command to be executed. Any YCPValueRep can be executed. The execution is performed by some YCPInterpreter. |
This method is only defined, if the component is a server.
Reimplemented in Y2AgentComp< Agent >, Y2PluginComponent, Y2ProgramComponent, Y2SerialComponent, and Y2StdioComponent.
References name(), and y2internal.
Referenced by StdioSCRAgent::Dir(), Y2StdioComponent::doActualWork(), Y2SerialComponent::doActualWork(), Y2ProgramComponent::doActualWork(), StdioSCRAgent::Error(), Y2PluginComponent::evaluate(), StdioSCRAgent::Execute(), main(), SCRSubAgent::mount(), StdioSCRAgent::Read(), StdioSCRAgent::RegisterAgent(), WFMSubAgent::start_and_check(), StdioSCRAgent::UnregisterAgent(), and StdioSCRAgent::Write().
SCRAgent * Y2Component::getSCRAgent | ( | ) | [virtual] |
Returns the SCRAgent of the Y2Component or NULL, if it doesn't have one. Note: This might trigger the creation of the Interpreter and Agent associated with the Y2Component. For plugins, this might trigger the loading of the plugin as well.
Reimplemented in Y2AgentComp< Agent >, and Y2PluginComponent.
Referenced by WFMSubAgent::agent(), Y2PluginComponent::getSCRAgent(), and SCRSubAgent::mount().
Y2Namespace * Y2Component::import | ( | const char * | name_space | ) | [virtual] |
Try to import a given namespace. This method is used for transparent handling of namespaces (YCP modules) through whole YaST. NOTICE: there is no reverse operation to import. Semantics of YCP modules is there is a single instance and it is available from the first import until the end of YaST run.
name_space | the name of the required namespace |
Reimplemented in Y2PluginComponent, TestY2Component, TestY2Component, Y2WFMComponent, and TestY2Component.
References y2internal.
Referenced by Y2WFMComponent::import(), Y2PluginComponent::import(), and Import::import().
virtual string Y2Component::name | ( | ) | const [pure virtual] |
Returns the name of the module.
Implemented in Y2AgentComp< Agent >, Y2ErrorComponent, Y2PluginComponent, Y2ProgramComponent, Y2SerialComponent, Y2StdioComponent, TestY2Component, TestY2Component, Y2WFMComponent, and TestY2Component.
Referenced by doActualWork(), evaluate(), and Import::import().
bool Y2Component::remote | ( | ) | const [virtual] |
Reimplemented in Y2ProgramComponent.
Referenced by Y2WFMComponent::SCRSetDefault().
void Y2Component::result | ( | const YCPValue & | result | ) | [virtual] |
Tells this server, that the client doesn't need it's services any longer and that the exit code of the client is result.
This method is only defined, if the component is a server.
Reimplemented in Y2PluginComponent, Y2ProgramComponent, Y2SerialComponent, and Y2StdioComponent.
Referenced by Y2WFMComponent::CallFunction(), main(), Y2PluginComponent::result(), SCRSubAgent::unmount(), WFMSubAgent::~WFMSubAgent(), and Y2PluginComponent::~Y2PluginComponent().
void Y2Component::setServerOptions | ( | int | argc, | |
char ** | argv | |||
) | [virtual] |
Sets the commandline options of the server.
argc | number of arguments including argv[0], the name of the component | |
argv | a pointer to a field of argc+1 char *, where the last one must be 0. The caller of the function must assure that the data field is persistent. This method will _not_ make a copy of it. |
This method is only defined, if the component is a server.
Reimplemented in Y2PluginComponent, Y2ProgramComponent, Y2SerialComponent, and Y2StdioComponent.
Referenced by Y2PluginComponent::loadPlugin(), main(), and Y2PluginComponent::setServerOptions().