From 5121ff565fa26160e0c30fad2804114b2947b4b8 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 24 Mar 2015 21:18:13 +0100 Subject: [PATCH] Moved stuff to 'core'. Signed-off-by: Roland Haeder --- application/hub/config.php | 6 - application/hub/main/lists/class_ | 70 --- application/hub/main/lists/class_BaseList.php | 481 ------------------ application/hub/main/lists/tasks/.htaccess | 1 - .../hub/main/lists/tasks/class_TaskList.php | 72 --- core | 2 +- 6 files changed, 1 insertion(+), 631 deletions(-) delete mode 100644 application/hub/main/lists/class_ delete mode 100644 application/hub/main/lists/class_BaseList.php delete mode 100644 application/hub/main/lists/tasks/.htaccess delete mode 100644 application/hub/main/lists/tasks/class_TaskList.php diff --git a/application/hub/config.php b/application/hub/config.php index c516e96c4..c79bf2b58 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -477,9 +477,6 @@ $cfg->setConfigEntry('stacker_multiple_message_max_size', 10); // CFG: NEWS-MAIN-LIMIT $cfg->setConfigEntry('news_main_limit', 5); -// CFG: TASK-HANDLER-CLASS -$cfg->setConfigEntry('task_handler_class', 'TaskHandler'); - // CFG: TASK-PACKAGE-TAGS-INIT-STARTUP-DELAY $cfg->setConfigEntry('task_package_tags_init_startup_delay', 50); @@ -684,9 +681,6 @@ $cfg->setConfigEntry('task_dht_publication_interval_delay', 5000); // CFG: TASK-DHT-PUBLICATION-MAX-RUNS $cfg->setConfigEntry('task_dht_publication_max_runs', 0); -// CFG: TASK-LIST-CLASS -$cfg->setConfigEntry('task_list_class', 'TaskList'); - // CFG: TASK-POOL-ITERATOR-CLASS $cfg->setConfigEntry('task_pool_iterator_class', 'TaskPoolIterator'); diff --git a/application/hub/main/lists/class_ b/application/hub/main/lists/class_ deleted file mode 100644 index 27ade7aab..000000000 --- a/application/hub/main/lists/class_ +++ /dev/null @@ -1,70 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class ???List extends BaseList implements Listable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this class - * - * @return $listInstance An instance a Listable class - */ - public final static function create???List () { - // Get new instance - $listInstance = new ???List(); - - // Return the prepared instance - return $listInstance; - } - - /** - * "Getter" for an iterator instance of this list - * - * @return $iteratorInstance An instance of a Iterator class - * @todo 0% done - */ - public function getListIterator () { - $this->partialStub('Please implement this method.'); - } - - /** - * Clears this list by cleaning up all groups together. - * - * @return void - * @todo 0% done - */ - public function clearList () { - $this->partialStub('Please implement this method.'); - } -} - -// [EOF] -?> diff --git a/application/hub/main/lists/class_BaseList.php b/application/hub/main/lists/class_BaseList.php deleted file mode 100644 index 641b52453..000000000 --- a/application/hub/main/lists/class_BaseList.php +++ /dev/null @@ -1,481 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { - // Exception constants - const EXCEPTION_GROUP_ALREADY_ADDED = 0xf20; - const EXCEPTION_GROUP_NOT_FOUND = 0xf21; - const EXCEPTION_INVALID_HASH = 0xf22; - - /** - * List groups array - */ - private $listGroups = array(); - - /** - * List entries array - */ - private $listEntries = array(); - - /** - * List index array - */ - private $listIndex = array(); - - /** - * Protected constructor - * - * @param $className Name of the class - * @return void - */ - protected function __construct ($className) { - // Call parent constructor - parent::__construct($className); - } - - /** - * Getter for iterator instance from this list - * - * @return $iteratorInstance An instance of a Iterator class - */ - public function getIterator () { - // Get iterator from here - $iteratorInstance = $this->getIteratorInstance(); - - // Is the instance set? - if (is_null($iteratorInstance)) { - // Prepare a default iterator - $iteratorInstance = ObjectFactory::createObjectByConfiguredName('default_iterator_class', array($this)); - - // Set it here - $this->setIteratorInstance($iteratorInstance); - } // END - if - - // And return it - return $iteratorInstance; - } - - /** - * Checks whether the given group is set - * - * @param $groupName Group to check if found in list - * @return $isset Whether the group is valid - */ - public function isGroupSet ($groupName) { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName); - return isset($this->listGroups[$groupName]); - } - - /** - * Adds the given group or if already added issues a ListGroupAlreadyAddedException - * - * @param $groupName Group to add - * @return void - * @throws ListGroupAlreadyAddedException If the given group is already added - */ - public function addGroup ($groupName) { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!'); - // Is the group already added? - if ($this->isGroupSet($groupName)) { - // Throw the exception here - throw new ListGroupAlreadyAddedException(array($this, $groupName), self::EXCEPTION_GROUP_ALREADY_ADDED); - } // END - if - - // Add the group which is a simple array - $this->listGroups[$groupName] = ObjectFactory::createObjectByConfiguredName('list_group_class'); - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ' - EXIT!'); - } - - /** - * Adds the given instance to list group and sub group - * - * @param $groupName Group to add instance to - * @param $subGroup Sub group to add instance to - * @param $visitableInstance An instance of Visitable - * @return void - * @throws NoListGroupException If the given group is not found - */ - public function addInstance ($groupName, $subGroup, Visitable $visitableInstance) { - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ',subGroup=' . $subGroup . ',visitableInstance=' . $visitableInstance->__toString() . ' - CALLED!'); - - // Is the group there? - if (!$this->isGroupSet($groupName)) { - // Throw the exception here - throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND); - } // END - if - - // Is the sub group there? - if (!$this->listGroups[$groupName]->isGroupSet($subGroup)) { - // Automatically add it - $this->listGroups[$groupName]->addGroup($subGroup); - } // END - if - - // Generate the hash - $hash = $this->generateHash($groupName, $subGroup, $visitableInstance); - - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ',subGroup=' . $subGroup . ',hash=' . $hash . ' - Calling addEntry() ...'); - - // Now add it to the group list and hash it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',this->listGroups[' . $groupName . ']=' . $this->listGroups[$groupName]->__toString()); - //$this->listGroups[$groupName]->addEntry($subGroup, $hash); - - // Add the hash to the index - array_push($this->listIndex, $hash); - - // Add the instance itself to the list - $this->listEntries[$hash] = $visitableInstance; - - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ',subGroup=' . $subGroup . ' - EXIT!'); - } - - /** - * Gets an array from given list - * - * @param $list The requested list - * @return $array The requested array - * @throws NoListGroupException If the given group is not found - */ - public final function getArrayFromList ($list) { - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',list[' . gettype($list) . ']=' . $list . ' - CALLED!'); - - // Is the group there? - if ((!is_null($list)) && (!$this->isGroupSet($list))) { - // Throw the exception here - throw new NoListGroupException(array($this, $list), self::EXCEPTION_GROUP_NOT_FOUND); - } // END - if - - // Init array - $array = array(); - - // Is there another list? - if (!is_null($list)) { - // Then get it as well - $array = $this->listGroups[$list]->getArrayFromList(NULL); - } // END - if - - // Walk through all entries - foreach ($this->listIndex as $hash) { - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: hash=' . $hash); - - // Is the list entry set? - if ($this->isHashValid($hash)) { - // Add it - array_push($array, $this->listEntries[$hash]); - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: hash=' . $hash . ',array(' . count($array) . ')=' . print_r($array, TRUE) . ' - ADDED!'); - } // END - if - } // END - foreach - - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',list[' . gettype($list) . ']=' . $list . ',array()=' . count($array) . ' - EXIT!'); - - // Return it - return $array; - } - - /** - * Adds the given entry to list group - * - * @param $groupName Group to add instance to - * @param $entry An entry of any type - * @return void - * @throws NoListGroupException If the given group is not found - */ - public function addEntry ($groupName, $entry) { - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!'); - - // Is the group already added? - if (!$this->isGroupSet($groupName)) { - // Throw the exception here - throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND); - } // END - if - - // Generate hash - $hash = $this->generateHash($groupName, $groupName, $entry); - - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ',entry=' . print_r($entry, TRUE) . ', hash=' . $hash); - - // Add the hash to the index - array_push($this->listIndex, $hash); - - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ',listEntries()=' . count($this->listEntries)); - - // Now add the entry to the list - $this->listEntries[$hash] = $entry; - - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ',listEntries()=' . count($this->listEntries) . ' - EXIT!'); - } - - /** - * Removes given entry from the list group - * - * @param $groupName Group where we should remove the entry from - * @param $entry The entry we should remove - * @return void - * @throws NoListGroupException If the given group is not found - */ - public function removeEntry ($groupName, $entry) { - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!'); - - // Is the group already added? - if (!$this->isGroupSet($groupName)) { - // Throw the exception here - throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND); - } // END - if - - // Generate hash - $hash = $this->generateHash($groupName, $groupName, $entry); - - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ',entry=' . $entry . ', hash=' . $hash); - - // Remove it from the list ... - unset($this->listEntries[$hash]); - - // ... and hash list as well - unset($this->listIndex[array_search($hash, $this->listIndex)]); - - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',groupName=' . $groupName . ' - EXIT!'); - } - - /** - * Generates a hash from given group, sub group and entry - * - * @param $groupName Group to add instance to - * @param $subGroup Sub group to add instance to - * @param $entry An entry of any type - * @return $hash The generated - */ - private function generateHash ($groupName, $subGroup, $entry) { - // Created entry, 'null' is default - $entry2 = 'null'; - - // Determine type of entry - if (is_null($entry)) { - // Ignore this - } elseif ($entry instanceof FrameworkInterface) { - // Own instance detected - $entry2 = $entry->hashCode(); - } elseif ((is_int($entry)) || (is_float($entry)) || (is_resource($entry))) { - // Integer/float/resource detected - $entry2 = gettype($entry) . ':' . $entry; - } elseif (is_string($entry)) { - // String found - $entry2 = crc32($entry) . ':' . strlen($entry); - } elseif ((is_array($entry)) && (isset($entry['id']))) { - // Supported array found - $entry2 = crc32($entry['id']) . ':' . count($entry); - } elseif ((is_array($entry)) && (isset($entry[BasePool::SOCKET_ARRAY_RESOURCE])) && (isset($entry[BasePool::SOCKET_ARRAY_CONN_TYPE]))) { - // Is a socket resource array - $entry2 = crc32($entry[BasePool::SOCKET_ARRAY_RESOURCE] . ':' . $entry[BasePool::SOCKET_ARRAY_CONN_TYPE]); - } else { - // Unsupported type detected - self::createDebugInstance(__CLASS__)->debugOutput('BASE-LIST[' . __METHOD__ . ':' . __LINE__ . ']: Entry type ' . gettype($entry) . ' is unsupported.'); - - // @TODO Extend this somehow? - $entry2 = gettype($entry); - } - - // Construct string which we shall hash - $hashString = $groupName . ':' . $subGroup . ':' . $entry2; - - // Hash it with fastest hasher - $hash = crc32($hashString); - - // And return it - return $hash; - } - - /** - * Clears an array of groups, all are being checked for existence - * - * @param $groupNames An array with existing list groups - * @return void - */ - protected function clearGroups (array $groupNames) { - // Walk through all groups - foreach ($groupNames as $groupName) { - // Clear this group - $this->clearGroup($groupName); - } // END - foreach - } - - /** - * Clears a single group by resetting it to its initial state (empty array) - * - * @param $groupName Name of an existing group to clear - * @return void - */ - protected function clearGroup ($groupName) { - // Does this group exist? - if (!$this->isGroupSet($groupName)) { - // Throw the exception here - throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND); - } // END - if - - // Then clear this group list - $this->listGroups[$groupName]->clearList(); - - // Clear this list - $this->listIndex = array(); - $this->listEntries = array(); - } - - /** - * Counts all entries in this list - * - * @return $count All entries in this list - */ - public final function count () { - return count($this->listIndex); - } - - /** - * Checks whether the given hash is valid - * - * @param $hash The hash we should validate - * @return $isValid Whether the given hash is valid - */ - public final function isHashValid ($hash) { - // Check it - $isValid = ((in_array($hash, $this->listIndex)) && (isset($this->listEntries[$hash]))); - - // Return the result - return $isValid; - } - - /** - * Getter for hash from given hash index - * - * @param $hashIndex Index holding the hash - * @return $hash The hash - */ - public final function getHash ($hashIndex) { - // Get it ... - $hash = $this->listIndex[$hashIndex]; - - // ... and return it - return $hash; - } - - /** - * Gets an entry from given hash index - * - * @param $hashIndex The hash index to resolve the mapped entry - * @return $entry Solved entry from list - * @throws InvalidListHashException If the solved hash index is invalid - */ - public function getEntry ($hashIndex) { - // Get the hash value - $hash = $this->getHash($hashIndex); - - // Is the hash valid? - if (!$this->isHashValid($hash)) { - // Throw an exception here - throw new InvalidListHashException(array($this, $hash, $hashIndex), self::EXCEPTION_INVALID_HASH); - } // END - if - - // Now copy the entry - $entry = $this->listEntries[$hash]; - - // Return it - return $entry; - } - - /** - * Gets a full array from given group name - * - * @param $groupName The group name to get a list for - * @return $entries The array with all entries - * @throws NoListGroupException If the specified group is invalid - */ - public function getArrayFromProtocolInstance ($groupName) { - // Is the group valid? - if (!$this->isGroupSet($groupName)) { - // Throw the exception here - throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND); - } // END - if - - // Init the entries' array - $entries = array(); - - // Get an iterator - $iteratorInstance = $this->listGroups[$groupName]->getIterator(); - - // Rewind the iterator for this round - $iteratorInstance->rewind(); - - // Go through all entries - while ($iteratorInstance->valid()) { - // Get key - $entryIndex = $iteratorInstance->key(); - - // ... and the final entry which is the stored instance - $entry = $this->getEntry($entryIndex); - - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('LIST: Adding entry ' . $entry . ' ...'); - - // Add it to the list - $entries[$iteratorInstance->current()] = $entry; - - // Skip to next one - $iteratorInstance->next(); - } // END - while - - // Return the list - return $entries; - } - - /** - * Updates the given entry by hash with given array - * - * @param $hash Hash for this entry - * @param $entryArray Array with entry we should update - * @return void - * @throws InvalidListHashException If the solved hash index is invalid - */ - public function updateCurrentEntryByHash ($hash, array $entryArray) { - // Is the hash valid? - if (!$this->isHashValid($hash)) { - // Throw an exception here, hashIndex is unknown at this point - throw new InvalidListHashException(array($this, $hash, -999), self::EXCEPTION_INVALID_HASH); - } // END - if - - // Set the entry - $this->listEntries[$hash] = $entryArray; - } -} - -// [EOF] -?> diff --git a/application/hub/main/lists/tasks/.htaccess b/application/hub/main/lists/tasks/.htaccess deleted file mode 100644 index 3a4288278..000000000 --- a/application/hub/main/lists/tasks/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/hub/main/lists/tasks/class_TaskList.php b/application/hub/main/lists/tasks/class_TaskList.php deleted file mode 100644 index 4b1e36f6c..000000000 --- a/application/hub/main/lists/tasks/class_TaskList.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class TaskList extends BaseList implements Listable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this class - * - * @return $listInstance An instance a Listable class - */ - public static final function createTaskList () { - // Get new instance - $listInstance = new TaskList(); - - // Add tasks group - $listInstance->addGroup('tasks'); - - // Return the prepared instance - return $listInstance; - } - - /** - * "Getter" for an iterator instance of this list (not implemented) - * - * @return $iteratorInstance An instance of a Iterator class - */ - public function getListIterator () { - $this->debugInstance($this->__toString() . ' uses the default iterator. Please call getIterator() instead!'); - } - - /** - * Clears this list by cleaning up all groups together. - * - * @return void - */ - public function clearList () { - // Clear the only one group - $this->clearGroup('tasks'); - } -} - -// [EOF] -?> diff --git a/core b/core index c53e2093d..cc089c43f 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit c53e2093d7c29639ea3f19fd89b442159edf4780 +Subproject commit cc089c43f020e43a2637f1c605382fcbaf5f75d2 -- 2.39.5