Back to index

d-push  2.0
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions
PingTracking Class Reference
Inheritance diagram for PingTracking:
Inheritance graph
[legend]
Collaboration diagram for PingTracking:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PingTracking ()
 Constructor.
 __destruct ()
 Destructor Used to remove the current ping data from shared memory.
 DoForcePingTimeout ()
 Checks if there are newer ping requests for the same device & user so the current process could be terminated.
 InterProcessData ()
 Constructor.
 InitializeParams ()
 Initializes internal parameters.
 ReInitSharedMem ()
 Reinitializes shared memory by removing, detaching and re-allocating it.
 Clean ()
 Cleans up the shared memory block.
 IsActive ()
 Indicates if the shared memory is active.

Public Attributes

const CLEANUPTIME = 1

Protected Member Functions

 initPing ()
 Initialized the current request.
 blockMutex ()
 Blocks the class mutex Method blocks until mutex is available! ATTENTION: make sure that you always release a blocked mutex!
 releaseMutex ()
 Releases the class mutex After the release other processes are able to block the mutex themselfs.
 hasData ($id=2)
 Indicates if the requested variable is available in shared memory.
 getData ($id=2)
 Returns the requested variable from shared memory.
 setData ($data, $id=2)
 Writes the transmitted variable to shared memory Subclasses may never use an id < 2!

Protected Attributes

 $type
 $allocate

Static Protected Attributes

static $devid
static $pid
static $user
static $start

Private Member Functions

 checkArrayStructure (&$array)
 Builds an array structure for the concurrent ping connection detection.

Detailed Description

Definition at line 44 of file pingtracking.php.


Constructor & Destructor Documentation

Destructor Used to remove the current ping data from shared memory.

public

Definition at line 66 of file pingtracking.php.

                                 {
        // exclusive block
        if ($this->blockMutex()) {
            $pings = $this->getData();

            // check if our ping is still in the list
            if (isset($pings[self::$devid][self::$user][self::$pid])) {
                unset($pings[self::$devid][self::$user][self::$pid]);
                $stat = $this->setData($pings);
            }

            $this->releaseMutex();
        }
        // end exclusive block
    }

Here is the call graph for this function:


Member Function Documentation

InterProcessData::blockMutex ( ) [protected, inherited]

Blocks the class mutex Method blocks until mutex is available! ATTENTION: make sure that you always release a blocked mutex!

protected

Returns:
boolean

Definition at line 200 of file interprocessdata.php.

                                    {
        if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false))
            return @sem_acquire($this->mutexid);

        return false;
    }

Here is the caller graph for this function:

PingTracking::checkArrayStructure ( &$  array) [private]

Builds an array structure for the concurrent ping connection detection.

Parameters:
array$arrayreference to the ping data array

private

Returns:

Definition at line 143 of file pingtracking.php.

                                                  {
        if (!is_array($array))
            $array = array();

        if (!isset($array[self::$devid]))
            $array[self::$devid] = array();

        if (!isset($array[self::$devid][self::$user]))
            $array[self::$devid][self::$user] = array();

    }

Here is the caller graph for this function:

InterProcessData::Clean ( ) [inherited]

Cleans up the shared memory block.

public

Returns:
boolean

Definition at line 166 of file interprocessdata.php.

                            {
        $stat = false;

        // exclusive block
        if ($this->blockMutex()) {
            $cleanuptime = ($this->hasData(1)) ? $this->getData(1) : false;

            // TODO implement Shared Memory cleanup

            $this->releaseMutex();
        }
        // end exclusive block

        return $stat;
    }

Here is the call graph for this function:

Checks if there are newer ping requests for the same device & user so the current process could be terminated.

public

Returns:
boolean true if the current process is obsolete

Definition at line 116 of file pingtracking.php.

                                         {
        $pings = false;
        // exclusive block
        if ($this->blockMutex()) {
            $pings = $this->getData();
            $this->releaseMutex();
        }
        // end exclusive block

        // check if there is another (and newer) active ping connection
        if (is_array($pings) && isset($pings[self::$devid][self::$user]) && count($pings[self::$devid][self::$user]) > 1) {
            foreach ($pings[self::$devid][self::$user] as $pid=>$starttime)
                if ($starttime > self::$start)
                    return true;
        }

        return false;
    }

Here is the call graph for this function:

InterProcessData::getData ( id = 2) [protected, inherited]

Returns the requested variable from shared memory.

Parameters:
int$idint indicating the variable

protected

