| 1 | /* |
|---|
| 2 | The phapipp module implements thin C++ wrapper around phapi |
|---|
| 3 | Copyright (C) 2007 Vadim Lebedev <vadim@mbdsys.com> |
|---|
| 4 | |
|---|
| 5 | This library is free software; you can redistribute it and/or |
|---|
| 6 | modify it under the terms of the GNU Lesser General Public |
|---|
| 7 | License as published by the Free Software Foundation; either |
|---|
| 8 | version 2.1 of the License, or (at your option) any later version. |
|---|
| 9 | |
|---|
| 10 | This library 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 GNU |
|---|
| 13 | Lesser General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU Lesser General Public |
|---|
| 16 | License along with this library; if not, write to the Free Software |
|---|
| 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | #include <phapi.h> |
|---|
| 21 | #include <string> |
|---|
| 22 | |
|---|
| 23 | /* |
|---|
| 24 | |
|---|
| 25 | This module declares: |
|---|
| 26 | 1/ phapi class which can be derived from or |
|---|
| 27 | used directly by the application. |
|---|
| 28 | |
|---|
| 29 | 2/ phapitp template class which can be used to simplify interface |
|---|
| 30 | with the code using C++ strings. |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | example using std::string is provided as a typedef stdphapi |
|---|
| 34 | |
|---|
| 35 | to use with QString one should do something like: |
|---|
| 36 | |
|---|
| 37 | struct qtenv { |
|---|
| 38 | typedef QString string; |
|---|
| 39 | static const char *cstr(const QString& str) { return str.toLatin(); } |
|---|
| 40 | }; |
|---|
| 41 | |
|---|
| 42 | typedef verona::phapitp<qtenv> QtPhapi; |
|---|
| 43 | |
|---|
| 44 | */ |
|---|
| 45 | |
|---|
| 46 | namespace verona { |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | class phapi |
|---|
| 50 | { |
|---|
| 51 | |
|---|
| 52 | public: |
|---|
| 53 | |
|---|
| 54 | phapi(); |
|---|
| 55 | virtual ~phapi(); |
|---|
| 56 | |
|---|
| 57 | virtual int init(bool asyncMode = true); |
|---|
| 58 | virtual void terminate(); |
|---|
| 59 | |
|---|
| 60 | virtual int addAuthInfo(const char* username, const char* userid, const char* passwd, |
|---|
| 61 | const char *realm, const char* ha1 = 0); |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | virtual int addVline(const char* displayname, const char* username, const char* host, |
|---|
| 65 | const char* proxy, int regTimeout, int mobility = PH_LINE_MOBILITY_DEFAULT); |
|---|
| 66 | |
|---|
| 67 | virtual int delVline(int vlid); |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | virtual int sendOptions(int vlid, const char *to); |
|---|
| 71 | |
|---|
| 72 | virtual int placeCall(int vlid, const char* uri, void* userdata, int rcid, int streams, |
|---|
| 73 | const char* adev = 0, const char* audio_addr = 0, const char* video_addr = 0); |
|---|
| 74 | |
|---|
| 75 | virtual int acceptCall(int cid, void* userData, int streams, |
|---|
| 76 | const char* audio_addr = 0, const char* video_addr = 0); |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | virtual int rejectCall(int cid, int reason, const char *uri = 0); |
|---|
| 81 | virtual int ringingCall(int cid); |
|---|
| 82 | virtual int closeCall(int cid); |
|---|
| 83 | virtual int holdCall(int cid); |
|---|
| 84 | virtual int resumeCall(int cid); |
|---|
| 85 | virtual int messageInCall(int cid, const char *buff, const char *mime); |
|---|
| 86 | virtual int getSipCallID(int cid, char *idbuf, int bufsize); |
|---|
| 87 | virtual int sendDtmf(int cid, int dtmfChar, int mode); |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | virtual int setFollowMe(int vlid, const char *uri); |
|---|
| 91 | virtual int setBusy(int vlid, bool busy); |
|---|
| 92 | virtual int sendMessage(int vlid, const char* to, const char* buff, const char* mime, |
|---|
| 93 | const char* target = 0, const char* sipcid = 0); |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | virtual int subscribe(int vlid, const char* to, int winfo); |
|---|
| 99 | virtual int unsubscribe(int vlid, const char* to, int winfo); |
|---|
| 100 | virtual int publish(int vlid, const char* to, const char* evt, const char* ctt, const char* content, |
|---|
| 101 | int expires = -1); |
|---|
| 102 | int unpublish(int vlid, const char* to, const char* evt) |
|---|
| 103 | { |
|---|
| 104 | return publish(vlid, to, evt, 0, 0, 0); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | virtual int getLineSipAddress(int vlid, char *buf, int size); |
|---|
| 110 | virtual int mobility(int vlid); |
|---|
| 111 | |
|---|
| 112 | int getVersion() { return phGetVersion(); } |
|---|
| 113 | struct ph_config_s* getConfig() { return ph_get_config(); } |
|---|
| 114 | |
|---|
| 115 | virtual void setUaString(const char *uastr); |
|---|
| 116 | virtual void changeAudioDevices(const char *devstr); |
|---|
| 117 | virtual int addCustomHeader(const char *reqnames, const char *hdrname, const char *hdrval); |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | virtual int poll(); |
|---|
| 122 | virtual void refresh(); |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | int getDebugLevel() { return phGetDebugLevel(); } |
|---|
| 126 | void setDebugLevel(int lvl) { phSetDebugLevel(lvl); } |
|---|
| 127 | |
|---|
| 128 | virtual void setLogFile(const char* logFile); |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | public: |
|---|
| 132 | |
|---|
| 133 | // user overridable callbacks |
|---|
| 134 | |
|---|
| 135 | virtual void onCallProgress(int cid, const phCallStateInfo_t *info); |
|---|
| 136 | virtual void onTransferProgress(int cid, const phTransferStateInfo_t *info); |
|---|
| 137 | virtual void onConfProgress(int cfid, const phConfStateInfo_t *info); |
|---|
| 138 | virtual void onRegProgress(int regid, int status); |
|---|
| 139 | virtual void onMsgProgress(int mid, const phMsgStateInfo_t *info); |
|---|
| 140 | virtual void onNotifyProgress (const char* event, const char* from, const char *ctt, const char* content); |
|---|
| 141 | virtual void onSubscriptionProgress(int sid, const phSubscriptionStateInfo_t *info); |
|---|
| 142 | virtual void onFrameReady(int cid, phVideoFrameReceivedEvent_t *ev); |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | private: |
|---|
| 148 | |
|---|
| 149 | static phCallbacks_t callbacks; |
|---|
| 150 | |
|---|
| 151 | static void callProgress(int cid, const phCallStateInfo_t *info); |
|---|
| 152 | static void transferProgress(int cid, const phTransferStateInfo_t *info); |
|---|
| 153 | static void confProgress(int cfid, const phConfStateInfo_t *info); |
|---|
| 154 | static void regProgress(int regid, int status); |
|---|
| 155 | static void msgProgress(int mid, const phMsgStateInfo_t *info); |
|---|
| 156 | static void notifyProgress(const char* event, const char* from, const char *ctt, const char* content); |
|---|
| 157 | static void subscriptionProgress(int sid, const phSubscriptionStateInfo_t *info); |
|---|
| 158 | static void frameReady(int cid, phVideoFrameReceivedEvent_t *ev); |
|---|
| 159 | |
|---|
| 160 | }; |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | #define phthis ((phapi *) this) |
|---|
| 164 | template<class Env> |
|---|
| 165 | class phapitp: public phapi |
|---|
| 166 | { |
|---|
| 167 | public: |
|---|
| 168 | |
|---|
| 169 | typedef typename Env::string string; |
|---|
| 170 | |
|---|
| 171 | static inline const char *cstr(const string& s) { return Env::cstr(s); } |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | int addAuthInfo(const string &username, const string& userid, const string& passwd, const char* realm) |
|---|
| 176 | { |
|---|
| 177 | return phthis->addAuthInfo(cstr(username), cstr(userid), cstr(passwd), realm); |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | int addAuthInfo(const string &username, const string& userid, const string& passwd, const string& realm, |
|---|
| 181 | const string& ha1) |
|---|
| 182 | { |
|---|
| 183 | return phthis->addAuthInfo(cstr(username), cstr(userid), cstr(passwd), cstr(realm), cstr(ha1)); |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | int addVline(const string& displayname, const string& username, const string& host, |
|---|
| 188 | const string& proxy, int regTimeout, int mobility = PH_LINE_MOBILITY_DEFAULT) |
|---|
| 189 | { |
|---|
| 190 | return phthis->addVline(cstr(displayname), cstr(username), cstr(host), cstr(proxy), regTimeout, mobility); |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | int sendOptions(int vlid, const string& to) |
|---|
| 196 | { |
|---|
| 197 | return phthis->sendOptions(vlid, cstr(to)); |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | int placeCall(int vlid, const string& uri, void* userdata, int rcid, int streams, |
|---|
| 202 | const char* adev = 0, const char* audio_addr = 0, const char* video_addr = 0) |
|---|
| 203 | { |
|---|
| 204 | return phthis->placeCall(vlid, cstr(uri), userdata, rcid, streams, adev, audio_addr, video_addr); |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | int rejectCall(int cid, int reason, const string& uri) |
|---|
| 210 | { |
|---|
| 211 | return phthis->rejectCall(cid, reason, cstr(uri)); |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | int messageInCall(int cid, const string& mime, const string& buf) |
|---|
| 217 | { |
|---|
| 218 | return phthis->messageInCall(cid, cstr(mime), cstr(buf)); |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | int setFollowMe(int vlid, const string& uri) |
|---|
| 225 | { |
|---|
| 226 | return phthis->setFollowMe(vlid, cstr(uri)); |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | string getSipCallID(int cid) |
|---|
| 232 | { |
|---|
| 233 | char buf[256]; |
|---|
| 234 | |
|---|
| 235 | phthis->getSipCallID(cid, buf, sizeof(buf)); |
|---|
| 236 | |
|---|
| 237 | return buf; |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | string getSipAddress(int vlid) |
|---|
| 242 | { |
|---|
| 243 | char buf[256]; |
|---|
| 244 | |
|---|
| 245 | phthis->getLineSipAddress(vlid, buf, sizeof(buf)); |
|---|
| 246 | |
|---|
| 247 | return buf; |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | int sendMessage(int vlid, const string& to, const string& buff, |
|---|
| 253 | const string& mime, |
|---|
| 254 | const string& target, const string& sipcid) |
|---|
| 255 | { |
|---|
| 256 | return phthis->sendMessage(vlid, cstr(to), cstr(buff), cstr(mime), cstr(target), cstr(sipcid)); |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | int sendMessage(int vlid, const string& to, const string& buff, |
|---|
| 261 | const string& mime, const string& target) |
|---|
| 262 | { |
|---|
| 263 | return phthis->sendMessage(vlid, cstr(to), cstr(buff), cstr(mime), cstr(target), 0); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | int sendMessage(int vlid, const string& to, const string& buff, const string& mime) |
|---|
| 269 | { |
|---|
| 270 | return phthis->sendMessage(vlid, cstr(to), cstr(buff), cstr(mime), 0, 0); |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | int subscribe(int vlid, const string& to, int winfo) |
|---|
| 276 | { |
|---|
| 277 | return phthis->subscribe(vlid, cstr(to), winfo); |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | int unsubscribe(int vlid, const string& to, int winfo) |
|---|
| 281 | { |
|---|
| 282 | return phthis->unsubscribe(vlid, cstr(to), winfo); |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | int publish(int vlid, const string& to, const string& evt, const string& ctt, |
|---|
| 286 | const string& content, int expires = -1) |
|---|
| 287 | { |
|---|
| 288 | return phthis->publish(vlid, cstr(to), cstr(evt), cstr(ctt), cstr(content), expires); |
|---|
| 289 | } |
|---|
| 290 | |
|---|
| 291 | int unpublish(int vlid, const string& to, const string& evt) |
|---|
| 292 | { |
|---|
| 293 | return phthis->unpublish(vlid, cstr(to), cstr(evt)); |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | void setUaString(const string& ua) { phthis->setUaString(cstr(ua)); } |
|---|
| 298 | void changeAudioDevices(const string& devstr) { phthis->changeAudioDevices(cstr(devstr)); } |
|---|
| 299 | int addCustomHeader(const string& reqnames, const string& hdrname, const string& hdrval) |
|---|
| 300 | { |
|---|
| 301 | return phthis->addCustomHeader(cstr(reqnames), cstr(hdrname), cstr(hdrval)); |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | void setLogFile(const string& logfile) { phthis->setLogFile(cstr(logfile)); } |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | protected: |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | }; |
|---|
| 319 | |
|---|
| 320 | #undef phthis |
|---|
| 321 | |
|---|
| 322 | class stdenv |
|---|
| 323 | { |
|---|
| 324 | public: |
|---|
| 325 | typedef std::string string; |
|---|
| 326 | static const char *cstr(const string& s) { if (&s != NULL) return s.c_str(); else return NULL; } |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | }; |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | // decalare a wrapper using std::string |
|---|
| 333 | typedef phapitp<stdenv> stdphapi; |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | } |
|---|