source: verona/phcpp/phapipp.h @ 299:3b282549a471

Last change on this file since 299:3b282549a471 was 299:3b282549a471, checked in by Vadim Lebedev <vadim@…>, 20 months ago

merging with qutecom trunk

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