f95954777cf16fd48a15893b9d47a56e63bbcf72
[curl-de-sac.git] / webtest / cds_test01.php
1 #!/usr/bin/php
2 <?php
3 require_once('Obj/curl-de-sac.phh');
4
5 class short_cmd_cls extends CDS_cmd_cls {
6     function short_cmd_cls()
7     {
8         parent::__construct("short", 10);
9     }
10
11     function cb()
12     {
13         printf("short_cb:\n");
14     }
15 }
16
17 class long_cmd_cls extends CDS_cmd_cls {
18     function long_cmd_cls()
19     {
20         parent::__construct("long", 15);
21     }
22
23     function cb()
24     {
25         printf("long_cb:\n");
26     }
27 }
28
29 function main()
30 {
31     // create cds
32     $cds = new Curl_de_sac();
33
34     // create cds_cmd 1
35     $cmd_cls1 = new short_cmd_cls();
36
37     // registrer cds_cmd 1
38     if (($cds->cmd_register($cmd_cls1)) == FALSE) {
39         fprintf(STDERR, "cmd_cls1 registration failed\n");
40         exit(1);
41     }
42
43     // create cds_cmd 2
44     $cmd_cls2 = new long_cmd_cls();
45
46     // register cds_cmd 2
47     if (($cds->cmd_register($cmd_cls2)) == FALSE) {
48         fprintf(STDERR, "cmd_cls2 registration failed\n");
49         exit(2);
50     }
51
52     // register cds_cmd 2 (retry)
53     if (($cds->cmd_register($cmd_cls2)) != FALSE) {
54         fprintf(STDERR, "cmd_cls2 re-registration success\n");
55         exit(3);
56     }
57
58     print_r($cds);
59     printf("SUCCESS\n");
60
61     // start loop
62     //   print status
63     //   if input data execute some command
64     //   if end => clean exit
65     exit(0);
66 }
67
68 main();
69
70 ?>