Class ServiceApp() Foundation

Class function of the ServiceApp class

Description

The ServiceApp class is used to implement service applications. Just like XppApplication() for console applications and XbpApplication() for GUI and hybrid mode applications, the ServiceApp class provides functionality for a specific application type. Please refer to the section Implementing services for technical background information on service applications.

The ServiceApp class is a singleton, which means that only the class object can be used and no instances can be created of the class. This reflects the fact that only one service can be implemented in a single executable file, and that only one application object is required per service application. Consequently, the ServiceApp class does not have a constructor method.

The ServiceApp class uses callbacks to implement the reaction of the service to particular service control requests like "start" or "stop". A minimum of two callbacks must be implemented: one callback containing the code for the task of the service, and another callback that allows to stop the service after it has been started. These callbacks are named :main() and :stop().

No limitation exists for spawning multiple threads in a service application when concurrent tasks are to be fulfilled.

Class methods
:start()
Starts the service process.
Callback class methods

These class methods are called automatically by the system in response to control requests from a service control application. The callbacks must be used to implement the behavior of the service with regard to the control requests.

:continue()
Service received "continue" control request.
:main()
Service has started.
:pause()
Service received "pause" control request.
:stop()
Service received "stop" control request.
Callback codeblocks
:Continue
Deprecated. Use :continue() instead.
:Main
Deprecated. Use :main() instead.
:Pause
Deprecated. Use :pause() instead.
:Stop
Deprecated. Use :stop() instead.
Examples
Application implementing a service.
// This sample demonstrates how a service can be implemented. 
// The service simply calls the function Tone() every 
// five seconds until it receives the Stop request. 
// To install and start this service see the 
// example for the ServiceController class. 

#include "service.ch" 

// Entry point of the executable 
PROCEDURE Main() 
   MyService():start() 
RETURN 


CLASS MyService From ServiceApp 
   EXPORTED: 
   CLASS METHOD main 
   CLASS METHOD stop 

   HIDDEN: 
   CLASS VAR lRunning 
ENDCLASS 


// Entry point of the service 
CLASS METHOD MyService:main() 
   ::lRunning := .T. 

   DO WHILE ::lRunning 
      Tone( 400, 9 ) 
      Sleep( 500 ) 
   ENDDO 
RETURN self 


// Entry point for Stop request 
CLASS METHOD MyService:stop() 
   ::lRunning := .F. 
RETURN self 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.