OpenMediaVault  3.0 (Erasmus)
The open network attached storage solution
Public Member Functions | Protected Member Functions | List of all members
OMV\Rpc\ServiceAbstract Class Reference

Public Member Functions

 getName ()
 
 initialize ()
 
 hasMethod ($name)
 
 callMethod ($name, $params, $context)
 
 callMethodBg ($name, $params, $context)
 
 execBgProc (\Closure $childProc,\Closure $error=NULL,\Closure $finally=NULL)
 

Protected Member Functions

 registerMethod ($rpcName, $methodName=NULL)
 
 registerMethodSequence ($service, $method, $method2)
 
 validateMethodParams ($params, $schema)
 
 validateMethodContext ($context, $required)
 
 getAdminContext ()
 
 fork ()
 
 createBgProcStatus ()
 
 createBgProcOutput ($prefix="bgoutput")
 
 writeBgProcOutput ($filename, $content)
 
 initializeBgProcStatus ($filename, $pid)
 
 finalizeBgProcStatus ($filename, $result=NULL, $exception=NULL)
 
 updateBgProcStatus ($filename, $key, $value)
 
 getBgProcStatus ($filename)
 
 unlinkBgProcStatus ($filename)
 
 exec ($command, &$output=NULL, $outputFilename=NULL)
 
 execve ($path, $args=NULL, $outputFilename=NULL)
 
 applyFilter ($array, $start, $limit, $sortField=NULL, $sortDir=NULL)
 
 deleteConfigObjectByUuid ($model, $uuid, $notifyId)
 
 deleteConfigObjectByObject (\OMV\Config\ConfigObject $object, $notifyId)
 
 setModuleDirty ($name)
 
 isModuleDirty ($name)
 

Detailed Description

The core RPC service class.

Member Function Documentation

OMV\Rpc\ServiceAbstract::applyFilter (   $array,
  $start,
  $limit,
  $sortField = NULL,
  $sortDir = NULL 
)
finalprotected

Helper function to filter the method result using the given filter arguments.

Parameters
arrayThe array of objects to filter.
startThe index where to start.
limitThe number of elements to process.
sortFieldThe name of the column used to sort.
sortDirThe sort direction, ASC or DESC.
Returns
An array containing the elements matching the given restrictions. The field total contains the total number of elements, data contains the elements as array. An exception will be thrown in case of an error.
OMV\Rpc\ServiceAbstract::callMethod (   $name,
  $params,
  $context 
)
final

Call the given RPC service method. Registered method hooks will be called after the origin method has been successfully called.

Parameters
nameThe name of the method.
paramsThe method parameters.
contextThe context of the caller.
Returns
Returns the return value of the RPC service method.
OMV\Rpc\ServiceAbstract::callMethodBg (   $name,
  $params,
  $context 
)
final

Call the given RPC service method in a background process. Registered method hooks will be called after the origin method has been successfully called.

Parameters
nameThe name of the method.
paramsThe method parameters.
contextThe context of the caller.
Returns
The name of the background process status file.
OMV\Rpc\ServiceAbstract::createBgProcOutput (   $prefix = "bgoutput")
finalprotected

Helper function to create the file containing the background process output.

Returns
The name of the background process output file.
Exceptions
OMV\Rpc\ServiceAbstract::createBgProcStatus ( )
finalprotected

Helper function to create the file containing the background process status.

Returns
The name of the background process status file.
Exceptions
OMV\Rpc\ServiceAbstract::deleteConfigObjectByObject ( \OMV\Config\ConfigObject  $object,
  $notifyId 
)
protected

Helper function to delete an configuration object. The notifications OMV_NOTIFY_PREDELETE and OMV_NOTIFY_DELETE will be submitted to its subscribers.

Deprecated:
Parameters
objectThe configuration object.
notifyIdThe notification identifier to be submitted.
Returns
The deleted configuration object.
OMV\Rpc\ServiceAbstract::deleteConfigObjectByUuid (   $model,
  $uuid,
  $notifyId 
)
protected

Helper function to delete an configuration object. The notifications OMV_NOTIFY_PREDELETE and OMV_NOTIFY_DELETE will be submitted to its subscribers.

Deprecated:
Parameters
modelThe data model identifier of the configuration object.
uuidThe UUID of the configuration object.
notifyIdThe notification identifier to be submitted.
Returns
The deleted configuration object.
OMV\Rpc\ServiceAbstract::exec (   $command,
$output = NULL,
  $outputFilename = NULL 
)
finalprotected

Helper function to execute an external program. The command output will be redirected to the given file if set.

Parameters
commandThe command that will be executed.
outputIf the output argument is present, then the specified array will be filled with every line of the command output from stdout. Trailing whitespace, such as
, is not included in this array.
outputFilenameThe name of the file that receives the command output from stdout. If set to NULL the command output will not be redirected to a file.
Returns
The exit code of the command or -1 in case of an error.
OMV\Rpc\ServiceAbstract::execBgProc ( \Closure  $childProc,
\Closure  $error = NULL,
\Closure  $finally = NULL 
)

Execute the specified anonymous function as a background process by forking the main process.

