Server
[
class tree: Server
] [
index: Server
] [
all elements
]
Todo List
Packages:
Client
CPAINT
JSON
Server
Source for file StatServer.inc.php
Documentation is available at
StatServer.inc.php
<?
/**
* StatServer
*
* LICENSE
*
* "THE BEER-WARE LICENSE" (Revision 42):
* "Sven Strittmatter" <ausserirdisch@sven-space.de> wrote this file.
* As long as you retain this notice you can do whatever you want with
* this stuff. If we meet some day, and you think this stuff is worth it,
* you can buy me a beer in return.
*
*
@category
StatServer
*
@package
Server
*
@copyright
Copyright (c) 2006 Sven Strittmatter
*/
/**
*
@see
cpaint
*/
require_once
dirname
(
__FILE__
)
.
'/cpaint/cpaint2.inc.php'
;
/**
* The service class.
*
*
@category
StatServer
*
@package
Server
*
@uses
cpaint
*
@copyright
Copyright (c) 2006 Sven Strittmatter
*/
class
StatServer
{
/**
* A reference to the actual CPAINT-Server object.
* It's the same object where the remote via AJAX accesable methods
* are registered.
*
*
@access
private
*
@var
cpaint
*/
private
$_cpaint_server
;
/**
* configuration array with the service names given as parameter
* to the method getServiceStatus and the apropriate status object
*
*
@access
private
*
@var
array
*/
private
$_checked_services
;
/**
* The constructor loads the actuaal configuration and cpaint
* server object from the global registry. And if the sesion is
* authenticated the user will be loaded by the authenticators
* username.
*
*
@access
publiic
*
@param
cpaint
$cpaint_server
*
@param
array
$checked_services
*/
public
function
__construct
(
array
$checked_services
)
{
$this
->
_cpaint_server
=
new
cpaint
(
)
;
$this
->
_checked_services
=
$checked_services
;
// Registration of all client callable functions.
$this
->
_cpaint_server
->
register
(
array
(
$this
,
'getServices'
))
;
$this
->
_cpaint_server
->
register
(
array
(
$this
,
'getServiceStatus'
))
;
}
/**
* Start server dispatching.
*
*
@access
public
*/
public
function
dispatch
(
)
{
$this
->
_cpaint_server
->
start
(
)
;
$this
->
_cpaint_server
->
return_data
(
)
;
}
/**
* Remote callable service method.
*
* service Searches for the given service name in the
* internal checked services array and trys to open a socket to
* the configured port.
*
*
@acces
public
*
@param
string
$service
*/
public
function
getServiceStatus
(
$service
)
{
if
(
array_key_exists
(
$service
,
$this
->
_checked_services
))
{
$socket
=
fsockopen
(
$service
,
$this
->
_checked_services
[
$service
]
)
;
if
(
false
===
$socket
)
{
$status
=
false
;
}
else
{
fclose
(
$socket
)
;
$status
=
true
;
}
}
else
{
$status
=
'ERROR: Service unknown!'
;
}
// Send the requested content by the cpaint sserver.
$this
->
_cpaint_server
->
set_data
(
array
(
'name'
=>
$service
,
'status'
=>
$status
))
;
}
/**
* Remote callable service method.
*
* Returns a list of the checked services.
*
*
@access
public
*/
public
function
getServices
(
)
{
$services
=
array_keys
(
$this
->
_checked_services
)
;
// Send the requested content by the cpaint sserver.
$this
->
_cpaint_server
->
set_data
(
$services
)
;
}
}
Documentation generated on Mon, 03 Aug 2009 21:33:19 +0200 by
phpDocumentor 1.4.2