source: verona/phcpp/phapipp.h @ 468:20cc76e23da7

Last change on this file since 468:20cc76e23da7 was 468:20cc76e23da7, checked in by Vadim Lebedev <vadim@…>, 13 months ago

fix calls to lineSubscribe2 and lineSubscribe3

File size: 13.9 KB
Line 
1#ifndef __PHAPIPP_H__
2#define __PHAPIPP_H__ 1
3
4/*
5  The phapipp module implements thin C++ wrapper around phapi
6  Copyright (C) 2007  Vadim Lebedev  <vadim@mbdsys.com>
7
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  Lesser General Public License for more details.
17
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 */
22
23#include <phapi.h>
24#include <string>
25#include <map>
26#include <vector>
27
28/*
29
30  This module declares:
31   1/  phapi class which can be derived from or
32   used directly by the application.
33
34   2/  phapitp template class which can be used to simplify interface
35   with the code using C++ strings.
36
37
38   example using std::string is provided as a typedef stdphapi
39
40   to use with QString one should do something like:
41
42   struct qtenv {
43      typedef QString string;
44      static const char *cstr(const QString& str) { return str.toLatin(); }
45      };
46
47   typedef verona::phapitp<qtenv> QtPhapi;
48
49 */
50
51struct phMsgStateInfo2 {
52  enum phMsgEvent event;
53  int   status;
54  const char *from;
55  const char *to;
56  const char *ctype;
57  const char *subtype;
58  const char *content;
59  const char *rawctt;
60  int   tid;     /*!<  Trasnaction id of corresponding MESSAGE request */
61  int   cid;     /*!<  when non-zero this is message inside a dialog corresponding to call 'cid' */
62  std::vector<std::pair<const char*, const char*> > hlist;
63};
64
65
66namespace verona {
67
68
69class phapi
70{
71
72public:
73
74        phapi();
75        virtual ~phapi();
76
77        virtual int init(bool asyncMode = true);
78        virtual void terminate();
79
80        virtual int addAuthInfo(const char* username, const char* userid,  const char* passwd,
81                        const char *realm, const char* ha1 = 0);
82
83        virtual int listenAddr(int local_sip_port);
84
85        virtual int addVline(const char* displayname, const char* username, const char* host,
86                        const char*  proxy, int regTimeout, int mobility = PH_LINE_MOBILITY_DEFAULT);
87
88        virtual int delVline(int vlid);
89
90        virtual int vlRegister(int vlid);
91
92        virtual int sendOptions(int vlid, const char *to);
93
94        virtual int placeCall(int vlid, const char*  uri, void* userdata =0 , int rcid = 0, int streams = PH_STREAM_AUDIO,
95                        const char* adev = 0, const char* audio_addr = 0, const char* video_addr = 0);
96
97        virtual int acceptCall(int cid, void* userData = 0, int streams = PH_STREAM_AUDIO,
98                        const char* audio_addr = 0, const char* video_addr = 0);
99
100        virtual int rejectCall(int cid, int reason, const char *uri = 0);
101        virtual int ringingCall(int cid);
102        virtual int closeCall(int cid);
103        virtual int holdCall(int cid);
104        virtual int resumeCall(int cid);
105        virtual int blindTransferCall(int cid, const char *uri);
106
107        virtual int messageInCall(int cid, const char *buff, const char *mime);
108        virtual int getSipCallID(int cid, char *idbuf,  int bufsize);
109        virtual int sendDtmf(int cid, int dtmfChar, int mode);
110
111
112        virtual int setFollowMe(int vlid, const char *uri);
113        virtual int setBusy(int vlid, bool busy);
114        virtual int sendMessage(int vlid, const char* to,  const char* buff, const char* mime,
115                        const char* target = 0, const char* sipcid = 0);
116        virtual int sendMessage3(int vlid, const char* to,  const char* buff, const char* mime,
117                        const std::vector<std::pair<const char*, const char* > >& hdrs, const char* target = 0);
118
119        virtual int subscribe(int vlid, const char* to, int winfo, int use_proxy = 1, int expire = 600,
120                        const std::vector<std::pair<const char*, const char* > >* hdrs = 0);
121        virtual int unsubscribe(int sid, int winfo);
122        virtual int publish(int vlid, const char* to, const char* evt, const char* ctt, const char* content,
123                        int expires = -1);
124        int unpublish(int vlid, const char* to, const char* evt)
125        {
126                return publish(vlid, to, evt, 0, 0, 0);
127        }
128
129        virtual int getLineSipAddress(int vlid, char *buf, int size);
130        virtual int mobility(int vlid);
131        virtual int setUsername2(int vlid, const char* username);
132
133        int getVersion() { return phGetVersion(); }
134        const char * getRevision() { return phGetRevision(); }
135        struct ph_config_s*  getConfig() { return ph_get_config(); }
136
137        void changeAudioCodecList(const char *audio_codecs);
138        void changeVideoCodecList(const char *video_codecs);
139        void changeLocalIP(const char *local_ip);
140
141        int addCustomHeader(const char *reqnames, const char *hdrname,  const char *hdrval)
142        {
143                return phAddCustomization(reqnames, hdrname, hdrval);
144        }
145
146        int enableCustomization(int ruleId, int enable)
147        {
148                return phEnableCustomization(ruleId, enable);
149        }
150
151        int monitorHeader(const char *reqnames, const char *hdrname)
152        {
153                return phMonitorHeader(reqnames, hdrname);
154        }
155
156
157        int enableMonitor(int ruleID, int enable) { return phEnableMonitor(ruleID, enable); }
158
159        void resetMonitoring() { phResetMonitoring(); }
160
161
162#if defined(_WIN32_WCE)
163#ifdef SWIG
164%newobject getLocalIpFromDescription;
165#endif
166        char * getLocalIpFromDescription(const char *description);
167#endif
168        virtual void setUaString(const char *uastr);
169
170#ifdef SWIG
171%newobject getAudioCaptureDevices;
172%newobject getAudioPlaybackDevices;
173%newobject getVideoWebcamDevices;
174#endif
175
176        virtual std::map<char*, char*> getAudioCaptureDevices();
177        virtual std::map<char*, char*> getAudioPlaybackDevices();
178        virtual std::map<char*, char*> getVideoWebcamDevices();
179       
180        virtual void changeAudioDeviceIn(const char *devstr);
181        virtual void changeAudioDeviceOut(const char *devstr);
182        virtual void changeVideoDevices(const char *devstr);
183
184        virtual int setSoftRecvVolumeGain(int cid, float gain);
185        virtual int setSoftSendVolumeGain(int cid, float gain);
186        virtual int setRecvVolumeLevel(int cid, int level);
187        virtual int setSendVolumeLevel(int cid, int level);
188        virtual int mutePlayback(int cid, int val);
189        virtual int muteCapture(int cid, int val);
190       
191        virtual int setSoundFileGain(phStream* phstream,float gain);
192        virtual phStream * playSoundFile(const char * filename, int interval, const char* deviceid);
193        virtual int stopSoundFile(phStream * phstream);
194        virtual phStream * videoStartPreview(const char* deviceid);
195        virtual int videoStopPreview(phStream * phstream);
196        virtual int videoSetDefaultImage(const char* path);
197
198        virtual int poll();
199        virtual void refresh();
200
201        int getDebugLevel() { return phGetDebugLevel(); }
202        void setDebugLevel(int lvl) { phSetDebugLevel(lvl); }
203
204        virtual void setLogFile(const char* logFile);
205
206
207protected:
208
209        //  user overridable callbacks
210        virtual void onCallProgress(int cid, const phCallStateInfo_t *info);
211        virtual void onTransferProgress(int cid, const phTransferStateInfo_t *info);
212        virtual void onConfProgress(int cfid, const phConfStateInfo_t *info);
213        virtual void onRegProgress(int regid, int status);
214        virtual void onMsgProgress(int mid,  const phMsgStateInfo *info);
215        virtual void onMsgProgress2(int mid,  char * type, char * content);
216        virtual void onConnectionLost(const char* host, int port);
217#if defined(_WIN32_WCE)
218        virtual void onNotifyProgress (const char* ev, const char* from, const char *ctt, wchar_t* content);
219#else
220        virtual void onNotifyProgress (const char* ev, const char* from, const char *ctt, const char* content);
221#endif
222        virtual void onSubscriptionProgress(int sid,  const phSubscriptionStateInfo_t *info);
223        virtual void onFrameReady(int cid, phVideoFrameReceivedEvent_t *ev);
224
225#if defined(_WIN32_WCE)
226        virtual void onCallProgress2(int cid, phCallStateEvent status, wchar_t * uri, int error);
227#else
228        virtual void onCallProgress2(int cid, phCallStateEvent status, char * uri, int error);
229#endif
230        virtual void onDtmfProgress(int cid, int dtmf);
231        virtual void onPhLogCsl(const char *msg);
232        virtual void onSoundFileStopped(void *userdata , unsigned int _id, void *arg);
233        virtual void onQosEvent(int cid, const phQosInfo_t * info);
234
235
236private:
237
238#ifndef SWIG
239        static phCallbacks_t callbacks;
240
241        static void  callProgress(int cid, const phCallStateInfo_t *info);
242        static void  transferProgress(int cid, const phTransferStateInfo_t *info);
243        static void  confProgress(int cfid, const phConfStateInfo_t *info);
244        static void  regProgress(int regid, int status);
245        static void  msgProgress(int mid,  const phMsgStateInfo_t *info);
246        static void  connectionLost(const char* host, int port);
247        static void  notifyProgress(const char* ev, const char* from, const char *ctt, const char* content);
248        static void  subscriptionProgress(int sid,  const phSubscriptionStateInfo_t *info);
249        static void  frameReady(int cid, phVideoFrameReceivedEvent_t *ev);
250        static void  phLogCsl(const char *msg);
251        static void  soundFileStopped(void *userdata , unsigned int _id, void *arg);
252        static void  qosEvent(int cid, const phQosInfo_t * info);
253#endif
254
255};
256
257#ifndef SWIG
258//#define phthis ((phapi *) this)
259template<class Env>
260class phapitp: public phapi
261{
262public:
263
264        typedef typename Env::string string;
265
266        static inline const char *cstr(const string& s) { return Env::cstr(s); }
267
268        virtual ~phapitp(){};
269
270        int addAuthInfo(const string &username, const string& userid, const string& passwd, const char* realm)
271        {
272                return phapi::addAuthInfo(cstr(username), cstr(userid), cstr(passwd), realm);
273        }
274
275        int addAuthInfo(const string &username, const string& userid, const string&passwd, const char* realm,
276                        const string& ha1)
277        {
278                return phapi::addAuthInfo(cstr(username), cstr(userid), cstr(passwd), realm, cstr(ha1));
279        }
280        int listenAddr(int local_sip_port)
281        {
282                return phapi::listenAddr(local_sip_port);
283        }
284
285        int addVline(const string& displayname, const string& username, const string& host,
286                        const string&  proxy, int regTimeout, int mobility = PH_LINE_MOBILITY_DEFAULT)
287        {
288                return phapi::addVline(cstr(displayname), cstr(username), cstr(host), cstr(proxy), regTimeout, mobility);
289        }
290
291        int vlRegister(int vlid)
292        {
293                return phvlRegister(vlid);
294        }
295
296        int  sendOptions(int vlid, const string& to)
297        {
298                return phapi::sendOptions(vlid, cstr(to));
299        }
300
301
302        int placeCall(int vlid, const string& uri, void* userdata = 0, int rcid =0 , int streams = PH_STREAM_AUDIO,
303                        const char* adev = 0, const char* audio_addr = 0, const char* video_addr = 0)
304        {
305                return phapi::placeCall(vlid, cstr(uri), userdata, rcid, streams, adev, audio_addr, video_addr);
306        }
307
308
309
310        int rejectCall(int cid, int reason, const string& uri)
311        {
312                return phapi::rejectCall(cid, reason, cstr(uri));
313        }
314
315
316
317        int messageInCall(int cid, const string& mime, const string& buf)
318        {
319                return phapi::messageInCall(cid, cstr(mime), cstr(buf));
320        }
321
322
323
324
325        int setFollowMe(int vlid, const string& uri)
326        {
327                return phapi::setFollowMe(vlid, cstr(uri));
328        }
329
330
331
332        string getSipCallID(int cid)
333        {
334                char buf[256];
335
336                phapi::getSipCallID(cid, buf, sizeof(buf));
337
338                return buf;
339        }
340
341
342        string getSipAddress(int vlid)
343        {
344                char buf[256];
345
346                phapi::getLineSipAddress(vlid, buf, sizeof(buf));
347
348                return buf;
349        }
350
351
352
353        int sendMessage(int vlid, const string& to, const string& buff,
354                        const string& mime,
355                        const string& target, const string& sipcid)
356        {
357                return  phapi::sendMessage(vlid, cstr(to), cstr(buff), cstr(mime), cstr(target), cstr(sipcid));
358        }
359
360
361        int sendMessage(int vlid, const string& to, const string& buff,
362                        const string& mime, const string& target)
363        {
364                return phapi::sendMessage(vlid, cstr(to), cstr(buff), cstr(mime), cstr(target), 0);
365        }
366
367
368
369        int sendMessage(int vlid, const string& to, const string& buff, const string& mime)
370        {
371                return phapi::sendMessage(vlid, cstr(to), cstr(buff), cstr(mime), 0, 0);
372        }
373
374
375
376        int subscribe(int vlid, const string& to, int winfo, int use_proxy = 1, int expire = 600,
377                        vector<pair<const char*, const char*> >* hdrs=0)
378        {
379                return phapi::subscribe(vlid, cstr(to), winfo, use_proxy, expire, hdrs);
380        }
381
382        int unsubscribe(int sid, int winfo)
383        {
384                return phapi::unsubscribe(sid, winfo);
385        }
386
387        int publish(int vlid, const string& to, const string& evt, const string& ctt,
388                        const string& content, int expires = -1)
389        {
390                return phapi::publish(vlid, cstr(to), cstr(evt), cstr(ctt), cstr(content), expires);
391        }
392
393        int unpublish(int vlid, const string& to, const string& evt)
394        {
395                return phapi::unpublish(vlid, cstr(to), cstr(evt));
396        }
397
398        std::map<char*, char*> getAudioCaptureDevices()
399    {
400                return phapi::getAudioCaptureDevices();
401    }
402
403        std::map<char*, char*> getAudioPlaybackDevices()
404    {
405                return phapi::getAudioPlaybackDevices();
406    }
407
408        int setSoftRecvVolumeGain(int cid, float gain)
409        {
410                return phapi::setSoftRecvVolumeGain(cid, gain);
411        }
412
413        int setSoftSendVolumeGain(int cid, float gain)
414        {
415                return phapi::setSoftSendVolumeGain(cid, gain);
416        }
417
418        int setRecvVolumeLevel(int cid, int level)
419        {
420                return phapi::setRecvVolumeLevel(cid, level);
421        }
422
423        int setSendVolumeLevel(int cid, int level)
424        {
425                return phapi::setSendVolumeLevel(cid, level);
426        }
427
428        int mutePlayback(int cid, int val)
429        {
430                return phapi::mutePlayback(cid, val);
431        }
432
433        int muteCapture(int cid, int val)
434        {
435                return phapi::muteCapture(cid, val);
436        }
437
438        int addCustomHeader(const string& reqnames, const string& hdrname,  const string& hdrval)
439        {
440                return phapi::addCustomHeader(cstr(reqnames), cstr(hdrname), cstr(hdrval));
441        }
442
443        int monitorHeader(const string& reqnames, const string& hdrname)
444        {
445                return phapi::monitorHeader(cstr(reqnames), cstr(hdrname));
446        }
447
448
449
450        void setUaString(const string& ua) {  phapi::setUaString(cstr(ua)); }
451        void changeAudioDeviceIn(const string& devstr) {  phapi::changeAudioDeviceIn(cstr(devstr)); }
452        void changeAudioDeviceOut(const string& devstr) {  phapi::changeAudioDeviceOut(cstr(devstr)); }
453        void changeAudioCodecList(const string& audio_codecs)
454        {
455                phapi::changeAudioCodecList(cstr(audio_codecs));
456        }
457        void changeLocalIP(const string& local_ip)
458        {
459                phapi::changeLocalIP(cstr(local_ip));
460        }
461
462        void setLogFile(const string& logfile) {  phapi::setLogFile(cstr(logfile)); }
463
464
465protected:
466
467};
468
469//#undef phthis
470
471class stdenv
472{
473public:
474        typedef std::string string;
475        static const char *cstr(const string& s) {  if (&s != NULL) return s.c_str(); else return NULL; }
476
477
478};
479
480
481// decalare a wrapper using std::string
482typedef phapitp<stdenv> stdphapi;
483#endif
484
485}
486
487#endif /* __PHAPIPP_H__ */
Note: See TracBrowser for help on using the repository browser.