1 | //----------------------------------------------------------- |
---|
2 | // Copyright Christian Arnault LAL-Orsay CNRS |
---|
3 | // arnault@lal.in2p3.fr |
---|
4 | // Modified by garonne@lal.in2p3.fr |
---|
5 | // See the complete license in cmt_license.txt "http://www.cecill.info". |
---|
6 | //----------------------------------------------------------- |
---|
7 | |
---|
8 | #include "cmt_error.h" |
---|
9 | #include "cmt_vector.h" |
---|
10 | #include "cmt_log.h" |
---|
11 | |
---|
12 | class TheError |
---|
13 | { |
---|
14 | public: |
---|
15 | static TheError& instance (); |
---|
16 | |
---|
17 | TheError () |
---|
18 | { |
---|
19 | error_names.add() = "ok"; |
---|
20 | error_names.add() = "Warning"; |
---|
21 | error_names.add() = "symbol not found"; |
---|
22 | error_names.add() = "pattern not found"; |
---|
23 | error_names.add() = "constituent not found"; |
---|
24 | error_names.add() = "fragment not found"; |
---|
25 | error_names.add() = "language not found"; |
---|
26 | error_names.add() = "syntax error"; |
---|
27 | error_names.add() = "command not implemented"; |
---|
28 | error_names.add() = "package not found"; |
---|
29 | error_names.add() = "path not found"; |
---|
30 | error_names.add() = "version conflict"; |
---|
31 | error_names.add() = "file access error"; |
---|
32 | error_names.add() = "configuration error"; |
---|
33 | error_names.add() = "execution error"; |
---|
34 | error_names.add() = "cannot lock"; |
---|
35 | error_names.add() = "cannot_write_lock"; |
---|
36 | error_names.add() = "cannot_run_lock_command"; |
---|
37 | error_names.add() = "cannot_unlock"; |
---|
38 | error_names.add() = "cannot_run_unlock_command"; |
---|
39 | error_names.add() = "cannot_remove_lock"; |
---|
40 | error_names.add() = "conflicting_lock"; |
---|
41 | error_names.add() = "unknown command"; |
---|
42 | error_names.add() = "wrong symbol type"; |
---|
43 | error_names.add() = "project release conflict"; |
---|
44 | error_names.add() = "execution failed"; |
---|
45 | m_execution_error = 0; |
---|
46 | } |
---|
47 | |
---|
48 | ~TheError () |
---|
49 | { |
---|
50 | } |
---|
51 | |
---|
52 | void clear () |
---|
53 | { |
---|
54 | m_code = CmtError::ok; |
---|
55 | m_text = ""; |
---|
56 | m_execution_error = 0 ; |
---|
57 | } |
---|
58 | |
---|
59 | void set (CmtError::code code, const cmt_string& text, const int execution_error) |
---|
60 | { |
---|
61 | m_code = code; |
---|
62 | m_text = text; |
---|
63 | m_execution_error = execution_error; |
---|
64 | } |
---|
65 | |
---|
66 | CmtError::code get_code () const |
---|
67 | { |
---|
68 | return (m_code); |
---|
69 | } |
---|
70 | |
---|
71 | int get_last_execution_error () |
---|
72 | { |
---|
73 | return m_execution_error; |
---|
74 | } |
---|
75 | |
---|
76 | const cmt_string& get_text () const |
---|
77 | { |
---|
78 | return (m_text); |
---|
79 | } |
---|
80 | |
---|
81 | const cmt_string& get_name (CmtError::code error) const |
---|
82 | { |
---|
83 | const cmt_string& s = error_names[error]; |
---|
84 | |
---|
85 | return (s); |
---|
86 | } |
---|
87 | |
---|
88 | private: |
---|
89 | CmtError::code m_code; |
---|
90 | cmt_string m_text; |
---|
91 | cmt_vector<cmt_string> error_names; |
---|
92 | int m_execution_error; |
---|
93 | }; |
---|
94 | |
---|
95 | //--------------------------------------------------------------- |
---|
96 | TheError& TheError::instance () |
---|
97 | { |
---|
98 | static TheError e; |
---|
99 | |
---|
100 | return (e); |
---|
101 | } |
---|
102 | |
---|
103 | //--------------------------------------------------------------- |
---|
104 | void CmtError::clear () |
---|
105 | { |
---|
106 | TheError& e = TheError::instance (); |
---|
107 | |
---|
108 | e.clear (); |
---|
109 | } |
---|
110 | |
---|
111 | //--------------------------------------------------------------- |
---|
112 | bool CmtError::has_pending_error () |
---|
113 | { |
---|
114 | TheError& e = TheError::instance (); |
---|
115 | |
---|
116 | if (e.get_code () == ok) return (false); |
---|
117 | else return (true); |
---|
118 | } |
---|
119 | |
---|
120 | //--------------------------------------------------------------- |
---|
121 | CmtError::code CmtError::get_last_error_code () |
---|
122 | { |
---|
123 | TheError& e = TheError::instance (); |
---|
124 | |
---|
125 | return (e.get_code ()); |
---|
126 | } |
---|
127 | |
---|
128 | //--------------------------------------------------------------- |
---|
129 | int CmtError::get_last_execution_error () |
---|
130 | { |
---|
131 | TheError& e = TheError::instance (); |
---|
132 | |
---|
133 | return (e.get_last_execution_error ()); |
---|
134 | } |
---|
135 | |
---|
136 | //--------------------------------------------------------------- |
---|
137 | const cmt_string& CmtError::get_error_name (code error) |
---|
138 | { |
---|
139 | TheError& e = TheError::instance (); |
---|
140 | |
---|
141 | return (e.get_name (error)); |
---|
142 | } |
---|
143 | |
---|
144 | //--------------------------------------------------------------- |
---|
145 | void CmtError::set (code error, const cmt_string& text, const int execution_error) |
---|
146 | { |
---|
147 | TheError& e = TheError::instance (); |
---|
148 | |
---|
149 | e.set (error, text, execution_error); |
---|
150 | } |
---|
151 | |
---|
152 | //--------------------------------------------------------------- |
---|
153 | cmt_string CmtError::get_last_error () |
---|
154 | { |
---|
155 | TheError& e = TheError::instance (); |
---|
156 | |
---|
157 | cmt_string result; |
---|
158 | |
---|
159 | result = get_error_name (e.get_code ()); |
---|
160 | result += " : "; |
---|
161 | result += e.get_text (); |
---|
162 | |
---|
163 | return (result); |
---|
164 | } |
---|
165 | |
---|
166 | //--------------------------------------------------------------- |
---|
167 | void CmtError::print () |
---|
168 | { |
---|
169 | /* |
---|
170 | TheError& e = TheError::instance (); |
---|
171 | |
---|
172 | cerr << "CMT> Error: " << get_error_name (e.get_code ()) << " : " << e.get_text () << endl; |
---|
173 | */ |
---|
174 | CmtMessage::error (get_last_error ()); |
---|
175 | } |
---|
176 | |
---|