/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
interface DATAHandlerInterface {
    public function SequenceStart($flags = 0);
    public function GroupStart($title, $subseconds = false, $flags = 0);
    public function GroupEnd($flags = 0);
    public function SequenceEnd($flags = 0);

    public function Start($vector_length, $flags = 0);
    public function DataHeaders(&$names, $flags = 0);
    public function DataVector(&$time, &$values, $flags = 0);
    public function End($flags = 0);

    public function GetContentType();
    public function GetExtension();
}


abstract class DATAHandler implements DATAHandlerInterface {
 var $h;
 var $output;
 var $info;

 var $content_type = false;
 var $extension = false;
 
 var $vector_length;
 var $subseconds;
 var $tz, $saved_tz;

 var $processed_groups;
 var $processed_vectors;
 
 var $multigroup = false;
 var $filewriter = false;
 var $filemode = false;
 var $nullwriter = false;
 
 function __construct(&$opts, STREAMWriterInterface $h = NULL) {
    $this->output = $h;
    $this->info = &$opts;

    if (isset($opts['content_type'])) 
	$this->content_type = $opts['content_type'];
    if (isset($opts['extension'])) 
	$this->extension = $opts['extension'];

    if ($opts) {
	$this->tz = $opts['timezone'];
    }

    if (!$this->tz) $this->tz = "UTC";
 }
 
 function SetOutput(STREAMWriterInterface $h) {
    $this->output = $h;
 }
 
 function SequenceStart($flags = 0) {
    if ($this->output) $this->h = $this->output;
    else {
	$this->h = new IO();
	$this->h->Open();
    }

    $this->saved_tz = date_default_timezone_get ();
    date_default_timezone_set($this->tz);

    $this->processed_groups = 0;
 }
 
 function GroupStart($title, $subseconds = false, $flags = 0) {
    $this->subseconds = $subseconds;
 }
 
 function GroupEnd($flags = 0) {
    $this->processed_groups++;
 }
 
 function SequenceEnd($flags = 0) {
    date_default_timezone_set($this->saved_tz);

    if (!$this->output) {
	$this->h->Close();
	unset($this->h);
    }
 }
 

 function Start($vector_length, $flags = 0) {
    $this->vector_length = $vector_length;
    $this->processed_vectors = 0;
 } 

 function DataHeaders(&$names, $flags = 0) {
 }
 
 function DataVector(&$time, &$values, $flags = 0) {
    $this->processed_vectors++;
 }

 function End($flags = 0) {
 }

 function GetContentType() {
    return $this->content_type;
 }
 function GetExtension() {
    return $this->extension;
 }

 function RequestFilemode() {
    if ($this->filewriter)
	$this->filemode = true;
    else
	throw new ADEIException(translate("Filemode is not supported by the handler"));

    return true;
 }
 
}

require("handlers/csv.php");
?>