source: verona/phcpp/phapipp.h @ 385:65e748226c91

Last change on this file since 385:65e748226c91 was 385:65e748226c91, checked in by Nikita Kozlov <nikita@…>, 17 months ago

adding phListenAddr to phapipp

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