Virtlab:Řídící server/ParserEquipment.php.inc

Z VirtlabWiki

(Rozdíly mezi verzemi)
Přejít na: navigace, hledání
Verze z 19:36, 19. 2. 2007
Vav166 (Diskuse | příspěvky)

← Předchozí porovnání
Verze z 12:52, 21. 2. 2007
Vav166 (Diskuse | příspěvky)

Následující porovnání →
Řádka 1: Řádka 1:
<pre> <pre>
-8: public function virtlabParserEquipment($file, $is_file=0, $cache_dev=1) {+8: public function virtlabParserEquipment($file, $is_file=0, $cache_dev=1) {
-24: public function getDevices() {+24: public function getDevices() {
-32: public function getDevicesCount() {+32: public function getDevicesCount() {
-42: public function getDevice($index) {+42: public function getDevice($index) {
-48: public function getDeviceType($index) {+48: public function getDeviceType($index) {
-54: public function getDeviceName($index) {+54: public function getDeviceName($index) {
-60: public function getDeviceSerial($index) {+60: public function getDeviceSerial($index) {
-66: public function getDevicePlatform($index) {+66: public function getDevicePlatform($index) {
-72: public function getDeviceByName($name, &$index) {+72: public function getDeviceByName($name, &$index) {
-84: public function getDeviceOS($name, $variant=1) {+84: public function getDeviceOS($name, $variant=1) {
103: public function getDeviceInterfaces($name) { 103: public function getDeviceInterfaces($name) {
110: public function getDeviceInterfacesCount($name) { 110: public function getDeviceInterfacesCount($name) {
Řádka 25: Řádka 25:
244: public function getDevicesList() { 244: public function getDevicesList() {
252: public function getDeviceInterfaceName($name, $index) { 252: public function getDeviceInterfaceName($name, $index) {
 +</pre>
 +
 +== Zdrojový kód ==
 +<pre>
 +<?php
 +
 +class virtlabParserEquipment {
 + private $parsed = array();
 + private $devices = array();
 + private $cached_devices = 0;
 +
 + public function virtlabParserEquipment($file, $is_file=0, $cache_dev=1) {
 + $parser = new virtlabXmlParser(1);
 +
 + if($is_file) $parser->parse($file);
 + else $parser->parse_data($file);
 +
 + $this->parsed = $parser->output;
 + unset($parser);
 +
 + if($cache_dev) {
 + $this->devices = $this->getDevices();
 + $this->cached_devices = 1;
 + }
 + }//function
 +
 +
 + public function getDevices() {
 + if(!$this->cached_devices) {
 + $temp = $this->parsed[0]["child"];
 + return $temp;
 + }
 + else return $this->devices;
 + }//function
 +
 + public function getDevicesCount() {
 + if(!$this->cached_devices)
 + {
 + $temp = $this->getDevices();
 + return count($temp);
 + }
 + else return count($this->devices);
 + }//function
 +
 +
 + public function getDevice($index) {
 + $temp = $this->getDevices();
 + return $temp[$index];
 + }//function
 +
 +
 + public function getDeviceType($index) {
 + $temp = $this->getDevice($index);
 + return $temp["attribs"]["TYPE"];
 + }//function
 +
 +
 + public function getDeviceName($index) {
 + $temp = $this->getDevice($index);
 + return $temp["attribs"]["NAME"];
 + }//function
 +
 +
 + public function getDeviceSerial($index) {
 + $temp = $this->getDevice($index);
 + return $temp["attribs"]["SERIAL_NUMBER"];
 + }//function
 +
 +
 + public function getDevicePlatform($index) {
 + $temp = $this->getDevice($index);
 + return $temp["attribs"]["PLATFORM"];
 + }//function
 +
 +
 + public function getDeviceByName($name, &$index) {
 + $result = array();
 + for($i = $this->getDevicesCount(); $i>=0; $i--) {
 + if($name==$this->getDeviceName($i)) {
 + $index = $i;
 + return $this->getDevice($i);
 + }//if
 + }//for
 + return NULL;
 + }//function
 +
 +
 + public function getDeviceOS($name, $variant=1) {
 + $temp = $this->getDeviceByName($name,$idx);
 + if($temp["child"]) {
 + $temp2 = $temp["child"][0];
 +
 + if(!isset($temp2)) return NULL;
 + if($variant) {
 + //$temp3["major"] = $temp2["child"][0]["content"];
 + //if($temp2["child"][1]) $temp3["minor"] = $temp2["child"][1]["content"];
 + //if($temp2["child"][2]) $temp3["other"] = $temp2["child"][2]["content"];
 + //return $temp3;
 + return $temp2["content"];
 + }
 + else return $temp2;
 + }//if
 + else return NULL;
 + }//function
 +
 +
 + public function getDeviceInterfaces($name) {
 + $temp = $this->getDeviceByName($name,$idx);
 + if($temp["child"][1]["name"]!="INTERFACES") return NULL;
 + return $temp["child"][1];
 + }//function
 +
 +
 + public function getDeviceInterfacesCount($name) {
 + $temp = $this->getDeviceInterfaces($name);
 + if(!$temp["child"]) return NULL;
 + return count($temp["child"]);
 + }//function
 +
 +
 + public function getDeviceInterface($name, $index, $variant=1) {
 + $temp = $this->getDeviceInterfaces($name);
 + if(!$temp["child"][$index]) return NULL;
 + if($variant) {
 + $temp2 = array();
 + $temp2["technology"] = $temp["child"][$index]["attribs"]["TECHNOLOGY"];
 + $temp2["connect_group"] = $temp["child"][$index]["attribs"]["CONNECT_GROUP"];
 + $temp2["name"] = $temp["child"][$index]["attribs"]["NAME"];
 + if($temp["child"][$index]["attribs"]["ETHER_TYPE"])
 + $temp2["ether_type"] = $temp["child"][$index]["attribs"]["ETHER_TYPE"];
 + return $temp2;
 + }
 + else return $temp["child"][$index];
 + }//function
 +
 +
 + public function getDeviceInterfaceTechnology($name, $index) {
 + $temp = $this->getDeviceInterface($name, $index, 1);
 + return $temp["technology"];
 + }//function
 +
 +
 + public function getDeviceInterfaceEthertype($name, $index) {
 + $temp = $this->getDeviceInterface($name, $index, 1);
 + if($temp["technology"] == "ethernet") return $temp["ether_type"];
 + else return NULL;
 + }//function
 +
 +
 + public function getDeviceInterfaceMaxbps($name, $index) {
 + $temp = $this->getDeviceInterface($name, $index, 0);
 + if($temp["child"][0]["name"]!="MAX_BPS") return NULL;
 + return $temp["child"][0]["content"];
 + }//function
 +
 +
 + public function getDeviceInterfaceFeatures($name, $index) {
 + $temp = $this->getDeviceInterface($name, $index, 0);
 + $temp2 = array();
 + if(is_array($temp) && $temp["child"])
 + foreach($temp["child"] as $hodnota) {
 + if($hodnota["name"]=="INT_FEATURE") {
 + array_push($temp2, $hodnota["content"]);
 + }//if
 + }//foreach
 + if(!$temp2[0]) return NULL;
 + else return $temp2;
 + }//function
 +
 +
 + public function getDeviceFeatures($name) {
 + $temp = $this->getDeviceByName($name,$idx);
 + foreach($temp["child"] as $hodnota) {
 + if($hodnota["name"]=="SPECIAL") {
 + $result = array();
 + foreach($hodnota["child"] as $hodnota2) {
 + array_push($result, $hodnota2["content"]);
 + }//foreach
 + break;
 + }//if
 + }//foreach
 + if(!$result[0]) return NULL;
 + else return $result;
 + }//function
 +
 +
 + public function getDevicesFeatures() {
 + $feat = array();
 + for($i = $this->getDevicesCount() - 1; $i >= 0; $i--) {
 + $jmeno = $this->getDeviceName($i);
 + $temp = $this->getDeviceFeatures($jmeno);
 + if(is_array($temp))
 + foreach($temp as $value)
 + array_push($feat, $value);
 + }//for
 + return $feat;
 + }
 +
 +
 + public function getDevicesByType($type) {
 + $temp = $this->getDevices();
 + $temp2 = array();
 + foreach($temp as $hodnota) {
 + if($hodnota["attribs"]["TYPE"] == $type)
 + array_push($temp2, $hodnota["attribs"]["NAME"]);
 + }
 + if(!$temp2[0]) return NULL;
 +
 + return Unique($temp2);
 + }//function
 +
 +
 + public function getDevicesTypes() {
 + $temp = $this->getDevices();
 + $temp2 = array();
 + foreach($temp as $hodnota) {
 + array_push($temp2, $hodnota["attribs"]["TYPE"]);
 + }
 + if(!$temp2[0]) return NULL;
 +
 + return Unique($temp2);
 + }//function
 +
 +
 + public function getDeviceInterfacesFeatures($name) {
 + $feat = array();
 + for($i = $this->getDeviceInterfacesCount($name) - 1; $i >= 0; $i--) {
 + $temp = $this->getDeviceInterfaceFeatures($name, $i);
 + if(is_array($temp))
 + foreach($temp as $hodnota)
 + array_push($feat, $hodnota);
 + }//for
 + return $feat;
 + }//function
 +
 + public function getDevicesInterfacesFeatures() {
 + $feat = array();
 + for($i = $this->getDevicesCount() - 1; $i >= 0; $i--) {
 + $jmeno = $this->getDeviceName($i);
 + $temp = $this->getDeviceInterfacesFeatures($jmeno);
 + if(is_array($temp))
 + foreach($temp as $hodnota)
 + array_push($feat, $hodnota);
 + }//for
 + return $feat;
 + }//function
 +
 + public function getDevicesList() {
 + $temp = array();
 + for($i = $this->getDevicesCount() - 1; $i >= 0; $i--) {
 + $temp[$i] = $this->getDeviceName($i);
 + }//for
 + return $temp;
 + }//function
 +
 + public function getDeviceInterfaceName($name, $index) {
 + $temp = $this->getDeviceInterface($name, $index, 1);
 + return $temp["name"];
 + }//function
 +}//class
 +?>
</pre> </pre>

Verze z 12:52, 21. 2. 2007

8:    public function virtlabParserEquipment($file, $is_file=0, $cache_dev=1) {
24:    public function getDevices() {
32:    public function getDevicesCount() {
42:    public function getDevice($index) {
48:    public function getDeviceType($index) {
54:    public function getDeviceName($index) {
60:    public function getDeviceSerial($index) {
66:    public function getDevicePlatform($index) {
72:    public function getDeviceByName($name, &$index) {
84:    public function getDeviceOS($name, $variant=1) {
103:    public function getDeviceInterfaces($name) {
110:    public function getDeviceInterfacesCount($name) {
117:    public function getDeviceInterface($name, $index, $variant=1) {
133:    public function getDeviceInterfaceTechnology($name, $index) {
139:    public function getDeviceInterfaceEthertype($name, $index) {
146:    public function getDeviceInterfaceMaxbps($name, $index) {
153:    public function getDeviceInterfaceFeatures($name, $index) {
167:    public function getDeviceFeatures($name) {
183:    public function getDevicesFeatures() {
196:    public function getDevicesByType($type) {
209:    public function getDevicesTypes() {
221:    public function getDeviceInterfacesFeatures($name) {
232:    public function getDevicesInterfacesFeatures() {
244:    public function getDevicesList() {
252:    public function getDeviceInterfaceName($name, $index) {

Zdrojový kód

<?php

class virtlabParserEquipment {
    private $parsed = array();
    private $devices = array();
    private $cached_devices = 0;
    
    public function virtlabParserEquipment($file, $is_file=0, $cache_dev=1) {
        $parser = new virtlabXmlParser(1);

        if($is_file) $parser->parse($file);
        else $parser->parse_data($file);

        $this->parsed = $parser->output;
        unset($parser);

        if($cache_dev) {
            $this->devices = $this->getDevices();
            $this->cached_devices = 1;
        }
    }//function

    
    public function getDevices() {
        if(!$this->cached_devices) {
            $temp = $this->parsed[0]["child"];
            return $temp;
        }
        else return $this->devices;
    }//function

    public function getDevicesCount() {
        if(!$this->cached_devices)
        {    
            $temp = $this->getDevices();
            return count($temp);
        }
        else return count($this->devices);
    }//function


    public function getDevice($index) {
        $temp = $this->getDevices();
        return $temp[$index];
    }//function    


    public function getDeviceType($index) {
        $temp = $this->getDevice($index);
        return $temp["attribs"]["TYPE"];
    }//function


    public function getDeviceName($index) {
        $temp = $this->getDevice($index);
        return $temp["attribs"]["NAME"];
    }//function


    public function getDeviceSerial($index) {
        $temp = $this->getDevice($index);
        return $temp["attribs"]["SERIAL_NUMBER"];
    }//function


    public function getDevicePlatform($index) {
        $temp = $this->getDevice($index);
        return $temp["attribs"]["PLATFORM"];
    }//function


    public function getDeviceByName($name, &$index) {
        $result = array();
        for($i = $this->getDevicesCount(); $i>=0; $i--) {
            if($name==$this->getDeviceName($i)) {
                $index = $i;
                return $this->getDevice($i);
            }//if
        }//for
        return NULL;
    }//function


    public function getDeviceOS($name, $variant=1) {
        $temp = $this->getDeviceByName($name,$idx);
        if($temp["child"]) {
            $temp2 = $temp["child"][0];

        if(!isset($temp2)) return NULL;
        if($variant) {
            //$temp3["major"] = $temp2["child"][0]["content"];
            //if($temp2["child"][1]) $temp3["minor"] = $temp2["child"][1]["content"];
            //if($temp2["child"][2]) $temp3["other"] = $temp2["child"][2]["content"];
            //return $temp3;
            return $temp2["content"];
        }
        else return $temp2;
        }//if
        else return NULL;
    }//function


    public function getDeviceInterfaces($name) {
        $temp = $this->getDeviceByName($name,$idx);
        if($temp["child"][1]["name"]!="INTERFACES") return NULL;
        return $temp["child"][1];
    }//function

    
    public function getDeviceInterfacesCount($name) {
        $temp = $this->getDeviceInterfaces($name);
        if(!$temp["child"]) return NULL;
        return count($temp["child"]);
    }//function

    
    public function getDeviceInterface($name, $index, $variant=1) {
        $temp = $this->getDeviceInterfaces($name);
        if(!$temp["child"][$index]) return NULL;
        if($variant) {
            $temp2 = array();
            $temp2["technology"] = $temp["child"][$index]["attribs"]["TECHNOLOGY"];
            $temp2["connect_group"] = $temp["child"][$index]["attribs"]["CONNECT_GROUP"];
            $temp2["name"] = $temp["child"][$index]["attribs"]["NAME"];
            if($temp["child"][$index]["attribs"]["ETHER_TYPE"])
                $temp2["ether_type"] = $temp["child"][$index]["attribs"]["ETHER_TYPE"];
            return $temp2;
        }
        else return $temp["child"][$index];
    }//function

    
    public function getDeviceInterfaceTechnology($name, $index) {
        $temp = $this->getDeviceInterface($name, $index, 1);
        return $temp["technology"];
    }//function


    public function getDeviceInterfaceEthertype($name, $index) {
        $temp = $this->getDeviceInterface($name, $index, 1);
        if($temp["technology"] == "ethernet") return $temp["ether_type"];
        else return NULL;
    }//function


    public function getDeviceInterfaceMaxbps($name, $index) {
        $temp = $this->getDeviceInterface($name, $index, 0);
        if($temp["child"][0]["name"]!="MAX_BPS") return NULL;
        return $temp["child"][0]["content"];
    }//function

    
    public function getDeviceInterfaceFeatures($name, $index) {
        $temp = $this->getDeviceInterface($name, $index, 0);
        $temp2 = array();
        if(is_array($temp) && $temp["child"])
            foreach($temp["child"] as $hodnota) {
                if($hodnota["name"]=="INT_FEATURE") {
                    array_push($temp2, $hodnota["content"]);
                }//if
            }//foreach
        if(!$temp2[0]) return NULL;
        else return $temp2;
    }//function


    public function getDeviceFeatures($name) {
        $temp = $this->getDeviceByName($name,$idx);
        foreach($temp["child"] as $hodnota) {
            if($hodnota["name"]=="SPECIAL") {
                $result = array();
                foreach($hodnota["child"] as $hodnota2) {
                    array_push($result, $hodnota2["content"]);
                }//foreach
                break;
            }//if
        }//foreach
        if(!$result[0]) return NULL;
        else return $result;
    }//function    


    public function getDevicesFeatures() {
        $feat = array();
        for($i = $this->getDevicesCount() - 1; $i >= 0; $i--) {
            $jmeno = $this->getDeviceName($i);
            $temp = $this->getDeviceFeatures($jmeno);
            if(is_array($temp))
                foreach($temp as $value)
                array_push($feat, $value);
        }//for
        return $feat;
    }


    public function getDevicesByType($type) {
        $temp = $this->getDevices();
        $temp2 = array();
        foreach($temp as $hodnota) {
            if($hodnota["attribs"]["TYPE"] == $type)
                array_push($temp2, $hodnota["attribs"]["NAME"]);
        }
        if(!$temp2[0]) return NULL;

        return Unique($temp2);
    }//function


    public function getDevicesTypes() {
        $temp = $this->getDevices();
        $temp2 = array();
        foreach($temp as $hodnota) {
            array_push($temp2, $hodnota["attribs"]["TYPE"]);
        }
        if(!$temp2[0]) return NULL;

        return Unique($temp2);
    }//function


    public function getDeviceInterfacesFeatures($name) {
        $feat = array();
        for($i = $this->getDeviceInterfacesCount($name) - 1; $i >= 0; $i--) {
            $temp = $this->getDeviceInterfaceFeatures($name, $i);
            if(is_array($temp))
                foreach($temp as $hodnota)
                    array_push($feat, $hodnota);
        }//for
        return $feat;
    }//function

    public function getDevicesInterfacesFeatures() {
        $feat = array();
        for($i = $this->getDevicesCount() - 1; $i >= 0; $i--) {
            $jmeno = $this->getDeviceName($i);
            $temp = $this->getDeviceInterfacesFeatures($jmeno);
            if(is_array($temp))
                foreach($temp as $hodnota)
                    array_push($feat, $hodnota);
        }//for
        return $feat;
    }//function

    public function getDevicesList() {
        $temp = array();
        for($i = $this->getDevicesCount() - 1; $i >= 0; $i--) {
            $temp[$i] = $this->getDeviceName($i);
        }//for
        return $temp;
    }//function

    public function getDeviceInterfaceName($name, $index) {
        $temp = $this->getDeviceInterface($name, $index, 1);
        return $temp["name"];
    }//function
}//class
?>
Osobní nástroje