1: <?php
2: /**
3: * ManiaLive - TrackMania dedicated server manager in PHP
4: *
5: * @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
6: * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
7: * @version $Revision: 440 $:
8: * @author $Author: martin.gwendal $:
9: * @date $Date: 2012-08-17 12:03:09 +0200 (ven., 17 août 2012) $:
10: */
11:
12: namespace ManiaLive\Threading;
13:
14: class Command
15: {
16: private static $count = 0;
17:
18: private $commandId;
19: private $result = null;
20: private $resultSet = false;
21: private $timeTaken = null;
22: private $callback;
23: private $task;
24:
25: static function GetCount()
26: {
27: return self::$count;
28: }
29:
30: function __construct(Runnable $task, $callback=null)
31: {
32: $this->commandId = self::$count++;
33: $this->task = $task;
34: $this->callback = $callback;
35: }
36:
37: function getId()
38: {
39: return $this->commandId;
40: }
41:
42: function getTask()
43: {
44: return $this->task;
45: }
46:
47: function isDone()
48: {
49: return $this->resultSet;
50: }
51:
52: function getResult()
53: {
54: return $this->result;
55: }
56:
57: function getTimeTaken()
58: {
59: return $this->timeTaken;
60: }
61:
62: function setResult($result, $timeTaken)
63: {
64: if($this->resultSet)
65: return;
66:
67: $this->result = $result;
68: $this->resultSet = true;
69: $this->timeTaken = $timeTaken;
70: if(is_callable($this->callback))
71: call_user_func($this->callback, $this);
72: }
73:
74: function fail()
75: {
76: if(is_callable($this->callback))
77: call_user_func($this->callback, $this);
78: }
79: }
80:
81: ?>
82: