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