1 /* 2 KHOMP generic endpoint/channel library. 3 Copyright (C) 2007-2009 Khomp Ind. & Com. 4 5 The contents of this file are subject to the Mozilla Public License Version 1.1 6 (the "License"); you may not use this file except in compliance with the 7 License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ 8 9 Software distributed under the License is distributed on an "AS IS" basis, 10 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for 11 the specific language governing rights and limitations under the License. 12 13 Alternatively, the contents of this file may be used under the terms of the 14 "GNU Lesser General Public License 2.1" license (the “LGPL" License), in which 15 case the provisions of "LGPL License" are applicable instead of those above. 16 17 If you wish to allow use of your version of this file only under the terms of 18 the LGPL License and not to allow others to use your version of this file under 19 the MPL, indicate your decision by deleting the provisions above and replace them 20 with the notice and other provisions required by the LGPL License. If you do not 21 delete the provisions above, a recipient may use your version of this file under 22 either the MPL or the LGPL License. 23 24 The LGPL header follows below: 25 26 This library is free software; you can redistribute it and/or 27 modify it under the terms of the GNU Lesser General Public 28 License as published by the Free Software Foundation; either 29 version 2.1 of the License, or (at your option) any later version. 30 31 This library is distributed in the hope that it will be useful, 32 but WITHOUT ANY WARRANTY; without even the implied warranty of 33 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 34 Lesser General Public License for more details. 35 36 You should have received a copy of the GNU Lesser General Public License 37 along with this library; if not, write to the Free Software Foundation, Inc., 38 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 39 40 */ 41 42 #ifndef _VERBOSE_HPP_ 43 #define _VERBOSE_HPP_ 44 45 #include <string> 46 #include <sstream> 47 #include <map> 48 49 #include <k3l.h> 50 51 // k3lApiMajorVersion 52 #ifndef CM_PING 53 # include <k3lVersion.h> 54 # include <KTools.h> 55 #endif 56 57 #include <types.hpp> 58 #include <k3lapi.hpp> 59 #include <format.hpp> 60 61 #include <verbose_traits.hpp> 62 63 struct Verbose 64 { 65 typedef enum 66 { 67 R2_COUNTRY_BRA = 1, 68 R2_COUNTRY_ARG = 2, 69 R2_COUNTRY_CHI = 3, 70 R2_COUNTRY_MEX = 4, 71 R2_COUNTRY_URY = 5, 72 R2_COUNTRY_VEN = 6 73 } 74 R2CountryType; 75 76 typedef enum 77 { 78 HUMAN, 79 EXACT 80 } 81 Presentation; 82 83 /* dynamic (object) stuff */ 84 VerboseVerbose85 Verbose(const K3LAPI & api) 86 : _api(api) {}; 87 88 #if K3L_AT_LEAST(2,0,0) 89 std::string event(const int32, const K3L_EVENT * const, 90 const R2CountryType r2_country = R2_COUNTRY_BRA, 91 const Presentation fmt = HUMAN) const; 92 #else 93 std::string event(const int32, const K3L_EVENT * const, 94 const Presentation fmt = HUMAN) const; 95 #endif 96 97 std::string channelStatus(const int32, const int32, const int32, 98 const Presentation fmt = HUMAN) const; 99 100 /* end of dynamic (object) stuff */ 101 102 protected: 103 const K3LAPI & _api; 104 105 /* used internally */ 106 struct internal_not_found {}; 107 108 public: 109 110 /* static (class) stuff */ 111 112 static std::string echoLocation(const KEchoLocation, const Presentation fmt = HUMAN); 113 static std::string echoCancellerConfig(const KEchoCancellerConfig, const Presentation fmt = HUMAN); 114 115 #if K3L_AT_LEAST(2,0,0) 116 static std::string event(const KSignaling, const int32, const K3L_EVENT * const, 117 const R2CountryType = R2_COUNTRY_BRA, Presentation fmt = HUMAN); 118 #else 119 static std::string event(const KSignaling, const int32, const K3L_EVENT * const, 120 const Presentation fmt = HUMAN); 121 #endif 122 123 #if K3L_AT_LEAST(2,0,0) 124 static std::string command(const int32, const K3L_COMMAND * const, 125 const R2CountryType = R2_COUNTRY_BRA, 126 const Presentation fmt = HUMAN); 127 128 static std::string command(const int32, const int32, const int32, const char * const, 129 const R2CountryType = R2_COUNTRY_BRA, 130 const Presentation fmt = HUMAN); 131 #else 132 static std::string command(const int32, const K3L_COMMAND * const, 133 const Presentation fmt = HUMAN); 134 135 static std::string command(const int32, const int32, const int32, const char * const, 136 const Presentation fmt = HUMAN); 137 #endif 138 139 static std::string deviceName(const KDeviceType, const int32, const int32 count = 0, const Presentation fmt = HUMAN); 140 static std::string deviceName(const KDeviceType, const int32, const Presentation fmt); 141 142 static std::string deviceType(const KDeviceType, const int32 count = 0, const Presentation fmt = HUMAN); 143 static std::string deviceType(const KDeviceType, const Presentation fmt); 144 145 static std::string deviceModel(const KDeviceType, const int32, const int32 count = 0, const Presentation fmt = HUMAN); 146 static std::string deviceModel(const KDeviceType, const int32, const Presentation fmt); 147 148 static std::string channelFeatures(const int32, const Presentation fmt = HUMAN); 149 static std::string signaling(const KSignaling, const Presentation fmt = HUMAN); 150 static std::string systemObject(const KSystemObject, const Presentation fmt = HUMAN); 151 static std::string mixerTone(const KMixerTone, const Presentation fmt = HUMAN); 152 static std::string mixerSource(const KMixerSource, const Presentation fmt = HUMAN); 153 154 static std::string seizeFail(const KSeizeFail, const Presentation fmt = HUMAN); 155 156 #if K3L_AT_LEAST(2,0,0) 157 static std::string callFail(const KSignaling, const R2CountryType, const int32, const Presentation fmt = HUMAN); 158 #else 159 static std::string callFail(const KSignaling, const int32, const Presentation fmt = HUMAN); 160 #endif 161 162 static std::string channelFail(const KSignaling, const int32, const Presentation fmt = HUMAN); 163 static std::string internalFail(const KInternalFail, const Presentation fmt = HUMAN); 164 165 static std::string linkErrorCounter(const KLinkErrorCounter, const Presentation fmt = HUMAN); 166 167 static std::string linkStatus(const KSignaling, const int32, const Presentation fmt = HUMAN, const bool simpleStatus = false); 168 static std::string channelStatus(const KSignaling, const int32, const Presentation fmt = HUMAN); 169 static std::string callStatus(const KCallStatus, const Presentation fmt = HUMAN); 170 static std::string status(const KLibraryStatus, const Presentation fmt = HUMAN); 171 172 #if K3L_AT_LEAST(2,0,0) 173 static std::string signGroupB(const KSignGroupB, const R2CountryType contry = R2_COUNTRY_BRA, 174 Presentation fmt = HUMAN); 175 #else 176 static std::string signGroupB(const KSignGroupB, const Presentation fmt = HUMAN); 177 #endif 178 179 #if K3L_AT_LEAST(2,0,0) 180 static std::string signGroupII(const KSignGroupII, const R2CountryType contry = R2_COUNTRY_BRA, 181 Presentation fmt = HUMAN); 182 #else 183 static std::string signGroupII(const KSignGroupII, const Presentation fmt = HUMAN); 184 #endif 185 186 static std::string h100configIndex(const KH100ConfigIndex, const Presentation fmt = HUMAN); 187 eventNameVerbose188 static std::string eventName(const int32 value) 189 { 190 return VerboseTraits::eventName((VerboseTraits::Event)value); 191 }; 192 commandNameVerbose193 static std::string commandName(const int32 value) 194 { 195 return VerboseTraits::commandName((VerboseTraits::Command)value); 196 }; 197 198 #if K3L_AT_LEAST(1,5,0) 199 static std::string sipFailures(const KSIP_Failures, const Presentation fmt = HUMAN); 200 #endif 201 202 #if K3L_AT_LEAST(1,5,1) 203 static std::string isdnCause(const KQ931Cause, const Presentation fmt = HUMAN); 204 #endif 205 206 #if K3L_AT_LEAST(1,5,2) 207 static std::string isdnDebug(const int32, const Presentation fmt = HUMAN); 208 #endif 209 210 #if K3L_AT_LEAST(1,6,0) 211 static std::string callStartInfo(const KCallStartInfo, const Presentation fmt = HUMAN); 212 213 static std::string gsmCallCause(const KGsmCallCause, const Presentation fmt = HUMAN); 214 static std::string gsmMobileCause(const KGsmMobileCause, const Presentation fmt = HUMAN); 215 static std::string gsmSmsCause(const KGsmSmsCause, const Presentation fmt = HUMAN); 216 217 static std::string q931ProgressIndication(const KQ931ProgressIndication, 218 Presentation fmt = HUMAN); 219 #endif 220 221 #if K3L_AT_LEAST(2,1,0) 222 static std::string faxResult(const KFaxResult code, const Presentation fmt = HUMAN); 223 static std::string faxFileErrorCause(const KFaxFileErrorCause code, const Presentation fmt = HUMAN); 224 #endif 225 226 /* end of static (class) stuff */ 227 228 private: 229 static std::string internal_deviceType(const KDeviceType, const int32); 230 static std::string internal_deviceModel(const KDeviceType, const int32, const int32); 231 232 #if K3L_AT_LEAST(1,5,0) 233 static std::string internal_sipFailures(const KSIP_Failures, const Presentation fmt = HUMAN); 234 #endif 235 #if K3L_AT_LEAST(1,5,1) 236 static std::string internal_isdnCause(const KQ931Cause, const Presentation fmt = HUMAN); 237 #endif 238 239 #if K3L_AT_LEAST(2,0,0) 240 static std::string internal_signGroupB(const KSignGroupB, const R2CountryType contry, const Presentation fmt = HUMAN); 241 static std::string internal_signGroupII(const KSignGroupII, const R2CountryType contry, const Presentation fmt = HUMAN); 242 #else 243 static std::string internal_signGroupB(const KSignGroupB, const Presentation fmt = HUMAN); 244 static std::string internal_signGroupII(const KSignGroupII, const Presentation fmt = HUMAN); 245 #endif 246 247 #if K3L_AT_LEAST(1,6,0) 248 static std::string internal_gsmCallCause(const KGsmCallCause, const Presentation fmt = HUMAN); 249 static std::string internal_gsmMobileCause(const KGsmMobileCause, const Presentation fmt = HUMAN); 250 static std::string internal_gsmSmsCause(const KGsmSmsCause, const Presentation fmt = HUMAN); 251 252 static std::string internal_q931ProgressIndication(const KQ931ProgressIndication, const Presentation fmt = HUMAN); 253 #endif 254 255 private: 256 enum Type 257 { 258 DEVICE, 259 CHANNEL, 260 PLAYER, 261 MIXER, 262 LINK, 263 NONE 264 }; 265 266 struct Target 267 { TargetVerbose::Target268 Target(Type _type) 269 : type(_type), device(-1), object(-1) 270 {}; 271 TargetVerbose::Target272 Target(Type _type, int32 _device) 273 : type(_type), device(_device), object(-1) 274 {}; 275 TargetVerbose::Target276 Target(Type _type, int32 _device, int32 _object) 277 : type(_type), device(_device), object(_object) 278 {}; 279 280 const Type type; 281 const int32 device; 282 const int32 object; 283 }; 284 285 static void generate(std::string &, const std::string &, const Target, const std::string &); 286 287 static std::string show(std::string &, const std::string &, const Target, const std::string &); 288 static std::string show(std::string &, const std::string &, const Target); 289 290 template < typename ReturnType > presentationVerbose291 static ReturnType presentation(const Presentation fmt, ReturnType str_exact, ReturnType str_human) 292 { 293 switch (fmt) 294 { 295 case HUMAN: return str_human; 296 case EXACT: return str_exact; 297 }; 298 299 return str_exact; 300 } 301 }; 302 303 #endif /* _VERBOSE_HPP_ */ 304