Server
[ class tree: Server ] [ index: Server ] [ all elements ]

Source for file StatServer.inc.php

Documentation is available at StatServer.inc.php

  1. <?
  2. /**
  3.  * StatServer
  4.  *
  5.  * LICENSE
  6.  *
  7.  * "THE BEER-WARE LICENSE" (Revision 42):
  8.  * "Sven Strittmatter" <ausserirdisch@sven-space.de> wrote this file.
  9.  * As long as you retain this notice you can do whatever you want with
  10.  * this stuff. If we meet some day, and you think this stuff is worth it,
  11.  * you can buy me a beer in return.
  12.  *
  13.  * @category    StatServer
  14.  * @package     Server
  15.  * @copyright   Copyright (c) 2006 Sven Strittmatter
  16.  */
  17.  
  18. /**
  19.  * @see cpaint
  20.  */
  21. require_once dirname(__FILE__'/cpaint/cpaint2.inc.php';
  22.  
  23. /**
  24.  * The service class.
  25.  *
  26.  * @category    StatServer
  27.  * @package     Server
  28.  * @uses        cpaint
  29.  * @copyright   Copyright (c) 2006 Sven Strittmatter
  30.  */
  31. class StatServer {
  32.     /**
  33.      * A reference to the actual CPAINT-Server object.
  34.      * It's the same object where the remote via AJAX accesable methods
  35.      * are registered.
  36.      *
  37.      * @access    private
  38.      * @var     cpaint 
  39.      */
  40.     private $_cpaint_server;
  41.     /**
  42.      * configuration array with the service names given as parameter
  43.      * to the method getServiceStatus and the apropriate status object
  44.      *
  45.      * @access  private
  46.      * @var     array 
  47.      */
  48.     private $_checked_services;
  49.  
  50.     /**
  51.      * The constructor loads the actuaal configuration and cpaint
  52.      * server object from the global registry. And if the sesion is
  53.      * authenticated the user will be loaded by the authenticators
  54.      * username.
  55.      *
  56.      * @access    publiic
  57.      * @param cpaint $cpaint_server 
  58.      * @param array $checked_services 
  59.      */
  60.     public function __construct(array $checked_services{
  61.         $this->_cpaint_server    new cpaint();
  62.         $this->_checked_services $checked_services;
  63.         // Registration of all client callable functions.
  64.         $this->_cpaint_server->register(array($this'getServices'));
  65.         $this->_cpaint_server->register(array($this'getServiceStatus'));
  66.     }
  67.  
  68.     /**
  69.      * Start server dispatching.
  70.      * 
  71.      * @access public
  72.      */
  73.     public function dispatch({
  74.         $this->_cpaint_server->start();
  75.         $this->_cpaint_server->return_data();
  76.     }
  77.  
  78.     /**
  79.      * Remote callable service method.
  80.      *
  81.      * service Searches for the given service name in the
  82.      * internal checked services array and trys to open a socket to
  83.      * the configured port.
  84.      *
  85.      * @acces public
  86.      * @param string $service 
  87.      */
  88.     public function getServiceStatus($service{
  89.         if (array_key_exists($service$this->_checked_services)) {
  90.             $socket fsockopen($service$this->_checked_services[$service]);
  91.  
  92.             if (false === $socket{
  93.                 $status false;
  94.             else {
  95.                 fclose($socket);
  96.                 $status true;
  97.             }
  98.         else {
  99.             $status 'ERROR: Service unknown!';
  100.         }
  101.  
  102.         // Send the requested content by the cpaint sserver.
  103.         $this->_cpaint_server->set_data(array('name' => $service'status' => $status));
  104.     }
  105.  
  106.     /**
  107.      * Remote callable service method.
  108.      *
  109.      * Returns a list of the checked services.
  110.      *
  111.      * @access public
  112.      */
  113.     public function getServices({
  114.         $services array_keys($this->_checked_services);
  115.  
  116.         // Send the requested content by the cpaint sserver.
  117.         $this->_cpaint_server->set_data($services);
  118.     }
  119. }

Documentation generated on Mon, 03 Aug 2009 21:33:19 +0200 by phpDocumentor 1.4.2