source: trunk/IPs/systemC/Environment/TTY/src/TTY.cpp @ 144

Last change on this file since 144 was 144, checked in by rosiere, 14 years ago

1) compatible gcc 4.4.3
2) Translation file in MORPHEO_PREFIX directory

  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1#include "../include/TTY.h"
2#include <stdlib.h>
3#include <stdio.h>
4
5namespace environment {
6namespace tty {
7
8  TTY::TTY (std::string  name,
9            Parameters * param)
10  {
11    this->name  = name;
12    this->param = param;
13
14    xtty = new xTTY [param->nb_tty];
15
16   
17    for (uint32_t i=0; i<param->nb_tty; i++)
18      {
19        // ***** Create a log_file *****
20        xtty [i].log_file = fopen(param->name_tty[i].c_str(),"w");
21
22        if (xtty [i].log_file == NULL)
23          {
24            // Error
25            std::cerr << "<Tty> Can't open the file : \"" << param->name_tty[i] << "\"" << std::endl;
26            exit(1);
27          }
28
29        if (param->with_xtty == true)
30          {
31            // ***** TTY and pipe init *****
32            canal canal_output;
33           
34            if (pipe (canal_output.CanalPipe) != 0)
35              {
36                std::cerr << "<Tty> Error in pipe creation" << std::endl;
37                exit(1);
38              }
39             
40            if ((xtty[i].pid = fork()) == 0)
41              {
42                // Childen -> transform in a xtty
43                close(0); // s
44                if (dup (canal_output.CanalPipe [0]) == -1)
45                  {
46                    std::cerr << "<Tty> Error in dupplicate file descriptor." << std::endl;
47                    exit (1);
48                  };
49                close(1);
50                execlp("xtty","xtty", param->name_tty [i].c_str() ,NULL); // devient un tty
51               
52                std::cerr << "<Tty> Error in the creation of tty" << std::endl
53                          << "Test if environment's variable $PATH is set with ${MORPHEO_TOPLEVEL}/IPs/systemC/Environment/TTY/xtty" << std::endl;
54                exit (1);
55              }
56            else
57              {
58                // father
59                xtty[i].pipe_output = canal_output.CanalPipe [1];
60              }
61          }
62      }//end for
63  }
64
65  TTY::~TTY (void)
66  {
67    // Kill all tty
68    for (unsigned int i=0; i<param->nb_tty; i++)
69      {
70        if (param->with_xtty == true)
71          if (xtty[i].pid)
72            kill(xtty[i].pid,SIGTERM);
73        fclose(xtty[i].log_file);
74      }
75
76    delete [] xtty;
77  }
78
79};
80};
Note: See TracBrowser for help on using the repository browser.