Parameters
Closure$childProcAn anonymous function that expects the parameters $bgStatusFilename and $bgOutputFilename. It should return a string with the process output.
Closure$errorAn anonymous function that expects the parameters $bgStatusFilename and $bgOutputFilename. It will be called in case of an exception within the $childProc closure.
Closure$finallyAn anonymous function without arguments. It will always be executed after the background process has been finished successfully or it has been failed.
Returns
The name of the background process status file.
OMV\Rpc\ServiceAbstract::execve (   $path,
  $args = NULL,
  $outputFilename = NULL 
)
finalprotected

Helper function to executes specified program in current process space.

Parameters
pathThe path to a binary executable or a script with a valid path pointing to an executable in the shebang as the first line.
argsAn array of argument strings passed to the program.
outputFilenameThe name of the file that receives the command output from STDOUT. STDERR will be redirected to this file, too. If set to NULL the command output will not be redirected to a file.
Returns
Returns FALSE on error and does not return on success.
OMV\Rpc\ServiceAbstract::finalizeBgProcStatus (   $filename,
  $result = NULL,
  $exception = NULL 
)
finalprotected

Helper function to finalize the background process status file.

Parameters
filenameThe name of the status file.
resultThe result of the background process, e.g. the output of an executed command. Defaults to NULL.
exceptionThe exception that has been thrown. Defaults to NULL.
Returns
The background process status.
OMV\Rpc\ServiceAbstract::fork ( )
finalprotected

Helper function to fork the current running process.

Returns
The PID of the child process.
Exceptions
OMV\Rpc\ServiceAbstract::getAdminContext ( )
finalprotected

Helper function to get the administrator context.

Returns
The context object.
OMV\Rpc\ServiceAbstract::getBgProcStatus (   $filename)
finalprotected

Helper function to get the background process status file content.

Parameters
filenameThe name of the status file.
Returns
The background process status.
OMV\Rpc\ServiceAbstract::getName ( )
abstract

Get the name of the RPC service.

Returns
The name of the RPC service.
OMV\Rpc\ServiceAbstract::hasMethod (   $name)
final

Check if the given service method exists.

Returns
TRUE if the service method exists, otherwise FALSE.
OMV\Rpc\ServiceAbstract::initialize ( )
abstract

Initialize the RPC service.

OMV\Rpc\ServiceAbstract::initializeBgProcStatus (   $filename,
  $pid 
)
finalprotected

Helper function to update the background process status file.

Parameters
filenameThe name of the status file.
pidThe PID of the background process.
Returns
The background process status.
OMV\Rpc\ServiceAbstract::isModuleDirty (   $name)
finalprotected

Helper function to check whether a module is marked dirty.

Parameters
nameThe name of the module.
Returns
TRUE if the module is marked dirty, otherwise FALSE.
OMV\Rpc\ServiceAbstract::registerMethod (   $rpcName,
  $methodName = NULL 
)
finalprotected

Register a RPC service method. Only those methods can be executed via RPC.

Parameters
rpcNameThe name of the RPC service method.
methodNameThe name of the class method that implements the RPC sevice method. If set to NULL the name given in rpcName is used. Defaults to NULL.
Returns
TRUE on success, otherwise an error is thrown.
OMV\Rpc\ServiceAbstract::registerMethodSequence (   $service,
  $method,
  $method2 
)
finalprotected

Create a combined RPC service method call sequence of the original method and the passed method. The passed method is called with the parameters of the original RPC service method.

Parameters
serviceThe name of the RPC service.
methodThe name of the original RPC service method.
method2The name of the method that should be called after the original RPC service method.
Returns
TRUE on success, otherwise an exception is thrown.
OMV\Rpc\ServiceAbstract::setModuleDirty (   $name)
finalprotected

Helper function to mark a module as dirty.

Parameters
nameThe name of the module.
Returns
The list of dirty modules.
OMV\Rpc\ServiceAbstract::unlinkBgProcStatus (   $filename)
finalprotected

Helper function to unlink the background process status file.

Parameters
filenameThe name of the status file.
Returns
None.
OMV\Rpc\ServiceAbstract::updateBgProcStatus (   $filename,
  $key,
  $value 
)
finalprotected

Helper function to update informations of the background process status file.

Parameters
filenameThe name of the status file.
keyThe name of the field to be modified.
valueThe new value of the field.
Returns
The background process status.
OMV\Rpc\ServiceAbstract::validateMethodContext (   $context,
  $required 
)
finalprotected

Helper function to validate the method caller context.

Parameters
contextThe caller context to be validated.
requiredThe required context.
Returns
None.
Exceptions
OMV\Rpc\ServiceAbstract::validateMethodParams (   $params,
  $schema 
)
finalprotected

Helper function to validate the given method parameters using JSON schema.

Parameters
paramsThe parameters to be validated.
schemaThe JSON schema that describes the method parameters. Can be given as UTF-8 encoded JSON or an associative array. Alternatively this can be the identifier of a data model used for validation.
Returns
None.
OMV\Rpc\ServiceAbstract::writeBgProcOutput (   $filename,
  $content 
)
finalprotected

Helper function to write a string to the background process output.

Parameters
filenamePath to the file where to write the content.
contentThe content to write.
Returns
This function returns the number of bytes that were written to the file, or FALSE on failure.

The documentation for this class was generated from the following file: