# Advanced Service Starting Widgets

CWMServiceStart is a set of widgets for CWM that can be used for setting service start-on-boot and immediately start/stop a service. It handles all the needed stuff via specified callback functions and via the Service module.

## Service start on boot

To create a widget for setting if service should be started on boot, use the CWMServiceStart::CreateAutoStartWidget () function. This function has one argument (a map from string to any).

Usage of the Service Start-on-Boot widget

    boolean GetStartService () {...}
    boolean SetStartService (boolean start) {...}

    map<string,any> widget = CWMServiceStart::CreateAutoStartWidget ($[
        "get_service_auto_start" : DhcpServer::GetStartService,
        "set_service_auto_start" : DhcpServer::SetStartService,
        "start_auto_button" : _("Start DHCP Server when &Booting"),
        "start_manual_button" : _("Start DHCP Server &Manually"),
        "help" : _("Help to the widget..."),
    ]);

The parameters for service starting are following:

- `"get_service_auto_start"` is reference to a function with no parameter returning boolean value that says if the service is started. It is mandatory.

- `"set_service_auto_start"` is reference to a function with one boolean parameter saying if the service should be started at boot and return type void. It is mandatory.

- `"get_service_start_via_xinetd"` is reference to a function with no parameter returning boolean value that says if the service is started via xinetd. It is optional, if not present, the xinetd part of the widget is not shown

- `"set_service_start_via_xinetd"` is a reference to a function with one boolean parameter saying if the service should be started via xinetd and return type void. It is optional. If it is setting the value to true, "set_service_auto_start" is set to false.

- `"start_auto_button"` contains the label of the "Start on boot" radio button. If not present, generic label is used.

- `"start_manual_button"` contains the label of the "Start only manually" radio button. If not present, generic label is used.

- `"start_xinetd_button"` contains the label of the "Start via xinetd" radio button. If not present, generic label is used. Used only if "get_service_start_via_xinetd" is defined.

- `"help"` contains the help to the widget. If not present, generic help is used. Note that if you change the labels of the buttons, you must specify the help. You can use CWMServiceStart::AutoStartHelpTemplate () and sformat to change only the button labels.

## LDAP support

To create a widget for enabling or disabling the LDAP support, use the CWMServiceStart::CreateLdapWidget () function. This function has one argument (a map from string to any).

Usage of the LDAP enablement widget

    global define void SetUseLdap (boolean use_ldap) {...}
    global define boolean GetUseLdap () {...}

    map<string,any> widget = CWMServiceStart::CreateWidget ($[
        "get_use_ldap" : GetUseLdap,
        "set_use_ldap" : SetUseLdap,
        "use_ldap_checkbox" : _("Read DHCP Settings from &LDAP"),
        "help" : _("Help to the widget..."),
    ]);

The parameters for LDAP support are following:

- `"get_use_ldap"` is reference to a function with no parameter returning boolean value that says if LDAP support is enabled. If it is missing, LDAP check-box is not shown.

- `"set_use_ldap"` is reference to a function with one boolean parameter saying if the LDAP support should be active and return type void. If it is missing, LDAP check-box is not shown.

- `"use_ldap_checkbox"` contains the label of the "Use LDAP" check-box. If not present, generic label is used.

- `"help"` contains the help to the widget. If not present, generic help is used. Note that if you change the label of the check box, you must specify the help. You can use CWMServiceStart::EnableLdapHelpTemplate () and sformat to change only the check box label.

## Immediate actions

To create a widget for displaying service status and immediate starting or stopping the service, use the CWMServiceStart::CreateStartStopWidget () function. This function has one argument (a map from string to any).

Usage of the Immediate Actions Widget

    define void SaveAndRestart () {...}

    map<string,any> widget = CWMServiceStart::CreateStartStopWidget ($[
        "service_id" : "dhcpd",
        "service_running_label" : _("DHCP Server is running"),
        "service_not_running_label" : _("DHCP Server is not running"),
        "start_now_button" : _("&Start DHCP Server Now"),
        "stop_now_button" : _("S&top DHCP Server Now"),
        "save_now_action" : SaveAndRestart,
        "save_now_button" : _("Save and Restart DHCP Server &Now"),
        "help" : _("Help to the widget..."),
    ]);

The parameters for Immediate actions are following:

- `"service_id"` is the service name to be passed as argument for functions of the Service module. If it is missing, the service status and immediate actions buttons are not shown.

- `"service_running_label"` label to be displayed if the service is running. If it is missing, generic label is used.

- `"service_not_running_label"` label to be displayed if the service is not running. If it is missing, generic label is used.

- `"start_now_button"` label of the "Start service now" button. If it is missing, generic label is used.

- `"stop_now_button"` label of the "Stop service now" button. If it is missing, generic label is used.

- `"save_now_action"` is a reference to function without any parameters with void return type. Its task is to save all changes and restart the service. It is is missing, the "Save and restart service now" button is not shown.

- `"start_now_action"` is a reference to function, without any parameters with void return type. Its task is to restart the service. If it is missing, generic function using the `"service_id"` parameter is used.

- `"stop_now_action"` is a reference to function, without any parameters with void return type. Its task is to stop the service. If it is missing, generic function using the `"service_id"` parameter is used.

- `"save_now_button"` label of the "Save and restart service now" button. If it is missing, generic label is used.

- `"help"` contains the help to the widget. If not present, generic help is used. Note that if you change the labels of the buttons, you must specify the help. You can use CWMServiceStart::StartStopHelpTemplate () and sformat to change only the button labels.