Returns:
mixed

Definition at line 249 of file interprocessdata.php.

                                        {
        if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false))
            return @shm_get_var($this->memid, $id);

        return ;
    }

Here is the caller graph for this function:

InterProcessData::hasData ( id = 2) [protected, inherited]

Indicates if the requested variable is available in shared memory.

Parameters:
int$idint indicating the variable

protected

Returns:
boolean

Definition at line 229 of file interprocessdata.php.

                                        {
        if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false)) {
            if (function_exists("shm_has_var"))
                return @shm_has_var($this->memid, $id);
            else {
                $some = $this->getData($id);
                return isset($some);
            }
        }
        return false;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Initializes internal parameters.

public

Returns:
boolean

Definition at line 76 of file interprocessdata.php.

                                       {
        if (!isset(self::$devid)) {
            self::$devid = Request::GetDeviceID();
            self::$pid = @getmypid();
            self::$user = Request::GetAuthUser();
            self::$start = time();
        }
        return true;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

PingTracking::initPing ( ) [protected]

Initialized the current request.

public

Returns:
boolean

Definition at line 88 of file pingtracking.php.

                                  {
        $stat = false;

        // initialize params
        $this->InitializeParams();

        // exclusive block
        if ($this->blockMutex()) {
            $pings = ($this->hasData()) ? $this->getData() : array();

            // set the start time for the current process
            $this->checkArrayStructure($pings);
            $pings[self::$devid][self::$user][self::$pid] = self::$start;
            $stat = $this->setData($pings);
            $this->releaseMutex();
        }
        // end exclusive block

        return $stat;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Constructor.

public

Definition at line 62 of file interprocessdata.php.

                                       {
        if (!isset($this->type) || !isset($this->allocate))
            throw new FatalNotImplementedException(sprintf("Class InterProcessData can not be initialized. Subclass %s did not initialize type and allocable memory.", get_class($this)));

        if ($this->InitSharedMem())
            ZLog::Write(LOGLEVEL_DEBUG, sprintf("%s(): Initialized mutexid %s and memid %s.", get_class($this), $this->mutexid, $this->memid));
    }

Here is the call graph for this function:

InterProcessData::IsActive ( ) [inherited]

Indicates if the shared memory is active.

public

Returns:
boolean

Definition at line 188 of file interprocessdata.php.

                               {
        return ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false));
    }

Here is the caller graph for this function:

Constructor.

public

Definition at line 51 of file pingtracking.php.

                                   {
        // initialize super parameters
        $this->allocate = 204800; // 200 KB
        $this->type = 2;
        parent::__construct();

        $this->initPing();
    }

Here is the call graph for this function:

Reinitializes shared memory by removing, detaching and re-allocating it.

public

Returns:
boolean

Definition at line 156 of file interprocessdata.php.

                                      {
        return ($this->RemoveSharedMem() && $this->InitSharedMem());
    }

Here is the call graph for this function:

InterProcessData::releaseMutex ( ) [protected, inherited]

Releases the class mutex After the release other processes are able to block the mutex themselfs.

protected

Returns:
boolean

Definition at line 214 of file interprocessdata.php.

                                      {
        if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false))
            return @sem_release($this->mutexid);

        return false;
    }

Here is the caller graph for this function:

InterProcessData::setData ( data,
id = 2 
) [protected, inherited]

Writes the transmitted variable to shared memory Subclasses may never use an id < 2!

Parameters:
mixed$datadata which should be saved into shared memory
int$idint indicating the variable (bigger than 2!)

protected

Returns:
boolean

Definition at line 266 of file interprocessdata.php.

                                               {
        if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false))
            return @shm_put_var($this->memid, $id, $data);

        return false;
    }

Here is the caller graph for this function:


Member Data Documentation

InterProcessData::$allocate [protected, inherited]

Definition at line 53 of file interprocessdata.php.

InterProcessData::$devid [static, protected, inherited]

Definition at line 48 of file interprocessdata.php.

InterProcessData::$pid [static, protected, inherited]

Definition at line 49 of file interprocessdata.php.

InterProcessData::$start [static, protected, inherited]

Definition at line 51 of file interprocessdata.php.

InterProcessData::$type [protected, inherited]

Definition at line 52 of file interprocessdata.php.

InterProcessData::$user [static, protected, inherited]

Definition at line 50 of file interprocessdata.php.

const InterProcessData::CLEANUPTIME = 1 [inherited]

Definition at line 46 of file interprocessdata.php.


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