Debian Codegraph @

Xpjproject/pjsip/src/pjsua2/types.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 #include <pjsua2/types.hpp>
19 #include "util.hpp"
20
21 using namespace pj;
22 using namespace std;
23
24 #define THIS_FILE "types.cpp"
25
26 ///////////////////////////////////////////////////////////////////////////////
27
28 Error::Error()
29 : status(PJ_SUCCESS), srcLine(0)
30 {
31 }
32
33 Error::Error( pj_status_t prm_status,
34 const string &prm_title,
35 const string &prm_reason,
36 const string &prm_src_file,
37 int prm_src_line)
38 : status(prm_status), title(prm_title), reason(prm_reason),
39 srcFile(prm_src_file), srcLine(prm_src_line)
40 {
41 if (this->status != PJ_SUCCESS && prm_reason.empty()) {
42 char errmsg[PJ_ERR_MSG_SIZE];
43 pj_strerror(this->status, errmsg, sizeof(errmsg));
44 this->reason = errmsg;
45 }
46 }
47
48 string Error::info(bool multi_line) const
49 {
50 string output;
51
52 if (status==PJ_SUCCESS) {
53 output = "No error";
54 } else if (!multi_line) {
55 char temp[80];
56
57 if (!title.empty()) {
58 output += title + " error: ";
59 }
60 snprintf(temp, sizeof(temp), " (status=%d)", status);
61 output += reason + temp;
62 if (!srcFile.empty()) {
63 output += " [";
64 output += srcFile;
65 snprintf(temp, sizeof(temp), ":%d]", srcLine);
66 output += temp;
67 }
68 } else {
69 char temp[80];
70
71 if (!title.empty()) {
72 output += string("Title: ") + title + "\n";
73 }
74
75 snprintf(temp, sizeof(temp), "%d\n", status);
76 output += string("Code: ") + temp;
77 output += string("Description: ") + reason + "\n";
78 if (!srcFile.empty()) {
79 snprintf(temp, sizeof(temp), ":%d\n", srcLine);
80 output += string("Location: ") + srcFile + temp;
81 }
82 }
83
84 return output;
85 }
86
87 ///////////////////////////////////////////////////////////////////////////////
88
89 void TimeVal::fromPj(const pj_time_val &prm)
90 {
91 this->sec = prm.sec;
92 this->msec = prm.msec;
93 }
94