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() = "syntax error"; |
---|
24 | error_names.add() = "command_not_implemented"; |
---|
25 | error_names.add() = "package_not_found"; |
---|
26 | error_names.add() = "path_not_found"; |
---|
27 | error_names.add() = "version_conflict"; |
---|
28 | error_names.add() = "file_access_error"; |
---|
29 | error_names.add() = "configuration_error"; |
---|
30 | error_names.add() = "execution_error"; |
---|
31 | error_names.add() = "cannot_lock"; |
---|
32 | error_names.add() = "cannot_write_lock"; |
---|
33 | error_names.add() = "cannot_run_lock_command"; |
---|
34 | error_names.add() = "cannot_unlock"; |
---|
35 | error_names.add() = "cannot_run_unlock_command"; |
---|
36 | error_names.add() = "cannot_remove_lock"; |
---|
37 | error_names.add() = "conflicting_lock"; |
---|
38 | error_names.add() = "unknown_command"; |
---|
39 | error_names.add() = "project_release_conflict"; |
---|
40 | error_names.add() = "execution_failed"; |
---|
41 | m_execution_error = 0; |
---|
42 | } |
---|
43 | |
---|
44 | ~TheError () |
---|
45 | { |
---|
46 | } |
---|
47 | |
---|
48 | void clear () |
---|
49 | { |
---|
50 | m_code = CmtError::ok; |
---|
51 | m_text = ""; |
---|
52 | m_execution_error = 0 ; |
---|
53 | } |
---|
54 | |
---|
55 | void set (CmtError::code code, const cmt_string& text, const int execution_error) |
---|
56 | { |
---|
57 | m_code = code; |
---|
58 | m_text = text; |
---|
59 | m_execution_error = execution_error; |
---|
60 | } |
---|
61 | |
---|
62 | CmtError::code get_code () const |
---|
63 | { |
---|
64 | return (m_code); |
---|
65 | } |
---|
66 | |
---|
67 | int get_last_execution_error () |
---|
68 | { |
---|
69 | return m_execution_error; |
---|
70 | } |
---|
71 | |
---|
72 | const cmt_string& get_text () const |
---|
73 | { |
---|
74 | return (m_text); |
---|
75 | } |
---|
76 | |
---|
77 | const cmt_string& get_name (CmtError::code error) const |
---|
78 | { |
---|
79 | const cmt_string& s = error_names[error]; |
---|
80 | |
---|
81 | return (s); |
---|
82 | } |
---|
83 | |
---|
84 | private: |
---|
85 | CmtError::code m_code; |
---|
86 | cmt_string m_text; |
---|
87 | cmt_vector<cmt_string> error_names; |
---|
88 | int m_execution_error; |
---|
89 | }; |
---|
90 | |
---|
91 | //--------------------------------------------------------------- |
---|
92 | TheError& TheError::instance () |
---|
93 | { |
---|
94 | static TheError e; |
---|
95 | |
---|
96 | return (e); |
---|
97 | } |
---|
98 | |
---|
99 | //--------------------------------------------------------------- |
---|
100 | void CmtError::clear () |
---|
101 | { |
---|
102 | TheError& e = TheError::instance (); |
---|
103 | |
---|
104 | e.clear (); |
---|
105 | } |
---|
106 | |
---|
107 | //--------------------------------------------------------------- |
---|
108 | bool CmtError::has_pending_error () |
---|
109 | { |
---|
110 | TheError& e = TheError::instance (); |
---|
111 | |
---|
112 | if (e.get_code () == ok) return (false); |
---|
113 | else return (true); |
---|
114 | } |
---|
115 | |
---|
116 | //--------------------------------------------------------------- |
---|
117 | CmtError::code CmtError::get_last_error_code () |
---|
118 | { |
---|
119 | TheError& e = TheError::instance (); |
---|
120 | |
---|
121 | return (e.get_code ()); |
---|
122 | } |
---|
123 | |
---|
124 | //--------------------------------------------------------------- |
---|
125 | int CmtError::get_last_execution_error () |
---|
126 | { |
---|
127 | TheError& e = TheError::instance (); |
---|
128 | |
---|
129 | return (e.get_last_execution_error ()); |
---|
130 | } |
---|
131 | |
---|
132 | //--------------------------------------------------------------- |
---|
133 | const cmt_string& CmtError::get_error_name (code error) |
---|
134 | { |
---|
135 | TheError& e = TheError::instance (); |
---|
136 | |
---|
137 | return (e.get_name (error)); |
---|
138 | } |
---|
139 | |
---|
140 | //--------------------------------------------------------------- |
---|
141 | void CmtError::set (code error, const cmt_string& text, const int execution_error) |
---|
142 | { |
---|
143 | TheError& e = TheError::instance (); |
---|
144 | |
---|
145 | e.set (error, text, execution_error); |
---|
146 | } |
---|
147 | |
---|
148 | //--------------------------------------------------------------- |
---|
149 | cmt_string CmtError::get_last_error () |
---|
150 | { |
---|
151 | TheError& e = TheError::instance (); |
---|
152 | |
---|
153 | cmt_string result; |
---|
154 | |
---|
155 | result = get_error_name (e.get_code ()); |
---|
156 | result += " : "; |
---|
157 | result += e.get_text (); |
---|
158 | |
---|
159 | return (result); |
---|
160 | } |
---|
161 | |
---|
162 | //--------------------------------------------------------------- |
---|
163 | void CmtError::print () |
---|
164 | { |
---|
165 | /* |
---|
166 | TheError& e = TheError::instance (); |
---|
167 | |
---|
168 | cerr << "CMT> Error: " << get_error_name (e.get_code ()) << " : " << e.get_text () << endl; |
---|
169 | */ |
---|
170 | CmtMessage::error (get_last_error ()); |
---|
171 | } |
---|
172 | |
---|